annotate TaskManager/Test/test_render/universe.cpp @ 224:ebfb9e389716

SceneGraph.cpp xmlcreate
author tkaito@nw0534.st.ie.u-ryukyu.ac.jp
date Tue, 10 Feb 2009 20:45:51 +0900
parents 5ffee529dc59
children c254a2bd1b34
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;
213
159519cdca1f add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 199
diff changeset
23 #if 0
195
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
24 if (node->angle[0] > 360.0f) {
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
25 node->remove();
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
26 //node->angle[0] = 0.0f;
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
27 moonrem = 1;
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
28 }
213
159519cdca1f add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 199
diff changeset
29 #endif
195
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
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
32
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
33 static void
222
gongo@localhost.localdomain
parents: 213
diff changeset
34 earth_move(SceneGraphPtr node, int screen_w, int screen_h)
157
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
35 {
222
gongo@localhost.localdomain
parents: 213
diff changeset
36 return;
gongo@localhost.localdomain
parents: 213
diff changeset
37
157
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
38 node->angle[1] += 1.0f;
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
39 if (node->angle[1] > 360.0f) {
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
40 node->angle[1] = 0.0f;
213
159519cdca1f add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 199
diff changeset
41 #if 0
195
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
42 if (moonrem) {
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
43 SceneGraphPtr moon = sgroot->createSceneGraph(Moon);
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
44 moon->set_move_collision(moon_move, moon_collision);
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
45 node->addChild(moon);
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
46 moonrem = 0;
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
47 }
213
159519cdca1f add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 199
diff changeset
48 #endif
157
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
49 }
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
50
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
51 node->xyz[0] += node->stack_xyz[0];
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
52 if ((int)node->xyz[0] > screen_w || (int)node->xyz[0] < 0) {
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
53 node->stack_xyz[0] = -node->stack_xyz[0];
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
54 }
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
55
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
56 node->xyz[1] += node->stack_xyz[1];
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
57 if ((int)node->xyz[1] > screen_h || (int)node->xyz[1] < 0) {
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
58 node->stack_xyz[1] = -node->stack_xyz[1];
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
59 }
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
60 }
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 void
198
57921c8d21c5 rename snake_bg to panel
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 195
diff changeset
63 universe_init(void)
157
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
64 {
195
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
65 SceneGraphPtr earth;
222
gongo@localhost.localdomain
parents: 213
diff changeset
66 //SceneGraphPtr 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 sgroot->createFromXMLfile("xml_file/universe.xml");
157
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
69
195
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
70 // SGList.h にある SceneGraph ID から SceneGraph を生成する
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
71 earth = sgroot->createSceneGraph(Earth);
157
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
72
195
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
73 // SceneGraph の move と collision を設定
222
gongo@localhost.localdomain
parents: 213
diff changeset
74 earth->set_move_collision(earth_move, earth_collision);
gongo@localhost.localdomain
parents: 213
diff changeset
75 earth->xyz[0] = 960.0f;
gongo@localhost.localdomain
parents: 213
diff changeset
76 earth->xyz[1] = 540.0f;
195
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
77 earth->stack_xyz[0] = 3.0f;
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
78 earth->stack_xyz[1] = 3.0f;
213
159519cdca1f add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 199
diff changeset
79
222
gongo@localhost.localdomain
parents: 213
diff changeset
80 //moon = sgroot->createSceneGraph(Moon);
gongo@localhost.localdomain
parents: 213
diff changeset
81 //moon->set_move_collision(moon_move, moon_collision);
gongo@localhost.localdomain
parents: 213
diff changeset
82
gongo@localhost.localdomain
parents: 213
diff changeset
83 // SceneGraph 同士の親子関係を設定 (今回は 親 earth、子 moon)
gongo@localhost.localdomain
parents: 213
diff changeset
84 //earth->addChild(moon);
195
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
85
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
86 // SceneGraphRoot に、使用する SceneGraph を設定する
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
87 // このとき、ユーザーが記述した SceneGraph の root を渡す。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
88 sgroot->setSceneData(earth);
157
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
89 }