Mouse hover, and part selection is now functional.

This commit is contained in:
MusicalProgrammer
2018-05-31 19:59:17 -04:00
parent 5aaf134ba8
commit 8816e96ba3
3 changed files with 41 additions and 34 deletions

View File

@@ -56,7 +56,10 @@ WorkspaceInstance* DataModelInstance::getWorkspace()
{ {
return workspace; return workspace;
} }
Vector2 DataModelInstance::getMousePos()
{
return Vector2(mousex,mousey);
}
Instance* DataModelInstance::getGuiRoot() Instance* DataModelInstance::getGuiRoot()
{ {
return guiRoot; return guiRoot;

View File

@@ -16,5 +16,6 @@ public:
Instance* getGuiRoot(); Instance* getGuiRoot();
float mousex; float mousex;
float mousey; float mousey;
Vector2 getMousePos();
bool mouseButton1Down; bool mouseButton1Down;
}; };

View File

@@ -98,6 +98,7 @@ class Demo : public GApp {
void onMouseLeftUp(int x, int y); void onMouseLeftUp(int x, int y);
void onMouseRightPressed(int x, int y); void onMouseRightPressed(int x, int y);
void onMouseRightUp(int x, int y); void onMouseRightUp(int x, int y);
void onMouseMoved(int x, int y);
void onMouseWheel(int x, int y, short delta); void onMouseWheel(int x, int y, short delta);
private: private:
@@ -894,6 +895,10 @@ short GetHoldKeyState(int key)
{ {
return GetKeyState(key) >> 1; return GetKeyState(key) >> 1;
} }
bool IsHolding(int button)
{
return (GetKeyState(button) >> 1)>0;
}
void Demo::onUserInput(UserInput* ui) { void Demo::onUserInput(UserInput* ui) {
if(mouseMovedBeginMotion) if(mouseMovedBeginMotion)
@@ -903,7 +908,7 @@ void Demo::onUserInput(UserInput* ui) {
} }
if(GetHoldKeyState(VK_RBUTTON)) if(GetHoldKeyState(VK_RBUTTON))
{ {
oldMouse = ui->getMouseXY(); oldMouse = dataModel->getMousePos();
showMouse = false; showMouse = false;
//window()->setRelativeMousePosition(window()->width()/2, window()->height()/2); //window()->setRelativeMousePosition(window()->width()/2, window()->height()/2);
mouseMovedBeginMotion = true; mouseMovedBeginMotion = true;
@@ -924,27 +929,14 @@ void Demo::onUserInput(UserInput* ui) {
moveRate = 0.5; moveRate = 0.5;
} }
if(ui->keyPressed(SDL_MOUSE_WHEEL_UP_KEY)) if(GetHoldKeyState(VK_DELETE))
{
AudioPlayer::playSound(cameraSound);
CoordinateFrame frame = debugCamera.getCoordinateFrame();
cameraPos = cameraPos + frame.lookVector()*2;
}
if(ui->keyPressed(SDL_MOUSE_WHEEL_DOWN_KEY))
{
AudioPlayer::playSound(cameraSound);
CoordinateFrame frame = debugCamera.getCoordinateFrame();
cameraPos = cameraPos - frame.lookVector()*2;
}
if(GetKeyState(VK_DELETE) >> 1)
{ {
deleteInstance(); deleteInstance();
} }
if(GetKeyState(VK_LCONTROL) >> 1) if(GetHoldKeyState(VK_LCONTROL))
{ {
if(GetKeyState('D') >> 1) if(GetHoldKeyState('D'))
{ {
messageTime = System::time(); messageTime = System::time();
if(debugMode()) if(debugMode())
@@ -961,32 +953,28 @@ void Demo::onUserInput(UserInput* ui) {
//setDesiredFrameRate(FPSVal[index]); //setDesiredFrameRate(FPSVal[index]);
//} //}
dataModel->mousex = ui->getMouseX(); //dataModel->mousex = ui->getMouseX();
dataModel->mousey = ui->getMouseY(); //dataModel->mousey = ui->getMouseY();
dataModel->mouseButton1Down = ui->keyDown(SDL_LEFT_MOUSE_KEY); dataModel->mouseButton1Down = IsHolding(VK_LBUTTON);
if(GetKeyState('U') >> 1) if(GetHoldKeyState('U'))
{ {
forwards = true; forwards = true;
} }
else if(GetKeyState('J') >> 1) if(GetHoldKeyState('J'))
{ {
backwards = true; backwards = true;
} }
if(GetKeyState('H') >> 1) if(GetHoldKeyState('H'))
{ {
left = true; left = true;
} }
else if(GetKeyState('K') >> 1) if(GetHoldKeyState('K'))
{ {
right = true; right = true;
} }
if(ui->keyDown('U'))
{
forwards = true;
}
if (ui->keyDown(SDL_LEFT_MOUSE_KEY)) { 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 = debugCamera.worldRay(dataModel->mousex, dataModel->mousey, renderDevice->getViewport());
@@ -1387,11 +1375,26 @@ void Demo::onMouseRightUp(int x,int y)
{ {
std::cout << "Release: " << x << "," << y << std::endl; std::cout << "Release: " << x << "," << y << std::endl;
} }
void Demo::onMouseMoved(int x,int y)
{
std::cout << "Moved: " << x << "," << y << std::endl;
dataModel->mousex = x;
dataModel->mousey = 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 (delta>0) // Mouse wheel up
{ {
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;
} }
} }
/* /*
@@ -1441,6 +1444,9 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
case WM_LBUTTONDOWN: case WM_LBUTTONDOWN:
app->onMouseLeftPressed(LOWORD(lParam),HIWORD(lParam)); app->onMouseLeftPressed(LOWORD(lParam),HIWORD(lParam));
break; break;
case WM_MOUSEMOVE:
app->onMouseMoved(LOWORD(lParam),HIWORD(lParam));
break;
case WM_LBUTTONUP: case WM_LBUTTONUP:
app->onMouseLeftUp(LOWORD(lParam),HIWORD(lParam)); app->onMouseLeftUp(LOWORD(lParam),HIWORD(lParam));
break; break;
@@ -1463,9 +1469,6 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
app->onGraphics(app->renderDevice); app->onGraphics(app->renderDevice);
} }
break; break;
case WM_MOUSEMOVE:
break;
default: default:
{ {
return DefWindowProc(hwnd, msg, wParam, lParam); return DefWindowProc(hwnd, msg, wParam, lParam);