From 6fb111067d4d00d23b4fe87bb5e1a03914dd2d39 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Fri, 6 Mar 2020 22:40:00 -0800 Subject: [PATCH 1/6] 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; }; From f92f01be8809902a96debe94c014be36d8240113 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Fri, 6 Mar 2020 23:28:49 -0800 Subject: [PATCH 2/6] Added bare bones physics --- Application.cpp | 75 +++++++++++++++++++++++++++++------ MenuButtonListener.cpp | 2 +- PartInstance.cpp | 6 +-- ToggleImageButtonInstance.cpp | 30 +++++++++++++- WorkspaceInstance.h | 3 +- 5 files changed, 96 insertions(+), 20 deletions(-) diff --git a/Application.cpp b/Application.cpp index fd7b90f..74d6d95 100644 --- a/Application.cpp +++ b/Application.cpp @@ -285,23 +285,71 @@ void Application::onCleanup() { -double grav = 0.32666666666666666666666666666667; -void Application::onLogic() { - //PhysicsStart +/* - for(size_t i = 0; i < this->_dataModel->getWorkspace()->physicalObjects.size(); i++) +Class HyperSnapSolver + +function getCollisionDepth(Part colliding, part collider); +function getFaceCollision(Part colliding, part collider); + +function eject(Part colliding, Part collider) +{ + if(!colliding.canCollide || !collider.canCollide) + return; + if(getCollisionDepth(colliding, collider) != 0) { + int ejectMultiplier, ejectMultipliery = 1-(collider.Friction+colliding.Friction), ejectMultiplierz = 1-(collider.Friction/2+colliding.Friction/2); + if(colliding.Anchored) + ejectMultiplier = collider.elasticity; + int faceCollided = getFaceCollision(colliding, collider); + if(faceCollided % 3 == 1) + { + ejectMultipliery = ejectMultiplier; + ejectMultiplier = 1-(collider.Friction+colliding.Friction/2); + } + else if(faceCollided % 3 == 2) + { + ejectMultiplierz = ejectMultiplier; + ejectMultiplier = 1-(collider.Friction+colliding.Friction/2); + } + + collider.Velocity *= Vector3.new(colliding.Velocity.x*ejectMultiplier,colliding.Velocity.y*ejectMultipliery,colliding.Velocity.z) + } +} + +*/ + +double grav = 0.32666666666666666666666666666667; +void simGrav(PartInstance * collider) +{ + if(!collider->anchored) { - 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)); - } - } + collider->setPosition(collider->getPosition()+collider->getVelocity()); + collider->setVelocity(collider->getVelocity()-Vector3(0,grav,0)); } } +void eject(PartInstance * colliding, PartInstance * collider) +{ + if(colliding == collider || !colliding->canCollide || !collider->canCollide) + return; + +} + + + +void Application::onLogic() { + //PhysicsStart + for_each (_dataModel->getWorkspace()->partObjects.begin(), _dataModel->getWorkspace()->partObjects.end(), simGrav); + for(size_t i = 0; i < _dataModel->getWorkspace()->partObjects.size(); i++) + { + for(size_t j = 0; j < _dataModel->getWorkspace()->partObjects.size(); j++) + { + eject(_dataModel->getWorkspace()->partObjects[i], _dataModel->getWorkspace()->partObjects[j]); + } + } +} + + void Application::onNetwork() { // Poll net messages here @@ -319,7 +367,8 @@ std::vector Application::getSelection() } void Application::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) { - onLogic(); + if(_dataModel->isRunning()) + onLogic(); _dataModel->getGuiRoot()->update(); diff --git a/MenuButtonListener.cpp b/MenuButtonListener.cpp index 72c4a41..e3aab7b 100644 --- a/MenuButtonListener.cpp +++ b/MenuButtonListener.cpp @@ -1,7 +1,7 @@ #include "MenuButtonListener.h" #include "toggleimagebuttoninstance.h" #include "Globals.h" -void onButton1MouseClick(BaseButtonInstance* button) +void MenuButtonListener::onButton1MouseClick(BaseButtonInstance* button) { if(button->name == "go") { diff --git a/PartInstance.cpp b/PartInstance.cpp index 58a4f70..4c257d7 100644 --- a/PartInstance.cpp +++ b/PartInstance.cpp @@ -83,7 +83,7 @@ void PartInstance::setParent(Instance* parent) { if(WorkspaceInstance* workspace = dynamic_cast(parent)) { - workspace->physicalObjects.erase(std::remove(workspace->physicalObjects.begin(), workspace->physicalObjects.end(), this), workspace->physicalObjects.end()); + workspace->partObjects.erase(std::remove(workspace->partObjects.begin(), workspace->partObjects.end(), this), workspace->partObjects.end()); break; } cparent = cparent->getParent(); @@ -93,7 +93,7 @@ void PartInstance::setParent(Instance* parent) { if(WorkspaceInstance* workspace = dynamic_cast(parent)) { - workspace->physicalObjects.push_back(this); + workspace->partObjects.push_back(this); break; } parent = parent->getParent(); @@ -188,7 +188,7 @@ void PartInstance::setShape(Enum::Shape::Value shape) void PartInstance::setPosition(Vector3 pos) { position = pos; - cFrame = CoordinateFrame(pos); + cFrame = CoordinateFrame(cFrame.rotation, pos); changed = true; } diff --git a/ToggleImageButtonInstance.cpp b/ToggleImageButtonInstance.cpp index 390e5e1..f59fdac 100644 --- a/ToggleImageButtonInstance.cpp +++ b/ToggleImageButtonInstance.cpp @@ -13,7 +13,7 @@ ToggleImageButtonInstance::ToggleImageButtonInstance(G3D::TextureRef newImage, openGLID2 = image2->getOpenGLID(); image_ovr2 = overImage2; if(!image_ovr2.isNull()) - openGLID2_ovr = image_ovr2->getOpenGLID(); + openGLID2_ovr = image_ovr2->getOpenGLID(); image_dn2 = downImage2; if(!image_dn2.isNull()) openGLID2_dn = image_dn2->getOpenGLID(); @@ -62,7 +62,33 @@ void ToggleImageButtonInstance::drawObj(RenderDevice* rd, Vector2 mousePos, bool positionRelative = Vector2(rd->getWidth() + position.x, position.y); } int renderimage = openGLID; - + if(checked) + { + renderimage = openGLID2; + if(selected == true && !image_dn2.isNull() && !disabled) + { + renderimage = openGLID2_dn; + } + else if(disabled) + { + if(!image_ds2.isNull()) + renderimage = openGLID2_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_dn2.isNull()) + { + renderimage = openGLID2_dn; + } + else if(!image_ovr2.isNull()) + { + renderimage = openGLID2_ovr; + } + } + } + else { if(selected == true && !image_dn.isNull() && !disabled) { diff --git a/WorkspaceInstance.h b/WorkspaceInstance.h index ee5409d..c854d6d 100644 --- a/WorkspaceInstance.h +++ b/WorkspaceInstance.h @@ -1,5 +1,6 @@ #pragma once #include "GroupInstance.h" +#include "PartInstance.h" class WorkspaceInstance : public GroupInstance @@ -7,5 +8,5 @@ class WorkspaceInstance : public: WorkspaceInstance(void); ~WorkspaceInstance(void); - std::vector physicalObjects; + std::vector partObjects; }; From 804e3295167c953a64dacb2339e5c8345b435665 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Sun, 8 Mar 2020 14:29:37 -0700 Subject: [PATCH 3/6] Temporarily set it to legacy load --- Application.cpp | 7 +++++-- PartInstance.cpp | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Application.cpp b/Application.cpp index 74d6d95..b5dbe0e 100644 --- a/Application.cpp +++ b/Application.cpp @@ -31,7 +31,7 @@ #include "DeleteListener.h" #include "CameraButtonListener.h" #include "RotateButtonListener.h" - +#define LEGACY_LOAD_G3DFUN_LEVEL Ray testRay; static int cursorid = 0; static int cursorOvrid = 0; @@ -332,6 +332,8 @@ void eject(PartInstance * colliding, PartInstance * collider) { if(colliding == collider || !colliding->canCollide || !collider->canCollide) return; + if(G3D::CollisionDetection::fixedSolidBoxIntersectsFixedSolidBox(collider->getBox(), colliding->getBox())); + collider->setVelocity(collider->getVelocity() - colliding->cFrame.lookVector()); } @@ -662,7 +664,8 @@ void Application::onGraphics(RenderDevice* rd) { glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); //if(_dataModel->getWorkspace() != NULL) - _dataModel->getWorkspace()->render(rd); + + _dataModel->getWorkspace()->render(rd); //else throw std::exception("Workspace not found"); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); diff --git a/PartInstance.cpp b/PartInstance.cpp index 4c257d7..1578823 100644 --- a/PartInstance.cpp +++ b/PartInstance.cpp @@ -1182,6 +1182,7 @@ std::vector PartInstance::getProperties() (LPARAM)anchored, PIT_CHECK )); + sprintf_s(pto, "%g, %g, %g", position.x, position.y, position.z); properties.push_back(createPGI( "Item", "Offset", From 4ff4d54f09a1a7a7e15add8c89eb7c15aba56199 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Sun, 8 Mar 2020 15:44:13 -0700 Subject: [PATCH 4/6] Physics kinda sorta? --- Application.cpp | 4 ++-- Instance.cpp | 1 + Instance.h | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Application.cpp b/Application.cpp index b5dbe0e..c831a4f 100644 --- a/Application.cpp +++ b/Application.cpp @@ -332,8 +332,8 @@ void eject(PartInstance * colliding, PartInstance * collider) { if(colliding == collider || !colliding->canCollide || !collider->canCollide) return; - if(G3D::CollisionDetection::fixedSolidBoxIntersectsFixedSolidBox(collider->getBox(), colliding->getBox())); - collider->setVelocity(collider->getVelocity() - colliding->cFrame.lookVector()); + if(G3D::CollisionDetection::fixedSolidBoxIntersectsFixedSolidBox(collider->getBox(), colliding->getBox())) + collider->setVelocity(collider->getVelocity().reflectionDirection(colliding->cFrame.upVector())/1.3); } diff --git a/Instance.cpp b/Instance.cpp index 996aaac..37bbcf7 100644 --- a/Instance.cpp +++ b/Instance.cpp @@ -3,6 +3,7 @@ #include "Instance.h" + Instance::Instance(void) { parent = NULL; diff --git a/Instance.h b/Instance.h index dcee204..7e25dce 100644 --- a/Instance.h +++ b/Instance.h @@ -1,6 +1,7 @@ #pragma once #include #include "propertyGrid.h" +#include "map" class Instance { @@ -31,5 +32,6 @@ protected: std::string className; Instance* parent; // Another pointer. PROPGRIDITEM createPGI(LPSTR catalog, LPSTR propName, LPSTR propDesc, LPARAM curVal, INT type, TCHAR choices[] = NULL); - +private: + static const std::map g_logLevelsDescriptions; }; From 9c76bf6956da449af3f8d71ffd0c8f69cfa0abce Mon Sep 17 00:00:00 2001 From: andreja6 Date: Sun, 8 Mar 2020 20:06:13 -0700 Subject: [PATCH 5/6] Added controllerflags and primary parts --- GroupInstance.h | 3 ++- PVInstance.cpp | 1 + PVInstance.h | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/GroupInstance.h b/GroupInstance.h index 40d870d..072645e 100644 --- a/GroupInstance.h +++ b/GroupInstance.h @@ -1,5 +1,5 @@ #pragma once -#include "PVInstance.h" +#include "PartInstance.h" class GroupInstance : public PVInstance @@ -11,4 +11,5 @@ public: virtual std::vector getProperties(); virtual void PropUpdate(LPPROPGRIDITEM &pItem); std::vector unGroup(); + PartInstance * primaryPart; }; diff --git a/PVInstance.cpp b/PVInstance.cpp index 206de12..f94c6d2 100644 --- a/PVInstance.cpp +++ b/PVInstance.cpp @@ -4,6 +4,7 @@ PVInstance::PVInstance(void) { Instance::Instance(); nameShown = false; + controllerFlagShown = true; className = "PVInstance"; listicon = 0; } diff --git a/PVInstance.h b/PVInstance.h index 9f6e65d..e150523 100644 --- a/PVInstance.h +++ b/PVInstance.h @@ -12,4 +12,5 @@ public: virtual std::vector getProperties(); virtual void PropUpdate(LPPROPGRIDITEM &pItem); bool nameShown; + bool controllerFlagShown; }; From 44d8947975afb56d085941616cd8358c99869451 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Sun, 8 Mar 2020 23:22:42 -0700 Subject: [PATCH 6/6] Added controllers and flags --- Enum.h | 6 ++++ GUDButtonListener.cpp | 4 +++ GroupInstance.cpp | 35 +++++++++++++++++++++++ GroupInstance.h | 1 + PVInstance.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++ PVInstance.h | 18 ++++++++++++ 6 files changed, 128 insertions(+) diff --git a/Enum.h b/Enum.h index 68c0755..5c4dea7 100644 --- a/Enum.h +++ b/Enum.h @@ -14,4 +14,10 @@ namespace Enum Ball = 0, Block = 1, Cylinder = 2 }; } + namespace Controller + { + enum Value { + Player = 7, KeyboardRight = 1, KeyboardLeft = 2, Joypad1 = 3, Joypad2 = 4, Chase = 5, Flee = 6, None = 0 + }; + } } \ No newline at end of file diff --git a/GUDButtonListener.cpp b/GUDButtonListener.cpp index aae080a..f493cad 100644 --- a/GUDButtonListener.cpp +++ b/GUDButtonListener.cpp @@ -44,6 +44,10 @@ void GUDButtonListener::onButton1MouseClick(BaseButtonInstance* button) if(g_selectedInstances.at(i)->canDelete) { g_selectedInstances.at(i)->setParent(inst); + if(PartInstance* part = dynamic_cast(g_selectedInstances.at(i))) + { + inst->primaryPart = part; + } } /*tempinst->setPosition(Vector3(tempPos.x, tempPos.y + tempSize.y, tempPos.z)); g_usableApp->cameraController.centerCamera(g_selectedInstances.at(0));*/ diff --git a/GroupInstance.cpp b/GroupInstance.cpp index f6be69c..908e99f 100644 --- a/GroupInstance.cpp +++ b/GroupInstance.cpp @@ -6,6 +6,7 @@ GroupInstance::GroupInstance(void) name = "Model"; className = "GroupInstance"; listicon = 12; + primaryPart = NULL; } GroupInstance::GroupInstance(const GroupInstance &oinst) @@ -14,6 +15,7 @@ GroupInstance::GroupInstance(const GroupInstance &oinst) name = "Model"; className = "GroupInstance"; listicon = 12; + primaryPart = NULL; } GroupInstance::~GroupInstance(void) @@ -39,4 +41,37 @@ std::vector GroupInstance::unGroup() children[0]->setParent(parent); } return child; +} + +void GroupInstance::render(RenderDevice * rd) +{ + Instance::render(rd); + if(primaryPart != NULL && controllerFlagShown && getControllerColor(controller) != Color3::gray()) + { + rd->disableLighting(); + Vector3 vec = Vector3(0,0,0); + Vector3 up = Vector3(0,8,0); + rd->setColor(getControllerColor(controller)); + rd->setObjectToWorldMatrix(primaryPart->cFrame); + rd->beforePrimitive(); + + glBegin(GL_LINES); + glVertex3f(vec.x, vec.y, vec.z); + glVertex3f(up.x, up.y, up.z); + glEnd(); + + glBegin( GL_TRIANGLES ); + glVertex3f(up.x, up.y-2, up.z); + glVertex3f(up.x, up.y-1, up.z-2); + glVertex3f(up.x, up.y, up.z); + + glVertex3f(up.x, up.y, up.z); + glVertex3f(up.x, up.y-1, up.z-2); + glVertex3f(up.x, up.y-2, up.z); + + glEnd(); + rd->afterPrimitive(); + rd->setColor(Color3::white()); + rd->enableLighting(); + } } \ No newline at end of file diff --git a/GroupInstance.h b/GroupInstance.h index 072645e..08baed3 100644 --- a/GroupInstance.h +++ b/GroupInstance.h @@ -12,4 +12,5 @@ public: virtual void PropUpdate(LPPROPGRIDITEM &pItem); std::vector unGroup(); PartInstance * primaryPart; + void render(RenderDevice * r); }; diff --git a/PVInstance.cpp b/PVInstance.cpp index f94c6d2..5dc627c 100644 --- a/PVInstance.cpp +++ b/PVInstance.cpp @@ -7,6 +7,7 @@ PVInstance::PVInstance(void) controllerFlagShown = true; className = "PVInstance"; listicon = 0; + controller = (Enum::Controller::Value)0; } PVInstance::PVInstance(const PVInstance &oinst) @@ -22,6 +23,46 @@ void PVInstance::postRender(RenderDevice* rd) { } +static TCHAR* enumStr(int controller) +{ + switch(controller) + { + case Enum::Controller::None: + return "None"; + case Enum::Controller::KeyboardLeft: + return "KeyboardLeft"; + case Enum::Controller::KeyboardRight: + return "KeyboardRight"; + case Enum::Controller::Joypad1: + return "Joypad1"; + case Enum::Controller::Joypad2: + return "Joypad2"; + case Enum::Controller::Chase: + return "Joypad1"; + case Enum::Controller::Flee: + return "Joypad2"; + } +} + +static Enum::Controller::Value strEnum(TCHAR * tval) +{ + if(strcmp(tval, "KeyboardLeft") == 0) + return Enum::Controller::KeyboardLeft; + if(strcmp(tval, "KeyboardRight") == 0) + return Enum::Controller::KeyboardRight; + if(strcmp(tval, "Joypad1") == 0) + return Enum::Controller::Joypad1; + if(strcmp(tval, "Joypad2") == 0) + return Enum::Controller::Joypad2; + if(strcmp(tval, "Chase") == 0) + return Enum::Controller::Chase; + if(strcmp(tval, "Flee") == 0) + return Enum::Controller::Flee; + return Enum::Controller::None; +} + + + std::vector PVInstance::getProperties() { std::vector properties = Instance::getProperties(); @@ -31,6 +72,21 @@ std::vector PVInstance::getProperties() "This chooses whether the item name is shown", nameShown, PIT_CHECK)); + properties.push_back(createPGI( + "Item", + "ControllerFlagShown", + "This chooses whether the item's ControllerFlag is shown", + controllerFlagShown, + PIT_CHECK)); + properties.push_back(createPGI( + "Behaviour", + "Controller", + "This chooses what type of controller is used", + (LPARAM)enumStr(controller), + PIT_COMBO, + TEXT("None\0KeyboardRight\0KeyboardLeft\0Joypad1\0Joypad2\0Chase\0Flee") + )); + return properties; } void PVInstance::PropUpdate(LPPROPGRIDITEM &pItem) @@ -39,5 +95,13 @@ void PVInstance::PropUpdate(LPPROPGRIDITEM &pItem) { nameShown = (bool)pItem->lpCurValue; } + if(strcmp(pItem->lpszPropName, "ControllerFlagShown") == 0) + { + controllerFlagShown = (bool)pItem->lpCurValue; + } + if(strcmp(pItem->lpszPropName, "Controller") == 0) + { + controller = strEnum((TCHAR *)pItem->lpCurValue); + } else Instance::PropUpdate(pItem); } diff --git a/PVInstance.h b/PVInstance.h index e150523..c22436f 100644 --- a/PVInstance.h +++ b/PVInstance.h @@ -1,5 +1,6 @@ #pragma once #include "instance.h" +#include "enum.h" class PVInstance : public Instance @@ -13,4 +14,21 @@ public: virtual void PropUpdate(LPPROPGRIDITEM &pItem); bool nameShown; bool controllerFlagShown; + Enum::Controller::Value controller; +protected: + static G3D::Color3 getControllerColor(int controller) + { + switch(controller) + { + case Enum::Controller::KeyboardLeft: + return Color3::red(); + case Enum::Controller::KeyboardRight: + return Color3::blue(); + case Enum::Controller::Chase: + return Color3::black(); + case Enum::Controller::Flee: + return Color3::yellow(); + } + return Color3::gray(); + } };