From edf1bc701b9cca7fc24c11b25ef20cde634b4d83 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Wed, 24 Oct 2018 14:14:38 -0700 Subject: [PATCH 01/33] The closest i've gotten so far to images on the property grid --- PropertyWindow.cpp | 80 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) diff --git a/PropertyWindow.cpp b/PropertyWindow.cpp index cd7b2e6..18378d0 100644 --- a/PropertyWindow.cpp +++ b/PropertyWindow.cpp @@ -4,6 +4,7 @@ #include "resource.h" #include "PropertyWindow.h" #include "Globals.h" +#include "strsafe.h" /*typedef struct typPRGP { Instance* instance; // Declare member types Property ∝ @@ -13,9 +14,12 @@ std::vector prop; std::vector children; Instance* selectedInstance; +const int CX_BITMAP = 16; +const int CY_BITMAP = 16; LRESULT CALLBACK PropProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { + TCHAR achTemp[256]; PropertyWindow *propWind = (PropertyWindow *)GetWindowLongPtr(hwnd, GWL_USERDATA); if (propWind==NULL) { @@ -28,6 +32,78 @@ LRESULT CALLBACK PropProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) ShowWindow(hwnd, SW_HIDE); } break; + case WM_DRAWITEM: + { + std::cout << "Drawing?" << "\r\n"; + COLORREF clrBackground; + COLORREF clrForeground; + TEXTMETRIC tm; + int x; + int y; + HRESULT hr; + size_t cch; + + LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT) lParam; + + if (lpdis->itemID == -1) // Empty item) + break; + + // Get the food icon from the item data. + HBITMAP hbmIcon = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP1)); + HBITMAP hbmMask = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP1)); + // The colors depend on whether the item is selected. + clrForeground = SetTextColor(lpdis->hDC, + GetSysColor(lpdis->itemState & ODS_SELECTED ? + COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT)); + + clrBackground = SetBkColor(lpdis->hDC, + GetSysColor(lpdis->itemState & ODS_SELECTED ? + COLOR_HIGHLIGHT : COLOR_WINDOW)); + + // Calculate the vertical and horizontal position. + GetTextMetrics(lpdis->hDC, &tm); + y = (lpdis->rcItem.bottom + lpdis->rcItem.top - tm.tmHeight) / 2; + x = LOWORD(GetDialogBaseUnits()) / 4; + + // Get and display the text for the list item. + SendMessage(lpdis->hwndItem, CB_GETLBTEXT, lpdis->itemID, (LPARAM) achTemp); + + hr = StringCchLength(achTemp, 256, &cch); + if (FAILED(hr)) + { + // TODO: Write error handler. + } + + ExtTextOut(lpdis->hDC, CX_BITMAP + 2 * x, y, + ETO_CLIPPED | ETO_OPAQUE, &lpdis->rcItem, + achTemp, (UINT)cch, NULL); + + // Restore the previous colors. + SetTextColor(lpdis->hDC, clrForeground); + SetBkColor(lpdis->hDC, clrBackground); + + // Draw the food icon for the item. + HDC hdc = CreateCompatibleDC(lpdis->hDC); + if (hdc == NULL) + break; + + SelectObject(hdc, hbmMask); + BitBlt(lpdis->hDC, x, lpdis->rcItem.top + 1, + CX_BITMAP, CY_BITMAP, hdc, 0, 0, SRCAND); + + SelectObject(hdc, hbmIcon); + BitBlt(lpdis->hDC, x, lpdis->rcItem.top + 1, + CX_BITMAP, CY_BITMAP, hdc, 0, 0, SRCPAINT); + + DeleteDC(hdc); + + // If the item has the focus, draw the focus rectangle. + if (lpdis->itemState & ODS_FOCUS) + DrawFocusRect(lpdis->hDC, &lpdis->rcItem); + + + } + break; case WM_MEASUREITEM: { LPMEASUREITEMSTRUCT lpmis = (LPMEASUREITEMSTRUCT) lParam; @@ -58,6 +134,7 @@ LRESULT CALLBACK PropProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) } } break; + case WM_NOTIFY: { switch(((LPNMHDR)lParam)->code) @@ -92,7 +169,8 @@ void PropertyWindow::refreshExplorer() { SendMessage(_explorerComboBox,CB_ADDSTRING, 0,(LPARAM)children.at(z)->name.c_str()); } - SendMessage(_explorerComboBox,CB_SETCURSEL,0,(LPARAM)0); + SendMessage(_explorerComboBox,CB_SETCURSEL,0,(LPARAM)0); + InvalidateRect(_explorerComboBox, NULL, NULL); } } From 0174605a3e6367cf1b65d02d409f4e01b8db21e0 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Wed, 24 Oct 2018 14:40:46 -0700 Subject: [PATCH 02/33] Made mouse way less awkward --- main.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/main.cpp b/main.cpp index 80fad74..94901e5 100644 --- a/main.cpp +++ b/main.cpp @@ -46,6 +46,7 @@ #endif HWND hwnd; + DEFINE_GUID(CLSID_G3d, 0xB323F8E0L, 0x2E68, 0x11D0, 0x90, 0xEA, 0x00, 0xAA, 0x00, 0x60, 0xF8, 0x6F); HRESULT hresult; OLECHAR dat = ((OLECHAR)"SayHello"); @@ -876,6 +877,8 @@ bool IsHolding(int button) return (GetKeyState(button) >> 1)>0; } + + BOOL GetKPBool(int VK) { return (GetKeyState(VK) & 0x8000); } @@ -979,7 +982,7 @@ void makeFlag(Vector3 &vec, RenderDevice* &rd) -bool mouseInArea(float point1x, float point1y, float point2x, float point2y) +/*bool mouseInArea(float point1x, float point1y, float point2x, float point2y) { @@ -991,7 +994,7 @@ bool mouseInArea(float point1x, float point1y, float point2x, float point2y) } } return false; -} +}*/ void drawButtons(RenderDevice* rd) @@ -1101,11 +1104,13 @@ void Demo::onGraphics(RenderDevice* rd) { mouseOnScreen = true; if (GetCursorPos(&mousepos)) { + POINT pointm = mousepos; if (ScreenToClient(_hWndMain, &mousepos)) { //mouseOnScreen = true; - - if(mousepos.x < 1 || mousepos.y < 1 || mousepos.x >= rd->getViewport().width()-1 || mousepos.y >= rd->getViewport().height()-1) + //POINT pointm; + ///GetCursorPos(&pointm); + if(_hwndRenderer != WindowFromPoint(pointm)) //OLD: mousepos.x < 1 || mousepos.y < 1 || mousepos.x >= rd->getViewport().width()-1 || mousepos.y >= rd->getViewport().height()-1 { mouseOnScreen = false; //ShowCursor(true); From 581f8a3413e28144c57b59536e53ff4a94aff912 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Wed, 24 Oct 2018 15:14:24 -0700 Subject: [PATCH 03/33] made delete work --- main.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/main.cpp b/main.cpp index 94901e5..888106d 100644 --- a/main.cpp +++ b/main.cpp @@ -1487,6 +1487,27 @@ LRESULT CALLBACK G3DProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) case WM_MOUSEMOVE: app->onMouseMoved(LOWORD(lParam),HIWORD(lParam)); break; + case WM_KEYDOWN: + if ((HIWORD(lParam)&0x4000)==0) // single key press + { + app->onKeyPressed(wParam); + } + break; + case WM_KEYUP: + { + app->onKeyUp(wParam); + } + break; + case WM_SYSKEYDOWN: + if ((HIWORD(lParam)&0x4000)==0) // single key press + { + app->onKeyPressed(wParam); + } + break; + case WM_SYSKEYUP: + { + app->onKeyUp(wParam); + } case WM_SIZE: { app->onGraphics(app->renderDevice); From 0f0be7f0b9bedf04a4ccebce32b8e49e321a5eea Mon Sep 17 00:00:00 2001 From: andreja6 Date: Wed, 24 Oct 2018 16:44:33 -0700 Subject: [PATCH 04/33] Attempted to fix dinging On phone, can't test --- main.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index 888106d..e07b3ee 100644 --- a/main.cpp +++ b/main.cpp @@ -1262,7 +1262,10 @@ void Demo::onKeyUp(int key) void Demo::onMouseLeftPressed(HWND hwnd,int x,int y) { - SetFocus(hwnd); + //Removed set focus + + + std::cout << "Click: " << x << "," << y << std::endl; From 4df67897dccf52b922d8ce33501f5812afb1e58f Mon Sep 17 00:00:00 2001 From: andreja6 Date: Wed, 24 Oct 2018 19:45:51 -0700 Subject: [PATCH 05/33] Datamodel V1.1 --- CameraController.cpp | 4 +- DataModelInstance.cpp | 1 + G3DTest.vcproj | 20 +++++- GroupInstance.cpp | 25 ++++++++ GroupInstance.h | 13 ++++ Instance.cpp | 2 + Instance.h | 3 +- PVInstance.cpp | 25 ++++++++ PVInstance.h | 13 ++++ PhysicalInstance.cpp => PartInstance.cpp | 39 ++++++------ PhysicalInstance.h => PartInstance.h | 13 ++-- TextButtonInstance.cpp | 11 +++- TextButtonInstance.h | 4 ++ WorkspaceInstance.cpp | 3 +- WorkspaceInstance.h | 5 +- main.cpp | 79 +++++++++++++++++------- 16 files changed, 203 insertions(+), 57 deletions(-) create mode 100644 GroupInstance.cpp create mode 100644 GroupInstance.h create mode 100644 PVInstance.cpp create mode 100644 PVInstance.h rename PhysicalInstance.cpp => PartInstance.cpp (88%) rename PhysicalInstance.h => PartInstance.h (78%) diff --git a/CameraController.cpp b/CameraController.cpp index 567f089..909ed9a 100644 --- a/CameraController.cpp +++ b/CameraController.cpp @@ -1,7 +1,7 @@ #include "CameraController.h" #include "win32Defines.h" #include -#include "PhysicalInstance.h" +#include "PartInstance.h" #include "Demo.h" #include "AudioPlayer.h" @@ -141,7 +141,7 @@ void CameraController::centerCamera(Instance* selection) } else { - Vector3 partPos = ((PhysicalInstance*)selection)->getPosition()/2; + Vector3 partPos = ((PartInstance*)selection)->getPosition()/2; lookAt(partPos); focusPosition=partPos; zoom=((partPos-frame.translation).magnitude()); diff --git a/DataModelInstance.cpp b/DataModelInstance.cpp index 4cba7db..8d8ba72 100644 --- a/DataModelInstance.cpp +++ b/DataModelInstance.cpp @@ -15,6 +15,7 @@ DataModelInstance::DataModelInstance(void) mousey = 0; mouseButton1Down = false; showMessage = false; + canDelete = false; } DataModelInstance::~DataModelInstance(void) diff --git a/G3DTest.vcproj b/G3DTest.vcproj index f234481..79a5e2c 100644 --- a/G3DTest.vcproj +++ b/G3DTest.vcproj @@ -313,6 +313,10 @@ RelativePath=".\DataModelInstance.cpp" > + + @@ -322,7 +326,11 @@ > + + + + @@ -419,7 +431,11 @@ > + + GroupInstance::getProperties() +{ + std::vector properties = PVInstance::getProperties(); + return properties; +} +void GroupInstance::PropUpdate(LPPROPGRIDITEM &pItem) +{ + PVInstance::PropUpdate(pItem); +} diff --git a/GroupInstance.h b/GroupInstance.h new file mode 100644 index 0000000..98d63e3 --- /dev/null +++ b/GroupInstance.h @@ -0,0 +1,13 @@ +#pragma once +#include "PVInstance.h" + +class GroupInstance : + public PVInstance +{ +public: + GroupInstance(void); + ~GroupInstance(void); + GroupInstance(const GroupInstance &oinst); + virtual std::vector getProperties(); + virtual void PropUpdate(LPPROPGRIDITEM &pItem); +}; diff --git a/Instance.cpp b/Instance.cpp index 7cc363d..1a9dbb0 100644 --- a/Instance.cpp +++ b/Instance.cpp @@ -9,6 +9,7 @@ Instance::Instance(void) name = "Default Game Instance"; className = "BaseInstance"; listicon = 0; + canDelete = true; } Instance::Instance(const Instance &oinst) @@ -16,6 +17,7 @@ Instance::Instance(const Instance &oinst) name = oinst.name; className = oinst.className; + canDelete = oinst.canDelete; //setParent(oinst.parent); } diff --git a/Instance.h b/Instance.h index 07231a1..2af6866 100644 --- a/Instance.h +++ b/Instance.h @@ -5,6 +5,7 @@ class Instance { public: + bool canDelete; Instance(void); Instance(const Instance&); virtual ~Instance(void); @@ -12,7 +13,7 @@ public: virtual void render(RenderDevice*); std::vector children; // All children. std::string getClassName(); - virtual Instance* findFirstChild(std::string); + Instance* findFirstChild(std::string); std::vector getChildren(); std::vector getAllChildren(); void setParent(Instance*); diff --git a/PVInstance.cpp b/PVInstance.cpp new file mode 100644 index 0000000..8f0332d --- /dev/null +++ b/PVInstance.cpp @@ -0,0 +1,25 @@ +#include "PVInstance.h" + +PVInstance::PVInstance(void) +{ + Instance::Instance(); +} + +PVInstance::PVInstance(const PVInstance &oinst) +{ + Instance::Instance(oinst); +} + +PVInstance::~PVInstance(void) +{ +} + +std::vector PVInstance::getProperties() +{ + std::vector properties = Instance::getProperties(); + return properties; +} +void PVInstance::PropUpdate(LPPROPGRIDITEM &pItem) +{ + Instance::PropUpdate(pItem); +} diff --git a/PVInstance.h b/PVInstance.h new file mode 100644 index 0000000..99f2233 --- /dev/null +++ b/PVInstance.h @@ -0,0 +1,13 @@ +#pragma once +#include "instance.h" + +class PVInstance : + public Instance +{ +public: + PVInstance(void); + ~PVInstance(void); + PVInstance(const PVInstance &oinst); + virtual std::vector getProperties(); + virtual void PropUpdate(LPPROPGRIDITEM &pItem); +}; diff --git a/PhysicalInstance.cpp b/PartInstance.cpp similarity index 88% rename from PhysicalInstance.cpp rename to PartInstance.cpp index c8734f3..7c1f2e1 100644 --- a/PhysicalInstance.cpp +++ b/PartInstance.cpp @@ -1,11 +1,11 @@ -#include "PhysicalInstance.h" +#include "PartInstance.h" #include "Globals.h" -PhysicalInstance::PhysicalInstance(void) +PartInstance::PartInstance(void) { - Instance::Instance(); - name = "Default PhysicalInstance"; + PVInstance::PVInstance(); + name = "Default PartInstance"; className = "Part"; canCollide = true; anchored = true; @@ -22,11 +22,12 @@ PhysicalInstance::PhysicalInstance(void) bottom = Enum::SurfaceType::Smooth; } -PhysicalInstance::PhysicalInstance(const PhysicalInstance &oinst) +PartInstance::PartInstance(const PartInstance &oinst) { - Instance::Instance(oinst); + PVInstance::PVInstance(oinst); //name = oinst.name; //className = "Part"; + name = oinst.name; canCollide = oinst.canCollide; setParent(oinst.parent); anchored = oinst.anchored; @@ -43,7 +44,7 @@ PhysicalInstance::PhysicalInstance(const PhysicalInstance &oinst) bottom = oinst.bottom; } -void PhysicalInstance::setSize(Vector3 newSize) +void PartInstance::setSize(Vector3 newSize) { int minsize = 1; int maxsize = 512; @@ -71,37 +72,37 @@ void PhysicalInstance::setSize(Vector3 newSize) } -Vector3 PhysicalInstance::getSize() +Vector3 PartInstance::getSize() { return size; } -Vector3 PhysicalInstance::getPosition() +Vector3 PartInstance::getPosition() { return position; } -void PhysicalInstance::setPosition(Vector3 pos) +void PartInstance::setPosition(Vector3 pos) { position = pos; cFrame = CoordinateFrame(pos); changed = true; } -CoordinateFrame PhysicalInstance::getCFrame() +CoordinateFrame PartInstance::getCFrame() { return cFrame; } -void PhysicalInstance::setCFrame(CoordinateFrame coordinateFrame) +void PartInstance::setCFrame(CoordinateFrame coordinateFrame) { cFrame = coordinateFrame; position = coordinateFrame.translation; changed = true; } -CoordinateFrame PhysicalInstance::getCFrameRenderBased() +CoordinateFrame PartInstance::getCFrameRenderBased() { return CoordinateFrame(getCFrame().rotation,Vector3(getCFrame().translation.x/2, getCFrame().translation.y/2, getCFrame().translation.z/2)); } -Box PhysicalInstance::getBox() +Box PartInstance::getBox() { if(changed) { @@ -132,12 +133,12 @@ Box PhysicalInstance::getBox() return itemBox; } -bool PhysicalInstance::collides(Box box) +bool PartInstance::collides(Box box) { return CollisionDetection::fixedSolidBoxIntersectsFixedSolidBox(getBox(), box); } -void PhysicalInstance::render(RenderDevice* rd) +void PartInstance::render(RenderDevice* rd) { if(changed) Box box = getBox(); @@ -211,14 +212,14 @@ void PhysicalInstance::render(RenderDevice* rd) } -PhysicalInstance::~PhysicalInstance(void) +PartInstance::~PartInstance(void) { } char pto[512]; char pto2[512]; #include -void PhysicalInstance::PropUpdate(LPPROPGRIDITEM &item) +void PartInstance::PropUpdate(LPPROPGRIDITEM &item) { if(strcmp(item->lpszPropName, "Color3") == 0) { @@ -285,7 +286,7 @@ void PhysicalInstance::PropUpdate(LPPROPGRIDITEM &item) else Instance::PropUpdate(item); } -std::vector PhysicalInstance::getProperties() +std::vector PartInstance::getProperties() { std::vector properties = Instance::getProperties(); diff --git a/PhysicalInstance.h b/PartInstance.h similarity index 78% rename from PhysicalInstance.h rename to PartInstance.h index 70d89b2..ccdbd45 100644 --- a/PhysicalInstance.h +++ b/PartInstance.h @@ -1,15 +1,14 @@ #pragma once -#include "instance.h" +#include "PVInstance.h" #include "Enum.h" -class PhysicalInstance : - public Instance +class PartInstance : public PVInstance { public: - PhysicalInstance(void); - PhysicalInstance(const PhysicalInstance &oinst); - Instance* clone() const { return new PhysicalInstance(*this); } - ~PhysicalInstance(void); + PartInstance(void); + PartInstance(const PartInstance &oinst); + Instance* clone() const { return new PartInstance(*this); } + ~PartInstance(void); virtual void render(RenderDevice*); Vector3 velocity; Enum::SurfaceType::Value top; diff --git a/TextButtonInstance.cpp b/TextButtonInstance.cpp index 6c8cfd1..5a9b472 100644 --- a/TextButtonInstance.cpp +++ b/TextButtonInstance.cpp @@ -58,6 +58,10 @@ void TextButtonInstance::setAllColorsSame() textOutlineColorDn = textOutlineColor; boxColorDn = boxColor; boxOutlineColorDn = boxOutlineColor; + textColorDis = textColor; + textOutlineColorDis = textOutlineColor; + boxColorDis = boxColor; + boxOutlineColorDis = boxOutlineColor; } TextButtonInstance::~TextButtonInstance(void) @@ -80,7 +84,12 @@ void TextButtonInstance::drawObj(RenderDevice* rd, Vector2 mousePos, bool mouseD point2 = Vector3(boxEnd.x, boxEnd.y,0); } Vector2 RelativeTo = Vector2(point1.x + fontLocationRelativeTo.x, point1.y + fontLocationRelativeTo.y); - if(mouseInArea(point1.x, point1.y, point2.x, point2.y, mousePos.x, mousePos.y) && mouseDown) + if(disabled) + { + Draw::box(Box(point1, point2), rd, boxColorDis, boxOutlineColorDis); + font->draw2D(rd, title, RelativeTo, textSize, textColorDis, textOutlineColorDis); + } + else if(mouseInArea(point1.x, point1.y, point2.x, point2.y, mousePos.x, mousePos.y) && mouseDown) { Draw::box(Box(point1, point2), rd, boxColorDn, boxOutlineColorDn); font->draw2D(rd, title, RelativeTo, textSize, textColorDn, textOutlineColorDn); diff --git a/TextButtonInstance.h b/TextButtonInstance.h index 2f8823c..cc53f7f 100644 --- a/TextButtonInstance.h +++ b/TextButtonInstance.h @@ -21,6 +21,10 @@ public: Color4 textOutlineColorDn; Color4 boxColorDn; Color4 boxOutlineColorDn; + Color4 textColorDis; + Color4 textOutlineColorDis; + Color4 boxColorDis; + Color4 boxOutlineColorDis; bool centeredWithinBox; std::string title; G3D::GFontRef font; diff --git a/WorkspaceInstance.cpp b/WorkspaceInstance.cpp index 2f4d463..8c62729 100644 --- a/WorkspaceInstance.cpp +++ b/WorkspaceInstance.cpp @@ -3,11 +3,12 @@ WorkspaceInstance::WorkspaceInstance(void) { - Instance::Instance(); + GroupInstance::GroupInstance(); name = "Instance"; className = "Level"; timer = 60.0F; score = 0; + canDelete = false; } WorkspaceInstance::~WorkspaceInstance(void) diff --git a/WorkspaceInstance.h b/WorkspaceInstance.h index 26a5bc4..1dc0517 100644 --- a/WorkspaceInstance.h +++ b/WorkspaceInstance.h @@ -1,13 +1,12 @@ #pragma once -#include "instance.h" +#include "GroupInstance.h" class WorkspaceInstance : - public Instance + public GroupInstance { public: float timer; int score; WorkspaceInstance(void); ~WorkspaceInstance(void); - }; diff --git a/main.cpp b/main.cpp index e07b3ee..c808215 100644 --- a/main.cpp +++ b/main.cpp @@ -20,7 +20,7 @@ #include #include "Instance.h" #include "resource.h" -#include "PhysicalInstance.h" +#include "PartInstance.h" #include "TextButtonInstance.h" #include "ImageButtonInstance.h" #include "DataModelInstance.h" @@ -192,9 +192,9 @@ std::string Convert (float number){ } -PhysicalInstance* makePart() +PartInstance* makePart() { - PhysicalInstance* part = new PhysicalInstance(); + PartInstance* part = new PartInstance(); return part; } @@ -246,7 +246,14 @@ public: void GUDButtonListener::onButton1MouseClick(BaseButtonInstance* button) { - if(g_selectedInstances.size() > 0) + bool cont = false; + for(size_t i = 0; i < g_selectedInstances.size(); i++) + if(g_selectedInstances.at(i)->canDelete) + { + cont = true; + break; + } + if(cont) { AudioPlayer::playSound(dingSound); if(button->name == "Duplicate") @@ -254,7 +261,7 @@ void GUDButtonListener::onButton1MouseClick(BaseButtonInstance* button) std::vector newinst; for(size_t i = 0; i < g_selectedInstances.size(); i++) { - if(g_selectedInstances.at(i) != dataModel->getWorkspace()) + if(g_selectedInstances.at(i)->canDelete) { Instance* tempinst = g_selectedInstances.at(i); @@ -283,7 +290,7 @@ void RotateButtonListener::onButton1MouseClick(BaseButtonInstance* button) { Instance* selectedInstance = g_selectedInstances.at(0); AudioPlayer::playSound(clickSound); - if(PhysicalInstance* part = dynamic_cast(selectedInstance)) + if(PartInstance* part = dynamic_cast(selectedInstance)) { if(button->name == "Tilt") part->setCFrame(part->getCFrame()*Matrix3::fromEulerAnglesXYZ(0,0,toRadians(90))); @@ -302,7 +309,7 @@ void deleteInstance() size_t undeletable = 0; while(g_selectedInstances.size() > undeletable) { - if(g_selectedInstances.at(0) != dataModel && g_selectedInstances.at(0) != dataModel->getWorkspace()) + if(g_selectedInstances.at(0)->canDelete) { AudioPlayer::playSound(GetFileInPath("/content/sounds/pageturn.wav")); Instance* selectedInstance = g_selectedInstances.at(0); @@ -503,7 +510,9 @@ void Demo::initGUI() button->boxColor = Color4::clear(); button->textSize = 12; button->title = "Group"; - button->setAllColorsSame(); + button->name = "Group"; + button->setAllColorsSame(); + button->textColorDis = Color3(0.8F,0.8F,0.8F); button->font = fntlighttrek; button->fontLocationRelativeTo = Vector2(10, 0); button->setParent(dataModel->getGuiRoot()); @@ -517,7 +526,9 @@ void Demo::initGUI() button->boxColor = Color4::clear(); button->textSize = 12; button->title = "UnGroup"; + button->name = "UnGroup"; button->setAllColorsSame(); + button->textColorDis = Color3(0.8F,0.8F,0.8F); button->font = fntlighttrek; button->fontLocationRelativeTo = Vector2(10, 0); button->setParent(dataModel->getGuiRoot()); @@ -531,6 +542,7 @@ void Demo::initGUI() button->textSize = 12; button->title = "Duplicate"; button->setAllColorsSame(); + button->textColorDis = Color3(0.8F,0.8F,0.8F); button->font = fntlighttrek; button->fontLocationRelativeTo = Vector2(10, 0); button->setParent(dataModel->getGuiRoot()); @@ -710,7 +722,7 @@ void Demo::onInit() { initGUI(); - PhysicalInstance* test = makePart(); + PartInstance* test = makePart(); test->setParent(dataModel->getWorkspace()); test->color = Color3(0.2F,0.3F,1); test->setSize(Vector3(24,1,24)); @@ -838,14 +850,39 @@ std::vector Demo::getSelection() } void Demo::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) { - Instance* obj = dataModel->getGuiRoot()->findFirstChild("Delete"); - if(obj != NULL) + + + Instance * obj6 = dataModel->getGuiRoot()->findFirstChild("Delete"); + Instance * obj = dataModel->getGuiRoot()->findFirstChild("Duplicate"); + Instance * obj2 = dataModel->getGuiRoot()->findFirstChild("Group"); + Instance * obj3 = dataModel->getGuiRoot()->findFirstChild("UnGroup"); + Instance * obj4 = dataModel->getGuiRoot()->findFirstChild("Rotate"); + Instance * obj5 = dataModel->getGuiRoot()->findFirstChild("Tilt"); + if(obj != NULL && obj2 != NULL && obj3 != NULL && obj4 !=NULL && obj5 != NULL && obj6 != NULL) { - ImageButtonInstance* button = (ImageButtonInstance*)obj; - if(g_selectedInstances.size() <= 0 || g_selectedInstances.at(0) == dataModel->getWorkspace()) - button->disabled = true; - else - button->disabled = false; + BaseButtonInstance* button = (BaseButtonInstance*)obj; + BaseButtonInstance* button2 = (BaseButtonInstance*)obj2; + BaseButtonInstance* button3 = (BaseButtonInstance*)obj3; + BaseButtonInstance* button4 = (BaseButtonInstance*)obj4; + BaseButtonInstance* button5 = (BaseButtonInstance*)obj5; + BaseButtonInstance* button6 = (BaseButtonInstance*)obj6; + button->disabled = true; + button2->disabled = true; + button3->disabled = true; + button4->disabled = true; + button5->disabled = true; + button6->disabled = true; + for(size_t i = 0; i < g_selectedInstances.size(); i++) + if(g_selectedInstances.at(i)->canDelete) + { + button->disabled = false; + button2->disabled = false; + button3->disabled = false; + button4->disabled = false; + button5->disabled = false; + button6->disabled = false; + break; + } } @@ -913,14 +950,14 @@ void Demo::onUserInput(UserInput* ui) { if (GetHoldKeyState(VK_LBUTTON)) { if (dragging) { - PhysicalInstance* part = NULL; + PartInstance* part = NULL; if(g_selectedInstances.size() > 0) - part = (PhysicalInstance*) g_selectedInstances.at(0); + part = (PartInstance*) g_selectedInstances.at(0); Ray dragRay = cameraController.getCamera()->worldRay(dataModel->mousex, dataModel->mousey, renderDevice->getViewport()); std::vector instances = dataModel->getWorkspace()->getAllChildren(); for(size_t i = 0; i < instances.size(); i++) { - if(PhysicalInstance* moveTo = dynamic_cast(instances.at(i))) + if(PartInstance* moveTo = dynamic_cast(instances.at(i))) { float __time = testRay.intersectionTime(moveTo->getBox()); float __nearest=std::numeric_limits::infinity(); @@ -1162,7 +1199,7 @@ void Demo::onGraphics(RenderDevice* rd) { { for(size_t i = 0; i < g_selectedInstances.size(); i++) { - if(PhysicalInstance* part = dynamic_cast(g_selectedInstances.at(i))) + if(PartInstance* part = dynamic_cast(g_selectedInstances.at(i))) { Vector3 size = part->getSize(); Vector3 pos = part->getPosition(); @@ -1291,7 +1328,7 @@ void Demo::onMouseLeftPressed(HWND hwnd,int x,int y) bool objFound = false; for(size_t i = 0; i < instances.size(); i++) { - if(PhysicalInstance* test = dynamic_cast(instances.at(i))) + if(PartInstance* test = dynamic_cast(instances.at(i))) { float time = testRay.intersectionTime(test->getBox()); From d2e0b29051809639af36a3acee57e546fc153e98 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Wed, 24 Oct 2018 20:34:14 -0700 Subject: [PATCH 06/33] Changed icon --- DataModelInstance.cpp | 60 +++++++++++++++++++++++++++++++++ DataModelInstance.h | 7 ++++ WorkspaceInstance.cpp | 6 ++-- WorkspaceInstance.h | 2 -- content/images/ArrowCursor.png | Bin 0 -> 2065 bytes main.cpp | 44 +++++++++++++++++------- 6 files changed, 101 insertions(+), 18 deletions(-) create mode 100644 content/images/ArrowCursor.png diff --git a/DataModelInstance.cpp b/DataModelInstance.cpp index 8d8ba72..087dd23 100644 --- a/DataModelInstance.cpp +++ b/DataModelInstance.cpp @@ -16,6 +16,10 @@ DataModelInstance::DataModelInstance(void) mouseButton1Down = false; showMessage = false; canDelete = false; + winMessage = "You Won!"; + loseMessage = "You Lost. Try Again"; + timer = 60.0F; + score = 0; } DataModelInstance::~DataModelInstance(void) @@ -69,3 +73,59 @@ Instance* DataModelInstance::getGuiRoot() { return guiRoot; } + +char timerTxt[12]; +char scoreTxt[12]; +std::vector DataModelInstance::getProperties() +{ + std::vector properties = Instance::getProperties(); + + + + properties.push_back(createPGI("Messages", + "WinMessage", + "The message that shows when the player wins.", + (LPARAM)winMessage.c_str(), + PIT_EDIT)); + properties.push_back(createPGI("Messages", + "LoseMessage", + "The message that shows when the player loses.", + (LPARAM)loseMessage.c_str(), + PIT_EDIT)); + + + sprintf(timerTxt, "%g", timer); + sprintf(scoreTxt, "%d", score); + properties.push_back(createPGI("Gameplay", + "InitialTimerValue", + "The ammount of time in seconds the player has to complete this level.\r\n\r\nPut 0 if time is limitless.", + (LPARAM)timerTxt, + PIT_EDIT)); + properties.push_back(createPGI("Gameplay", + "InitialScoreValue", + "The ammount of points the player starts with.", + (LPARAM)scoreTxt, + PIT_EDIT)); + return properties; +} +void DataModelInstance::PropUpdate(LPPROPGRIDITEM &pItem) +{ + if(strcmp(pItem->lpszPropName, "InitialTimerValue") == 0) + { + timer = atoi((LPSTR)pItem->lpCurValue); + } + if(strcmp(pItem->lpszPropName, "InitialScoreValue") == 0) + { + score = atof((LPSTR)pItem->lpCurValue); + } + if(strcmp(pItem->lpszPropName, "LoseMessage") == 0) + { + loseMessage = (LPSTR)pItem->lpCurValue; + } + if(strcmp(pItem->lpszPropName, "WinMessage") == 0) + { + winMessage = (LPSTR)pItem->lpCurValue; + } + else + Instance::PropUpdate(pItem); +} \ No newline at end of file diff --git a/DataModelInstance.h b/DataModelInstance.h index ac614d4..879f732 100644 --- a/DataModelInstance.h +++ b/DataModelInstance.h @@ -24,4 +24,11 @@ public: void setMousePos(int x,int y); void setMousePos(Vector2 pos); bool mouseButton1Down; + + float timer; + int score; + virtual std::vector getProperties(); + std::string winMessage; + std::string loseMessage; + virtual void PropUpdate(LPPROPGRIDITEM &pItem); }; diff --git a/WorkspaceInstance.cpp b/WorkspaceInstance.cpp index 8c62729..47fceec 100644 --- a/WorkspaceInstance.cpp +++ b/WorkspaceInstance.cpp @@ -4,10 +4,8 @@ WorkspaceInstance::WorkspaceInstance(void) { GroupInstance::GroupInstance(); - name = "Instance"; - className = "Level"; - timer = 60.0F; - score = 0; + name = "Workspace"; + className = "Workspace"; canDelete = false; } diff --git a/WorkspaceInstance.h b/WorkspaceInstance.h index 1dc0517..9ca7899 100644 --- a/WorkspaceInstance.h +++ b/WorkspaceInstance.h @@ -5,8 +5,6 @@ class WorkspaceInstance : public GroupInstance { public: - float timer; - int score; WorkspaceInstance(void); ~WorkspaceInstance(void); }; diff --git a/content/images/ArrowCursor.png b/content/images/ArrowCursor.png new file mode 100644 index 0000000000000000000000000000000000000000..85c463983a935de602927cec0f490c630091476c GIT binary patch literal 2065 zcmb7F_g4~%A4LU8d61Q>Ov91p1_48`oG2<7jt1ty)Wi~#a8(*A4M);LUy8F{D&^ii z%_Pm$%l90)%G{cxoN2l1%li|)_niB==iGDdFQ0Qi=MztHw1r9^kp=(&P&=Zvvq&lb zai64Uau0kf5s6+1;X;VjbwBTrfNMc;*8qkez?B{fH!^~|_yxm_5C{w$X@o-~aHx}T zeFPSPD1S?w5#_)kc4Pv0Knxo|3z!At;(h}Uv^%pPT>_#7{d&P?1Cbd-S?fAuk|;>igO9u zl3FjLrO(B7MRzpLO1Mj(hP83_o*2GAiQ}#2D5`oGZJ+qyMN`^5RSVSE8Cn=pwcEw1Pb%D=wl$wr@y9O)1()K2<(q)2io8o*AH#eQ{ z-@jM-b;wI=$H&J{u5Fn%H#d*+csy5k7wK~x4DH5vgT$pTpVjTw=rV`{kq7lGTI@nY zYl_`!>{AWB3~Fj>oX?&;URPIV#27+1{kjGBot&Ga%ilI=x-}4M$hk|);IFGlb(>Lv zz9YJl9bhoH;q&Luj_b!YG_YBitEnqB@7~!LJb(Usa`M4+q>tp7LipZxXxZ4Z|E#Bh zX2N5M$AGF9G(2o;g2-;Nh2Ct$t?0BC7Zvq(q#1tAj;6qPokO2K6=|Kx>5JO=F@F!L zgg$j@uTwHaA`r|5i~(lt`I%?1O+;^xog_8*(E9p(FZaR*r=kM6xUkUYQ6FZqoNdAq zXliMVeeA#0RMsdLGp67|^DQ^o1#-!cPkUr$WE}Oj6f1ijwwPgzM$dieFOr)-rU!4B z?i#<0IQ2(nVq!IJL+rMl4H1k5?x>ZNlq?8U*)mt2X5m8ZaX1_>_NAd0zzj4dsnim8 zm_-9efnSM#87R3ZcWLgL|uo13eXt;|+Vb`M0sV2-Pdm(?65Q{DKi@g3Ubyw?}7PLjr)Tq>11G(2ot8V%mB z()URB{FlB07mwA5-5r|;**8uc%Ar4xF}T^%r+aMoNfwql$yVs5?}tLAp1K5$zS3qg znXz15qR&RM>dO9=2c{ao6reUZMNJqOiD_s^zTx!eT%s| zK%`RB*VeYyX15HlD&uk4VMYA7EHsVBCX>`xQJ9_W?Vp(L^JSj>+4yiBN6o;43B7SC zGu4L0X~i5;)K(en{R>&^ZHK!`3w(6nPY^_Y?oX@xvIT`;*wJoLeXm4DzWVxg&S_V6 zZLTLbVXb0HEPQ#iWNo(VeA!@8%+=eVqLz>euw`{V;;OMyqbUp)0TXDoXj{=r=NIX) zj|GSG=gSRO84N}xy+=)3N9TIy-&OuysSarde~T7m8aHfG8&tuc8hL!Fm`vh?%{T-D zp_Z!mQc_7&Bsu1p9JkU_{Gz$pLq?`C!+GCg$YnJA)b;7OQjhup@~jh5b58=H{@x35 zG{S*o3p<_gJ;p1V69F*9+qL#$~QQxm>kwIC#2%*q8}C<0RY4%Rq+oRF$V zRXZVZ{l^0Jj0my(3Ed4{4>48D05Fe|HMY0!HZ14St>x33ICW&wp)X5IOBxvqt%(Zw zfA82RJ(JZoFpyumD3h;(P6MKIBaxiJAY{8RuI$V)V>*5*JgB{sEYV3<_FXF|EPT(J z?HmbP$n7_Y+$=BkdhN-Z3}X06ji;M@_B^JNbbxrLviFJNU~6Bs8XfbjstN^b`_vpI zoe}pW5#Pg4Ntr5!(AYq67PZx^ua^dka3*cl>gVU4ZKPOKq;rS6_3y-`D=RBAv!p5| zD+?&rMkrM80bZ=7bxr|Qp$_MF|Fwpuj;&T^G%)vtE_}x5aaY>V=%_(C))6}0-9&J6 z%TS*ju491)BPjTJvybjG@mp3QphWCP1auhm6MDtMBF5O*SO>T_hJ64j^l9e?5D0`7 z%LH=Kxl6&}2c_L1=r=C^B*^Jj=jXQ`ZX9KtxV5{<6kR;j(}r2p&hUKaYd=9lB+ng4 zPu^;1Xz)bKX+1L0^wIyVt+6p01)HkNtRhB-^3*F*iEJJ*_Q$=4>|ixiTLC6qzxw3T zyFYqn-IUM@1Rw7sti!*u`Glx%oL}1?0I1*V4dR>S q<`0=zq$Rw3C}ir(uw3|3_t^kLt~x+Zmf0!#!2mmgqjjkzE%tx=TfQLx literal 0 HcmV?d00001 diff --git a/main.cpp b/main.cpp index c808215..18389da 100644 --- a/main.cpp +++ b/main.cpp @@ -68,7 +68,10 @@ static std::string cameraSound = ""; static std::string clickSound = ""; static std::string dingSound = ""; static int cursorid = 0; +static int cursorOvrid = 0; +static int currentcursorid = 0; static G3D::TextureRef cursor = NULL; +static G3D::TextureRef cursorOvr = NULL; static bool running = true; static bool mouseMovedBeginMotion = false; static const int CURSOR = 0; @@ -1234,9 +1237,9 @@ void Demo::onGraphics(RenderDevice* rd) { //TODO--Move these to their own instance std::stringstream stream; - stream << std::fixed << std::setprecision(1) << dataModel->getWorkspace()->timer; + stream << std::fixed << std::setprecision(1) << dataModel->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()); + fntdominant->draw2D(rd, "Score: " + Convert(dataModel->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)); @@ -1262,19 +1265,34 @@ void Demo::onGraphics(RenderDevice* rd) { glEnable(GL_BLEND);// you enable blending function glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + std::vector instances = dataModel->getWorkspace()->getAllChildren(); + for(size_t i = 0; i < instances.size(); i++) + { + if(PartInstance* test = dynamic_cast(instances.at(i))) + { + float time = cameraController.getCamera()->worldRay(dataModel->mousex, dataModel->mousey, renderDevice->getViewport()).intersectionTime(test->getBox()); + //float time = testRay.intersectionTime(test->getBox()); + if (time != inf()) + { + currentcursorid = cursorOvrid; + break; + } + else currentcursorid = cursorid; + } + } - glBindTexture( GL_TEXTURE_2D, cursorid); + glBindTexture( GL_TEXTURE_2D, currentcursorid); glBegin( GL_QUADS ); glTexCoord2d(0.0,0.0); - glVertex2f(mousepos.x-40, mousepos.y-40); + glVertex2f(mousepos.x-64, mousepos.y-64); glTexCoord2d( 1.0,0.0 ); - glVertex2f(mousepos.x+40, mousepos.y-40); + glVertex2f(mousepos.x+64, mousepos.y-64); glTexCoord2d(1.0,1.0 ); - glVertex2f(mousepos.x+40, mousepos.y+40 ); + glVertex2f(mousepos.x+64, mousepos.y+64 ); glTexCoord2d( 0.0,1.0 ); - glVertex2f( mousepos.x-40, mousepos.y+40 ); + glVertex2f( mousepos.x-64, mousepos.y+64 ); glEnd(); glDisable( GL_TEXTURE_2D ); @@ -1367,8 +1385,8 @@ void Demo::onMouseLeftPressed(HWND hwnd,int x,int y) { while(g_selectedInstances.size() > 0) g_selectedInstances.erase(g_selectedInstances.begin()); - g_selectedInstances.push_back(dataModel->getWorkspace()); - _propWindow->SetProperties(dataModel->getWorkspace()); + g_selectedInstances.push_back(dataModel); + _propWindow->SetProperties(dataModel); } } @@ -1381,7 +1399,7 @@ void Demo::onMouseLeftUp(int x,int y) //message = "Dragging = false."; //messageTime = System::time(); std::vector instances_2D = dataModel->getGuiRoot()->getAllChildren(); - std::vector instances = dataModel->getWorkspace()->getAllChildren(); + //std::vector instances = dataModel->getWorkspace()->getAllChildren(); for(size_t i = 0; i < instances_2D.size(); i++) { if(BaseButtonInstance* button = dynamic_cast(instances_2D[i])) @@ -1582,7 +1600,8 @@ void Demo::run() { UpdateWindow(_hWndMain); // Load objects here= - cursor = Texture::fromFile(GetFileInPath("/content/cursor2.png")); + 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(); fntdominant = GFont::fromFile(GetFileInPath("/content/font/dominant.fnt")); @@ -1592,7 +1611,8 @@ void Demo::run() { 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; From c50d2a81666f1e279d262608dc1a7d07df5d553a Mon Sep 17 00:00:00 2001 From: andreja6 Date: Wed, 24 Oct 2018 20:49:26 -0700 Subject: [PATCH 07/33] Added basic shape stuff --- Enum.h | 6 ++++++ PartInstance.cpp | 12 ++++++++++++ PartInstance.h | 1 + main.cpp | 3 ++- 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Enum.h b/Enum.h index 4e70d15..5de2af4 100644 --- a/Enum.h +++ b/Enum.h @@ -6,4 +6,10 @@ namespace Enum Smooth, Bumps, Welds, Glue }; } + namespace Shape + { + enum Value { + Block, Sphere, Cylinder + }; + } } \ No newline at end of file diff --git a/PartInstance.cpp b/PartInstance.cpp index 7c1f2e1..8a1c627 100644 --- a/PartInstance.cpp +++ b/PartInstance.cpp @@ -20,6 +20,7 @@ PartInstance::PartInstance(void) back = Enum::SurfaceType::Smooth; left = Enum::SurfaceType::Smooth; bottom = Enum::SurfaceType::Smooth; + shape = Enum::Shape::Block; } PartInstance::PartInstance(const PartInstance &oinst) @@ -42,6 +43,7 @@ PartInstance::PartInstance(const PartInstance &oinst) back = oinst.back; left = oinst.left; bottom = oinst.bottom; + shape = oinst.shape; } void PartInstance::setSize(Vector3 newSize) @@ -67,6 +69,16 @@ void PartInstance::setSize(Vector3 newSize) if(sizez > 512) sizez = 512; + if(shape != Enum::Shape::Block) + { + int max = sizex; + if(sizey > max) + max = sizey; + if(sizez > max) + max = sizez; + sizex = sizey = sizez = max; + } + size = Vector3(sizex, sizey, sizez); diff --git a/PartInstance.h b/PartInstance.h index ccdbd45..84c4fe2 100644 --- a/PartInstance.h +++ b/PartInstance.h @@ -17,6 +17,7 @@ public: Enum::SurfaceType::Value back; Enum::SurfaceType::Value left; Enum::SurfaceType::Value bottom; + Enum::Shape::Value shape; CoordinateFrame cFrame; Color3 color; Vector3 getPosition(); diff --git a/main.cpp b/main.cpp index 18389da..90b1ef6 100644 --- a/main.cpp +++ b/main.cpp @@ -1266,6 +1266,7 @@ void Demo::onGraphics(RenderDevice* rd) { glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); std::vector instances = dataModel->getWorkspace()->getAllChildren(); + currentcursorid = cursorid; for(size_t i = 0; i < instances.size(); i++) { if(PartInstance* test = dynamic_cast(instances.at(i))) @@ -1277,7 +1278,7 @@ void Demo::onGraphics(RenderDevice* rd) { currentcursorid = cursorOvrid; break; } - else currentcursorid = cursorid; + } } From 62208a14a56f63e997afd85a235da9009fa90eca Mon Sep 17 00:00:00 2001 From: andreja6 Date: Thu, 25 Oct 2018 09:45:13 -0700 Subject: [PATCH 08/33] Made LevelInstance (DataModel V1.1_01?) --- DataModelInstance.cpp | 63 ++++--------------------------------- DataModelInstance.h | 10 +++--- G3DTest.vcproj | 8 +++++ GroupInstance.cpp | 1 + LevelInstance.cpp | 72 +++++++++++++++++++++++++++++++++++++++++++ LevelInstance.h | 16 ++++++++++ PVInstance.cpp | 1 + main.cpp | 4 +-- 8 files changed, 110 insertions(+), 65 deletions(-) create mode 100644 LevelInstance.cpp create mode 100644 LevelInstance.h diff --git a/DataModelInstance.cpp b/DataModelInstance.cpp index 087dd23..380ea83 100644 --- a/DataModelInstance.cpp +++ b/DataModelInstance.cpp @@ -9,17 +9,16 @@ DataModelInstance::DataModelInstance(void) Instance::Instance(); workspace = new WorkspaceInstance(); guiRoot = new Instance(); + level = new LevelInstance(); children.push_back(workspace); + children.push_back(level); className = "dataModel"; mousex = 0; mousey = 0; mouseButton1Down = false; showMessage = false; canDelete = false; - winMessage = "You Won!"; - loseMessage = "You Lost. Try Again"; - timer = 60.0F; - score = 0; + } DataModelInstance::~DataModelInstance(void) @@ -74,58 +73,8 @@ Instance* DataModelInstance::getGuiRoot() return guiRoot; } -char timerTxt[12]; -char scoreTxt[12]; -std::vector DataModelInstance::getProperties() + +LevelInstance* DataModelInstance::getLevel() { - std::vector properties = Instance::getProperties(); - - - - properties.push_back(createPGI("Messages", - "WinMessage", - "The message that shows when the player wins.", - (LPARAM)winMessage.c_str(), - PIT_EDIT)); - properties.push_back(createPGI("Messages", - "LoseMessage", - "The message that shows when the player loses.", - (LPARAM)loseMessage.c_str(), - PIT_EDIT)); - - - sprintf(timerTxt, "%g", timer); - sprintf(scoreTxt, "%d", score); - properties.push_back(createPGI("Gameplay", - "InitialTimerValue", - "The ammount of time in seconds the player has to complete this level.\r\n\r\nPut 0 if time is limitless.", - (LPARAM)timerTxt, - PIT_EDIT)); - properties.push_back(createPGI("Gameplay", - "InitialScoreValue", - "The ammount of points the player starts with.", - (LPARAM)scoreTxt, - PIT_EDIT)); - return properties; -} -void DataModelInstance::PropUpdate(LPPROPGRIDITEM &pItem) -{ - if(strcmp(pItem->lpszPropName, "InitialTimerValue") == 0) - { - timer = atoi((LPSTR)pItem->lpCurValue); - } - if(strcmp(pItem->lpszPropName, "InitialScoreValue") == 0) - { - score = atof((LPSTR)pItem->lpCurValue); - } - if(strcmp(pItem->lpszPropName, "LoseMessage") == 0) - { - loseMessage = (LPSTR)pItem->lpCurValue; - } - if(strcmp(pItem->lpszPropName, "WinMessage") == 0) - { - winMessage = (LPSTR)pItem->lpCurValue; - } - else - Instance::PropUpdate(pItem); + return level; } \ No newline at end of file diff --git a/DataModelInstance.h b/DataModelInstance.h index 879f732..45844dc 100644 --- a/DataModelInstance.h +++ b/DataModelInstance.h @@ -1,6 +1,7 @@ #pragma once #include "instance.h" #include "WorkspaceInstance.h" +#include "LevelInstance.h" class DataModelInstance : public Instance @@ -13,6 +14,8 @@ public: void drawMessage(RenderDevice*); WorkspaceInstance* getWorkspace(); WorkspaceInstance* workspace; + LevelInstance * level; + LevelInstance * getLevel(); Instance* guiRoot; std::string message; bool showMessage; @@ -25,10 +28,5 @@ public: void setMousePos(Vector2 pos); bool mouseButton1Down; - float timer; - int score; - virtual std::vector getProperties(); - std::string winMessage; - std::string loseMessage; - virtual void PropUpdate(LPPROPGRIDITEM &pItem); + }; diff --git a/G3DTest.vcproj b/G3DTest.vcproj index 79a5e2c..5e82c5e 100644 --- a/G3DTest.vcproj +++ b/G3DTest.vcproj @@ -325,6 +325,10 @@ RelativePath=".\Instance.cpp" > + + @@ -430,6 +434,10 @@ RelativePath=".\Instance.h" > + + diff --git a/GroupInstance.cpp b/GroupInstance.cpp index 7560448..c8c593b 100644 --- a/GroupInstance.cpp +++ b/GroupInstance.cpp @@ -3,6 +3,7 @@ GroupInstance::GroupInstance(void) { PVInstance::PVInstance(); + className = "GroupInstance"; } GroupInstance::GroupInstance(const GroupInstance &oinst) diff --git a/LevelInstance.cpp b/LevelInstance.cpp new file mode 100644 index 0000000..4bab150 --- /dev/null +++ b/LevelInstance.cpp @@ -0,0 +1,72 @@ +#include "LevelInstance.h" + +LevelInstance::LevelInstance(void) +{ + Instance::Instance(); + name = "Level"; + winMessage = "You Won!"; + loseMessage = "You Lost. Try Again"; + timer = 60.0F; + score = 0; +} + +LevelInstance::~LevelInstance(void) +{ +} + + +char timerTxt[12]; +char scoreTxt[12]; +std::vector LevelInstance::getProperties() +{ + std::vector properties = Instance::getProperties(); + + + + properties.push_back(createPGI("Messages", + "WinMessage", + "The message that shows when the player wins.", + (LPARAM)winMessage.c_str(), + PIT_EDIT)); + properties.push_back(createPGI("Messages", + "LoseMessage", + "The message that shows when the player loses.", + (LPARAM)loseMessage.c_str(), + PIT_EDIT)); + + + sprintf(timerTxt, "%g", timer); + sprintf(scoreTxt, "%d", score); + properties.push_back(createPGI("Gameplay", + "InitialTimerValue", + "The ammount of time in seconds the player has to complete this level.\r\n\r\nPut 0 if time is limitless.", + (LPARAM)timerTxt, + PIT_EDIT)); + properties.push_back(createPGI("Gameplay", + "InitialScoreValue", + "The ammount of points the player starts with.", + (LPARAM)scoreTxt, + PIT_EDIT)); + return properties; +} +void LevelInstance::PropUpdate(LPPROPGRIDITEM &pItem) +{ + if(strcmp(pItem->lpszPropName, "InitialTimerValue") == 0) + { + timer = atoi((LPSTR)pItem->lpCurValue); + } + if(strcmp(pItem->lpszPropName, "InitialScoreValue") == 0) + { + score = atof((LPSTR)pItem->lpCurValue); + } + if(strcmp(pItem->lpszPropName, "LoseMessage") == 0) + { + loseMessage = (LPSTR)pItem->lpCurValue; + } + if(strcmp(pItem->lpszPropName, "WinMessage") == 0) + { + winMessage = (LPSTR)pItem->lpCurValue; + } + else + Instance::PropUpdate(pItem); +} \ No newline at end of file diff --git a/LevelInstance.h b/LevelInstance.h new file mode 100644 index 0000000..f29ca78 --- /dev/null +++ b/LevelInstance.h @@ -0,0 +1,16 @@ +#pragma once +#include "instance.h" + +class LevelInstance : + public Instance +{ +public: + LevelInstance(void); + ~LevelInstance(void); + float timer; + int score; + virtual std::vector getProperties(); + std::string winMessage; + std::string loseMessage; + virtual void PropUpdate(LPPROPGRIDITEM &pItem); +}; diff --git a/PVInstance.cpp b/PVInstance.cpp index 8f0332d..271ea50 100644 --- a/PVInstance.cpp +++ b/PVInstance.cpp @@ -3,6 +3,7 @@ PVInstance::PVInstance(void) { Instance::Instance(); + className = "PVInstance"; } PVInstance::PVInstance(const PVInstance &oinst) diff --git a/main.cpp b/main.cpp index 90b1ef6..7fa68c9 100644 --- a/main.cpp +++ b/main.cpp @@ -1237,9 +1237,9 @@ void Demo::onGraphics(RenderDevice* rd) { //TODO--Move these to their own instance std::stringstream stream; - stream << std::fixed << std::setprecision(1) << dataModel->timer; + stream << std::fixed << std::setprecision(1) << dataModel->getLevel()->timer; fntdominant->draw2D(rd, "Timer: " + stream.str(), Vector2(rd->getWidth() - 120, 25), 20, Color3::fromARGB(0x81C518), Color3::black()); - fntdominant->draw2D(rd, "Score: " + Convert(dataModel->score), Vector2(rd->getWidth() - 120, 50), 20, Color3::fromARGB(0x81C518), Color3::black()); + fntdominant->draw2D(rd, "Score: " + Convert(dataModel->getLevel()->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)); From 5020de484cb03b3dcb16f622d139d1e78930655e Mon Sep 17 00:00:00 2001 From: DirtPiper Date: Thu, 25 Oct 2018 12:48:59 -0400 Subject: [PATCH 09/33] name fix for accuracy hnnnnng dat accuracy boiii --- PartInstance.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PartInstance.cpp b/PartInstance.cpp index 8a1c627..098a2db 100644 --- a/PartInstance.cpp +++ b/PartInstance.cpp @@ -5,7 +5,7 @@ PartInstance::PartInstance(void) { PVInstance::PVInstance(); - name = "Default PartInstance"; + name = "Unnamed PVItem"; className = "Part"; canCollide = true; anchored = true; From 99d5a1de3864924ff73007c1dbd3865eeba05ebd Mon Sep 17 00:00:00 2001 From: andreja6 Date: Thu, 25 Oct 2018 10:06:52 -0700 Subject: [PATCH 10/33] Made parent selectable if exists --- DataModelInstance.cpp | 7 +++++-- PropertyWindow.cpp | 37 ++++++++++++++++++++++++++++++++----- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/DataModelInstance.cpp b/DataModelInstance.cpp index 380ea83..904c6d6 100644 --- a/DataModelInstance.cpp +++ b/DataModelInstance.cpp @@ -10,14 +10,17 @@ DataModelInstance::DataModelInstance(void) workspace = new WorkspaceInstance(); guiRoot = new Instance(); level = new LevelInstance(); - children.push_back(workspace); - children.push_back(level); + //children.push_back(workspace); + //children.push_back(level); className = "dataModel"; mousex = 0; mousey = 0; mouseButton1Down = false; showMessage = false; canDelete = false; + + workspace->setParent(this); + level->setParent(this); } diff --git a/PropertyWindow.cpp b/PropertyWindow.cpp index 18378d0..d6364fb 100644 --- a/PropertyWindow.cpp +++ b/PropertyWindow.cpp @@ -12,8 +12,8 @@ std::vector prop; std::vector children; -Instance* selectedInstance; - +Instance * selectedInstance; +Instance * parent = NULL; const int CX_BITMAP = 16; const int CY_BITMAP = 16; @@ -128,8 +128,26 @@ LRESULT CALLBACK PropProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) propWind->ClearProperties(); while(g_selectedInstances.size() != 0) g_selectedInstances.erase(g_selectedInstances.begin()); - g_selectedInstances.push_back(children.at(ItemIndex-1)); - propWind->SetProperties(children.at(ItemIndex-1)); + if(parent != NULL) + { + std::cout << ItemIndex << std::endl; + if(ItemIndex == 1) + { + g_selectedInstances.push_back(parent); + propWind->SetProperties(parent); + } + else + { + g_selectedInstances.push_back(children.at(ItemIndex+2)); + propWind->SetProperties(children.at(ItemIndex+2)); + } + + } + else + { + g_selectedInstances.push_back(children.at(ItemIndex-1)); + propWind->SetProperties(children.at(ItemIndex-1)); + } } } } @@ -162,15 +180,24 @@ LRESULT CALLBACK PropProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) void PropertyWindow::refreshExplorer() { SendMessage(_explorerComboBox,CB_RESETCONTENT,0,0); + parent = NULL; for (unsigned int i=0;iname.c_str()); + if(g_selectedInstances[i]->getParent() != NULL) + { + std::string title = ".. ("; + title += g_selectedInstances[i]->getParent()->name; + title += ")"; + SendMessage(_explorerComboBox,CB_ADDSTRING, 0,(LPARAM)title.c_str()); + parent = g_selectedInstances[i]->getParent(); + } children = g_selectedInstances[i]->getChildren(); for(size_t z = 0; z < children.size(); z++) { SendMessage(_explorerComboBox,CB_ADDSTRING, 0,(LPARAM)children.at(z)->name.c_str()); } SendMessage(_explorerComboBox,CB_SETCURSEL,0,(LPARAM)0); - InvalidateRect(_explorerComboBox, NULL, NULL); } } From 0566dd0217b9c69fd4933feb3e984df8a9d286fa Mon Sep 17 00:00:00 2001 From: andreja6 Date: Thu, 25 Oct 2018 11:50:40 -0700 Subject: [PATCH 11/33] Removed unneeded include --- DataModelInstance.h | 1 - 1 file changed, 1 deletion(-) diff --git a/DataModelInstance.h b/DataModelInstance.h index 45844dc..96ad7a5 100644 --- a/DataModelInstance.h +++ b/DataModelInstance.h @@ -1,5 +1,4 @@ #pragma once -#include "instance.h" #include "WorkspaceInstance.h" #include "LevelInstance.h" From 5dd6ae7d9ce28e5da4566cf86426e0621be277e3 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Thu, 25 Oct 2018 12:58:56 -0700 Subject: [PATCH 12/33] Physixxxxx --- Globals.cpp | 1 + Globals.h | 3 ++- main.cpp | 20 +++++++++++++++++--- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Globals.cpp b/Globals.cpp index 5d7ca78..4ccf40e 100644 --- a/Globals.cpp +++ b/Globals.cpp @@ -11,6 +11,7 @@ bool Globals::useMousePoint = false; const std::string Globals::PlaceholderName = "Dynamica"; std::vector g_selectedInstances = std::vector(); +bool running = false; G3D::TextureRef Globals::surface; POINT Globals::mousepoint; Globals::Globals(void){} diff --git a/Globals.h b/Globals.h index 8aed8fa..5e5d88e 100644 --- a/Globals.h +++ b/Globals.h @@ -20,4 +20,5 @@ public: static const std::string PlaceholderName; }; -extern std::vector g_selectedInstances; \ No newline at end of file +extern std::vector g_selectedInstances; +extern bool running; \ No newline at end of file diff --git a/main.cpp b/main.cpp index 7fa68c9..b416f48 100644 --- a/main.cpp +++ b/main.cpp @@ -72,7 +72,6 @@ static int cursorOvrid = 0; static int currentcursorid = 0; static G3D::TextureRef cursor = NULL; static G3D::TextureRef cursorOvr = NULL; -static bool running = true; static bool mouseMovedBeginMotion = false; static const int CURSOR = 0; static const int ARROWS = 1; @@ -852,8 +851,23 @@ std::vector Demo::getSelection() return g_selectedInstances; } void Demo::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) { - - + if(!running) + { + std::vector objects = dataModel->getWorkspace()->getAllChildren(); + for(size_t i = 0; i < objects.size(); i++) + { + if(PartInstance* moveTo = dynamic_cast(objects.at(i))) + { + moveTo->velocity.y -= (196.2F/30); + moveTo->setPosition(Vector3(moveTo->getPosition().x, moveTo->getPosition().y+(moveTo->velocity.y)/30, moveTo->getPosition().z)); + if(moveTo->getPosition().y < -128) + { + moveTo->setParent(NULL); + delete moveTo; + } + } + } + } Instance * obj6 = dataModel->getGuiRoot()->findFirstChild("Delete"); Instance * obj = dataModel->getGuiRoot()->findFirstChild("Duplicate"); From 7b4abe3efe4e205cad5498053a8961b9fb684b2a Mon Sep 17 00:00:00 2001 From: andreja6 Date: Thu, 25 Oct 2018 15:43:45 -0700 Subject: [PATCH 13/33] Made properties "dynamically update", no longer simply says NO when object makes no sense --- DataModelInstance.cpp | 33 +++++++++++++++++++++++++++++++++ DataModelInstance.h | 5 ++++- PartInstance.cpp | 3 +-- PropertyWindow.cpp | 1 + main.cpp | 30 +++++++++++++++++++----------- 5 files changed, 58 insertions(+), 14 deletions(-) diff --git a/DataModelInstance.cpp b/DataModelInstance.cpp index 904c6d6..ae18fc3 100644 --- a/DataModelInstance.cpp +++ b/DataModelInstance.cpp @@ -31,17 +31,50 @@ DataModelInstance::~DataModelInstance(void) void DataModelInstance::setMessage(std::string msg) { message = msg; + isBrickCount = false; showMessage = true; } void DataModelInstance::clearMessage() { showMessage = false; + isBrickCount = false; message = ""; } +void DataModelInstance::setMessageBrickCount() +{ + isBrickCount = true; + showMessage = true; +} + void DataModelInstance::drawMessage(RenderDevice* rd) { + if(isBrickCount) + { + int brickCount = 0; + int instCount = 0; + std::vector inst = getAllChildren(); + for(size_t i = 0; i < inst.size(); i++) + { + if(PartInstance* moveTo = dynamic_cast(inst.at(i))) + { + brickCount++; + } + else + { + instCount++; + } + } + char brkc[12]; + sprintf(brkc, "%d", brickCount); + char instc[12]; + sprintf(instc, "%d", instCount); + message = "Bricks: "; + message += brkc; + message += " Snaps: "; + message += instc; + } if(showMessage && !font.isNull()) { int x = rd->getWidth()/2; diff --git a/DataModelInstance.h b/DataModelInstance.h index 96ad7a5..26a4be1 100644 --- a/DataModelInstance.h +++ b/DataModelInstance.h @@ -1,6 +1,7 @@ #pragma once #include "WorkspaceInstance.h" #include "LevelInstance.h" +#include "PartInstance.h" class DataModelInstance : public Instance @@ -9,6 +10,7 @@ public: DataModelInstance(void); ~DataModelInstance(void); void setMessage(std::string); + void setMessageBrickCount(); void clearMessage(); void drawMessage(RenderDevice*); WorkspaceInstance* getWorkspace(); @@ -26,6 +28,7 @@ public: void setMousePos(int x,int y); void setMousePos(Vector2 pos); bool mouseButton1Down; - +private: + bool isBrickCount; }; diff --git a/PartInstance.cpp b/PartInstance.cpp index 098a2db..963842f 100644 --- a/PartInstance.cpp +++ b/PartInstance.cpp @@ -152,6 +152,7 @@ bool PartInstance::collides(Box box) void PartInstance::render(RenderDevice* rd) { + if(changed) Box box = getBox(); @@ -257,7 +258,6 @@ void PartInstance::PropUpdate(LPPROPGRIDITEM &item) sprintf(pto, "%g, %g, %g", cFrame.translation.x, cFrame.translation.y, cFrame.translation.z, "what"); LPCSTR str = LPCSTR(pto); item->lpCurValue = (LPARAM)str; - MessageBox(NULL, "NO","NO", MB_OK); } else { @@ -286,7 +286,6 @@ void PartInstance::PropUpdate(LPPROPGRIDITEM &item) sprintf(pto, "%g, %g, %g", cFrame.translation.x, cFrame.translation.y, cFrame.translation.z, "what"); LPCSTR str = LPCSTR(pto); item->lpCurValue = (LPARAM)str; - MessageBox(NULL, "NO","NO", MB_OK); } else { diff --git a/PropertyWindow.cpp b/PropertyWindow.cpp index d6364fb..22881bd 100644 --- a/PropertyWindow.cpp +++ b/PropertyWindow.cpp @@ -164,6 +164,7 @@ LRESULT CALLBACK PropProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) LPNMPROPGRID lpnmp = (LPNMPROPGRID)pnm; LPPROPGRIDITEM item = PropGrid_GetItemData(pnm->hwndFrom,lpnmp->iIndex); selectedInstance->PropUpdate(item); + propWind->SetProperties(selectedInstance); } } break; diff --git a/main.cpp b/main.cpp index b416f48..0758a10 100644 --- a/main.cpp +++ b/main.cpp @@ -786,7 +786,7 @@ void Demo::onInit() { test->setSize(Vector3(4,1,2)); test->setPosition(Vector3(-2,5,0)); - + //dataModel->setMessageBrickCount(); test = makePart(); @@ -851,7 +851,7 @@ std::vector Demo::getSelection() return g_selectedInstances; } void Demo::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) { - if(!running) + if(running) { std::vector objects = dataModel->getWorkspace()->getAllChildren(); for(size_t i = 0; i < objects.size(); i++) @@ -1182,6 +1182,8 @@ void Demo::onGraphics(RenderDevice* rd) { } } + + if(Globals::useMousePoint) { mousepos = Globals::mousepoint; @@ -1208,10 +1210,25 @@ void Demo::onGraphics(RenderDevice* rd) { renderDevice->setLight(0, GLight::directional(lighting.lightDirection, lighting.lightColor)); renderDevice->setAmbientLightColor(lighting.ambient); + + 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); + } + rd->beforePrimitive(); + + dataModel->getWorkspace()->render(rd); rd->afterPrimitive(); + if(g_selectedInstances.size() > 0) { for(size_t i = 0; i < g_selectedInstances.size(); i++) @@ -1226,16 +1243,7 @@ void Demo::onGraphics(RenderDevice* rd) { } - //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(); From 866d644c6317a32c679b7961d25562236d17a6e9 Mon Sep 17 00:00:00 2001 From: MusicalProgrammer <38636805+MusicalProgrammer@users.noreply.github.com> Date: Thu, 25 Oct 2018 20:29:38 -0400 Subject: [PATCH 14/33] Manual merge... (Improved renderer, and added bevels.) --- CameraController.cpp | 27 +++-- Instance.cpp | 7 ++ PartInstance.cpp | 252 +++++++++++++++++++++++++++++++++++++---- PartInstance.h | 20 +++- TextButtonInstance.cpp | 4 + main.cpp | 21 ++-- 6 files changed, 286 insertions(+), 45 deletions(-) diff --git a/CameraController.cpp b/CameraController.cpp index 909ed9a..db6eec8 100644 --- a/CameraController.cpp +++ b/CameraController.cpp @@ -7,18 +7,17 @@ -CameraController::CameraController(){ - yaw=0; - pitch=0; - moveRate=0.5f; - forwards=false; - backwards=false; - left=false; - right=false; - zoom=7.f; - rightButtonHolding=false; - focusPosition=Vector3(0,0,0); -} +CameraController::CameraController() : +yaw(0), +pitch(0), +moveRate(1.0f), +forwards(false), +backwards(false), +left(false), +right(false), +zoom(14.f), +rightButtonHolding(false), +focusPosition(Vector3(0,0,0)) {} GCamera* CameraController::getCamera() { @@ -209,10 +208,10 @@ void CameraController::update(Demo* demo) } if(GetHoldKeyState(VK_RSHIFT) || GetHoldKeyState(VK_LSHIFT)) { - moveRate = 1; + moveRate = 2; } else { - moveRate = 0.5; + moveRate = 1; } if(GetHoldKeyState(VK_RBUTTON)) diff --git a/Instance.cpp b/Instance.cpp index 1a9dbb0..b9ea6de 100644 --- a/Instance.cpp +++ b/Instance.cpp @@ -25,10 +25,17 @@ Instance::Instance(const Instance &oinst) void Instance::render(RenderDevice* rd) { + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); + glEnableClientState(GL_NORMAL_ARRAY); + for(size_t i = 0; i < children.size(); i++) { children.at(i)->render(rd); } + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_NORMAL_ARRAY); } diff --git a/PartInstance.cpp b/PartInstance.cpp index 963842f..0363455 100644 --- a/PartInstance.cpp +++ b/PartInstance.cpp @@ -1,8 +1,10 @@ #include "PartInstance.h" #include "Globals.h" +#include +#include -PartInstance::PartInstance(void) +PartInstance::PartInstance(void) : _bevelSize(0.03f), _parseVert(0), _debugTimer(0) { PVInstance::PVInstance(); name = "Unnamed PVItem"; @@ -108,12 +110,20 @@ void PartInstance::setCFrame(CoordinateFrame coordinateFrame) position = coordinateFrame.translation; changed = true; } - +// Can probably be deleted CoordinateFrame PartInstance::getCFrameRenderBased() { - return CoordinateFrame(getCFrame().rotation,Vector3(getCFrame().translation.x/2, getCFrame().translation.y/2, getCFrame().translation.z/2)); + return CoordinateFrame(getCFrame().rotation,Vector3(getCFrame().translation.x, getCFrame().translation.y, getCFrame().translation.z)); } - +#ifdef NEW_BOX_RENDER +Box PartInstance::getBox() +{ + Box box = Box(Vector3(size.x/2, size.y/2, size.z/2) ,Vector3(-size.x/2,-size.y/2,-size.z/2)); + CoordinateFrame c = getCFrameRenderBased(); + itemBox = c.toWorldSpace(box); + return itemBox; +} +#else Box PartInstance::getBox() { if(changed) @@ -124,32 +134,227 @@ Box PartInstance::getBox() Vector3 v0,v1,v2,v3; for (int f = 0; f < 6; f++) { itemBox.getFaceCorners(f, v0,v1,v2,v3); - vertecies[f*16] = v0.x; - vertecies[(f*16)+1] = v0.y; - vertecies[(f*16)+2] = v0.z; - vertecies[(f*16)+3] = v1.x; - vertecies[(f*16)+4] = v1.y; - vertecies[(f*16)+5] = v1.z; - vertecies[(f*16)+6] = v2.x; - vertecies[(f*16)+7] = v2.y; - vertecies[(f*16)+8] = v2.z; - vertecies[(f*16)+9] = v3.x; - vertecies[(f*16)+10] = v3.y; - vertecies[(f*16)+11] = v3.z; - vertecies[(f*16)+12] = color.r; - vertecies[(f*16)+13] = color.g; - vertecies[(f*16)+14] = color.b; - vertecies[(f*16)+15] = 1; + _vertices[f*16] = v0.x; + _vertices[(f*16)+1] = v0.y; + _vertices[(f*16)+2] = v0.z; + _vertices[(f*16)+3] = v1.x; + _vertices[(f*16)+4] = v1.y; + _vertices[(f*16)+5] = v1.z; + _vertices[(f*16)+6] = v2.x; + _vertices[(f*16)+7] = v2.y; + _vertices[(f*16)+8] = v2.z; + _vertices[(f*16)+9] = v3.x; + _vertices[(f*16)+10] = v3.y; + _vertices[(f*16)+11] = v3.z; + _vertices[(f*16)+12] = color.r; + _vertices[(f*16)+13] = color.g; + _vertices[(f*16)+14] = color.b; + _vertices[(f*16)+15] = 1; } } return itemBox; } +#endif bool PartInstance::collides(Box box) { return CollisionDetection::fixedSolidBoxIntersectsFixedSolidBox(getBox(), box); } +void PartInstance::addVertex(Vector3 vertexPos,Color3 color) +{ + _vertices.push_back(vertexPos.x); + _vertices.push_back(vertexPos.y); + _vertices.push_back(vertexPos.z); + _vertices.push_back(color.r); + _vertices.push_back(color.g); + _vertices.push_back(color.b); +} + void PartInstance::addNormals(Vector3 normal) +{ + for (unsigned int i=0;i<3;i+=1) { + _normals.push_back(normal.x); + _normals.push_back(normal.y); + _normals.push_back(normal.z); + } +} + void PartInstance::addTriangle(Vector3 v1,Vector3 v2,Vector3 v3) +{ + addVertex(v1,color); + addVertex(v2,color); + addVertex(v3,color); + addNormals(cross(v2-v1,v3-v1).direction()); +} + void PartInstance::debugPrintVertexIDs(RenderDevice* rd,GFontRef font,Matrix3 rot) +{ + _debugUniqueVertices.clear(); + glDisable(GL_DEPTH_TEST); + + for (unsigned int i=0;i<_vertices.size();i+=6) + { + std::stringstream stream; + stream << std::fixed << std::setprecision(1) << i; + Vector3 testVector = Vector3(_vertices[i],_vertices[i+1],_vertices[i+2]); + if (isUniqueVertex(testVector)) + { + + font->draw3D(rd, stream.str(), CoordinateFrame(testVector) * -rot, 0.05, Color3::fromARGB(0xFF4F0000), Color4::clear()); + _debugUniqueVertices.push_back(testVector); + } + } + glEnable(GL_DEPTH_TEST); +} + void PartInstance::makeFace(int vertex1,int vertex2, int vertex3) +{ + addTriangle(Vector3(_vertices[vertex1],_vertices[vertex1+1],_vertices[vertex1+2]), + Vector3(_vertices[vertex2],_vertices[vertex2+1],_vertices[vertex2+2]), + Vector3(_vertices[vertex3],_vertices[vertex3+1],_vertices[vertex3+2])); +} +bool PartInstance::isUniqueVertex(Vector3 pos) +{ + for (unsigned int i=0;i<_debugUniqueVertices.size();i+=1) + { + if (pos==_debugUniqueVertices[i]) + { + return false; + } + } + return true; +} + +#ifdef NEW_BOX_RENDER +void PartInstance::render(RenderDevice* rd) { + if (changed) + { + getBox(); + _vertices.clear(); + Vector3 renderSize = size/2; + // Front + addTriangle(Vector3(renderSize.x-_bevelSize,renderSize.y-_bevelSize,renderSize.z), + Vector3(-renderSize.x+_bevelSize,-renderSize.y+_bevelSize,renderSize.z), + Vector3(renderSize.x-_bevelSize,-renderSize.y+_bevelSize,renderSize.z) + ); + + addTriangle(Vector3(-renderSize.x+_bevelSize,renderSize.y-_bevelSize,renderSize.z), + Vector3(-renderSize.x+_bevelSize,-renderSize.y+_bevelSize,renderSize.z), + Vector3(renderSize.x-_bevelSize,renderSize.y-_bevelSize,renderSize.z) + ); + + // Top + addTriangle(Vector3(renderSize.x-_bevelSize,renderSize.y,renderSize.z-_bevelSize), + Vector3(renderSize.x-_bevelSize,renderSize.y,-renderSize.z+_bevelSize), + Vector3(-renderSize.x+_bevelSize,renderSize.y,renderSize.z-_bevelSize) + ); + addTriangle(Vector3(-renderSize.x+_bevelSize,renderSize.y,renderSize.z-_bevelSize), + Vector3(renderSize.x-_bevelSize,renderSize.y,-renderSize.z+_bevelSize), + Vector3(-renderSize.x+_bevelSize,renderSize.y,-renderSize.z+_bevelSize) + ); + + // Back + addTriangle(Vector3(renderSize.x-_bevelSize,renderSize.y-_bevelSize,-renderSize.z), + Vector3(renderSize.x-_bevelSize,-renderSize.y+_bevelSize,-renderSize.z), + Vector3(-renderSize.x+_bevelSize,-renderSize.y+_bevelSize,-renderSize.z) + ); + addTriangle(Vector3(renderSize.x-_bevelSize,renderSize.y-_bevelSize,-renderSize.z), + Vector3(-renderSize.x+_bevelSize,-renderSize.y+_bevelSize,-renderSize.z), + Vector3(-renderSize.x+_bevelSize,renderSize.y-_bevelSize,-renderSize.z) + ); + + // Bottom + addTriangle(Vector3(renderSize.x-_bevelSize,-renderSize.y,-renderSize.z+_bevelSize), + Vector3(renderSize.x-_bevelSize,-renderSize.y,renderSize.z-_bevelSize), + Vector3(-renderSize.x+_bevelSize,-renderSize.y,renderSize.z-_bevelSize) + ); + addTriangle(Vector3(-renderSize.x+_bevelSize,-renderSize.y,renderSize.z-_bevelSize), + Vector3(-renderSize.x+_bevelSize,-renderSize.y,-renderSize.z+_bevelSize), + Vector3(renderSize.x-_bevelSize,-renderSize.y,-renderSize.z+_bevelSize) + ); + // Left + addTriangle(Vector3(-renderSize.x,renderSize.y-_bevelSize,-renderSize.z+_bevelSize), + Vector3(-renderSize.x,-renderSize.y+_bevelSize,renderSize.z-_bevelSize), + Vector3(-renderSize.x,renderSize.y-_bevelSize,renderSize.z-_bevelSize) + ); + addTriangle(Vector3(-renderSize.x,-renderSize.y+_bevelSize,renderSize.z-_bevelSize), + Vector3(-renderSize.x,renderSize.y-_bevelSize,-renderSize.z+_bevelSize), + Vector3(-renderSize.x,-renderSize.y+_bevelSize,-renderSize.z+_bevelSize) + ); + // Right + addTriangle(Vector3(renderSize.x,renderSize.y-_bevelSize,renderSize.z-_bevelSize), + Vector3(renderSize.x,-renderSize.y+_bevelSize,renderSize.z-_bevelSize), + Vector3(renderSize.x,renderSize.y-_bevelSize,-renderSize.z+_bevelSize) + ); + addTriangle(Vector3(renderSize.x,-renderSize.y+_bevelSize,-renderSize.z+_bevelSize), + Vector3(renderSize.x,renderSize.y-_bevelSize,-renderSize.z+_bevelSize), + Vector3(renderSize.x,-renderSize.y+_bevelSize,renderSize.z-_bevelSize) + ); + + // Bevel Top Front + makeFace(0,36,48); + makeFace(48,18,0); + // Bevel Left Front Corner + makeFace(18,156,162); + makeFace(24,18,162); + // Bevel Left Front Top Corner + makeFace(48,156,18); + // Bevel Left Front Bottom Corner + makeFace(120,6,150); + // Bevel Left Top + makeFace(48,66,156); + makeFace(144,156,66); + // Bevel Bottom + makeFace(6,120,114); + makeFace(114,12,6); + // Left Bottom + makeFace(120,150,174); + makeFace(174,132,120); + // Right Front Top Corner + makeFace(36,0,180); + // Right Front Corner + makeFace(180,0,12); + makeFace(186,180,12); + // Right Front Bottom Corner + makeFace(186,12,114); + // Right Bottom + makeFace(186,114,108); + makeFace(108,198,186); + // Right Top Corner + makeFace(180,192,36); + makeFace(192,42,36); + // Right Back Top Corner + makeFace(72,42,192); + // Right Back Bottom Corner + makeFace(78,198,108); + // Right Back Corner + makeFace(72,192,198); + makeFace(198,78,72); + // Back Bottom Corner + makeFace(78,108,132); + makeFace(132,84,78); + // Back Top + makeFace(42,72,102); + makeFace(102,66,42); + // Back Left Top Corner + makeFace(144,66,102); + // Back Left Corner + makeFace(144,102,84); + makeFace(84,174,144); + // Back Left Bottom Corner + makeFace(174,84,132); + + for (unsigned short i=0;i<_vertices.size()/6;i++) { + _indices.push_back(i); + } + changed=false; + } + glVertexPointer(3, GL_FLOAT,6 * sizeof(GLfloat), &_vertices[0]); + glColorPointer(3, GL_FLOAT,6 * sizeof(GLfloat), &_vertices[3]); + glNormalPointer(GL_FLOAT,3 * sizeof(GLfloat), &_normals[0]); + glPushMatrix(); + glTranslatef(position.x,position.y,position.z); + glDrawElements(GL_TRIANGLES, _indices.size(), GL_UNSIGNED_SHORT, &_indices[0]); + glPopMatrix(); +} +#else void PartInstance::render(RenderDevice* rd) { @@ -184,14 +389,14 @@ void PartInstance::render(RenderDevice* rd) else if(face == Inlets) add = 0.2;*/ - Vector3 v0 = Vector3(vertecies[i], vertecies[i+1], vertecies[i+2]), v1 = Vector3(vertecies[i+3], vertecies[i+4], vertecies[i+5]), v3 = Vector3(vertecies[i+9], vertecies[i+10], vertecies[i+11]); + Vector3 v0 = Vector3(_vertices[i], _vertices[i+1], _vertices[i+2]), v1 = Vector3(_vertices[i+3], _vertices[i+4], _vertices[i+5]), v3 = Vector3(_vertices[i+9], _vertices[i+10], _vertices[i+11]); /*glNormal3fv((v1 - v0).cross(v3 - v0).direction()); glTexCoord2f(0.0F,0.0F); glVertex3fv(v0); glTexCoord2f(1.0F,0.0F); glVertex3fv(v1); glTexCoord2f(1.0F,0.25F); - glVertex3f(vertecies[i+6], vertecies[i+7], vertecies[i+8]); + glVertex3f(_vertices[i+6], _vertices[i+7], _vertices[i+8]); glTexCoord2f(0.0F,0.25F); glVertex3fv(v3);*/ @@ -206,7 +411,7 @@ void PartInstance::render(RenderDevice* rd) glTexCoord2d( 1.0,0.0+add); glVertex3fv(v1); glTexCoord2d(1.0,0.2+add); - glVertex3f(vertecies[i+6], vertecies[i+7], vertecies[i+8]); + glVertex3f(_vertices[i+6], _vertices[i+7], _vertices[i+8]); glTexCoord2d( 0.0,0.2+add); glVertex3fv(v3); glEnd(); @@ -224,6 +429,7 @@ void PartInstance::render(RenderDevice* rd) } } +#endif PartInstance::~PartInstance(void) { diff --git a/PartInstance.h b/PartInstance.h index 84c4fe2..16d9a02 100644 --- a/PartInstance.h +++ b/PartInstance.h @@ -2,6 +2,8 @@ #include "PVInstance.h" #include "Enum.h" +#define NEW_BOX_RENDER + class PartInstance : public PVInstance { public: @@ -35,10 +37,26 @@ public: bool collides(Box); virtual std::vector getProperties(); virtual void PropUpdate(LPPROPGRIDITEM &pItem); + void addVertex(Vector3 vertexPos,Color3 color); + void addNormals(Vector3 normal); + void addTriangle(Vector3 vertexPos,Vector3 vertexPos2, Vector3 vertexPos3); + void debugPrintVertexIDs(RenderDevice* rd, GFontRef font, Matrix3 camRot); + void makeFace(int vertex1, int vertex2, int vertex3); + bool isUniqueVertex(Vector3 pos); private: Vector3 position; Vector3 size; - GLfloat vertecies[96]; + float _bevelSize; + int _parseVert; + int _debugTimer; + std::vector _debugUniqueVertices; + #ifdef NEW_BOX_RENDER + std::vector _vertices; + std::vector _normals; + #else + GLfloat _vertices[96]; + #endif + std::vector _indices; bool changed; Box itemBox; }; diff --git a/TextButtonInstance.cpp b/TextButtonInstance.cpp index 5a9b472..a93e0e9 100644 --- a/TextButtonInstance.cpp +++ b/TextButtonInstance.cpp @@ -72,6 +72,8 @@ void TextButtonInstance::drawObj(RenderDevice* rd, Vector2 mousePos, bool mouseD { Vector3 point1; Vector3 point2; + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); if(floatBottom) { point1 = Vector3(boxBegin.x, rd->getHeight() + boxBegin.y,0); @@ -104,6 +106,8 @@ void TextButtonInstance::drawObj(RenderDevice* rd, Vector2 mousePos, bool mouseD Draw::box(Box(point1, point2), rd, boxColor, boxOutlineColor); font->draw2D(rd, title, RelativeTo, textSize, textColor, textOutlineColor); } + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); } void doNullCheck() diff --git a/main.cpp b/main.cpp index 0758a10..39d73b9 100644 --- a/main.cpp +++ b/main.cpp @@ -1064,18 +1064,18 @@ void drawOutline(Vector3 from, Vector3 to, RenderDevice* rd, LightingParameters { Color3 outline = Color3::cyan();//Color3(0.098F,0.6F,1.0F); - float offsetSize = 0.05F; + float offsetSize = 0.1F; //X Draw::box(c.toWorldSpace(Box(Vector3(from.x - offsetSize, from.y + offsetSize, from.z + offsetSize), Vector3(to.x + offsetSize, from.y - offsetSize, from.z - offsetSize))), rd, outline, Color4::clear()); Draw::box(c.toWorldSpace(Box(Vector3(from.x - offsetSize, to.y + offsetSize, from.z + offsetSize), Vector3(to.x + offsetSize, to.y - offsetSize, from.z - offsetSize))), rd, outline, Color4::clear()); Draw::box(c.toWorldSpace(Box(Vector3(from.x - offsetSize, to.y + offsetSize, to.z + offsetSize), Vector3(to.x + offsetSize, to.y - offsetSize, to.z - offsetSize))), rd, outline, Color4::clear()); Draw::box(c.toWorldSpace(Box(Vector3(from.x - offsetSize, from.y + offsetSize, to.z + offsetSize), Vector3(to.x + offsetSize, from.y - offsetSize, to.z - offsetSize))), rd, outline, Color4::clear()); //Y - Draw::box(c.toWorldSpace(Box(Vector3(from.x + offsetSize, from.y - offsetSize + 0.1, from.z + offsetSize), Vector3(from.x - offsetSize, to.y + offsetSize - 0.1, from.z - offsetSize))), rd, outline, Color4::clear()); - Draw::box(c.toWorldSpace(Box(Vector3(to.x + offsetSize, from.y - offsetSize + 0.1, from.z + offsetSize), Vector3(to.x - offsetSize, to.y + offsetSize - 0.1, from.z - offsetSize))), rd, outline, Color4::clear()); - Draw::box(c.toWorldSpace(Box(Vector3(to.x + offsetSize, from.y - offsetSize + 0.1, to.z + offsetSize), Vector3(to.x - offsetSize, to.y + offsetSize-0.1, to.z - offsetSize))), rd, outline, Color4::clear()); - Draw::box(c.toWorldSpace(Box(Vector3(from.x + offsetSize, from.y - offsetSize + 0.1, to.z + offsetSize), Vector3(from.x - offsetSize, to.y + offsetSize - 0.1, to.z - offsetSize))), rd, outline, Color4::clear()); - + Draw::box(c.toWorldSpace(Box(Vector3(from.x + offsetSize, from.y - offsetSize + 0.2, from.z + offsetSize), Vector3(from.x - offsetSize, to.y + offsetSize - 0.2, from.z - offsetSize))), rd, outline, Color4::clear()); + Draw::box(c.toWorldSpace(Box(Vector3(to.x + offsetSize, from.y - offsetSize + 0.2, from.z + offsetSize), Vector3(to.x - offsetSize, to.y + offsetSize - 0.2, from.z - offsetSize))), rd, outline, Color4::clear()); + Draw::box(c.toWorldSpace(Box(Vector3(to.x + offsetSize, from.y - offsetSize + 0.2, to.z + offsetSize), Vector3(to.x - offsetSize, to.y + offsetSize-0.2, to.z - offsetSize))), rd, outline, Color4::clear()); + Draw::box(c.toWorldSpace(Box(Vector3(from.x + offsetSize, from.y - offsetSize + 0.2, to.z + offsetSize), Vector3(from.x - offsetSize, to.y + offsetSize - 0.2, to.z - offsetSize))), rd, outline, Color4::clear()); + //Z Draw::box(c.toWorldSpace(Box(Vector3(from.x + offsetSize, from.y + offsetSize, from.z - offsetSize), Vector3(from.x - offsetSize, from.y - offsetSize, to.z + offsetSize))), rd, outline, Color4::clear()); Draw::box(c.toWorldSpace(Box(Vector3(from.x + offsetSize, to.y + offsetSize, from.z - offsetSize), Vector3(from.x - offsetSize, to.y - offsetSize, to.z + offsetSize))), rd, outline, Color4::clear()); @@ -1153,6 +1153,7 @@ void Demo::exitApplication() void Demo::onGraphics(RenderDevice* rd) { + G3D::uint8 num = 0; POINT mousepos; mouseOnScreen = true; @@ -1226,6 +1227,8 @@ void Demo::onGraphics(RenderDevice* rd) { dataModel->getWorkspace()->render(rd); + //if (dataModel->children[0]->children.size()>0) + //((PartInstance*)dataModel->children[0]->children[0])->debugPrintVertexIDs(rd,fntdominant,-cameraController.getCoordinateFrame().rotation); rd->afterPrimitive(); @@ -1237,7 +1240,7 @@ void Demo::onGraphics(RenderDevice* rd) { { 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()); + drawOutline(Vector3(size.x/2, size.y/2, size.z/2) ,Vector3(-size.x/2,-size.y/2,-size.z/2), rd, lighting, Vector3(size.x/2, size.y/2, size.z/2), Vector3(pos.x, pos.y, pos.z), part->getCFrameRenderBased()); } } } @@ -1259,6 +1262,10 @@ void Demo::onGraphics(RenderDevice* rd) { //TODO--Move these to their own instance std::stringstream stream; + stream << std::fixed << std::setprecision(3) << m_graphicsWatch.FPS(); + fntdominant->draw2D(rd, "FPS: " + stream.str(), Vector2(120, 25), 10, Color3::fromARGB(0xFFFF00), Color3::black()); + stream.str(""); + stream.clear(); stream << std::fixed << std::setprecision(1) << dataModel->getLevel()->timer; fntdominant->draw2D(rd, "Timer: " + stream.str(), Vector2(rd->getWidth() - 120, 25), 20, Color3::fromARGB(0x81C518), Color3::black()); fntdominant->draw2D(rd, "Score: " + Convert(dataModel->getLevel()->score), Vector2(rd->getWidth() - 120, 50), 20, Color3::fromARGB(0x81C518), Color3::black()); From b1af53995a1181327988288360e628949ae26e79 Mon Sep 17 00:00:00 2001 From: MusicalProgrammer <38636805+MusicalProgrammer@users.noreply.github.com> Date: Thu, 25 Oct 2018 20:51:15 -0400 Subject: [PATCH 15/33] Parts now recolor properly again. --- PartInstance.cpp | 1 + TextButtonInstance.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/PartInstance.cpp b/PartInstance.cpp index 0363455..c9cefac 100644 --- a/PartInstance.cpp +++ b/PartInstance.cpp @@ -443,6 +443,7 @@ void PartInstance::PropUpdate(LPPROPGRIDITEM &item) if(strcmp(item->lpszPropName, "Color3") == 0) { color = Color3(GetRValue(item->lpCurValue)/255.0F,GetGValue(item->lpCurValue)/255.0F,GetBValue(item->lpCurValue)/255.0F); + changed=true; } else if(strcmp(item->lpszPropName, "Offset") == 0) { diff --git a/TextButtonInstance.cpp b/TextButtonInstance.cpp index a93e0e9..5b74ecc 100644 --- a/TextButtonInstance.cpp +++ b/TextButtonInstance.cpp @@ -74,6 +74,7 @@ void TextButtonInstance::drawObj(RenderDevice* rd, Vector2 mousePos, bool mouseD Vector3 point2; glEnableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_COLOR_ARRAY); + if(floatBottom) { point1 = Vector3(boxBegin.x, rd->getHeight() + boxBegin.y,0); From 30a05af3b29f278f5a0b87f5fbbb4e619327b724 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Thu, 25 Oct 2018 18:16:39 -0700 Subject: [PATCH 16/33] Added postrender --- Globals.cpp | 2 +- Globals.h | 2 ++ PartInstance.cpp | 18 ++++++++++++++++++ PartInstance.h | 1 + main.cpp | 7 ++++++- 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Globals.cpp b/Globals.cpp index 4ccf40e..3f63fb1 100644 --- a/Globals.cpp +++ b/Globals.cpp @@ -8,7 +8,7 @@ int const Globals::patch = 2; int Globals::surfaceId = 2; bool Globals::showMouse = true; bool Globals::useMousePoint = false; - +std::stack postRenderStack = std::stack(); const std::string Globals::PlaceholderName = "Dynamica"; std::vector g_selectedInstances = std::vector(); bool running = false; diff --git a/Globals.h b/Globals.h index 5e5d88e..4bc98fb 100644 --- a/Globals.h +++ b/Globals.h @@ -1,6 +1,7 @@ #pragma once #include "DataModelInstance.h" #include +#include class Globals { @@ -20,5 +21,6 @@ public: static const std::string PlaceholderName; }; +extern std::stack postRenderStack; extern std::vector g_selectedInstances; extern bool running; \ No newline at end of file diff --git a/PartInstance.cpp b/PartInstance.cpp index c9cefac..9c5e8e6 100644 --- a/PartInstance.cpp +++ b/PartInstance.cpp @@ -25,6 +25,24 @@ PartInstance::PartInstance(void) : _bevelSize(0.03f), _parseVert(0), _debugTimer shape = Enum::Shape::Block; } +void PartInstance::postRender(RenderDevice *rd) +{ + G3D::GFontRef fntdominant = NULL; + if(fntdominant != NULL) + { + Vector3 gamepoint = cFrame.translation; + 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); + } + } +} + PartInstance::PartInstance(const PartInstance &oinst) { PVInstance::PVInstance(oinst); diff --git a/PartInstance.h b/PartInstance.h index 16d9a02..5c507f3 100644 --- a/PartInstance.h +++ b/PartInstance.h @@ -10,6 +10,7 @@ public: PartInstance(void); PartInstance(const PartInstance &oinst); Instance* clone() const { return new PartInstance(*this); } + void PartInstance::postRender(RenderDevice* rd); ~PartInstance(void); virtual void render(RenderDevice*); Vector3 velocity; diff --git a/main.cpp b/main.cpp index 39d73b9..0f7333f 100644 --- a/main.cpp +++ b/main.cpp @@ -1246,7 +1246,12 @@ void Demo::onGraphics(RenderDevice* rd) { } - + while(!postRenderStack.empty()) + { + Instance* inst = postRenderStack.top(); + postRenderStack.pop(); + + } renderDevice->disableLighting(); From f7d678169864a7180de3a1b83e33d4791d0adb64 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Thu, 25 Oct 2018 18:18:08 -0700 Subject: [PATCH 17/33] Fixed properties --- PartInstance.cpp | 2 +- PropertyWindow.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PartInstance.cpp b/PartInstance.cpp index 9c5e8e6..a321d06 100644 --- a/PartInstance.cpp +++ b/PartInstance.cpp @@ -28,7 +28,7 @@ PartInstance::PartInstance(void) : _bevelSize(0.03f), _parseVert(0), _debugTimer void PartInstance::postRender(RenderDevice *rd) { G3D::GFontRef fntdominant = NULL; - if(fntdominant != NULL) + if(fntdominant.notNull()) { Vector3 gamepoint = cFrame.translation; Vector3 camerapoint = rd->getCameraToWorldMatrix().translation; diff --git a/PropertyWindow.cpp b/PropertyWindow.cpp index 22881bd..d15e976 100644 --- a/PropertyWindow.cpp +++ b/PropertyWindow.cpp @@ -164,7 +164,7 @@ LRESULT CALLBACK PropProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) LPNMPROPGRID lpnmp = (LPNMPROPGRID)pnm; LPPROPGRIDITEM item = PropGrid_GetItemData(pnm->hwndFrom,lpnmp->iIndex); selectedInstance->PropUpdate(item); - propWind->SetProperties(selectedInstance); + //propWind->SetProperties(selectedInstance); } } break; From 7e2eb2c694751a12e28a0bbc35073cdc19d4b7b2 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Thu, 25 Oct 2018 18:56:00 -0700 Subject: [PATCH 18/33] Parts with "ShowName" enabled now do what they are supposed to. Huzzah! --- Globals.cpp | 2 +- Globals.h | 3 +-- PVInstance.cpp | 17 ++++++++++++++++- PVInstance.h | 2 ++ PartInstance.cpp | 33 ++++++++++++++++++++++++--------- PartInstance.h | 2 +- main.cpp | 14 ++++++++++---- 7 files changed, 55 insertions(+), 18 deletions(-) diff --git a/Globals.cpp b/Globals.cpp index 3f63fb1..1c00f66 100644 --- a/Globals.cpp +++ b/Globals.cpp @@ -8,7 +8,7 @@ int const Globals::patch = 2; int Globals::surfaceId = 2; bool Globals::showMouse = true; bool Globals::useMousePoint = false; -std::stack postRenderStack = std::stack(); +std::vector postRenderStack = std::vector(); const std::string Globals::PlaceholderName = "Dynamica"; std::vector g_selectedInstances = std::vector(); bool running = false; diff --git a/Globals.h b/Globals.h index 4bc98fb..09efa1b 100644 --- a/Globals.h +++ b/Globals.h @@ -1,7 +1,6 @@ #pragma once #include "DataModelInstance.h" #include -#include class Globals { @@ -21,6 +20,6 @@ public: static const std::string PlaceholderName; }; -extern std::stack postRenderStack; +extern std::vector postRenderStack; extern std::vector g_selectedInstances; extern bool running; \ No newline at end of file diff --git a/PVInstance.cpp b/PVInstance.cpp index 271ea50..ea85c51 100644 --- a/PVInstance.cpp +++ b/PVInstance.cpp @@ -3,6 +3,7 @@ PVInstance::PVInstance(void) { Instance::Instance(); + nameShown = false; className = "PVInstance"; } @@ -15,12 +16,26 @@ PVInstance::~PVInstance(void) { } +void PVInstance::postRender(RenderDevice* rd) +{ +} + std::vector PVInstance::getProperties() { std::vector properties = Instance::getProperties(); + properties.push_back(createPGI( + "Item", + "NameShown", + "This chooses whether the item name is shown", + false, + PIT_CHECK)); return properties; } void PVInstance::PropUpdate(LPPROPGRIDITEM &pItem) { - Instance::PropUpdate(pItem); + if(strcmp(pItem->lpszPropName, "NameShown") == 0) + { + nameShown = (bool)pItem->lpCurValue; + } + else Instance::PropUpdate(pItem); } diff --git a/PVInstance.h b/PVInstance.h index 99f2233..9f6e65d 100644 --- a/PVInstance.h +++ b/PVInstance.h @@ -8,6 +8,8 @@ public: PVInstance(void); ~PVInstance(void); PVInstance(const PVInstance &oinst); + virtual void postRender(RenderDevice* rd); virtual std::vector getProperties(); virtual void PropUpdate(LPPROPGRIDITEM &pItem); + bool nameShown; }; diff --git a/PartInstance.cpp b/PartInstance.cpp index a321d06..f6d1136 100644 --- a/PartInstance.cpp +++ b/PartInstance.cpp @@ -27,18 +27,31 @@ PartInstance::PartInstance(void) : _bevelSize(0.03f), _parseVert(0), _debugTimer void PartInstance::postRender(RenderDevice *rd) { - G3D::GFontRef fntdominant = NULL; - if(fntdominant.notNull()) + if(!nameShown) + return; + G3D::GFontRef fnt = NULL; + Instance* dm = parent; + while(dm != NULL) { - Vector3 gamepoint = cFrame.translation; + if(DataModelInstance* mod = dynamic_cast(dm)) + { + fnt = mod->font; + break; + } + dm = dm->getParent(); + } + if(!fnt.isNull()) + { + Vector3 gamepoint = position + Vector3(0,1.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 < 100 && distance > -100) { 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); + glDisable(GL_DEPTH_TEST); + fnt->draw3D(rd, name, CoordinateFrame(rd->getCameraToWorldMatrix().rotation, gamepoint), 0.03*distance, Color3::yellow(), Color3::black(), G3D::GFont::XALIGN_CENTER, G3D::GFont::YALIGN_CENTER); + glEnable(GL_DEPTH_TEST); } } } @@ -131,7 +144,7 @@ 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)); } #ifdef NEW_BOX_RENDER Box PartInstance::getBox() @@ -242,6 +255,8 @@ bool PartInstance::isUniqueVertex(Vector3 pos) #ifdef NEW_BOX_RENDER void PartInstance::render(RenderDevice* rd) { + if(nameShown) + postRenderStack.push_back(this); if (changed) { getBox(); @@ -519,12 +534,12 @@ void PartInstance::PropUpdate(LPPROPGRIDITEM &item) } } - else Instance::PropUpdate(item); + else PVInstance::PropUpdate(item); } std::vector PartInstance::getProperties() { - std::vector properties = Instance::getProperties(); + std::vector properties = PVInstance::getProperties(); properties.push_back(createPGI( diff --git a/PartInstance.h b/PartInstance.h index 5c507f3..fe2a3e5 100644 --- a/PartInstance.h +++ b/PartInstance.h @@ -10,7 +10,7 @@ public: PartInstance(void); PartInstance(const PartInstance &oinst); Instance* clone() const { return new PartInstance(*this); } - void PartInstance::postRender(RenderDevice* rd); + virtual void PartInstance::postRender(RenderDevice* rd); ~PartInstance(void); virtual void render(RenderDevice*); Vector3 velocity; diff --git a/main.cpp b/main.cpp index 0f7333f..6d8016f 100644 --- a/main.cpp +++ b/main.cpp @@ -1211,7 +1211,7 @@ void Demo::onGraphics(RenderDevice* rd) { renderDevice->setLight(0, GLight::directional(lighting.lightDirection, lighting.lightColor)); renderDevice->setAmbientLightColor(lighting.ambient); - +/* 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); @@ -1222,7 +1222,7 @@ void Demo::onGraphics(RenderDevice* rd) { 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); } - +*/ rd->beforePrimitive(); @@ -1248,11 +1248,17 @@ void Demo::onGraphics(RenderDevice* rd) { while(!postRenderStack.empty()) { - Instance* inst = postRenderStack.top(); - postRenderStack.pop(); + Instance* inst = postRenderStack.at(0); + postRenderStack.erase(postRenderStack.begin()); + if(PVInstance* pinst = dynamic_cast(inst)) + { + pinst->postRender(rd); + } } + + renderDevice->disableLighting(); if (sky.notNull()) { From 5773584f488630d73be9b64a91215e3cbe5111da Mon Sep 17 00:00:00 2001 From: andreja6 Date: Thu, 25 Oct 2018 19:01:14 -0700 Subject: [PATCH 19/33] made bevels a bit bigger --- PartInstance.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PartInstance.cpp b/PartInstance.cpp index f6d1136..96b3f38 100644 --- a/PartInstance.cpp +++ b/PartInstance.cpp @@ -4,7 +4,7 @@ #include -PartInstance::PartInstance(void) : _bevelSize(0.03f), _parseVert(0), _debugTimer(0) +PartInstance::PartInstance(void) : _bevelSize(0.08f), _parseVert(0), _debugTimer(0) { PVInstance::PVInstance(); name = "Unnamed PVItem"; From c9bb2ae72bf7053ff3d1220c19ebe2e26c291e17 Mon Sep 17 00:00:00 2001 From: DirtPiper Date: Thu, 25 Oct 2018 22:33:45 -0400 Subject: [PATCH 20/33] Bevel fix Made more accurate. --- PartInstance.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PartInstance.cpp b/PartInstance.cpp index 96b3f38..75c2eef 100644 --- a/PartInstance.cpp +++ b/PartInstance.cpp @@ -4,7 +4,7 @@ #include -PartInstance::PartInstance(void) : _bevelSize(0.08f), _parseVert(0), _debugTimer(0) +PartInstance::PartInstance(void) : _bevelSize(0.07f), _parseVert(0), _debugTimer(0) { PVInstance::PVInstance(); name = "Unnamed PVItem"; From ff5b855e1237275663c9dd57e1dc84c55565983d Mon Sep 17 00:00:00 2001 From: andreja6 Date: Fri, 26 Oct 2018 13:15:54 -0700 Subject: [PATCH 21/33] Fixed bevels going mentally insane on duplicate --- PVInstance.cpp | 2 +- PartInstance.cpp | 3 ++- main.cpp | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/PVInstance.cpp b/PVInstance.cpp index ea85c51..1a0da08 100644 --- a/PVInstance.cpp +++ b/PVInstance.cpp @@ -27,7 +27,7 @@ std::vector PVInstance::getProperties() "Item", "NameShown", "This chooses whether the item name is shown", - false, + nameShown, PIT_CHECK)); return properties; } diff --git a/PartInstance.cpp b/PartInstance.cpp index 75c2eef..e6366c8 100644 --- a/PartInstance.cpp +++ b/PartInstance.cpp @@ -56,7 +56,7 @@ void PartInstance::postRender(RenderDevice *rd) } } -PartInstance::PartInstance(const PartInstance &oinst) +PartInstance::PartInstance(const PartInstance &oinst) : _bevelSize(0.07f), _parseVert(0), _debugTimer(0) { PVInstance::PVInstance(oinst); //name = oinst.name; @@ -77,6 +77,7 @@ PartInstance::PartInstance(const PartInstance &oinst) left = oinst.left; bottom = oinst.bottom; shape = oinst.shape; + changed = true; } void PartInstance::setSize(Vector3 newSize) diff --git a/main.cpp b/main.cpp index 6d8016f..7e7a482 100644 --- a/main.cpp +++ b/main.cpp @@ -1342,6 +1342,7 @@ void Demo::onGraphics(RenderDevice* rd) { rd->afterPrimitive(); rd->popState(); renderDevice->pop2D(); + debugAssertGLOk(); } void Demo::onKeyPressed(int key) From 17002580012f48ba1741fdc865166ecba7ce7e91 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Fri, 26 Oct 2018 13:28:44 -0700 Subject: [PATCH 22/33] Added dynamic cast to camera to prevent corrupted CFrame --- CameraController.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/CameraController.cpp b/CameraController.cpp index db6eec8..1d3e2ce 100644 --- a/CameraController.cpp +++ b/CameraController.cpp @@ -133,18 +133,20 @@ void CameraController::tiltDown() void CameraController::centerCamera(Instance* selection) { CoordinateFrame frame = CoordinateFrame(g3dCamera.getCoordinateFrame().translation); - if(selection == NULL) + if(PartInstance* part = dynamic_cast(selection)) { - lookAt(Vector3(0,0,0)); - focusPosition=Vector3(0,0,0); - } - else - { - Vector3 partPos = ((PartInstance*)selection)->getPosition()/2; + Vector3 partPos = (part)->getPosition()/2; lookAt(partPos); focusPosition=partPos; zoom=((partPos-frame.translation).magnitude()); } + else + { + { + lookAt(Vector3(0,0,0)); + focusPosition=Vector3(0,0,0); + } + } } void CameraController::update(Demo* demo) From d492e438d2b9b165e55c9a8799bbc45e5f5bd967 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Fri, 26 Oct 2018 13:34:55 -0700 Subject: [PATCH 23/33] Fixed camera a bit --- CameraController.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/CameraController.cpp b/CameraController.cpp index 1d3e2ce..a03649a 100644 --- a/CameraController.cpp +++ b/CameraController.cpp @@ -133,7 +133,12 @@ void CameraController::tiltDown() void CameraController::centerCamera(Instance* selection) { CoordinateFrame frame = CoordinateFrame(g3dCamera.getCoordinateFrame().translation); - if(PartInstance* part = dynamic_cast(selection)) + if(selection == NULL) + { + lookAt(Vector3(0,0,0)); + focusPosition=Vector3(0,0,0); + } + else if(PartInstance* part = dynamic_cast(selection)) { Vector3 partPos = (part)->getPosition()/2; lookAt(partPos); @@ -142,10 +147,8 @@ void CameraController::centerCamera(Instance* selection) } else { - { - lookAt(Vector3(0,0,0)); - focusPosition=Vector3(0,0,0); - } + lookAt(Vector3(0,0,0)); + focusPosition=Vector3(0,0,0); } } From f5f5f269d515f4a482902a174155056dedca5feb Mon Sep 17 00:00:00 2001 From: andreja6 Date: Fri, 26 Oct 2018 14:03:00 -0700 Subject: [PATCH 24/33] Fixed CoordinateFrame --- PartInstance.cpp | 6 +++++- main.cpp | 39 ++++++++++++++++++++------------------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/PartInstance.cpp b/PartInstance.cpp index e6366c8..a4ab474 100644 --- a/PartInstance.cpp +++ b/PartInstance.cpp @@ -380,13 +380,17 @@ void PartInstance::render(RenderDevice* rd) { } changed=false; } + //rd->setObjectToWorldMatrix(cFrame); + CoordinateFrame forDraw = rd->getObjectToWorldMatrix(); + rd->setObjectToWorldMatrix(cFrame); glVertexPointer(3, GL_FLOAT,6 * sizeof(GLfloat), &_vertices[0]); glColorPointer(3, GL_FLOAT,6 * sizeof(GLfloat), &_vertices[3]); glNormalPointer(GL_FLOAT,3 * sizeof(GLfloat), &_normals[0]); glPushMatrix(); - glTranslatef(position.x,position.y,position.z); + //glTranslatef(2,7,0); glDrawElements(GL_TRIANGLES, _indices.size(), GL_UNSIGNED_SHORT, &_indices[0]); glPopMatrix(); + rd->setObjectToWorldMatrix(forDraw); } #else void PartInstance::render(RenderDevice* rd) diff --git a/main.cpp b/main.cpp index 7e7a482..4aadd6a 100644 --- a/main.cpp +++ b/main.cpp @@ -1084,6 +1084,7 @@ void drawOutline(Vector3 from, Vector3 to, RenderDevice* rd, LightingParameters if(mode == ARROWS) { + glScalef(2,2,2); rd->setLight(0, NULL); rd->setAmbientLightColor(Color3(1,1,1)); @@ -1091,23 +1092,24 @@ void drawOutline(Vector3 from, Vector3 to, RenderDevice* rd, LightingParameters c.toWorldSpace(Box(from, to)).getBounds(box); float max = box.high().y - pos.y; - Draw::arrow(pos, Vector3(0, 1.5+max, 0), rd); - Draw::arrow(pos, Vector3(0, (-1.5)-max, 0), rd); + Draw::arrow(pos/2, Vector3(0, 1.5+max, 0), rd); + Draw::arrow(pos/2, Vector3(0, (-1.5)-max, 0), rd); max = box.high().x - pos.x; - Draw::arrow(pos, Vector3(1.5+max, 0, 0), rd); - Draw::arrow(pos, Vector3((-1.5)-max, 0, 0), rd); + Draw::arrow(pos/2, Vector3(1.5+max, 0, 0), rd); + Draw::arrow(pos/2, Vector3((-1.5)-max, 0, 0), rd); max = box.high().z - pos.z; - Draw::arrow(pos, Vector3(0, 0, 1.5+max), rd); - Draw::arrow(pos, Vector3(0, 0, (-1.5)-max), rd); + Draw::arrow(pos/2, Vector3(0, 0, 1.5+max), rd); + Draw::arrow(pos/2, Vector3(0, 0, (-1.5)-max), rd); rd->setAmbientLightColor(lighting.ambient); rd->setLight(0, GLight::directional(lighting.lightDirection, lighting.lightColor)); + glScalef(1,1,1); } else if(mode == RESIZE) { @@ -1119,24 +1121,23 @@ void drawOutline(Vector3 from, Vector3 to, RenderDevice* rd, LightingParameters 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 < 200) { - float multiplier = distance * 0.025F/2; if(multiplier < 0.25F) multiplier = 0.25F; - Vector3 position = pos + (c.lookVector()*((size.z/2)+1)); - Draw::sphere(Sphere(position, multiplier), rd, sphereColor, Color4::clear()); - position = pos - (c.lookVector()*((size.z/2)+1)); - Draw::sphere(Sphere(position, multiplier), rd, sphereColor, Color4::clear()); + Vector3 position = pos + (c.lookVector()*((size.z)+2)); + Draw::sphere(Sphere(position, multiplier*2), rd, sphereColor, Color4::clear()); + position = pos - (c.lookVector()*((size.z)+2)); + Draw::sphere(Sphere(position, multiplier*2), rd, sphereColor, Color4::clear()); - position = pos + (c.rightVector()*((size.x/2)+1)); - Draw::sphere(Sphere(position, multiplier), rd, sphereColor, Color4::clear()); - position = pos - (c.rightVector()*((size.x/2)+1)); - Draw::sphere(Sphere(position, multiplier), rd, sphereColor, Color4::clear()); + position = pos + (c.rightVector()*((size.x)+2)); + Draw::sphere(Sphere(position, multiplier*2), rd, sphereColor, Color4::clear()); + position = pos - (c.rightVector()*((size.x)+2)); + Draw::sphere(Sphere(position, multiplier*2), rd, sphereColor, Color4::clear()); - position = pos + (c.upVector()*((size.y/2)+1)); - Draw::sphere(Sphere(position, multiplier), rd, sphereColor, Color4::clear()); - position = pos - (c.upVector()*((size.y/2)+1)); - Draw::sphere(Sphere(position, multiplier), rd, sphereColor, Color4::clear()); + position = pos + (c.upVector()*((size.y)+2)); + Draw::sphere(Sphere(position, multiplier*2), rd, sphereColor, Color4::clear()); + position = pos - (c.upVector()*((size.y)+2)); + Draw::sphere(Sphere(position, multiplier*2), rd, sphereColor, Color4::clear()); } rd->setAmbientLightColor(lighting.ambient); rd->setLight(0, GLight::directional(lighting.lightDirection, lighting.lightColor)); From e83a67ade2904204fdb20d8a0ceb4416fe099e75 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Sat, 27 Oct 2018 02:24:08 -0700 Subject: [PATCH 25/33] hm --- Demo.h | 4 ++- LevelInstance.cpp | 1 + main.cpp | 67 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 70 insertions(+), 2 deletions(-) diff --git a/Demo.h b/Demo.h index e6fef08..a6968e5 100644 --- a/Demo.h +++ b/Demo.h @@ -35,6 +35,7 @@ class Demo { // : public GApp { RenderDevice* renderDevice; UserInput* userInput; PropertyWindow* _propWindow; + void generateShadowMap(const CoordinateFrame& lightViewMatrix) const; private: void initGUI(); HWND _hWndMain; @@ -47,7 +48,8 @@ class Demo { // : public GApp { HWND _hwndToolbox; HWND _buttonTest; HWND _hwndRenderer; - + G3D::TextureRef shadowMap; + double lightProjX, lightProjY, lightProjNear, lightProjFar; protected: Stopwatch m_graphicsWatch; Stopwatch m_logicWatch; diff --git a/LevelInstance.cpp b/LevelInstance.cpp index 4bab150..89f6be7 100644 --- a/LevelInstance.cpp +++ b/LevelInstance.cpp @@ -8,6 +8,7 @@ LevelInstance::LevelInstance(void) loseMessage = "You Lost. Try Again"; timer = 60.0F; score = 0; + canDelete = false; } LevelInstance::~LevelInstance(void) diff --git a/main.cpp b/main.cpp index 4aadd6a..c30e3b7 100644 --- a/main.cpp +++ b/main.cpp @@ -86,6 +86,7 @@ static const std::string PlaceholderName = "HyperCube"; Demo *usableApp = NULL; Demo::Demo(const GAppSettings& settings,HWND parentWindow) { //: GApp(settings,window) { + lightProjX = 17; lightProjY = 17; lightProjNear = 1; lightProjFar = 40; _hWndMain = parentWindow; HMODULE hThisInstance = GetModuleHandle(NULL); @@ -729,7 +730,7 @@ void Demo::onInit() { test->color = Color3(0.2F,0.3F,1); test->setSize(Vector3(24,1,24)); test->setPosition(Vector3(0,0,0)); - test->setCFrame(test->getCFrame() * Matrix3::fromEulerAnglesXYZ(0,toRadians(0),toRadians(0))); + test->setCFrame(test->getCFrame() * Matrix3::fromEulerAnglesXYZ(0,toRadians(54),toRadians(0))); @@ -1154,6 +1155,7 @@ void Demo::exitApplication() void Demo::onGraphics(RenderDevice* rd) { + G3D::uint8 num = 0; POINT mousepos; @@ -1193,6 +1195,20 @@ void Demo::onGraphics(RenderDevice* rd) { } LightingParameters lighting(G3D::toSeconds(11, 00, 00, AM)); + + Matrix4 lightProjectionMatrix(Matrix4::orthogonalProjection(-lightProjX, lightProjX, -lightProjY, lightProjY, lightProjNear, lightProjFar)); + + CoordinateFrame lightCFrame; + lightCFrame.lookAt(-lighting.lightDirection, Vector3::unitY()); + lightCFrame.translation = lighting.lightDirection * 20; + + Matrix4 lightMVP = lightProjectionMatrix * lightCFrame.inverse(); + + if (GLCaps::supports_GL_ARB_shadow()) { + generateShadowMap(lightCFrame); + } + + renderDevice->setProjectionAndCameraMatrix(*cameraController.getCamera()); // Cyan background @@ -1224,6 +1240,16 @@ void Demo::onGraphics(RenderDevice* rd) { fntdominant->draw3D(rd, "Testing", CoordinateFrame(rd->getCameraToWorldMatrix().rotation, gamepoint), 0.04*distance, Color3::yellow(), Color3::black(), G3D::GFont::XALIGN_CENTER, G3D::GFont::YALIGN_CENTER); } */ + + rd->setAmbientLightColor(Color3::black()); + rd->setDepthTest(RenderDevice::DEPTH_LEQUAL); + rd->disableDepthWrite(); + rd->setLight(0, GLight::directional(lighting.lightDirection, lighting.lightColor)); + + rd->setBlendFunc(RenderDevice::BLEND_ONE, RenderDevice::BLEND_ONE); + if (GLCaps::supports_GL_ARB_shadow()) { + rd->configureShadowMap(1, lightMVP, shadowMap); + } rd->beforePrimitive(); @@ -1622,6 +1648,37 @@ LRESULT CALLBACK G3DProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) return 0; } + +void Demo::generateShadowMap(const CoordinateFrame& lightViewMatrix) const { + + + //debugAssert(shadowMapSize < app->renderDevice->getHeight()); + //debugAssert(shadowMapSize < app->renderDevice->getWidth()); + + //app->renderDevice->clear(debugLightMap, true, false); + + Rect2D rect = Rect2D::xywh(0, 0, 512, 512); + renderDevice->pushState(); + renderDevice->setViewport(rect); + + // Draw from the light's point of view + renderDevice->setProjectionMatrix(Matrix4::orthogonalProjection(-lightProjX, lightProjX, -lightProjY, lightProjY, lightProjNear, lightProjFar)); + renderDevice->setCameraToWorldMatrix(lightViewMatrix); + + renderDevice->disableColorWrite(); + + // We can choose to use a large bias or render from + // the backfaces in order to avoid front-face self + // shadowing. Here, we use a large offset. + renderDevice->setPolygonOffset(8); + + dataModel->render(renderDevice); + renderDevice->popState(); + + shadowMap->copyFromScreen(rect); +} + + void Demo::run() { usableApp = this; //setDebugMode(false); @@ -1653,6 +1710,14 @@ void Demo::run() { clickSound = GetFileInPath("/content/sounds/switch.wav"); dingSound = GetFileInPath("/content/sounds/electronicpingshort.wav"); sky = Sky::create(NULL, ExePath() + "/content/sky/"); + + + if (GLCaps::supports_GL_ARB_shadow()) { + shadowMap = Texture::createEmpty(512, 512, "Shadow map", TextureFormat::depth(), + Texture::CLAMP, Texture::BILINEAR_NO_MIPMAP, Texture::DIM_2D, Texture::DEPTH_LEQUAL); + } + + cursorid = cursor->openGLID(); currentcursorid = cursorid; cursorOvrid = cursorOvr->openGLID(); From 948835df9898cede5e3b4dfb59bef401c66fc61d Mon Sep 17 00:00:00 2001 From: andreja6 Date: Fri, 26 Oct 2018 19:43:46 -0700 Subject: [PATCH 26/33] Shadows work (?) --- main.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/main.cpp b/main.cpp index c30e3b7..f4bec41 100644 --- a/main.cpp +++ b/main.cpp @@ -1240,13 +1240,8 @@ void Demo::onGraphics(RenderDevice* rd) { fntdominant->draw3D(rd, "Testing", CoordinateFrame(rd->getCameraToWorldMatrix().rotation, gamepoint), 0.04*distance, Color3::yellow(), Color3::black(), G3D::GFont::XALIGN_CENTER, G3D::GFont::YALIGN_CENTER); } */ - - rd->setAmbientLightColor(Color3::black()); - rd->setDepthTest(RenderDevice::DEPTH_LEQUAL); - rd->disableDepthWrite(); - rd->setLight(0, GLight::directional(lighting.lightDirection, lighting.lightColor)); - - rd->setBlendFunc(RenderDevice::BLEND_ONE, RenderDevice::BLEND_ONE); + + rd->pushState(); if (GLCaps::supports_GL_ARB_shadow()) { rd->configureShadowMap(1, lightMVP, shadowMap); } @@ -1258,7 +1253,7 @@ void Demo::onGraphics(RenderDevice* rd) { //((PartInstance*)dataModel->children[0]->children[0])->debugPrintVertexIDs(rd,fntdominant,-cameraController.getCoordinateFrame().rotation); rd->afterPrimitive(); - + rd->popState(); if(g_selectedInstances.size() > 0) { for(size_t i = 0; i < g_selectedInstances.size(); i++) From 61d07a8557b9aec9f5e492b34ebdcc277b3377ef Mon Sep 17 00:00:00 2001 From: andreja6 Date: Sat, 27 Oct 2018 09:00:39 -0700 Subject: [PATCH 27/33] "Drag" --- main.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/main.cpp b/main.cpp index f4bec41..43ba8f6 100644 --- a/main.cpp +++ b/main.cpp @@ -79,7 +79,8 @@ static const int RESIZE = 2; static POINT oldGlobalMouse; static int mode = CURSOR; bool dragging = false; -Vector2 oldMouse = Vector2(0,0); +#include +Vector2 mouseDownOn = Vector2(nan(), 0); float moveRate = 0.5; static const std::string PlaceholderName = "HyperCube"; @@ -967,6 +968,17 @@ void Demo::onUserInput(UserInput* ui) { dataModel->mouseButton1Down = (GetKeyState(VK_LBUTTON) & 0x100) != 0; if (GetHoldKeyState(VK_LBUTTON)) { + if(!G3D::isNaN(mouseDownOn.x)) + { + if(abs(mouseDownOn.x - dataModel->mousex) > 4 || abs(mouseDownOn.y - dataModel->mousey) > 4) + { + dragging = true; + } + } + else + { + mouseDownOn = Vector2(dataModel->mousex, dataModel->mousey); + } if (dragging) { PartInstance* part = NULL; if(g_selectedInstances.size() > 0) @@ -983,7 +995,7 @@ void Demo::onUserInput(UserInput* ui) { { if (__nearest>__time) { - Vector3 closest = (dragRay.closestPoint(moveTo->getPosition()) * 2); + Vector3 closest = (dragRay.closestPoint(moveTo->getPosition())); part->setPosition(closest); //part->setPosition(Vector3(floor(closest.x),part->getPosition().y,floor(closest.z))); } @@ -993,6 +1005,11 @@ void Demo::onUserInput(UserInput* ui) { Sleep(10); } } + else + { + dragging = false; + mouseDownOn = Vector2(nan(), 0); + } // Camera KB Handling { if (GetKPBool(VK_OEM_COMMA)) //Left usableApp->cameraController.panLeft(); @@ -1483,7 +1500,7 @@ void Demo::onMouseRightUp(int x,int y) } void Demo::onMouseMoved(int x,int y) { - oldMouse = dataModel->getMousePos(); + //oldMouse = dataModel->getMousePos(); dataModel->mousex = x; dataModel->mousey = y; From 89f9e0bfa2228252cd11b05cbd8ce009a79b1bb9 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Sat, 27 Oct 2018 11:21:09 -0700 Subject: [PATCH 28/33] Moving works-ish, fixed box selection --- TextButtonInstance.cpp | 6 ++++++ main.cpp | 31 +++++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/TextButtonInstance.cpp b/TextButtonInstance.cpp index 5b74ecc..3ac8ec9 100644 --- a/TextButtonInstance.cpp +++ b/TextButtonInstance.cpp @@ -21,6 +21,7 @@ TextButtonInstance::TextButtonInstance(void) visible = true; className = "TextButton"; disabled = false; + selected = false; } bool TextButtonInstance::mouseInButton(float mousex, float mousey, RenderDevice* rd) @@ -102,6 +103,11 @@ void TextButtonInstance::drawObj(RenderDevice* rd, Vector2 mousePos, bool mouseD Draw::box(Box(point1, point2), rd, boxColorOvr, boxOutlineColorOvr); font->draw2D(rd, title, RelativeTo, textSize, textColorOvr, textOutlineColorOvr); } + else if(selected) + { + Draw::box(Box(point1, point2), rd, boxColorOvr, boxOutlineColorOvr); + font->draw2D(rd, title, RelativeTo, textSize, textColorOvr, textOutlineColorOvr); + } else { Draw::box(Box(point1, point2), rd, boxColor, boxOutlineColor); diff --git a/main.cpp b/main.cpp index 43ba8f6..59cc03e 100644 --- a/main.cpp +++ b/main.cpp @@ -390,6 +390,7 @@ void Demo::initGUI() button->title = "Hopper"; button->fontLocationRelativeTo = Vector2(10, 3); button->setAllColorsSame(); + button->boxOutlineColorOvr = Color3(0,255,255); button = makeTextButton(); button->boxBegin = Vector2(0, -48); @@ -402,6 +403,7 @@ void Demo::initGUI() button->title = "Controller"; button->fontLocationRelativeTo = Vector2(10, 3); button->setAllColorsSame(); + button->boxOutlineColorOvr = Color3(0,255,255); button = makeTextButton(); button->boxBegin = Vector2(0, -72); @@ -414,6 +416,7 @@ void Demo::initGUI() button->title = "Color"; button->fontLocationRelativeTo = Vector2(10, 3); button->setAllColorsSame(); + button->boxOutlineColorOvr = Color3(0,255,255); button = makeTextButton(); button->boxBegin = Vector2(0, -96); @@ -426,6 +429,7 @@ void Demo::initGUI() button->title = "Surface"; button->fontLocationRelativeTo = Vector2(10, 3); button->setAllColorsSame(); + button->boxOutlineColorOvr = Color3(0,255,255); button = makeTextButton(); button->boxBegin = Vector2(0, -120); @@ -434,10 +438,10 @@ void Demo::initGUI() button->setParent(dataModel->getGuiRoot()); button->font = fntlighttrek; button->textColor = Color3(0,255,255); - button->boxOutlineColor = Color3(0,255,255); button->title = "Model"; button->fontLocationRelativeTo = Vector2(10, 3); button->setAllColorsSame(); + button->boxOutlineColorOvr = Color3(0,255,255); button = makeTextButton(); button->boxBegin = Vector2(0, 0); @@ -451,6 +455,7 @@ void Demo::initGUI() button->textSize = 16; button->fontLocationRelativeTo = Vector2(10, 0); button->setAllColorsSame(); + button->boxColorOvr = Color4(0.6F,0.6F,0.6F,0.4F); button = makeTextButton(); button->boxBegin = Vector2(125, 0); @@ -464,6 +469,7 @@ void Demo::initGUI() button->textSize = 16; button->fontLocationRelativeTo = Vector2(10, 0); button->setAllColorsSame(); + button->boxColorOvr = Color4(0.6F,0.6F,0.6F,0.4F); button = makeTextButton(); button->boxBegin = Vector2(250, 0); @@ -477,6 +483,7 @@ void Demo::initGUI() button->textSize = 16; button->fontLocationRelativeTo = Vector2(10, 0); button->setAllColorsSame(); + button->boxColorOvr = Color4(0.6F,0.6F,0.6F,0.4F); button = makeTextButton(); button->boxBegin = Vector2(375, 0); @@ -490,6 +497,7 @@ void Demo::initGUI() button->textSize = 16; button->fontLocationRelativeTo = Vector2(10, 0); button->setAllColorsSame(); + button->boxColorOvr = Color4(0.6F,0.6F,0.6F,0.4F); button = makeTextButton(); button->boxBegin = Vector2(500, 0); @@ -503,6 +511,7 @@ void Demo::initGUI() button->textSize = 16; button->fontLocationRelativeTo = Vector2(10, 0); button->setAllColorsSame(); + button->boxColorOvr = Color4(0.6F,0.6F,0.6F,0.4F); @@ -991,13 +1000,13 @@ void Demo::onUserInput(UserInput* ui) { { float __time = testRay.intersectionTime(moveTo->getBox()); float __nearest=std::numeric_limits::infinity(); - if (__time != inf()) + if (__time != inf() && moveTo != part) { if (__nearest>__time) { Vector3 closest = (dragRay.closestPoint(moveTo->getPosition())); - part->setPosition(closest); - //part->setPosition(Vector3(floor(closest.x),part->getPosition().y,floor(closest.z))); + //part->setPosition(closest); + part->setPosition(Vector3(floor(closest.x),floor(closest.y),floor(closest.z))); } } } @@ -1346,6 +1355,20 @@ void Demo::onGraphics(RenderDevice* rd) { std::vector instances = dataModel->getWorkspace()->getAllChildren(); currentcursorid = cursorid; + bool onGUI = false; + std::vector guis = dataModel->getGuiRoot()->getAllChildren(); + for(size_t i = 0; i < guis.size(); i++) + { + if(BaseButtonInstance* button = dynamic_cast(guis.at(i))) + { + if(button->mouseInButton(dataModel->mousex,dataModel->mousey, renderDevice)) + { + onGUI = true; + break; + } + } + } + if(!onGUI) for(size_t i = 0; i < instances.size(); i++) { if(PartInstance* test = dynamic_cast(instances.at(i))) From 057d86e05a36af7f7203fed91601f1a2794259ca Mon Sep 17 00:00:00 2001 From: MusicalProgrammer <38636805+MusicalProgrammer@users.noreply.github.com> Date: Sat, 27 Oct 2018 19:32:28 -0400 Subject: [PATCH 29/33] Using new part dragging code... (Needs adjusting) --- main.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/main.cpp b/main.cpp index 59cc03e..1b9046f 100644 --- a/main.cpp +++ b/main.cpp @@ -994,10 +994,22 @@ void Demo::onUserInput(UserInput* ui) { part = (PartInstance*) g_selectedInstances.at(0); Ray dragRay = cameraController.getCamera()->worldRay(dataModel->mousex, dataModel->mousey, renderDevice->getViewport()); std::vector instances = dataModel->getWorkspace()->getAllChildren(); + for(size_t i = 0; i < instances.size(); i++) { if(PartInstance* moveTo = dynamic_cast(instances.at(i))) { + Vector3 outLocation=Vector3(0,0,0); + Vector3 outNormal=Vector3(0,0,0); + + if (moveTo!=part) { + if (CollisionDetection::collisionTimeForMovingPointFixedBox(dragRay.origin,dragRay.direction*100,moveTo->getBox(),outLocation,outNormal)!=inf()) + { + part->setPosition(Vector3(floor(outLocation.x),floor(outLocation.y+1),floor(outLocation.z))); + break; + } + } + /* float __time = testRay.intersectionTime(moveTo->getBox()); float __nearest=std::numeric_limits::infinity(); if (__time != inf() && moveTo != part) @@ -1009,6 +1021,7 @@ void Demo::onUserInput(UserInput* ui) { part->setPosition(Vector3(floor(closest.x),floor(closest.y),floor(closest.z))); } } + */ } } Sleep(10); From 98e73cd7ca59b1ae3598833a47f780d6a0f658b3 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Sat, 27 Oct 2018 19:40:41 -0700 Subject: [PATCH 30/33] Kinda sorta works --- main.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/main.cpp b/main.cpp index 1b9046f..b111b26 100644 --- a/main.cpp +++ b/main.cpp @@ -992,12 +992,46 @@ void Demo::onUserInput(UserInput* ui) { 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()); - std::vector instances = dataModel->getWorkspace()->getAllChildren(); - - for(size_t i = 0; i < instances.size(); i++) + Ray dragRay = cameraController.getCamera()->worldRay(dataModel->mousex, dataModel->mousey, renderDevice->getViewport()); + std::vector instances = dataModel->getWorkspace()->getAllChildren(); + PartInstance* moveTo; + for(size_t i = 0; i < instances.size(); i++) { - if(PartInstance* moveTo = dynamic_cast(instances.at(i))) + + } + + + + + + + float nearest=std::numeric_limits::infinity(); + Vector3 camPos = cameraController.getCamera()->getCoordinateFrame().translation; + for(size_t i = 0; i < instances.size(); i++) + { + if(PartInstance* test = dynamic_cast(instances.at(i))) + { + float time = dragRay.intersectionTime(test->getBox()); + + if (time != inf()) + { + if (nearest>time && test != part) + { + nearest=time; + moveTo = test; + //message = "Dragging = true."; + //messageTime = System::time(); + //dragging = true; + } + } + } + } + + + + + + if(moveTo != NULL) { Vector3 outLocation=Vector3(0,0,0); Vector3 outNormal=Vector3(0,0,0); @@ -1006,7 +1040,7 @@ void Demo::onUserInput(UserInput* ui) { if (CollisionDetection::collisionTimeForMovingPointFixedBox(dragRay.origin,dragRay.direction*100,moveTo->getBox(),outLocation,outNormal)!=inf()) { part->setPosition(Vector3(floor(outLocation.x),floor(outLocation.y+1),floor(outLocation.z))); - break; + //break; } } /* @@ -1023,8 +1057,9 @@ void Demo::onUserInput(UserInput* ui) { } */ } - } - Sleep(10); + + + Sleep(10); } } else From 1dd930af49c05d5e8d806abbe9e14be9231ca1de Mon Sep 17 00:00:00 2001 From: andreja6 Date: Sat, 27 Oct 2018 20:32:48 -0700 Subject: [PATCH 31/33] fixed crashing --- main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index b111b26..8831c80 100644 --- a/main.cpp +++ b/main.cpp @@ -1031,7 +1031,7 @@ void Demo::onUserInput(UserInput* ui) { - if(moveTo != NULL) + if(nearest != inf()) { Vector3 outLocation=Vector3(0,0,0); Vector3 outNormal=Vector3(0,0,0); From 2919f4ebaac0d5a2045e6c12d8c1069c7a16d188 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Sat, 27 Oct 2018 20:38:33 -0700 Subject: [PATCH 32/33] Disabled shadows --- main.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.cpp b/main.cpp index 8831c80..f3bf781 100644 --- a/main.cpp +++ b/main.cpp @@ -1278,9 +1278,9 @@ void Demo::onGraphics(RenderDevice* rd) { Matrix4 lightMVP = lightProjectionMatrix * lightCFrame.inverse(); - if (GLCaps::supports_GL_ARB_shadow()) { + /*if (GLCaps::supports_GL_ARB_shadow()) { generateShadowMap(lightCFrame); - } + } */ renderDevice->setProjectionAndCameraMatrix(*cameraController.getCamera()); @@ -1316,9 +1316,9 @@ void Demo::onGraphics(RenderDevice* rd) { */ rd->pushState(); - if (GLCaps::supports_GL_ARB_shadow()) { + /*if (GLCaps::supports_GL_ARB_shadow()) { rd->configureShadowMap(1, lightMVP, shadowMap); - } + }*/ rd->beforePrimitive(); From ab242470b69a824dca356ede6245d5a37d49842a Mon Sep 17 00:00:00 2001 From: andreja6 Date: Sat, 27 Oct 2018 21:14:24 -0700 Subject: [PATCH 33/33] Added tilt and rotate to drag, made drag a bit cleaner --- PartInstance.cpp | 2 +- content/images/GrabRotateCursor.png | Bin 0 -> 2893 bytes main.cpp | 111 ++++++++++++++++++++++------ 3 files changed, 89 insertions(+), 24 deletions(-) create mode 100644 content/images/GrabRotateCursor.png diff --git a/PartInstance.cpp b/PartInstance.cpp index a4ab474..b6f09e1 100644 --- a/PartInstance.cpp +++ b/PartInstance.cpp @@ -129,7 +129,7 @@ Vector3 PartInstance::getPosition() void PartInstance::setPosition(Vector3 pos) { position = pos; - cFrame = CoordinateFrame(pos); + cFrame = CoordinateFrame(cFrame.rotation,pos); changed = true; } CoordinateFrame PartInstance::getCFrame() diff --git a/content/images/GrabRotateCursor.png b/content/images/GrabRotateCursor.png new file mode 100644 index 0000000000000000000000000000000000000000..0cd0c1375a92495955fcd1608d78b0be5fe3d1b4 GIT binary patch literal 2893 zcmV-T3$pZyP)WdKxlWgsy)AWvg-ATls8H6SrEIx{jlGc_PBFgP$UA|Bi$00007bV*G` z2i5@t7Bn(UFs^w3000SaNLh0L01FWS01FWTe`H^g00004XF*Lt006O%3;baP000W4 zNkl7+l#gs3mibpSb z2y(GB#)nP$5Gz$YW-UmmNYt1`K~W0@AsCg5C<+L;j@%h$xDAu<^w91&PBVZrOpEP@q780tE^bC{Un4fdT~z z+y#}V8!#PYXJ`M?VzDfPsVSL4pM zX*^Ai6i%Et;b$_LBAF<&*}N2=U-tC$tOyJYj8m)C+E=e$sf|V>#l*x=Vqzk7cXv~5 zZ7nTXvLt-#)~!C+4+sef8G{-JacvvS=#F-Jd73CGtX;cy9#ppmn@O-mu=w`&_PBeZ{)KyCg|U?9{O0rw0W8ygGcb82d8=+UD`g7Vg{Ur#Gmte`7b zu26GxGm|;8XU`rzu4%k*;X*@UVPOYcyd0NZcXeB3r$EHJ1t4bQ;NakT?EV5SnzR52 z3kwU0ii+}Kmt~8NjuupR>((toOr-Gea7s>2CcR$I0g*R^87>w8#g3f|YpFZ7_pPyfg!&R_R@f>6` zpR>V57a~^rGI2RMIW#mhL>o42cyljwL>k1+=(xBzAG{PZUc~1({1R3=X9;wG4%k0o zgW>^n7Eh|Gs=CwD(|?CuUuQRfN<%n*^zrc-aAm_j6avjK6WQc)=wS!pjzbukSf+Rn zH3;-lagXCds6EY$6u5^)B238V%!p$?=rj^=IA|)@qW2}FL4@lFE>3W9TC`}9TiPjG z1qKBL2?XrgwQC5Sg6`zWlRI$u60F+Uwe#l9qhrU8kxr*$*A>zmB-KKW=xWH7z+rSE z!&#Px1z zsO$(th~g1MGkVhnP)`EXHy`PYHgqE0_4O?l&xO)rL9_-$v#WCsDUdarkRyRN zu3x{dS-Enh842`nu&)M@Iw&z6%K8+2hFLt9$peBoq2`eY$IaP>>^hOm%uGW|OG~f8 zVCVx`-1ClsL=DIZfJ^G2wg}O1ER=gzCXQ7ILKOlhU_kQwBgVte@afXL&DD@4fk;_u z(PLh@bm`Lfhd90S=2?X-31lF)jUop2 zfxr%=FR#ct4j%V(yX+xb0?}b~qH`##sHiw!UteErHk*5Kc+Au7vWM)_7!gQ{S#iBN zIXTsciE8A7TI7A7VLOqmvvIPhrps1=B9PX!R99EuI&z;$z4R=xN)Oz*|KGw4<0-i zz_2bfI5;>OqYvMS=Ws|O5^+gwKHK|IEzza{IE3bz5j(~A*GIohS^ z@9#IIq@-+yBBSt?*3tQ0U0rnK$PuWR=hlA>wQA-=v^-&tI6Bry)SOIo^#Jz&0ed*z z_DCu)A|fJ-$wL|;6gEY&@YV&3ii#4Z7I})1_n``&PCVP*-u}p)1YW&*bsS1GLWxGS zhh16=0{yWaLRJ;NQ6jtTnKS30zDM-@IeY3Nd=~`81wyrfAelqk(W6JLH_>Q#_DhI2vk7=bKhm1J4Gj&Nfq{WxbTS)pEav6Q zm)hLiTq-Hy0nFF1a3^yK(`6T)|~!A$@Rq6F!H}oviB1lRu6obfk_? z1&0qG<{x|wC00ZI7M)I~h3BMIRyM}}@I!ELYb(2Ju+-(8M|Msa#@UhRiK9DQPM~d# zjn|%tU>D}t$KZ492^43`m>h9iY6i{r+?f!GPNEgw(Es@H<1uu6ef9O;Yl-p^=lZ>^ z%V9>yt`@=Mae;y-*LjZEWZlkuG2P#mOr)6%dzWMv=G9Q|yal*0pDUg(s!AkJBt~Te zd%|pqo(a&I8Q=+(9UUDuD-ICW=vQQ2gZUO%b^n8Lr%?wx2|s!~li!t8AS;UFnj=x{ z+qdtn80biWQgEiinF4L%x2K;VWdb^~&bf2P%KWr*p4UxQ)p3AC#-O?d4bONHrc(l^ zQYPn;x~&2yBTrPFJz*}M@aB7uTg?v-@D&q@W3S-L<|cg2MDr@GLXhWlnshQu>caet z$g_m~b?er>^*zTxn};X#f^P^E-O*78As%-`?)$3nCyc-qMmTfs`svt0$Z%6LoSkzm zcHh6^@!z}JEvZ1BoHiH?LK?&Q9j7&{#-5%Y;geOzv5)yd@=O?CzSU#f6DOrGS1+{y zK+0$tQ7MLLDl|x38W#ov0}%V#ptzT}kx5p$;>RQ#f9=|}+RV&MVFf6Y$LeBL@-`c9 zi#;_HnU=!ETK_Q3vx{r7TPw}FcZo^HbgxYF_& z(YL=R`pch*T40txz`lg(T=_#ETrpva;Jof0Q4xk_|3xhP0=w}TqNy5O{X>!j78Mmy zeSJOgpH_I;1jjvgRUXFi*q9gY@B$$2WK1TLusXD{u~8OPVjDDLRNrhR&^?%OF@eE( zpr?una>0~~37p38HV@}Gk>=G;;!w`Em>{Mu_Me`9P6C??oteEi5O{P&ym}_uKpeu?AA8ib@EhdO?R1dT*CfLV4 z+xp*JgxiV<9}6T2+`oT+omfm@0;gC^7|h7X@bojyDkKSvkB>jc|HEx+YNFQGR)Hi| rnEfXkt1>k;mH#=Z_w)lP_`vXg=zJ0o91R?H00000NkvXXu0mjf-^O45 literal 0 HcmV?d00001 diff --git a/main.cpp b/main.cpp index f3bf781..67c794b 100644 --- a/main.cpp +++ b/main.cpp @@ -69,9 +69,11 @@ static std::string clickSound = ""; static std::string dingSound = ""; static int cursorid = 0; static int cursorOvrid = 0; +static int cursorDragid = 0; static int currentcursorid = 0; static G3D::TextureRef cursor = NULL; static G3D::TextureRef cursorOvr = NULL; +static G3D::TextureRef cursorDrag = NULL; static bool mouseMovedBeginMotion = false; static const int CURSOR = 0; static const int ARROWS = 1; @@ -740,7 +742,7 @@ void Demo::onInit() { test->color = Color3(0.2F,0.3F,1); test->setSize(Vector3(24,1,24)); test->setPosition(Vector3(0,0,0)); - test->setCFrame(test->getCFrame() * Matrix3::fromEulerAnglesXYZ(0,toRadians(54),toRadians(0))); + //test->setCFrame(test->getCFrame() * Matrix3::fromEulerAnglesXYZ(0,toRadians(54),toRadians(0))); @@ -1403,33 +1405,40 @@ void Demo::onGraphics(RenderDevice* rd) { std::vector instances = dataModel->getWorkspace()->getAllChildren(); currentcursorid = cursorid; - bool onGUI = false; - std::vector guis = dataModel->getGuiRoot()->getAllChildren(); - for(size_t i = 0; i < guis.size(); i++) + if(!dragging) { - if(BaseButtonInstance* button = dynamic_cast(guis.at(i))) + bool onGUI = false; + std::vector guis = dataModel->getGuiRoot()->getAllChildren(); + for(size_t i = 0; i < guis.size(); i++) { - if(button->mouseInButton(dataModel->mousex,dataModel->mousey, renderDevice)) + if(BaseButtonInstance* button = dynamic_cast(guis.at(i))) { - onGUI = true; - break; + if(button->mouseInButton(dataModel->mousex,dataModel->mousey, renderDevice)) + { + onGUI = true; + break; + } + } + } + if(!onGUI) + for(size_t i = 0; i < instances.size(); i++) + { + if(PartInstance* test = dynamic_cast(instances.at(i))) + { + float time = cameraController.getCamera()->worldRay(dataModel->mousex, dataModel->mousey, renderDevice->getViewport()).intersectionTime(test->getBox()); + //float time = testRay.intersectionTime(test->getBox()); + if (time != inf()) + { + currentcursorid = cursorOvrid; + break; + } + } } } - if(!onGUI) - for(size_t i = 0; i < instances.size(); i++) + else { - if(PartInstance* test = dynamic_cast(instances.at(i))) - { - float time = cameraController.getCamera()->worldRay(dataModel->mousex, dataModel->mousey, renderDevice->getViewport()).intersectionTime(test->getBox()); - //float time = testRay.intersectionTime(test->getBox()); - if (time != inf()) - { - currentcursorid = cursorOvrid; - break; - } - - } + currentcursorid = cursorDragid; } glBindTexture( GL_TEXTURE_2D, currentcursorid); @@ -1461,6 +1470,60 @@ void Demo::onKeyPressed(int key) { deleteInstance(); } + if(dragging) + { + if(key == 'T') + { + if(g_selectedInstances.size() > 0) + { + Instance* selectedInstance = g_selectedInstances.at(0); + AudioPlayer::playSound(clickSound); + if(PartInstance* part = dynamic_cast(selectedInstance)) + { + part->setCFrame(part->getCFrame()*Matrix3::fromEulerAnglesXYZ(0,0,toRadians(90))); + } + } + } + if(key == 'R') + { + if(g_selectedInstances.size() > 0) + { + Instance* selectedInstance = g_selectedInstances.at(0); + AudioPlayer::playSound(clickSound); + if(PartInstance* part = dynamic_cast(selectedInstance)) + { + part->setCFrame(part->getCFrame()*Matrix3::fromEulerAnglesXYZ(0,toRadians(90),0)); + } + } + } + } + if(GetHoldKeyState(VK_LCONTROL)) + { + if(key == 'D') + { + if(g_selectedInstances.size() > 0) + { + AudioPlayer::playSound(dingSound); + std::vector newinst; + for(size_t i = 0; i < g_selectedInstances.size(); i++) + { + if(g_selectedInstances.at(i)->canDelete) + { + Instance* tempinst = g_selectedInstances.at(i); + + Instance* clonedInstance = g_selectedInstances.at(i)->clone(); + + newinst.push_back(tempinst); + } + /*tempinst->setPosition(Vector3(tempPos.x, tempPos.y + tempSize.y, tempPos.z)); + usableApp->cameraController.centerCamera(g_selectedInstances.at(0));*/ + } + g_selectedInstances = newinst; + if(g_selectedInstances.size() > 0) + usableApp->_propWindow->SetProperties(newinst.at(0)); + } + } + } } void Demo::onKeyUp(int key) { @@ -1785,6 +1848,7 @@ void Demo::run() { // Load objects here= cursor = Texture::fromFile(GetFileInPath("/content/images/ArrowCursor.png")); cursorOvr = Texture::fromFile(GetFileInPath("/content/images/DragCursor.png")); + cursorDrag = Texture::fromFile(GetFileInPath("/content/images/GrabRotateCursor.png")); Globals::surface = Texture::fromFile(GetFileInPath("/content/images/surfacebr.png")); Globals::surfaceId = Globals::surface->getOpenGLID(); fntdominant = GFont::fromFile(GetFileInPath("/content/font/dominant.fnt")); @@ -1795,14 +1859,15 @@ void Demo::run() { sky = Sky::create(NULL, ExePath() + "/content/sky/"); - if (GLCaps::supports_GL_ARB_shadow()) { + /*if (GLCaps::supports_GL_ARB_shadow()) { shadowMap = Texture::createEmpty(512, 512, "Shadow map", TextureFormat::depth(), Texture::CLAMP, Texture::BILINEAR_NO_MIPMAP, Texture::DIM_2D, Texture::DEPTH_LEQUAL); - } + }*/ cursorid = cursor->openGLID(); currentcursorid = cursorid; + cursorDragid = cursorDrag->openGLID(); cursorOvrid = cursorOvr->openGLID(); RealTime now=0, lastTime=0; double simTimeRate = 1.0f;