Changed how render works

This commit is contained in:
andreja6
2018-05-01 19:58:58 -07:00
parent 930aee06dc
commit 9999eb62e4
5 changed files with 46 additions and 13 deletions

View File

@@ -14,6 +14,14 @@ Instance::Instance(void)
className = "BaseInstance"; className = "BaseInstance";
} }
void Instance::render(RenderDevice* rd)
{
for(size_t i = 0; i < children.size(); i++)
{
children.at(i)->render(rd);
}
}
Instance::~Instance(void) Instance::~Instance(void)
{ {
for(size_t i = 0; i < children.size(); i++) for(size_t i = 0; i < children.size(); i++)
@@ -33,15 +41,20 @@ std::vector<Instance* > Instance::getChildren()
} }
std::vector<Instance* > Instance::getAllChildren() std::vector<Instance* > Instance::getAllChildren()
{
if(!children.empty())
{ {
std::vector<Instance* > totalchildren = children; std::vector<Instance* > totalchildren = children;
for(size_t i = 0; i < children.size(); i++) for(size_t i = 0; i < children.size(); i++)
{ {
std::vector<Instance* > subchildren = children.at(i)->getAllChildren(); std::vector<Instance* > subchildren = children.at(i)->getAllChildren();
if(!subchildren.empty())
totalchildren.insert(totalchildren.end(), subchildren.begin(), subchildren.end()); totalchildren.insert(totalchildren.end(), subchildren.begin(), subchildren.end());
} }
return totalchildren; return totalchildren;
} }
return children;
}
void Instance::setParent(Instance* newParent) void Instance::setParent(Instance* newParent)
{ {

View File

@@ -7,7 +7,7 @@ public:
Instance(void); Instance(void);
virtual ~Instance(void); virtual ~Instance(void);
std::string name; std::string name;
virtual void render(RenderDevice*);
std::vector<Instance*> children; // All children. std::vector<Instance*> children; // All children.
std::string getClassName(); std::string getClassName();
Instance* findFirstChild(std::string); Instance* findFirstChild(std::string);

View File

@@ -93,6 +93,19 @@ Box PhysicalInstance::getBox()
return itemBox; 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) PhysicalInstance::~PhysicalInstance(void)
{ {
} }

View File

@@ -7,7 +7,7 @@ class PhysicalInstance :
public: public:
PhysicalInstance(void); PhysicalInstance(void);
~PhysicalInstance(void); ~PhysicalInstance(void);
virtual void render(RenderDevice*);
Vector3 velocity; Vector3 velocity;
Vector3 rotvelocity; Vector3 rotvelocity;
CoordinateFrame cFrame; CoordinateFrame cFrame;

View File

@@ -1032,7 +1032,6 @@ void Demo::onUserInput(UserInput* ui) {
showMouse = true; showMouse = true;
app->debugController.setActive(false); app->debugController.setActive(false);
} }
if(ui->keyPressed(SDLK_LSHIFT) || ui->keyPressed(SDLK_RSHIFT)) if(ui->keyPressed(SDLK_LSHIFT) || ui->keyPressed(SDLK_RSHIFT))
{ {
moveRate = 1; moveRate = 1;
@@ -1443,16 +1442,24 @@ void Demo::onGraphics(RenderDevice* rd) {
//app->renderDevice->pushState(); //app->renderDevice->pushState();
//app->renderDevice->popState(); //app->renderDevice->popState();
dataModel->getWorkspace()->render(rd);
std::vector<Instance*> instances = dataModel->getWorkspace()->getAllChildren(); 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<Instance*> instances = dataModel->getWorkspace()->getAllChildren();
for(size_t i = 0; i < instances.size(); i++) for(size_t i = 0; i < instances.size(); i++)
{ {
Instance* instance = instances.at(i); Instance* instance = instances.at(i);
if(instance->getClassName() == "Part") if(instance->getClassName() == "Part")
{ {
instance->render(rd);
PhysicalInstance* part = (PhysicalInstance*)instance; 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) if(selectedInstance == part)
{ {
Vector3 size = part->getSize(); Vector3 size = part->getSize();
@@ -1463,7 +1470,7 @@ void Demo::onGraphics(RenderDevice* rd) {
} }
} }
Box box; Box box;*/
//Draw::ray(testRay, rd, Color3::orange(), 1); //Draw::ray(testRay, rd, Color3::orange(), 1);