annotate Renderer/Test/ladybug.cc @ 2069:26aa08c9a1de draft default tip

cuda example fix
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 12 Feb 2017 10:04:55 +0900
parents 9a5e21195600
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1207
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include <stdlib.h>
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #include "SceneGraphRoot.h"
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #include "ladybug.h"
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 static void
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 obj_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h,
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 SceneGraphPtr tree)
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 static void
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 moon_collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h,
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 SceneGraphPtr tree)
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 static void
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 moon_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h)
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 node->angle[0] += 3.0f;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 static void
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 tyre_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h)
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 Pad *pad = sgroot->getController();
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 if (pad->left.isHold()) {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 node->angle[1] += 10;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 } else if (pad->right.isHold()) {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 node->angle[1] -= 10;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 if (pad->up.isHold()) {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 node->angle[0] += 10;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 } else if (pad->down.isHold()) {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 node->angle[0] -= 10;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 MainLoopPtr
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 ladybug::init(Viewer *sgroot, int screen_w, int screen_h)
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 SceneGraphPtr body;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 SceneGraphPtr body2;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 SceneGraphPtr tyre;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 SceneGraphPtr tyre2;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 SceneGraphPtr tyre3;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 SceneGraphPtr tyre4;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 SceneGraphPtr antenna;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 //camera
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55  SceneGraphPtr camera = sgroot-> getCamera();
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 sgroot->createFromXMLfile( "xml_file/ladybug4.xml");
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 sgroot->OnLightSysSwitch();
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 SceneGraphPtr light = sgroot->getLight(0);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 sgroot->OnLightSwitch(1);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 light->xyz[2] -= 10;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 // SceneGraph ID から SceneGraph を生成する
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 body = sgroot->createSceneGraph("body");
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 //body->set_move_collision(tyre_move, obj_collision);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 tyre = sgroot->createSceneGraph("tyre");
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 //tyre->set_move_collision(tyre_move, obj_collision);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 tyre2 = sgroot->createSceneGraph("tyre2");
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 //tyre2->set_move_collision(tyre_move, obj_collision);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 tyre3 = sgroot->createSceneGraph("tyre3");
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 //tyre3->set_move_collision(tyre_move, obj_collision);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 tyre4 = sgroot->createSceneGraph("tyre4");
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 //tyre4->set_move_collision(tyre_move, obj_collision);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 camera->set_move_collision(tyre_move, obj_collision);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 // SceneGraph の move と collision を設定
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 //body->set_move_collision(earth_move, earth_collision);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 body->xyz[0] = screen_w / 2;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 body->xyz[1] = screen_h / 2;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 body->stack_xyz[0] = 3.0f;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 body->stack_xyz[1] = 3.0f;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 body2 = sgroot->createSceneGraph("body2");
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 //body2->set_move_collision(moon_move, moon_collision);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 // SceneGraph 同士の親子関係を設定 (今回は 親 earth、子 moon)
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 body->addChild(body2);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 body->addChild(tyre);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 body->addChild(tyre2);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 body->addChild(tyre3);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 body->addChild(tyre4);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
101
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 // SceneGraphRoot に、使用する SceneGraph を設定する
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 // このとき、ユーザーは SceneGraph の root を渡す。
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 sgroot->setSceneData(body);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 return sgroot;
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 extern Application *
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 application() {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 return new ladybug();
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
112
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n";
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 extern int init(TaskManager *manager, int argc, char *argv[]);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 extern void task_initialize();
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 static void TMend(TaskManager *manager);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
118
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 int
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 TMmain(TaskManager *manager, int argc, char *argv[])
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 task_initialize();
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 manager->set_TMend(TMend);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 return init(manager, argc, argv);
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
125
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
127
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 void
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 TMend(TaskManager *manager)
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 {
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 printf("test_nogl end\n");
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 }
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
133
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 /* end */
9a5e21195600 clipping
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
135