From 7e2eb2c694751a12e28a0bbc35073cdc19d4b7b2 Mon Sep 17 00:00:00 2001 From: andreja6 Date: Thu, 25 Oct 2018 18:56:00 -0700 Subject: [PATCH] Parts with "ShowName" enabled now do what they are supposed to. Huzzah! --- Globals.cpp | 2 +- Globals.h | 3 +-- PVInstance.cpp | 17 ++++++++++++++++- PVInstance.h | 2 ++ PartInstance.cpp | 33 ++++++++++++++++++++++++--------- PartInstance.h | 2 +- main.cpp | 14 ++++++++++---- 7 files changed, 55 insertions(+), 18 deletions(-) diff --git a/Globals.cpp b/Globals.cpp index 3f63fb1..1c00f66 100644 --- a/Globals.cpp +++ b/Globals.cpp @@ -8,7 +8,7 @@ int const Globals::patch = 2; int Globals::surfaceId = 2; bool Globals::showMouse = true; bool Globals::useMousePoint = false; -std::stack postRenderStack = std::stack(); +std::vector postRenderStack = std::vector(); const std::string Globals::PlaceholderName = "Dynamica"; std::vector g_selectedInstances = std::vector(); bool running = false; diff --git a/Globals.h b/Globals.h index 4bc98fb..09efa1b 100644 --- a/Globals.h +++ b/Globals.h @@ -1,7 +1,6 @@ #pragma once #include "DataModelInstance.h" #include -#include class Globals { @@ -21,6 +20,6 @@ public: static const std::string PlaceholderName; }; -extern std::stack postRenderStack; +extern std::vector postRenderStack; extern std::vector g_selectedInstances; extern bool running; \ No newline at end of file diff --git a/PVInstance.cpp b/PVInstance.cpp index 271ea50..ea85c51 100644 --- a/PVInstance.cpp +++ b/PVInstance.cpp @@ -3,6 +3,7 @@ PVInstance::PVInstance(void) { Instance::Instance(); + nameShown = false; className = "PVInstance"; } @@ -15,12 +16,26 @@ PVInstance::~PVInstance(void) { } +void PVInstance::postRender(RenderDevice* rd) +{ +} + std::vector PVInstance::getProperties() { std::vector properties = Instance::getProperties(); + properties.push_back(createPGI( + "Item", + "NameShown", + "This chooses whether the item name is shown", + false, + PIT_CHECK)); return properties; } void PVInstance::PropUpdate(LPPROPGRIDITEM &pItem) { - Instance::PropUpdate(pItem); + if(strcmp(pItem->lpszPropName, "NameShown") == 0) + { + nameShown = (bool)pItem->lpCurValue; + } + else Instance::PropUpdate(pItem); } diff --git a/PVInstance.h b/PVInstance.h index 99f2233..9f6e65d 100644 --- a/PVInstance.h +++ b/PVInstance.h @@ -8,6 +8,8 @@ public: PVInstance(void); ~PVInstance(void); PVInstance(const PVInstance &oinst); + virtual void postRender(RenderDevice* rd); virtual std::vector getProperties(); virtual void PropUpdate(LPPROPGRIDITEM &pItem); + bool nameShown; }; diff --git a/PartInstance.cpp b/PartInstance.cpp index a321d06..f6d1136 100644 --- a/PartInstance.cpp +++ b/PartInstance.cpp @@ -27,18 +27,31 @@ PartInstance::PartInstance(void) : _bevelSize(0.03f), _parseVert(0), _debugTimer void PartInstance::postRender(RenderDevice *rd) { - G3D::GFontRef fntdominant = NULL; - if(fntdominant.notNull()) + if(!nameShown) + return; + G3D::GFontRef fnt = NULL; + Instance* dm = parent; + while(dm != NULL) { - Vector3 gamepoint = cFrame.translation; + if(DataModelInstance* mod = dynamic_cast(dm)) + { + fnt = mod->font; + break; + } + dm = dm->getParent(); + } + if(!fnt.isNull()) + { + Vector3 gamepoint = position + Vector3(0,1.5,0); Vector3 camerapoint = rd->getCameraToWorldMatrix().translation; float distance = pow(pow((double)gamepoint.x - (double)camerapoint.x, 2) + pow((double)gamepoint.y - (double)camerapoint.y, 2) + pow((double)gamepoint.z - (double)camerapoint.z, 2), 0.5); - if(distance < 50 && distance > -50) - + if(distance < 100 && distance > -100) { if(distance < 0) distance = distance*-1; - fntdominant->draw3D(rd, "Testing", CoordinateFrame(rd->getCameraToWorldMatrix().rotation, gamepoint), 0.04*distance, Color3::yellow(), Color3::black(), G3D::GFont::XALIGN_CENTER, G3D::GFont::YALIGN_CENTER); + glDisable(GL_DEPTH_TEST); + fnt->draw3D(rd, name, CoordinateFrame(rd->getCameraToWorldMatrix().rotation, gamepoint), 0.03*distance, Color3::yellow(), Color3::black(), G3D::GFont::XALIGN_CENTER, G3D::GFont::YALIGN_CENTER); + glEnable(GL_DEPTH_TEST); } } } @@ -131,7 +144,7 @@ void PartInstance::setCFrame(CoordinateFrame coordinateFrame) // Can probably be deleted CoordinateFrame PartInstance::getCFrameRenderBased() { - return CoordinateFrame(getCFrame().rotation,Vector3(getCFrame().translation.x, getCFrame().translation.y, getCFrame().translation.z)); + return cFrame;//CoordinateFrame(getCFrame().rotation,Vector3(getCFrame().translation.x, getCFrame().translation.y, getCFrame().translation.z)); } #ifdef NEW_BOX_RENDER Box PartInstance::getBox() @@ -242,6 +255,8 @@ bool PartInstance::isUniqueVertex(Vector3 pos) #ifdef NEW_BOX_RENDER void PartInstance::render(RenderDevice* rd) { + if(nameShown) + postRenderStack.push_back(this); if (changed) { getBox(); @@ -519,12 +534,12 @@ void PartInstance::PropUpdate(LPPROPGRIDITEM &item) } } - else Instance::PropUpdate(item); + else PVInstance::PropUpdate(item); } std::vector PartInstance::getProperties() { - std::vector properties = Instance::getProperties(); + std::vector properties = PVInstance::getProperties(); properties.push_back(createPGI( diff --git a/PartInstance.h b/PartInstance.h index 5c507f3..fe2a3e5 100644 --- a/PartInstance.h +++ b/PartInstance.h @@ -10,7 +10,7 @@ public: PartInstance(void); PartInstance(const PartInstance &oinst); Instance* clone() const { return new PartInstance(*this); } - void PartInstance::postRender(RenderDevice* rd); + virtual void PartInstance::postRender(RenderDevice* rd); ~PartInstance(void); virtual void render(RenderDevice*); Vector3 velocity; diff --git a/main.cpp b/main.cpp index 0f7333f..6d8016f 100644 --- a/main.cpp +++ b/main.cpp @@ -1211,7 +1211,7 @@ void Demo::onGraphics(RenderDevice* rd) { renderDevice->setLight(0, GLight::directional(lighting.lightDirection, lighting.lightColor)); renderDevice->setAmbientLightColor(lighting.ambient); - +/* Vector3 gamepoint = Vector3(0, 5, 0); Vector3 camerapoint = rd->getCameraToWorldMatrix().translation; float distance = pow(pow((double)gamepoint.x - (double)camerapoint.x, 2) + pow((double)gamepoint.y - (double)camerapoint.y, 2) + pow((double)gamepoint.z - (double)camerapoint.z, 2), 0.5); @@ -1222,7 +1222,7 @@ void Demo::onGraphics(RenderDevice* rd) { distance = distance*-1; fntdominant->draw3D(rd, "Testing", CoordinateFrame(rd->getCameraToWorldMatrix().rotation, gamepoint), 0.04*distance, Color3::yellow(), Color3::black(), G3D::GFont::XALIGN_CENTER, G3D::GFont::YALIGN_CENTER); } - +*/ rd->beforePrimitive(); @@ -1248,11 +1248,17 @@ void Demo::onGraphics(RenderDevice* rd) { while(!postRenderStack.empty()) { - Instance* inst = postRenderStack.top(); - postRenderStack.pop(); + Instance* inst = postRenderStack.at(0); + postRenderStack.erase(postRenderStack.begin()); + if(PVInstance* pinst = dynamic_cast(inst)) + { + pinst->postRender(rd); + } } + + renderDevice->disableLighting(); if (sky.notNull()) {