summaryrefslogtreecommitdiff
path: root/src/world_camera.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/world_camera.cpp')
-rw-r--r--src/world_camera.cpp94
1 files changed, 94 insertions, 0 deletions
diff --git a/src/world_camera.cpp b/src/world_camera.cpp
new file mode 100644
index 0000000..1fc3a5a
--- /dev/null
+++ b/src/world_camera.cpp
@@ -0,0 +1,94 @@
+#include "worldmap.h"
+
+dWorldCamera_c *dWorldCamera_c::instance = 0;
+
+dWorldCamera_c *dWorldCamera_c::build() {
+ OSReport("Creating WorldCamera\n");
+
+ void *buffer = AllocFromGameHeap1(sizeof(dWorldCamera_c));
+ dWorldCamera_c *c = new(buffer) dWorldCamera_c;
+
+ OSReport("Created WorldCamera @ %p\n", c);
+
+ instance = c;
+ return c;
+}
+
+
+
+
+int dWorldCamera_c::onCreate() {
+ this->camPos = (Point3d){0.0f, 400.0f, 400.0f};
+ this->camRotate = (Point3d){-40.0f, 0.0f, 0.0f}; // ZXY order
+
+ return true;
+}
+
+
+int dWorldCamera_c::onDelete() {
+ return true;
+}
+
+
+int dWorldCamera_c::onExecute() {
+ int heldButtons = Remocon_GetButtons(GetActiveRemocon());
+
+ if (heldButtons & WPAD_LEFT)
+ this->camPos.x -= 5.0f;
+ if (heldButtons & WPAD_RIGHT)
+ this->camPos.x += 5.0f;
+
+ if (heldButtons & WPAD_UP)
+ this->camPos.z -= 5.0f;
+ if (heldButtons & WPAD_DOWN)
+ this->camPos.z += 5.0f;
+
+ if (heldButtons & WPAD_MINUS)
+ this->camRotate.y -= 2.0f;
+ if (heldButtons & WPAD_PLUS)
+ this->camRotate.y += 2.0f;
+
+ return true;
+}
+
+
+int dWorldCamera_c::onDraw() {
+ // fixup camera shit
+ GXRenderModeObj *rmode = nw4r::g3d::G3DState::GetRenderModeObj();
+
+ // 2D camera
+ nw4r::g3d::Camera cam2d(GetCameraByID(1));
+
+ if (rmode->field_rendering != 0)
+ cam2d.SetViewportJitter(VIGetNextField());
+
+ cam2d.SetOrtho(rmode->efbHeight, 0.0f, 0.0f, rmode->fbWidth * (IsWideScreen() ? 1.3333334f : 1.0f), -100000.0f, 100000.0f);
+
+ // 3D camera
+ nw4r::g3d::Camera cam3d(GetCameraByID(0));
+
+ if (rmode->field_rendering != 0)
+ cam3d.SetViewportJitter(VIGetNextField());
+
+ cam3d.SetPerspective(45, (f32)rmode->viWidth / (f32)rmode->viHeight, 0.1f, 2400.0f);
+
+ nw4r::g3d::Camera::PostureInfo posture;
+ posture.tp = nw4r::g3d::Camera::POSTURE_ROTATE;
+ posture.cameraRotate = this->camRotate;
+
+ cam3d.SetPosition(this->camPos);
+ cam3d.SetPosture(posture);
+
+ /*nw4r::g3d::Camera::PostureInfo posture;
+ posture.tp = nw4r::g3d::Camera::POSTURE_LOOKAT;
+ posture.cameraUp = (Point3d){0,1,0};
+ posture.cameraTarget = (Point3d){0,0,0};
+
+ cam3d.SetPosition((Point3d){-3,2,3});
+ cam3d.SetPosture(posture);*/
+
+ //cam3d.GetCameraMtx(&T3D::Camera.view_matrix);
+
+ return true;
+}
+