mirror of
https://github.com/devZoGok/vb01.git
synced 2026-08-26 19:43:30 +00:00
removable lights and skybox
This commit is contained in:
@@ -26,9 +26,7 @@ namespace vb01{
|
||||
for(Text *t : texts)
|
||||
delete t;
|
||||
for(Node *c : children){
|
||||
Node *par=c->getParent();
|
||||
if(par)
|
||||
par->dettachChild(c);
|
||||
//dettachChild(c);
|
||||
delete c;
|
||||
}
|
||||
}
|
||||
@@ -49,27 +47,11 @@ namespace vb01{
|
||||
}
|
||||
|
||||
void Node::attachChild(Node *child){
|
||||
/*
|
||||
Node *parent=getParent();
|
||||
while(parent){
|
||||
parent->getDescendants().push_back(child);
|
||||
parent=parent->getParent();
|
||||
}
|
||||
descendants.push_back(child);
|
||||
*/
|
||||
child->setParent(this);
|
||||
children.push_back(child);
|
||||
}
|
||||
|
||||
void Node::dettachChild(Node *child){
|
||||
/*
|
||||
Node *parent=getParent();
|
||||
while(parent){
|
||||
parent->getDescendants().push_back(child);
|
||||
parent=parent->getParent();
|
||||
}
|
||||
descendants.push_back(child);
|
||||
*/
|
||||
child->setParent(nullptr);
|
||||
int id=-1;
|
||||
for(int i=0;i<children.size()&&id==-1;i++)
|
||||
@@ -89,26 +71,18 @@ namespace vb01{
|
||||
}
|
||||
|
||||
void Node::addLight(Light *light){
|
||||
Root::getSingleton()->numLights++;
|
||||
lights.push_back(light);
|
||||
light->setNode(this);
|
||||
Root *root=Root::getSingleton();
|
||||
updateShaders();
|
||||
}
|
||||
|
||||
Node *rootNode=Root::getSingleton()->getRootNode();
|
||||
vector<Node*> descendants;
|
||||
rootNode->getDescendants(rootNode,descendants);
|
||||
descendants.push_back(rootNode);
|
||||
root->numLights++;
|
||||
for(Node *n : descendants){
|
||||
vector<Mesh*> meshes=n->getMeshes();
|
||||
for(Mesh *m : meshes){
|
||||
Material *mat=m->getMaterial();
|
||||
string str=to_string(root->numLights>0?root->numLights:1);
|
||||
if(mat){
|
||||
//mat->getShader()->editShader(true,'=',';',str);
|
||||
mat->getShader()->editShader(false,'=',';',str);
|
||||
}
|
||||
}
|
||||
}
|
||||
void Node::removeLight(int id){
|
||||
Root::getSingleton()->numLights--;
|
||||
Light *light=lights[id];
|
||||
light->setNode(nullptr);
|
||||
lights.erase(lights.begin()+id);
|
||||
updateShaders();
|
||||
}
|
||||
|
||||
void Node::addText(Text *text){
|
||||
@@ -242,4 +216,23 @@ namespace vb01{
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
void Node::updateShaders(){
|
||||
Root *root=Root::getSingleton();
|
||||
Node *rootNode=Root::getSingleton()->getRootNode();
|
||||
vector<Node*> descendants;
|
||||
rootNode->getDescendants(rootNode,descendants);
|
||||
descendants.push_back(rootNode);
|
||||
for(Node *n : descendants){
|
||||
vector<Mesh*> meshes=n->getMeshes();
|
||||
for(Mesh *m : meshes){
|
||||
Material *mat=m->getMaterial();
|
||||
string str=to_string(root->numLights>0?root->numLights:1);
|
||||
if(mat){
|
||||
//mat->getShader()->editShader(true,'=',';',str);
|
||||
mat->getShader()->editShader(false,'=',';',str);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace vb01{
|
||||
void attachChild(Node*);
|
||||
void dettachChild(Node*);
|
||||
void addLight(Light*);
|
||||
void removeLight(int);
|
||||
void addText(Text*);
|
||||
void lookAt(Vector3,Vector3);
|
||||
Transform getWorldTransform();
|
||||
@@ -57,6 +58,8 @@ namespace vb01{
|
||||
inline void setVisible(bool v){this->visible=v;}
|
||||
void getDescendants(Node*,std::vector<Node*>&);
|
||||
protected:
|
||||
void updateShaders();
|
||||
|
||||
bool visible=true;
|
||||
Vector3 pos,scale;
|
||||
Quaternion orientation;
|
||||
|
||||
@@ -162,4 +162,10 @@ namespace vb01{
|
||||
skyboxMat->addDiffuseMap(textures);
|
||||
skybox->setMaterial(skyboxMat);
|
||||
}
|
||||
|
||||
void Root::removeSkybox(){
|
||||
Material *mat=skybox->getMaterial();
|
||||
delete skybox;
|
||||
skybox=nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ namespace vb01{
|
||||
inline void setBlurLevel(bool level){this->blurLevel=level;}
|
||||
inline Box* getSkybox(){return skybox;}
|
||||
void createSkybox(std::string[6]);
|
||||
void removeSkybox();
|
||||
static Root* getSingleton();
|
||||
int numLights=0;
|
||||
private:
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define VECTOR_H
|
||||
|
||||
#include<cmath>
|
||||
#include<iostream>
|
||||
|
||||
namespace vb01{
|
||||
struct Vector4{
|
||||
@@ -67,6 +68,7 @@ namespace vb01{
|
||||
float getLength(){return std::sqrt(getLengthSq());}
|
||||
float dot(Vector2 v){return x*v.x+y*v.y;}
|
||||
float getAngleBetween(Vector2 v){return std::acos(dot(v));}
|
||||
float getDistanceFrom(Vector2 v){return (v-*this).getLengthSq();}
|
||||
Vector2 norm(){return *this/getLength();}
|
||||
|
||||
float x,y;
|
||||
|
||||
Reference in New Issue
Block a user