Mercurial > hg > Game > Cerium
annotate Renderer/Test/viewer.cc @ 1276:e92f00ed2fc0 draft
apply view matrix to normal vector
author | Yutaka_Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 22 Nov 2011 19:26:18 +0900 |
parents | 5ffe41af8d3b |
children |
rev | line source |
---|---|
589 | 1 #include <math.h> |
2 #include <stdlib.h> | |
3 #include "SceneGraphRoot.h" | |
4 #include "MainLoop.h" | |
5 #include "viewer.h" | |
6 | |
7 | |
8 // prototype | |
795 | 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); | |
589 | 12 |
827 | 13 int light_sysswitch = 1; |
793 | 14 int light_num = 4; |
15 | |
16 void LightSysSwitch(Viewer *sgroot) { | |
827 | 17 if (light_sysswitch == 1) { |
793 | 18 sgroot->OnLightSysSwitch(); |
827 | 19 } else if (light_sysswitch == 0) { |
793 | 20 sgroot->OffLightSysSwitch(); |
21 } | |
22 } | |
23 | |
589 | 24 |
795 | 25 |
26 | |
589 | 27 static void |
795 | 28 object_move_rotation(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) |
589 | 29 { |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
589
diff
changeset
|
30 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_; |
589 | 31 Pad *pad = sgroot->getController(); |
795 | 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 } | |
589 | 45 |
46 | |
47 } | |
48 | |
49 static void | |
795 | 50 object_move_translation(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h) |
589 | 51 { |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
589
diff
changeset
|
52 SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_; |
589 | 53 Pad *pad = sgroot->getController(); |
54 | |
55 if (pad->circle.isPush()) { | |
795 | 56 node->set_move_collision(object_move_rotation, object_collision); |
589 | 57 } |
58 | |
795 | 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 } | |
589 | 69 |
795 | 70 |
589 | 71 } |
72 | |
73 | |
74 static void | |
795 | 75 object_collision(SceneGraphPtr node, void *sgroot_, int screen_w, |
653
7a311860a76e
remove global variable "sgroot" , add SgChange.{cc, h} SgMain.cc SgRootChange.{cc, h}
hiroki@henri.cr.ie.u-ryukyu.ac.jp
parents:
589
diff
changeset
|
76 int screen_h, SceneGraphPtr tree) |
589 | 77 { |
78 | |
79 } | |
80 | |
81 char *xmlfile; | |
82 #define MAX_ROOT 100 | |
83 char *parts[MAX_ROOT ]; | |
84 int parts_cnt; | |
85 | |
86 MainLoopPtr | |
87 viewer::init(Viewer *sgroot, int screen_w, int screen_h) | |
88 { | |
793 | 89 |
90 LightSysSwitch(sgroot); | |
91 | |
795 | 92 SceneGraphPtr object; |
589 | 93 |
793 | 94 for (int i = 0; i < light_num; i++) { |
95 SceneGraphPtr light = sgroot->getLight(i); | |
96 sgroot->OnLightSwitch(i); | |
97 light->xyz[0] = screen_w / 2; | |
98 light->xyz[1] = screen_h / 2; | |
99 light->xyz[2] = -100; | |
1276
e92f00ed2fc0
apply view matrix to normal vector
Yutaka_Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
parents:
827
diff
changeset
|
100 |
793 | 101 } |
102 | |
795 | 103 |
589 | 104 // 固定した値で srandom すると、毎回同じ、random() 列が生成される |
105 // random な値が欲しいなら、man random に方法が書いてあります。 | |
106 srandom(100); | |
107 | |
108 sgroot->createFromXMLfile(xmlfile); | |
109 | |
795 | 110 object = sgroot->createSceneGraph(); |
111 object->set_move_collision(object_move_rotation, object_collision); | |
589 | 112 |
795 | 113 object->xyz[0] = screen_w/2; |
114 object->xyz[1] = screen_h/2;; | |
115 object->xyz[2] = 30.0f; | |
589 | 116 |
117 for(int i=0;i<parts_cnt; i++) { | |
795 | 118 object->addChild(sgroot->createSceneGraph(parts[i])); |
589 | 119 } |
795 | 120 sgroot->setSceneData(object); |
589 | 121 |
122 return sgroot; | |
123 } | |
124 | |
125 extern Application * | |
126 application() { | |
127 return new viewer(); | |
128 } | |
129 | |
130 const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n"; | |
131 | |
132 extern int init(TaskManager *manager, int argc, char *argv[]); | |
133 extern void task_initialize(); | |
134 static void TMend(TaskManager *manager); | |
135 | |
136 int | |
137 TMmain(TaskManager *manager, int argc, char *argv[]) | |
138 { | |
139 task_initialize(); | |
140 manager->set_TMend(TMend); | |
141 | |
827 | 142 |
589 | 143 for(int i=0;i<argc;i++) { |
144 if (strcmp(argv[i],"-sg") == 0 && i+1<=argc) { | |
145 xmlfile = argv[i+1]; | |
146 } else if (strcmp(argv[i],"-name") == 0 && i+1<=argc) { | |
827 | 147 parts[parts_cnt++] = argv[i+1]; |
793 | 148 } else if (strcmp(argv[i],"-lightsys") == 0 && i+1<=argc) { |
827 | 149 if (strcmp(argv[i],"on") == 0) { |
150 light_sysswitch = 1; | |
151 } else if (strcmp(argv[i],"off") == 0) { | |
152 light_sysswitch = 0; | |
153 } | |
793 | 154 } else if (strcmp(argv[i],"-lightnum") == 0 && i+1<=argc) { |
827 | 155 light_num = atoi(argv[i+1]); |
793 | 156 } |
589 | 157 } |
158 return init(manager, argc, argv); | |
159 | |
160 } | |
161 | |
162 void | |
163 TMend(TaskManager *manager) | |
164 { | |
165 printf("test_nogl end\n"); | |
166 } | |
167 | |
168 /* end */ | |
169 |