comparison TaskManager/Test/test_render/Camera.cpp @ 207:e1746a2d1343 draft

add Camera.cpp
author gongo@gendarme.cr.ie.u-ryukyu.ac.jp
date Thu, 29 Jan 2009 13:53:04 +0900
parents
children c020ccff4627
comparison
equal deleted inserted replaced
206:f5784443dd50 207:e1746a2d1343
1 #include <math.h>
2 #include "SceneGraphRoot.h"
3 #include "Camera.h"
4 #include "sys.h"
5
6 static void
7 camera_move(SceneGraphPtr _node, int screen_w, int screen_h)
8 {
9 Pad *pad = sgroot->getController();
10 CameraPtr node = (CameraPtr)_node;
11
12 if (pad->left.isPush() || pad->left.isHold()) {
13 node->xyz[0] += 2.0f;
14 } else if (pad->right.isPush() || pad->right.isHold()) {
15 node->xyz[0] -= 2.0f;
16 }
17
18 if (pad->up.isPush() || pad->up.isHold()) {
19 node->xyz[1] += 2.0f;
20 } else if (pad->down.isPush() || pad->down.isHold()) {
21 node->xyz[1] -= 2.0f;
22 }
23
24 if (pad->start.isPush() || pad->start.isHold()) {
25 node->xyz[2] += 10.0f;
26 } else if (pad->select.isPush() || pad->select.isHold()) {
27 node->xyz[2] -= 10.0f;
28 }
29 }
30
31 static void
32 camera_collision(SceneGraphPtr node, int screen_w, int screen_h,
33 SceneGraphPtr tree)
34 {
35 }
36
37 Camera::Camera(void)
38 {
39 name = (const char*)"Camera";
40
41 fov = 120.0f;
42 near = 0.0f;
43 far = 1000.0f;
44
45 this->set_move_collision(camera_move, camera_collision);
46 }
47
48 #if 0
49 void
50 Camera::updatePerspectiveMatrix(float *m, float z0, float z1)
51 {
52 // scale = az + b;
53 // z が near position(z0) => 縮小率 1
54 // z が far position(z1) => 縮小率 0.00053 (1920pixel が 1 pixel になる)
55 // でPerspective変換を行う
56 float a = 0.99947f / (near - far);
57 float b = 1-((0.99947f*near)/(near - far));
58
59 matrix[0] *= a*txyz[2]+b;
60 matrix[5] *= a*txyz[2]+b;
61
62 float a = -0.01;
63 //float b = 1 + -a*z0;
64 float b = 1.0;
65
66 float z = a*z0 + b;
67
68 m[0] = z;
69 m[5] = z;
70 }
71
72 #endif
73 void
74 Camera::updatePerspectiveMatrix(float *m, float s, float r)
75 {
76 m[0] = s*r;
77 m[5] = s;
78 }
79
80 void
81 Camera::update(int w, int h)
82 {
83 float pers_matrix[16] = {
84 1, 0, 0, 0,
85 0, 1, 0, 0,
86 0, 0, 1, 0,
87 0, 0, 0, 0
88 };
89
90 float m[16];
91
92 float zoom = 1.0f / tan(fov*0.5f*M_PI/180.0f);
93
94 //updatePerspectiveMatrix(pers_matrix, zoom, (float)h/(float)w);
95 get_matrix(matrix, angle, xyz, NULL);
96 //matrix4x4(matrix, m, pers_matrix);
97 }