annotate TaskManager/Test/test_render/universe.cpp @ 213:8ac35507094d draft

add SceneGraph "3D Super-Dandy"
author gongo@localhost.localdomain
date Sun, 01 Feb 2009 20:45:07 +0900
parents 1fd0107ebb25
children 0351818cf0fe
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
1fd0107ebb25 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
8ac35507094d 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
8ac35507094d 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
199
1fd0107ebb25 add SceneGraph(ieshoot), add SystemSceneGraph(Camera)
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 198
diff changeset
34 earthmove(SceneGraphPtr node, int screen_w, int screen_h)
157
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
35 {
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
36 node->angle[1] += 1.0f;
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
37 if (node->angle[1] > 360.0f) {
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
38 node->angle[1] = 0.0f;
213
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 199
diff changeset
39 #if 0
195
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
40 if (moonrem) {
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
41 SceneGraphPtr moon = sgroot->createSceneGraph(Moon);
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
42 moon->set_move_collision(moon_move, moon_collision);
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
43 node->addChild(moon);
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
44 moonrem = 0;
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
45 }
213
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 199
diff changeset
46 #endif
157
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
47 }
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
48
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
49 node->xyz[0] += node->stack_xyz[0];
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
50 if ((int)node->xyz[0] > screen_w || (int)node->xyz[0] < 0) {
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
51 node->stack_xyz[0] = -node->stack_xyz[0];
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
52 }
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
53
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
54 node->xyz[1] += node->stack_xyz[1];
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
55 if ((int)node->xyz[1] > screen_h || (int)node->xyz[1] < 0) {
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
56 node->stack_xyz[1] = -node->stack_xyz[1];
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
57 }
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
58 }
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
59
195
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
60 void
198
b832e6cff83e rename snake_bg to panel
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 195
diff changeset
61 universe_init(void)
157
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
62 {
195
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
63 SceneGraphPtr earth;
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
64 SceneGraphPtr moon;
157
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
65
195
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
66 sgroot->createFromXMLfile("xml_file/universe.xml");
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 // SGList.h にある SceneGraph ID から SceneGraph を生成する
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
69 earth = sgroot->createSceneGraph(Earth);
157
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
70
195
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
71 // SceneGraph の move と collision を設定
199
1fd0107ebb25 add SceneGraph(ieshoot), add SystemSceneGraph(Camera)
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 198
diff changeset
72 earth->set_move_collision(earthmove, earth_collision);
195
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
73 earth->stack_xyz[0] = 3.0f;
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
74 earth->stack_xyz[1] = 3.0f;
213
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 199
diff changeset
75
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 199
diff changeset
76 for (int i = 0; i < 1; i++) {
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 199
diff changeset
77 moon = sgroot->createSceneGraph(Moon);
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 199
diff changeset
78 moon->set_move_collision(moon_move, moon_collision);
157
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
79
213
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 199
diff changeset
80 moon->xyz[1] = 30*i;
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 199
diff changeset
81 moon->xyz[0] = 30*i;
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 199
diff changeset
82 moon->angle[0] = 30*i;
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 199
diff changeset
83
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 199
diff changeset
84 // SceneGraph 同士の親子関係を設定 (今回は 親 earth、子 moon)
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 199
diff changeset
85 earth->addChild(moon);
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 199
diff changeset
86 }
8ac35507094d add SceneGraph "3D Super-Dandy"
gongo@localhost.localdomain
parents: 199
diff changeset
87
195
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
88
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
89 // SceneGraphRoot に、使用する SceneGraph を設定する
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
90 // このとき、ユーザーが記述した SceneGraph の root を渡す。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 165
diff changeset
91 sgroot->setSceneData(earth);
157
gongo@henri.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
92 }