annotate TaskManager/Test/simple_render/polygon.cpp @ 106:c9efdb17e8d2

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