Custom unstable camera added.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#include "ButtonListener.h"
|
||||
|
||||
|
||||
ButtonListener::ButtonListener(void)
|
||||
ButtonListener::ButtonListener()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
#pragma once
|
||||
#include "Demo.h"
|
||||
#include "BaseButtonInstance.h"
|
||||
class BaseButtonInstance;
|
||||
|
||||
class ButtonListener
|
||||
{
|
||||
public:
|
||||
ButtonListener(void);
|
||||
ButtonListener();
|
||||
~ButtonListener(void);
|
||||
virtual void onButton1MouseClick(BaseButtonInstance*);
|
||||
//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);
|
||||
}
|
||||
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()
|
||||
{
|
||||
return guiRoot;
|
||||
|
||||
@@ -17,5 +17,7 @@ public:
|
||||
float mousex;
|
||||
float mousey;
|
||||
Vector2 getMousePos();
|
||||
void setMousePos(int x,int y);
|
||||
void setMousePos(Vector2 pos);
|
||||
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();
|
||||
};
|
||||
382
main.cpp
382
main.cpp
@@ -21,11 +21,14 @@
|
||||
#include "TextButtonInstance.h"
|
||||
#include "ImageButtonInstance.h"
|
||||
#include "DataModelInstance.h"
|
||||
#include "CameraController.h"
|
||||
#include "AudioPlayer.h"
|
||||
#include "Globals.h"
|
||||
#include "Demo.h"
|
||||
#include <limits.h>
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
#if G3D_VER < 61000
|
||||
#error Requires G3D 6.10
|
||||
#endif
|
||||
@@ -70,6 +73,8 @@ static bool tiltUp = false;
|
||||
static const int CURSOR = 0;
|
||||
static const int ARROWS = 1;
|
||||
static const int RESIZE = 2;
|
||||
static POINT oldGlobalMouse;
|
||||
|
||||
static int mode = CURSOR;
|
||||
bool dragging = false;
|
||||
Vector3 cameraPos = Vector3(0,2,10);
|
||||
@@ -77,44 +82,13 @@ Vector2 oldMouse = Vector2(0,0);
|
||||
float moveRate = 0.5;
|
||||
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::Demo(const GAppSettings& settings,Win32Window* window) : GApp(settings,window) {
|
||||
varStatic = VARArea::create(1024 * 1024);
|
||||
hWndMain = window->hwnd();
|
||||
quit=false;
|
||||
rightButtonHolding=false;
|
||||
}
|
||||
|
||||
void clearInstances()
|
||||
@@ -192,19 +166,19 @@ public:
|
||||
void CameraButtonListener::onButton1MouseClick(BaseButtonInstance* button)
|
||||
{
|
||||
AudioPlayer::playSound(cameraSound);
|
||||
CoordinateFrame frame = usableApp->debugCamera.getCoordinateFrame();
|
||||
CoordinateFrame frame = usableApp->cameraController.getCamera()->getCoordinateFrame();
|
||||
if(button->name == "CenterCam")
|
||||
centerCam = true;
|
||||
usableApp->cameraController.centerCamera(selectedInstance);
|
||||
else if(button->name == "ZoomIn")
|
||||
cameraPos = Vector3(cameraPos.x, cameraPos.y, cameraPos.z) + frame.lookVector()*2;
|
||||
else if(button->name == "ZoomOut")
|
||||
cameraPos = Vector3(cameraPos.x, cameraPos.y, cameraPos.z) - frame.lookVector()*2;
|
||||
else if(button->name == "PanRight")
|
||||
panRight = true;
|
||||
usableApp->cameraController.panRight();
|
||||
else if(button->name == "PanLeft")
|
||||
panLeft = true;
|
||||
usableApp->cameraController.panLeft();
|
||||
else if(button->name == "TiltUp")
|
||||
tiltUp = true;
|
||||
usableApp->cameraController.tiltUp();
|
||||
}
|
||||
|
||||
class GUDButtonListener : public ButtonListener {
|
||||
@@ -282,7 +256,7 @@ public:
|
||||
|
||||
void ModeSelectionListener::onButton1MouseClick(BaseButtonInstance* button)
|
||||
{
|
||||
CoordinateFrame frame = usableApp->debugCamera.getCoordinateFrame();
|
||||
//CoordinateFrame frame = usableApp->g3dCamera.getCoordinateFrame();
|
||||
|
||||
std::vector<Instance*> instances_2D = dataModel->getGuiRoot()->getAllChildren();
|
||||
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();
|
||||
button->boxBegin = Vector2(0, -24);
|
||||
@@ -637,8 +611,7 @@ void initGUI()
|
||||
void Demo::onInit() {
|
||||
|
||||
// Called before Demo::run() beings
|
||||
|
||||
|
||||
cameraController.getCamera()->setCoordinateFrame(cameraPos);
|
||||
dataModel = new DataModelInstance();
|
||||
dataModel->setParent(NULL);
|
||||
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);
|
||||
//}
|
||||
|
||||
Instance* Demo::getSelection()
|
||||
{
|
||||
return selectedInstance;
|
||||
}
|
||||
void Demo::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) {
|
||||
if(dataModel->name != title)
|
||||
{
|
||||
@@ -796,86 +773,8 @@ void Demo::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) {
|
||||
|
||||
}
|
||||
|
||||
CoordinateFrame frame = debugCamera.getCoordinateFrame();
|
||||
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);
|
||||
cameraController.update(this);
|
||||
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*double getOSVersion() {
|
||||
@@ -899,38 +798,6 @@ bool IsHolding(int button)
|
||||
}
|
||||
|
||||
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))
|
||||
{
|
||||
@@ -955,27 +822,10 @@ void Demo::onUserInput(UserInput* ui) {
|
||||
//dataModel->mousey = ui->getMouseY();
|
||||
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 (dragging) {
|
||||
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();
|
||||
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));
|
||||
renderDevice->setProjectionAndCameraMatrix(debugCamera);
|
||||
|
||||
|
||||
|
||||
|
||||
renderDevice->setProjectionAndCameraMatrix(*cameraController.getCamera());
|
||||
|
||||
// Cyan background
|
||||
//renderDevice->setColorClearValue(Color3(0.0f, 0.5f, 1.0f));
|
||||
@@ -1194,39 +1040,37 @@ void Demo::onGraphics(RenderDevice* rd) {
|
||||
if (sky.notNull()) {
|
||||
sky->render(renderDevice, lighting);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Setup lighting
|
||||
renderDevice->enableLighting();
|
||||
|
||||
renderDevice->setShadeMode(RenderDevice::SHADE_SMOOTH);
|
||||
renderDevice->setAmbientLightColor(Color3(1,1,1));
|
||||
renderDevice->setShadeMode(RenderDevice::SHADE_SMOOTH);
|
||||
renderDevice->setAmbientLightColor(Color3(1,1,1));
|
||||
|
||||
renderDevice->setLight(0, GLight::directional(lighting.lightDirection, lighting.lightColor));
|
||||
renderDevice->setAmbientLightColor(lighting.ambient);
|
||||
renderDevice->setLight(0, GLight::directional(lighting.lightDirection, lighting.lightColor));
|
||||
renderDevice->setAmbientLightColor(lighting.ambient);
|
||||
|
||||
|
||||
dataModel->getWorkspace()->render(rd);
|
||||
if(selectedInstance != NULL)
|
||||
{
|
||||
PhysicalInstance* part = (PhysicalInstance*)selectedInstance;
|
||||
Vector3 size = part->getSize();
|
||||
Vector3 pos = part->getPosition();
|
||||
drawOutline(Vector3(0+size.x/4, 0+size.y/4, 0+size.z/4) ,Vector3(0-size.x/4,0-size.y/4,0-size.z/4), rd, lighting, Vector3(size.x/2, size.y/2, size.z/2), Vector3(pos.x/2, pos.y/2, pos.z/2), part->getCFrameRenderBased());
|
||||
}
|
||||
|
||||
dataModel->getWorkspace()->render(rd);
|
||||
if(selectedInstance != NULL)
|
||||
{
|
||||
PhysicalInstance* part = (PhysicalInstance*)selectedInstance;
|
||||
Vector3 size = part->getSize();
|
||||
Vector3 pos = part->getPosition();
|
||||
drawOutline(Vector3(0+size.x/4, 0+size.y/4, 0+size.z/4) ,Vector3(0-size.x/4,0-size.y/4,0-size.z/4), rd, lighting, Vector3(size.x/2, size.y/2, size.z/2), Vector3(pos.x/2, pos.y/2, pos.z/2), part->getCFrameRenderBased());
|
||||
}
|
||||
|
||||
|
||||
//Vector3 gamepoint = Vector3(0, 5, 0);
|
||||
//Vector3 camerapoint = rd->getCameraToWorldMatrix().translation;
|
||||
//float distance = pow(pow((double)gamepoint.x - (double)camerapoint.x, 2) + pow((double)gamepoint.y - (double)camerapoint.y, 2) + pow((double)gamepoint.z - (double)camerapoint.z, 2), 0.5);
|
||||
//if(distance < 50 && distance > -50)
|
||||
|
||||
//{
|
||||
// if(distance < 0)
|
||||
// distance = distance*-1;
|
||||
// fntdominant->draw3D(rd, "Testing", CoordinateFrame(rd->getCameraToWorldMatrix().rotation, gamepoint), 0.04*distance, Color3::yellow(), Color3::black(), G3D::GFont::XALIGN_CENTER, G3D::GFont::YALIGN_CENTER);
|
||||
//}
|
||||
//Vector3 gamepoint = Vector3(0, 5, 0);
|
||||
//Vector3 camerapoint = rd->getCameraToWorldMatrix().translation;
|
||||
//float distance = pow(pow((double)gamepoint.x - (double)camerapoint.x, 2) + pow((double)gamepoint.y - (double)camerapoint.y, 2) + pow((double)gamepoint.z - (double)camerapoint.z, 2), 0.5);
|
||||
//if(distance < 50 && distance > -50)
|
||||
|
||||
//{
|
||||
// if(distance < 0)
|
||||
// distance = distance*-1;
|
||||
// fntdominant->draw3D(rd, "Testing", CoordinateFrame(rd->getCameraToWorldMatrix().rotation, gamepoint), 0.04*distance, Color3::yellow(), Color3::black(), G3D::GFont::XALIGN_CENTER, G3D::GFont::YALIGN_CENTER);
|
||||
//}
|
||||
|
||||
renderDevice->disableLighting();
|
||||
|
||||
@@ -1234,63 +1078,59 @@ void Demo::onGraphics(RenderDevice* rd) {
|
||||
sky->renderLensFlare(renderDevice, lighting);
|
||||
}
|
||||
renderDevice->push2D();
|
||||
|
||||
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
std::stringstream stream;
|
||||
stream << std::fixed << std::setprecision(1) << dataModel->getWorkspace()->timer;
|
||||
fntdominant->draw2D(rd, "Timer: " + stream.str(), Vector2(rd->getWidth() - 120, 25), 20, Color3::fromARGB(0x81C518), Color3::black());
|
||||
fntdominant->draw2D(rd, "Score: " + Convert(dataModel->getWorkspace()->score), Vector2(rd->getWidth() - 120, 50), 20, Color3::fromARGB(0x81C518), Color3::black());
|
||||
|
||||
//GUI Boxes
|
||||
Draw::box(G3D::Box(Vector3(0,25,0),Vector3(80,355,0)),rd,Color4(0.6F,0.6F,0.6F,0.4F), Color4(0,0,0,0));
|
||||
Draw::box(G3D::Box(Vector3(rd->getWidth() - 120,rd->getHeight() - 120,0),Vector3(rd->getWidth(),rd->getHeight(),0)),rd,Color4(0.6F,0.6F,0.6F,0.4F), Color4(0,0,0,0));
|
||||
|
||||
//Camera menu title
|
||||
fntlighttrek->draw2D(rd, "CameraMenu", Vector2(rd->getWidth()-(fntlighttrek->get2DStringBounds("CameraMenu", 14).x+1),rd->getHeight() - 120), 14, Color3::white(), Color4(0.5F,0.5F,0.5F,0.5F));
|
||||
|
||||
//Tools menu
|
||||
Draw::box(G3D::Box(Vector3(5, 210,0),Vector3(75, 210,0)),rd,Color4(0.6F,0.6F,0.6F,0.4F), Color4(0.6F,0.6F,0.6F,0.4F));
|
||||
fntlighttrek->draw2D(rd,"MENU", Vector2(10,332), 14, Color3::white(), Color4(0.5F,0.5F,0.5F,0.5F));
|
||||
|
||||
|
||||
drawButtons(rd);
|
||||
dataModel->drawMessage(rd);
|
||||
rd->pushState();
|
||||
rd->beforePrimitive();
|
||||
|
||||
if(showMouse && mouseOnScreen)
|
||||
if(System::time() - 3 < messageTime)
|
||||
{
|
||||
glEnable( GL_TEXTURE_2D );
|
||||
glEnable(GL_BLEND);// you enable blending function
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
|
||||
glBindTexture( GL_TEXTURE_2D, cursorid);
|
||||
|
||||
|
||||
glBegin( GL_QUADS );
|
||||
glTexCoord2d(0.0,0.0);
|
||||
glVertex2f(mousepos.x-40, mousepos.y-40);
|
||||
glTexCoord2d( 1.0,0.0 );
|
||||
glVertex2f(mousepos.x+40, mousepos.y-40);
|
||||
glTexCoord2d(1.0,1.0 );
|
||||
glVertex2f(mousepos.x+40, mousepos.y+40 );
|
||||
glTexCoord2d( 0.0,1.0 );
|
||||
glVertex2f( mousepos.x-40, mousepos.y+40 );
|
||||
glEnd();
|
||||
|
||||
glDisable( GL_TEXTURE_2D );
|
||||
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());
|
||||
}
|
||||
|
||||
rd->afterPrimitive();
|
||||
std::stringstream stream;
|
||||
stream << std::fixed << std::setprecision(1) << dataModel->getWorkspace()->timer;
|
||||
fntdominant->draw2D(rd, "Timer: " + stream.str(), Vector2(rd->getWidth() - 120, 25), 20, Color3::fromARGB(0x81C518), Color3::black());
|
||||
fntdominant->draw2D(rd, "Score: " + Convert(dataModel->getWorkspace()->score), Vector2(rd->getWidth() - 120, 50), 20, Color3::fromARGB(0x81C518), Color3::black());
|
||||
|
||||
//GUI Boxes
|
||||
Draw::box(G3D::Box(Vector3(0,25,0),Vector3(80,355,0)),rd,Color4(0.6F,0.6F,0.6F,0.4F), Color4(0,0,0,0));
|
||||
Draw::box(G3D::Box(Vector3(rd->getWidth() - 120,rd->getHeight() - 120,0),Vector3(rd->getWidth(),rd->getHeight(),0)),rd,Color4(0.6F,0.6F,0.6F,0.4F), Color4(0,0,0,0));
|
||||
|
||||
//Camera menu title
|
||||
fntlighttrek->draw2D(rd, "CameraMenu", Vector2(rd->getWidth()-(fntlighttrek->get2DStringBounds("CameraMenu", 14).x+1),rd->getHeight() - 120), 14, Color3::white(), Color4(0.5F,0.5F,0.5F,0.5F));
|
||||
|
||||
rd->popState();
|
||||
//Tools menu
|
||||
Draw::box(G3D::Box(Vector3(5, 210,0),Vector3(75, 210,0)),rd,Color4(0.6F,0.6F,0.6F,0.4F), Color4(0.6F,0.6F,0.6F,0.4F));
|
||||
fntlighttrek->draw2D(rd,"MENU", Vector2(10,332), 14, Color3::white(), Color4(0.5F,0.5F,0.5F,0.5F));
|
||||
|
||||
|
||||
drawButtons(rd);
|
||||
dataModel->drawMessage(rd);
|
||||
rd->pushState();
|
||||
rd->beforePrimitive();
|
||||
|
||||
if(showMouse && mouseOnScreen)
|
||||
{
|
||||
glEnable( GL_TEXTURE_2D );
|
||||
glEnable(GL_BLEND);// you enable blending function
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
|
||||
glBindTexture( GL_TEXTURE_2D, cursorid);
|
||||
|
||||
|
||||
glBegin( GL_QUADS );
|
||||
glTexCoord2d(0.0,0.0);
|
||||
glVertex2f(mousepos.x-40, mousepos.y-40);
|
||||
glTexCoord2d( 1.0,0.0 );
|
||||
glVertex2f(mousepos.x+40, mousepos.y-40);
|
||||
glTexCoord2d(1.0,1.0 );
|
||||
glVertex2f(mousepos.x+40, mousepos.y+40 );
|
||||
glTexCoord2d( 0.0,1.0 );
|
||||
glVertex2f( mousepos.x-40, mousepos.y+40 );
|
||||
glEnd();
|
||||
|
||||
glDisable( GL_TEXTURE_2D );
|
||||
}
|
||||
|
||||
rd->afterPrimitive();
|
||||
rd->popState();
|
||||
renderDevice->pop2D();
|
||||
}
|
||||
|
||||
@@ -1300,6 +1140,10 @@ void Demo::onKeyPressed(int key)
|
||||
{
|
||||
std::cout << "A PRESS" << std::endl;
|
||||
}
|
||||
if(key==VK_DELETE)
|
||||
{
|
||||
deleteInstance();
|
||||
}
|
||||
}
|
||||
void Demo::onKeyUp(int key)
|
||||
{
|
||||
@@ -1330,9 +1174,9 @@ void Demo::onMouseLeftPressed(int x,int y)
|
||||
if(!onGUI)
|
||||
{
|
||||
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();
|
||||
Vector3 camPos = debugCamera.getCoordinateFrame().translation;
|
||||
Vector3 camPos = cameraController.getCamera()->getCoordinateFrame().translation;
|
||||
std::vector<Instance*> instances = dataModel->getWorkspace()->getAllChildren();
|
||||
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)
|
||||
{
|
||||
oldMouse = dataModel->getMousePos();
|
||||
std::cout << "Moved: " << x << "," << y << std::endl;
|
||||
dataModel->mousex = x;
|
||||
dataModel->mousey = y;
|
||||
@@ -1393,17 +1238,9 @@ void Demo::onMouseMoved(int x,int y)
|
||||
}
|
||||
void Demo::onMouseWheel(int x,int y,short delta)
|
||||
{
|
||||
if (delta>0) // Mouse wheel up
|
||||
if (cameraController.onMouseWheel(x, y, delta))
|
||||
{
|
||||
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)
|
||||
{
|
||||
Demo *app = (Demo *)GetWindowLongPtr(hwnd, GWL_USERDATA);
|
||||
if (app==NULL)
|
||||
{
|
||||
return DefWindowProc(hwnd, msg, wParam, lParam);
|
||||
}
|
||||
switch(msg)
|
||||
{
|
||||
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 0;
|
||||
}
|
||||
|
||||
|
||||
LRESULT CALLBACK ToolProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
//Demo *app = (Demo *)GetWindowLongPtr(hwnd, GWL_USERDATA);
|
||||
@@ -1525,7 +1366,7 @@ bool createWindowClass(const char* name,WNDPROC proc,HMODULE hInstance)
|
||||
|
||||
void Demo::main() {
|
||||
usableApp = this;
|
||||
setDebugMode(true);
|
||||
setDebugMode(false);
|
||||
debugController.setActive(false);
|
||||
/*
|
||||
if (!createWindowClass("ToolWindowClass",ToolProc,GetModuleHandle(0)))
|
||||
@@ -1586,9 +1427,9 @@ void Demo::main() {
|
||||
m_userInputWatch.tock();
|
||||
|
||||
m_simulationWatch.tick();
|
||||
debugController.doSimulation(clamp(timeStep, 0.0, 0.1));
|
||||
debugCamera.setCoordinateFrame
|
||||
(debugController.getCoordinateFrame());
|
||||
//debugController.doSimulation(clamp(timeStep, 0.0, 0.1));
|
||||
//g3dCamera.setCoordinateFrame
|
||||
//(debugController.getCoordinateFrame());
|
||||
|
||||
double rate = simTimeRate;
|
||||
RealTime rdt = timeStep;
|
||||
@@ -1626,6 +1467,7 @@ void Demo::main() {
|
||||
}
|
||||
}
|
||||
}
|
||||
onCleanup();
|
||||
}
|
||||
|
||||
void Demo::QuitApp()
|
||||
@@ -1677,7 +1519,7 @@ int main(int argc, char** argv) {
|
||||
return 0;
|
||||
}
|
||||
ShowWindow(hwndMain, SW_SHOW);
|
||||
|
||||
|
||||
Win32Window* win32Window = Win32Window::create(settings.window,hwndMain);
|
||||
Demo demo = Demo(settings,win32Window);
|
||||
|
||||
|
||||
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