From 6fb111067d4d00d23b4fe87bb5e1a03914dd2d39 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Fri, 6 Mar 2020 22:40:00 -0800 Subject: [PATCH] I hate the linker --- Application.cpp | 23 ++++--- DataModelInstance.cpp | 10 +++ DataModelInstance.h | 3 + G3DTest.vcproj | 48 ++++++++++----- GuiRoot.cpp | 12 +++- Instance.h | 2 +- MenuButtonListener.cpp | 11 ++++ MenuButtonListener.h | 8 +++ PartInstance.cpp | 59 +++++++++++++++++- PartInstance.h | 9 ++- ToggleImageButtonInstance.cpp | 113 ++++++++++++++++++++++++++++++++++ ToggleImageButtonInstance.h | 29 +++++++++ WorkspaceInstance.h | 1 + 13 files changed, 297 insertions(+), 31 deletions(-) create mode 100644 MenuButtonListener.cpp create mode 100644 MenuButtonListener.h create mode 100644 ToggleImageButtonInstance.cpp create mode 100644 ToggleImageButtonInstance.h diff --git a/Application.cpp b/Application.cpp index 5fb0a23..fd7b90f 100644 --- a/Application.cpp +++ b/Application.cpp @@ -167,6 +167,7 @@ void Application::deleteInstance() g_usableApp->_propWindow->ClearProperties(); } + void Application::onInit() { // Called before Application::run() beings @@ -284,13 +285,21 @@ void Application::onCleanup() { +double grav = 0.32666666666666666666666666666667; +void Application::onLogic() { + //PhysicsStart -void Application::onLogic() { - // Add non-simulation game logic and AI code here - - - - + for(size_t i = 0; i < this->_dataModel->getWorkspace()->physicalObjects.size(); i++) + { + if(PartInstance* collider = dynamic_cast(this->_dataModel->getWorkspace()->physicalObjects.at(i))) + { + if(!collider->anchored) + { + collider->setPosition(collider->getPosition()+collider->getVelocity()); + collider->setVelocity(Vector3(collider->getVelocity().x,collider->getVelocity().y-grav,collider->getVelocity().z)); + } + } + } } @@ -310,7 +319,7 @@ std::vector Application::getSelection() } void Application::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) { - + onLogic(); _dataModel->getGuiRoot()->update(); diff --git a/DataModelInstance.cpp b/DataModelInstance.cpp index cf3ff3e..2c9fca2 100644 --- a/DataModelInstance.cpp +++ b/DataModelInstance.cpp @@ -30,9 +30,19 @@ DataModelInstance::DataModelInstance(void) level->setParent(this); _loadedFileName="..//skooter.rbxm"; listicon = 5; + running = false; } +void DataModelInstance::toggleRun() +{ + running = !running; +} +bool DataModelInstance::isRunning() +{ + return running; +} + DataModelInstance::~DataModelInstance(void) { } diff --git a/DataModelInstance.h b/DataModelInstance.h index 926d916..7afa538 100644 --- a/DataModelInstance.h +++ b/DataModelInstance.h @@ -36,6 +36,8 @@ public: bool mouseButton1Down; PartInstance* makePart(); void clearLevel(); + void toggleRun(); + bool isRunning(); #if _DEBUG void modXMLLevel(float modY); #endif @@ -51,4 +53,5 @@ private: WorkspaceInstance* workspace; LevelInstance * level; GuiRoot* guiRoot; + bool running; }; diff --git a/G3DTest.vcproj b/G3DTest.vcproj index 07b0d90..bc40e81 100644 --- a/G3DTest.vcproj +++ b/G3DTest.vcproj @@ -250,10 +250,6 @@ RelativePath=".\BrowserCallHandler.cpp" > - - @@ -266,14 +262,6 @@ RelativePath=".\Globals.cpp" > - - - - @@ -314,6 +302,10 @@ RelativePath=".\StringFunctions.cpp" > + + @@ -329,6 +321,14 @@ RelativePath=".\DataModelInstance.cpp" > + + + + @@ -361,6 +361,10 @@ + + @@ -373,6 +377,10 @@ RelativePath=".\GUDButtonListener.cpp" > + + @@ -427,10 +435,6 @@ RelativePath=".\Globals.h" > - - @@ -479,6 +483,10 @@ RelativePath=".\StringFunctions.h" > + + @@ -502,6 +510,10 @@ RelativePath=".\GroupInstance.h" > + + @@ -546,6 +558,10 @@ RelativePath=".\GUDButtonListener.h" > + + diff --git a/GuiRoot.cpp b/GuiRoot.cpp index 6e15dc2..4ad9e5a 100644 --- a/GuiRoot.cpp +++ b/GuiRoot.cpp @@ -4,12 +4,14 @@ #include "BaseButtonInstance.h" #include "TextButtonInstance.h" #include "ImageButtonInstance.h" +#include "ToggleImageButtonInstance.h" #include "GuiRoot.h" #include "Globals.h" #include "StringFunctions.h" #include "GUDButtonListener.h" #include "ModeSelectionListener.h" +#include "MenuButtonListener.h" #include "RotateButtonListener.h" #include "CameraButtonListener.h" #include "DeleteListener.h" @@ -210,10 +212,16 @@ GuiRoot::GuiRoot() : _message(""), _messageTime(0) button->name = "Duplicate"; button->setButtonListener(new GUDButtonListener()); - ImageButtonInstance* instance = makeImageButton( + ImageButtonInstance* instance = new ToggleImageButtonInstance( Texture::fromFile(GetFileInPath("/content/images/Run.png")), Texture::fromFile(GetFileInPath("/content/images/Run_ovr.png")), - Texture::fromFile(GetFileInPath("/content/images/Run_dn.png"))); + Texture::fromFile(GetFileInPath("/content/images/Run_dn.png")), + NULL, + Texture::fromFile(GetFileInPath("/content/images/Stop.png")), + Texture::fromFile(GetFileInPath("/content/images/Stop_ovr.png")), + Texture::fromFile(GetFileInPath("/content/images/Stop_dn.png")) + ); + instance->setButtonListener(new MenuButtonListener()); instance->name = "go"; instance->size = Vector2(65,65); instance->position = Vector2(6.5, 25); diff --git a/Instance.h b/Instance.h index 04ea7af..dcee204 100644 --- a/Instance.h +++ b/Instance.h @@ -17,7 +17,7 @@ public: Instance* findFirstChild(std::string); std::vector getChildren(); std::vector getAllChildren(); - void setParent(Instance*); + virtual void setParent(Instance*); void setName(std::string newName); void addChild(Instance*); void removeChild(Instance*); diff --git a/MenuButtonListener.cpp b/MenuButtonListener.cpp new file mode 100644 index 0000000..72c4a41 --- /dev/null +++ b/MenuButtonListener.cpp @@ -0,0 +1,11 @@ +#include "MenuButtonListener.h" +#include "toggleimagebuttoninstance.h" +#include "Globals.h" +void onButton1MouseClick(BaseButtonInstance* button) +{ + if(button->name == "go") + { + g_dataModel->toggleRun(); + ((ToggleImageButtonInstance*)button)->checked = g_dataModel->isRunning(); + } +} \ No newline at end of file diff --git a/MenuButtonListener.h b/MenuButtonListener.h new file mode 100644 index 0000000..8216961 --- /dev/null +++ b/MenuButtonListener.h @@ -0,0 +1,8 @@ +#pragma once +#include "buttonlistener.h" +class MenuButtonListener : + public ButtonListener +{ +public: + void onButton1MouseClick(BaseButtonInstance*); +}; diff --git a/PartInstance.cpp b/PartInstance.cpp index ea2d065..58a4f70 100644 --- a/PartInstance.cpp +++ b/PartInstance.cpp @@ -11,7 +11,7 @@ PartInstance::PartInstance(void) : _bevelSize(0.07f), _parseVert(0), _debugTimer name = "Unnamed PVItem"; className = "Part"; canCollide = true; - anchored = true; + anchored = false; size = Vector3(2,1,4); setCFrame(CoordinateFrame(Vector3(0,0,0))); color = Color3::gray(); @@ -26,6 +26,25 @@ PartInstance::PartInstance(void) : _bevelSize(0.07f), _parseVert(0), _debugTimer shape = Enum::Shape::Block; } + +Vector3 PartInstance::getVelocity() +{ + return velocity; +} +Vector3 PartInstance::getRotVelocity() +{ + return rotVelocity; +} + +void PartInstance::setVelocity(Vector3 v) +{ + velocity = v; +} +void PartInstance::setRotVelocity(Vector3 v) +{ + rotVelocity = v; +} + void PartInstance::postRender(RenderDevice *rd) { if(!nameShown) @@ -57,6 +76,30 @@ void PartInstance::postRender(RenderDevice *rd) } } +void PartInstance::setParent(Instance* parent) +{ + Instance * cparent = this->parent; + while(cparent != NULL) + { + if(WorkspaceInstance* workspace = dynamic_cast(parent)) + { + workspace->physicalObjects.erase(std::remove(workspace->physicalObjects.begin(), workspace->physicalObjects.end(), this), workspace->physicalObjects.end()); + break; + } + cparent = cparent->getParent(); + } + Instance::setParent(parent); + while(parent != NULL) + { + if(WorkspaceInstance* workspace = dynamic_cast(parent)) + { + workspace->physicalObjects.push_back(this); + break; + } + parent = parent->getParent(); + } +} + PartInstance::PartInstance(const PartInstance &oinst) : _bevelSize(0.07f), _parseVert(0), _debugTimer(0) { PVInstance::PVInstance(oinst); @@ -1048,6 +1091,11 @@ void PartInstance::PropUpdate(LPPROPGRIDITEM &item) color = Color3(GetRValue(item->lpCurValue)/255.0F,GetGValue(item->lpCurValue)/255.0F,GetBValue(item->lpCurValue)/255.0F); changed=true; } + if(strcmp(item->lpszPropName, "Anchored") == 0) + { + anchored=(bool)item->lpCurValue; + changed=true; + } else if(strcmp(item->lpszPropName, "Offset") == 0) { std::string str = (LPTSTR)item->lpCurValue; @@ -1127,8 +1175,13 @@ std::vector PartInstance::getProperties() RGB((color.r*255),(color.g*255),(color.b*255)), PIT_COLOR )); - - sprintf_s(pto, "%g, %g, %g", cFrame.translation.x, cFrame.translation.y, cFrame.translation.z); + properties.push_back(createPGI( + "Item", + "Anchored", + "Whether the block can move or not", + (LPARAM)anchored, + PIT_CHECK + )); properties.push_back(createPGI( "Item", "Offset", diff --git a/PartInstance.h b/PartInstance.h index 0defb42..b47e22b 100644 --- a/PartInstance.h +++ b/PartInstance.h @@ -16,7 +16,6 @@ public: virtual void PartInstance::postRender(RenderDevice* rd); ~PartInstance(void); virtual void render(RenderDevice*); - Vector3 velocity; Enum::SurfaceType::Value top; Enum::SurfaceType::Value front; Enum::SurfaceType::Value right; @@ -27,7 +26,12 @@ public: CoordinateFrame cFrame; Color3 color; Vector3 getPosition(); + Vector3 getVelocity(); + Vector3 getRotVelocity(); + void setParent(Instance* parent); void setPosition(Vector3); + void setVelocity(Vector3); + void setRotVelocity(Vector3); CoordinateFrame getCFrame(); void setCFrame(CoordinateFrame); Box getBox(); @@ -38,7 +42,6 @@ public: void setShape(Enum::Shape::Value shape); bool canCollide; bool anchored; - Vector3 rotVelocity; bool collides(Box); virtual std::vector getProperties(); virtual void PropUpdate(LPPROPGRIDITEM &pItem); @@ -61,6 +64,8 @@ public: private: Vector3 position; Vector3 size; + Vector3 velocity; + Vector3 rotVelocity; float _bevelSize; int _parseVert; int _debugTimer; diff --git a/ToggleImageButtonInstance.cpp b/ToggleImageButtonInstance.cpp new file mode 100644 index 0000000..390e5e1 --- /dev/null +++ b/ToggleImageButtonInstance.cpp @@ -0,0 +1,113 @@ +#include "ToggleImageButtonInstance.h" + +ToggleImageButtonInstance::ToggleImageButtonInstance(G3D::TextureRef newImage, + G3D::TextureRef overImage, + G3D::TextureRef downImage, + G3D::TextureRef disableImage, + G3D::TextureRef newImage2, + G3D::TextureRef overImage2, + G3D::TextureRef downImage2, + G3D::TextureRef disableImage2) : ImageButtonInstance(newImage, overImage, downImage, disableImage) +{ + image2 = newImage2; + openGLID2 = image2->getOpenGLID(); + image_ovr2 = overImage2; + if(!image_ovr2.isNull()) + openGLID2_ovr = image_ovr2->getOpenGLID(); + image_dn2 = downImage2; + if(!image_dn2.isNull()) + openGLID2_dn = image_dn2->getOpenGLID(); + image_ds2 = disableImage2; + if(!image_ds2.isNull()) + openGLID2_ds = image_ds2->getOpenGLID(); + checked = false; + className = "ToggleImageButton"; +} + +ToggleImageButtonInstance::~ToggleImageButtonInstance(void) +{ + //Delete everything on destruction + image2.~ReferenceCountedPointer(); + delete image2.getPointer(); + image_ovr2.~ReferenceCountedPointer(); + delete image_ovr2.getPointer(); + image_ds2.~ReferenceCountedPointer(); + delete image_ds2.getPointer(); + image_dn2.~ReferenceCountedPointer(); + delete image_dn2.getPointer(); + image = NULL; + image_ovr = NULL; + image_ds = NULL; + image_dn = NULL; + delete listener; + listener = NULL; + selected = false; +} + + +void ToggleImageButtonInstance::drawObj(RenderDevice* rd, Vector2 mousePos, bool mouseDown) +{ + bool drawDisabledBox = false; + Vector2 positionRelative = position; + if(floatRight && floatBottom) + { + positionRelative = Vector2(rd->getWidth() + position.x, rd->getHeight() + position.y); + } + else if(floatBottom) + { + positionRelative = Vector2(position.x, rd->getHeight() + position.y); + } + else if(floatRight) + { + positionRelative = Vector2(rd->getWidth() + position.x, position.y); + } + int renderimage = openGLID; + + { + if(selected == true && !image_dn.isNull() && !disabled) + { + renderimage = openGLID_dn; + } + else if(disabled) + { + if(!image_ds.isNull()) + renderimage = openGLID_ds; + else + drawDisabledBox = true; + } + else if(mouseInArea(positionRelative.x, positionRelative.y, positionRelative.x + size.x, positionRelative.y + size.y, mousePos.x, mousePos.y)) + { + if(mouseDown && !image_dn.isNull()) + { + renderimage = openGLID_dn; + } + else if(!image_ovr.isNull()) + { + renderimage = openGLID_ovr; + } + } + } + + + + glEnable( GL_TEXTURE_2D ); + glEnable(GL_BLEND);// you enable blending function + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBindTexture( GL_TEXTURE_2D, renderimage); + glBegin( GL_QUADS ); + glTexCoord2d(0.0,0.0); + glVertex2f( positionRelative.x, positionRelative.y ); + glTexCoord2d( 1.0,0.0 ); + glVertex2f( positionRelative.x + size.x, positionRelative.y ); + glTexCoord2d( 1.0,1.0 ); + glVertex2f( positionRelative.x + size.x, positionRelative.y + size.y ); + glTexCoord2d( 0.0,1.0 ); + glVertex2f( positionRelative.x, positionRelative.y + size.y ); + glEnd(); + glDisable( GL_TEXTURE_2D ); + + if(drawDisabledBox) + { + Draw::box(Box(Vector3(positionRelative.x, positionRelative.y, 0), Vector3(positionRelative.x+size.x, positionRelative.y+size.y, 0)), rd, Color4(0.7F,0.7F,0.7F,0.3F), Color4::clear()); + } +} \ No newline at end of file diff --git a/ToggleImageButtonInstance.h b/ToggleImageButtonInstance.h new file mode 100644 index 0000000..0e6f685 --- /dev/null +++ b/ToggleImageButtonInstance.h @@ -0,0 +1,29 @@ +#pragma once +#include "imagebuttoninstance.h" + + +class ToggleImageButtonInstance : public ImageButtonInstance +{ +public: + //ImageButtonInstance(G3D::TextureRef); + //ImageButtonInstance(G3D::TextureRef,G3D::TextureRef); + //ImageButtonInstance(G3D::TextureRef,G3D::TextureRef,G3D::TextureRef); + ToggleImageButtonInstance(G3D::TextureRef newImage,G3D::TextureRef overImage = NULL, + G3D::TextureRef downImage = NULL, + G3D::TextureRef disableImage = NULL, + G3D::TextureRef newImage2 = NULL, + G3D::TextureRef overImage2 = NULL, + G3D::TextureRef downImage2 = NULL, + G3D::TextureRef disableImage2 = NULL); + ~ToggleImageButtonInstance(void); + void drawObj(RenderDevice*, Vector2, bool); + bool checked; + G3D::TextureRef image2; + int openGLID2; + G3D::TextureRef image_ovr2; + int openGLID2_ovr; + G3D::TextureRef image_dn2; + int openGLID2_dn; + G3D::TextureRef image_ds2; + int openGLID2_ds; +}; diff --git a/WorkspaceInstance.h b/WorkspaceInstance.h index 9ca7899..ee5409d 100644 --- a/WorkspaceInstance.h +++ b/WorkspaceInstance.h @@ -7,4 +7,5 @@ class WorkspaceInstance : public: WorkspaceInstance(void); ~WorkspaceInstance(void); + std::vector physicalObjects; };