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);