Mercurial > hg > Members > kono > tree_dandy2
annotate SgoexCerium.cc @ 34:b65f6fc9c84f
position is correct now.
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 21 May 2011 20:44:24 +0900 |
parents | 9a5300cedb14 |
children | 3b92a4b17049 |
rev | line source |
---|---|
33 | 1 |
32 | 2 #include "matrix_calc.h" |
33 | 3 #include "TaskManager.h" |
4 #include "SceneGraph.h" | |
5 #include "Application.h" | |
6 | |
32 | 7 #include "SgoexCerium.h" |
8 | |
33 | 9 extern Viewer *droot; |
10 | |
32 | 11 static SceneGraphPtr root; |
12 | |
13 void | |
14 flip() | |
15 { | |
16 CameraPtr camera = droot->sgroot->getCamera(); | |
17 | |
18 droot->sgroot->flip(); | |
19 droot->sgroot->lightCalc(); | |
20 | |
21 root = droot->createSceneGraph(); | |
22 //root->xyz[0] = screen_w/2; | |
23 //root->xyz[1] = screen_h/2;; | |
24 root->xyz[0] = 0; | |
25 root->xyz[1] = 0; | |
26 root->xyz[2] = 30.0f; | |
27 | |
28 /*親の回転、座標から、子の回転、座標を算出*/ | |
29 get_matrix(root->matrix, root->angle, root->xyz, camera->matrix); | |
30 /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/ | |
31 get_matrix(root->real_matrix, root->angle, root->xyz, camera->real_matrix); | |
32 | |
33 droot->setSceneData(root); | |
34 } | |
35 | |
36 | |
37 SpriteTable sptable[DEFOBJ]; | |
38 | |
39 | |
40 void | |
41 DefSpriteEx(int number, short middlex, short middley) | |
42 { | |
43 sptable[number].mx = middlex; | |
44 sptable[number].my = middley; | |
45 } | |
46 | |
47 | |
48 void | |
49 DefSprite(int number, const char *name, float w, float h, int color, OBJECT *obj) | |
50 { | |
51 SpriteTable *m = &sptable[number]; | |
52 m->w = w; | |
53 m->h = h; | |
54 m->color = (color & 32); | |
55 m->mx = w / 2; | |
56 m->my = h / 2; | |
57 m->tex_w = power_of_two(m->w); | |
58 m->tex_h = power_of_two(m->h); | |
59 m->texture = (int *)name; | |
60 | |
61 } | |
62 | |
63 static float my_scale = 5; | |
64 | |
65 void | |
66 PutSprite(int zorder, short x, short y, int number) | |
67 { | |
68 SpriteTable *m = &sptable[number]; | |
69 char *name = (char *) m->texture; | |
70 if (!name) { | |
71 printf("PutSprite %d unknown\n",number); | |
72 return; | |
73 } | |
74 SceneGraphPtr object = droot->createSceneGraph(name); | |
75 //object->c_xyz[0] = m->mx; | |
76 //object->c_xyz[1] = m->my; | |
77 root->addChild(object); | |
78 | |
34
b65f6fc9c84f
position is correct now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
79 object->xyz[0] -= object->c_xyz[0]*my_scale; |
b65f6fc9c84f
position is correct now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
80 object->xyz[1] -= object->c_xyz[1]*my_scale; |
b65f6fc9c84f
position is correct now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
81 object->xyz[2] -= object->c_xyz[2]; |
b65f6fc9c84f
position is correct now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
82 |
b65f6fc9c84f
position is correct now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
83 object->xyz[0] += x+m->mx; |
b65f6fc9c84f
position is correct now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
84 object->xyz[1] += y+m->my; |
b65f6fc9c84f
position is correct now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
85 object->xyz[2] += zorder * 0.01; |
b65f6fc9c84f
position is correct now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
86 |
b65f6fc9c84f
position is correct now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
87 float scale[] = {my_scale,my_scale,1}; |
b65f6fc9c84f
position is correct now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
88 //float c_xyz[] = {0,0,0}; |
b65f6fc9c84f
position is correct now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
89 //scale_matrix(object->matrix, scale, c_xyz); |
32 | 90 |
91 /*親の回転、座標から、子の回転、座標を算出*/ | |
34
b65f6fc9c84f
position is correct now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
92 get_matrix_scale(object->matrix, object->angle, object->xyz, scale, root->matrix); |
32 | 93 |
94 /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/ | |
34
b65f6fc9c84f
position is correct now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
95 // get_matrix(object->real_matrix, object->angle, object->xyz, root->real_matrix); |
32 | 96 } |
97 | |
98 void | |
99 PutSpriteEx(int number, int x, int y, float scalex, float scaley, float angle) | |
100 { | |
34
b65f6fc9c84f
position is correct now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
101 if (1) { |
32 | 102 PutSprite(1, x, y, number); |
103 return; | |
104 } | |
105 | |
106 SpriteTable *m = &sptable[number]; | |
107 char *name = (char *) m->texture; | |
108 if (!name) { | |
109 printf("PutSpriteEx %d unknown\n",number); | |
110 return; | |
111 } | |
112 SceneGraphPtr object = droot->createSceneGraph(name); | |
113 root->addChild(object); | |
114 | |
115 float scale[] = {my_scale*scalex*4,my_scale*scaley*4,1}; | |
116 | |
117 /*親の回転、座標から、子の回転、座標を算出*/ | |
118 object->xyz[0] = x - object->c_xyz[0] * my_scale - m->w*my_scale; | |
119 object->xyz[1] = y - object->c_xyz[1] * my_scale - m->h*my_scale; | |
120 object->xyz[2] = number * 0.01; | |
121 //object->c_xyz[0] = m->mx; | |
122 //object->c_xyz[1] = m->my; | |
123 object->angle[3] = angle * (3.1415926*2/4096); | |
124 get_matrix(object->matrix, object->angle, object->xyz, root->matrix); | |
125 float c_xyz[] = {0,0,0}; | |
126 scale_matrix(object->matrix, scale, c_xyz); | |
127 /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/ | |
34
b65f6fc9c84f
position is correct now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
33
diff
changeset
|
128 // get_matrix(object->real_matrix, object->angle, object->xyz, root->real_matrix); |
32 | 129 } |
130 | |
131 | |
132 struct SGO_PAD pad[2]; | |
133 | |
134 | |
135 /* コントローラ状態の読み込み */ | |
136 void Pad(SDL_Joystick *joy) | |
137 { | |
138 Sint16 axis; | |
139 | |
140 SDL_JoystickUpdate(); | |
141 | |
142 if(SDL_JoystickGetButton(joy,PS2_CROSS)==SDL_PRESSED) | |
143 pad[0].k0++; | |
144 else | |
145 pad[0].k0=0; | |
146 | |
147 if(SDL_JoystickGetButton(joy,PS2_CIRCLE)==SDL_PRESSED) | |
148 pad[0].k1++; | |
149 else | |
150 pad[0].k1=0; | |
151 | |
152 if(SDL_JoystickGetButton(joy,PS2_SQUARE)==SDL_PRESSED) | |
153 pad[0].k3++; | |
154 else | |
155 pad[0].k3=0; | |
156 | |
157 if(SDL_JoystickGetButton(joy,PS2_TRIANGLE)==SDL_PRESSED) | |
158 pad[0].k4++; | |
159 else | |
160 pad[0].k4=0; | |
161 | |
162 if(SDL_JoystickGetButton(joy,PS2_L1)==SDL_PRESSED) | |
163 pad[0].l1++; | |
164 else | |
165 pad[0].l1=0; | |
166 | |
167 if(SDL_JoystickGetButton(joy,PS2_R1)==SDL_PRESSED) | |
168 pad[0].r1++; | |
169 else | |
170 pad[0].r1=0; | |
171 | |
172 if(SDL_JoystickGetButton(joy,PS2_L2)==SDL_PRESSED) | |
173 pad[0].l2++; | |
174 else | |
175 pad[0].l2=0; | |
176 | |
177 if(SDL_JoystickGetButton(joy,PS2_R2)==SDL_PRESSED) | |
178 pad[0].r2++; | |
179 else | |
180 pad[0].r2=0; | |
181 | |
182 if(SDL_JoystickGetButton(joy,PS2_START)==SDL_PRESSED) | |
183 pad[0].st++; | |
184 else | |
185 pad[0].st=0; | |
186 | |
187 if(SDL_JoystickGetButton(joy,PS2_SELECT)==SDL_PRESSED) | |
188 pad[0].se++; | |
189 else | |
190 pad[0].se=0; | |
191 | |
192 if(SDL_JoystickGetButton(joy,PS2_L3)==SDL_PRESSED) | |
193 pad[0].l3++; | |
194 else | |
195 pad[0].l3=0; | |
196 | |
197 if(SDL_JoystickGetButton(joy,PS2_R3)==SDL_PRESSED) | |
198 pad[0].r3++; | |
199 else | |
200 pad[0].r3=0; | |
201 //x | |
202 axis=SDL_JoystickGetAxis(joy,0); | |
203 if(axis>=3200){ | |
204 pad[0].left=0; | |
205 pad[0].right++; | |
206 } | |
207 else if(axis<=-3200){ | |
208 pad[0].right=0; | |
209 pad[0].left++; | |
210 } | |
211 else { | |
212 pad[0].right=0; | |
213 pad[0].left=0; | |
214 } | |
215 //y | |
216 axis=SDL_JoystickGetAxis(joy,1); | |
217 if(axis>=3200){ | |
218 pad[0].up=0; | |
219 pad[0].down++; | |
220 } | |
221 else if(axis<=-3200){ | |
222 pad[0].down=0; | |
223 pad[0].up++; | |
224 } | |
225 else { | |
226 pad[0].down=0; | |
227 pad[0].up=0; | |
228 } | |
229 | |
230 if ((pad[0].l1 != 0) && (pad[0].r1 != 0) && | |
231 (pad[0].l2 != 0) && (pad[0].r2 != 0) && | |
232 (pad[0].st != 0) && (pad[0].se != 0)) { | |
233 pad[0].quit = 1; | |
234 } else { | |
235 pad[0].quit = 0; | |
236 } | |
237 | |
238 } | |
239 | |
240 | |
241 void keybord() | |
242 { | |
243 SDL_PumpEvents(); | |
244 Uint8 *keys = SDL_GetKeyState(NULL); | |
245 | |
246 if (keys[SDLK_UP]) { | |
247 pad[0].up++; | |
248 } else { | |
249 pad[0].up = 0; | |
250 } | |
251 if (keys[SDLK_DOWN]) { | |
252 pad[0].down++; | |
253 } else { | |
254 pad[0].down = 0; | |
255 } | |
256 | |
257 if (keys[SDLK_RIGHT]) { | |
258 pad[0].right++; | |
259 } else { | |
260 pad[0].right = 0; | |
261 } | |
262 | |
263 if (keys[SDLK_LEFT]) { | |
264 pad[0].left++; | |
265 } else { | |
266 pad[0].left = 0; | |
267 } | |
268 | |
269 if (keys[SDLK_a]) { | |
270 pad[0].k0++; | |
271 } else { | |
272 pad[0].k0 = 0; | |
273 } | |
274 | |
275 if (keys[SDLK_z]) { | |
276 pad[0].k1++; | |
277 } else { | |
278 pad[0].k1 = 0; | |
279 } | |
280 | |
281 if (keys[SDLK_s]) { | |
282 pad[0].k3++; | |
283 } else { | |
284 pad[0].k3 = 0; | |
285 } | |
286 | |
287 if (keys[SDLK_x]) { | |
288 pad[0].k4++; | |
289 } else { | |
290 pad[0].k4 = 0; | |
291 } | |
292 | |
293 if (keys[SDLK_r]) { | |
294 pad[0].r2++; | |
295 } else { | |
296 pad[0].r2 = 0; | |
297 } | |
298 | |
299 if (keys[SDLK_e]) { | |
300 pad[0].r1++; | |
301 } else { | |
302 pad[0].r1 = 0; | |
303 } | |
304 | |
305 if (keys[SDLK_w]) { | |
306 pad[0].l1++; | |
307 } else { | |
308 pad[0].l1 = 0; | |
309 } | |
310 | |
311 if (keys[SDLK_q]) { | |
312 pad[0].l2++; | |
313 } else { | |
314 pad[0].l2 = 0; | |
315 } | |
316 | |
317 // START ボタンは Return が似合う気がする | |
318 //if(keys[SDLK_1]) | |
319 if (keys[SDLK_RETURN]) { | |
320 pad[0].st++; | |
321 } else { | |
322 pad[0].st = 0; | |
323 } | |
324 | |
325 if (keys[SDLK_2]) { | |
326 pad[0].se++; | |
327 } else { | |
328 pad[0].se = 0; | |
329 } | |
330 | |
331 if (keys[SDLK_ESCAPE]) { | |
332 SDL_Quit(); | |
333 exit(1); | |
334 //pad[0].st = 1; | |
335 //pad[0].se = 1; | |
336 } | |
337 | |
338 if (keys[SDLK_0]) { | |
339 pad[0].quit = 1; | |
340 } else { | |
341 pad[0].quit = 0; | |
342 } | |
343 } | |
344 | |
345 | |
346 /* end */ |