From 9986f2ee5f172b6068198b302e7b47a0bbd0061d Mon Sep 17 00:00:00 2001 From: andreja6 Date: Mon, 30 Apr 2018 21:43:02 -0700 Subject: [PATCH 1/9] Made class name getter, can not be set outside of class --- Instance.cpp | 10 ++++++++-- Instance.h | 3 +++ main.cpp | 12 ++++++------ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Instance.cpp b/Instance.cpp index b981f8b..4d72d43 100644 --- a/Instance.cpp +++ b/Instance.cpp @@ -4,12 +4,13 @@ std::string name; Instance* parent; -static std::string className = "DataModel"; +std::vector children; +static std::string className = "BaseInstance"; Instance::Instance(void) { name = "Default Game Instance"; - className = "DataModel"; + className = "BaseInstance"; } Instance::~Instance(void) @@ -17,6 +18,11 @@ Instance::~Instance(void) name = "Default Game Instance"; } +std::string Instance::getClassName() +{ + return className; +} + diff --git a/Instance.h b/Instance.h index 8a58954..b718a3e 100644 --- a/Instance.h +++ b/Instance.h @@ -8,5 +8,8 @@ public: virtual ~Instance(void); std::string name; Instance* parent; // Another pointer. + std::vector children; // All children. + std::string getClassName(); +protected: std::string className; }; diff --git a/main.cpp b/main.cpp index 2d4f3e2..3e5c58a 100644 --- a/main.cpp +++ b/main.cpp @@ -299,7 +299,7 @@ void RotateButtonListener::onButton1MouseClick(BaseButtonInstance* button) if(selectedInstance != NULL) { AudioPlayer::PlaySound(clickSound); - if(selectedInstance->className == "Part") + if(selectedInstance->getClassName() == "Part") { PhysicalInstance* part = (PhysicalInstance*) selectedInstance; if(button->name == "Tilt") @@ -1122,7 +1122,7 @@ void Demo::onUserInput(UserInput* ui) { bool onGUI = false; for(size_t i = 0; i < instances_2D.size(); i++) { - if(instances_2D.at(i)->className == "TextButton" || instances_2D.at(i)->className == "ImageButton") + if(instances_2D.at(i)->getClassName() == "TextButton" || instances_2D.at(i)->getClassName() == "ImageButton") { BaseButtonInstance* button = (BaseButtonInstance*)instances_2D.at(i); if(button->mouseInButton(ui->mouseXY().x, ui->mouseXY().y, app->renderDevice)) @@ -1140,7 +1140,7 @@ void Demo::onUserInput(UserInput* ui) { Vector3 camPos = app->debugCamera.getCoordinateFrame().translation; for(size_t i = 0; i < instances.size(); i++) { - if(instances.at(i)->className == "Part" && instances.at(i)->parent == dataModel) + if(instances.at(i)->getClassName() == "Part" && instances.at(i)->parent == dataModel) { PhysicalInstance* test = (PhysicalInstance*)instances.at(i); float time = testRay.intersectionTime(test->getBox()); @@ -1167,7 +1167,7 @@ void Demo::onUserInput(UserInput* ui) { for(size_t i = 0; i < instances_2D.size(); i++) { - if(instances_2D.at(i)->className == "TextButton" || instances_2D.at(i)->className == "ImageButton") + if(instances_2D.at(i)->getClassName() == "TextButton" || instances_2D.at(i)->getClassName() == "ImageButton") { BaseButtonInstance* button = (BaseButtonInstance*)instances_2D.at(i); if(button->mouseInButton(ui->mouseXY().x, ui->mouseXY().y, app->renderDevice)) @@ -1237,7 +1237,7 @@ void drawButtons(RenderDevice* rd) for(size_t i = 0; i < instances_2D.size(); i++) { Instance* instance = instances_2D.at(i); - if((instance->className == "TextButton" || instance->className == "ImageButton") && instance->parent == dataModel) + if((instance->getClassName() == "TextButton" || instance->getClassName() == "ImageButton") && instance->parent == dataModel) { BaseButtonInstance* tbi = (BaseButtonInstance*)instance; tbi->drawObj(rd, Vector2(mousex, mousey), mouseButton1Down); @@ -1451,7 +1451,7 @@ void Demo::onGraphics(RenderDevice* rd) { for(size_t i = 0; i < instances.size(); i++) { Instance* instance = instances.at(i); - if(instance->className == "Part" && instance->parent != NULL) + if(instance->getClassName() == "Part" && instance->parent != NULL) { PhysicalInstance* part = (PhysicalInstance*)instance; From 388962a5e7b126d33baf88706c9a4738dd775c9e Mon Sep 17 00:00:00 2001 From: andreja6 Date: Tue, 1 May 2018 11:33:24 -0700 Subject: [PATCH 2/9] Finished base for new datamodel --- Instance.cpp | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++- Instance.h | 7 ++++++ 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/Instance.cpp b/Instance.cpp index 4d72d43..1d3fe47 100644 --- a/Instance.cpp +++ b/Instance.cpp @@ -15,7 +15,10 @@ Instance::Instance(void) Instance::~Instance(void) { - name = "Default Game Instance"; + for(size_t i = 0; i < children.size(); i++) + { + delete children.at(i); + } } std::string Instance::getClassName() @@ -23,6 +26,66 @@ std::string Instance::getClassName() return className; } +std::vector Instance::getChildren() +{ + return children; +} +std::vector Instance::getAllChildren() +{ + std::vector totalchildren = children; + for(size_t i = 0; i < children.size(); i++) + { + std::vector subchildren = children.at(i)->getAllChildren(); + totalchildren.insert(totalchildren.end(), subchildren.begin(), subchildren.end()); + } + return totalchildren; +} +void Instance::setParent(Instance* newParent) +{ + if(parent != NULL) + { + parent->removeChild(this); + } + parent = newParent; + if(newParent != NULL) + { + newParent->addChild(this); + } +} +Instance* Instance::getParent() +{ + return parent; +} + +void Instance::addChild(Instance* newChild) +{ + children.push_back(newChild); +} + +void Instance::removeChild(Instance* oldChild) +{ + for(size_t i = 0; i < children.size(); i++) + { + if(children.at(i) == oldChild) + { + children.erase(children.begin() + i); + } + } +} + +Instance* Instance::findFirstChild(std::string name) +{ + Instance* child = NULL; + for(size_t i = 0; i < children.size(); i++) + { + if(children.at(i)->name == name) + { + child = children.at(i); + break; + } + } + return child; +} diff --git a/Instance.h b/Instance.h index b718a3e..be3f943 100644 --- a/Instance.h +++ b/Instance.h @@ -10,6 +10,13 @@ public: Instance* parent; // Another pointer. std::vector children; // All children. std::string getClassName(); + Instance* findFirstChild(std::string); + std::vector getChildren(); + std::vector getAllChildren(); + void setParent(Instance*); + void addChild(Instance*); + void removeChild(Instance*); + Instance* getParent(); protected: std::string className; }; From c875454b40c72587ed14037247e872e5cbe505e7 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Tue, 1 May 2018 11:47:23 -0700 Subject: [PATCH 3/9] Created bare workspace and datamodel classes --- DataModelInstance.cpp | 10 ++++++++++ DataModelInstance.h | 10 ++++++++++ G3DTest.vcproj | 8 ++++++++ WorkspaceInstance.cpp | 10 ++++++++++ WorkspaceInstance.h | 10 ++++++++++ 5 files changed, 48 insertions(+) create mode 100644 DataModelInstance.cpp create mode 100644 DataModelInstance.h create mode 100644 WorkspaceInstance.cpp create mode 100644 WorkspaceInstance.h diff --git a/DataModelInstance.cpp b/DataModelInstance.cpp new file mode 100644 index 0000000..0d12f30 --- /dev/null +++ b/DataModelInstance.cpp @@ -0,0 +1,10 @@ +#include "DataModelInstance.h" + +DataModelInstance::DataModelInstance(void) +{ + className = "DataModel"; +} + +DataModelInstance::~DataModelInstance(void) +{ +} diff --git a/DataModelInstance.h b/DataModelInstance.h new file mode 100644 index 0000000..5215f05 --- /dev/null +++ b/DataModelInstance.h @@ -0,0 +1,10 @@ +#pragma once +#include "instance.h" + +class DataModelInstance : + public Instance +{ +public: + DataModelInstance(void); + ~DataModelInstance(void); +}; diff --git a/G3DTest.vcproj b/G3DTest.vcproj index 3f6d76b..4839a34 100644 --- a/G3DTest.vcproj +++ b/G3DTest.vcproj @@ -242,6 +242,10 @@ RelativePath=".\ButtonListener.cpp" > + + @@ -299,6 +303,10 @@ RelativePath=".\ButtonListener.h" > + + diff --git a/WorkspaceInstance.cpp b/WorkspaceInstance.cpp new file mode 100644 index 0000000..e86a021 --- /dev/null +++ b/WorkspaceInstance.cpp @@ -0,0 +1,10 @@ +#include "WorkspaceInstance.h" + +WorkspaceInstance::WorkspaceInstance(void) +{ + className = "Workspace"; +} + +WorkspaceInstance::~WorkspaceInstance(void) +{ +} diff --git a/WorkspaceInstance.h b/WorkspaceInstance.h new file mode 100644 index 0000000..c6c45b0 --- /dev/null +++ b/WorkspaceInstance.h @@ -0,0 +1,10 @@ +#pragma once +#include "instance.h" + +class WorkspaceInstance : + public Instance +{ +public: + WorkspaceInstance(void); + ~WorkspaceInstance(void); +}; From e6ca1cd502fe867a4a51be57f7cc3b606b851848 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Tue, 1 May 2018 12:14:54 -0700 Subject: [PATCH 4/9] changed AudioPlayer::PlaySound() to AudioPlayer::playSound() --- AudioPlayer.cpp | 2 +- AudioPlayer.h | 2 +- G3DTest.vcproj | 108 +++++++++++++++++++++++++++--------------------- main.cpp | 12 +++--- 4 files changed, 70 insertions(+), 54 deletions(-) diff --git a/AudioPlayer.cpp b/AudioPlayer.cpp index bfbc2c1..92556c1 100644 --- a/AudioPlayer.cpp +++ b/AudioPlayer.cpp @@ -58,7 +58,7 @@ void mixaudio(void *unused, Uint8 *stream, int len) } } -void AudioPlayer::PlaySound(std::string fileString) +void AudioPlayer::playSound(std::string fileString) { if(initiated) diff --git a/AudioPlayer.h b/AudioPlayer.h index 772accc..7467064 100644 --- a/AudioPlayer.h +++ b/AudioPlayer.h @@ -6,6 +6,6 @@ class AudioPlayer public: AudioPlayer(void); ~AudioPlayer(void); - static void PlaySound(std::string); + static void playSound(std::string); static void init(); }; diff --git a/G3DTest.vcproj b/G3DTest.vcproj index 4839a34..5a94fc8 100644 --- a/G3DTest.vcproj +++ b/G3DTest.vcproj @@ -234,30 +234,14 @@ RelativePath=".\AudioPlayer.cpp" > - - - - - - - - @@ -278,14 +262,38 @@ /> - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + + + + debugCamera.getCoordinateFrame(); if(button->name == "CenterCam") centerCam = true; @@ -280,7 +280,7 @@ void GUDButtonListener::onButton1MouseClick(BaseButtonInstance* button) { if(selectedInstance != NULL) { - AudioPlayer::PlaySound(dingSound); + AudioPlayer::playSound(dingSound); if(button->name == "Duplicate") { @@ -298,7 +298,7 @@ void RotateButtonListener::onButton1MouseClick(BaseButtonInstance* button) { if(selectedInstance != NULL) { - AudioPlayer::PlaySound(clickSound); + AudioPlayer::playSound(clickSound); if(selectedInstance->getClassName() == "Part") { PhysicalInstance* part = (PhysicalInstance*) selectedInstance; @@ -324,7 +324,7 @@ void deleteInstance() instances.erase(instances.begin() + i); delete deleting; selectedInstance = NULL; - AudioPlayer::PlaySound(GetFileInPath("/content/sounds/pageturn.wav")); + AudioPlayer::playSound(GetFileInPath("/content/sounds/pageturn.wav")); } } } @@ -1049,13 +1049,13 @@ void Demo::onUserInput(UserInput* ui) { if(ui->keyPressed(SDL_MOUSE_WHEEL_UP_KEY)) { - AudioPlayer::PlaySound(cameraSound); + AudioPlayer::playSound(cameraSound); CoordinateFrame frame = app->debugCamera.getCoordinateFrame(); cameraPos = cameraPos + frame.lookVector()*2; } if(ui->keyPressed(SDL_MOUSE_WHEEL_DOWN_KEY)) { - AudioPlayer::PlaySound(cameraSound); + AudioPlayer::playSound(cameraSound); CoordinateFrame frame = app->debugCamera.getCoordinateFrame(); cameraPos = cameraPos - frame.lookVector()*2; } From 930aee06dcba8a24b08e8c87333b4fba47e8a7ac Mon Sep 17 00:00:00 2001 From: andreja6 Date: Tue, 1 May 2018 15:02:04 -0700 Subject: [PATCH 5/9] Finished new datamodel Not very efficient, but its somewhere --- DataModelInstance.cpp | 10 ++++ DataModelInstance.h | 2 + Instance.cpp | 3 +- Instance.h | 3 +- main.cpp | 125 +++++++++++++++++++++--------------------- 5 files changed, 77 insertions(+), 66 deletions(-) diff --git a/DataModelInstance.cpp b/DataModelInstance.cpp index 0d12f30..eeaab1b 100644 --- a/DataModelInstance.cpp +++ b/DataModelInstance.cpp @@ -1,10 +1,20 @@ #include "DataModelInstance.h" + +WorkspaceInstance* workspace; + DataModelInstance::DataModelInstance(void) { + workspace = new WorkspaceInstance(); + children.push_back(workspace); className = "DataModel"; } DataModelInstance::~DataModelInstance(void) { } + +WorkspaceInstance* DataModelInstance::getWorkspace() +{ + return workspace; +} diff --git a/DataModelInstance.h b/DataModelInstance.h index 5215f05..400a71d 100644 --- a/DataModelInstance.h +++ b/DataModelInstance.h @@ -1,5 +1,6 @@ #pragma once #include "instance.h" +#include "WorkspaceInstance.h" class DataModelInstance : public Instance @@ -7,4 +8,5 @@ class DataModelInstance : public: DataModelInstance(void); ~DataModelInstance(void); + WorkspaceInstance* getWorkspace(); }; diff --git a/Instance.cpp b/Instance.cpp index 1d3fe47..b50c024 100644 --- a/Instance.cpp +++ b/Instance.cpp @@ -3,12 +3,13 @@ #include "Instance.h" std::string name; -Instance* parent; +Instance* parent = NULL; std::vector children; static std::string className = "BaseInstance"; Instance::Instance(void) { + parent = NULL; name = "Default Game Instance"; className = "BaseInstance"; } diff --git a/Instance.h b/Instance.h index be3f943..d1ded43 100644 --- a/Instance.h +++ b/Instance.h @@ -7,7 +7,7 @@ public: Instance(void); virtual ~Instance(void); std::string name; - Instance* parent; // Another pointer. + std::vector children; // All children. std::string getClassName(); Instance* findFirstChild(std::string); @@ -19,4 +19,5 @@ public: Instance* getParent(); protected: std::string className; + Instance* parent; // Another pointer. }; diff --git a/main.cpp b/main.cpp index 4250f63..7323ae2 100644 --- a/main.cpp +++ b/main.cpp @@ -16,6 +16,7 @@ #include "PhysicalInstance.h" #include "TextButtonInstance.h" #include "ImageButtonInstance.h" +#include "DataModelInstance.h" #include "AudioPlayer.h" #include @@ -26,9 +27,9 @@ HWND hwnd; static const float VNUM = 0.01F; static std::string title = ""; static const std::string VERSION = "PRE-ALPHA "; -static std::vector instances; +//static std::vector instances; static std::vector instances_2D; -static Instance* dataModel; +static DataModelInstance* dataModel; GFontRef fntdominant = NULL; GFontRef fntlighttrek = NULL; Ray testRay; @@ -175,10 +176,10 @@ Demo::Demo(App* _app) : GApplet(_app), app(_app) { void clearInstances() { - for(size_t i = 0; i < instances.size(); i++) - { - delete instances.at(i); - } + //for(size_t i = 0; i < instances.size(); i++) + //{ + // delete instances.at(i); + //} delete dataModel; } @@ -226,14 +227,14 @@ std::string Convert (float number){ PhysicalInstance* makePart() { PhysicalInstance* part = new PhysicalInstance(); - instances.push_back(part); +// instances.push_back(part); return part; } TextButtonInstance* makeTextButton() { TextButtonInstance* part = new TextButtonInstance(); - instances.push_back(part); +// instances.push_back(part); instances_2D.push_back(part); return part; } @@ -241,7 +242,7 @@ TextButtonInstance* makeTextButton() ImageButtonInstance* makeImageButton(G3D::TextureRef newImage = NULL, G3D::TextureRef overImage = NULL, G3D::TextureRef downImage = NULL, G3D::TextureRef disableImage = NULL) { ImageButtonInstance* part = new ImageButtonInstance(newImage,overImage, downImage, disableImage); - instances.push_back(part); +// instances.push_back(part); instances_2D.push_back(part); return part; } @@ -316,17 +317,11 @@ void deleteInstance() { if(selectedInstance != NULL) { - for(size_t i = 0; i < instances.size(); i++) - { - if(instances.at(i) == selectedInstance) - { - Instance* deleting = instances.at(i); - instances.erase(instances.begin() + i); - delete deleting; - selectedInstance = NULL; - AudioPlayer::playSound(GetFileInPath("/content/sounds/pageturn.wav")); - } - } + if(selectedInstance->getParent() != NULL) + selectedInstance->getParent()->removeChild(selectedInstance); + delete selectedInstance; + selectedInstance = NULL; + AudioPlayer::playSound(GetFileInPath("/content/sounds/pageturn.wav")); } } @@ -380,7 +375,7 @@ void initGUI() button->boxBegin = Vector2(0, -24); button->boxEnd = Vector2(80, 0); button->floatBottom = true; - button->parent = dataModel; + button->setParent(dataModel); button->font = fntlighttrek; button->textColor = Color3(0,255,255); button->textOutlineColor = Color4::clear(); @@ -392,7 +387,7 @@ void initGUI() button->boxBegin = Vector2(0, -48); button->boxEnd = Vector2(80, -24); button->floatBottom = true; - button->parent = dataModel; + button->setParent(dataModel); button->font = fntlighttrek; button->textColor = Color3(0,255,255); button->textOutlineColor = Color4::clear(); @@ -404,7 +399,7 @@ void initGUI() button->boxBegin = Vector2(0, -72); button->boxEnd = Vector2(80, -48); button->floatBottom = true; - button->parent = dataModel; + button->setParent(dataModel); button->font = fntlighttrek; button->textColor = Color3(0,255,255); button->textOutlineColor = Color4::clear(); @@ -416,7 +411,7 @@ void initGUI() button->boxBegin = Vector2(0, -96); button->boxEnd = Vector2(80, -72); button->floatBottom = true; - button->parent = dataModel; + button->setParent(dataModel); button->font = fntlighttrek; button->textColor = Color3(0,255,255); button->textOutlineColor = Color4::clear(); @@ -428,7 +423,7 @@ void initGUI() button->boxBegin = Vector2(0, -120); button->boxEnd = Vector2(80, -96); button->floatBottom = true; - button->parent = dataModel; + button->setParent(dataModel); button->font = fntlighttrek; button->textColor = Color3(0,255,255); button->boxOutlineColor = Color3(0,255,255); @@ -439,7 +434,7 @@ void initGUI() button = makeTextButton(); button->boxBegin = Vector2(0, 0); button->boxEnd = Vector2(125, 25); - button->parent = dataModel; + button->setParent(dataModel); button->font = fntlighttrek; button->textColor = Color3::white(); button->boxColor = Color4::clear(); @@ -452,7 +447,7 @@ void initGUI() button = makeTextButton(); button->boxBegin = Vector2(125, 0); button->boxEnd = Vector2(250, 25); - button->parent = dataModel; + button->setParent(dataModel); button->font = fntlighttrek; button->textColor = Color3::white(); button->boxColor = Color4::clear(); @@ -465,7 +460,7 @@ void initGUI() button = makeTextButton(); button->boxBegin = Vector2(250, 0); button->boxEnd = Vector2(375, 25); - button->parent = dataModel; + button->setParent(dataModel); button->font = fntlighttrek; button->textColor = Color3::white(); button->boxColor = Color4::clear(); @@ -478,7 +473,7 @@ void initGUI() button = makeTextButton(); button->boxBegin = Vector2(375, 0); button->boxEnd = Vector2(500, 25); - button->parent = dataModel; + button->setParent(dataModel); button->font = fntlighttrek; button->textColor = Color3::white(); button->boxColor = Color4::clear(); @@ -491,7 +486,7 @@ void initGUI() button = makeTextButton(); button->boxBegin = Vector2(500, 0); button->boxEnd = Vector2(625, 25); - button->parent = dataModel; + button->setParent(dataModel); button->font = fntlighttrek; button->textColor = Color3::white(); button->boxColor = Color4::clear(); @@ -514,7 +509,7 @@ void initGUI() button->setAllColorsSame(); button->font = fntlighttrek; button->fontLocationRelativeTo = Vector2(10, 0); - button->parent = dataModel; + button->setParent(dataModel); button = makeTextButton(); @@ -528,7 +523,7 @@ void initGUI() button->setAllColorsSame(); button->font = fntlighttrek; button->fontLocationRelativeTo = Vector2(10, 0); - button->parent = dataModel; + button->setParent(dataModel); button = makeTextButton(); button->boxBegin = Vector2(0,265); @@ -541,7 +536,7 @@ void initGUI() button->setAllColorsSame(); button->font = fntlighttrek; button->fontLocationRelativeTo = Vector2(10, 0); - button->parent = dataModel; + button->setParent(dataModel); button->name = "Duplicate"; button->setButtonListener(new GUDButtonListener()); @@ -550,7 +545,7 @@ void initGUI() instance->name = "go"; instance->size = Vector2(65,65); instance->position = Vector2(6.5, 25); - instance->parent = dataModel; + instance->setParent(dataModel); @@ -561,14 +556,14 @@ void initGUI() Texture::fromFile(GetFileInPath("/content/images/ArrowTool_ds.png"))); instance->size = Vector2(50,50); instance->position = Vector2(15, 90); - instance->parent = dataModel; + instance->setParent(dataModel); instance->name = "Cursor"; instance->setButtonListener(new ModeSelectionListener()); instance = makeImageButton(Texture::fromFile(GetFileInPath("/content/images/ScaleTool.png")),Texture::fromFile(GetFileInPath("/content/images/ScaleTool_ovr.png")),Texture::fromFile(GetFileInPath("/content/images/ScaleTool_dn.png")),Texture::fromFile(GetFileInPath("/content/images/ScaleTool_ds.png"))); instance->size = Vector2(40,40); instance->position = Vector2(0, 140); - instance->parent = dataModel; + instance->setParent(dataModel); instance->name = "Resize"; instance->setButtonListener(new ModeSelectionListener()); @@ -580,7 +575,7 @@ void initGUI() Texture::fromFile(GetFileInPath("/content/images/MoveTool_ds.png"))); instance->size = Vector2(40,40); instance->position = Vector2(40, 140); - instance->parent = dataModel; + instance->setParent(dataModel); instance->name = "Arrows"; instance->setButtonListener(new ModeSelectionListener()); @@ -591,7 +586,7 @@ void initGUI() Texture::fromFile(GetFileInPath("/content/images/SelectionRotate_ds.png"))); instance->size = Vector2(30,30); instance->position = Vector2(10, 175); - instance->parent = dataModel; + instance->setParent(dataModel); instance->name = "Rotate"; instance->setButtonListener(new RotateButtonListener()); @@ -602,7 +597,7 @@ void initGUI() Texture::fromFile(GetFileInPath("/content/images/SelectionTilt_ds.png"))); instance->size = Vector2(30,30); instance->position = Vector2(40, 175); - instance->parent = dataModel; + instance->setParent(dataModel); instance->name = "Tilt"; instance->setButtonListener(new RotateButtonListener()); @@ -614,7 +609,7 @@ void initGUI() Texture::fromFile(GetFileInPath("/content/images/Delete_ds.png"))); instance->size = Vector2(40,46); instance->position = Vector2(20, 284); - instance->parent = dataModel; + instance->setParent(dataModel); instance->name = "Delete"; instance->setButtonListener(new DeleteListener()); @@ -626,7 +621,7 @@ void initGUI() instance->floatBottom = true; instance->floatRight = true; instance->position = Vector2(-77, -90); - instance->parent = dataModel; + instance->setParent(dataModel); instance->name = "ZoomIn"; instance->setButtonListener(new CameraButtonListener()); @@ -638,7 +633,7 @@ void initGUI() instance->floatBottom = true; instance->floatRight = true; instance->position = Vector2(-77, -31); - instance->parent = dataModel; + instance->setParent(dataModel); instance->name = "ZoomOut"; instance->setButtonListener(new CameraButtonListener()); @@ -650,7 +645,7 @@ void initGUI() instance->floatBottom = true; instance->floatRight = true; instance->position = Vector2(-110, -50); - instance->parent = dataModel; + instance->setParent(dataModel); instance->name = "PanLeft"; instance->setButtonListener(new CameraButtonListener()); @@ -662,7 +657,7 @@ void initGUI() instance->floatBottom = true; instance->floatRight = true; instance->position = Vector2(-45, -50); - instance->parent = dataModel; + instance->setParent(dataModel); instance->name = "PanRight"; instance->setButtonListener(new CameraButtonListener()); @@ -674,7 +669,7 @@ void initGUI() instance->floatBottom = true; instance->floatRight = true; instance->position = Vector2(-77, -60); - instance->parent = dataModel; + instance->setParent(dataModel); instance->name = "CenterCam"; instance->setButtonListener(new CameraButtonListener()); @@ -686,7 +681,7 @@ void initGUI() instance->floatBottom = true; instance->floatRight = true; instance->position = Vector2(-105, -75); - instance->parent = dataModel; + instance->setParent(dataModel); instance->name = "TiltUp"; instance->setButtonListener(new CameraButtonListener()); @@ -698,7 +693,7 @@ void initGUI() instance->floatBottom = true; instance->floatRight = true; instance->position = Vector2(-40, -75); - instance->parent = dataModel; + instance->setParent(dataModel); instance->name = "TiltDown"; instance->setButtonListener(new CameraButtonListener()); } @@ -709,15 +704,15 @@ void Demo::onInit() { // Called before Demo::run() beings - dataModel = new Instance(); - dataModel->parent = NULL; + dataModel = new DataModelInstance(); + dataModel->setParent(NULL); dataModel->name = "undefined"; initGUI(); PhysicalInstance* test = makePart(); - test->parent = dataModel; + test->setParent(dataModel->getWorkspace()); test->color = Color3(0.2F,0.3F,1); test->setSize(Vector3(24,1,24)); test->setPosition(Vector3(0,0,0)); @@ -727,54 +722,54 @@ void Demo::onInit() { test = makePart(); - test->parent = dataModel; + test->setParent(dataModel->getWorkspace()); test->color = Color3(.5F,1,.5F); test->setSize(Vector3(4,1,2)); test->setPosition(Vector3(-10,1,0)); test = makePart(); - test->parent = dataModel; + test->setParent(dataModel->getWorkspace()); test->color = Color3(.5F,1,.5F); test->setSize(Vector3(4,1,2)); test->setPosition(Vector3(10,1,0)); test = makePart(); - test->parent = dataModel; + test->setParent(dataModel->getWorkspace()); test->color = Color3::gray(); test->setSize(Vector3(4,1,2)); test->setPosition(Vector3(7,2,0)); test = makePart(); - test->parent = dataModel; + test->setParent(dataModel->getWorkspace()); test->color = Color3::gray(); test->setSize(Vector3(4,1,2)); test->setPosition(Vector3(-7,2,0)); test = makePart(); - test->parent = dataModel; + test->setParent(dataModel->getWorkspace()); test->color = Color3::gray(); test->setSize(Vector3(4,1,2)); test->setPosition(Vector3(4,3,0)); test = makePart(); - test->parent = dataModel; + test->setParent(dataModel->getWorkspace()); test->color = Color3::gray(); test->setSize(Vector3(4,1,2)); test->setPosition(Vector3(-5,3,0)); test = makePart(); - test->parent = dataModel; + test->setParent(dataModel->getWorkspace()); test->color = Color3::gray(); test->setSize(Vector3(4,1,2)); test->setPosition(Vector3(1,4,0)); test = makePart(); - test->parent = dataModel; + test->setParent(dataModel->getWorkspace()); test->color = Color3::gray(); test->setSize(Vector3(4,1,2)); test->setPosition(Vector3(-3,4,0)); test = makePart(); - test->parent = dataModel; + test->setParent(dataModel->getWorkspace()); test->color = Color3::gray(); test->setSize(Vector3(4,1,2)); test->setPosition(Vector3(-2,5,0)); @@ -783,13 +778,13 @@ void Demo::onInit() { test = makePart(); - test->parent = dataModel; + test->setParent(dataModel->getWorkspace()); test->color = Color3::gray(); test->setSize(Vector3(4,1,2)); test->setPosition(Vector3(0,6,0)); test = makePart(); - test->parent = dataModel; + test->setParent(dataModel->getWorkspace()); test->color = Color3::gray(); test->setSize(Vector3(4,1,2)); test->setPosition(Vector3(2,7,0)); @@ -1138,9 +1133,10 @@ void Demo::onUserInput(UserInput* ui) { testRay = app->debugCamera.worldRay(mousex, mousey, app->renderDevice->getViewport()); float nearest=std::numeric_limits::infinity(); Vector3 camPos = app->debugCamera.getCoordinateFrame().translation; + std::vector instances = dataModel->getWorkspace()->getAllChildren(); for(size_t i = 0; i < instances.size(); i++) { - if(instances.at(i)->getClassName() == "Part" && instances.at(i)->parent == dataModel) + if(instances.at(i)->getClassName() == "Part") { PhysicalInstance* test = (PhysicalInstance*)instances.at(i); float time = testRay.intersectionTime(test->getBox()); @@ -1237,7 +1233,7 @@ void drawButtons(RenderDevice* rd) for(size_t i = 0; i < instances_2D.size(); i++) { Instance* instance = instances_2D.at(i); - if((instance->getClassName() == "TextButton" || instance->getClassName() == "ImageButton") && instance->parent == dataModel) + if((instance->getClassName() == "TextButton" || instance->getClassName() == "ImageButton") && instance->getParent() == dataModel) { BaseButtonInstance* tbi = (BaseButtonInstance*)instance; tbi->drawObj(rd, Vector2(mousex, mousey), mouseButton1Down); @@ -1448,10 +1444,11 @@ void Demo::onGraphics(RenderDevice* rd) { //app->renderDevice->pushState(); //app->renderDevice->popState(); + std::vector instances = dataModel->getWorkspace()->getAllChildren(); for(size_t i = 0; i < instances.size(); i++) { Instance* instance = instances.at(i); - if(instance->getClassName() == "Part" && instance->parent != NULL) + if(instance->getClassName() == "Part") { PhysicalInstance* part = (PhysicalInstance*)instance; From 9999eb62e422b7997251f75c479b59d1408bcc60 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Tue, 1 May 2018 19:58:58 -0700 Subject: [PATCH 6/9] Changed how render works --- Instance.cpp | 23 ++++++++++++++++++----- Instance.h | 2 +- PhysicalInstance.cpp | 13 +++++++++++++ PhysicalInstance.h | 2 +- main.cpp | 19 +++++++++++++------ 5 files changed, 46 insertions(+), 13 deletions(-) diff --git a/Instance.cpp b/Instance.cpp index b50c024..3872eba 100644 --- a/Instance.cpp +++ b/Instance.cpp @@ -14,6 +14,14 @@ Instance::Instance(void) className = "BaseInstance"; } +void Instance::render(RenderDevice* rd) +{ + for(size_t i = 0; i < children.size(); i++) + { + children.at(i)->render(rd); + } +} + Instance::~Instance(void) { for(size_t i = 0; i < children.size(); i++) @@ -34,13 +42,18 @@ std::vector Instance::getChildren() std::vector Instance::getAllChildren() { - std::vector totalchildren = children; - for(size_t i = 0; i < children.size(); i++) + if(!children.empty()) { - std::vector subchildren = children.at(i)->getAllChildren(); - totalchildren.insert(totalchildren.end(), subchildren.begin(), subchildren.end()); + std::vector totalchildren = children; + for(size_t i = 0; i < children.size(); i++) + { + std::vector subchildren = children.at(i)->getAllChildren(); + if(!subchildren.empty()) + totalchildren.insert(totalchildren.end(), subchildren.begin(), subchildren.end()); + } + return totalchildren; } - return totalchildren; + return children; } void Instance::setParent(Instance* newParent) diff --git a/Instance.h b/Instance.h index d1ded43..f379d63 100644 --- a/Instance.h +++ b/Instance.h @@ -7,7 +7,7 @@ public: Instance(void); virtual ~Instance(void); std::string name; - + virtual void render(RenderDevice*); std::vector children; // All children. std::string getClassName(); Instance* findFirstChild(std::string); diff --git a/PhysicalInstance.cpp b/PhysicalInstance.cpp index 3a9891b..416551e 100644 --- a/PhysicalInstance.cpp +++ b/PhysicalInstance.cpp @@ -93,6 +93,19 @@ Box PhysicalInstance::getBox() return itemBox; } +void PhysicalInstance::render(RenderDevice* rd) +{ + Draw::box(getBox(), rd, color, Color4::clear()); + if(!children.empty()) + { + for(size_t i = 0; i < children.size(); i++) + { + children.at(i)->render(rd); + } + } + +} + PhysicalInstance::~PhysicalInstance(void) { } diff --git a/PhysicalInstance.h b/PhysicalInstance.h index 66381db..8731067 100644 --- a/PhysicalInstance.h +++ b/PhysicalInstance.h @@ -7,7 +7,7 @@ class PhysicalInstance : public: PhysicalInstance(void); ~PhysicalInstance(void); - + virtual void render(RenderDevice*); Vector3 velocity; Vector3 rotvelocity; CoordinateFrame cFrame; diff --git a/main.cpp b/main.cpp index 7323ae2..316197f 100644 --- a/main.cpp +++ b/main.cpp @@ -1032,7 +1032,6 @@ void Demo::onUserInput(UserInput* ui) { showMouse = true; app->debugController.setActive(false); } - if(ui->keyPressed(SDLK_LSHIFT) || ui->keyPressed(SDLK_RSHIFT)) { moveRate = 1; @@ -1443,16 +1442,24 @@ void Demo::onGraphics(RenderDevice* rd) { //app->renderDevice->pushState(); //app->renderDevice->popState(); - - std::vector instances = dataModel->getWorkspace()->getAllChildren(); + dataModel->getWorkspace()->render(rd); + if(selectedInstance != NULL) + { + PhysicalInstance* part = (PhysicalInstance*)selectedInstance; + Vector3 size = part->getSize(); + Vector3 pos = part->getPosition(); + drawOutline(Vector3(0+size.x/4, 0+size.y/4, 0+size.z/4) ,Vector3(0-size.x/4,0-size.y/4,0-size.z/4), rd, lighting, Vector3(size.x/2, size.y/2, size.z/2), Vector3(pos.x/2, pos.y/2, pos.z/2), part->getCFrameRenderBased()); + } + /*std::vector instances = dataModel->getWorkspace()->getAllChildren(); for(size_t i = 0; i < instances.size(); i++) { Instance* instance = instances.at(i); if(instance->getClassName() == "Part") { - + instance->render(rd); PhysicalInstance* part = (PhysicalInstance*)instance; - Draw::box(part->getBox(), app->renderDevice, part->color, Color4::clear()); + //part->render(rd); + //Draw::box(part->getBox(), app->renderDevice, part->color, Color4::clear()); if(selectedInstance == part) { Vector3 size = part->getSize(); @@ -1463,7 +1470,7 @@ void Demo::onGraphics(RenderDevice* rd) { } } - Box box; + Box box;*/ //Draw::ray(testRay, rd, Color3::orange(), 1); From 57b407c894d2ba515d29d1c8f894d1ef23e47885 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Tue, 1 May 2018 20:10:52 -0700 Subject: [PATCH 7/9] Made timer and score a part of Workspace --- WorkspaceInstance.cpp | 4 ++++ WorkspaceInstance.h | 2 ++ main.cpp | 14 ++++++-------- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/WorkspaceInstance.cpp b/WorkspaceInstance.cpp index e86a021..09a1c50 100644 --- a/WorkspaceInstance.cpp +++ b/WorkspaceInstance.cpp @@ -1,8 +1,12 @@ #include "WorkspaceInstance.h" +float timer = 60.0F; +int score = 0; WorkspaceInstance::WorkspaceInstance(void) { className = "Workspace"; + timer = 60.0F; + score = 0; } WorkspaceInstance::~WorkspaceInstance(void) diff --git a/WorkspaceInstance.h b/WorkspaceInstance.h index c6c45b0..fdb4b78 100644 --- a/WorkspaceInstance.h +++ b/WorkspaceInstance.h @@ -5,6 +5,8 @@ class WorkspaceInstance : public Instance { public: + float timer; + int score; WorkspaceInstance(void); ~WorkspaceInstance(void); }; diff --git a/main.cpp b/main.cpp index 316197f..b6cfe3c 100644 --- a/main.cpp +++ b/main.cpp @@ -11,6 +11,7 @@ @author Morgan McGuire, matrix@graphics3d.com */ #include +#include #include "Instance.h" #include "resource.h" #include "PhysicalInstance.h" @@ -24,10 +25,8 @@ #error Requires G3D 6.10 #endif HWND hwnd; -static const float VNUM = 0.01F; + static std::string title = ""; -static const std::string VERSION = "PRE-ALPHA "; -//static std::vector instances; static std::vector instances_2D; static DataModelInstance* dataModel; GFontRef fntdominant = NULL; @@ -43,8 +42,6 @@ static int index = 2; static std::string cameraSound = ""; static std::string clickSound = ""; static std::string dingSound = ""; -static float TIMERVAL = 60.0F; -static int SCOREVAL = 0; static G3D::TextureRef go = NULL; static G3D::TextureRef go_ovr = NULL; static G3D::TextureRef go_dn = NULL; @@ -71,7 +68,6 @@ static const int ARROWS = 1; static const int RESIZE = 2; static int mode = CURSOR; Vector3 cameraPos = Vector3(0,2,10); -Vector3 focalPointT = Vector3(0,0,0); Vector2 oldMouse = Vector2(0,0); float moveRate = 0.5; Instance* selectedInstance = NULL; @@ -1505,8 +1501,10 @@ void Demo::onGraphics(RenderDevice* rd) { fntdominant->draw2D(rd, message, Vector2((rd->getWidth()/2)-(fntdominant->get2DStringBounds(message, 20).x/2),(rd->getHeight()/2)-(fntdominant->get2DStringBounds(message, 20).y/2)), 20, Color3::yellow(), Color3::black()); } - fntdominant->draw2D(rd, "Timer: " + Convert(TIMERVAL), Vector2(rd->getWidth() - 120, 0+offset), 20, Color3::fromARGB(0x81C518), Color3::black()); - fntdominant->draw2D(rd, "Score: " + Convert(SCOREVAL), Vector2(rd->getWidth() - 120, 25+offset), 20, Color3::fromARGB(0x81C518), Color3::black()); + std::stringstream stream; + stream << std::fixed << std::setprecision(1) << dataModel->getWorkspace()->timer; + fntdominant->draw2D(rd, "Timer: " + stream.str(), Vector2(rd->getWidth() - 120, 0+offset), 20, Color3::fromARGB(0x81C518), Color3::black()); + fntdominant->draw2D(rd, "Score: " + Convert(dataModel->getWorkspace()->score), Vector2(rd->getWidth() - 120, 25+offset), 20, Color3::fromARGB(0x81C518), Color3::black()); //GUI Boxes From 3ee06b6c6220e4f3a01e769f5aeca02ea506abaa Mon Sep 17 00:00:00 2001 From: andreja6 Date: Tue, 1 May 2018 21:00:46 -0700 Subject: [PATCH 8/9] Made guiroot a child of datamodel --- DataModelInstance.cpp | 9 ++++- DataModelInstance.h | 1 + main.cpp | 88 +++++++++++++++++++++---------------------- 3 files changed, 53 insertions(+), 45 deletions(-) diff --git a/DataModelInstance.cpp b/DataModelInstance.cpp index eeaab1b..d79e5e9 100644 --- a/DataModelInstance.cpp +++ b/DataModelInstance.cpp @@ -2,12 +2,14 @@ WorkspaceInstance* workspace; +Instance* guiRoot; DataModelInstance::DataModelInstance(void) { workspace = new WorkspaceInstance(); + guiRoot = new Instance(); children.push_back(workspace); - className = "DataModel"; + className = "dataModel"; } DataModelInstance::~DataModelInstance(void) @@ -18,3 +20,8 @@ WorkspaceInstance* DataModelInstance::getWorkspace() { return workspace; } + +Instance* DataModelInstance::getGuiRoot() +{ + return guiRoot; +} diff --git a/DataModelInstance.h b/DataModelInstance.h index 400a71d..9142a57 100644 --- a/DataModelInstance.h +++ b/DataModelInstance.h @@ -9,4 +9,5 @@ public: DataModelInstance(void); ~DataModelInstance(void); WorkspaceInstance* getWorkspace(); + Instance* getGuiRoot(); }; diff --git a/main.cpp b/main.cpp index b6cfe3c..1a37e68 100644 --- a/main.cpp +++ b/main.cpp @@ -27,7 +27,6 @@ HWND hwnd; static std::string title = ""; -static std::vector instances_2D; static DataModelInstance* dataModel; GFontRef fntdominant = NULL; GFontRef fntlighttrek = NULL; @@ -231,7 +230,7 @@ TextButtonInstance* makeTextButton() { TextButtonInstance* part = new TextButtonInstance(); // instances.push_back(part); - instances_2D.push_back(part); +// instances_2D.push_back(part); return part; } @@ -239,7 +238,7 @@ ImageButtonInstance* makeImageButton(G3D::TextureRef newImage = NULL, G3D::Textu { ImageButtonInstance* part = new ImageButtonInstance(newImage,overImage, downImage, disableImage); // instances.push_back(part); - instances_2D.push_back(part); +// instances_2D.push_back(part); return part; } @@ -345,7 +344,7 @@ void ModeSelectionListener::onButton1MouseClick(BaseButtonInstance* button) { CoordinateFrame frame = usableApp->debugCamera.getCoordinateFrame(); - + std::vector instances_2D = dataModel->getGuiRoot()->getAllChildren(); for(size_t i = 0; i < instances_2D.size(); i++) { if(instances_2D.at(i)->name == "Cursor" || instances_2D.at(i)->name == "Resize" || instances_2D.at(i)->name == "Arrows") @@ -371,7 +370,7 @@ void initGUI() button->boxBegin = Vector2(0, -24); button->boxEnd = Vector2(80, 0); button->floatBottom = true; - button->setParent(dataModel); + button->setParent(dataModel->getGuiRoot()); button->font = fntlighttrek; button->textColor = Color3(0,255,255); button->textOutlineColor = Color4::clear(); @@ -383,7 +382,7 @@ void initGUI() button->boxBegin = Vector2(0, -48); button->boxEnd = Vector2(80, -24); button->floatBottom = true; - button->setParent(dataModel); + button->setParent(dataModel->getGuiRoot()); button->font = fntlighttrek; button->textColor = Color3(0,255,255); button->textOutlineColor = Color4::clear(); @@ -395,7 +394,7 @@ void initGUI() button->boxBegin = Vector2(0, -72); button->boxEnd = Vector2(80, -48); button->floatBottom = true; - button->setParent(dataModel); + button->setParent(dataModel->getGuiRoot()); button->font = fntlighttrek; button->textColor = Color3(0,255,255); button->textOutlineColor = Color4::clear(); @@ -407,7 +406,7 @@ void initGUI() button->boxBegin = Vector2(0, -96); button->boxEnd = Vector2(80, -72); button->floatBottom = true; - button->setParent(dataModel); + button->setParent(dataModel->getGuiRoot()); button->font = fntlighttrek; button->textColor = Color3(0,255,255); button->textOutlineColor = Color4::clear(); @@ -419,7 +418,7 @@ void initGUI() button->boxBegin = Vector2(0, -120); button->boxEnd = Vector2(80, -96); button->floatBottom = true; - button->setParent(dataModel); + button->setParent(dataModel->getGuiRoot()); button->font = fntlighttrek; button->textColor = Color3(0,255,255); button->boxOutlineColor = Color3(0,255,255); @@ -430,7 +429,7 @@ void initGUI() button = makeTextButton(); button->boxBegin = Vector2(0, 0); button->boxEnd = Vector2(125, 25); - button->setParent(dataModel); + button->setParent(dataModel->getGuiRoot()); button->font = fntlighttrek; button->textColor = Color3::white(); button->boxColor = Color4::clear(); @@ -443,7 +442,7 @@ void initGUI() button = makeTextButton(); button->boxBegin = Vector2(125, 0); button->boxEnd = Vector2(250, 25); - button->setParent(dataModel); + button->setParent(dataModel->getGuiRoot()); button->font = fntlighttrek; button->textColor = Color3::white(); button->boxColor = Color4::clear(); @@ -456,7 +455,7 @@ void initGUI() button = makeTextButton(); button->boxBegin = Vector2(250, 0); button->boxEnd = Vector2(375, 25); - button->setParent(dataModel); + button->setParent(dataModel->getGuiRoot()); button->font = fntlighttrek; button->textColor = Color3::white(); button->boxColor = Color4::clear(); @@ -469,7 +468,7 @@ void initGUI() button = makeTextButton(); button->boxBegin = Vector2(375, 0); button->boxEnd = Vector2(500, 25); - button->setParent(dataModel); + button->setParent(dataModel->getGuiRoot()); button->font = fntlighttrek; button->textColor = Color3::white(); button->boxColor = Color4::clear(); @@ -482,7 +481,7 @@ void initGUI() button = makeTextButton(); button->boxBegin = Vector2(500, 0); button->boxEnd = Vector2(625, 25); - button->setParent(dataModel); + button->setParent(dataModel->getGuiRoot()); button->font = fntlighttrek; button->textColor = Color3::white(); button->boxColor = Color4::clear(); @@ -505,7 +504,7 @@ void initGUI() button->setAllColorsSame(); button->font = fntlighttrek; button->fontLocationRelativeTo = Vector2(10, 0); - button->setParent(dataModel); + button->setParent(dataModel->getGuiRoot()); button = makeTextButton(); @@ -519,7 +518,7 @@ void initGUI() button->setAllColorsSame(); button->font = fntlighttrek; button->fontLocationRelativeTo = Vector2(10, 0); - button->setParent(dataModel); + button->setParent(dataModel->getGuiRoot()); button = makeTextButton(); button->boxBegin = Vector2(0,265); @@ -532,7 +531,7 @@ void initGUI() button->setAllColorsSame(); button->font = fntlighttrek; button->fontLocationRelativeTo = Vector2(10, 0); - button->setParent(dataModel); + button->setParent(dataModel->getGuiRoot()); button->name = "Duplicate"; button->setButtonListener(new GUDButtonListener()); @@ -541,7 +540,7 @@ void initGUI() instance->name = "go"; instance->size = Vector2(65,65); instance->position = Vector2(6.5, 25); - instance->setParent(dataModel); + instance->setParent(dataModel->getGuiRoot()); @@ -552,14 +551,14 @@ void initGUI() Texture::fromFile(GetFileInPath("/content/images/ArrowTool_ds.png"))); instance->size = Vector2(50,50); instance->position = Vector2(15, 90); - instance->setParent(dataModel); + instance->setParent(dataModel->getGuiRoot()); instance->name = "Cursor"; instance->setButtonListener(new ModeSelectionListener()); instance = makeImageButton(Texture::fromFile(GetFileInPath("/content/images/ScaleTool.png")),Texture::fromFile(GetFileInPath("/content/images/ScaleTool_ovr.png")),Texture::fromFile(GetFileInPath("/content/images/ScaleTool_dn.png")),Texture::fromFile(GetFileInPath("/content/images/ScaleTool_ds.png"))); instance->size = Vector2(40,40); instance->position = Vector2(0, 140); - instance->setParent(dataModel); + instance->setParent(dataModel->getGuiRoot()); instance->name = "Resize"; instance->setButtonListener(new ModeSelectionListener()); @@ -571,7 +570,7 @@ void initGUI() Texture::fromFile(GetFileInPath("/content/images/MoveTool_ds.png"))); instance->size = Vector2(40,40); instance->position = Vector2(40, 140); - instance->setParent(dataModel); + instance->setParent(dataModel->getGuiRoot()); instance->name = "Arrows"; instance->setButtonListener(new ModeSelectionListener()); @@ -582,7 +581,7 @@ void initGUI() Texture::fromFile(GetFileInPath("/content/images/SelectionRotate_ds.png"))); instance->size = Vector2(30,30); instance->position = Vector2(10, 175); - instance->setParent(dataModel); + instance->setParent(dataModel->getGuiRoot()); instance->name = "Rotate"; instance->setButtonListener(new RotateButtonListener()); @@ -593,7 +592,7 @@ void initGUI() Texture::fromFile(GetFileInPath("/content/images/SelectionTilt_ds.png"))); instance->size = Vector2(30,30); instance->position = Vector2(40, 175); - instance->setParent(dataModel); + instance->setParent(dataModel->getGuiRoot()); instance->name = "Tilt"; instance->setButtonListener(new RotateButtonListener()); @@ -605,7 +604,7 @@ void initGUI() Texture::fromFile(GetFileInPath("/content/images/Delete_ds.png"))); instance->size = Vector2(40,46); instance->position = Vector2(20, 284); - instance->setParent(dataModel); + instance->setParent(dataModel->getGuiRoot()); instance->name = "Delete"; instance->setButtonListener(new DeleteListener()); @@ -617,7 +616,7 @@ void initGUI() instance->floatBottom = true; instance->floatRight = true; instance->position = Vector2(-77, -90); - instance->setParent(dataModel); + instance->setParent(dataModel->getGuiRoot()); instance->name = "ZoomIn"; instance->setButtonListener(new CameraButtonListener()); @@ -629,7 +628,7 @@ void initGUI() instance->floatBottom = true; instance->floatRight = true; instance->position = Vector2(-77, -31); - instance->setParent(dataModel); + instance->setParent(dataModel->getGuiRoot()); instance->name = "ZoomOut"; instance->setButtonListener(new CameraButtonListener()); @@ -641,7 +640,7 @@ void initGUI() instance->floatBottom = true; instance->floatRight = true; instance->position = Vector2(-110, -50); - instance->setParent(dataModel); + instance->setParent(dataModel->getGuiRoot()); instance->name = "PanLeft"; instance->setButtonListener(new CameraButtonListener()); @@ -653,7 +652,7 @@ void initGUI() instance->floatBottom = true; instance->floatRight = true; instance->position = Vector2(-45, -50); - instance->setParent(dataModel); + instance->setParent(dataModel->getGuiRoot()); instance->name = "PanRight"; instance->setButtonListener(new CameraButtonListener()); @@ -665,7 +664,7 @@ void initGUI() instance->floatBottom = true; instance->floatRight = true; instance->position = Vector2(-77, -60); - instance->setParent(dataModel); + instance->setParent(dataModel->getGuiRoot()); instance->name = "CenterCam"; instance->setButtonListener(new CameraButtonListener()); @@ -677,7 +676,7 @@ void initGUI() instance->floatBottom = true; instance->floatRight = true; instance->position = Vector2(-105, -75); - instance->setParent(dataModel); + instance->setParent(dataModel->getGuiRoot()); instance->name = "TiltUp"; instance->setButtonListener(new CameraButtonListener()); @@ -689,7 +688,7 @@ void initGUI() instance->floatBottom = true; instance->floatRight = true; instance->position = Vector2(-40, -75); - instance->setParent(dataModel); + instance->setParent(dataModel->getGuiRoot()); instance->name = "TiltDown"; instance->setButtonListener(new CameraButtonListener()); } @@ -823,19 +822,18 @@ void Demo::onCleanup() { void Demo::onLogic() { // Add non-simulation game logic and AI code here - for(size_t i = 0; i < instances_2D.size(); i++) + + Instance* obj = dataModel->getGuiRoot()->findFirstChild("Delete"); + if(obj != NULL) { - if(instances_2D.at(i)->name == "Delete") - { - ImageButtonInstance* button = (ImageButtonInstance*)instances_2D.at(i); - if(selectedInstance == NULL) - button->disabled = true; - else - button->disabled = false; - - } + ImageButtonInstance* button = (ImageButtonInstance*)obj; + if(selectedInstance == NULL) + button->disabled = true; + else + button->disabled = false; } + } @@ -1110,6 +1108,7 @@ void Demo::onUserInput(UserInput* ui) { if(ui->keyPressed(SDL_LEFT_MOUSE_KEY)) { bool onGUI = false; + std::vector instances_2D = dataModel->getGuiRoot()->getAllChildren(); for(size_t i = 0; i < instances_2D.size(); i++) { if(instances_2D.at(i)->getClassName() == "TextButton" || instances_2D.at(i)->getClassName() == "ImageButton") @@ -1155,7 +1154,7 @@ void Demo::onUserInput(UserInput* ui) { if(ui->keyReleased(SDL_LEFT_MOUSE_KEY)) { - + std::vector instances_2D = dataModel->getGuiRoot()->getAllChildren(); for(size_t i = 0; i < instances_2D.size(); i++) { if(instances_2D.at(i)->getClassName() == "TextButton" || instances_2D.at(i)->getClassName() == "ImageButton") @@ -1225,10 +1224,11 @@ bool mouseInArea(float point1x, float point1y, float point2x, float point2y) void drawButtons(RenderDevice* rd) { + std::vector instances_2D = dataModel->getGuiRoot()->getChildren(); for(size_t i = 0; i < instances_2D.size(); i++) { Instance* instance = instances_2D.at(i); - if((instance->getClassName() == "TextButton" || instance->getClassName() == "ImageButton") && instance->getParent() == dataModel) + if(instance->getClassName() == "TextButton" || instance->getClassName() == "ImageButton") { BaseButtonInstance* tbi = (BaseButtonInstance*)instance; tbi->drawObj(rd, Vector2(mousex, mousey), mouseButton1Down); @@ -1794,7 +1794,7 @@ int main(int argc, char** argv) { app.run(); } - catch(std::exception) + catch(...) { OnError(-1); } From 60c7a386f07c89735c3283c9c8bd19b4754ffb9e Mon Sep 17 00:00:00 2001 From: andreja6 Date: Tue, 1 May 2018 21:43:18 -0700 Subject: [PATCH 9/9] Changed how selection boxes work --- main.cpp | 103 +++++++++++++++++++++---------------------------------- 1 file changed, 39 insertions(+), 64 deletions(-) diff --git a/main.cpp b/main.cpp index 1a37e68..07e6b4d 100644 --- a/main.cpp +++ b/main.cpp @@ -711,7 +711,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(90),0)); + test->setCFrame(test->getCFrame() * Matrix3::fromEulerAnglesXYZ(0,toRadians(40),toRadians(40))); //selectedInstance = test; @@ -1238,6 +1238,7 @@ void drawButtons(RenderDevice* rd) void drawOutline(Vector3 from, Vector3 to, RenderDevice* rd, LightingParameters lighting, Vector3 size, Vector3 pos, CoordinateFrame c) { + //rd->setLight(0, NULL); //rd->setAmbientLightColor(Color3(1,1,1)); Color3 outline = Color3::cyan();//Color3(0.098F,0.6F,1.0F); @@ -1263,49 +1264,32 @@ void drawOutline(Vector3 from, Vector3 to, RenderDevice* rd, LightingParameters { rd->setLight(0, NULL); rd->setAmbientLightColor(Color3(1,1,1)); - float max = size.x; - if(abs(size.y) > max) - max = size.y; - if(abs(size.z) > max) - max = size.z; - max = max / 2; - Draw::arrow(pos, Vector3(0, 1+max, 0), rd); - Draw::arrow(pos, Vector3(1+max, 0, 0), rd); - Draw::arrow(pos, Vector3(0, 0, 1+max), rd); - Draw::arrow(pos, Vector3(0, (-1)-max, 0), rd); - Draw::arrow(pos, Vector3((-1)-max, 0, 0), rd); - Draw::arrow(pos, Vector3(0, 0, (-1)-max), rd); + + AABox box; + 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); + + 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); + + 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); - Vector3 gamepoint = pos; - 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 < 0) - distance = distance*-1; - CoordinateFrame frame = CoordinateFrame(rd->getCameraToWorldMatrix().rotation, Vector3(pos.x, pos.y+max+0.8, pos.z)); - Box icon = Box(Vector3(0-distance/128, 0-distance/128, 0-distance/128), Vector3(distance/128, distance/128, distance/128)); - Draw::box(frame.toWorldSpace(icon), rd, Color3::orange(), Color4::clear()); - frame = CoordinateFrame(rd->getCameraToWorldMatrix().rotation, Vector3(pos.x+max+0.8, pos.y, pos.z)); - icon = Box(Vector3(0-distance/128, 0-distance/128, 0-distance/128), Vector3(distance/128, distance/128, distance/128)); - Draw::box(frame.toWorldSpace(icon), rd, Color3::orange(), Color4::clear()); - frame = CoordinateFrame(rd->getCameraToWorldMatrix().rotation, Vector3(pos.x, pos.y, pos.z+(max+0.8))); - icon = Box(Vector3(0-distance/128, 0-distance/128, 0-distance/128), Vector3(distance/128, distance/128, distance/128)); - Draw::box(frame.toWorldSpace(icon), rd, Color3::orange(), Color4::clear()); - frame = CoordinateFrame(rd->getCameraToWorldMatrix().rotation, Vector3(pos.x, pos.y-(max+0.8), pos.z)); - icon = Box(Vector3(0-distance/128, 0-distance/128, 0-distance/128), Vector3(distance/128, distance/128, distance/128)); - Draw::box(frame.toWorldSpace(icon), rd, Color3::orange(), Color4::clear()); - frame = CoordinateFrame(rd->getCameraToWorldMatrix().rotation, Vector3(pos.x-(max+0.8), pos.y, pos.z)); - icon = Box(Vector3(0-distance/128, 0-distance/128, 0-distance/128), Vector3(distance/128, distance/128, distance/128)); - Draw::box(frame.toWorldSpace(icon), rd, Color3::orange(), Color4::clear()); - frame = CoordinateFrame(rd->getCameraToWorldMatrix().rotation, Vector3(pos.x, pos.y, pos.z-(max+0.8))); - icon = Box(Vector3(0-distance/128, 0-distance/128, 0-distance/128), Vector3(distance/128, distance/128, distance/128)); - Draw::box(frame.toWorldSpace(icon), rd, Color3::orange(), Color4::clear()); rd->setAmbientLightColor(lighting.ambient); rd->setLight(0, GLight::directional(lighting.lightDirection, lighting.lightColor)); } else if(mode == RESIZE) { + //Box box = c.toWorldSpace(Box(from, to)) Color3 sphereColor = outline; rd->setLight(0, NULL); rd->setAmbientLightColor(Color3(1,1,1)); @@ -1318,37 +1302,28 @@ void drawOutline(Vector3 from, Vector3 to, RenderDevice* rd, LightingParameters float multiplier = distance * 0.025F/2; if(multiplier < 0.25F) multiplier = 0.25F; - - Draw::sphere(Sphere(Vector3(pos.x, pos.y + (size.y/2 + 1), pos.z), multiplier), rd, sphereColor, Color4::clear()); - Draw::sphere(Sphere(Vector3(pos.x, pos.y - (size.y/2 + 1), pos.z), multiplier), rd, sphereColor, Color4::clear()); - Draw::sphere(Sphere(Vector3(pos.x + (size.x/2 + 1), pos.y, pos.z), multiplier), rd, sphereColor, Color4::clear()); - Draw::sphere(Sphere(Vector3(pos.x - (size.x/2 + 1), pos.y, pos.z), multiplier), rd, sphereColor, Color4::clear()); - Draw::sphere(Sphere(Vector3(pos.x, pos.y, pos.z + (size.z/2 + 1)), multiplier), rd, sphereColor, Color4::clear()); - Draw::sphere(Sphere(Vector3(pos.x, pos.y, pos.z - (size.z/2 + 1)), multiplier), rd, sphereColor, Color4::clear()); + 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()); + + 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.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()); + //Draw::sphere(Sphere(Vector3(pos.x, pos.y - (size.y/2 + 1), pos.z), multiplier), rd, sphereColor, Color4::clear()); + //Draw::sphere(Sphere(Vector3(pos.x + (size.x/2 + 1), pos.y, pos.z), multiplier), rd, sphereColor, Color4::clear()); + //Draw::sphere(Sphere(Vector3(pos.x - (size.x/2 + 1), pos.y, pos.z), multiplier), rd, sphereColor, Color4::clear()); + //Draw::sphere(Sphere(Vector3(pos.x, pos.y, pos.z + (size.z/2 + 1)), multiplier), rd, sphereColor, Color4::clear()); + //Draw::sphere(Sphere(Vector3(pos.x, pos.y, pos.z - (size.z/2 + 1)), multiplier), rd, sphereColor, Color4::clear()); } - 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 < 0) - distance = distance*-1; - CoordinateFrame frame = CoordinateFrame(rd->getCameraToWorldMatrix().rotation, Vector3(pos.x, pos.y+size.y/2+1, pos.z)); - Box icon = Box(Vector3(0-distance/128, 0-distance/128, 0-distance/128), Vector3(distance/128, distance/128, distance/128)); - Draw::box(frame.toWorldSpace(icon), rd, sphereColor, Color4::clear()); - frame = CoordinateFrame(rd->getCameraToWorldMatrix().rotation, Vector3(pos.x+size.x/2+1, pos.y, pos.z)); - icon = Box(Vector3(0-distance/128, 0-distance/128, 0-distance/128), Vector3(distance/128, distance/128, distance/128)); - Draw::box(frame.toWorldSpace(icon), rd, sphereColor , Color4::clear()); - frame = CoordinateFrame(rd->getCameraToWorldMatrix().rotation, Vector3(pos.x, pos.y, pos.z+(size.z/2+1))); - icon = Box(Vector3(0-distance/128, 0-distance/128, 0-distance/128), Vector3(distance/128, distance/128, distance/128)); - Draw::box(frame.toWorldSpace(icon), rd, sphereColor, Color4::clear()); - frame = CoordinateFrame(rd->getCameraToWorldMatrix().rotation, Vector3(pos.x, pos.y-(size.y/2+1), pos.z)); - icon = Box(Vector3(0-distance/128, 0-distance/128, 0-distance/128), Vector3(distance/128, distance/128, distance/128)); - Draw::box(frame.toWorldSpace(icon), rd, sphereColor, Color4::clear()); - frame = CoordinateFrame(rd->getCameraToWorldMatrix().rotation, Vector3(pos.x-(size.x/2+1), pos.y, pos.z)); - icon = Box(Vector3(0-distance/128, 0-distance/128, 0-distance/128), Vector3(distance/128, distance/128, distance/128)); - Draw::box(frame.toWorldSpace(icon), rd, sphereColor, Color4::clear()); - frame = CoordinateFrame(rd->getCameraToWorldMatrix().rotation, Vector3(pos.x, pos.y, pos.z-(size.z/2+1))); - icon = Box(Vector3(0-distance/128, 0-distance/128, 0-distance/128), Vector3(distance/128, distance/128, distance/128)); - Draw::box(frame.toWorldSpace(icon), rd, sphereColor, Color4::clear()); rd->setAmbientLightColor(lighting.ambient); rd->setLight(0, GLight::directional(lighting.lightDirection, lighting.lightColor)); }