Custom unstable camera added.
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
#include "ButtonListener.h"
|
#include "ButtonListener.h"
|
||||||
|
|
||||||
|
|
||||||
ButtonListener::ButtonListener(void)
|
ButtonListener::ButtonListener()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "Demo.h"
|
||||||
#include "BaseButtonInstance.h"
|
#include "BaseButtonInstance.h"
|
||||||
class BaseButtonInstance;
|
class BaseButtonInstance;
|
||||||
|
|
||||||
class ButtonListener
|
class ButtonListener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ButtonListener(void);
|
ButtonListener();
|
||||||
~ButtonListener(void);
|
~ButtonListener(void);
|
||||||
virtual void onButton1MouseClick(BaseButtonInstance*);
|
virtual void onButton1MouseClick(BaseButtonInstance*);
|
||||||
//virtual void onMouseOver(); //TODO
|
//virtual void onMouseOver(); //TODO
|
||||||
|
|||||||
195
CameraController.cpp
Normal file
195
CameraController.cpp
Normal file
@@ -0,0 +1,195 @@
|
|||||||
|
#include "CameraController.h"
|
||||||
|
#include "win32Defines.h"
|
||||||
|
#include <iostream>
|
||||||
|
#include "PhysicalInstance.h"
|
||||||
|
#include "Demo.h"
|
||||||
|
#include "AudioPlayer.h"
|
||||||
|
|
||||||
|
// TODO: FIX PAN AND TILT
|
||||||
|
|
||||||
|
CameraController::CameraController(){
|
||||||
|
yaw=0;
|
||||||
|
pitch=0;
|
||||||
|
moveRate=0.5f;
|
||||||
|
forwards=false;
|
||||||
|
backwards=false;
|
||||||
|
left=false;
|
||||||
|
right=false;
|
||||||
|
rightButtonHolding=false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
GCamera* CameraController::getCamera()
|
||||||
|
{
|
||||||
|
return &g3dCamera;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CameraController::lookAt(const Vector3& position) {
|
||||||
|
//g3dCamera.lookAt(position,g3dCamera.getCoordinateFrame().upVector());
|
||||||
|
|
||||||
|
const Vector3 look = (position - g3dCamera.getCoordinateFrame().translation);
|
||||||
|
yaw = aTan2(look.x, -look.z);
|
||||||
|
|
||||||
|
pitch = -aTan2(look.y, distance(look.x, look.z));
|
||||||
|
std::cout << distance(look.x, look.z) << "pitch:" << pitch << std::endl;
|
||||||
|
CoordinateFrame frame = g3dCamera.getCoordinateFrame().translation;
|
||||||
|
frame.rotation = Matrix3::fromEulerAnglesZYX(0, -yaw, -pitch);
|
||||||
|
g3dCamera.setCoordinateFrame(frame);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CameraController::setFrame(const CoordinateFrame& cf) {
|
||||||
|
Vector3 look = cf.getLookVector();
|
||||||
|
lookAt(cf.translation + look);
|
||||||
|
}
|
||||||
|
|
||||||
|
CoordinateFrame CameraController::getCoordinateFrame() {
|
||||||
|
CoordinateFrame cf;
|
||||||
|
cf.translation=translation;
|
||||||
|
cf.rotation = Matrix3::fromEulerAnglesZYX(0, -yaw, -pitch);
|
||||||
|
return cf;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CameraController::pan(int spdX, int spdY)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
bool CameraController::onMouseWheel(int x, int y, short delta)
|
||||||
|
{
|
||||||
|
CoordinateFrame frame = g3dCamera.getCoordinateFrame();
|
||||||
|
if (delta>0) { // Mouse wheel up
|
||||||
|
g3dCamera.setCoordinateFrame(g3dCamera.getCoordinateFrame() + frame.lookVector()*2);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
g3dCamera.setCoordinateFrame(g3dCamera.getCoordinateFrame() - frame.lookVector()*2);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
void CameraController::panRight()
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CameraController::tiltUp()
|
||||||
|
{
|
||||||
|
//CoordinateFrame frame = CoordinateFrame(g3dCamera.getCoordinateFrame().rotation, g3dCamera.getCoordinateFrame().translation);
|
||||||
|
Vector3 camerapoint = frame.translation;
|
||||||
|
|
||||||
|
Vector3 focalPoint = camerapoint + frame.lookVector() * 25;
|
||||||
|
float distance = pow(pow((double)focalPoint.x - (double)camerapoint.x, 2) + pow((double)camerapoint.y - (double)camerapoint.y, 2) + pow((double)focalPoint.z - (double)camerapoint.z, 2), 0.5);
|
||||||
|
float x = distance * cos(22.5 * G3D::pi() / 180) + focalPoint.x;
|
||||||
|
float z = distance * sin(22.5 * G3D::pi() / 180) + focalPoint.z;
|
||||||
|
camerapoint = Vector3(camerapoint.x, camerapoint.y+2, camerapoint.z);
|
||||||
|
|
||||||
|
CoordinateFrame newFrame = CoordinateFrame(camerapoint);
|
||||||
|
newFrame.lookAt(focalPoint);
|
||||||
|
cameraPos = camerapoint;
|
||||||
|
frame = newFrame;
|
||||||
|
}
|
||||||
|
void CameraController::tiltDown()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
void CameraController::centerCamera(Instance* selection)
|
||||||
|
{
|
||||||
|
CoordinateFrame frame = CoordinateFrame(g3dCamera.getCoordinateFrame().translation);
|
||||||
|
if(selection == NULL)
|
||||||
|
lookAt(Vector3(0,0,0));
|
||||||
|
else
|
||||||
|
lookAt(((PhysicalInstance*)selection)->getPosition()/2);
|
||||||
|
//g3dCamera.setCoordinateFrame(frame);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CameraController::update(Demo* demo)
|
||||||
|
{
|
||||||
|
|
||||||
|
Vector3 cameraPos = g3dCamera.getCoordinateFrame().translation;
|
||||||
|
CoordinateFrame frame = g3dCamera.getCoordinateFrame();
|
||||||
|
//CoordinateFrame cf = getCoordinateFrame();
|
||||||
|
|
||||||
|
if(GetHoldKeyState('U')) {
|
||||||
|
forwards = true;
|
||||||
|
}
|
||||||
|
if(GetHoldKeyState('J')) {
|
||||||
|
backwards = true;
|
||||||
|
}
|
||||||
|
if(GetHoldKeyState('H')) {
|
||||||
|
left = true;
|
||||||
|
}
|
||||||
|
if(GetHoldKeyState('K')) {
|
||||||
|
right = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(forwards) {
|
||||||
|
forwards = false;
|
||||||
|
frame.translation += frame.lookVector()*moveRate;
|
||||||
|
}
|
||||||
|
else if(backwards) {
|
||||||
|
backwards = false;
|
||||||
|
frame.translation -= frame.lookVector()*moveRate;
|
||||||
|
}
|
||||||
|
if(left) {
|
||||||
|
left = false;
|
||||||
|
frame.translation += frame.leftVector()*moveRate;
|
||||||
|
}
|
||||||
|
else if(right) {
|
||||||
|
right = false;
|
||||||
|
frame.translation += frame.rightVector()*moveRate;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(rightButtonHolding) {
|
||||||
|
POINT mouse;
|
||||||
|
GetCursorPos(&mouse);
|
||||||
|
|
||||||
|
yaw+=(mouse.x-oldDesktopMouse.x)/100.f;
|
||||||
|
pitch+=(mouse.y-oldDesktopMouse.y)/100.f;
|
||||||
|
|
||||||
|
SetCursorPos(oldDesktopMouse.x,oldDesktopMouse.y);
|
||||||
|
//frame.translation=cameraPos;
|
||||||
|
frame.rotation = Matrix3::fromEulerAnglesZYX(0, -yaw, -pitch);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(GetHoldKeyState(VK_RSHIFT) || GetHoldKeyState(VK_LSHIFT)) {
|
||||||
|
moveRate = 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
moveRate = 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(GetHoldKeyState(VK_RBUTTON))
|
||||||
|
{
|
||||||
|
if (rightButtonHolding==false)
|
||||||
|
{
|
||||||
|
GetCursorPos(&oldDesktopMouse);
|
||||||
|
rightButtonHolding = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rightButtonHolding = false;
|
||||||
|
}
|
||||||
|
g3dCamera.setCoordinateFrame(frame);
|
||||||
|
}
|
||||||
|
|
||||||
43
CameraController.h
Normal file
43
CameraController.h
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <G3DAll.h>
|
||||||
|
#include "Instance.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class Demo;
|
||||||
|
|
||||||
|
class CameraController {
|
||||||
|
public:
|
||||||
|
CameraController();
|
||||||
|
G3D::CoordinateFrame getCoordinateFrame();
|
||||||
|
|
||||||
|
void setFrame(const CoordinateFrame& cf);
|
||||||
|
void lookAt(const Vector3& position);
|
||||||
|
void pan(int spdX,int spdY);
|
||||||
|
void update(Demo* demo);
|
||||||
|
void centerCamera(Instance* selection);
|
||||||
|
void panLeft();
|
||||||
|
void panRight();
|
||||||
|
void tiltUp();
|
||||||
|
void tiltDown();
|
||||||
|
bool onMouseWheel(int x, int y, short delta);
|
||||||
|
GCamera* getCamera();
|
||||||
|
private:
|
||||||
|
Vector3 translation;
|
||||||
|
Vector3 focusPosition;
|
||||||
|
float yaw;
|
||||||
|
float pitch;
|
||||||
|
float moveRate;
|
||||||
|
bool forwards;
|
||||||
|
bool backwards;
|
||||||
|
bool left;
|
||||||
|
bool right;
|
||||||
|
bool rightButtonHolding;
|
||||||
|
//bool centerCam;
|
||||||
|
//bool panRight;
|
||||||
|
//bool panLeft;
|
||||||
|
//bool tiltUp;
|
||||||
|
POINT oldDesktopMouse;
|
||||||
|
GCamera g3dCamera;
|
||||||
|
std::string cameraSound;
|
||||||
|
};
|
||||||
@@ -60,6 +60,16 @@ Vector2 DataModelInstance::getMousePos()
|
|||||||
{
|
{
|
||||||
return Vector2(mousex,mousey);
|
return Vector2(mousex,mousey);
|
||||||
}
|
}
|
||||||
|
void DataModelInstance::setMousePos(int x,int y)
|
||||||
|
{
|
||||||
|
mousex=x;
|
||||||
|
mousey=y;
|
||||||
|
}
|
||||||
|
void DataModelInstance::setMousePos(Vector2 pos)
|
||||||
|
{
|
||||||
|
mousex=pos.x;
|
||||||
|
mousey=pos.y;
|
||||||
|
}
|
||||||
Instance* DataModelInstance::getGuiRoot()
|
Instance* DataModelInstance::getGuiRoot()
|
||||||
{
|
{
|
||||||
return guiRoot;
|
return guiRoot;
|
||||||
|
|||||||
@@ -17,5 +17,7 @@ public:
|
|||||||
float mousex;
|
float mousex;
|
||||||
float mousey;
|
float mousey;
|
||||||
Vector2 getMousePos();
|
Vector2 getMousePos();
|
||||||
|
void setMousePos(int x,int y);
|
||||||
|
void setMousePos(Vector2 pos);
|
||||||
bool mouseButton1Down;
|
bool mouseButton1Down;
|
||||||
};
|
};
|
||||||
|
|||||||
37
Demo.h
Normal file
37
Demo.h
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <G3DAll.h>
|
||||||
|
#include "CameraController.h"
|
||||||
|
|
||||||
|
class Demo : public GApp {
|
||||||
|
public:
|
||||||
|
Demo(const GAppSettings& settings,Win32Window* wind);
|
||||||
|
virtual ~Demo() {}
|
||||||
|
virtual void exitApplication();
|
||||||
|
virtual void onInit();
|
||||||
|
virtual void onLogic();
|
||||||
|
virtual void onNetwork();
|
||||||
|
virtual void onSimulation(RealTime rdt, SimTime sdt, SimTime idt);
|
||||||
|
virtual void onGraphics(RenderDevice* rd);
|
||||||
|
virtual void onUserInput(UserInput* ui);
|
||||||
|
virtual void onCleanup();
|
||||||
|
|
||||||
|
Instance* getSelection();
|
||||||
|
void QuitApp();
|
||||||
|
void onKeyPressed(int key);
|
||||||
|
void onKeyUp(int key);
|
||||||
|
void onMouseLeftPressed(int x, int y);
|
||||||
|
void onMouseLeftUp(int x, int y);
|
||||||
|
void onMouseRightPressed(int x, int y);
|
||||||
|
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();
|
||||||
|
HWND hWndMain;
|
||||||
|
SkyRef sky;
|
||||||
|
bool quit;
|
||||||
|
bool rightButtonHolding;
|
||||||
|
void main();
|
||||||
|
};
|
||||||
236
main.cpp
236
main.cpp
@@ -21,11 +21,14 @@
|
|||||||
#include "TextButtonInstance.h"
|
#include "TextButtonInstance.h"
|
||||||
#include "ImageButtonInstance.h"
|
#include "ImageButtonInstance.h"
|
||||||
#include "DataModelInstance.h"
|
#include "DataModelInstance.h"
|
||||||
|
#include "CameraController.h"
|
||||||
#include "AudioPlayer.h"
|
#include "AudioPlayer.h"
|
||||||
#include "Globals.h"
|
#include "Globals.h"
|
||||||
|
#include "Demo.h"
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
|
|
||||||
#if G3D_VER < 61000
|
#if G3D_VER < 61000
|
||||||
#error Requires G3D 6.10
|
#error Requires G3D 6.10
|
||||||
#endif
|
#endif
|
||||||
@@ -70,6 +73,8 @@ static bool tiltUp = false;
|
|||||||
static const int CURSOR = 0;
|
static const int CURSOR = 0;
|
||||||
static const int ARROWS = 1;
|
static const int ARROWS = 1;
|
||||||
static const int RESIZE = 2;
|
static const int RESIZE = 2;
|
||||||
|
static POINT oldGlobalMouse;
|
||||||
|
|
||||||
static int mode = CURSOR;
|
static int mode = CURSOR;
|
||||||
bool dragging = false;
|
bool dragging = false;
|
||||||
Vector3 cameraPos = Vector3(0,2,10);
|
Vector3 cameraPos = Vector3(0,2,10);
|
||||||
@@ -77,44 +82,13 @@ Vector2 oldMouse = Vector2(0,0);
|
|||||||
float moveRate = 0.5;
|
float moveRate = 0.5;
|
||||||
Instance* selectedInstance = NULL;
|
Instance* selectedInstance = NULL;
|
||||||
|
|
||||||
class Demo : public GApp {
|
|
||||||
public:
|
|
||||||
Demo(const GAppSettings& settings,Win32Window* wind);
|
|
||||||
|
|
||||||
virtual void exitApplication();
|
|
||||||
virtual ~Demo() {}
|
|
||||||
virtual void onInit();
|
|
||||||
virtual void onLogic();
|
|
||||||
virtual void onNetwork();
|
|
||||||
virtual void onSimulation(RealTime rdt, SimTime sdt, SimTime idt);
|
|
||||||
virtual void onGraphics(RenderDevice* rd);
|
|
||||||
virtual void onUserInput(UserInput* ui);
|
|
||||||
virtual void onCleanup();
|
|
||||||
|
|
||||||
void QuitApp();
|
|
||||||
void onKeyPressed(int key);
|
|
||||||
void onKeyUp(int key);
|
|
||||||
void onMouseLeftPressed(int x, int y);
|
|
||||||
void onMouseLeftUp(int x, int y);
|
|
||||||
void onMouseRightPressed(int x, int y);
|
|
||||||
void onMouseRightUp(int x, int y);
|
|
||||||
void onMouseMoved(int x, int y);
|
|
||||||
void onMouseWheel(int x, int y, short delta);
|
|
||||||
|
|
||||||
private:
|
|
||||||
HWND hWndMain;
|
|
||||||
SkyRef sky;
|
|
||||||
bool quit;
|
|
||||||
void main();
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
Demo *usableApp = NULL;
|
Demo *usableApp = NULL;
|
||||||
|
|
||||||
Demo::Demo(const GAppSettings& settings,Win32Window* window) : GApp(settings,window) {
|
Demo::Demo(const GAppSettings& settings,Win32Window* window) : GApp(settings,window) {
|
||||||
varStatic = VARArea::create(1024 * 1024);
|
varStatic = VARArea::create(1024 * 1024);
|
||||||
hWndMain = window->hwnd();
|
hWndMain = window->hwnd();
|
||||||
quit=false;
|
quit=false;
|
||||||
|
rightButtonHolding=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearInstances()
|
void clearInstances()
|
||||||
@@ -192,19 +166,19 @@ public:
|
|||||||
void CameraButtonListener::onButton1MouseClick(BaseButtonInstance* button)
|
void CameraButtonListener::onButton1MouseClick(BaseButtonInstance* button)
|
||||||
{
|
{
|
||||||
AudioPlayer::playSound(cameraSound);
|
AudioPlayer::playSound(cameraSound);
|
||||||
CoordinateFrame frame = usableApp->debugCamera.getCoordinateFrame();
|
CoordinateFrame frame = usableApp->cameraController.getCamera()->getCoordinateFrame();
|
||||||
if(button->name == "CenterCam")
|
if(button->name == "CenterCam")
|
||||||
centerCam = true;
|
usableApp->cameraController.centerCamera(selectedInstance);
|
||||||
else if(button->name == "ZoomIn")
|
else if(button->name == "ZoomIn")
|
||||||
cameraPos = Vector3(cameraPos.x, cameraPos.y, cameraPos.z) + frame.lookVector()*2;
|
cameraPos = Vector3(cameraPos.x, cameraPos.y, cameraPos.z) + frame.lookVector()*2;
|
||||||
else if(button->name == "ZoomOut")
|
else if(button->name == "ZoomOut")
|
||||||
cameraPos = Vector3(cameraPos.x, cameraPos.y, cameraPos.z) - frame.lookVector()*2;
|
cameraPos = Vector3(cameraPos.x, cameraPos.y, cameraPos.z) - frame.lookVector()*2;
|
||||||
else if(button->name == "PanRight")
|
else if(button->name == "PanRight")
|
||||||
panRight = true;
|
usableApp->cameraController.panRight();
|
||||||
else if(button->name == "PanLeft")
|
else if(button->name == "PanLeft")
|
||||||
panLeft = true;
|
usableApp->cameraController.panLeft();
|
||||||
else if(button->name == "TiltUp")
|
else if(button->name == "TiltUp")
|
||||||
tiltUp = true;
|
usableApp->cameraController.tiltUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
class GUDButtonListener : public ButtonListener {
|
class GUDButtonListener : public ButtonListener {
|
||||||
@@ -282,7 +256,7 @@ public:
|
|||||||
|
|
||||||
void ModeSelectionListener::onButton1MouseClick(BaseButtonInstance* button)
|
void ModeSelectionListener::onButton1MouseClick(BaseButtonInstance* button)
|
||||||
{
|
{
|
||||||
CoordinateFrame frame = usableApp->debugCamera.getCoordinateFrame();
|
//CoordinateFrame frame = usableApp->g3dCamera.getCoordinateFrame();
|
||||||
|
|
||||||
std::vector<Instance*> instances_2D = dataModel->getGuiRoot()->getAllChildren();
|
std::vector<Instance*> instances_2D = dataModel->getGuiRoot()->getAllChildren();
|
||||||
for(size_t i = 0; i < instances_2D.size(); i++)
|
for(size_t i = 0; i < instances_2D.size(); i++)
|
||||||
@@ -304,7 +278,7 @@ void ModeSelectionListener::onButton1MouseClick(BaseButtonInstance* button)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void initGUI()
|
void Demo::initGUI()
|
||||||
{
|
{
|
||||||
TextButtonInstance* button = makeTextButton();
|
TextButtonInstance* button = makeTextButton();
|
||||||
button->boxBegin = Vector2(0, -24);
|
button->boxBegin = Vector2(0, -24);
|
||||||
@@ -637,8 +611,7 @@ void initGUI()
|
|||||||
void Demo::onInit() {
|
void Demo::onInit() {
|
||||||
|
|
||||||
// Called before Demo::run() beings
|
// Called before Demo::run() beings
|
||||||
|
cameraController.getCamera()->setCoordinateFrame(cameraPos);
|
||||||
|
|
||||||
dataModel = new DataModelInstance();
|
dataModel = new DataModelInstance();
|
||||||
dataModel->setParent(NULL);
|
dataModel->setParent(NULL);
|
||||||
dataModel->name = "undefined";
|
dataModel->name = "undefined";
|
||||||
@@ -787,6 +760,10 @@ void Demo::onNetwork() {
|
|||||||
// return pow(pow((double)vector1.x - (double)vector2.x, 2) + pow((double)vector1.y - (double)vector2.y, 2) + pow((double)vector1.z - (double)vector2.z, 2), 0.5);
|
// return pow(pow((double)vector1.x - (double)vector2.x, 2) + pow((double)vector1.y - (double)vector2.y, 2) + pow((double)vector1.z - (double)vector2.z, 2), 0.5);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
Instance* Demo::getSelection()
|
||||||
|
{
|
||||||
|
return selectedInstance;
|
||||||
|
}
|
||||||
void Demo::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) {
|
void Demo::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) {
|
||||||
if(dataModel->name != title)
|
if(dataModel->name != title)
|
||||||
{
|
{
|
||||||
@@ -796,85 +773,7 @@ void Demo::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CoordinateFrame frame = debugCamera.getCoordinateFrame();
|
cameraController.update(this);
|
||||||
if(forwards)
|
|
||||||
{
|
|
||||||
forwards = false;
|
|
||||||
cameraPos = Vector3(cameraPos.x, cameraPos.y, cameraPos.z) + frame.lookVector()*moveRate;
|
|
||||||
}
|
|
||||||
else if(backwards)
|
|
||||||
{
|
|
||||||
backwards = false;
|
|
||||||
cameraPos = Vector3(cameraPos.x, cameraPos.y, cameraPos.z) - frame.lookVector()*moveRate;
|
|
||||||
}
|
|
||||||
if(left)
|
|
||||||
{
|
|
||||||
left = false;
|
|
||||||
cameraPos = Vector3(cameraPos.x, cameraPos.y, cameraPos.z) + frame.leftVector()*moveRate;
|
|
||||||
}
|
|
||||||
else if(right)
|
|
||||||
{
|
|
||||||
right = false;
|
|
||||||
cameraPos = Vector3(cameraPos.x, cameraPos.y, cameraPos.z) + frame.rightVector()*moveRate;
|
|
||||||
}
|
|
||||||
debugCamera.setPosition(cameraPos);
|
|
||||||
if(centerCam)
|
|
||||||
{
|
|
||||||
CoordinateFrame frame = CoordinateFrame(debugCamera.getCoordinateFrame().translation);
|
|
||||||
if(selectedInstance == NULL)
|
|
||||||
frame.lookAt(Vector3(0,0,0));
|
|
||||||
else
|
|
||||||
frame.lookAt(((PhysicalInstance*)selectedInstance)->getPosition());
|
|
||||||
debugController.setCoordinateFrame(frame);
|
|
||||||
centerCam = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(panRight)
|
|
||||||
{
|
|
||||||
panRight = false;
|
|
||||||
CoordinateFrame frame = debugCamera.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);
|
|
||||||
frame2 = frame2 - frame2.lookVector()*25;
|
|
||||||
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);
|
|
||||||
debugController.setCoordinateFrame(newFrame);
|
|
||||||
|
|
||||||
}
|
|
||||||
if(panLeft)
|
|
||||||
{
|
|
||||||
panLeft = false;
|
|
||||||
CoordinateFrame frame = debugCamera.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);
|
|
||||||
frame2 = frame2 - frame2.lookVector()*25;
|
|
||||||
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);
|
|
||||||
debugController.setCoordinateFrame(newFrame);
|
|
||||||
}
|
|
||||||
if(tiltUp)
|
|
||||||
{
|
|
||||||
tiltUp = false;
|
|
||||||
CoordinateFrame frame = CoordinateFrame(debugCamera.getCoordinateFrame().rotation, debugCamera.getCoordinateFrame().translation);
|
|
||||||
Vector3 camerapoint = frame.translation;
|
|
||||||
|
|
||||||
Vector3 focalPoint = camerapoint + frame.lookVector() * 25;
|
|
||||||
float distance = pow(pow((double)focalPoint.x - (double)camerapoint.x, 2) + pow((double)camerapoint.y - (double)camerapoint.y, 2) + pow((double)focalPoint.z - (double)camerapoint.z, 2), 0.5);
|
|
||||||
float x = distance * cos(22.5 * G3D::pi() / 180) + focalPoint.x;
|
|
||||||
float z = distance * sin(22.5 * G3D::pi() / 180) + focalPoint.z;
|
|
||||||
camerapoint = Vector3(camerapoint.x, camerapoint.y+2, camerapoint.z);
|
|
||||||
|
|
||||||
CoordinateFrame newFrame = CoordinateFrame(camerapoint);
|
|
||||||
newFrame.lookAt(focalPoint);
|
|
||||||
cameraPos = camerapoint;
|
|
||||||
debugController.setCoordinateFrame(newFrame);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -899,38 +798,6 @@ bool IsHolding(int button)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Demo::onUserInput(UserInput* ui) {
|
void Demo::onUserInput(UserInput* ui) {
|
||||||
if(mouseMovedBeginMotion)
|
|
||||||
{
|
|
||||||
mouseMovedBeginMotion = false;
|
|
||||||
debugController.setActive(true);
|
|
||||||
}
|
|
||||||
if(GetHoldKeyState(VK_RBUTTON))
|
|
||||||
{
|
|
||||||
oldMouse = dataModel->getMousePos();
|
|
||||||
showMouse = false;
|
|
||||||
//window()->setRelativeMousePosition(window()->width()/2, window()->height()/2);
|
|
||||||
mouseMovedBeginMotion = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//ui->setMouseXY(oldMouse);
|
|
||||||
showMouse = true;
|
|
||||||
debugController.setActive(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(GetHoldKeyState(VK_RSHIFT) || GetHoldKeyState(VK_LSHIFT))
|
|
||||||
{
|
|
||||||
moveRate = 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
moveRate = 0.5;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(GetHoldKeyState(VK_DELETE))
|
|
||||||
{
|
|
||||||
deleteInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(GetHoldKeyState(VK_LCONTROL))
|
if(GetHoldKeyState(VK_LCONTROL))
|
||||||
{
|
{
|
||||||
@@ -955,27 +822,10 @@ void Demo::onUserInput(UserInput* ui) {
|
|||||||
//dataModel->mousey = ui->getMouseY();
|
//dataModel->mousey = ui->getMouseY();
|
||||||
dataModel->mouseButton1Down = IsHolding(VK_LBUTTON);
|
dataModel->mouseButton1Down = IsHolding(VK_LBUTTON);
|
||||||
|
|
||||||
if(GetHoldKeyState('U'))
|
|
||||||
{
|
|
||||||
forwards = true;
|
|
||||||
}
|
|
||||||
if(GetHoldKeyState('J'))
|
|
||||||
{
|
|
||||||
backwards = true;
|
|
||||||
}
|
|
||||||
if(GetHoldKeyState('H'))
|
|
||||||
{
|
|
||||||
left = true;
|
|
||||||
}
|
|
||||||
if(GetHoldKeyState('K'))
|
|
||||||
{
|
|
||||||
right = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (GetHoldKeyState(VK_LBUTTON)) {
|
if (GetHoldKeyState(VK_LBUTTON)) {
|
||||||
if (dragging) {
|
if (dragging) {
|
||||||
PhysicalInstance* part = (PhysicalInstance*) selectedInstance;
|
PhysicalInstance* part = (PhysicalInstance*) selectedInstance;
|
||||||
Ray dragRay = debugCamera.worldRay(dataModel->mousex, dataModel->mousey, renderDevice->getViewport());
|
Ray dragRay = cameraController.getCamera()->worldRay(dataModel->mousex, dataModel->mousey, renderDevice->getViewport());
|
||||||
std::vector<Instance*> instances = dataModel->getWorkspace()->getAllChildren();
|
std::vector<Instance*> instances = dataModel->getWorkspace()->getAllChildren();
|
||||||
for(size_t i = 0; i < instances.size(); i++)
|
for(size_t i = 0; i < instances.size(); i++)
|
||||||
{
|
{
|
||||||
@@ -1181,11 +1031,7 @@ void Demo::onGraphics(RenderDevice* rd) {
|
|||||||
|
|
||||||
|
|
||||||
LightingParameters lighting(G3D::toSeconds(11, 00, 00, AM));
|
LightingParameters lighting(G3D::toSeconds(11, 00, 00, AM));
|
||||||
renderDevice->setProjectionAndCameraMatrix(debugCamera);
|
renderDevice->setProjectionAndCameraMatrix(*cameraController.getCamera());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Cyan background
|
// Cyan background
|
||||||
//renderDevice->setColorClearValue(Color3(0.0f, 0.5f, 1.0f));
|
//renderDevice->setColorClearValue(Color3(0.0f, 0.5f, 1.0f));
|
||||||
@@ -1195,8 +1041,6 @@ void Demo::onGraphics(RenderDevice* rd) {
|
|||||||
sky->render(renderDevice, lighting);
|
sky->render(renderDevice, lighting);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Setup lighting
|
// Setup lighting
|
||||||
renderDevice->enableLighting();
|
renderDevice->enableLighting();
|
||||||
|
|
||||||
@@ -1234,9 +1078,6 @@ void Demo::onGraphics(RenderDevice* rd) {
|
|||||||
sky->renderLensFlare(renderDevice, lighting);
|
sky->renderLensFlare(renderDevice, lighting);
|
||||||
}
|
}
|
||||||
renderDevice->push2D();
|
renderDevice->push2D();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(System::time() - 3 < messageTime)
|
if(System::time() - 3 < messageTime)
|
||||||
{
|
{
|
||||||
fntdominant->draw2D(rd, message, Vector2((rd->getWidth()/2)-(fntdominant->get2DStringBounds(message, 20).x/2),(rd->getHeight()/2)-(fntdominant->get2DStringBounds(message, 20).y/2)), 20, Color3::yellow(), Color3::black());
|
fntdominant->draw2D(rd, message, Vector2((rd->getWidth()/2)-(fntdominant->get2DStringBounds(message, 20).x/2),(rd->getHeight()/2)-(fntdominant->get2DStringBounds(message, 20).y/2)), 20, Color3::yellow(), Color3::black());
|
||||||
@@ -1289,7 +1130,6 @@ void Demo::onGraphics(RenderDevice* rd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
rd->afterPrimitive();
|
rd->afterPrimitive();
|
||||||
|
|
||||||
rd->popState();
|
rd->popState();
|
||||||
renderDevice->pop2D();
|
renderDevice->pop2D();
|
||||||
}
|
}
|
||||||
@@ -1300,6 +1140,10 @@ void Demo::onKeyPressed(int key)
|
|||||||
{
|
{
|
||||||
std::cout << "A PRESS" << std::endl;
|
std::cout << "A PRESS" << std::endl;
|
||||||
}
|
}
|
||||||
|
if(key==VK_DELETE)
|
||||||
|
{
|
||||||
|
deleteInstance();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
void Demo::onKeyUp(int key)
|
void Demo::onKeyUp(int key)
|
||||||
{
|
{
|
||||||
@@ -1330,9 +1174,9 @@ void Demo::onMouseLeftPressed(int x,int y)
|
|||||||
if(!onGUI)
|
if(!onGUI)
|
||||||
{
|
{
|
||||||
selectedInstance = NULL;
|
selectedInstance = NULL;
|
||||||
testRay = debugCamera.worldRay(dataModel->mousex, dataModel->mousey, renderDevice->getViewport());
|
testRay = cameraController.getCamera()->worldRay(dataModel->mousex, dataModel->mousey, renderDevice->getViewport());
|
||||||
float nearest=std::numeric_limits<float>::infinity();
|
float nearest=std::numeric_limits<float>::infinity();
|
||||||
Vector3 camPos = debugCamera.getCoordinateFrame().translation;
|
Vector3 camPos = cameraController.getCamera()->getCoordinateFrame().translation;
|
||||||
std::vector<Instance*> instances = dataModel->getWorkspace()->getAllChildren();
|
std::vector<Instance*> instances = dataModel->getWorkspace()->getAllChildren();
|
||||||
for(size_t i = 0; i < instances.size(); i++)
|
for(size_t i = 0; i < instances.size(); i++)
|
||||||
{
|
{
|
||||||
@@ -1386,6 +1230,7 @@ void Demo::onMouseRightUp(int x,int y)
|
|||||||
}
|
}
|
||||||
void Demo::onMouseMoved(int x,int y)
|
void Demo::onMouseMoved(int x,int y)
|
||||||
{
|
{
|
||||||
|
oldMouse = dataModel->getMousePos();
|
||||||
std::cout << "Moved: " << x << "," << y << std::endl;
|
std::cout << "Moved: " << x << "," << y << std::endl;
|
||||||
dataModel->mousex = x;
|
dataModel->mousex = x;
|
||||||
dataModel->mousey = y;
|
dataModel->mousey = y;
|
||||||
@@ -1393,17 +1238,9 @@ void Demo::onMouseMoved(int x,int y)
|
|||||||
}
|
}
|
||||||
void Demo::onMouseWheel(int x,int y,short delta)
|
void Demo::onMouseWheel(int x,int y,short delta)
|
||||||
{
|
{
|
||||||
if (delta>0) // Mouse wheel up
|
if (cameraController.onMouseWheel(x, y, delta))
|
||||||
{
|
{
|
||||||
AudioPlayer::playSound(cameraSound);
|
AudioPlayer::playSound(cameraSound);
|
||||||
CoordinateFrame frame = debugCamera.getCoordinateFrame();
|
|
||||||
cameraPos = cameraPos + frame.lookVector()*2;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
AudioPlayer::playSound(cameraSound);
|
|
||||||
CoordinateFrame frame = debugCamera.getCoordinateFrame();
|
|
||||||
cameraPos = cameraPos - frame.lookVector()*2;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1432,6 +1269,10 @@ App::~App() {
|
|||||||
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
Demo *app = (Demo *)GetWindowLongPtr(hwnd, GWL_USERDATA);
|
Demo *app = (Demo *)GetWindowLongPtr(hwnd, GWL_USERDATA);
|
||||||
|
if (app==NULL)
|
||||||
|
{
|
||||||
|
return DefWindowProc(hwnd, msg, wParam, lParam);
|
||||||
|
}
|
||||||
switch(msg)
|
switch(msg)
|
||||||
{
|
{
|
||||||
case WM_QUIT:
|
case WM_QUIT:
|
||||||
@@ -1484,10 +1325,10 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||||||
return DefWindowProc(hwnd, msg, wParam, lParam);
|
return DefWindowProc(hwnd, msg, wParam, lParam);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
LRESULT CALLBACK ToolProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
LRESULT CALLBACK ToolProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
//Demo *app = (Demo *)GetWindowLongPtr(hwnd, GWL_USERDATA);
|
//Demo *app = (Demo *)GetWindowLongPtr(hwnd, GWL_USERDATA);
|
||||||
@@ -1525,7 +1366,7 @@ bool createWindowClass(const char* name,WNDPROC proc,HMODULE hInstance)
|
|||||||
|
|
||||||
void Demo::main() {
|
void Demo::main() {
|
||||||
usableApp = this;
|
usableApp = this;
|
||||||
setDebugMode(true);
|
setDebugMode(false);
|
||||||
debugController.setActive(false);
|
debugController.setActive(false);
|
||||||
/*
|
/*
|
||||||
if (!createWindowClass("ToolWindowClass",ToolProc,GetModuleHandle(0)))
|
if (!createWindowClass("ToolWindowClass",ToolProc,GetModuleHandle(0)))
|
||||||
@@ -1586,9 +1427,9 @@ void Demo::main() {
|
|||||||
m_userInputWatch.tock();
|
m_userInputWatch.tock();
|
||||||
|
|
||||||
m_simulationWatch.tick();
|
m_simulationWatch.tick();
|
||||||
debugController.doSimulation(clamp(timeStep, 0.0, 0.1));
|
//debugController.doSimulation(clamp(timeStep, 0.0, 0.1));
|
||||||
debugCamera.setCoordinateFrame
|
//g3dCamera.setCoordinateFrame
|
||||||
(debugController.getCoordinateFrame());
|
//(debugController.getCoordinateFrame());
|
||||||
|
|
||||||
double rate = simTimeRate;
|
double rate = simTimeRate;
|
||||||
RealTime rdt = timeStep;
|
RealTime rdt = timeStep;
|
||||||
@@ -1626,6 +1467,7 @@ void Demo::main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
onCleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Demo::QuitApp()
|
void Demo::QuitApp()
|
||||||
|
|||||||
4
win32Defines.h
Normal file
4
win32Defines.h
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
#define GetHoldKeyState(nVirtKey) (GetKeyState(nVirtKey)>>1)
|
||||||
Reference in New Issue
Block a user