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";
}
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* > Instance::getChildren()
std::vector<Instance* > Instance::getAllChildren()
{
if(!children.empty())
{
std::vector<Instance* > totalchildren = children;
for(size_t i = 0; i < children.size(); i++)
{
std::vector<Instance* > subchildren = children.at(i)->getAllChildren();
if(!subchildren.empty())
totalchildren.insert(totalchildren.end(), subchildren.begin(), subchildren.end());
}
return totalchildren;
}
return children;
}
void Instance::setParent(Instance* newParent)

View File

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

View File

@@ -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)
{
}

View File

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

View File

@@ -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<Instance*> 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<Instance*> 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);