Debian Codegraph @

src/model/ac3dsurface.cpp

raw symbols SCIP
1 /***************************************************************************
2 AC3DSurface.cpp - description
3 -------------------
4 begin : june 29th, 05
5 copyright : (C) 2005 by Duong Khang NGUYEN
6 email : neoneurone @ gmail com
7
8 $Id: ac3dsurface.cpp 395 2008-12-27 21:12:05Z neoneurone $
9 ***************************************************************************/
10
11 /***************************************************************************
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * any later version. *
17 * *
18 ***************************************************************************/
19
20 #include "ac3dsurface.h"
21
22 #include "macros.h" // debug macros
23 #include "ac3dmacros.h"
24
25 #include <cstdio>
26 #include <cstring>
27
28 namespace AC3D {
29
30
31 /*=====================================================================*/
32 AC3DSurface::AC3DSurface():
33 uiAttribute(0)
34 {
35 OPENCITY_DEBUG("ctor1");
36 }
37
38
39 /*=====================================================================*/
40 AC3DSurface::AC3DSurface
41 (
42 stringstream& data
43 ):
44 uiAttribute(0)
45 {
46 // OPENCITY_DEBUG("ctor2");
47
48 this->Parse( data );
49 }
50
51
52 /*=====================================================================*/
53 AC3DSurface::~AC3DSurface()
54 {
55 }
56
57
58 /*=====================================================================*/
59 bool
60 AC3DSurface::IsTwoSide() const
61 {
62 return this->bTwoSide;
63 }
64
65
66 /*=====================================================================*/
67 const unsigned int
68 AC3DSurface::GetMat() const
69 {
70 return this->uiMat;
71 }
72
73
74 /*=====================================================================*/
75 const vector<Ref>&
76 AC3DSurface::GetVRef() const
77 {
78 return this->vRef;
79 }
80
81
82 /*=====================================================================*/
83 void
84 AC3DSurface::Parse
85 (
86 stringstream& data
87 )
88 {
89 char line[AC3D_MAX_LINE_LENGTH];
90 unsigned int numRef;
91 bool end;
92 Ref newRef;
93
94 //debug cout << "Given ss: " << data.str() << endl;
95
96 data.getline( line, AC3D_MAX_LINE_LENGTH );
97 end = false;
98 while (data.good() && !end) {
99 if ( strncmp( line, AC3D_TOKEN_SURF, AC3D_TOKEN_SURF_L ) == 0 ) {
100 sscanf( line, "SURF %x", &(this->uiAttribute));
101 this->type = (SURFACE_TYPE)(this->uiAttribute & 0xF);
102 this->bShaded = this->uiAttribute & 0x10;
103 this->bTwoSide = this->uiAttribute & 0x20;
104 data.getline( line, AC3D_MAX_LINE_LENGTH );
105 } else
106 if ( strncmp( line, AC3D_TOKEN_MAT, AC3D_TOKEN_MAT_L ) == 0 ) {
107 sscanf( line, "mat %u", &(this->uiMat) );
108 data.getline( line, AC3D_MAX_LINE_LENGTH );
109 } else
110 if ( strncmp( line, AC3D_TOKEN_REFS, AC3D_TOKEN_REFS_L ) == 0 ) {
111 sscanf( line, "refs %u", &(this->uiNumRef) );
112
113 // Read all the following "refs line"
114 numRef = this->uiNumRef;
115 data.getline( line, AC3D_MAX_LINE_LENGTH );
116 while (data.good() && (numRef-- > 0)) {
117 sscanf(
118 line,
119 "%u %f %f",
120 &newRef.uiVertIndex, &newRef.fTexS, &newRef.fTexT
121 );
122 this->vRef.push_back( newRef );
123 data.getline( line, AC3D_MAX_LINE_LENGTH );
124 }
125 end = true;
126 }
127 }
128
129 data.clear();
130 }
131
132
133 /*=====================================================================*/
134 string
135 AC3DSurface::ToStr() const
136 {
137 stringstream ss;
138 vector<Ref>::size_type pos, size;
139
140 ss.flags( stringstream::hex );
141 ss << "SURF 0x" << this->uiAttribute << endl;
142 ss.flags( stringstream::dec );
143
144 ss << "mat " << this->uiMat << endl
145 << "refs " << this->uiNumRef << endl;
146
147 size = this->vRef.size();
148 for (pos = 0; pos < size; pos++ ) {
149 ss << vRef[pos].uiVertIndex << " "
150 << vRef[pos].fTexS << " "
151 << vRef[pos].fTexT << endl;
152 }
153
154 return ss.str();
155 }
156
157
158
159 }
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187