Mercurial > hg > Game > Cerium
annotate Renderer/Test/viewer.cc @ 795:abbf28a8ca42 draft
add xmlfile
author | game@henri.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Wed, 05 May 2010 16:33:41 +0900 |
parents | 66497087393d |
children | d98371202f1d |
rev | line source |
---|---|
589 | 1 #include <math.h> |
2 #include <stdlib.h> | |
3 #include "SceneGraphRoot.h" | |
4 #include "MainLoop.h" | |
5 #include "viewer.h" | |
6 | |
7 | |
8 // prototype | |
795 | 9 static void object_move_rotation(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h); |
10 static void object_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, SceneGraphPtr tree); | |
11 static void object_collision_idle(SceneGraphPtr, void *sgroot_, int w, int h, SceneGraphPtr tree); | |
12 static void object_move_translation(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h); | |
589 | 13 |
14 | |
793 | 15 char *light_sysswitch = NULL; |
16 int light_num = 4; | |
17 | |
18 void LightSysSwitch(Viewer *sgroot) { | |
19 if (strcmp(light_sysswitch,"on") == 0) { | |
20 sgroot->OnLightSysSwitch(); | |
21 } else if (strcmp(light_sysswitch,"off") == 0) { | |
22 sgroot->OffLightSysSwitch(); | |
23 } | |
24 } | |
25 | |
589 | 26 |
795 | 27 |
28 | |
589 | 29 static void |
795 | 30 object_move_rotation(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) |
589 | 31 { |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
589
diff
changeset
|
32 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_; |
589 | 33 Pad *pad = sgroot->getController(); |
795 | 34 if (pad->circle.isPush()) { |
35 node->set_move_collision(object_move_translation, object_collision); | |
36 } | |
37 if (pad->left.isHold()) { | |
38 node->angle[1] += 10; | |
39 } else if (pad->right.isHold()) { | |
40 node->angle[1] -= 10; | |
41 } | |
42 if (pad->up.isHold()) { | |
43 node->angle[0] += 10; | |
44 } else if (pad->down.isHold()) { | |
45 node->angle[0] -= 10; | |
46 } | |
589 | 47 |
48 | |
49 } | |
50 | |
51 static void | |
795 | 52 object_move_translation(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) |
589 | 53 { |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
589
diff
changeset
|
54 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_; |
589 | 55 Pad *pad = sgroot->getController(); |
56 | |
57 if (pad->circle.isPush()) { | |
795 | 58 node->set_move_collision(object_move_rotation, object_collision); |
589 | 59 } |
60 | |
795 | 61 if (pad->left.isHold()) { |
62 node->xyz[0] -= 10; | |
63 } else if (pad->right.isHold()) { | |
64 node->xyz[0] += 10; | |
65 } | |
66 if (pad->up.isHold()) { | |
67 node->xyz[1] -= 10; | |
68 } else if (pad->down.isHold()) { | |
69 node->xyz[1] += 10; | |
70 } | |
589 | 71 |
795 | 72 |
589 | 73 } |
74 | |
75 | |
76 static void | |
795 | 77 object_collision_idle(SceneGraphPtr, void *sgroot_, int w, int h, SceneGraphPtr tree) |
589 | 78 { |
79 } | |
80 | |
81 static void | |
795 | 82 object_collision(SceneGraphPtr node, void *sgroot_, int screen_w, |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
589
diff
changeset
|
83 int screen_h, SceneGraphPtr tree) |
589 | 84 { |
795 | 85 // if (node->xyz[1] > screen_h - object_radius) { |
86 // node->xyz[1] = screen_h - object_radius; | |
589 | 87 |
795 | 88 // vy *= e; |
89 // if (vy > -g && vy < 0) { | |
90 // vy = 0.0; | |
91 // node->set_move_collision(object_move_idle, object_collision_idle); | |
92 // } | |
93 // } | |
589 | 94 } |
95 | |
96 char *xmlfile; | |
97 #define MAX_ROOT 100 | |
98 char *parts[MAX_ROOT ]; | |
99 int parts_cnt; | |
100 | |
101 MainLoopPtr | |
102 viewer::init(Viewer *sgroot, int screen_w, int screen_h) | |
103 { | |
793 | 104 |
105 LightSysSwitch(sgroot); | |
106 | |
795 | 107 SceneGraphPtr object; |
589 | 108 |
793 | 109 for (int i = 0; i < light_num; i++) { |
110 SceneGraphPtr light = sgroot->getLight(i); | |
111 sgroot->OnLightSwitch(i); | |
112 light->xyz[0] = screen_w / 2; | |
113 light->xyz[1] = screen_h / 2; | |
114 light->xyz[2] = -100; | |
115 } | |
116 | |
795 | 117 |
589 | 118 // 固定した値で srandom すると、毎回同じ、random() 列が生成される |
119 // random な値が欲しいなら、man random に方法が書いてあります。 | |
120 srandom(100); | |
121 | |
122 sgroot->createFromXMLfile(xmlfile); | |
123 | |
795 | 124 object = sgroot->createSceneGraph(); |
125 object->set_move_collision(object_move_rotation, object_collision); | |
589 | 126 |
795 | 127 object->xyz[0] = screen_w/2; |
128 object->xyz[1] = screen_h/2;; | |
129 object->xyz[2] = 30.0f; | |
589 | 130 |
131 for(int i=0;i<parts_cnt; i++) { | |
795 | 132 object->addChild(sgroot->createSceneGraph(parts[i])); |
589 | 133 } |
795 | 134 sgroot->setSceneData(object); |
589 | 135 |
136 return sgroot; | |
137 } | |
138 | |
139 extern Application * | |
140 application() { | |
141 return new viewer(); | |
142 } | |
143 | |
144 const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n"; | |
145 | |
146 extern int init(TaskManager *manager, int argc, char *argv[]); | |
147 extern void task_initialize(); | |
148 static void TMend(TaskManager *manager); | |
149 | |
150 int | |
151 TMmain(TaskManager *manager, int argc, char *argv[]) | |
152 { | |
153 task_initialize(); | |
154 manager->set_TMend(TMend); | |
155 | |
156 for(int i=0;i<argc;i++) { | |
157 if (strcmp(argv[i],"-sg") == 0 && i+1<=argc) { | |
158 xmlfile = argv[i+1]; | |
159 } else if (strcmp(argv[i],"-name") == 0 && i+1<=argc) { | |
160 parts[parts_cnt++] = argv[i+1]; | |
793 | 161 } else if (strcmp(argv[i],"-lightsys") == 0 && i+1<=argc) { |
162 light_sysswitch = argv[i+1]; | |
163 } else if (strcmp(argv[i],"-lightnum") == 0 && i+1<=argc) { | |
164 light_num = atoi(argv[i+1]); | |
165 } | |
589 | 166 } |
167 return init(manager, argc, argv); | |
168 | |
169 } | |
170 | |
171 void | |
172 TMend(TaskManager *manager) | |
173 { | |
174 printf("test_nogl end\n"); | |
175 } | |
176 | |
177 /* end */ | |
178 |