Pan and tilt restored.

This commit is contained in:
MusicalProgrammer
2018-06-01 20:53:57 -04:00
parent b66d676254
commit 6730ddc7bc
4 changed files with 17 additions and 23 deletions

View File

@@ -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;
@@ -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);
}

View File

@@ -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;

1
Demo.h
View File

@@ -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();

View File

@@ -25,8 +25,9 @@
#include "AudioPlayer.h"
#include "Globals.h"
#include "Demo.h"
#include "win32Defines.h"
#include <limits.h>
#include <windows.h>
#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;
@@ -1050,6 +1047,7 @@ 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)