annotate old/simple_pack/polygon.cpp @ 639:91d03774c407 draft

fix
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 19 Nov 2009 18:45:24 +0900
parents 3bc98f6d31ff
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
53
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
1 #include <iostream>
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
2 #include <SDL.h>
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
3 #include <SDL_opengl.h>
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
4 #include <SDL_image.h>
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
5 #include <libxml/parser.h>
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
6 #include "polygon.h"
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
7 #include "xml.h"
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
8 #include "texture.h"
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
9 #include "sys.h"
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
10 #include "triangle.h"
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
11 #include "vertex.h"
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
12 #include "span.h"
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
13 #include "scene_graph_pack.h"
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
14 using namespace std;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
15
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
16 //extern int decode(char *cont, char *file_name);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
17 extern int decode(char *cont, FILE *outfile);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
18
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
19 Polygon::Polygon()
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
20 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
21 xyz[0] = 0;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
22 xyz[1] = 0;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
23 xyz[2] = 0;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
24 xyz[3] = 1;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
25 c_xyz[0] = 0;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
26 c_xyz[1] = 0;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
27 c_xyz[2] = 0;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
28 c_xyz[3] = 1;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
29 angle[0] = 0;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
30 angle[1] = 0;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
31 angle[2] = 0;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
32 angle[3] = 1;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
33 next = NULL;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
34 child = NULL;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
35 parent = NULL;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
36 brother = NULL;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
37 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
38
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
39
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
40 void Polygon::tree_check()
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
41 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
42 Polygon *t;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
43 t = this;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
44
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
45 while(t)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
46 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
47 cout << "my_name : " << t->name << endl;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
48 if(t->child != NULL)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
49 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
50 cout << "--move child : " << t->child->name << endl;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
51 t = t->child;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
52 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
53 else if(t->brother != NULL)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
54 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
55 cout << "--move brother : " << t->brother->name << endl;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
56 t = t->brother;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
57 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
58 else
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
59 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
60 while(t)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
61 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
62 if(t->brother != NULL)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
63 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
64 cout << "--move brother : " << t->brother->name << endl;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
65 t = t->brother;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
66 break;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
67 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
68 else
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
69 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
70 if(t->parent)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
71 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
72 cout << "--move parent : " << t->parent->name << endl;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
73 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
74 t = t->parent;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
75 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
76 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
77 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
78 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
79 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
80
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
81 void Polygon::print_member()
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
82 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
83 //int n;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
84
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
85 cout << "size = " << size << endl;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
86 cout << "name = " << name << endl;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
87 cout << "parent_name = " << parent_name << endl;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
88 /*
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
89 for(n=0; n<size*3; n+=3)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
90 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
91 cout<<"coordinate = "<<data[n]<<" "<<data[n+1]<<" "<< data[n+2]<<endl;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
92 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
93 */
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
94 /*
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
95 for(n=size*3; n<size*6; n+=3)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
96 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
97 cout<<"narmal = "<<data[n]<<" "<<data[n+1]<<" "<<data[n+2]<<endl;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
98 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
99 */
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
100 cout<<"c_xyz = "<<c_xyz[0]<<" "<<c_xyz[1]<<" "<<c_xyz[2]<<endl;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
101 /*
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
102 for(n=size*6; n<size*9; n+=3)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
103 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
104 cout<<"texture = "<<data[n]<<" "<<data[n+1]<<" "<<data[n+2]<<endl;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
105 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
106 */
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
107 /*
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
108 for(n=0; n<size*3; n+=3)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
109 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
110 cout<<"coordinate = "<<data[n]<<" "<<data[n+1]<<" "<<data[n+2]<<endl;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
111 cout<<"normal = "<<data[n+size*3]<<" "<<data[n+size*3+1]<<" "<<data[n+size*3+2]<<endl;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
112 cout<<"texture = "<<data[n+size*6]<<" "<<1-data[n+size*6+1]<<endl;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
113 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
114 */
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
115 //cout << "image_name = " << image_name << endl;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
116 if(parent != NULL)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
117 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
118 cout << "parent->name = " << parent->name << endl;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
119 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
120 if(child != NULL)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
121 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
122 cout << "child->name = " << child->name << endl;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
123 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
124 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
125
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
126
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
127 void Polygon::parameter_change(char *name, float x, float y, float z, float ax, float ay, float az)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
128 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
129 Polygon *p;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
130 p = this;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
131 while(p)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
132 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
133 if(!strcmp(p->name,name))
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
134 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
135 p->xyz[0] = x;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
136 p->xyz[1] = y;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
137 p->xyz[2] = z;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
138 p->angle[0] = ax;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
139 p->angle[1] = ay;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
140 p->angle[2] = az;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
141 break;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
142 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
143 p = p->next;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
144 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
145 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
146
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
147 /*
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
148 void Polygon::load_texture(char *image_name)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
149 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
150 SDL_Surface *image;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
151 GLfloat texcoord[4];
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
152 image = IMG_Load(image_name);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
153 //image = IMG_Load("icon.bmp");
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
154 texture = (int *)SDL_GL_LoadTexture(image, texcoord);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
155 SDL_FreeSurface(image);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
156 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
157 */
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
158
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
159 void Polygon::draw(float *stack=NULL)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
160 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
161 float xyz1[4],xyz2[4],xyz3[4];
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
162
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
163 get_matrix(matrix, angle, xyz, stack);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
164 for(int n=0; n<size*3; n+=9)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
165 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
166 xyz1[0] = data[n];
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
167 xyz1[1] = data[n+1];
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
168 xyz1[2] = data[n+2]*-1;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
169 xyz1[3] = 1;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
170 xyz2[0] = data[n+3];
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
171 xyz2[1] = data[n+3+1];
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
172 xyz2[2] = data[n+3+2]*-1;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
173 xyz2[3] = 1;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
174 xyz3[0] = data[n+6];
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
175 xyz3[1] = data[n+6+1];
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
176 xyz3[2] = data[n+6+2]*-1;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
177 xyz3[3] = 1;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
178
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
179 rotate(xyz1, matrix);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
180 rotate(xyz2, matrix);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
181 rotate(xyz3, matrix);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
182
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
183 Vertex *ver1 = new Vertex(xyz1[0],xyz1[1],xyz1[2],data[n+size*6],data[n+size*6+1]);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
184 Vertex *ver2 = new Vertex(xyz2[0],xyz2[1],xyz2[2],data[n+size*6+3],data[n+size*6+3+1]);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
185 Vertex *ver3 = new Vertex(xyz3[0],xyz3[1],xyz3[2],data[n+size*6+6],data[n+size*6+6+1]);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
186 //printf("x1:%f ,%f ,%f , %f, %f\n",xyz1[0],xyz1[1],xyz1[2],data[n+size*6],data[n+size*6+1]);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
187 //printf("x2:%f ,%f ,%f , %f, %f\n",xyz2[0],xyz2[1],xyz2[2],data[n+size*6+3],data[n+size*6+3+1]);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
188 //printf("x3:%f ,%f ,%f , %f, %f\n",xyz3[0],xyz3[1],xyz3[2],data[n+size*6+6],data[n+size*6+6+1]);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
189 Triangle *tri = new Triangle(ver1,ver2,ver3);
68
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
190 Span_c *span = new Span_c();
53
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
191 span->viewer = viewer;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
192 span->p = this;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
193 span->create_span(tri,texture_image);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
194 delete ver1;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
195 delete ver2;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
196 delete ver3;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
197 delete tri;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
198 delete span;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
199 //viewer->write_triangle(xyz1[0],xyz1[1],xyz2[0],xyz2[1],xyz3[0],xyz3[1],rgb);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
200 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
201 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
202
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
203
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
204 void Polygon::tree_draw()
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
205 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
206 Polygon *t;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
207 t = this;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
208 /*
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
209 float *stack[128];
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
210 for(int i=0; i<128; i++)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
211 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
212 stack[i] = NULL;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
213 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
214 */
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
215
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
216 //glPushMatrix();
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
217 //int s=0;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
218 while(t)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
219 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
220
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
221 //t->draw(stack[s-1]);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
222 if(t->parent)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
223 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
224 t->draw(t->parent->matrix);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
225 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
226 else
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
227 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
228 t->draw();
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
229 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
230
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
231 if(t->child != NULL)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
232 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
233 //stack[s++] = t->matrix; //push
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
234 t = t->child;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
235 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
236 else if(t->brother != NULL)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
237 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
238 //stack[--s] = NULL; //pop
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
239 //stack[s++] = t->matrix; //push
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
240 t = t->brother;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
241 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
242 else
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
243 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
244 while(t)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
245 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
246 if(t->brother != NULL)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
247 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
248 //stack[--s] = NULL; //pop
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
249 //stack[s++] = t->matrix; //push
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
250 t = t->brother;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
251 break;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
252 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
253 else
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
254 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
255 t = t->parent;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
256 if(t)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
257 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
258 //stack[--s] = NULL; //pop
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
259 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
260 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
261 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
262 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
263 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
264 //glPopMatrix();
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
265 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
266
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
267 /*
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
268 void Polygon::sgp_update()
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
269 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
270 for (int i = 0; i < sgp->info.size; i++) {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
271 //(*my_func[node->move])(node);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
272 //(*my_func[node->interaction])(node, sgp);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
273
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
274 if(sgp->node[i].pn != -1) {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
275 get_matrix(sgp->node[i].translation, sgp->node[i].angle, sgp->node[i].obj_pos, sgp->node[sgp->node[i].pn].translation);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
276 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
277 else {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
278 get_matrix(sgp->node[i].translation, sgp->node[i].angle, sgp->node[i].obj_pos, NULL);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
279 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
280
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
281 //get_matrix(sgp->node[i].translation, sgp->node[i].angle, sgp->node[i].obj_pos, sgp->node[sgp->node[i].pn].translation);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
282 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
283 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
284 */
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
285
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
286 void Polygon::draw(SceneGraphPack *sgp)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
287 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
288 float xyz1[4],xyz2[4],xyz3[4];
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
289
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
290 /***SceneGraphUpdate***/
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
291 //sgp_update();
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
292 for (int i = 0; i < sgp->info.size; i++) {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
293 SceneGraphNode node = sgp->node[i];
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
294
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
295 /***draw***/
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
296 int n,nt;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
297 for(n=0,nt=0; n<node.size*3; n+=9,nt+=6) {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
298 xyz1[0] = node.vertex[n];
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
299 xyz1[1] = node.vertex[n+1];
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
300 xyz1[2] = node.vertex[n+2]*-1;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
301 xyz1[3] = 1;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
302 xyz2[0] = node.vertex[n+3];
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
303 xyz2[1] = node.vertex[n+3+1];
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
304 xyz2[2] = node.vertex[n+3+2]*-1;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
305 xyz2[3] = 1;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
306 xyz3[0] = node.vertex[n+6];
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
307 xyz3[1] = node.vertex[n+6+1];
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
308 xyz3[2] = node.vertex[n+6+2]*-1;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
309 xyz3[3] = 1;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
310
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
311 rotate(xyz1, node.translation);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
312 rotate(xyz2, node.translation);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
313 rotate(xyz3, node.translation);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
314
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
315 Vertex *ver1 = new Vertex(xyz1[0],xyz1[1],xyz1[2],node.texture[nt],node.texture[nt+1]);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
316 Vertex *ver2 = new Vertex(xyz2[0],xyz2[1],xyz2[2],node.texture[nt+2],node.texture[nt+2+1]);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
317 Vertex *ver3 = new Vertex(xyz3[0],xyz3[1],xyz3[2],node.texture[nt+4],node.texture[nt+4+1]);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
318
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
319 Triangle *tri = new Triangle(ver1,ver2,ver3);
68
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
320 Span_c *span = new Span_c();
53
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
321 span->viewer = viewer;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
322 span->p = this;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
323 span->create_span(tri,texture_image);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
324 delete ver1;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
325 delete ver2;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
326 delete ver3;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
327 delete tri;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
328 delete span;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
329 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
330 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
331 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
332
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
333
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
334 void Polygon::draw(PolygonPack *pp)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
335 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
336 for(int n=0; n<pp->info.size; n++)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
337 {
68
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
338 Vertex *ver1 = new Vertex(pp->tri[n].ver1.x,pp->tri[n].ver1.y,pp->tri[n].ver1.z,pp->tri[n].ver1.tex_x,pp->tri[n].ver1.tex_y);
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
339 Vertex *ver2 = new Vertex(pp->tri[n].ver2.x,pp->tri[n].ver2.y,pp->tri[n].ver2.z,pp->tri[n].ver2.tex_x,pp->tri[n].ver2.tex_y);
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
340 Vertex *ver3 = new Vertex(pp->tri[n].ver3.x,pp->tri[n].ver3.y,pp->tri[n].ver3.z,pp->tri[n].ver3.tex_x,pp->tri[n].ver3.tex_y);
53
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
341
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
342 Triangle *tri = new Triangle(ver1,ver2,ver3);
68
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
343 Span_c *span = new Span_c();
53
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
344 span->viewer = viewer;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
345 span->p = this;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
346 span->create_span(tri,texture_image);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
347 delete ver1;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
348 delete ver2;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
349 delete ver3;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
350 delete tri;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
351 delete span;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
352 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
353 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
354
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
355
68
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
356 void Polygon::draw(SPANPACK *sp)
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
357 {
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
358 for(int n=0; n<sp->info.size; n++)
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
359 {
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
360 int end = sp->span[n].length_x;
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
361 Uint32 rgb;
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
362 float tex1 = sp->span[n].tex_x1;
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
363 float tex2= sp->span[n].tex_x2;
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
364 float tey1 = sp->span[n].tex_y1;
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
365 float tey2= sp->span[n].tex_y2;
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
366 int tex_xpos;
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
367 int tex_ypos;
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
368 int tex_zpos;
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
369 int x = sp->span[n].x;
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
370 int y = sp->span[n].y;
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
371 float z = sp->span[n].start_z;
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
372 float zpos = sp->span[n].end_z;
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
373 float tex_x,tex_y,tex_z;
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
374
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
375 if(end == 1) {
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
376 //printf("end == 1\n");
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
377 //printf("tex_x:%f tex_y:%f\n",tex1,tex2);
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
378 //if(tex1 > 1) tex1 = 1;
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
379 //if(tey1 > 1) tey1 = 1;
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
380 tex_xpos = (int)((sp->span[n].tex_height-1) * tex1);
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
381 tex_ypos = (int)((sp->span[n].tex_width-1) * tey1);
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
382 tex_zpos = (int)z;
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
383 //printf("tex_xpos:%d tex_ypos:%d\n",tex_xpos,tex_ypos);
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
384 //printf("image->h:%d tex_x:%f\n",(int)sp->span[n].tex_height,tex1);
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
385 rgb = get_rgb(tex_xpos,tex_ypos);
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
386 viewer->write_pixel(x,y,zpos,rgb);
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
387 }else {
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
388 //printf("end != 1\n");
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
389 for(int j = 0; j < end; j++) {
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
390 tex_x = tex1*(end-1-j)/(end-1) + tex2*j/(end-1);
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
391 tex_y = tey1*(end-1-j)/(end-1) + tey2*j/(end-1);
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
392 tex_z = z*(end-1-j)/(end-1) + zpos*j/(end-1);
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
393 if(tex_x > 1) tex_x = 1;
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
394 if(tex_y > 1) tex_y = 1;
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
395 tex_xpos = (int)((sp->span[n].tex_height-1) * tex_x);
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
396 tex_ypos = (int)((sp->span[n].tex_width-1) * tex_y);
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
397 //printf("tex_xpos:%d tex_ypos:%d\n",tex_xpos,tex_ypos);
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
398 //printf("z:%f zpos:%f tex_z:%f\n",z,zpos,tex_z);
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
399 //printf("tex_x:%f tex_y:%f\n",tex_x,tex_y);
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
400 rgb = get_rgb(tex_xpos,tex_ypos);
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
401 viewer->write_pixel(j+x,y,tex_z,rgb);
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
402 }
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
403 }
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
404 }
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
405 }
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
406
35a6cf176c38 *** empty log message ***
chiaki
parents: 53
diff changeset
407
53
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
408 /*
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
409 void Polygon::create_scene_graph_pack()
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
410 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
411 //SceneGraphPack *sgp = new SceneGraphPack;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
412 sgp = new SceneGraphPack;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
413 int i = 0;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
414 int nnpn = -1;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
415
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
416 Polygon *t;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
417 t = this;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
418
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
419 while(t)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
420 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
421 //SceneGraphNode node;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
422 sgp->node[i].size = t->size;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
423 int d,tex;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
424 for(d=0,tex=0; d<t->size*3; d+=3,tex+=2)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
425 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
426 sgp->node[i].vertex[d] = t->data[d];
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
427 sgp->node[i].vertex[d+1] = t->data[d+1];
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
428 sgp->node[i].vertex[d+2] = t->data[d+2];
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
429 sgp->node[i].texture[tex] = t->data[d+t->size*6];
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
430 sgp->node[i].texture[tex+1] = t->data[d+t->size*6+1];
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
431 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
432
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
433 sgp->node[i].obj_pos[0] = 0;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
434 sgp->node[i].obj_pos[1] = 0;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
435 sgp->node[i].obj_pos[2] = 0;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
436 sgp->node[i].obj_pos[3] = 1;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
437 sgp->node[i].angle[0] = 0;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
438 sgp->node[i].angle[1] = 0;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
439 sgp->node[i].angle[2] = 0;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
440 sgp->node[i].angle[3] = 1;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
441
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
442 for(int tm=0; tm<16; tm++)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
443 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
444 sgp->node[i].translation[tm] = 0;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
445 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
446 sgp->node[i].id = 0;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
447 sgp->node[i].move = 0;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
448 sgp->node[i].interaction = 0;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
449 sgp->node[i].pn = nnpn;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
450
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
451 if(t->child != NULL)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
452 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
453 nnpn = i;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
454 t = t->child;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
455 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
456 else if(t->brother != NULL)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
457 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
458 nnpn = sgp->node[i].pn;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
459 t = t->brother;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
460 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
461 else
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
462 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
463 while(t)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
464 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
465 if(t->brother != NULL)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
466 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
467 t = t->brother;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
468 break;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
469 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
470 else
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
471 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
472 if(t->parent == NULL)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
473 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
474 t = NULL;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
475 break;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
476 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
477 nnpn = sgp->node[nnpn].pn;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
478 t = t->parent;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
479 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
480 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
481 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
482 //printf("sgp->node[%d].pn = %d\n", i, sgp->node[i].pn);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
483 i++;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
484 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
485 sgp->info.size = i;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
486
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
487
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
488 //for(int s=0; s<i; s++)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
489 //{
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
490 //printf("sgp.node[%d].pn = %d\n",s,sgp.node[s].pn);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
491 //}
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
492
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
493 //delete sgp;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
494 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
495 */
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
496
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
497
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
498 void Polygon::add_next()
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
499 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
500 Polygon *p;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
501 p = new Polygon;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
502
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
503 next = p;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
504 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
505
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
506
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
507 void Polygon::create_tree()
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
508 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
509 Polygon *list;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
510 Polygon *check_list;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
511 Polygon *p;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
512 Polygon *bros;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
513
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
514 check_list = this;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
515
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
516 for(list=this; list; list=list->next)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
517 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
518 if(xmlStrcmp((xmlChar *)list->parent_name, (xmlChar *)"NULL"))
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
519 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
520 p = this;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
521 while(p)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
522 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
523 if(!xmlStrcmp((xmlChar *)p->name,(xmlChar *)list->parent_name))
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
524 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
525 list->parent = p;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
526 if(p->child == NULL)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
527 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
528 p->child = list;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
529 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
530 else
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
531 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
532 bros = p->child;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
533 while(bros->brother != NULL)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
534 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
535 bros = bros->brother;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
536 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
537 bros->brother = list;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
538 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
539 break;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
540 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
541 p = p->next;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
542 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
543 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
544 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
545 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
546
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
547 /*
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
548 void Polygon::create_scene_graph_pack()
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
549 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
550 SceneGraphPack sgp;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
551 int i = 0;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
552 int nnpn = -1;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
553
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
554 Polygon *t;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
555 t = this;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
556 while(t)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
557 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
558 //t->draw();
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
559 SceneGraphNode node;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
560 node.obj_pos[0] = 0;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
561 node.obj_pos[1] = 0;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
562 node.obj_pos[2] = 0;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
563 node.obj_pos[3] = 1;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
564 for(int tm=0; tm<16; tm++)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
565 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
566 node.translation[tm] = 0;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
567 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
568 node.id = 0;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
569 node.move = 0;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
570 node.interaction = 0;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
571 for(int a=0; a<10; a++)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
572 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
573 node.op[a] = -1;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
574 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
575 node.pn = nnpn;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
576 int p = 0;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
577
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
578 if(t->child != NULL)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
579 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
580 //glPushMatrix();
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
581 //node.op[p] = PUSH;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
582 //nnpn = i;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
583 t = t->child;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
584 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
585 else if(t->brother != NULL)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
586 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
587 //glPopMatrix();
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
588 //glPushMatrix();
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
589 //node.op[p] = SHIFT;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
590 //nnpn = node.pn;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
591 t = t->brother;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
592 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
593 else
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
594 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
595 while(t)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
596 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
597 if(t->brother != NULL)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
598 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
599 //glPopMatrix();
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
600 //glPushMatrix();
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
601 //node.op[p] = SHIFT;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
602 t = t->brother;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
603 break;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
604 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
605 else
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
606 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
607 t = t->parent;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
608 if(t)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
609 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
610 //glPopMatrix();
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
611 //node.op[p] = POP;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
612 //nnpn = sgp.node[nnpn].pn;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
613 p++;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
614 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
615 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
616 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
617 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
618 sgp.node[i] = node;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
619 i++;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
620 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
621
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
622 sgp.info.size = i;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
623
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
624 for(int s=0; s<4; s++)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
625 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
626 for(int a=0; sgp.node[s].op[a]!=-1; a++)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
627 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
628 printf("sgp.node[%d].op[%d] = %d\n",s, a, sgp.node[s].op[a]);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
629 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
630 //printf("sgp.node[%d].pn = %d\n",s,sgp.node[s].pn);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
631 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
632 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
633 */
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
634
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
635
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
636
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
637 void Polygon::pickup_coordinate(char *cont)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
638 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
639 for(int n=0; n<size*3; n+=3)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
640 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
641 cont = pickup_float(cont, data+n);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
642 cont = pickup_float(cont, data+n+1);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
643 cont = pickup_float(cont, data+n+2);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
644
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
645 if (cont == NULL)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
646 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
647 cout << "Analyzing obj data failed coordinate\n";
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
648 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
649 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
650 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
651
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
652 void Polygon::pickup_normal(char *cont)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
653 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
654 for(int n=size*3;n<size*6;n+=3)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
655 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
656 cont = pickup_float(cont,data+n);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
657 cont = pickup_float(cont,data+n+1);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
658 cont = pickup_float(cont,data+n+2);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
659
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
660 if (cont == NULL)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
661 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
662 cout << "Analyzing obj data failed normal\n";
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
663 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
664 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
665 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
666
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
667 void Polygon::pickup_model(char *cont)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
668 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
669 cont = pickup_float(cont,c_xyz);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
670 cont = pickup_float(cont,c_xyz+1);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
671 cont = pickup_float(cont,c_xyz+2);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
672
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
673 if (cont == NULL)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
674 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
675 cout << "Analyzing obj data failed model\n";
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
676 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
677 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
678
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
679 void Polygon::pickup_texture(char *cont)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
680 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
681 for(int n=size*6; n<size*9; n+=3)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
682 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
683 cont = pickup_float(cont,data+n);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
684 cont = pickup_float(cont,data+n+1);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
685 data[n+2] = 1.0;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
686
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
687 if (cont == NULL)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
688 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
689 cout << "Analyzing obj data failed texture\n";
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
690 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
691 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
692 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
693
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
694 char *get_pixel(int tx, int ty, SDL_Surface *texture_image)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
695 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
696 return (char*)texture_image->pixels+(texture_image->format->BytesPerPixel*((texture_image->w)*ty+tx));
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
697 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
698
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
699 unsigned my_ntohl(unsigned u) {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
700 // rr gg bb 00
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
701 // rr
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
702 // bb gg rr
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
703 //unsigned u1 = ((u&0xff)<<24) +
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
704 // ((u&0xff00)<<8) +
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
705 // ((u&0xff0000)>>8) +
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
706 // ((u&0xff000000)>>24);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
707 unsigned u1;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
708 unsigned b = (u&0xff000000)>>24;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
709 unsigned g = (u&0xff0000)>>16;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
710 unsigned r = (u&0xff00)>>8;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
711 u1 = r + (g<<8) + (b<<16);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
712 //printf("pixel %x->%x\n",u,u1);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
713 return u1;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
714 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
715
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
716 Uint32 Polygon::get_rgb(int tx, int ty)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
717 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
718 SDL_PixelFormat *fmt;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
719 //Uint32 temp, pixel;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
720 Uint8 red, green, blue;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
721
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
722 fmt = texture_image->format;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
723
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
724 if (tx<0) tx = 0;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
725 if (texture_image->w-1< tx) tx = texture_image->w-1 ;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
726 if (ty<0) ty = 0;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
727 if (texture_image->h-1< ty) ty = texture_image->h-1 ;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
728
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
729
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
730
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
731 //SDL_LockSurface(texture_image);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
732 char *p = get_pixel(tx,ty,texture_image);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
733 #if 0
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
734 pixel = my_ntohl(*(Uint32*)p);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
735 //printf("pixel = %d\n", pixel);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
736 //printf("pixel %x bpp = %d ",p, fmt->BytesPerPixel);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
737 //SDL_UnlockSurface(texture_image);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
738
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
739 temp = pixel&fmt->Rmask;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
740 temp = temp>>fmt->Rshift;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
741 temp = temp<<fmt->Rloss;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
742 red = (Uint8)temp;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
743
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
744 temp = pixel&fmt->Gmask;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
745 temp = temp>>fmt->Gshift;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
746 temp = temp<<fmt->Gloss;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
747 green = (Uint8)temp;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
748
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
749 temp = pixel&fmt->Bmask;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
750 temp = temp>>fmt->Bshift;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
751 temp = temp<<fmt->Bloss;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
752 blue = (Uint8)temp;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
753 #endif
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
754 blue = (Uint8) p[0];
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
755 green = (Uint8) p[1];
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
756 red = (Uint8) p[2];
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
757
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
758 //printf("tx = %d ty = %d ", tx,ty);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
759 //printf("pixel color => R: %d, G: %d, B: %d\n", red, green, blue);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
760
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
761 SDL_PixelFormat *pf;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
762 pf = viewer->screen->format;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
763
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
764 //cout << SDL_MapRGB(pf, red, green, blue) << endl;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
765 return SDL_MapRGB(pf, red, green, blue);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
766 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
767
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
768 void Polygon::get_data(xmlNodePtr cur)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
769 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
770 char *cont;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
771 //char *image_name;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
772
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
773 for(;cur;cur=cur->next)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
774 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
775 if(!xmlStrcmp(cur->name,(xmlChar*)"coordinate"))
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
776 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
777 cont = (char *)xmlNodeGetContent(cur);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
778 pickup_coordinate(cont);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
779 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
780 else if(!xmlStrcmp(cur->name,(xmlChar*)"normal"))
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
781 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
782 cont = (char *)xmlNodeGetContent(cur);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
783 pickup_normal(cont);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
784 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
785 else if(!xmlStrcmp(cur->name,(xmlChar*)"model"))
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
786 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
787 cont = (char *)xmlNodeGetContent(cur);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
788 pickup_model(cont);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
789 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
790 else if(!xmlStrcmp(cur->name,(xmlChar*)"texture"))
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
791 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
792 cont = (char *)xmlNodeGetContent(cur);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
793 pickup_texture(cont);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
794 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
795 else if(!xmlStrcmp(cur->name,(xmlChar*)"image"))
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
796 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
797 char image_name[20] = "/tmp/image_XXXXXX";
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
798 int fd = mkstemp(image_name);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
799 FILE *outfile = fdopen(fd, "wb");
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
800 if(NULL == outfile)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
801 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
802 cout << "error open file\n";
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
803 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
804 cont = (char *)xmlNodeGetContent(cur);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
805 //decode(cont, image_name);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
806 decode(cont, outfile);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
807 fclose(outfile);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
808
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
809 texture_image = IMG_Load(image_name);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
810
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
811 //load_texture(image_name);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
812 if(unlink(image_name))
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
813 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
814 cout << "unlink error\n";
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
815 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
816 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
817 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
818 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
819
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
820
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
821 void Polygon::create_data(xmlNodePtr cur)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
822 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
823 size = atoi((char *)xmlGetProp(cur,(xmlChar *)"size"));
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
824 name = (char *)xmlGetProp(cur,(xmlChar *)"name");
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
825 parent_name = (char *)xmlGetProp(cur,(xmlChar *)"parent");
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
826 next = NULL;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
827
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
828 data = new float[size*3*3];
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
829
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
830 get_data(cur->children);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
831 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
832
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
833 void Polygon::set_data(char *file_name)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
834 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
835 xmlDocPtr doc;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
836 xmlNodePtr cur;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
837 Polygon *tmp;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
838
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
839 doc = xmlParseFile(file_name);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
840
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
841 cur = xmlDocGetRootElement(doc);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
842
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
843 xmlStrcmp(cur->name,(xmlChar*)"OBJECT-3D");
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
844
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
845 tmp = this;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
846
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
847 for (cur=cur->children; cur; cur=cur->next)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
848 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
849 if (!xmlStrcmp(cur->name,(xmlChar*)"surface"))
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
850 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
851 tmp->create_data(cur);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
852 if(cur->next->next)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
853 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
854 tmp->add_next();
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
855 tmp = tmp->next;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
856 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
857 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
858 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
859
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
860 create_tree();
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
861 //tree_check();
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
862 //create_scene_graph_pack();
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
863
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
864 xmlFreeDoc(doc);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
865
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
866 /*
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
867 for(int s=0; s<sgp->info.size; s++)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
868 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
869 printf("sgp->node[%d].pn = %d\n",s,sgp->node[s].pn);
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
870 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
871 */
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
872 //delete sgp;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
873 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
874
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
875 void Polygon::delete_data()
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
876 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
877 Polygon *n,*m;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
878
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
879 n = this;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
880 delete [] n->data;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
881
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
882 if(next)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
883 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
884 for(n = this->next; n; n=m)
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
885 {
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
886 m = n->next;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
887 delete [] n->data;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
888 delete n;
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
889 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
890 }
0c8ae614d421 Initial revision
chiaki
parents:
diff changeset
891 }