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