From 7b4abe3efe4e205cad5498053a8961b9fb684b2a Mon Sep 17 00:00:00 2001 From: andreja6 Date: Thu, 25 Oct 2018 15:43:45 -0700 Subject: [PATCH] Made properties "dynamically update", no longer simply says NO when object makes no sense --- DataModelInstance.cpp | 33 +++++++++++++++++++++++++++++++++ DataModelInstance.h | 5 ++++- PartInstance.cpp | 3 +-- PropertyWindow.cpp | 1 + main.cpp | 30 +++++++++++++++++++----------- 5 files changed, 58 insertions(+), 14 deletions(-) diff --git a/DataModelInstance.cpp b/DataModelInstance.cpp index 904c6d6..ae18fc3 100644 --- a/DataModelInstance.cpp +++ b/DataModelInstance.cpp @@ -31,17 +31,50 @@ DataModelInstance::~DataModelInstance(void) void DataModelInstance::setMessage(std::string msg) { message = msg; + isBrickCount = false; showMessage = true; } void DataModelInstance::clearMessage() { showMessage = false; + isBrickCount = false; message = ""; } +void DataModelInstance::setMessageBrickCount() +{ + isBrickCount = true; + showMessage = true; +} + void DataModelInstance::drawMessage(RenderDevice* rd) { + if(isBrickCount) + { + int brickCount = 0; + int instCount = 0; + std::vector inst = getAllChildren(); + for(size_t i = 0; i < inst.size(); i++) + { + if(PartInstance* moveTo = dynamic_cast(inst.at(i))) + { + brickCount++; + } + else + { + instCount++; + } + } + char brkc[12]; + sprintf(brkc, "%d", brickCount); + char instc[12]; + sprintf(instc, "%d", instCount); + message = "Bricks: "; + message += brkc; + message += " Snaps: "; + message += instc; + } if(showMessage && !font.isNull()) { int x = rd->getWidth()/2; diff --git a/DataModelInstance.h b/DataModelInstance.h index 96ad7a5..26a4be1 100644 --- a/DataModelInstance.h +++ b/DataModelInstance.h @@ -1,6 +1,7 @@ #pragma once #include "WorkspaceInstance.h" #include "LevelInstance.h" +#include "PartInstance.h" class DataModelInstance : public Instance @@ -9,6 +10,7 @@ public: DataModelInstance(void); ~DataModelInstance(void); void setMessage(std::string); + void setMessageBrickCount(); void clearMessage(); void drawMessage(RenderDevice*); WorkspaceInstance* getWorkspace(); @@ -26,6 +28,7 @@ public: void setMousePos(int x,int y); void setMousePos(Vector2 pos); bool mouseButton1Down; - +private: + bool isBrickCount; }; diff --git a/PartInstance.cpp b/PartInstance.cpp index 098a2db..963842f 100644 --- a/PartInstance.cpp +++ b/PartInstance.cpp @@ -152,6 +152,7 @@ bool PartInstance::collides(Box box) void PartInstance::render(RenderDevice* rd) { + if(changed) Box box = getBox(); @@ -257,7 +258,6 @@ void PartInstance::PropUpdate(LPPROPGRIDITEM &item) sprintf(pto, "%g, %g, %g", cFrame.translation.x, cFrame.translation.y, cFrame.translation.z, "what"); LPCSTR str = LPCSTR(pto); item->lpCurValue = (LPARAM)str; - MessageBox(NULL, "NO","NO", MB_OK); } else { @@ -286,7 +286,6 @@ void PartInstance::PropUpdate(LPPROPGRIDITEM &item) sprintf(pto, "%g, %g, %g", cFrame.translation.x, cFrame.translation.y, cFrame.translation.z, "what"); LPCSTR str = LPCSTR(pto); item->lpCurValue = (LPARAM)str; - MessageBox(NULL, "NO","NO", MB_OK); } else { diff --git a/PropertyWindow.cpp b/PropertyWindow.cpp index d6364fb..22881bd 100644 --- a/PropertyWindow.cpp +++ b/PropertyWindow.cpp @@ -164,6 +164,7 @@ LRESULT CALLBACK PropProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) LPNMPROPGRID lpnmp = (LPNMPROPGRID)pnm; LPPROPGRIDITEM item = PropGrid_GetItemData(pnm->hwndFrom,lpnmp->iIndex); selectedInstance->PropUpdate(item); + propWind->SetProperties(selectedInstance); } } break; diff --git a/main.cpp b/main.cpp index b416f48..0758a10 100644 --- a/main.cpp +++ b/main.cpp @@ -786,7 +786,7 @@ void Demo::onInit() { test->setSize(Vector3(4,1,2)); test->setPosition(Vector3(-2,5,0)); - + //dataModel->setMessageBrickCount(); test = makePart(); @@ -851,7 +851,7 @@ std::vector Demo::getSelection() return g_selectedInstances; } void Demo::onSimulation(RealTime rdt, SimTime sdt, SimTime idt) { - if(!running) + if(running) { std::vector objects = dataModel->getWorkspace()->getAllChildren(); for(size_t i = 0; i < objects.size(); i++) @@ -1182,6 +1182,8 @@ void Demo::onGraphics(RenderDevice* rd) { } } + + if(Globals::useMousePoint) { mousepos = Globals::mousepoint; @@ -1208,10 +1210,25 @@ void Demo::onGraphics(RenderDevice* rd) { renderDevice->setLight(0, GLight::directional(lighting.lightDirection, lighting.lightColor)); renderDevice->setAmbientLightColor(lighting.ambient); + + Vector3 gamepoint = Vector3(0, 5, 0); + Vector3 camerapoint = rd->getCameraToWorldMatrix().translation; + float distance = pow(pow((double)gamepoint.x - (double)camerapoint.x, 2) + pow((double)gamepoint.y - (double)camerapoint.y, 2) + pow((double)gamepoint.z - (double)camerapoint.z, 2), 0.5); + if(distance < 50 && distance > -50) + + { + if(distance < 0) + distance = distance*-1; + fntdominant->draw3D(rd, "Testing", CoordinateFrame(rd->getCameraToWorldMatrix().rotation, gamepoint), 0.04*distance, Color3::yellow(), Color3::black(), G3D::GFont::XALIGN_CENTER, G3D::GFont::YALIGN_CENTER); + } + rd->beforePrimitive(); + + dataModel->getWorkspace()->render(rd); rd->afterPrimitive(); + if(g_selectedInstances.size() > 0) { for(size_t i = 0; i < g_selectedInstances.size(); i++) @@ -1226,16 +1243,7 @@ void Demo::onGraphics(RenderDevice* rd) { } - //Vector3 gamepoint = Vector3(0, 5, 0); - //Vector3 camerapoint = rd->getCameraToWorldMatrix().translation; - //float distance = pow(pow((double)gamepoint.x - (double)camerapoint.x, 2) + pow((double)gamepoint.y - (double)camerapoint.y, 2) + pow((double)gamepoint.z - (double)camerapoint.z, 2), 0.5); - //if(distance < 50 && distance > -50) - //{ - // if(distance < 0) - // distance = distance*-1; - // fntdominant->draw3D(rd, "Testing", CoordinateFrame(rd->getCameraToWorldMatrix().rotation, gamepoint), 0.04*distance, Color3::yellow(), Color3::black(), G3D::GFont::XALIGN_CENTER, G3D::GFont::YALIGN_CENTER); - //} renderDevice->disableLighting();