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