From 6730ddc7bc59b83cc4c57f26b9443711e3e20bf0 Mon Sep 17 00:00:00 2001 From: MusicalProgrammer <38636805+MusicalProgrammer@users.noreply.github.com> Date: Fri, 1 Jun 2018 20:53:57 -0400 Subject: [PATCH] Pan and tilt restored. --- CameraController.cpp | 23 ++++++++++++----------- CameraController.h | 4 ---- Demo.h | 1 - main.cpp | 12 +++++------- 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/CameraController.cpp b/CameraController.cpp index 78da60d..eb24b24 100644 --- a/CameraController.cpp +++ b/CameraController.cpp @@ -39,6 +39,7 @@ void CameraController::lookAt(const Vector3& position) { void CameraController::setFrame(const CoordinateFrame& cf) { Vector3 look = cf.getLookVector(); + g3dCamera.setCoordinateFrame(cf); lookAt(cf.translation + look); } @@ -70,13 +71,13 @@ void CameraController::panLeft() CoordinateFrame frame = g3dCamera.getCoordinateFrame(); float y = frame.translation.y; CoordinateFrame frame2 = CoordinateFrame(frame.rotation, frame.translation + frame.lookVector()*25); - Vector3 focus = frame.translation+frame.lookVector()*25; - //frame2 = frame2 * Matrix3::fromEulerAnglesXYZ(0,toRadians(-45),0); + Vector3 focus = Vector3(0,0,0); //frame.translation+frame.lookVector()*25; + frame2 = frame2 * Matrix3::fromEulerAnglesXYZ(0,toRadians(-45),0); frame2 = frame2 - frame2.lookVector()*25; Vector3 cameraPos = Vector3(frame2.translation.x, y, frame2.translation.z); CoordinateFrame newFrame = CoordinateFrame(frame2.rotation, Vector3(frame2.translation.x, y, frame2.translation.z)); - newFrame.lookAt(focus); - setFrame(newFrame); + newFrame.lookAt(focus,frame2.upVector()); + setFrame(CoordinateFrame(focus)); } void CameraController::panRight() { @@ -84,7 +85,7 @@ void CameraController::panRight() float y = frame.translation.y; CoordinateFrame frame2 = CoordinateFrame(frame.rotation, frame.translation + frame.lookVector()*25); Vector3 focus = frame.translation+frame.lookVector()*25; - //frame2 = frame2 * Matrix3::fromEulerAnglesXYZ(0,toRadians(45),0); + frame2 = frame2 * Matrix3::fromEulerAnglesXYZ(0,toRadians(45),0); frame2 = frame2 - frame2.lookVector()*25; Vector3 cameraPos = Vector3(frame2.translation.x, y, frame2.translation.z); CoordinateFrame newFrame = CoordinateFrame(frame2.rotation, Vector3(frame2.translation.x, y, frame2.translation.z)); @@ -94,7 +95,7 @@ void CameraController::panRight() void CameraController::tiltUp() { - //CoordinateFrame frame = CoordinateFrame(g3dCamera.getCoordinateFrame().rotation, g3dCamera.getCoordinateFrame().translation); + CoordinateFrame frame = CoordinateFrame(g3dCamera.getCoordinateFrame().rotation, g3dCamera.getCoordinateFrame().translation); Vector3 camerapoint = frame.translation; Vector3 focalPoint = camerapoint + frame.lookVector() * 25; @@ -105,12 +106,14 @@ void CameraController::tiltUp() CoordinateFrame newFrame = CoordinateFrame(camerapoint); newFrame.lookAt(focalPoint); - cameraPos = camerapoint; + Vector3 cameraPos = camerapoint; frame = newFrame; + setFrame(newFrame); } void CameraController::tiltDown() { } + void CameraController::centerCamera(Instance* selection) { CoordinateFrame frame = CoordinateFrame(g3dCamera.getCoordinateFrame().translation); @@ -118,15 +121,14 @@ void CameraController::centerCamera(Instance* selection) lookAt(Vector3(0,0,0)); else lookAt(((PhysicalInstance*)selection)->getPosition()/2); - //g3dCamera.setCoordinateFrame(frame); } void CameraController::update(Demo* demo) { + float offsetSize = 0.05F; Vector3 cameraPos = g3dCamera.getCoordinateFrame().translation; CoordinateFrame frame = g3dCamera.getCoordinateFrame(); - //CoordinateFrame cf = getCoordinateFrame(); if(GetHoldKeyState('U')) { forwards = true; @@ -140,7 +142,7 @@ void CameraController::update(Demo* demo) if(GetHoldKeyState('K')) { right = true; } - + if(forwards) { forwards = false; frame.translation += frame.lookVector()*moveRate; @@ -167,7 +169,6 @@ void CameraController::update(Demo* demo) pitch+=(mouse.y-oldDesktopMouse.y)/100.f; SetCursorPos(oldDesktopMouse.x,oldDesktopMouse.y); - //frame.translation=cameraPos; frame.rotation = Matrix3::fromEulerAnglesZYX(0, -yaw, -pitch); } diff --git a/CameraController.h b/CameraController.h index 673e690..769bab8 100644 --- a/CameraController.h +++ b/CameraController.h @@ -33,10 +33,6 @@ class CameraController { bool left; bool right; bool rightButtonHolding; - //bool centerCam; - //bool panRight; - //bool panLeft; - //bool tiltUp; POINT oldDesktopMouse; GCamera g3dCamera; std::string cameraSound; diff --git a/Demo.h b/Demo.h index 8610ceb..a449294 100644 --- a/Demo.h +++ b/Demo.h @@ -25,7 +25,6 @@ class Demo : public GApp { void onMouseRightUp(int x, int y); void onMouseMoved(int x, int y); void onMouseWheel(int x, int y, short delta); - //GCamera g3dCamera; CameraController cameraController; private: void initGUI(); diff --git a/main.cpp b/main.cpp index 8f072ba..642275b 100644 --- a/main.cpp +++ b/main.cpp @@ -25,8 +25,9 @@ #include "AudioPlayer.h" #include "Globals.h" #include "Demo.h" +#include "win32Defines.h" #include -#include + #if G3D_VER < 61000 @@ -788,10 +789,6 @@ void Demo::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) { return ::atof(version.c_str()); }*/ -short GetHoldKeyState(int key) -{ - return GetKeyState(key) >> 1; -} bool IsHolding(int button) { return (GetKeyState(button) >> 1)>0; @@ -1049,8 +1046,9 @@ void Demo::onGraphics(RenderDevice* rd) { renderDevice->setLight(0, GLight::directional(lighting.lightDirection, lighting.lightColor)); renderDevice->setAmbientLightColor(lighting.ambient); - - + + Draw::box(Box(Vector3(-0.25, -0.25, -0.25), Vector3(0.25, 0.25, 0.25)), renderDevice, Color4(1,1,1,1), Color4::clear()); + dataModel->getWorkspace()->render(rd); if(selectedInstance != NULL) {