Panning done?

This commit is contained in:
MusicalProgrammer
2018-04-30 11:04:05 -04:00
parent 59510383e6
commit 78ece8c2a2

View File

@@ -57,6 +57,7 @@ static bool running = true;
static bool mouseMovedBeginMotion = false; static bool mouseMovedBeginMotion = false;
static bool showMouse = true; static bool showMouse = true;
//Controller //Controller
static bool moving = false;
static bool forwards = false; static bool forwards = false;
static bool backwards = false; static bool backwards = false;
static bool left = false; static bool left = false;
@@ -874,30 +875,38 @@ void Demo::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) {
} }
CoordinateFrame frame = app->debugCamera.getCoordinateFrame(); CoordinateFrame frame = app->debugCamera.getCoordinateFrame();
if (moving)
{
cameraPos = frame.translation;
if(forwards) if(forwards)
{ {
forwards = false; forwards = false;
cameraPos = Vector3(cameraPos.x, cameraPos.y, cameraPos.z) + frame.lookVector()*moveRate; frame.translation = Vector3(cameraPos.x, cameraPos.y, cameraPos.z) + frame.lookVector()*moveRate;
} }
else if(backwards) else if(backwards)
{ {
backwards = false; backwards = false;
cameraPos = Vector3(cameraPos.x, cameraPos.y, cameraPos.z) - frame.lookVector()*moveRate; frame.translation = Vector3(cameraPos.x, cameraPos.y, cameraPos.z) - frame.lookVector()*moveRate;
} }
if(left) if(left)
{ {
left = false; left = false;
cameraPos = Vector3(cameraPos.x, cameraPos.y, cameraPos.z) + frame.leftVector()*moveRate; frame.translation = Vector3(cameraPos.x, cameraPos.y, cameraPos.z) + frame.leftVector()*moveRate;
} }
else if(right) else if(right)
{ {
right = false; right = false;
cameraPos = Vector3(cameraPos.x, cameraPos.y, cameraPos.z) + frame.rightVector()*moveRate; frame.translation = Vector3(cameraPos.x, cameraPos.y, cameraPos.z) + frame.rightVector()*moveRate;
}
moving=false;
app->setFocalPoint(frame.translation + frame.lookVector() * 15);
} }
//app->debugCamera.setPosition(cameraPos); //app->debugCamera.setPosition(cameraPos);
if(centerCam) if(centerCam)
{ {
CoordinateFrame frame = CoordinateFrame(app->debugCamera.getCoordinateFrame().translation); CoordinateFrame frame = app->debugCamera.getCoordinateFrame();
Vector3 focalPos; Vector3 focalPos;
if(selectedInstance == NULL) if(selectedInstance == NULL)
{ {
@@ -907,12 +916,13 @@ void Demo::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) {
} }
else else
{ {
focalPos=((PhysicalInstance*)selectedInstance)->getPosition(); focalPos=((PhysicalInstance*)selectedInstance)->getPosition()/2;
frame.lookAt(focalPos); frame.lookAt(focalPos);
app->setFocalPoint(focalPos); app->setFocalPoint(focalPos);
} }
app->debugController.setCoordinateFrame(frame); app->debugController.setCoordinateFrame(frame);
//app->debugCamera.setCoordinateFrame(frame);
centerCam = false; centerCam = false;
} }
@@ -923,7 +933,7 @@ void Demo::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) {
//test+=0.1f; //test+=0.1f;
//app->debugController.setCoordinateFrame(cf); //app->debugController.setCoordinateFrame(frame);
//app->setFocalPoint(Vector3(0,0,0)); //app->setFocalPoint(Vector3(0,0,0));
@@ -934,15 +944,15 @@ void Demo::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) {
Vector3 camPos = frame.translation; Vector3 camPos = frame.translation;
Vector3 focalPoint = app->getFocalPoint(); Vector3 focalPoint = app->getFocalPoint();
CoordinateFrame localFrame = CoordinateFrame(); CoordinateFrame localFrame = CoordinateFrame();
CoordinateFrame cf = CoordinateFrame(Vector3(focalPoint.x,focalPoint.y,focalPoint.z)); CoordinateFrame cf = CoordinateFrame(Vector3(focalPoint.x,0,focalPoint.z));
cf.lookAt(Vector3(camPos.x,focalPoint.y,camPos.z)); cf.lookAt(Vector3(camPos.x,0,camPos.z));
cf=cf*Matrix3::fromEulerAnglesXYZ(0,addOrSubtractThis,0); cf=cf*Matrix3::fromEulerAnglesXYZ(0,addOrSubtractThis,0);
float distd = (Vector3(camPos.x,0,camPos.z)-Vector3(focalPoint.x,0,focalPoint.z)).magnitude(); float distd = (Vector3(camPos.x,0,camPos.z)-Vector3(focalPoint.x,0,focalPoint.z)).magnitude();
cf=cf+cf.lookVector()*distd; // Distance cf=cf+cf.lookVector()*distd; // Distance
cf=cf+Vector3(0,camPos.y,0); cf=cf+Vector3(0,camPos.y,0);
cf.lookAt(focalPoint); cf.lookAt(focalPoint);
panRight = false; panRight = false;
Vector3 camerapoint = frame.translation; //Vector3 camerapoint = frame.translation;
messageTime = System::time(); messageTime = System::time();
cameraPos=camPos; cameraPos=camPos;
@@ -1080,19 +1090,23 @@ void Demo::onUserInput(UserInput* ui) {
if(ui->keyDown(SDLK_UP)) if(ui->keyDown(SDLK_UP))
{ {
forwards = true; forwards = true;
moving = true;
} }
else if(ui->keyDown(SDLK_DOWN)) else if(ui->keyDown(SDLK_DOWN))
{ {
backwards = true; backwards = true;
moving = true;
} }
if(ui->keyDown(SDLK_LEFT)) if(ui->keyDown(SDLK_LEFT))
{ {
left = true; left = true;
moving = true;
} }
else if(ui->keyDown(SDLK_RIGHT)) else if(ui->keyDown(SDLK_RIGHT))
{ {
right = true; right = true;
moving = true;
} }
if(ui->keyPressed(SDL_LEFT_MOUSE_KEY)) if(ui->keyPressed(SDL_LEFT_MOUSE_KEY))