annotate TaskManager/Test/test_render/Camera.cpp @ 222:5ffee529dc59

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