annotate TaskManager/Test/test_render/Camera.cpp @ 362:a64a6c34868f

vacuum -sg 15
author e065746@localhost.localdomain
date Fri, 17 Jul 2009 23:02:07 +0900
parents b89ba1d96fff
children a4f690f44842
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
207
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
1 #include <math.h>
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
2 #include "SceneGraphRoot.h"
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
3 #include "Camera.h"
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
4 #include "sys.h"
316
1d88baf53e57 run に smanager を引数として渡すようにした
e065746@localhost.localdomain
parents: 227
diff changeset
5 #include "Scheduler.h"
327
7c6d4b101956 add test_render/show_time.{cpp,h} {spe,task}/ShowTime.{cpp,h} but incomplete
aaa
parents: 316
diff changeset
6 #include "show_time.h"
207
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
7
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
8 static void
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
9 camera_move(SceneGraphPtr _node, int screen_w, int screen_h)
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
10 {
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
11 Pad *pad = sgroot->getController();
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
12 CameraPtr node = (CameraPtr)_node;
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
13
222
gongo@localhost.localdomain
parents: 221
diff changeset
14 #if 0
221
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
15 if (pad->right.isHold()) {
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
16 node->xyz[0] += 10.0f;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
17 } else if (pad->left.isHold()) {
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
18 node->xyz[0] -= 10.0f;
207
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
19 }
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
20
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
21 if (pad->up.isPush() || pad->up.isHold()) {
222
gongo@localhost.localdomain
parents: 221
diff changeset
22 node->xyz[1] -= 2.0f;
207
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
23 } else if (pad->down.isPush() || pad->down.isHold()) {
222
gongo@localhost.localdomain
parents: 221
diff changeset
24 node->xyz[1] += 2.0f;
207
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
25 }
222
gongo@localhost.localdomain
parents: 221
diff changeset
26 #endif
207
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
27
316
1d88baf53e57 run に smanager を引数として渡すようにした
e065746@localhost.localdomain
parents: 227
diff changeset
28 /*
1d88baf53e57 run に smanager を引数として渡すようにした
e065746@localhost.localdomain
parents: 227
diff changeset
29 * ここに show_dma_wait 表示をいれようか
1d88baf53e57 run に smanager を引数として渡すようにした
e065746@localhost.localdomain
parents: 227
diff changeset
30 */
1d88baf53e57 run に smanager を引数として渡すようにした
e065746@localhost.localdomain
parents: 227
diff changeset
31
327
7c6d4b101956 add test_render/show_time.{cpp,h} {spe,task}/ShowTime.{cpp,h} but incomplete
aaa
parents: 316
diff changeset
32 if (pad->r1.isPush()) {
7c6d4b101956 add test_render/show_time.{cpp,h} {spe,task}/ShowTime.{cpp,h} but incomplete
aaa
parents: 316
diff changeset
33 show_time();
7c6d4b101956 add test_render/show_time.{cpp,h} {spe,task}/ShowTime.{cpp,h} but incomplete
aaa
parents: 316
diff changeset
34 }
316
1d88baf53e57 run に smanager を引数として渡すようにした
e065746@localhost.localdomain
parents: 227
diff changeset
35
212
gongo@localhost.localdomain
parents: 207
diff changeset
36 if (pad->r1.isPush() || pad->r1.isHold()) {
207
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
37 node->xyz[2] += 10.0f;
212
gongo@localhost.localdomain
parents: 207
diff changeset
38 } else if (pad->l1.isPush() || pad->l1.isHold()) {
207
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
39 node->xyz[2] -= 10.0f;
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
40 }
221
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
41
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
42 if (pad->r2.isHold()) {
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
43 if (node->zd[0] <= 1.0f) {
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
44 node->zd[0] += 0.02f;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
45 }
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
46 if (node->zd[2] >= 0.0f) {
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
47 node->zd[2] -= 0.02f;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
48 }
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
49 } else if (pad->l2.isHold()) {
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
50 if (node->zd[0] > -1.0f) {
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
51 node->zd[0] -= -0.02f;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
52 }
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
53 if (node->zd[2] >= 0.0f) {
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
54 node->zd[2] -= 0.02f;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
55 }
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
56 } else {
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
57 node->zd[0] = 0.0f;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
58 node->zd[2] = 1.0f;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
59 }
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
60
207
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
61 }
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
62
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
63 static void
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
64 camera_collision(SceneGraphPtr node, int screen_w, int screen_h,
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
65 SceneGraphPtr tree)
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
66 {
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
67 }
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
68
221
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
69 /**
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
70 * @param w Width of screen
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
71 * @param h Height of screen
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
72 */
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
73 Camera::Camera(float w, float h)
207
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
74 {
227
d54cbfafcb82 add sort
gongo@localhost.localdomain
parents: 226
diff changeset
75 name = (char*)"Camera";
207
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
76
226
0f80d90fe40a fix Makefile
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 222
diff changeset
77
0f80d90fe40a fix Makefile
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 222
diff changeset
78 fov = 60.0f;
0f80d90fe40a fix Makefile
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 222
diff changeset
79 near = 0.0f;
0f80d90fe40a fix Makefile
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 222
diff changeset
80 far = 1000.0f;
0f80d90fe40a fix Makefile
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 222
diff changeset
81
219
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
82 zd[0] = 0.0f;
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
83 zd[1] = 0.0f;
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
84 zd[2] = 1.0f;
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
85 zd[3] = 1.0f;
212
gongo@localhost.localdomain
parents: 207
diff changeset
86
219
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
87 yd[0] = 0.0f;
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
88 yd[1] = 1.0f;
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
89 yd[2] = 0.0f;
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
90 yd[3] = 1.0f;
212
gongo@localhost.localdomain
parents: 207
diff changeset
91
221
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
92 // Screen の真ん中を初期値とする
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
93 xyz[0] = w/2.0f;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
94 xyz[1] = h/2.0f;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
95
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
96 // min(w, h) がちょうど一杯見えるような z の位置の計算
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
97 xyz[2] = -(((xyz[1] < xyz[0]) ? xyz[1] : xyz[0])/tanf((fov/2.0f)*M_PI/180.0f));
222
gongo@localhost.localdomain
parents: 221
diff changeset
98 //xyz[2] = -200.0f;
221
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
99 xyz[3] = 1.0f;
226
0f80d90fe40a fix Makefile
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 222
diff changeset
100
0f80d90fe40a fix Makefile
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 222
diff changeset
101 m_view = new float[16];
0f80d90fe40a fix Makefile
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 222
diff changeset
102 m_pers = new float[16];
0f80d90fe40a fix Makefile
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents: 222
diff changeset
103 m_screen = new float[16];
207
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
104
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
105 this->set_move_collision(camera_move, camera_collision);
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
106 }
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
107
221
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
108 Camera::~Camera(void)
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
109 {
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
110 delete [] m_view;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
111 delete [] m_pers;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
112 delete [] m_screen;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
113 }
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
114
212
gongo@localhost.localdomain
parents: 207
diff changeset
115 void
221
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
116 Camera::updateView(void)
212
gongo@localhost.localdomain
parents: 207
diff changeset
117 {
219
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
118 float radx,rady,radz;
221
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
119 float cx[4], cy[4], cz[4], p[4];
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
120 float tm[16];
219
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
121
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
122 radx = angle[0]*3.14/180;
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
123 rady = angle[1]*3.14/180;
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
124 radz = angle[2]*3.14/180;
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
125
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
126 float sinx = sin(radx);
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
127 float cosx = cos(radx);
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
128 float siny = sin(rady);
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
129 float cosy = cos(rady);
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
130 float sinz = sin(radz);
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
131 float cosz = cos(radz);
212
gongo@localhost.localdomain
parents: 207
diff changeset
132
219
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
133 /* View Transform */
221
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
134 tm[0] = cosz*cosy+sinz*sinx*siny;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
135 tm[1] = sinz*cosx;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
136 tm[2] = -cosz*siny+sinz*sinx*cosy;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
137 tm[3] = 0.0f;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
138 tm[4] = -sinz*cosy+cosz*sinx*siny;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
139 tm[5] = cosz*cosx;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
140 tm[6] = sinz*siny+cosz*sinx*cosy;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
141 tm[7] = 0.0f;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
142 tm[8] = cosx*siny;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
143 tm[9] = -sinx;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
144 tm[10] = cosx*cosy;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
145 tm[11] = 0.0f;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
146 tm[12] = 0.0f;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
147 tm[13] = 0.0f;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
148 tm[14] = 0.0f;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
149 tm[15] = 1.0f;
219
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
150
221
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
151 applyMatrix(cz, tm, zd);
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
152 applyMatrix(cy, tm, yd);
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
153 applyMatrix(p, tm, xyz);
219
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
154
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
155 outerProduct(cx, cy, cz);
221
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
156 normalize(cx, cx);
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
157 normalize(cz, cz);
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
158 outerProduct(cy, cz, cx);
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
159
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
160 m_view[ 0] = cx[0];
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
161 m_view[ 1] = cy[0];
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
162 m_view[ 2] = cz[0];
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
163 m_view[ 3] = 0.0f;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
164
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
165 m_view[ 4] = cx[1];
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
166 m_view[ 5] = cy[1];
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
167 m_view[ 6] = cz[1];
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
168 m_view[ 7] = 0.0f;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
169 m_view[ 8] = cx[2];
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
170 m_view[ 9] = cy[2];
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
171 m_view[10] = cz[2];
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
172 m_view[11] = 0.0f;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
173
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
174 m_view[12] = innerProduct(xyz, cx)*(-1);
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
175 m_view[13] = innerProduct(xyz, cy)*(-1);
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
176 m_view[14] = innerProduct(xyz, cz)*(-1);
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
177 m_view[15] = 1.0f;
212
gongo@localhost.localdomain
parents: 207
diff changeset
178 }
gongo@localhost.localdomain
parents: 207
diff changeset
179
gongo@localhost.localdomain
parents: 207
diff changeset
180 void
221
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
181 Camera::updatePerspective(float w, float h)
207
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
182 {
221
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
183 float sx, sy, sz;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
184 float aspect = w/h;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
185
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
186 sy = (1.0f/tanf((fov/2.0f)*M_PI/180.0f));
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
187 sx = sy/aspect;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
188 //sz = far/(far+near);
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
189 sz = far/(far-near);
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
190
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
191 m_pers[ 0] = sx;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
192 m_pers[ 1] = 0.0f;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
193 m_pers[ 2] = 0.0f;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
194 m_pers[ 3] = 0.0f;
212
gongo@localhost.localdomain
parents: 207
diff changeset
195
221
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
196 m_pers[ 4] = 0.0f;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
197 m_pers[ 5] = sy;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
198 m_pers[ 6] = 0.0f;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
199 m_pers[ 7] = 0.0f;
207
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
200
221
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
201 m_pers[ 8] = 0.0f;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
202 m_pers[ 9] = 0.0f;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
203 m_pers[10] = sz;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
204 m_pers[11] = 1.0f;
207
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
205
221
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
206 m_pers[12] = 0.0f;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
207 m_pers[13] = 0.0f;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
208 m_pers[14] = -near*sz;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
209 m_pers[15] = 0.0f;
207
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
210 }
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
211
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
212 void
221
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
213 Camera::updateScreen(float _w, float _h)
212
gongo@localhost.localdomain
parents: 207
diff changeset
214 {
gongo@localhost.localdomain
parents: 207
diff changeset
215 float w = _w/2.0f;
gongo@localhost.localdomain
parents: 207
diff changeset
216 float h = _h/2.0f;
gongo@localhost.localdomain
parents: 207
diff changeset
217
221
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
218 m_screen[ 0] = w;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
219 m_screen[ 1] = 0.0f;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
220 m_screen[ 2] = 0.0f;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
221 m_screen[ 3] = 0.0f;
212
gongo@localhost.localdomain
parents: 207
diff changeset
222
221
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
223 m_screen[ 4] = 0.0f;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
224 m_screen[ 5] = h;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
225 m_screen[ 6] = 0.0f;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
226 m_screen[ 7] = 0.0f;
212
gongo@localhost.localdomain
parents: 207
diff changeset
227
221
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
228 m_screen[ 8] = 0.0f;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
229 m_screen[ 9] = 0.0f;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
230 m_screen[10] = 1.0f;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
231 m_screen[11] = 0.0f;
212
gongo@localhost.localdomain
parents: 207
diff changeset
232
221
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
233 m_screen[12] = w;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
234 m_screen[13] = h;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
235 m_screen[14] = 0.0f;
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
236 m_screen[15] = 1.0f;
207
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
237 }
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
238
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
239 void
219
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
240 Camera::setCamera(float *pose)
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
241 {
221
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
242 //memcpy(xyz, &pose[12], sizeof(float)*4);
219
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
243 }
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
244
0f1ff7b06157 allExecute する度に SceneGraph をコピーしていく様に変更
gongo@gendarme.local
parents: 215
diff changeset
245 void
221
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
246 Camera::update(float w, float h)
207
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
247 {
221
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
248 #if 1
212
gongo@localhost.localdomain
parents: 207
diff changeset
249 float tmp[16];
207
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
250
221
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
251 updateView();
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
252 updatePerspective(w, h);
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
253 updateScreen(w, h);
212
gongo@localhost.localdomain
parents: 207
diff changeset
254
221
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
255 matrix4x4(tmp, this->m_pers, this->m_screen);
d61fded0729e Cameraの設定、Makefile 修正
gongo@gendarme.local
parents: 219
diff changeset
256 matrix4x4(this->matrix, this->m_view, tmp);
215
7ca6a2ef5be9 fix SceneGraph Constructor, Destructor
gongo@gendarme.local
parents: 212
diff changeset
257 #else
207
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
258 get_matrix(matrix, angle, xyz, NULL);
215
7ca6a2ef5be9 fix SceneGraph Constructor, Destructor
gongo@gendarme.local
parents: 212
diff changeset
259 #endif
207
6b230b6a7ba2 add Camera.cpp
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff changeset
260 }