3 types of lights

supported number of n lights
This commit is contained in:
devZoGok
2021-10-18 19:03:19 +03:00
parent 0083f9e5b8
commit aebc069053
16 changed files with 350 additions and 23 deletions
+28
View File
@@ -1,5 +1,9 @@
#include"root.h"
#include"node.h"
#include"mesh.h"
#include"light.h"
using namespace std;
namespace vb01{
Node::Node(Vector3 pos){
@@ -11,16 +15,40 @@ namespace vb01{
void Node::update(){
if(mesh)
mesh->update();
for(Light *l : lights)
l->update();
for(Node *c : children)
c->update();
}
void Node::attachChild(Node *child){
Node *parent=getParent();
while(parent){
parent->getDescendants().push_back(child);
parent=parent->getParent();
}
children.push_back(child);
descendants.push_back(child);
}
void Node::setObject(Mesh *mesh){
this->mesh=mesh;
mesh->setNode(this);
}
void Node::addLight(Light *light){
lights.push_back(light);
light->setNode(this);
Node *rootNode=Root::getSingleton()->getRootNode();
vector<Node*> descendants=rootNode->getDescendants();
descendants.push_back(rootNode);
int numLights=0;
for(Node *n : descendants)
numLights+=n->getNumLights();
for(Node *n : descendants)
if(n->getMesh())
if(n->getMesh()->getMaterial())
n->getMesh()->getMaterial()->getShader()->setNumLights(numLights>0?numLights:1);
}
}