annotate TaskManager/Test/test_render/polygon.cpp @ 132:e7c80537b6aa

add XML
author gongo@charles.cr.ie.u-ryukyu.ac.jp
date Tue, 25 Nov 2008 18:19:53 +0900
parents 8a33f4859ed8
children 6cf991f28c6c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
1 #include <iostream>
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
2 #include <SDL.h>
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
3 #include <SDL_opengl.h>
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
4 #include <SDL_image.h>
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
5 #include <libxml/parser.h>
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
6 #include "polygon.h"
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
7 #include "xml.h"
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
8 #include "texture.h"
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
9 #include "sys.h"
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
10 #include "triangle.h"
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
11 #include "vertex.h"
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
12 #include "Span.h"
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
13 #include "SpanC.h"
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
14 #include "scene_graph_pack.h"
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
15 #include "error.h"
120
a52e193f9a42 fix Load Texture
gongo@gendarme.local
parents: 109
diff changeset
16 #include "viewer_types.h"
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
17 using namespace std;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
18
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
19 //extern int decode(char *cont, char *file_name);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
20 extern int decode(char *cont, FILE *outfile);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
21
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
22
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
23 SDL_Surface* Polygon::texture_image;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
24
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
25 Polygon::Polygon()
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
26 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
27 xyz[0] = 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
28 xyz[1] = 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
29 xyz[2] = 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
30 xyz[3] = 1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
31 c_xyz[0] = 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
32 c_xyz[1] = 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
33 c_xyz[2] = 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
34 c_xyz[3] = 1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
35 angle[0] = 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
36 angle[1] = 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
37 angle[2] = 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
38 angle[3] = 1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
39 next = NULL;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
40 parent = NULL;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
41 brother = NULL;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
42 children = NULL;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
43 lastChild = NULL;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
44 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
45
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
46
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
47
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
48 void Polygon::tree_check()
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
49 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
50 Polygon *t;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
51 t = this;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
52
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
53 while(t)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
54 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
55 cout << "my_name : " << t->name << endl;
123
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
56 if(t->children != NULL)
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
57 {
123
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
58 cout << "--move children : " << t->children->name << endl;
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
59 t = t->children;
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
60 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
61 else if(t->brother != NULL)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
62 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
63 cout << "--move brother : " << t->brother->name << endl;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
64 t = t->brother;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
65 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
66 else
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
67 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
68 while(t)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
69 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
70 if(t->brother != NULL)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
71 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
72 cout << "--move brother : " << t->brother->name << endl;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
73 t = t->brother;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
74 break;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
75 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
76 else
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
77 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
78 if(t->parent)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
79 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
80 cout << "--move parent : " << t->parent->name << endl;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
81 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
82 t = t->parent;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
83 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
84 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
85 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
86 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
87 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
88
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
89 void Polygon::print_member()
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
90 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
91 //int n;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
92
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
93 cout << "size = " << size << endl;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
94 cout << "name = " << name << endl;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
95 cout << "parent_name = " << parent_name << endl;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
96 /*
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
97 for(n=0; n<size*3; n+=3)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
98 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
99 cout<<"coordinate = "<<data[n]<<" "<<data[n+1]<<" "<< data[n+2]<<endl;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
100 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
101 */
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
102 /*
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
103 for(n=size*3; n<size*6; n+=3)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
104 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
105 cout<<"narmal = "<<data[n]<<" "<<data[n+1]<<" "<<data[n+2]<<endl;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
106 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
107 */
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
108 cout<<"c_xyz = "<<c_xyz[0]<<" "<<c_xyz[1]<<" "<<c_xyz[2]<<endl;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
109 /*
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
110 for(n=size*6; n<size*9; n+=3)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
111 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
112 cout<<"texture = "<<data[n]<<" "<<data[n+1]<<" "<<data[n+2]<<endl;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
113 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
114 */
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
115 /*
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
116 for(n=0; n<size*3; n+=3)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
117 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
118 cout<<"coordinate = "<<data[n]<<" "<<data[n+1]<<" "<<data[n+2]<<endl;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
119 cout<<"normal = "<<data[n+size*3]<<" "<<data[n+size*3+1]<<" "<<data[n+size*3+2]<<endl;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
120 cout<<"texture = "<<data[n+size*6]<<" "<<1-data[n+size*6+1]<<endl;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
121 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
122 */
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
123 //cout << "image_name = " << image_name << endl;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
124 if(parent != NULL)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
125 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
126 cout << "parent->name = " << parent->name << endl;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
127 }
123
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
128 if(children != NULL)
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
129 {
123
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
130 cout << "children->name = " << children->name << endl;
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
131 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
132 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
133
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
134 void Polygon::draw(SceneGraphPack *sgp)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
135 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
136 float xyz1[4],xyz2[4],xyz3[4];
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
137
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
138 /***SceneGraphUpdate***/
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
139 //sgp_update();
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
140 for (int i = 0; i < sgp->info.size; i++) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
141 SceneGraphNode node = sgp->node[i];
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
142
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
143 /***draw***/
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
144 int n,nt;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
145 for(n=0,nt=0; n<node.size*3; n+=9,nt+=6) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
146 xyz1[0] = node.vertex[n];
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
147 xyz1[1] = node.vertex[n+1];
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
148 xyz1[2] = node.vertex[n+2]*-1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
149 xyz1[3] = 1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
150 xyz2[0] = node.vertex[n+3];
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
151 xyz2[1] = node.vertex[n+3+1];
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
152 xyz2[2] = node.vertex[n+3+2]*-1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
153 xyz2[3] = 1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
154 xyz3[0] = node.vertex[n+6];
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
155 xyz3[1] = node.vertex[n+6+1];
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
156 xyz3[2] = node.vertex[n+6+2]*-1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
157 xyz3[3] = 1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
158
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
159 rotate(xyz1, node.translation);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
160 rotate(xyz2, node.translation);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
161 rotate(xyz3, node.translation);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
162
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
163 Vertex *ver1 = new Vertex(xyz1[0],xyz1[1],xyz1[2],node.texture[nt],node.texture[nt+1]);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
164 Vertex *ver2 = new Vertex(xyz2[0],xyz2[1],xyz2[2],node.texture[nt+2],node.texture[nt+2+1]);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
165 Vertex *ver3 = new Vertex(xyz3[0],xyz3[1],xyz3[2],node.texture[nt+4],node.texture[nt+4+1]);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
166
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
167 Triangle *tri = new Triangle(ver1,ver2,ver3);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
168 Span_c *span = new Span_c();
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
169 span->viewer = viewer;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
170 span->p = this;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
171 span->create_span(tri,texture_image);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
172 delete ver1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
173 delete ver2;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
174 delete ver3;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
175 delete tri;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
176 delete span;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
177 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
178 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
179 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
180
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
181
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
182 void Polygon::draw(PolygonPack *pp)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
183 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
184 for(int n=0; n<pp->info.size; n++)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
185 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
186 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);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
187 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);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
188 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);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
189
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
190 Triangle *tri = new Triangle(ver1,ver2,ver3);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
191 Span_c *span = new Span_c();
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
192 span->viewer = viewer;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
193 span->p = this;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
194 span->create_span(tri,texture_image);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
195 delete ver1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
196 delete ver2;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
197 delete ver3;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
198 delete tri;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
199 delete span;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
200 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
201 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
202
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
203 void Polygon::draw(SpanPack *sp)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
204 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
205 Span *span;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
206
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
207 for (int n = 0; n < sp->info.size; n++) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
208 span = &sp->span[n];
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
209
123
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
210 //int x = span->x;
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
211 //int y = span->y;
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
212 float z = span->start_z;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
213 int end = span->length_x;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
214 float zpos = span->end_z;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
215 float tex1 = span->tex_x1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
216 float tex2 = span->tex_x2;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
217 float tey1 = span->tex_y1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
218 float tey2 = span->tex_y2;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
219 Uint32 rgb;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
220 int tex_xpos;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
221 int tex_ypos;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
222 int tex_zpos;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
223 float tex_x, tex_y, tex_z;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
224
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
225 if (end == 1) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
226 tex_xpos = (int)((span->tex_height-1) * tex1);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
227 tex_ypos = (int)((span->tex_width-1) * tey1);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
228 tex_zpos = (int)z;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
229 rgb = get_rgb(tex_xpos, tex_ypos);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
230 //viewer->write_pixel(x, y, zpos, rgb);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
231 } else {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
232 for (int j = 0; j < end; j++) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
233 tex_x = tex1*(end-1-j)/(end-1) + tex2*j/(end-1);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
234 tex_y = tey1*(end-1-j)/(end-1) + tey2*j/(end-1);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
235 tex_z = z*(end-1-j)/(end-1) + zpos*j/(end-1);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
236 if (tex_x > 1) tex_x = 1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
237 if (tex_y > 1) tex_y = 1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
238 tex_xpos = (int)((span->tex_height-1) * tex_x);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
239 tex_ypos = (int)((span->tex_width-1) * tex_y);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
240 rgb = get_rgb(tex_xpos,tex_ypos);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
241 //viewer->write_pixel(j + x, y, tex_z, rgb);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
242 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
243 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
244 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
245 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
246
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
247 void Polygon::add_next()
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
248 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
249 Polygon *p;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
250 p = new Polygon;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
251
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
252 next = p;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
253 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
254
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
255
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
256 void Polygon::create_tree()
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
257 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
258 Polygon *list;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
259 Polygon *check_list;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
260 Polygon *p;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
261 Polygon *bros;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
262
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
263 check_list = this;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
264
123
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
265 for (list=this; list; list=list->next) {
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
266 if (xmlStrcmp((xmlChar *)list->parent_name, (xmlChar *)"NULL")) {
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
267 p = this;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
268
123
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
269 while (p) {
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
270 if (!xmlStrcmp((xmlChar *)p->name,(xmlChar *)list->parent_name))
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
271 {
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
272 list->parent = p;
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
273 if(p->children == NULL)
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
274 {
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
275 p->children = list;
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
276 }
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
277 else
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
278 {
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
279 bros = p->children;
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
280 while(bros->brother != NULL)
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
281 {
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
282 bros = bros->brother;
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
283 }
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
284 bros->brother = list;
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
285 }
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
286 break;
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
287 }
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
288 p = p->next;
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
289 }
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
290 }
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
291 }
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
292 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
293
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
294 void Polygon::pickup_coordinate(char *cont)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
295 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
296 for(int n=0; n<size*3; n+=3)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
297 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
298 cont = pickup_float(cont, data+n);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
299 cont = pickup_float(cont, data+n+1);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
300 cont = pickup_float(cont, data+n+2);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
301
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
302 if (cont == NULL)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
303 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
304 cout << "Analyzing obj data failed coordinate\n";
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
305 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
306 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
307 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
308
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
309 void Polygon::pickup_normal(char *cont)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
310 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
311 for(int n=size*3;n<size*6;n+=3)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
312 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
313 cont = pickup_float(cont,data+n);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
314 cont = pickup_float(cont,data+n+1);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
315 cont = pickup_float(cont,data+n+2);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
316
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
317 if (cont == NULL)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
318 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
319 cout << "Analyzing obj data failed normal\n";
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
320 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
321 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
322 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
323
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
324 void Polygon::pickup_model(char *cont)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
325 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
326 cont = pickup_float(cont,c_xyz);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
327 cont = pickup_float(cont,c_xyz+1);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
328 cont = pickup_float(cont,c_xyz+2);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
329
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
330 if (cont == NULL)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
331 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
332 cout << "Analyzing obj data failed model\n";
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
333 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
334 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
335
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
336 void Polygon::pickup_texture(char *cont)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
337 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
338 for(int n=size*6; n<size*9; n+=3)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
339 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
340 cont = pickup_float(cont,data+n);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
341 cont = pickup_float(cont,data+n+1);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
342 data[n+2] = 1.0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
343
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
344 if (cont == NULL)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
345 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
346 cout << "Analyzing obj data failed texture\n";
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
347 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
348 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
349 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
350
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
351 char *get_pixel(int tx, int ty, SDL_Surface *texture_image)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
352 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
353 return (char*)texture_image->pixels+(texture_image->format->BytesPerPixel*((texture_image->w)*ty+tx));
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
354 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
355
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
356 unsigned my_ntohl(unsigned u) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
357 // rr gg bb 00
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
358 // rr
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
359 // bb gg rr
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
360 //unsigned u1 = ((u&0xff)<<24) +
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
361 // ((u&0xff00)<<8) +
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
362 // ((u&0xff0000)>>8) +
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
363 // ((u&0xff000000)>>24);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
364 unsigned u1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
365 unsigned b = (u&0xff000000)>>24;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
366 unsigned g = (u&0xff0000)>>16;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
367 unsigned r = (u&0xff00)>>8;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
368 u1 = r + (g<<8) + (b<<16);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
369 //printf("pixel %x->%x\n",u,u1);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
370 return u1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
371 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
372
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
373 Uint32 Polygon::get_rgb(int tx, int ty)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
374 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
375 SDL_PixelFormat *fmt;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
376 //Uint32 temp, pixel;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
377 Uint8 red, green, blue;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
378
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
379 fmt = texture_image->format;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
380
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
381 if (tx<0) tx = 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
382 if (texture_image->w-1< tx) tx = texture_image->w-1 ;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
383 if (ty<0) ty = 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
384 if (texture_image->h-1< ty) ty = texture_image->h-1 ;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
385
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
386
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
387
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
388 //SDL_LockSurface(texture_image);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
389 char *p = get_pixel(tx,ty,texture_image);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
390 #if 0
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
391 pixel = my_ntohl(*(Uint32*)p);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
392 //printf("pixel = %d\n", pixel);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
393 //printf("pixel %x bpp = %d ",p, fmt->BytesPerPixel);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
394 //SDL_UnlockSurface(texture_image);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
395
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
396 temp = pixel&fmt->Rmask;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
397 temp = temp>>fmt->Rshift;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
398 temp = temp<<fmt->Rloss;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
399 red = (Uint8)temp;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
400
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
401 temp = pixel&fmt->Gmask;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
402 temp = temp>>fmt->Gshift;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
403 temp = temp<<fmt->Gloss;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
404 green = (Uint8)temp;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
405
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
406 temp = pixel&fmt->Bmask;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
407 temp = temp>>fmt->Bshift;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
408 temp = temp<<fmt->Bloss;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
409 blue = (Uint8)temp;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
410 #endif
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
411 blue = (Uint8) p[0];
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
412 green = (Uint8) p[1];
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
413 red = (Uint8) p[2];
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
414
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
415 //printf("tx = %d ty = %d ", tx,ty);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
416 //printf("pixel color => R: %d, G: %d, B: %d\n", red, green, blue);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
417
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
418 SDL_PixelFormat *pf;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
419 //pf = viewer->screen->format;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
420
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
421 //cout << SDL_MapRGB(pf, red, green, blue) << endl;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
422 return SDL_MapRGB(pf, red, green, blue);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
423 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
424
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
425
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
426 /*
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
427 * surface nodeからポリゴンの情報を読み出す 再帰しない
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
428 */
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
429 void Polygon::get_data(xmlNodePtr cur)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
430 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
431 char *cont;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
432 //char *image_name;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
433
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
434 for(;cur;cur=cur->next)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
435 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
436 if(!xmlStrcmp(cur->name,(xmlChar*)"coordinate"))
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
437 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
438 cont = (char *)xmlNodeGetContent(cur);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
439 pickup_coordinate(cont);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
440 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
441 else if(!xmlStrcmp(cur->name,(xmlChar*)"normal"))
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
442 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
443 cont = (char *)xmlNodeGetContent(cur);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
444 pickup_normal(cont);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
445 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
446 else if(!xmlStrcmp(cur->name,(xmlChar*)"model"))
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
447 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
448 cont = (char *)xmlNodeGetContent(cur);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
449 pickup_model(cont);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
450 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
451 else if(!xmlStrcmp(cur->name,(xmlChar*)"texture"))
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
452 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
453 cont = (char *)xmlNodeGetContent(cur);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
454 pickup_texture(cont);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
455 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
456 else if(!xmlStrcmp(cur->name,(xmlChar*)"image"))
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
457 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
458 char image_name[20] = "/tmp/image_XXXXXX";
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
459 int fd = mkstemp(image_name);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
460 FILE *outfile = fdopen(fd, "wb");
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
461 if(NULL == outfile)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
462 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
463 cout << "error open file\n";
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
464 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
465 cont = (char *)xmlNodeGetContent(cur);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
466 //decode(cont, image_name);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
467 decode(cont, outfile);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
468 fclose(outfile);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
469
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
470 texture_image = IMG_Load(image_name);
123
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
471
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
472 /**
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
473 * image を 32bit(RGBA) に変換する
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
474 */
120
a52e193f9a42 fix Load Texture
gongo@gendarme.local
parents: 109
diff changeset
475 SDL_Surface *tmpImage
a52e193f9a42 fix Load Texture
gongo@gendarme.local
parents: 109
diff changeset
476 = SDL_CreateRGBSurface(SDL_HWSURFACE, texture_image->w,
a52e193f9a42 fix Load Texture
gongo@gendarme.local
parents: 109
diff changeset
477 texture_image->h, 32,
a52e193f9a42 fix Load Texture
gongo@gendarme.local
parents: 109
diff changeset
478 redMask, greenMask, blueMask, alphaMask);
a52e193f9a42 fix Load Texture
gongo@gendarme.local
parents: 109
diff changeset
479 SDL_Surface *converted;
a52e193f9a42 fix Load Texture
gongo@gendarme.local
parents: 109
diff changeset
480 converted = SDL_ConvertSurface(texture_image,
a52e193f9a42 fix Load Texture
gongo@gendarme.local
parents: 109
diff changeset
481 tmpImage->format, SDL_HWSURFACE);
a52e193f9a42 fix Load Texture
gongo@gendarme.local
parents: 109
diff changeset
482 if( converted != NULL){
a52e193f9a42 fix Load Texture
gongo@gendarme.local
parents: 109
diff changeset
483 SDL_FreeSurface(texture_image);
a52e193f9a42 fix Load Texture
gongo@gendarme.local
parents: 109
diff changeset
484 texture_image = converted;
a52e193f9a42 fix Load Texture
gongo@gendarme.local
parents: 109
diff changeset
485 }
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
486
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
487 //load_texture(image_name);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
488 if(unlink(image_name))
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
489 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
490 cout << "unlink error\n";
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
491 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
492 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
493 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
494 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
495
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
496
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
497 /*
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
498 * ノードを受け取って、そこからポリゴンを生成
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
499 * リークしてない? data上書きしちゃだめ
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
500 */
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
501 void Polygon::create_data(xmlNodePtr cur)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
502 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
503 char *p = (char *)xmlGetProp(cur,(xmlChar *)"size");
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
504 //error 出力?
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
505
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
506 #ifndef _DEBUG
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
507 if(strlen(p)>8){
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
508 __debug("Polygon size is too large.\n");
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
509 exit(1);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
510 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
511 #endif
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
512
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
513 size = atoi((char *)xmlGetProp(cur,(xmlChar *)"size"));
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
514 name = (char *)xmlGetProp(cur,(xmlChar *)"name");
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
515 parent_name = (char *)xmlGetProp(cur,(xmlChar *)"parent");
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
516 next = NULL;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
517
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
518 data = new float[size*3*3];
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
519
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
520 get_data(cur->children);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
521 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
522
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
523 /*
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
524 * xmlをオープンして、Surfaceノードからポリゴンを作る
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
525 *
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
526 */
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
527 void Polygon::set_data(char *file_name)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
528 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
529 xmlDocPtr doc;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
530 xmlNodePtr cur;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
531 Polygon *tmp;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
532
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
533 doc = xmlParseFile(file_name);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
534
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
535 cur = xmlDocGetRootElement(doc);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
536
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
537 xmlStrcmp(cur->name,(xmlChar*)"OBJECT-3D");
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
538
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
539 tmp = this;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
540
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
541 for (cur=cur->children; cur; cur=cur->next)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
542 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
543 if (!xmlStrcmp(cur->name,(xmlChar*)"surface"))
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
544 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
545 tmp->create_data(cur);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
546 if(cur->next->next)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
547 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
548 tmp->add_next();
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
549 tmp = tmp->next;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
550 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
551 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
552 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
553
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
554 create_tree();
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
555 //tree_check();
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
556 //create_scene_graph_pack();
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
557
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
558 xmlFreeDoc(doc);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
559
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
560 /*
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
561 for(int s=0; s<sgp->info.size; s++)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
562 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
563 printf("sgp->node[%d].pn = %d\n",s,sgp->node[s].pn);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
564 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
565 */
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
566 //delete sgp;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
567 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
568
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
569 void Polygon::delete_data()
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
570 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
571 Polygon *n,*m;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
572
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
573 n = this;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
574 delete [] n->data;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
575
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
576 if(next)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
577 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
578 for(n = this->next; n; n=m)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
579 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
580 m = n->next;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
581 delete [] n->data;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
582 delete n;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
583 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
584 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
585 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
586
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
587
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
588
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
589 /* construct polygon from xml. */
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
590 /*
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
591 Polygon::Polygon(char *xmlfile)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
592 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
593 Polygon();
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
594 xmlDocPtr doc;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
595 xmlNodePtr cur;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
596 Polygon *tmp;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
597
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
598 doc = xmlParseFile(file_name);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
599
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
600 cur = xmlDocGetRootElement(doc);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
601
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
602 xmlStrcmp(cur->name,(xmlChar*)"OBJECT-3D");
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
603
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
604 tmp = this;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
605
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
606 for (cur=cur->children; cur; cur=cur->next)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
607 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
608 if ( xmlStrcmp(cur->name,(xmlChar*)"surface")!=0 )
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
609 continue;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
610
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
611 if ( xmlStrcmp(cur->parent ))
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
612 tmp->create_data(cur);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
613 if(cur->next->next)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
614 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
615 tmp->add_next();
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
616 tmp = tmp->next;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
617 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
618 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
619
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
620 create_tree();
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
621 //tree_check();
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
622 //create_scene_graph_pack();
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
623
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
624 xmlFreeDoc(doc);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
625 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
626 */
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
627
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
628 /* construct polygon from xmlNode. */
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
629 Polygon::Polygon(xmlNodePtr surface)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
630 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
631 #if 1
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
632 xyz[0] = 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
633 xyz[1] = 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
634 xyz[2] = 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
635 xyz[3] = 1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
636 c_xyz[0] = 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
637 c_xyz[1] = 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
638 c_xyz[2] = 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
639 c_xyz[3] = 1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
640 angle[0] = 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
641 angle[1] = 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
642 angle[2] = 0;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
643 angle[3] = 1;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
644 next = NULL;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
645 parent = NULL;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
646 brother = NULL;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
647 children = NULL;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
648 lastChild = NULL;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
649 #else
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
650 /* これ使うにはどうすればいいの? */
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
651 this->Polygon();
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
652 #endif
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
653 size = atoi((char *)xmlGetProp(surface,(xmlChar *)"size"));
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
654 name = (char *)xmlGetProp(surface,(xmlChar *)"name");
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
655 parent_name = (char *)xmlGetProp(surface,(xmlChar *)"parent");
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
656 next = NULL;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
657
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
658 data = new float[size*3*3];
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
659
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
660 get_data(surface->children);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
661 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
662
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
663 /* XMLファイルからポリゴンを作成 */
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
664 Polygon *Polygon::createFromXMLfile(char *xmlfile)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
665 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
666 xmlDocPtr doc;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
667 xmlNodePtr cur;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
668 Polygon *root=NULL, *tmp, *parent;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
669
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
670 /* パース DOM生成 */
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
671 doc = xmlParseFile(xmlfile);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
672 cur = xmlDocGetRootElement(doc);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
673
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
674 /* ?? */
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
675 xmlStrcmp(cur->name,(xmlChar*)"OBJECT-3D");
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
676
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
677 /* XMLのノードを一つずつ解析 */
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
678 for (cur=cur->children; cur; cur=cur->next)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
679 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
680 /* 扱うのはsurfaceオンリー */
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
681 if ( xmlStrcmp(cur->name,(xmlChar*)"surface")!=0 )
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
682 continue;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
683
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
684 /* ポリゴン生成 */
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
685 tmp = new Polygon(cur);
123
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
686 if ( tmp->parent_name==NULL || 0==strcmp(tmp->parent_name, "NULL")) {
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
687 /* このsurfaceがroot */
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
688 root = tmp;
123
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
689 } else {
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
690 /* 親はこのsurfaceより前に定義されているものとする (していい?) */
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
691 // ここで parent_name を用いるのは間違っていて、
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
692 // *cur->properties->children から探すべきらしい kono
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
693 parent = root->searchPolygon(tmp->parent_name);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
694 if (parent==NULL) {
123
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
695 fprintf(stderr, "[%s] No such parent %s\n",
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
696 tmp->name, tmp->parent_name);
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
697 root->addChild(tmp);
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
698 } else {
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
699 parent->addChild(tmp);
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
700 }
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
701 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
702 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
703
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
704 xmlFreeDoc(doc);
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
705 return root;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
706 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
707
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
708 /* 子供を追加 */
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
709 Polygon *Polygon::addChild(Polygon *child)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
710 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
711 Polygon *tmp;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
712
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
713 /* childrenのリストの最後に加える */
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
714 if (this->lastChild != NULL) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
715 tmp = this->lastChild;
123
f515436feb71 delete scene_graph->child (instead use "children")
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents: 120
diff changeset
716 tmp->children = child;
109
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
717 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
718
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
719 this->lastChild = child;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
720
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
721 if (this->children == NULL) {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
722 this->children = child;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
723 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
724
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
725 return child;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
726 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
727
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
728 /* thisの子や子孫にnameのものが存在すればそいつを返す なければNULL. */
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
729 Polygon *Polygon::searchPolygon(char *name)
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
730 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
731 Polygon *tmp, *result;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
732
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
733 /* 本人か */
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
734 if( 0==strcmp(this->name, name) ) return this;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
735
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
736 /* 子供から再帰的に探す */
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
737 for( tmp=this->children; tmp; tmp=tmp->next )
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
738 {
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
739 if( (result=tmp->searchPolygon(name))!=NULL )
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
740 return result;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
741 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
742
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
743 /* 無かったら NULL. */
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
744 return NULL;
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
745 }
5c194c71eca8 Cerium cvs version
gongo@gendarme.local
parents:
diff changeset
746