0
|
1 #include <math.h>
|
|
2 #include <stdlib.h>
|
|
3 #include "SceneGraphRoot.h"
|
|
4 #include "MainLoop.h"
|
|
5 #include "viewer.h"
|
|
6
|
|
7
|
|
8 // prototype
|
|
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);
|
1
|
11 //static void object_collision_idle(SceneGraphPtr, void *sgroot_, int w, int h, SceneGraphPtr tree);
|
0
|
12 static void object_move_translation(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h);
|
|
13
|
|
14
|
|
15 char *light_sysswitch = "off";
|
|
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
|
|
26
|
|
27
|
|
28
|
|
29 static void
|
|
30 object_move_rotation(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h)
|
|
31 {
|
|
32 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
|
|
33 Pad *pad = sgroot->getController();
|
|
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 }
|
|
47
|
|
48
|
|
49 }
|
|
50
|
|
51 static void
|
|
52 object_move_translation(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h)
|
|
53 {
|
|
54 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
|
|
55 Pad *pad = sgroot->getController();
|
|
56
|
|
57 if (pad->circle.isPush()) {
|
|
58 node->set_move_collision(object_move_rotation, object_collision);
|
|
59 }
|
|
60
|
|
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 }
|
|
71
|
|
72
|
|
73 }
|
|
74
|
1
|
75 /*
|
0
|
76 static void
|
|
77 object_collision_idle(SceneGraphPtr, void *sgroot_, int w, int h, SceneGraphPtr tree)
|
|
78 {
|
|
79 }
|
1
|
80 */
|
0
|
81 static void
|
|
82 object_collision(SceneGraphPtr node, void *sgroot_, int screen_w,
|
|
83 int screen_h, SceneGraphPtr tree)
|
|
84 {
|
|
85 // if (node->xyz[1] > screen_h - object_radius) {
|
|
86 // node->xyz[1] = screen_h - object_radius;
|
|
87
|
|
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 // }
|
|
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 {
|
|
104
|
|
105 LightSysSwitch(sgroot);
|
|
106
|
|
107 SceneGraphPtr object;
|
|
108
|
|
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
|
|
117
|
|
118 // 固定した値で srandom すると、毎回同じ、random() 列が生成される
|
|
119 // random な値が欲しいなら、man random に方法が書いてあります。
|
|
120 srandom(100);
|
|
121
|
|
122 sgroot->createFromXMLfile(xmlfile);
|
|
123
|
|
124 object = sgroot->createSceneGraph();
|
|
125 object->set_move_collision(object_move_rotation, object_collision);
|
|
126
|
|
127 object->xyz[0] = screen_w/2;
|
|
128 object->xyz[1] = screen_h/2;;
|
|
129 object->xyz[2] = 30.0f;
|
|
130
|
|
131 for(int i=0;i<parts_cnt; i++) {
|
|
132 object->addChild(sgroot->createSceneGraph(parts[i]));
|
|
133 }
|
|
134 sgroot->setSceneData(object);
|
|
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];
|
|
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 }
|
|
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
|