annotate TaskManager/Test/test_render/universe.cpp @ 205:efb1df3176f4

fix
author gongo@localhost.localdomain
date Tue, 27 Jan 2009 18:21:12 +0900
parents eb20274baa7c
children 159519cdca1f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
157
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
1 #include <stdlib.h>
195
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
2 #include "SceneGraphRoot.h"
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
3 #include "SGList.h"
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
4
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
5 int moonrem = 0;
157
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
6
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
7 static void
199
eb20274baa7c add SceneGraph(ieshoot), add SystemSceneGraph(Camera)
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 198
diff changeset
8 earth_collision(SceneGraphPtr node, int screen_w, int screen_h,
157
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
9 SceneGraphPtr tree)
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
10 {
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
11 }
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
12
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
13 static void
195
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
14 moon_collision(SceneGraphPtr node, int screen_w, int screen_h,
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
15 SceneGraphPtr tree)
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
16 {
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
17 }
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
18
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
19 static void
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
20 moon_move(SceneGraphPtr node, int screen_w, int screen_h)
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
21 {
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
22 node->angle[0] += 3.0f;
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
23 if (node->angle[0] > 360.0f) {
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
24 node->remove();
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
25 //node->angle[0] = 0.0f;
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
26 moonrem = 1;
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
27 }
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
28 }
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
29
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
30
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
31 static void
199
eb20274baa7c add SceneGraph(ieshoot), add SystemSceneGraph(Camera)
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 198
diff changeset
32 earthmove(SceneGraphPtr node, int screen_w, int screen_h)
157
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
33 {
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
34 node->angle[1] += 1.0f;
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
35 if (node->angle[1] > 360.0f) {
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
36 node->angle[1] = 0.0f;
195
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
37 if (moonrem) {
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
38 SceneGraphPtr moon = sgroot->createSceneGraph(Moon);
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
39 moon->set_move_collision(moon_move, moon_collision);
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
40 node->addChild(moon);
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
41 moonrem = 0;
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
42 }
157
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
43 }
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
44
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
45 node->xyz[0] += node->stack_xyz[0];
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
46 if ((int)node->xyz[0] > screen_w || (int)node->xyz[0] < 0) {
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
47 node->stack_xyz[0] = -node->stack_xyz[0];
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
48 }
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
49
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
50 node->xyz[1] += node->stack_xyz[1];
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
51 if ((int)node->xyz[1] > screen_h || (int)node->xyz[1] < 0) {
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
52 node->stack_xyz[1] = -node->stack_xyz[1];
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
53 }
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
54 }
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
55
195
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
56 void
198
57921c8d21c5 rename snake_bg to panel
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 195
diff changeset
57 universe_init(void)
157
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
58 {
195
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
59 SceneGraphPtr earth;
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
60 SceneGraphPtr moon;
157
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
61
195
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
62 sgroot->createFromXMLfile("xml_file/universe.xml");
157
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
63
195
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
64 // SGList.h にある SceneGraph ID から SceneGraph を生成する
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
65 earth = sgroot->createSceneGraph(Earth);
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
66 moon = sgroot->createSceneGraph(Moon);
157
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
67
195
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
68 // SceneGraph の move と collision を設定
199
eb20274baa7c add SceneGraph(ieshoot), add SystemSceneGraph(Camera)
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 198
diff changeset
69 earth->set_move_collision(earthmove, earth_collision);
195
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
70 earth->stack_xyz[0] = 3.0f;
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
71 earth->stack_xyz[1] = 3.0f;
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
72 moon->set_move_collision(moon_move, moon_collision);
157
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
73
195
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
74 // SceneGraph 同士の親子関係を設定 (今回は 親 earth、子 moon)
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
75 earth->addChild(moon);
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
76
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
77 // SceneGraphRoot に、使用する SceneGraph を設定する
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
78 // このとき、ユーザーが記述した SceneGraph の root を渡す。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
79 sgroot->setSceneData(earth);
157
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
80 }