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);
|
|
11 static void object_move_translation(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h);
|
|
12
|
|
13 int light_sysswitch = 1;
|
|
14 int light_num = 4;
|
|
15
|
|
16 void LightSysSwitch(Viewer *sgroot) {
|
|
17 if (light_sysswitch == 1) {
|
|
18 sgroot->OnLightSysSwitch();
|
|
19 } else if (light_sysswitch == 0) {
|
|
20 sgroot->OffLightSysSwitch();
|
|
21 }
|
|
22 }
|
|
23
|
|
24
|
|
25
|
|
26
|
|
27 static void
|
|
28 object_move_rotation(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h)
|
|
29 {
|
|
30 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
|
|
31 Pad *pad = sgroot->getController();
|
|
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 }
|
|
45
|
|
46
|
|
47 }
|
|
48
|
|
49 static void
|
|
50 object_move_translation(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h)
|
|
51 {
|
|
52 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
|
|
53 Pad *pad = sgroot->getController();
|
|
54
|
|
55 if (pad->circle.isPush()) {
|
|
56 node->set_move_collision(object_move_rotation, object_collision);
|
|
57 }
|
|
58
|
|
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 }
|
|
69
|
|
70
|
|
71 }
|
|
72
|
|
73
|
|
74 static void
|
|
75 object_collision(SceneGraphPtr node, void *sgroot_, int screen_w,
|
|
76 int screen_h, SceneGraphPtr tree)
|
|
77 {
|
|
78 // if (node->xyz[1] > screen_h - object_radius) {
|
|
79 // node->xyz[1] = screen_h - object_radius;
|
|
80
|
|
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 // }
|
|
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 {
|
|
97
|
|
98 LightSysSwitch(sgroot);
|
|
99
|
|
100 SceneGraphPtr object;
|
|
101
|
|
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
|
|
110
|
|
111 // 固定した値で srandom すると、毎回同じ、random() 列が生成される
|
|
112 // random な値が欲しいなら、man random に方法が書いてあります。
|
|
113 srandom(100);
|
|
114
|
|
115 sgroot->createFromXMLfile(xmlfile);
|
|
116
|
|
117 object = sgroot->createSceneGraph();
|
|
118 object->set_move_collision(object_move_rotation, object_collision);
|
|
119
|
|
120 object->xyz[0] = screen_w/2;
|
|
121 object->xyz[1] = screen_h/2;;
|
|
122 object->xyz[2] = 30.0f;
|
|
123
|
|
124 for(int i=0;i<parts_cnt; i++) {
|
|
125 object->addChild(sgroot->createSceneGraph(parts[i]));
|
|
126 }
|
|
127 sgroot->setSceneData(object);
|
|
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
|
|
149
|
|
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) {
|
|
154 parts[parts_cnt++] = argv[i+1];
|
|
155 } else if (strcmp(argv[i],"-lightsys") == 0 && i+1<=argc) {
|
|
156 if (strcmp(argv[i],"on") == 0) {
|
|
157 light_sysswitch = 1;
|
|
158 } else if (strcmp(argv[i],"off") == 0) {
|
|
159 light_sysswitch = 0;
|
|
160 }
|
|
161 } else if (strcmp(argv[i],"-lightnum") == 0 && i+1<=argc) {
|
|
162 light_num = atoi(argv[i+1]);
|
|
163 }
|
|
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
|