annotate Renderer/test_render/Camera.cpp @ 503:516d5c91d5b4 draft double-linked-task-list

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