changeset 207:6b230b6a7ba2

add Camera.cpp
author gongo@gendarme.cr.ie.u-ryukyu.ac.jp
date Thu, 29 Jan 2009 13:53:04 +0900
parents dee3b5092a70
children 07f3cd0bcc14
files TaskManager/Test/test_render/Camera.cpp
diffstat 1 files changed, 97 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TaskManager/Test/test_render/Camera.cpp	Thu Jan 29 13:53:04 2009 +0900
@@ -0,0 +1,97 @@
+#include <math.h>
+#include "SceneGraphRoot.h"
+#include "Camera.h"
+#include "sys.h"
+
+static void
+camera_move(SceneGraphPtr _node, int screen_w, int screen_h)
+{
+    Pad *pad = sgroot->getController();
+    CameraPtr node = (CameraPtr)_node;
+
+    if (pad->left.isPush() || pad->left.isHold()) {
+	node->xyz[0] += 2.0f;
+    } else if (pad->right.isPush() || pad->right.isHold()) {
+	node->xyz[0] -= 2.0f;
+    }
+
+    if (pad->up.isPush() || pad->up.isHold()) {
+	node->xyz[1] += 2.0f;
+    } else if (pad->down.isPush() || pad->down.isHold()) {
+	node->xyz[1] -= 2.0f;
+    }
+
+    if (pad->start.isPush() || pad->start.isHold()) {
+	node->xyz[2] += 10.0f;
+    } else if (pad->select.isPush() || pad->select.isHold()) {
+	node->xyz[2] -= 10.0f;
+    }
+}
+
+static void
+camera_collision(SceneGraphPtr node, int screen_w, int screen_h,
+		 SceneGraphPtr tree)
+{
+}
+
+Camera::Camera(void)
+{
+    name = (const char*)"Camera";
+
+    fov  = 120.0f;
+    near = 0.0f;
+    far  = 1000.0f;
+    
+    this->set_move_collision(camera_move, camera_collision);
+}
+
+#if 0
+void
+Camera::updatePerspectiveMatrix(float *m, float z0, float z1)
+{
+    // scale = az + b;
+    //   z が near position(z0) => 縮小率 1
+    //   z が far position(z1) => 縮小率 0.00053 (1920pixel が 1 pixel になる)
+    // でPerspective変換を行う
+    float a = 0.99947f / (near - far);
+    float b = 1-((0.99947f*near)/(near - far));
+    
+    matrix[0] *= a*txyz[2]+b;
+    matrix[5] *= a*txyz[2]+b;
+
+    float a = -0.01;
+    //float b = 1 + -a*z0;
+    float b = 1.0;
+
+    float z = a*z0 + b;
+
+    m[0] = z;
+    m[5] = z;
+}
+
+#endif
+void
+Camera::updatePerspectiveMatrix(float *m, float s, float r)
+{
+    m[0]  = s*r;
+    m[5]  = s;
+}
+
+void
+Camera::update(int w, int h)
+{
+    float pers_matrix[16] = {
+	1, 0, 0, 0,
+	0, 1, 0, 0,
+	0, 0, 1, 0,
+	0, 0, 0, 0
+    };
+
+    float m[16];
+
+    float zoom = 1.0f / tan(fov*0.5f*M_PI/180.0f);
+
+    //updatePerspectiveMatrix(pers_matrix, zoom, (float)h/(float)w);
+    get_matrix(matrix, angle, xyz, NULL);
+    //matrix4x4(matrix, m, pers_matrix);
+}