From 03a7d5345d2721b257c4a2cf5bd0fa40e8a02fac Mon Sep 17 00:00:00 2001 From: andreja6 Date: Tue, 10 Mar 2020 12:41:47 -0700 Subject: [PATCH 01/18] Added tool, fixed some pages --- G3DTest.vcproj | 8 ++++++++ Tool.cpp | 9 +++++++++ Tool.h | 16 ++++++++++++++++ content/page/hopper.html | 14 +++++++------- content/page/surface.html | 14 +++++++------- 5 files changed, 47 insertions(+), 14 deletions(-) create mode 100644 Tool.cpp create mode 100644 Tool.h diff --git a/G3DTest.vcproj b/G3DTest.vcproj index bc40e81..606f513 100644 --- a/G3DTest.vcproj +++ b/G3DTest.vcproj @@ -306,6 +306,10 @@ RelativePath=".\ToggleImageButtonInstance.cpp" > + + @@ -487,6 +491,10 @@ RelativePath=".\ToggleImageButtonInstance.h" > + + diff --git a/Tool.cpp b/Tool.cpp new file mode 100644 index 0000000..7459701 --- /dev/null +++ b/Tool.cpp @@ -0,0 +1,9 @@ +#include "Tool.h" + +Tool::Tool(void) +{ +} + +Tool::~Tool(void) +{ +} diff --git a/Tool.h b/Tool.h new file mode 100644 index 0000000..4489938 --- /dev/null +++ b/Tool.h @@ -0,0 +1,16 @@ +#pragma once + +class Tool +{ +public: + Tool(void); + ~Tool(void); + void OnButton1MouseDown(); + void OnButton2MouseDown(); + void OnButton3MouseDown(); + void OnButton1MouseUp(); + void OnButton2MouseUp(); + void OnButton3MouseUp(); + void OnKeyPress(); + void OnKeyRelease(); +}; diff --git a/content/page/hopper.html b/content/page/hopper.html index d1e1ea2..1abc863 100644 --- a/content/page/hopper.html +++ b/content/page/hopper.html @@ -22,25 +22,25 @@ } - + - + - + - + - + - + - + diff --git a/content/page/surface.html b/content/page/surface.html index f1652d1..a165e6a 100644 --- a/content/page/surface.html +++ b/content/page/surface.html @@ -12,12 +12,12 @@ } - - - - - - - + + + + + + + \ No newline at end of file From 30529c5387e78d6f1c2bb956b0de07ea5a65ea53 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Tue, 10 Mar 2020 12:50:59 -0700 Subject: [PATCH 02/18] Changed stuffs --- Application.cpp | 2 +- ax.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Application.cpp b/Application.cpp index e41f7df..4c90e99 100644 --- a/Application.cpp +++ b/Application.cpp @@ -136,7 +136,7 @@ Application::Application(HWND parentWindow) : _propWindow(NULL) { //: GApp(setti _propWindow = new PropertyWindow(0, 0, 200, 640, hThisInstance); webBrowser = new IEBrowser(_hwndToolbox); - SetWindowLongPtr(_hwndToolbox,GWL_USERDATA+1,(LONG)webBrowser); + SetWindowLongPtr(_hwndToolbox,GWL_USERDATA,(LONG)webBrowser); //webBrowser->navigateSyncURL(L"http://androdome.com/res/ClientToolbox.php"); //navigateToolbox(GetFileInPath("/content/page/controller.html")); navigateToolbox(GetFileInPath("/content/page/surface.html")); diff --git a/ax.cpp b/ax.cpp index a8f6eba..bc56313 100644 --- a/ax.cpp +++ b/ax.cpp @@ -505,7 +505,7 @@ HRESULT _stdcall AXClientSite :: Invoke( EXCEPINFO FAR* pExcepInfo, unsigned int FAR* puArgErr) { - IEBrowser * browser = (IEBrowser *)GetWindowLongPtr(Window,GWL_USERDATA+1); + IEBrowser * browser = (IEBrowser *)GetWindowLongPtr(Window,GWL_USERDATA); return browser->doExternal(m_lastExternalName,dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr); //return S_OK; From 72c6d19d7f4a3b40a5521cdd361278b4d5514043 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Tue, 10 Mar 2020 13:26:01 -0700 Subject: [PATCH 03/18] Menu now works --- BaseButtonInstance.cpp | 6 +++++- ButtonListener.cpp | 1 + ButtonListener.h | 3 ++- G3DTest.vcproj | 16 ++++++++++++---- GuiRoot.cpp | 21 +++++++++++++++++++-- GuiRoot.h | 1 + Tool.h | 5 +++-- ToolbarListener.cpp | 23 +++++++++++++++++++++++ ToolbarListener.h | 13 +++++++++++++ 9 files changed, 79 insertions(+), 10 deletions(-) create mode 100644 ToolbarListener.cpp create mode 100644 ToolbarListener.h diff --git a/BaseButtonInstance.cpp b/BaseButtonInstance.cpp index b1fb23f..8c92859 100644 --- a/BaseButtonInstance.cpp +++ b/BaseButtonInstance.cpp @@ -20,7 +20,11 @@ void BaseButtonInstance::render(RenderDevice* rd) BaseButtonInstance::~BaseButtonInstance(void) { - delete listener; + if(listener != NULL && listener->doDelete) + { + delete listener; + listener = NULL; + } } void BaseButtonInstance::setButtonListener(ButtonListener* buttonListener) diff --git a/ButtonListener.cpp b/ButtonListener.cpp index 8d6c5d0..7d1f9e9 100644 --- a/ButtonListener.cpp +++ b/ButtonListener.cpp @@ -4,6 +4,7 @@ ButtonListener::ButtonListener() { + doDelete = true; } ButtonListener::~ButtonListener(void) diff --git a/ButtonListener.h b/ButtonListener.h index bbf2e40..b334c63 100644 --- a/ButtonListener.h +++ b/ButtonListener.h @@ -1,6 +1,6 @@ #pragma once //#include "Application.h" -//#include "BaseButtonInstance.h" +#include "BaseButtonInstance.h" class BaseButtonInstance; @@ -10,6 +10,7 @@ class ButtonListener ButtonListener(); ~ButtonListener(void); virtual void onButton1MouseClick(BaseButtonInstance*); + bool doDelete; //virtual void onMouseOver(); //TODO //virtual void onMouseOut(); //TODO //virtual void onButton1MouseDown(); //TODO diff --git a/G3DTest.vcproj b/G3DTest.vcproj index 606f513..cd1ef4d 100644 --- a/G3DTest.vcproj +++ b/G3DTest.vcproj @@ -302,10 +302,6 @@ RelativePath=".\StringFunctions.cpp" > - - @@ -357,6 +353,10 @@ RelativePath=".\TextButtonInstance.cpp" > + + @@ -393,6 +393,10 @@ RelativePath=".\RotateButtonListener.cpp" > + + + + doDelete = false; g_fntdominant = GFont::fromFile(GetFileInPath("/content/font/dominant.fnt")); g_fntlighttrek = GFont::fromFile(GetFileInPath("/content/font/lighttrek.fnt")); @@ -51,6 +54,8 @@ GuiRoot::GuiRoot() : _message(""), _messageTime(0) button->setAllColorsSame(); button->boxOutlineColorOvr = Color3(0,255,255); button->boxColorDn = Color4(button->boxColor.r,button->boxColor.g,button->boxColor.b, 0.2F); + button->setButtonListener(toolbar); + toolbar->addButtonRef(button); button = makeTextButton(); @@ -66,7 +71,8 @@ GuiRoot::GuiRoot() : _message(""), _messageTime(0) button->setAllColorsSame(); button->boxOutlineColorOvr = Color3(0,255,255); button->boxColorDn = Color4(button->boxColor.r,button->boxColor.g,button->boxColor.b, 0.2F); - + button->setButtonListener(toolbar); + toolbar->addButtonRef(button); button = makeTextButton(); button->boxBegin = Vector2(0, -72); @@ -81,6 +87,8 @@ GuiRoot::GuiRoot() : _message(""), _messageTime(0) button->setAllColorsSame(); button->boxOutlineColorOvr = Color3(0,255,255); button->boxColorDn = Color4(button->boxColor.r,button->boxColor.g,button->boxColor.b, 0.2F); + button->setButtonListener(toolbar); + toolbar->addButtonRef(button); button = makeTextButton(); button->boxBegin = Vector2(0, -96); @@ -95,6 +103,8 @@ GuiRoot::GuiRoot() : _message(""), _messageTime(0) button->setAllColorsSame(); button->boxOutlineColorOvr = Color3(0,255,255); button->boxColorDn = Color4(button->boxColor.r,button->boxColor.g,button->boxColor.b, 0.2F); + button->setButtonListener(toolbar); + toolbar->addButtonRef(button); button = makeTextButton(); button->boxBegin = Vector2(0, -120); @@ -109,6 +119,8 @@ GuiRoot::GuiRoot() : _message(""), _messageTime(0) button->setAllColorsSame(); button->boxOutlineColorOvr = Color3(0,255,255); button->boxColorDn = Color4(button->boxColor.r,button->boxColor.g,button->boxColor.b, 0.2F); + button->setButtonListener(toolbar); + toolbar->addButtonRef(button); //Top bar button = makeTextButton(); @@ -503,6 +515,11 @@ void GuiRoot::update() } } +GuiRoot::~GuiRoot() +{ + delete toolbar; +} + void GuiRoot::onMouseLeftUp(G3D::RenderDevice* renderDevice, int x,int y) { std::vector instances_2D = this->getAllChildren(); diff --git a/GuiRoot.h b/GuiRoot.h index 546c5b5..a19339f 100644 --- a/GuiRoot.h +++ b/GuiRoot.h @@ -9,6 +9,7 @@ class GuiRoot : public Instance { public: GuiRoot(); + GuiRoot::~GuiRoot(); TextButtonInstance* makeTextButton(); void drawButtons(RenderDevice* rd); ImageButtonInstance* makeImageButton(G3D::TextureRef newImage, G3D::TextureRef overImage, G3D::TextureRef downImage, G3D::TextureRef disableImage); diff --git a/Tool.h b/Tool.h index 4489938..2336dbe 100644 --- a/Tool.h +++ b/Tool.h @@ -11,6 +11,7 @@ public: void OnButton1MouseUp(); void OnButton2MouseUp(); void OnButton3MouseUp(); - void OnKeyPress(); - void OnKeyRelease(); + void OnMouseScroll(); + void OnKeyDown(); + void OnKeyUp(); }; diff --git a/ToolbarListener.cpp b/ToolbarListener.cpp new file mode 100644 index 0000000..f551275 --- /dev/null +++ b/ToolbarListener.cpp @@ -0,0 +1,23 @@ +#include "ToolbarListener.h" +#include "Globals.h" +#include "StringFunctions.h" +#include "Application.h" + +void ToolbarListener::onButton1MouseClick(BaseButtonInstance* btn) +{ + if(TextButtonInstance* button = dynamic_cast(btn)) + { + for(size_t i = 0; i < btns.size(); i++) + btns[i]->selected = false; + button->selected = true; + if(button->title == "Model") g_usableApp->navigateToolbox("http://androdome.com/res/ClientToolbox.php"); + else if(button->title == "Surface") g_usableApp->navigateToolbox(GetFileInPath("/content/page/surface.html")); + else if(button->title == "Color") g_usableApp->navigateToolbox(GetFileInPath("/content/page/color.html")); + else if(button->title == "Controller") g_usableApp->navigateToolbox(GetFileInPath("/content/page/controller.html")); + else if(button->title == "Hopper") g_usableApp->navigateToolbox(GetFileInPath("/content/page/hopper.html")); + } +} +void ToolbarListener::addButtonRef(BaseButtonInstance* button) +{ + btns.push_back(button); +} \ No newline at end of file diff --git a/ToolbarListener.h b/ToolbarListener.h new file mode 100644 index 0000000..21079a4 --- /dev/null +++ b/ToolbarListener.h @@ -0,0 +1,13 @@ +#pragma once +#include "buttonlistener.h" +#pragma once +#include + +class ToolbarListener : public ButtonListener +{ +public: + void onButton1MouseClick(BaseButtonInstance* button); + void addButtonRef(BaseButtonInstance* button); +private: + std::vector btns; +}; From 0ec896e2fd13dc3c7ecae7fbfb55cf6c439dfc50 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Wed, 11 Mar 2020 23:10:49 -0700 Subject: [PATCH 04/18] Starting to transfer everything to Tool --- Application.cpp | 44 +++++++++++++++++++++------------------ Application.h | 4 ++++ BaseButtonInstance.cpp | 5 +++-- DataModelInstance.cpp | 10 ++++----- DataModelInstance.h | 12 +++++------ G3DTest.vcproj | 32 +++++++++++++++++++++------- Globals.cpp | 4 +++- Globals.h | 4 +++- IEBrowser.cpp | 41 ++++++++++++++++++++++++++++++++---- Mouse.cpp | 31 +++++++++++++++++++++++++++ Mouse.h | 18 ++++++++++++++++ Tool.cpp | 26 +++++++++++++++++++++++ Tool.h | 37 +++++++++++++++++++++++--------- content/page/color.html | Bin 2088 -> 4371 bytes content/page/hopper.html | 2 +- 15 files changed, 212 insertions(+), 58 deletions(-) create mode 100644 Mouse.cpp create mode 100644 Mouse.h diff --git a/Application.cpp b/Application.cpp index 4c90e99..a1e1de4 100644 --- a/Application.cpp +++ b/Application.cpp @@ -32,11 +32,9 @@ #include "RotateButtonListener.h" #define LEGACY_LOAD_G3DFUN_LEVEL Ray testRay; -static int cursorid = 0; -static int cursorOvrid = 0; -static int currentcursorid = 0; -static G3D::TextureRef cursor = NULL; -static G3D::TextureRef cursorOvr = NULL; +//static int cursorid = 0; +//static int cursorOvrid = 0; +//static int currentcursorid = 0; static bool mouseMovedBeginMotion = false; static POINT oldGlobalMouse; Vector2 oldMouse = Vector2(0,0); @@ -181,7 +179,7 @@ void Application::deleteInstance() void Application::onInit() { - + tool = new Tool(); // Called before Application::run() beings cameraController.setFrame(Vector3(0,2,10)); _dataModel = new DataModelInstance(); @@ -440,14 +438,14 @@ void Application::onUserInput(UserInput* ui) { //_dataModel->mousex = ui->getMouseX(); //_dataModel->mousey = ui->getMouseY(); - _dataModel->mouseButton1Down = (GetKeyState(VK_LBUTTON) & 0x100) != 0; + mouse.setMouseDown((GetKeyState(VK_LBUTTON) & 0x100) != 0); if (GetHoldKeyState(VK_LBUTTON)) { if (_dragging) { PartInstance* part = NULL; if(g_selectedInstances.size() > 0) part = (PartInstance*) g_selectedInstances.at(0); - Ray dragRay = cameraController.getCamera()->worldRay(_dataModel->mousex, _dataModel->mousey, renderDevice->getViewport()); + Ray dragRay = cameraController.getCamera()->worldRay(mouse.x, mouse.y, renderDevice->getViewport()); std::vector instances = _dataModel->getWorkspace()->getAllChildren(); for(size_t i = 0; i < instances.size(); i++) { @@ -735,7 +733,7 @@ void Application::onGraphics(RenderDevice* rd) { } } */ - glBindTexture( GL_TEXTURE_2D, currentcursorid); + glBindTexture( GL_TEXTURE_2D, tool->getCursorId()); glBegin( GL_QUADS ); @@ -767,10 +765,11 @@ void Application::onKeyPressed(int key) { _dataModel->getOpen(); } + tool->onKeyDown(key); } void Application::onKeyUp(int key) { - + tool->onKeyUp(key); } void Application::onMouseLeftPressed(HWND hwnd,int x,int y) @@ -779,14 +778,16 @@ void Application::onMouseLeftPressed(HWND hwnd,int x,int y) //std::cout << "Click: " << x << "," << y << std::endl; - + + bool onGUI = _dataModel->getGuiRoot()->mouseInGUI(renderDevice, x, y); if(!onGUI) { + tool->onButton1MouseDown(mouse); Instance * selectedInstance = NULL; - testRay = cameraController.getCamera()->worldRay(_dataModel->mousex, _dataModel->mousey, renderDevice->getViewport()); + testRay = cameraController.getCamera()->worldRay(mouse.x, mouse.y, renderDevice->getViewport()); float nearest=std::numeric_limits::infinity(); Vector3 camPos = cameraController.getCamera()->getCoordinateFrame().translation; std::vector instances = _dataModel->getWorkspace()->getAllChildren(); @@ -868,6 +869,7 @@ void Application::onMouseLeftUp(G3D::RenderDevice* renderDevice, int x, int y) //std::cout << "Release: " << x << "," << y << std::endl; _dataModel->getGuiRoot()->onMouseLeftUp(renderDevice, x, y); _dragging = false; + tool->onButton1MouseUp(mouse); //_message = "Dragging = false."; //_messageTime = System::time(); @@ -875,15 +877,20 @@ void Application::onMouseLeftUp(G3D::RenderDevice* renderDevice, int x, int y) void Application::onMouseRightPressed(int x,int y) { + tool->onButton2MouseDown(mouse); } void Application::onMouseRightUp(int x,int y) { + tool->onButton2MouseUp(mouse); } void Application::onMouseMoved(int x,int y) { - oldMouse = _dataModel->getMousePos(); - _dataModel->mousex = x; - _dataModel->mousey = y; + oldMouse = Vector2(mouse.x, mouse.y); + mouse.x = x; + mouse.y = y; + tool->onMouseMoved(mouse); + //_dataModel->mousex = x; + //_dataModel->mousey = y; } void Application::onMouseWheel(int x,int y,short delta) @@ -893,6 +900,7 @@ void Application::onMouseWheel(int x,int y,short delta) { AudioPlayer::playSound(cameraSound); } + tool->onMouseScroll(mouse); } void Application::run() { @@ -916,17 +924,13 @@ void Application::run() { UpdateWindow(_hWndMain); // Load objects here= - cursor = Texture::fromFile(GetFileInPath("/content/images/ArrowCursor.png")); - cursorOvr = Texture::fromFile(GetFileInPath("/content/images/DragCursor.png")); + Globals::surface = Texture::fromFile(GetFileInPath("/content/images/surfacebr.png")); Globals::surfaceId = Globals::surface->getOpenGLID(); cameraSound = GetFileInPath("/content/sounds/SWITCH3.wav"); clickSound = GetFileInPath("/content/sounds/switch.wav"); dingSound = GetFileInPath("/content/sounds/electronicpingshort.wav"); sky = Sky::create(NULL, ExePath() + "/content/sky/"); - cursorid = cursor->openGLID(); - currentcursorid = cursorid; - cursorOvrid = cursorOvr->openGLID(); RealTime now=0, lastTime=0; double simTimeRate = 1.0f; float fps=30.0f; diff --git a/Application.h b/Application.h index 2584550..3e08059 100644 --- a/Application.h +++ b/Application.h @@ -5,6 +5,8 @@ #include "ImageButtonInstance.h" #include "CameraController.h" #include "IEBrowser.h" +#include "Mouse.h" +#include "Tool.h" //#include "GuiRoot.h" class TextButtonInstance; @@ -54,6 +56,8 @@ class Application { // : public GApp { RenderDevice* getRenderDevice(); void selectInstance(Instance* selectedInstance,PropertyWindow* propWindow); void setMode(int mode); + Mouse mouse; + Tool * tool; private: RenderDevice* renderDevice; //void initGUI(); diff --git a/BaseButtonInstance.cpp b/BaseButtonInstance.cpp index 8c92859..2df06ef 100644 --- a/BaseButtonInstance.cpp +++ b/BaseButtonInstance.cpp @@ -1,5 +1,6 @@ #include "BaseButtonInstance.h" #include "Globals.h" +#include "Application.h" ButtonListener* listener = NULL; @@ -13,8 +14,8 @@ BaseButtonInstance::BaseButtonInstance(void) void BaseButtonInstance::render(RenderDevice* rd) { DataModelInstance* dataModel = g_dataModel; - Vector2 pos = Vector2(dataModel->mousex,dataModel->mousey); - drawObj(rd, pos, dataModel->mouseButton1Down); + Vector2 pos = Vector2(g_usableApp->mouse.x,g_usableApp->mouse.y); + drawObj(rd, pos, g_usableApp->mouse.isMouseDown()); Instance::render(rd); } diff --git a/DataModelInstance.cpp b/DataModelInstance.cpp index 2c9fca2..5364ff6 100644 --- a/DataModelInstance.cpp +++ b/DataModelInstance.cpp @@ -20,9 +20,9 @@ DataModelInstance::DataModelInstance(void) //children.push_back(workspace); //children.push_back(level); className = "dataModel"; - mousex = 0; - mousey = 0; - mouseButton1Down = false; + //mousex = 0; + //mousey = 0; + //mouseButton1Down = false; showMessage = false; canDelete = false; _modY=0; @@ -586,7 +586,7 @@ WorkspaceInstance* DataModelInstance::getWorkspace() { return workspace; } -Vector2 DataModelInstance::getMousePos() +/*Vector2 DataModelInstance::getMousePos() { return Vector2(mousex,mousey); } @@ -599,7 +599,7 @@ void DataModelInstance::setMousePos(Vector2 pos) { mousex=pos.x; mousey=pos.y; -} +}*/ GuiRoot* DataModelInstance::getGuiRoot() { return guiRoot; diff --git a/DataModelInstance.h b/DataModelInstance.h index 7afa538..c143a05 100644 --- a/DataModelInstance.h +++ b/DataModelInstance.h @@ -28,12 +28,12 @@ public: bool showMessage; G3D::GFontRef font; GuiRoot* getGuiRoot(); - float mousex; - float mousey; - Vector2 getMousePos(); - void setMousePos(int x,int y); - void setMousePos(Vector2 pos); - bool mouseButton1Down; + //float mousex; + //float mousey; + //Vector2 getMousePos(); + //void setMousePos(int x,int y); + //void setMousePos(Vector2 pos); + //bool mouseButton1Down; PartInstance* makePart(); void clearLevel(); void toggleRun(); diff --git a/G3DTest.vcproj b/G3DTest.vcproj index cd1ef4d..dbc0833 100644 --- a/G3DTest.vcproj +++ b/G3DTest.vcproj @@ -290,6 +290,10 @@ /> + + @@ -302,10 +306,6 @@ RelativePath=".\StringFunctions.cpp" > - - @@ -398,6 +398,14 @@ > + + + + + + @@ -495,10 +507,6 @@ RelativePath=".\ToggleImageButtonInstance.h" > - - @@ -583,6 +591,14 @@ > + + + + postRenderStack; @@ -31,7 +32,8 @@ extern Application* g_usableApp; extern GFontRef g_fntdominant; extern GFontRef g_fntlighttrek; +extern COLORREF g_acrCustClr[16]; //Will be dynamic later extern std::string cameraSound; extern std::string clickSound; extern std::string dingSound; -const std::string g_PlaceholderName = "HyperCube"; \ No newline at end of file +const std::string g_PlaceholderName = "Dygysphere"; \ No newline at end of file diff --git a/IEBrowser.cpp b/IEBrowser.cpp index b560aea..5bf843c 100644 --- a/IEBrowser.cpp +++ b/IEBrowser.cpp @@ -4,7 +4,7 @@ #include - +#include #include "IEBrowser.h" #include "Globals.h" #pragma once @@ -28,7 +28,9 @@ HRESULT IEBrowser::doExternal(std::wstring funcName, } else if (funcName==L"ToggleHopperBin") { - MessageBox(NULL, "BOOP", "Boopity boop",MB_OK); + pVarResult->vt = VT_INT; + pVarResult->intVal = 5; + //MessageBox(NULL, "BOOP", "Boopity boop",MB_OK); } else if (funcName==L"SetController") { @@ -51,10 +53,41 @@ HRESULT IEBrowser::doExternal(std::wstring funcName, AudioPlayer::playSound(dingSound); return S_OK; } - else + else if(funcName==L"SetColor") { - return E_NOTIMPL; + + return S_OK; } + else if(funcName==L"ChooseColor") + { + CHOOSECOLOR color; + + DWORD rgbCurrent; //Will be dynamic later + ZeroMemory(&color, sizeof(CHOOSECOLOR)); + color.lStructSize = sizeof(color); + color.hwndOwner = hwnd; + color.lpCustColors = (LPDWORD) g_acrCustClr; + color.rgbResult = rgbCurrent; + color.Flags = CC_FULLOPEN | CC_RGBINIT; + if(ChooseColorA((LPCHOOSECOLOR)&color)) + { + //DWORD dwR = GetRValue(color.rgbResult); + //DWORD dwG = GetGValue(color.rgbResult); + //DWORD dwB = GetBValue(color.rgbResult); + //wchar_t * str = L"Test"; + //swprintf_s(str, 16, L"#%02X%02X%02X", dwR, dwG, dwB); + pVarResult->vt = VT_UI4; + pVarResult->ulVal = color.rgbResult; + } + else + { + DWORD error = CommDlgExtendedError(); + std::cout << error; + pVarResult->vt = VT_NULL; + } + return S_OK; + } + return E_NOTIMPL; } IEBrowser::IEBrowser(HWND attachHWnd) { diff --git a/Mouse.cpp b/Mouse.cpp new file mode 100644 index 0000000..4b9cd8a --- /dev/null +++ b/Mouse.cpp @@ -0,0 +1,31 @@ +#include "Mouse.h" +Mouse::Mouse(){ + x = y = 0; +} +Mouse::~Mouse(){} + + +Instance * Mouse::getTarget() +{ + return NULL; +} +Vector3 Mouse::getPosition() +{ + return Vector3(); + //Not implemented +} +bool Mouse::isMouseOnScreen() +{ + //hm + return true; +} + +bool Mouse::isMouseDown() +{ + return mouseDown; +} + +void Mouse::setMouseDown(bool bval) +{ + mouseDown = bval; +} \ No newline at end of file diff --git a/Mouse.h b/Mouse.h new file mode 100644 index 0000000..83a1c4c --- /dev/null +++ b/Mouse.h @@ -0,0 +1,18 @@ +#pragma once +#include "PartInstance.h" +#pragma once + +class Mouse +{ +public: + Mouse(void); + ~Mouse(void); + int x, y; + Instance * getTarget(); + Vector3 getPosition(); + bool isMouseOnScreen(); + bool isMouseDown(); + void setMouseDown(bool mouseDown); +private: + bool mouseDown; +}; diff --git a/Tool.cpp b/Tool.cpp index 7459701..169b92b 100644 --- a/Tool.cpp +++ b/Tool.cpp @@ -2,8 +2,34 @@ Tool::Tool(void) { + cursorRef = Texture::fromFile(GetFileInPath("/content/images/ArrowCursor.png")); + cursorId = cursorRef->openGLID(); } Tool::~Tool(void) { } + +void Tool::onButton1MouseDown(Mouse mouse){} +void Tool::onButton2MouseDown(Mouse mouse){} +void Tool::onButton3MouseDown(Mouse mouse){} +void Tool::onButton1MouseUp(Mouse mouse){} +void Tool::onButton2MouseUp(Mouse mouse){} +void Tool::onButton3MouseUp(Mouse mouse){} +void Tool::onMouseMoved(Mouse mouse){} +void Tool::onSelect(Mouse mouse){} +void Tool::onDeselect(Mouse mouse){} +void Tool::onMouseScroll(Mouse mouse){} +void Tool::onKeyDown(char key){} +void Tool::onKeyUp(char key){} +void Tool::setCursor(std::string) +{ +} +int Tool::getCursorId() +{ + return cursorId; +} +void Tool::setCursorId(int id) +{ + cursorId = id; +} \ No newline at end of file diff --git a/Tool.h b/Tool.h index 2336dbe..bd1868b 100644 --- a/Tool.h +++ b/Tool.h @@ -1,17 +1,34 @@ #pragma once - +#include +#pragma once +#include "Mouse.h" +#pragma once +#include "Globals.h" +#pragma once +#include "StringFunctions.h" +#pragma once class Tool { public: Tool(void); ~Tool(void); - void OnButton1MouseDown(); - void OnButton2MouseDown(); - void OnButton3MouseDown(); - void OnButton1MouseUp(); - void OnButton2MouseUp(); - void OnButton3MouseUp(); - void OnMouseScroll(); - void OnKeyDown(); - void OnKeyUp(); + void onButton1MouseDown(Mouse); //yes + void onButton2MouseDown(Mouse); //yes + void onButton3MouseDown(Mouse); + void onButton1MouseUp(Mouse);//yes + void onButton2MouseUp(Mouse);//yes + void onButton3MouseUp(Mouse); + void onMouseMoved(Mouse);//yes + void onSelect(Mouse);//For later + void onDeselect(Mouse);//For later + void onMouseScroll(Mouse);//Kinda + void onKeyDown(char);//yes + void onKeyUp(char);//yes + void setCursor(std::string); + void setCursorId(int);//yes + int getCursorId();//yes +private: + int cursorId; + G3D::TextureRef cursorRef; + std::string cursorString; }; diff --git a/content/page/color.html b/content/page/color.html index 88582929609379f5ff75e75564ae44f5675b222e..acdb23f15b44331e78e63db1cd78cc058968d26d 100644 GIT binary patch literal 4371 zcmcIoZExE)5dJLx3QoZmdy8J&cCI1I{?MRC19ZTE<`3wFwzyEFM^UleHvfHhq@*ZC z^I?E#1r}e9&)q$|JJLxjUGvQ(Z3@K>dNY}%QQu4(edcsC@mRh8Hu1cQvVEl!GLPe5 zR}=4P;)R72I%9&Wi8q#b_x^AK3Gc{CT_xnt*mmno?U@Kv4+EoKkHck$kxNxl6&T$K zVWOcLp}OG?@y!^2zOcQ{zP`Hy+k%FDr3r}<0sczX9C&t4nBZV^kaJl);MDIgCsqW< zzDijqbC?E4uZmVFDs&+SJB=kPvNT)_+;rXl;e@3TVE<;tLr-Mq=G)HCp82l-gqvjd zX4p6HF;ir0C0P^ySTRlg6^WwziZ$fOI43zJ|F%>yT9TcTHPIC%+2O!hk!dCc;h9D& zcC9E(ANapTucx^dGrP@36^?-p7!8drVV)HadnH>@8hPZ^2=Y6jLGX~NhC*{{I1Ckq zohazkzw&SV_~g%KxS*6pTLaJGp6ZXBV)MiKuAKT~&-~fXHG&d@jX*~xN_hAQW;c_PUypKc2^|*Sb~W#n=<%{V4K*{5P;a zcM!AC>|$S0vuucFn7IM}Y($L~V~(9oBu#&kH9v;uZ6#$xJ8`s*?QEWqUvP&x2MkkT zJrgKE&ug)2<_%4kOD0GaQ*yc^BF$xaCMN0E{&UvbKuySpR%*8WhnG!(v>|GKq(B5cwK;4X-}jPdau;9_36z+F1Qje!Lh_9Cte zevw@lxX6MV+-3aEK|I8O>IQciZ?~6^U$oZ^zp)d0ao3*nBF#-{yHHKrn$P7qzK!v@ zJnnXjS?2;5kuQ&n5#b8gO>Ve}VPwIDy%@eOav804fr}N*1rK<_xxmGJbHM|$`{K+< zBYRg%b!o3wxw#xZ-_yp|i%STh3~U6hHr;R#E?4FS9m09_2E{suNez&C*1JP!!8f4iHvi;ue-E`XpA;_daU ztJtGKQJ9ZeW0CdVhuU2L)x6#)j~E)d`8xrzqz)e-7qz>uFP-CWj&X&#QW{5tUo*+v z3ePw3VYFu^E|QmpU5`0<1{k|I*Ba1@oU~**u(hbyx2Ydf8GAyV%=xWm)qZ6=fZ>-| zEg#ID94D8ZmT<$#YUfp6lxEfH)GZ$Id@jlCcN4&^Po~pT22pVD`MKHGjU1l5Y*0Mb zgMfjHv6`de3;K>tFsuaIDs0auG|)J%9-sK78!T75J#!CF<+|aATjaHKiNxS{<r0nFG_xZGn`*Kblu5m=wjv^GX{MC9Tg0Kn8xRlf zaFU)wAR~;^6}ud{KKA#R(OQE(y*@);90R8Zz2pUpoawUj(kpi~y&;N5s(iIzM3k&- z9E4OjHAi#vkGRvLVYd)Xwe`(k0#(Jq2PIU-l$3()&i-eQ9z%*JQha|E@!8GJ6>*-A z-1Htx{9hy1ugnBT7Y2oWNP}Eqa@n0zy`es(_ANA*V%>+*v}tjxiCA${6cw^R@qBOz zu(KKe^IkjHGpv<{Gq{57d#iEBE4b>yB3E5sq+p*T_bRh^rJ}XUD?UL5t8{J*rn*8G ztr>F^S>|IE-fKNj81@b6fAy(88{L&9<0Vv8<6kGb=tg02R5b_l$o3p$e!G!Pbs>91 zx(FFXFYc3ET(E3ZP+(+&+gz3$7+6>DJdMmmKPo??7Y}bNNLiXyf{lnWrj?JIBn82~ zhW?`UF7j-609MBTB-rs*Q&=-cDY>BdWj#;(Qes@^`)g?j(8Uz3$y2?CgA>*|i=g_L zDj^}Owrf$*mNt$WdA&ycq(5tu)vE0`zG3zpiuyUPONyWXCXml3KyC#9>y0D0Y}Wp@ zWL@7II>IsR^#p&`tWG#w>b{LvS0h3wWF8+RiV>`W_Dyu0*rli66%z5lcd91z;attJ zaU)gltaH)Y3&Kw)>=B<2jmw7z_m`8X?~a)S53ZK;Q>S^;vO3poO>iTBr0+sn_{JrP zXJS(OtaBg@gaDa8UO)}0r))FTB!{A;m?4QU>7wP8Wx}r(rQ_&?`M>UK9O8Sh=SxR~u;%NZSulo2t91g=Cjl(%25bP1KydfD67YiwC7~NSyJLbQ4d(Xp zUWgWuO^}r}MEd!~LQc@BDQDMLGalg+8O1c`H7Csn?>`GZpB?d&*IPu2UXM4Oa!i$E zb>(O^xx1S2`72v25A(KUGsSjYeQ?1;Hg!}nM`gG!NX>yZMO3xAdP(XN+9(5)jV9Ii zZ~}Ihz!{fr65X;Wg~-y54z5Nno~L^+C$mRhf;?ngONxCyLoVQ``xTa>Ygfv=sX;x( z8SJ&5z;G2xHgodv=wUJFnp{LR>P4o-SX`v>VouFdnzZ!H-k&4yKe}(u8HgGI1%WnI zG=LE5h5H_N4CTURTgS5h*`K&}Ps6vz)XeQ9HoMz3-7C#5U)8hTvV=93r01Sj7@|*C z?^q2}uQpY{3bxyPfL)Ou;6enB-bR}YL_%LZtmu!U_)kyDJDRCE&xkSoADtl>hY;G1 zQk)c`tkZ9DmjXGeyq)^^z^7h0@{ez8>5a=mrw-fd>fF`EFYN`Ze2S2Q*_>k?Igfe~ zfqx_&lKcgI=2oF{wfq7S3RVubhd=a1zlpDlp(uc5Dkd*G zbsJc%7+6q7>n{?uPanXy8^q2yDY(;X*(r BU>yJe diff --git a/content/page/hopper.html b/content/page/hopper.html index 1abc863..f20c4a0 100644 --- a/content/page/hopper.html +++ b/content/page/hopper.html @@ -22,7 +22,7 @@ } - + From 9a8aff54ff8ee7dc38369686f273ec282786e7c5 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Fri, 13 Mar 2020 10:08:03 -0700 Subject: [PATCH 05/18] Added change tool function --- Application.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Application.cpp b/Application.cpp index a1e1de4..023558f 100644 --- a/Application.cpp +++ b/Application.cpp @@ -483,6 +483,15 @@ void Application::onUserInput(UserInput* ui) { // Add other key handling here } +void Application::changeTool(Tool * newTool) +{ + delete tool; + if(newTool != NULL) + tool = newTool; + else + tool = new Tool(); //Nulltool +} + void Application::makeFlag(Vector3 &vec, RenderDevice* &rd) { From 2494a5e509d540678a97fd16cc1e93e305224563 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Fri, 13 Mar 2020 10:08:40 -0700 Subject: [PATCH 06/18] Fixed --- Application.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Application.h b/Application.h index 3e08059..ced42a1 100644 --- a/Application.h +++ b/Application.h @@ -58,6 +58,7 @@ class Application { // : public GApp { void setMode(int mode); Mouse mouse; Tool * tool; + void changeTool(Tool *); private: RenderDevice* renderDevice; //void initGUI(); From cee1b1308c35a82678f99ecd25aac1653d40374e Mon Sep 17 00:00:00 2001 From: andreja6 Date: Fri, 13 Mar 2020 10:30:22 -0700 Subject: [PATCH 07/18] Added dependancies --- G3DTest.vcproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/G3DTest.vcproj b/G3DTest.vcproj index dbc0833..d2d994b 100644 --- a/G3DTest.vcproj +++ b/G3DTest.vcproj @@ -170,7 +170,7 @@ /> Date: Fri, 13 Mar 2020 10:42:30 -0700 Subject: [PATCH 08/18] Fixed exception --- Application.cpp | 2 +- DataModelInstance.cpp | 1 + PartInstance.cpp | 1 + ax.cpp | 2 +- 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Application.cpp b/Application.cpp index 023558f..4a8ffaa 100644 --- a/Application.cpp +++ b/Application.cpp @@ -134,7 +134,7 @@ Application::Application(HWND parentWindow) : _propWindow(NULL) { //: GApp(setti _propWindow = new PropertyWindow(0, 0, 200, 640, hThisInstance); webBrowser = new IEBrowser(_hwndToolbox); - SetWindowLongPtr(_hwndToolbox,GWL_USERDATA,(LONG)webBrowser); + SetWindowLongPtr(_hwndToolbox,GWL_USERDATA+1,(LONG)webBrowser); //webBrowser->navigateSyncURL(L"http://androdome.com/res/ClientToolbox.php"); //navigateToolbox(GetFileInPath("/content/page/controller.html")); navigateToolbox(GetFileInPath("/content/page/surface.html")); diff --git a/DataModelInstance.cpp b/DataModelInstance.cpp index 5364ff6..c3a4b25 100644 --- a/DataModelInstance.cpp +++ b/DataModelInstance.cpp @@ -452,6 +452,7 @@ bool DataModelInstance::load(const char* filename, bool clearObjects) std::stringstream msg; msg << "Failed to load file:" << std::endl << filename << std::endl << strerror(errno); MessageBoxStr(msg.str()); + return false; } } diff --git a/PartInstance.cpp b/PartInstance.cpp index 1578823..e71c224 100644 --- a/PartInstance.cpp +++ b/PartInstance.cpp @@ -1082,6 +1082,7 @@ static TCHAR* enumStr(int shape) case Enum::Shape::Cylinder: return "Cylinder"; } + return "Block"; } void PartInstance::PropUpdate(LPPROPGRIDITEM &item) diff --git a/ax.cpp b/ax.cpp index bc56313..a8f6eba 100644 --- a/ax.cpp +++ b/ax.cpp @@ -505,7 +505,7 @@ HRESULT _stdcall AXClientSite :: Invoke( EXCEPINFO FAR* pExcepInfo, unsigned int FAR* puArgErr) { - IEBrowser * browser = (IEBrowser *)GetWindowLongPtr(Window,GWL_USERDATA); + IEBrowser * browser = (IEBrowser *)GetWindowLongPtr(Window,GWL_USERDATA+1); return browser->doExternal(m_lastExternalName,dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr); //return S_OK; From 24854a062acec3cb2a420686392ba0a6dd39edc6 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Fri, 13 Mar 2020 16:28:12 -0700 Subject: [PATCH 09/18] Added tools and texture handler --- Application.cpp | 82 ++++++---------------------- Application.h | 4 +- ArrowTool.cpp | 28 ++++++++++ ArrowTool.h | 13 +++++ G3DTest.vcproj | 16 ++++++ ModeSelectionListener.cpp | 3 +- Mouse.cpp | 65 ++++++++++++++++++++-- Mouse.h | 8 ++- TextureHandler.cpp | 12 +++++ TextureHandler.h | 87 ++++++++++++++++++++++++++++++ Tool.cpp | 13 ++--- Tool.h | 34 ++++++------ content/images/ArrowFarCursor.png | Bin 0 -> 2169 bytes 13 files changed, 267 insertions(+), 98 deletions(-) create mode 100644 ArrowTool.cpp create mode 100644 ArrowTool.h create mode 100644 TextureHandler.cpp create mode 100644 TextureHandler.h create mode 100644 content/images/ArrowFarCursor.png diff --git a/Application.cpp b/Application.cpp index 4a8ffaa..c643ecc 100644 --- a/Application.cpp +++ b/Application.cpp @@ -30,8 +30,8 @@ #include "DeleteListener.h" #include "CameraButtonListener.h" #include "RotateButtonListener.h" -#define LEGACY_LOAD_G3DFUN_LEVEL -Ray testRay; +//#define LEGACY_LOAD_G3DFUN_LEVEL +//Ray testRay; //static int cursorid = 0; //static int cursorOvrid = 0; //static int currentcursorid = 0; @@ -161,8 +161,7 @@ void Application::deleteInstance() { AudioPlayer::playSound(GetFileInPath("/content/sounds/pageturn.wav")); Instance* selectedInstance = g_selectedInstances.at(0); - if(selectedInstance->getParent() != NULL) - selectedInstance->getParent()->removeChild(selectedInstance); + selectedInstance->setParent(NULL); delete selectedInstance; selectedInstance = NULL; g_selectedInstances.erase(g_selectedInstances.begin()); @@ -415,7 +414,11 @@ bool IsHolding(int button) */ void Application::onUserInput(UserInput* ui) { - + if(mouseMoveState) + { + mouseMoveState = false; + tool->onMouseMoved(mouse); + } /* if(GetHoldKeyState(VK_LCONTROL)) { @@ -441,7 +444,7 @@ void Application::onUserInput(UserInput* ui) { mouse.setMouseDown((GetKeyState(VK_LBUTTON) & 0x100) != 0); if (GetHoldKeyState(VK_LBUTTON)) { - if (_dragging) { + /* if (_dragging) { PartInstance* part = NULL; if(g_selectedInstances.size() > 0) part = (PartInstance*) g_selectedInstances.at(0); @@ -466,7 +469,7 @@ void Application::onUserInput(UserInput* ui) { } } Sleep(10); - } + }*/ } // Camera KB Handling { if (GetKPBool(VK_OEM_COMMA)) //Left @@ -485,11 +488,14 @@ void Application::onUserInput(UserInput* ui) { void Application::changeTool(Tool * newTool) { + tool->onDeselect(mouse); delete tool; if(newTool != NULL) tool = newTool; else tool = new Tool(); //Nulltool + tool->onSelect(mouse); + } void Application::makeFlag(Vector3 &vec, RenderDevice* &rd) @@ -795,63 +801,6 @@ void Application::onMouseLeftPressed(HWND hwnd,int x,int y) if(!onGUI) { tool->onButton1MouseDown(mouse); - Instance * selectedInstance = NULL; - testRay = cameraController.getCamera()->worldRay(mouse.x, mouse.y, renderDevice->getViewport()); - float nearest=std::numeric_limits::infinity(); - Vector3 camPos = cameraController.getCamera()->getCoordinateFrame().translation; - std::vector instances = _dataModel->getWorkspace()->getAllChildren(); - bool objFound = false; - for(size_t i = 0; i < instances.size(); i++) - { - if(PartInstance* test = dynamic_cast(instances.at(i))) - { - float time = testRay.intersectionTime(test->getBox()); - - if (time != inf()) - { - objFound = true; - if (nearest>time) - { - nearest=time; - //bool found = false; - selectedInstance = test; - /*for(size_t i = 0; i < g_selectedInstances.size(); i++) - { - if(g_selectedInstances.at(i) == test) - { - found = true; - //ShowWindow(_propWindow->_hwndProp, SW_SHOW); - //SetActiveWindow(_propWindow->_hwndProp); - //SetForegroundWindow(_propWindow->_hwndProp); - break; - } - } - if(!found) - { - selectedInstance = test; - //if(!GetHoldKeyState(VK_RCONTROL) && !GetHoldKeyState(VK_LCONTROL)) - //g_selectedInstances.clear(); - //if(std::find(g_selectedInstances.begin(), g_selectedInstances.end(),test)==g_selectedInstances.end()) - //g_selectedInstances.push_back(test); - } - //selectInstance(test, _propWindow); - //_message = "Dragging = true."; - //_messageTime = System::time(); - //_dragging = true;*/ - } - } - } - } - if(!objFound) - selectInstance(_dataModel,_propWindow); - else - { - while(selectedInstance->getParent() != g_dataModel->getWorkspace()) - { - selectedInstance = selectedInstance->getParent(); - } - selectInstance(selectedInstance, _propWindow); - } } } @@ -895,9 +844,12 @@ void Application::onMouseRightUp(int x,int y) void Application::onMouseMoved(int x,int y) { oldMouse = Vector2(mouse.x, mouse.y); + mouse.oldx = mouse.x; + mouse.oldy = mouse.y; mouse.x = x; mouse.y = y; - tool->onMouseMoved(mouse); + //tool->onMouseMoved(mouse); + mouseMoveState = true; //_dataModel->mousex = x; //_dataModel->mousey = y; diff --git a/Application.h b/Application.h index ced42a1..c33f121 100644 --- a/Application.h +++ b/Application.h @@ -56,10 +56,12 @@ class Application { // : public GApp { RenderDevice* getRenderDevice(); void selectInstance(Instance* selectedInstance,PropertyWindow* propWindow); void setMode(int mode); - Mouse mouse; + Tool * tool; void changeTool(Tool *); + Mouse mouse; private: + bool mouseMoveState; RenderDevice* renderDevice; //void initGUI(); HWND _hWndMain; diff --git a/ArrowTool.cpp b/ArrowTool.cpp new file mode 100644 index 0000000..784d57f --- /dev/null +++ b/ArrowTool.cpp @@ -0,0 +1,28 @@ +#include "ArrowTool.h" + +ArrowTool::ArrowTool(void) +{ +} + +ArrowTool::~ArrowTool(void) +{ +} + +void ArrowTool::onButton1MouseDown(Mouse mouse) +{ + g_selectedInstances.clear(); + PartInstance * target = mouse.getTarget(); + if(target != NULL) + g_selectedInstances.push_back(target); +} +void ArrowTool::onMouseMoved(Mouse mouse) +{ + PartInstance * target = mouse.getTarget(); + if(target == NULL) + this->setCursor(GetFileInPath("/content/images/ArrowCursor.png")); + else this->setCursor(GetFileInPath("/content/images/DragCursor.png")); +} +void ArrowTool::onSelect(Mouse mouse) +{ + this->setCursor(GetFileInPath("/content/images/ArrowCursor.png")); +} \ No newline at end of file diff --git a/ArrowTool.h b/ArrowTool.h new file mode 100644 index 0000000..7f24e0b --- /dev/null +++ b/ArrowTool.h @@ -0,0 +1,13 @@ +#pragma once +#include "tool.h" + +class ArrowTool : + public Tool +{ +public: + ArrowTool(void); //OnSelect? + ~ArrowTool(void); //OnDeselect? + virtual void onButton1MouseDown(Mouse); + virtual void onMouseMoved(Mouse mouse); + virtual void onSelect(Mouse mouse); //Why is this not being called +}; diff --git a/G3DTest.vcproj b/G3DTest.vcproj index d2d994b..036c122 100644 --- a/G3DTest.vcproj +++ b/G3DTest.vcproj @@ -306,6 +306,10 @@ RelativePath=".\StringFunctions.cpp" > + + @@ -401,6 +405,10 @@ + + @@ -503,6 +511,10 @@ RelativePath=".\StringFunctions.h" > + + @@ -594,6 +606,10 @@ + + diff --git a/ModeSelectionListener.cpp b/ModeSelectionListener.cpp index 653cd8e..9356155 100644 --- a/ModeSelectionListener.cpp +++ b/ModeSelectionListener.cpp @@ -2,6 +2,7 @@ #include "Instance.h" #include "ModeSelectionListener.h" #include "Application.h" +#include "ArrowTool.h" void ModeSelectionListener::onButton1MouseClick(BaseButtonInstance* button) { @@ -20,7 +21,7 @@ void ModeSelectionListener::onButton1MouseClick(BaseButtonInstance* button) button->selected = true; if(button->name == "Cursor") - g_usableApp->setMode(CURSOR); + g_usableApp->changeTool(new ArrowTool()); else if(button->name == "Resize") g_usableApp->setMode(RESIZE); else if(button->name == "Arrows") diff --git a/Mouse.cpp b/Mouse.cpp index 4b9cd8a..b903b43 100644 --- a/Mouse.cpp +++ b/Mouse.cpp @@ -1,14 +1,43 @@ #include "Mouse.h" +#include "Application.h" +#include "Globals.h" Mouse::Mouse(){ x = y = 0; } Mouse::~Mouse(){} - -Instance * Mouse::getTarget() +PartInstance * selectedInstance = NULL; +Ray testRay; +float nearest=std::numeric_limits::infinity(); +void eprt(PartInstance * instance) { - return NULL; + float time = testRay.intersectionTime(instance->getBox()); + if (time != inf()) + { + if (nearest>time) + { + nearest=time; + selectedInstance = instance; + //This is where dead code below was + } + } } + +PartInstance * Mouse::getTarget() +{ + selectedInstance = NULL; + testRay = g_usableApp->cameraController.getCamera()->worldRay(x, y, g_usableApp->getRenderDevice()->getViewport()); + nearest=std::numeric_limits::infinity(); + //Vector3 camPos = g_usableApp->cameraController.getCamera()->getCoordinateFrame().translation; + for_each (g_dataModel->getWorkspace()->partObjects.begin(), g_dataModel->getWorkspace()->partObjects.end(), eprt); + return selectedInstance; +} + + + + + + Vector3 Mouse::getPosition() { return Vector3(); @@ -28,4 +57,32 @@ bool Mouse::isMouseDown() void Mouse::setMouseDown(bool bval) { mouseDown = bval; -} \ No newline at end of file +} + + + + //bool found = false; + /*for(size_t i = 0; i < g_selectedInstances.size(); i++) + { + if(g_selectedInstances.at(i) == test) + { + found = true; + //ShowWindow(_propWindow->_hwndProp, SW_SHOW); + //SetActiveWindow(_propWindow->_hwndProp); + //SetForegroundWindow(_propWindow->_hwndProp); + break; + } + } + if(!found) + { + selectedInstance = test; + //if(!GetHoldKeyState(VK_RCONTROL) && !GetHoldKeyState(VK_LCONTROL)) + //g_selectedInstances.clear(); + //if(std::find(g_selectedInstances.begin(), g_selectedInstances.end(),test)==g_selectedInstances.end()) + //g_selectedInstances.push_back(test); + } + //selectInstance(test, _propWindow); + //_message = "Dragging = true."; + //_messageTime = System::time(); + //_dragging = true;*/ + diff --git a/Mouse.h b/Mouse.h index 83a1c4c..ff7d1d8 100644 --- a/Mouse.h +++ b/Mouse.h @@ -1,14 +1,18 @@ #pragma once #include "PartInstance.h" +#pragma once +#include "WorkspaceInstance.h" + #pragma once class Mouse { public: - Mouse(void); + Mouse(); ~Mouse(void); int x, y; - Instance * getTarget(); + int oldx, oldy; + PartInstance * getTarget(); Vector3 getPosition(); bool isMouseOnScreen(); bool isMouseDown(); diff --git a/TextureHandler.cpp b/TextureHandler.cpp new file mode 100644 index 0000000..9e3a578 --- /dev/null +++ b/TextureHandler.cpp @@ -0,0 +1,12 @@ +#include "TextureHandler.h" + +TextureHandler::TextureHandler(void) +{ +} + +TextureHandler::~TextureHandler(void) +{ +} +std::map TextureHandler::volTex = std::map(); +std::map TextureHandler::volExp = std::map(); +std::map TextureHandler::permTex = std::map(); \ No newline at end of file diff --git a/TextureHandler.h b/TextureHandler.h new file mode 100644 index 0000000..0c0abf9 --- /dev/null +++ b/TextureHandler.h @@ -0,0 +1,87 @@ +#pragma once +#include +#include +class TextureHandler +{ +public: + TextureHandler(void); + ~TextureHandler(void); + static int getTextureVolatile(std::string str) + { + if(!volTex[str].isNull()) + { + volExp[str] = G3D::System::time(); + return volTex[str]->openGLID(); + } + else + { + G3D::TextureRef tex = G3D::Texture::fromFile(str); + volExp[str] = G3D::System::time(); + volTex[str] = tex; + return tex->openGLID(); + } + } + static int getTexturePermanent(std::string str) + { + if(!permTex[str].isNull()) + { + return permTex[str]->openGLID(); + } + else + { + G3D::TextureRef tex = G3D::Texture::fromFile(str); + permTex[str] = tex; + return tex->openGLID(); + } + } + static void flushVolatile() + { + std::map::iterator it; + for (it=volExp.begin(); it!=volExp.end(); ++it) + { + if(it->second < G3D::System::time() - 3) + { + volTex[it->first]->~Texture(); + volTex.erase(it->first); + volExp.erase(it->first); + //it->second->~ReferenceCountedPointer(); + } + } + } + static void dispose() + { + std::map::iterator it; + for (it=volTex.begin(); it!=volTex.end(); ++it) + { + it->second->~Texture(); + //it->second->~ReferenceCountedPointer(); + } + for (it=permTex.begin(); it!=permTex.end(); ++it) + { + it->second->~Texture(); + //it->second->~ReferenceCountedPointer(); + } + permTex.clear(); + volTex.clear(); + } + + static void remove(std::string str) + { + if(!volTex[str].isNull()) + { + volTex[str]->~Texture(); + //volTex[str]->~ReferenceCountedPointer(); + volTex.erase(str); + } + if(!permTex[str].isNull()) + { + permTex[str]->~Texture(); + //permTex[str]->~ReferenceCountedPointer(); + permTex.erase(str); + } + } +private: + static std::map volTex; + static std::map volExp; + static std::map permTex; +}; \ No newline at end of file diff --git a/Tool.cpp b/Tool.cpp index 169b92b..529f3af 100644 --- a/Tool.cpp +++ b/Tool.cpp @@ -2,8 +2,8 @@ Tool::Tool(void) { - cursorRef = Texture::fromFile(GetFileInPath("/content/images/ArrowCursor.png")); - cursorId = cursorRef->openGLID(); + cursorString = GetFileInPath("/content/images/ArrowFarCursor.png"); + //cursorId = cursorRef->openGLID(); } Tool::~Tool(void) @@ -22,14 +22,11 @@ void Tool::onDeselect(Mouse mouse){} void Tool::onMouseScroll(Mouse mouse){} void Tool::onKeyDown(char key){} void Tool::onKeyUp(char key){} -void Tool::setCursor(std::string) +void Tool::setCursor(std::string str) { + cursorString = str; } int Tool::getCursorId() { - return cursorId; -} -void Tool::setCursorId(int id) -{ - cursorId = id; + return TextureHandler::getTexturePermanent(cursorString); } \ No newline at end of file diff --git a/Tool.h b/Tool.h index bd1868b..dc81f7d 100644 --- a/Tool.h +++ b/Tool.h @@ -1,4 +1,6 @@ #pragma once +#include "TextureHandler.h" +#pragma once #include #pragma once #include "Mouse.h" @@ -12,23 +14,21 @@ class Tool public: Tool(void); ~Tool(void); - void onButton1MouseDown(Mouse); //yes - void onButton2MouseDown(Mouse); //yes - void onButton3MouseDown(Mouse); - void onButton1MouseUp(Mouse);//yes - void onButton2MouseUp(Mouse);//yes - void onButton3MouseUp(Mouse); - void onMouseMoved(Mouse);//yes - void onSelect(Mouse);//For later - void onDeselect(Mouse);//For later - void onMouseScroll(Mouse);//Kinda - void onKeyDown(char);//yes - void onKeyUp(char);//yes - void setCursor(std::string); - void setCursorId(int);//yes - int getCursorId();//yes + virtual void onButton1MouseDown(Mouse); //yes + virtual void onButton2MouseDown(Mouse); //yes + virtual void onButton3MouseDown(Mouse); //no + virtual void onButton1MouseUp(Mouse);//yes + virtual void onButton2MouseUp(Mouse);//yes + virtual void onButton3MouseUp(Mouse); //no + virtual void onMouseMoved(Mouse);//yes + virtual void onSelect(Mouse);//yes + virtual void onDeselect(Mouse);//yes + virtual void onMouseScroll(Mouse);//Kinda + virtual void onKeyDown(char);//yes + virtual void onKeyUp(char);//yes + virtual int getCursorId();//yes +protected: + virtual void setCursor(std::string); private: - int cursorId; - G3D::TextureRef cursorRef; std::string cursorString; }; diff --git a/content/images/ArrowFarCursor.png b/content/images/ArrowFarCursor.png new file mode 100644 index 0000000000000000000000000000000000000000..9a1954a334a7b330ad6beae16d11c14ef670f0a6 GIT binary patch literal 2169 zcmb7F`8yMiA9uDKi_8$JIaY3SPAILAOmY;V^wpp6eLv6Z{d%6)^Ss`#=Xw3|PDa^W0t!kCa&d71krt+Q2aNiM!-o!b z`q7Q*15zWIp-C4*ys;#F;0=faKERvH0T&9<)`r-72SK!9Fg=KtwxKS}PzMfChZ(?N zwQnsJ4}1U;(%K9#!Yw2r!{;Ec>Tw_m1X(x}xwuYr`~!Cv-ogGrSY16@LF+oaSgb4);Jk_6gkjP{!bg|pz%PGOkLPT40bMx1{hYxdyaHQFM zz}&blELQ+}mu^>8B1Kr{@Vm6|;A0*m&VHe0W@2)(vW`lhJZUoY=~HV>X=!)i5RNf1 zKE7go>Yj*KF%?A?201hM8NIJXv>*tL9d1x?x-Atp6Pu!>q9Qoa5HMkzm6f$n+xKvO zHY_a6XZwczs*!Nntr|k0IS^(1xMUrG8z#^vySg4vybSuY`?CU%$9E464K*eSAM12; zbyf3(DsL)MdlU3pp8LwGvP`9ZodpG_1x_(`FwV|nyztmxYct`E{$n9Z%E}ew$)@0K z27{qieYdZmtv#?EP7NX&(cz=)!k2-dUvOn?M;w1NtMclNv(0r)O=O~@ zfNEr9^bm~fOMEe6jsCL{E6DjJh)7&tE+p{lW}q|COW#Q zwY9bMzkA*%Fvb4MITFa=+Eo3^t5Tw(qFV+cXM$%{ni7| zElg{yiIQ93gD=4RAIdbeugLn@K04RGyu2JK4(LbMdnJ3~@n0z^DJcSUI(-rYlUo0I zHOK_bRp8kvwg;8%h`@kx(q}>xGg4Bd+4p30baZGNo11=+&nxruUSZC=a)KSYs5iU8 zJawkBXubw}d_A@+$qfpHo)c-o&h?~q%`7fZD3k|dIguRyAOn!edr-#%?IYbrA#-6V z?$*}UfnDJEmmoDwO}4_6ncVdr7Ml&w)7Q__%$hjCN9-VMiMx)BM`10Qi?=Ct`9w*Q zqVU-uZf(w0OF6I6TKgw9F%df(3uF8H`z=?tWVe6($d8`u0fzq=n6JE;d*@G1ZaM#> za@z(d|6Mvc{@Dde!5v>|^lZUF1C~A%Dpe}hYgEBP`<{xbYN(u?T=2&ywttTVd_pK~ z&?_rd*o%uk1pW%zW1iNeWIooCy^LRn)S41bSWs{lH6TxtIl>vK{#g9VFO*2sA?W7C za*XaKXJoirz*i?416M|>uT5l=Ed&+XrrwzP$IPN}s*tBUvMWL1;Y*e|8Vi2xntoRX zIan{oQQY&ywtbOrN^0snacO{tfJ=hG5nyrgwWA8=RB!yG*~h#JUbEyEy*nkcgzo9$ z=no}GS*-#8&=TFtV!EM4yEXhFW%uukr>ExEhku_MD9NQ#4GiVwI}4Sv_6vMG(hVS@ z{igb>4tcZn!|y(1-(s8;t+?=(F|0vSoQa{XO zq6%m-o+^Ax)LjH@#Zf*->$5lSE0-lI*#&_eH!r?RwR%Eg(QQe*J*)`HYZq#4%zP zbc&nUE=LG#c*d03E*^+aDy6mR_KSnW#3~)D&_x`TCeJtN=6$OxZB?&wetKH20Q0F9 zV%dcP)sW*N`3O7+tDJDcr6p!>D(n{_#G!+1H~NF)c5Et(k+c0cLCnoj=8yXtm91iEJ!q0h-!Jdv83NL%AI!Fotxi?28#5ZuS>pR=Ai z4cb~+F{+ztkXbu|CA`&?mDX*_cn8fY;_scVz1M4NVVhBUCB`A!B&PkhZWq-r z*)yIP0Pw_p`8 Date: Fri, 13 Mar 2020 18:06:55 -0700 Subject: [PATCH 10/18] Fixed memory error --- PartInstance.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/PartInstance.cpp b/PartInstance.cpp index e71c224..cc95f0f 100644 --- a/PartInstance.cpp +++ b/PartInstance.cpp @@ -76,19 +76,20 @@ void PartInstance::postRender(RenderDevice *rd) } } -void PartInstance::setParent(Instance* parent) +void PartInstance::setParent(Instance* prnt) { - Instance * cparent = this->parent; + Instance * cparent = getParent(); while(cparent != NULL) { - if(WorkspaceInstance* workspace = dynamic_cast(parent)) + if(WorkspaceInstance* workspace = dynamic_cast(cparent)) { + std::cout << "Removed from partarray " << std::endl; workspace->partObjects.erase(std::remove(workspace->partObjects.begin(), workspace->partObjects.end(), this), workspace->partObjects.end()); break; } cparent = cparent->getParent(); } - Instance::setParent(parent); + Instance::setParent(prnt); while(parent != NULL) { if(WorkspaceInstance* workspace = dynamic_cast(parent)) From bd8209958dfc2aa2677d7a9adff126c61685b77c Mon Sep 17 00:00:00 2001 From: andreja6 Date: Fri, 13 Mar 2020 18:50:48 -0700 Subject: [PATCH 11/18] New selection method, fixed crashing --- ArrowTool.cpp | 25 +++++++++++++++++++++++-- ArrowTool.h | 7 ++++++- Tool.cpp | 4 ++-- Tool.h | 4 ++-- 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/ArrowTool.cpp b/ArrowTool.cpp index 784d57f..e89c63d 100644 --- a/ArrowTool.cpp +++ b/ArrowTool.cpp @@ -1,7 +1,10 @@ #include "ArrowTool.h" +#include "Application.h" ArrowTool::ArrowTool(void) { + lctrlDown = false; + rctrlDown = false; } ArrowTool::~ArrowTool(void) @@ -10,10 +13,14 @@ ArrowTool::~ArrowTool(void) void ArrowTool::onButton1MouseDown(Mouse mouse) { - g_selectedInstances.clear(); + if(!lctrlDown && !rctrlDown) + g_selectedInstances.clear(); PartInstance * target = mouse.getTarget(); - if(target != NULL) + if(target != NULL && std::find(g_selectedInstances.begin(), g_selectedInstances.end(), target) == g_selectedInstances.end()) g_selectedInstances.push_back(target); + if(g_selectedInstances.size() == 0) + g_selectedInstances.push_back(g_dataModel); + g_usableApp->_propWindow->UpdateSelected(g_selectedInstances[0]); } void ArrowTool::onMouseMoved(Mouse mouse) { @@ -25,4 +32,18 @@ void ArrowTool::onMouseMoved(Mouse mouse) void ArrowTool::onSelect(Mouse mouse) { this->setCursor(GetFileInPath("/content/images/ArrowCursor.png")); +} + +void ArrowTool::onKeyDown(int key) +{ + if(key == VK_CONTROL) + { + lctrlDown = true; + } +} + +void ArrowTool::onKeyUp(int key) +{ + if(key == VK_CONTROL) + lctrlDown = false; } \ No newline at end of file diff --git a/ArrowTool.h b/ArrowTool.h index 7f24e0b..5eb928c 100644 --- a/ArrowTool.h +++ b/ArrowTool.h @@ -9,5 +9,10 @@ public: ~ArrowTool(void); //OnDeselect? virtual void onButton1MouseDown(Mouse); virtual void onMouseMoved(Mouse mouse); - virtual void onSelect(Mouse mouse); //Why is this not being called + virtual void onSelect(Mouse mouse); + virtual void onKeyDown(int key); + virtual void onKeyUp(int key); +private: + bool lctrlDown; + bool rctrlDown; }; diff --git a/Tool.cpp b/Tool.cpp index 529f3af..25f8f93 100644 --- a/Tool.cpp +++ b/Tool.cpp @@ -20,8 +20,8 @@ void Tool::onMouseMoved(Mouse mouse){} void Tool::onSelect(Mouse mouse){} void Tool::onDeselect(Mouse mouse){} void Tool::onMouseScroll(Mouse mouse){} -void Tool::onKeyDown(char key){} -void Tool::onKeyUp(char key){} +void Tool::onKeyDown(int key){} +void Tool::onKeyUp(int key){} void Tool::setCursor(std::string str) { cursorString = str; diff --git a/Tool.h b/Tool.h index dc81f7d..292db3f 100644 --- a/Tool.h +++ b/Tool.h @@ -24,8 +24,8 @@ public: virtual void onSelect(Mouse);//yes virtual void onDeselect(Mouse);//yes virtual void onMouseScroll(Mouse);//Kinda - virtual void onKeyDown(char);//yes - virtual void onKeyUp(char);//yes + virtual void onKeyDown(int);//yes + virtual void onKeyUp(int);//yes virtual int getCursorId();//yes protected: virtual void setCursor(std::string); From 9217e78084c5c503186edce09bd8d133cbcacf87 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Fri, 13 Mar 2020 23:13:58 -0700 Subject: [PATCH 12/18] Attempted to make getPosition... --- Application.cpp | 3 ++- Mouse.cpp | 46 +++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/Application.cpp b/Application.cpp index c643ecc..1e09ce1 100644 --- a/Application.cpp +++ b/Application.cpp @@ -689,7 +689,8 @@ void Application::onGraphics(RenderDevice* rd) { glDisableClientState(GL_NORMAL_ARRAY); rd->setObjectToWorldMatrix(forDraw); rd->afterPrimitive(); - + + Draw::sphere(G3D::Sphere(mouse.getPosition(), 1), rd, Color3::cyan(), Color4::clear()); if(g_selectedInstances.size() > 0) { for(size_t i = 0; i < g_selectedInstances.size(); i++) diff --git a/Mouse.cpp b/Mouse.cpp index b903b43..2fec28a 100644 --- a/Mouse.cpp +++ b/Mouse.cpp @@ -1,6 +1,7 @@ #include "Mouse.h" #include "Application.h" #include "Globals.h" + Mouse::Mouse(){ x = y = 0; } @@ -34,14 +35,49 @@ PartInstance * Mouse::getTarget() } - - - +double getVectorDistance(Vector3 vector1, Vector3 vector2) +{ + 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); +} Vector3 Mouse::getPosition() { - return Vector3(); - //Not implemented + testRay = g_usableApp->cameraController.getCamera()->worldRay(x, y, g_usableApp->getRenderDevice()->getViewport()); + Vector3 pos = testRay.closestPoint(Vector3(0,0,0)); + nearest=std::numeric_limits::infinity(); + //Vector3 camPos = g_usableApp->cameraController.getCamera()->getCoordinateFrame().translation; + for(size_t i = 0; i < g_dataModel->getWorkspace()->partObjects.size(); i++) + { + PartInstance * p = g_dataModel->getWorkspace()->partObjects[i]; + if(G3D::isFinite(testRay.intersectionTime(p->getBox()))) + { + + if (nearest>testRay.intersectionTime(p->getBox())) + { + + // BROKEN + pos = (testRay.closestPoint(p->getPosition()/2)); + } + + /* // This would be an overall better solution + for(char i = 0; i < 6; i++) + { + Vector3 side1; + Vector3 side2; + Vector3 side3; + Vector3 side4; + p->getBox().getFaceCorners(i, side1, side2, side3, side4); + Vector3 inter = testRay.intersection(G3D::Plane(side2, side3, side4)); + float newdistance = testRay.distance(inter); + if(nearest > abs(newdistance)) + { + nearest = newdistance; + pos = inter; + } + }*/ + } + } + return pos; } bool Mouse::isMouseOnScreen() { From 520e7f1befae30f780c6f1f57aa665863f6313c6 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Fri, 13 Mar 2020 23:50:37 -0700 Subject: [PATCH 13/18] Added (really horrible) dragging --- ArrowTool.cpp | 31 +++++++++++++++++++++++++++++++ ArrowTool.h | 5 +++++ Mouse.cpp | 8 ++++---- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/ArrowTool.cpp b/ArrowTool.cpp index e89c63d..be6ca89 100644 --- a/ArrowTool.cpp +++ b/ArrowTool.cpp @@ -5,6 +5,8 @@ ArrowTool::ArrowTool(void) { lctrlDown = false; rctrlDown = false; + dragging = false; + mouseDown = false; } ArrowTool::~ArrowTool(void) @@ -13,6 +15,7 @@ ArrowTool::~ArrowTool(void) void ArrowTool::onButton1MouseDown(Mouse mouse) { + mouseDown = true; if(!lctrlDown && !rctrlDown) g_selectedInstances.clear(); PartInstance * target = mouse.getTarget(); @@ -22,8 +25,36 @@ void ArrowTool::onButton1MouseDown(Mouse mouse) g_selectedInstances.push_back(g_dataModel); g_usableApp->_propWindow->UpdateSelected(g_selectedInstances[0]); } +void ArrowTool::onButton1MouseUp(Mouse mouse) +{ + if(dragging) + this->setCursor(GetFileInPath("/content/images/ArrowCursor.png")); + mouseDown = false; + dragging = false; +} + void ArrowTool::onMouseMoved(Mouse mouse) { + if(mouseDown) + { + if(!dragging) + { + if(abs(mouse.x-mouseDownStartx) > 5 || abs(mouse.y-mouseDownStarty) > 5) + { + this->setCursor(GetFileInPath("/content/images/GrabRotateCursor.png")); + dragging = true; + } + else return; + } + for(size_t i = 0; i < g_selectedInstances.size(); i++) //This will later decide primary and move all parts according to primary + { + if(PartInstance * part = dynamic_cast(g_selectedInstances[i])) + { + part->setPosition(mouse.getPosition()); + } + } + return; + } PartInstance * target = mouse.getTarget(); if(target == NULL) this->setCursor(GetFileInPath("/content/images/ArrowCursor.png")); diff --git a/ArrowTool.h b/ArrowTool.h index 5eb928c..0da873d 100644 --- a/ArrowTool.h +++ b/ArrowTool.h @@ -8,6 +8,7 @@ public: ArrowTool(void); //OnSelect? ~ArrowTool(void); //OnDeselect? virtual void onButton1MouseDown(Mouse); + virtual void onButton1MouseUp(Mouse); virtual void onMouseMoved(Mouse mouse); virtual void onSelect(Mouse mouse); virtual void onKeyDown(int key); @@ -15,4 +16,8 @@ public: private: bool lctrlDown; bool rctrlDown; + int mouseDownStartx; + int mouseDownStarty; + bool dragging; + bool mouseDown; }; diff --git a/Mouse.cpp b/Mouse.cpp index 2fec28a..b029b33 100644 --- a/Mouse.cpp +++ b/Mouse.cpp @@ -52,14 +52,14 @@ Vector3 Mouse::getPosition() if(G3D::isFinite(testRay.intersectionTime(p->getBox()))) { - if (nearest>testRay.intersectionTime(p->getBox())) + /*if (nearest>testRay.intersectionTime(p->getBox())) { // BROKEN pos = (testRay.closestPoint(p->getPosition()/2)); - } + }*/ - /* // This would be an overall better solution + // This would be an overall better solution for(char i = 0; i < 6; i++) { Vector3 side1; @@ -74,7 +74,7 @@ Vector3 Mouse::getPosition() nearest = newdistance; pos = inter; } - }*/ + } } } return pos; From 24a4aed4f184e6424b6c66f919ad2ec803fcfc84 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Sat, 14 Mar 2020 13:13:59 -0700 Subject: [PATCH 14/18] Made dragging slightly less horrific --- ArrowTool.cpp | 2 +- Mouse.cpp | 9 ++++++--- Mouse.h | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/ArrowTool.cpp b/ArrowTool.cpp index be6ca89..596ea8a 100644 --- a/ArrowTool.cpp +++ b/ArrowTool.cpp @@ -50,7 +50,7 @@ void ArrowTool::onMouseMoved(Mouse mouse) { if(PartInstance * part = dynamic_cast(g_selectedInstances[i])) { - part->setPosition(mouse.getPosition()); + part->setPosition(mouse.getPosition(g_selectedInstances)); } } return; diff --git a/Mouse.cpp b/Mouse.cpp index b029b33..6e57791 100644 --- a/Mouse.cpp +++ b/Mouse.cpp @@ -1,6 +1,7 @@ #include "Mouse.h" #include "Application.h" #include "Globals.h" +#include Mouse::Mouse(){ x = y = 0; @@ -40,15 +41,17 @@ double getVectorDistance(Vector3 vector1, Vector3 vector2) 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); } -Vector3 Mouse::getPosition() +Vector3 Mouse::getPosition(std::vector ignore) { testRay = g_usableApp->cameraController.getCamera()->worldRay(x, y, g_usableApp->getRenderDevice()->getViewport()); - Vector3 pos = testRay.closestPoint(Vector3(0,0,0)); + Vector3 pos = Vector3(0,0,0); nearest=std::numeric_limits::infinity(); //Vector3 camPos = g_usableApp->cameraController.getCamera()->getCoordinateFrame().translation; for(size_t i = 0; i < g_dataModel->getWorkspace()->partObjects.size(); i++) { PartInstance * p = g_dataModel->getWorkspace()->partObjects[i]; + if(std::find(ignore.begin(), ignore.end(), p) != ignore.end()) + continue; if(G3D::isFinite(testRay.intersectionTime(p->getBox()))) { @@ -67,7 +70,7 @@ Vector3 Mouse::getPosition() Vector3 side3; Vector3 side4; p->getBox().getFaceCorners(i, side1, side2, side3, side4); - Vector3 inter = testRay.intersection(G3D::Plane(side2, side3, side4)); + Vector3 inter = testRay.intersection(G3D::Plane(side1, side2, side3)); float newdistance = testRay.distance(inter); if(nearest > abs(newdistance)) { diff --git a/Mouse.h b/Mouse.h index ff7d1d8..2d6e4aa 100644 --- a/Mouse.h +++ b/Mouse.h @@ -13,7 +13,7 @@ public: int x, y; int oldx, oldy; PartInstance * getTarget(); - Vector3 getPosition(); + Vector3 getPosition(std::vector ignore = std::vector()); bool isMouseOnScreen(); bool isMouseDown(); void setMouseDown(bool mouseDown); From 5bdeac2f6649672fbb1f40810ca7a832e16fd508 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Sat, 14 Mar 2020 17:59:56 -0700 Subject: [PATCH 15/18] Removed comment --- Mouse.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/Mouse.cpp b/Mouse.cpp index 6e57791..970dfb4 100644 --- a/Mouse.cpp +++ b/Mouse.cpp @@ -54,15 +54,6 @@ Vector3 Mouse::getPosition(std::vector ignore) continue; if(G3D::isFinite(testRay.intersectionTime(p->getBox()))) { - - /*if (nearest>testRay.intersectionTime(p->getBox())) - { - - // BROKEN - pos = (testRay.closestPoint(p->getPosition()/2)); - }*/ - - // This would be an overall better solution for(char i = 0; i < 6; i++) { Vector3 side1; From 73a6b72c206af88e34b518ecc25482b727957ccb Mon Sep 17 00:00:00 2001 From: andreja6 Date: Sat, 14 Mar 2020 18:56:49 -0700 Subject: [PATCH 16/18] added getPositionAndPart --- Mouse.cpp | 42 ++++++++++++++++++++---------------------- Mouse.h | 12 +++++++++++- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/Mouse.cpp b/Mouse.cpp index 970dfb4..3ead8d0 100644 --- a/Mouse.cpp +++ b/Mouse.cpp @@ -41,38 +41,36 @@ double getVectorDistance(Vector3 vector1, Vector3 vector2) 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); } -Vector3 Mouse::getPosition(std::vector ignore) +MousePoint Mouse::getPositionAndPart(std::vector ignore) { testRay = g_usableApp->cameraController.getCamera()->worldRay(x, y, g_usableApp->getRenderDevice()->getViewport()); - Vector3 pos = Vector3(0,0,0); + PartInstance * currPart = NULL; + Vector3 pos = testRay.closestPoint(Vector3(0,0,0)); nearest=std::numeric_limits::infinity(); - //Vector3 camPos = g_usableApp->cameraController.getCamera()->getCoordinateFrame().translation; for(size_t i = 0; i < g_dataModel->getWorkspace()->partObjects.size(); i++) { PartInstance * p = g_dataModel->getWorkspace()->partObjects[i]; if(std::find(ignore.begin(), ignore.end(), p) != ignore.end()) continue; - if(G3D::isFinite(testRay.intersectionTime(p->getBox()))) - { - for(char i = 0; i < 6; i++) - { - Vector3 side1; - Vector3 side2; - Vector3 side3; - Vector3 side4; - p->getBox().getFaceCorners(i, side1, side2, side3, side4); - Vector3 inter = testRay.intersection(G3D::Plane(side1, side2, side3)); - float newdistance = testRay.distance(inter); - if(nearest > abs(newdistance)) - { - nearest = newdistance; - pos = inter; - } - } - } + float newdistance = testRay.intersectionTime(p->getBox()); //testRay.distance(inter); + if(G3D::isFinite(newdistance)) + { + if(nearest > abs(newdistance)) + { + nearest = newdistance; + pos = testRay.origin+(testRay.direction*nearest); + currPart = p; + } + } } - return pos; + return MousePoint(pos, currPart); } + +Vector3 Mouse::getPosition(std::vector ignore) +{ + return getPositionAndPart(ignore).position; +} + bool Mouse::isMouseOnScreen() { //hm diff --git a/Mouse.h b/Mouse.h index 2d6e4aa..929fbf6 100644 --- a/Mouse.h +++ b/Mouse.h @@ -3,8 +3,17 @@ #pragma once #include "WorkspaceInstance.h" -#pragma once +struct MousePoint{ + Vector3 position; + PartInstance * target; + MousePoint(Vector3 pos, PartInstance * targ) + { + position = pos; + target = targ; + } +}; +#pragma once class Mouse { public: @@ -13,6 +22,7 @@ public: int x, y; int oldx, oldy; PartInstance * getTarget(); + MousePoint getPositionAndPart(std::vector ignore = std::vector()); Vector3 getPosition(std::vector ignore = std::vector()); bool isMouseOnScreen(); bool isMouseDown(); From 0090c6c8a1775b0d1de2fbc8c741bdf59eccef44 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Sun, 15 Mar 2020 11:46:06 -0700 Subject: [PATCH 17/18] Added PartInstance->Collides function --- PartInstance.cpp | 28 +++++++++++++++++++++++++++- PartInstance.h | 2 ++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/PartInstance.cpp b/PartInstance.cpp index cc95f0f..9c244e3 100644 --- a/PartInstance.cpp +++ b/PartInstance.cpp @@ -206,8 +206,27 @@ void PartInstance::setCFrame(CoordinateFrame coordinateFrame) // Can probably be deleted CoordinateFrame PartInstance::getCFrameRenderBased() { - return CoordinateFrame(getCFrame().rotation,Vector3(getCFrame().translation.x, getCFrame().translation.y, getCFrame().translation.z)); + return cFrame;//CoordinateFrame(getCFrame().rotation,Vector3(getCFrame().translation.x, getCFrame().translation.y, getCFrame().translation.z)); } + +bool PartInstance::collides(PartInstance * part) +{ + if(shape == Enum::Shape::Block) + { + if(part->shape == Enum::Shape::Block) + return G3D::CollisionDetection::fixedSolidBoxIntersectsFixedSolidBox(getBox(), part->getBox()); + else + return G3D::CollisionDetection::fixedSolidSphereIntersectsFixedSolidBox(part->getSphere(), getBox()); + } + else + { + if(part->shape == Enum::Shape::Block) + return G3D::CollisionDetection::fixedSolidSphereIntersectsFixedSolidBox(getSphere(), part->getBox()); + else + return G3D::CollisionDetection::fixedSolidSphereIntersectsFixedSolidSphere(getSphere(), part->getSphere()); + } +} + #ifdef NEW_BOX_RENDER Box PartInstance::getBox() { @@ -216,6 +235,13 @@ Box PartInstance::getBox() itemBox = c.toWorldSpace(box); return itemBox; } +Sphere PartInstance::getSphere() +{ + Sphere sphere = Sphere(Vector3(0,0,0), size.y/2); + CoordinateFrame c = getCFrameRenderBased(); + //itemBox = c.toWorldSpace(Sphere); + return sphere;//itemBox; +} #else Box PartInstance::getBox() { diff --git a/PartInstance.h b/PartInstance.h index b47e22b..6df56b7 100644 --- a/PartInstance.h +++ b/PartInstance.h @@ -31,10 +31,12 @@ public: void setParent(Instance* parent); void setPosition(Vector3); void setVelocity(Vector3); + bool collides(PartInstance * part); void setRotVelocity(Vector3); CoordinateFrame getCFrame(); void setCFrame(CoordinateFrame); Box getBox(); + Sphere getSphere(); Box getScaledBox(); CoordinateFrame getCFrameRenderBased(); Vector3 getSize(); From c08254562fca1b7a5572d2d1c888ada379f17e2e Mon Sep 17 00:00:00 2001 From: andreja6 Date: Mon, 16 Mar 2020 21:11:28 -0700 Subject: [PATCH 18/18] fixed teleporting drag --- Application.cpp | 7 ++++++- ArrowTool.cpp | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Application.cpp b/Application.cpp index 1e09ce1..5e12d2a 100644 --- a/Application.cpp +++ b/Application.cpp @@ -674,7 +674,9 @@ void Application::onGraphics(RenderDevice* rd) { renderDevice->setLight(0, GLight::directional(lighting.lightDirection, lighting.lightColor)); renderDevice->setAmbientLightColor(lighting.ambient); - + //renderDevice->setBlendFunc(RenderDevice::BLEND_ONE, RenderDevice::BLEND_ONE); + + rd->beforePrimitive(); CoordinateFrame forDraw = rd->getObjectToWorldMatrix(); glEnableClientState(GL_VERTEX_ARRAY); @@ -689,6 +691,9 @@ void Application::onGraphics(RenderDevice* rd) { glDisableClientState(GL_NORMAL_ARRAY); rd->setObjectToWorldMatrix(forDraw); rd->afterPrimitive(); + + + Draw::sphere(G3D::Sphere(mouse.getPosition(), 1), rd, Color3::cyan(), Color4::clear()); if(g_selectedInstances.size() > 0) diff --git a/ArrowTool.cpp b/ArrowTool.cpp index 596ea8a..ad58279 100644 --- a/ArrowTool.cpp +++ b/ArrowTool.cpp @@ -15,6 +15,8 @@ ArrowTool::~ArrowTool(void) void ArrowTool::onButton1MouseDown(Mouse mouse) { + mouseDownStartx = mouse.x; + mouseDownStarty = mouse.y; mouseDown = true; if(!lctrlDown && !rctrlDown) g_selectedInstances.clear();