comparison Renderer/Test_/viewer.cc @ 4:b5b462ac9b3b

Cerium Blender ball_bound
author Daiki KINJYO <e085722@ie.u-ryukyu.ac.jp>
date Mon, 29 Nov 2010 16:42:42 +0900
parents
children
comparison
equal deleted inserted replaced
3:3f6fe22ac669 4:b5b462ac9b3b
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 object_move_rotation(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h){
28 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
29 Pad *pad = sgroot->getController();
30 if (pad->circle.isPush()) {
31 node->set_move_collision(object_move_translation, object_collision);
32 }
33 if (pad->left.isHold()) {
34 node->angle[1] += 10;
35 } else if (pad->right.isHold()) {
36 node->angle[1] -= 10;
37 }
38 if (pad->up.isHold()) {
39 node->angle[0] += 10;
40 } else if (pad->down.isHold()) {
41 node->angle[0] -= 10;
42 }
43 }
44
45
46
47 static void object_move_translation(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) {
48 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
49 Pad *pad = sgroot->getController();
50 if (pad->circle.isPush()) {
51 node->set_move_collision(object_move_rotation, object_collision);
52 }
53
54 if (pad->left.isHold()) {
55 node->xyz[0] -= 10;
56 } else if (pad->right.isHold()) {
57 node->xyz[0] += 10;
58 }
59 if (pad->up.isHold()) {
60 node->xyz[1] -= 10;
61 } else if (pad->down.isHold()) {
62 node->xyz[1] += 10;
63 }
64 }
65
66
67 static void object_collision(SceneGraphPtr node, void *sgroot_, int screen_w,int screen_h, SceneGraphPtr tree){
68
69 // if (node->xyz[1] > screen_h - object_radius) {
70 // node->xyz[1] = screen_h - object_radius;
71 // vy *= e;
72 // if (vy > -g && vy < 0) {
73 // vy = 0.0;
74 // node->set_move_collision(object_move_idle, object_collision_idle);
75 // }
76 // }
77 }
78
79
80
81
82 char *xmlfile;
83 #define MAX_ROOT 100
84 char *parts[MAX_ROOT ];
85 int parts_cnt;
86
87 MainLoopPtr viewer::init(Viewer *sgroot, int screen_w, int screen_h){
88 LightSysSwitch(sgroot);
89 SceneGraphPtr object;
90 for (int i = 0; i < light_num; i++) {
91 SceneGraphPtr light = sgroot->getLight(i);
92 sgroot->OnLightSwitch(i);
93 light->xyz[0] = screen_w / 2;
94 light->xyz[1] = screen_h / 2;
95 light->xyz[2] = 0;
96 }
97 sgroot->createFromXMLfile(xmlfile);
98 object = sgroot->createSceneGraph();
99 object->set_move_collision(object_move_rotation, object_collision);
100
101 object->xyz[0] = screen_w/2;
102 object->xyz[1] = screen_h/2;;
103 object->xyz[2] = 0;
104
105 for(int i=0;i<parts_cnt; i++) {
106 object->addChild(sgroot->createSceneGraph(parts[i]));
107 }
108 sgroot->setSceneData(object);
109 return sgroot;
110 }
111
112
113 extern Application *
114 application() {
115 return new viewer();
116 }
117
118
119 const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n";
120
121 extern int init(TaskManager *manager, int argc, char *argv[]);
122 extern void task_initialize();
123 static void TMend(TaskManager *manager);
124
125 int TMmain(TaskManager *manager, int argc, char *argv[]) {
126 task_initialize();
127 manager->set_TMend(TMend);
128 for(int i=0;i<argc;i++) {
129 if (strcmp(argv[i],"-sg") == 0 && i+1<=argc) {
130 xmlfile = argv[i+1];
131 } else if (strcmp(argv[i],"-name") == 0 && i+1<=argc) {
132 parts[parts_cnt++] = argv[i+1];
133 } else if (strcmp(argv[i],"-lightsys") == 0 && i+1<=argc) {
134 if (strcmp(argv[i],"on") == 0) {
135 light_sysswitch = 1;
136 } else if (strcmp(argv[i],"off") == 0) {
137 light_sysswitch = 0;
138 }
139 } else if (strcmp(argv[i],"-lightnum") == 0 && i+1<=argc) {
140 light_num = atoi(argv[i+1]);
141 }
142 }
143
144 //xmlfile = (char *)"xml_file/Ball.xml";
145 //parts[parts_cnt++] = (char *)"Ball";
146
147 return init(manager, argc, argv);
148 }
149
150 void
151 TMend(TaskManager *manager)
152 {
153 printf("test_nogl end\n");
154 }
155
156 /* end */
157