Implemented KROctree class to be used by upcoming occlusion culling and physics features

Refactored scene graph notification system structures to be owned by the KRScene object
Merged Mike's changes

--HG--
extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%4082
This commit is contained in:
kearwood
2012-08-29 21:43:11 +00:00
parent 43a4ecd2ea
commit f8810110cd
31 changed files with 551 additions and 137 deletions

View File

@@ -96,6 +96,10 @@
E491019D13C99BDC0098455B /* KRTextureManager.h in Headers */ = {isa = PBXBuildFile; fileRef = E491018513C99BDC0098455B /* KRTextureManager.h */; settings = {ATTRIBUTES = (); }; }; E491019D13C99BDC0098455B /* KRTextureManager.h in Headers */ = {isa = PBXBuildFile; fileRef = E491018513C99BDC0098455B /* KRTextureManager.h */; settings = {ATTRIBUTES = (); }; };
E491019E13C99BDC0098455B /* KRTexture.h in Headers */ = {isa = PBXBuildFile; fileRef = E491018613C99BDC0098455B /* KRTexture.h */; settings = {ATTRIBUTES = (); }; }; E491019E13C99BDC0098455B /* KRTexture.h in Headers */ = {isa = PBXBuildFile; fileRef = E491018613C99BDC0098455B /* KRTexture.h */; settings = {ATTRIBUTES = (); }; };
E49101A013C99BF50098455B /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E491019F13C99BF50098455B /* OpenGLES.framework */; }; E49101A013C99BF50098455B /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E491019F13C99BF50098455B /* OpenGLES.framework */; };
E4924C2615EE95E800B965C6 /* KROctree.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4924C2415EE95E700B965C6 /* KROctree.cpp */; };
E4924C2715EE95E800B965C6 /* KROctree.h in Headers */ = {isa = PBXBuildFile; fileRef = E4924C2515EE95E800B965C6 /* KROctree.h */; };
E4924C2B15EE96AB00B965C6 /* KROctreeNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4924C2915EE96AA00B965C6 /* KROctreeNode.cpp */; };
E4924C2C15EE96AB00B965C6 /* KROctreeNode.h in Headers */ = {isa = PBXBuildFile; fileRef = E4924C2A15EE96AA00B965C6 /* KROctreeNode.h */; };
E497B946151BA99500D3DC67 /* KRVector2.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E497B945151BA99400D3DC67 /* KRVector2.cpp */; }; E497B946151BA99500D3DC67 /* KRVector2.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E497B945151BA99400D3DC67 /* KRVector2.cpp */; };
E497B947151BA99500D3DC67 /* KRVector2.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E497B945151BA99400D3DC67 /* KRVector2.cpp */; }; E497B947151BA99500D3DC67 /* KRVector2.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E497B945151BA99400D3DC67 /* KRVector2.cpp */; };
E497B948151BB89D00D3DC67 /* KRVector2.h in Headers */ = {isa = PBXBuildFile; fileRef = E497B943151BA93400D3DC67 /* KRVector2.h */; settings = {ATTRIBUTES = (Public, ); }; }; E497B948151BB89D00D3DC67 /* KRVector2.h in Headers */ = {isa = PBXBuildFile; fileRef = E497B943151BA93400D3DC67 /* KRVector2.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -234,6 +238,10 @@
E491018513C99BDC0098455B /* KRTextureManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRTextureManager.h; path = Classes/KRTextureManager.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; E491018513C99BDC0098455B /* KRTextureManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRTextureManager.h; path = Classes/KRTextureManager.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
E491018613C99BDC0098455B /* KRTexture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRTexture.h; path = Classes/KRTexture.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; E491018613C99BDC0098455B /* KRTexture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRTexture.h; path = Classes/KRTexture.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
E491019F13C99BF50098455B /* OpenGLES.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGLES.framework; path = System/Library/Frameworks/OpenGLES.framework; sourceTree = SDKROOT; }; E491019F13C99BF50098455B /* OpenGLES.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGLES.framework; path = System/Library/Frameworks/OpenGLES.framework; sourceTree = SDKROOT; };
E4924C2415EE95E700B965C6 /* KROctree.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KROctree.cpp; path = Classes/KROctree.cpp; sourceTree = "<group>"; };
E4924C2515EE95E800B965C6 /* KROctree.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KROctree.h; path = Classes/KROctree.h; sourceTree = "<group>"; };
E4924C2915EE96AA00B965C6 /* KROctreeNode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KROctreeNode.cpp; path = Classes/KROctreeNode.cpp; sourceTree = "<group>"; };
E4924C2A15EE96AA00B965C6 /* KROctreeNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KROctreeNode.h; path = Classes/KROctreeNode.h; sourceTree = "<group>"; };
E497B943151BA93400D3DC67 /* KRVector2.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = KRVector2.h; path = Classes/KRVector2.h; sourceTree = "<group>"; }; E497B943151BA93400D3DC67 /* KRVector2.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = KRVector2.h; path = Classes/KRVector2.h; sourceTree = "<group>"; };
E497B945151BA99400D3DC67 /* KRVector2.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRVector2.cpp; path = Classes/KRVector2.cpp; sourceTree = "<group>"; }; E497B945151BA99400D3DC67 /* KRVector2.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRVector2.cpp; path = Classes/KRVector2.cpp; sourceTree = "<group>"; };
E497B949151BCEE900D3DC67 /* KRResource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRResource.h; path = Classes/KRResource.h; sourceTree = "<group>"; }; E497B949151BCEE900D3DC67 /* KRResource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRResource.h; path = Classes/KRResource.h; sourceTree = "<group>"; };
@@ -437,6 +445,10 @@
E45772E313C99F160037BEEA /* Shaders */, E45772E313C99F160037BEEA /* Shaders */,
E491016E13C99BAE0098455B /* Classes */, E491016E13C99BAE0098455B /* Classes */,
E491016713C99B9E0098455B /* Supporting Files */, E491016713C99B9E0098455B /* Supporting Files */,
E4924C2415EE95E700B965C6 /* KROctree.cpp */,
E4924C2515EE95E800B965C6 /* KROctree.h */,
E4924C2915EE96AA00B965C6 /* KROctreeNode.cpp */,
E4924C2A15EE96AA00B965C6 /* KROctreeNode.h */,
); );
path = KREngine; path = KREngine;
sourceTree = "<group>"; sourceTree = "<group>";
@@ -568,6 +580,8 @@
E42CB1EC158446940066E0D8 /* KRQuaternion.h in Headers */, E42CB1EC158446940066E0D8 /* KRQuaternion.h in Headers */,
E43B0ACB15DDBB8500A5CB9F /* KRNotified.h in Headers */, E43B0ACB15DDBB8500A5CB9F /* KRNotified.h in Headers */,
E43B0AD815DDCA0F00A5CB9F /* KRContextObject.h in Headers */, E43B0AD815DDCA0F00A5CB9F /* KRContextObject.h in Headers */,
E4924C2715EE95E800B965C6 /* KROctree.h in Headers */,
E4924C2C15EE96AB00B965C6 /* KROctreeNode.h in Headers */,
1000469E15E6EF550053B072 /* KRSkyBox.h in Headers */, 1000469E15E6EF550053B072 /* KRSkyBox.h in Headers */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
@@ -727,6 +741,8 @@
E42CB1F0158446AB0066E0D8 /* KRQuaternion.cpp in Sources */, E42CB1F0158446AB0066E0D8 /* KRQuaternion.cpp in Sources */,
E43B0AC915DDBB8500A5CB9F /* KRNotified.cpp in Sources */, E43B0AC915DDBB8500A5CB9F /* KRNotified.cpp in Sources */,
E43B0AD615DDCA0F00A5CB9F /* KRContextObject.cpp in Sources */, E43B0AD615DDCA0F00A5CB9F /* KRContextObject.cpp in Sources */,
E4924C2615EE95E800B965C6 /* KROctree.cpp in Sources */,
E4924C2B15EE96AB00B965C6 /* KROctreeNode.cpp in Sources */,
1000469D15E6EF550053B072 /* KRSkyBox.cpp in Sources */, 1000469D15E6EF550053B072 /* KRSkyBox.cpp in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;

View File

@@ -84,39 +84,3 @@ void KRContext::loadResource(std::string path) {
fprintf(stderr, "KRContext::loadResource - Unknown resource file type: %s\n", path.c_str()); fprintf(stderr, "KRContext::loadResource - Unknown resource file type: %s\n", path.c_str());
} }
} }
void KRContext::registerNotified(KRNotified *pNotified)
{
m_notifiedObjects.insert(pNotified);
for(std::set<KRNode *>::iterator itr=m_allNodes.begin(); itr != m_allNodes.end(); itr++) {
pNotified->notify_sceneGraphCreate(*itr);
}
}
void KRContext::unregisterNotified(KRNotified *pNotified)
{
m_notifiedObjects.erase(pNotified);
}
void KRContext::notify_sceneGraphCreate(KRNode *pNode)
{
m_allNodes.insert(pNode);
for(std::set<KRNotified *>::iterator itr = m_notifiedObjects.begin(); itr != m_notifiedObjects.end(); itr++) {
(*itr)->notify_sceneGraphCreate(pNode);
}
}
void KRContext::notify_sceneGraphDelete(KRNode *pNode)
{
for(std::set<KRNotified *>::iterator itr = m_notifiedObjects.begin(); itr != m_notifiedObjects.end(); itr++) {
(*itr)->notify_sceneGraphDelete(pNode);
}
m_allNodes.erase(pNode);
}
void KRContext::notify_sceneGraphModify(KRNode *pNode)
{
for(std::set<KRNotified *>::iterator itr = m_notifiedObjects.begin(); itr != m_notifiedObjects.end(); itr++) {
(*itr)->notify_sceneGraphModify(pNode);
}
}

View File

@@ -31,22 +31,12 @@ public:
KRCamera *createCamera(int width, int height); KRCamera *createCamera(int width, int height);
void registerNotified(KRNotified *pNotified);
void unregisterNotified(KRNotified *pNotified);
void notify_sceneGraphCreate(KRNode *pNode);
void notify_sceneGraphDelete(KRNode *pNode);
void notify_sceneGraphModify(KRNode *pNode);
private: private:
KRSceneManager *m_pSceneManager; KRSceneManager *m_pSceneManager;
KRTextureManager *m_pTextureManager; KRTextureManager *m_pTextureManager;
KRMaterialManager *m_pMaterialManager; KRMaterialManager *m_pMaterialManager;
KRShaderManager *m_pShaderManager; KRShaderManager *m_pShaderManager;
KRModelManager *m_pModelManager; KRModelManager *m_pModelManager;
std::set<KRNotified *> m_notifiedObjects;
std::set<KRNode *> m_allNodes;
}; };
#endif #endif

View File

@@ -13,7 +13,7 @@
#import "KRContext.h" #import "KRContext.h"
#import "KRMat4.h" #import "KRMat4.h"
KRDirectionalLight::KRDirectionalLight(KRContext &context, std::string name) : KRLight(context, name) KRDirectionalLight::KRDirectionalLight(KRScene &scene, std::string name) : KRLight(scene, name)
{ {
} }

View File

@@ -16,7 +16,7 @@ class KRDirectionalLight : public KRLight {
public: public:
KRDirectionalLight(KRContext &context, std::string name); KRDirectionalLight(KRScene &scene, std::string name);
virtual ~KRDirectionalLight(); virtual ~KRDirectionalLight();
virtual std::string getElementName(); virtual std::string getElementName();

View File

@@ -32,9 +32,10 @@
#include <iostream> #include <iostream>
#import "KRInstance.h" #import "KRInstance.h"
#import "KRContext.h" #import "KRContext.h"
#import "KRMesh.h"
#include <assert.h> #include <assert.h>
KRInstance::KRInstance(KRContext &context, std::string instance_name, std::string model_name, const KRMat4 modelMatrix, std::string light_map) : KRNode(context, instance_name) { KRInstance::KRInstance(KRScene &scene, std::string instance_name, std::string model_name, const KRMat4 modelMatrix, std::string light_map) : KRNode(scene, instance_name) {
m_modelMatrix = modelMatrix; m_modelMatrix = modelMatrix;
m_lightMap = light_map; m_lightMap = light_map;
m_pLightMap = NULL; m_pLightMap = NULL;
@@ -68,9 +69,6 @@ KRMat4 &KRInstance::getModelMatrix() {
void KRInstance::loadModel() { void KRInstance::loadModel() {
if(m_pModel == NULL) { if(m_pModel == NULL) {
m_pModel = m_pContext->getModelManager()->getModel(m_model_name.c_str()); m_pModel = m_pContext->getModelManager()->getModel(m_model_name.c_str());
if(m_pModel->hasTransparency()) {
m_pContext->notify_sceneGraphModify(this);
}
} }
} }
@@ -128,7 +126,7 @@ void KRInstance::calcExtents(KRContext *pContext) {
KRNode::calcExtents(pContext); KRNode::calcExtents(pContext);
loadModel(); loadModel();
KRMesh *pMesh = m_pModel->getMesh(); KRMesh *pMesh = m_pModel->getMesh();
KRBoundingVolume mesh_bounds = KRBoundingVolume(KRVector3(pMesh->getMinX(), pMesh->getMinY(), pMesh->getMinZ()), KRVector3(pMesh->getMaxX(), pMesh->getMaxY(), pMesh->getMaxZ()), m_modelMatrix); KRBoundingVolume mesh_bounds = KRBoundingVolume(pMesh->getMinPoint(), pMesh->getMaxPoint(), m_modelMatrix);
if(m_pExtents) { if(m_pExtents) {
*m_pExtents = m_pExtents->get_union(mesh_bounds); *m_pExtents = m_pExtents->get_union(mesh_bounds);
} else { } else {
@@ -142,5 +140,14 @@ bool KRInstance::hasTransparency() {
} else { } else {
return false; return false;
} }
}
KRVector3 KRInstance::getMinPoint() {
loadModel();
return KRMat4::Dot(m_modelMatrix, m_pModel->getMesh()->getMinPoint());
}
KRVector3 KRInstance::getMaxPoint() {
loadModel();
return KRMat4::Dot(m_modelMatrix, m_pModel->getMesh()->getMaxPoint());
} }

View File

@@ -53,7 +53,7 @@ class KRBoundingVolume;
class KRInstance : public KRNode { class KRInstance : public KRNode {
public: public:
KRInstance(KRContext &context, std::string instance_name, std::string model_name, const KRMat4 modelMatrix, std::string light_map); KRInstance(KRScene &scene, std::string instance_name, std::string model_name, const KRMat4 modelMatrix, std::string light_map);
virtual ~KRInstance(); virtual ~KRInstance();
virtual std::string getElementName(); virtual std::string getElementName();
@@ -70,6 +70,10 @@ public:
bool hasTransparency(); bool hasTransparency();
virtual KRVector3 getMinPoint();
virtual KRVector3 getMaxPoint();
private: private:
KRModel *m_pModel; KRModel *m_pModel;
KRMat4 m_modelMatrix; KRMat4 m_modelMatrix;

View File

@@ -22,7 +22,7 @@
#import "KRShaderManager.h" #import "KRShaderManager.h"
#import "KRShader.h" #import "KRShader.h"
KRLight::KRLight(KRContext &context, std::string name) : KRNode(context, name) KRLight::KRLight(KRScene &scene, std::string name) : KRNode(scene, name)
{ {
m_intensity = 1.0f; m_intensity = 1.0f;
m_flareTexture = ""; m_flareTexture = "";

View File

@@ -41,7 +41,7 @@ public:
#endif #endif
protected: protected:
KRLight(KRContext &context, std::string name); KRLight(KRScene &scene, std::string name);
float m_intensity; float m_intensity;
float m_decayStart; float m_decayStart;

View File

@@ -94,13 +94,8 @@ void KRMesh::loadPack(std::string path) {
m_iPackFileSize = statbuf.st_size; m_iPackFileSize = statbuf.st_size;
pack_header *pHeader = (pack_header *)m_pPackData; pack_header *pHeader = (pack_header *)m_pPackData;
m_minPoint = KRVector3(pHeader->minx, pHeader->miny, pHeader->minz);
m_minx = pHeader->minx; m_maxPoint = KRVector3(pHeader->maxx, pHeader->maxy, pHeader->maxz);
m_miny = pHeader->miny;
m_minz = pHeader->minz;
m_maxx = pHeader->maxx;
m_maxy = pHeader->maxy;
m_maxz = pHeader->maxz;
} }
} }
@@ -156,31 +151,12 @@ void KRMesh::unmap() {
GLfloat KRMesh::getMaxDimension() { GLfloat KRMesh::getMaxDimension() {
GLfloat m = 0.0; GLfloat m = 0.0;
if(m_maxx - m_minx > m) m = m_maxx - m_minx; if(m_maxPoint.x - m_minPoint.x > m) m = m_maxPoint.x - m_minPoint.x;
if(m_maxy - m_miny > m) m = m_maxy - m_miny; if(m_maxPoint.y - m_minPoint.y > m) m = m_maxPoint.y - m_minPoint.y;
if(m_maxz - m_minz > m) m = m_maxz - m_minz; if(m_maxPoint.z - m_minPoint.z > m) m = m_maxPoint.z - m_minPoint.z;
return m; return m;
} }
GLfloat KRMesh::getMinX() {
return m_minx;
}
GLfloat KRMesh::getMaxX() {
return m_maxx;
}
GLfloat KRMesh::getMinY() {
return m_miny;
}
GLfloat KRMesh::getMaxY() {
return m_maxy;
}
GLfloat KRMesh::getMinZ() {
return m_minz;
}
GLfloat KRMesh::getMaxZ() {
return m_maxz;
}
vector<KRMesh::Submesh *> KRMesh::getSubmeshes() { vector<KRMesh::Submesh *> KRMesh::getSubmeshes() {
if(m_submeshes.size() == 0) { if(m_submeshes.size() == 0) {
pack_header *pHeader = (pack_header *)m_pPackData; pack_header *pHeader = (pack_header *)m_pPackData;
@@ -301,19 +277,15 @@ void KRMesh::LoadData(std::vector<KRVector3> vertices, std::vector<KRVector2> uv
pVertex->vertex.z = source_vertex.z; pVertex->vertex.z = source_vertex.z;
if(bFirstVertex) { if(bFirstVertex) {
bFirstVertex = false; bFirstVertex = false;
m_minx = source_vertex.x; m_minPoint = source_vertex;
m_miny = source_vertex.y; m_maxPoint = source_vertex;
m_minz = source_vertex.z;
m_maxx = source_vertex.x;
m_maxy = source_vertex.y;
m_maxz = source_vertex.z;
} else { } else {
if(source_vertex.x < m_minx) m_minx = source_vertex.x; if(source_vertex.x < m_minPoint.x) m_minPoint.x = source_vertex.x;
if(source_vertex.y < m_miny) m_miny = source_vertex.y; if(source_vertex.y < m_minPoint.y) m_minPoint.y = source_vertex.y;
if(source_vertex.z < m_minz) m_minz = source_vertex.z; if(source_vertex.z < m_minPoint.z) m_minPoint.z = source_vertex.z;
if(source_vertex.x > m_maxx) m_maxx = source_vertex.x; if(source_vertex.x > m_maxPoint.x) m_maxPoint.x = source_vertex.x;
if(source_vertex.y > m_maxy) m_maxy = source_vertex.y; if(source_vertex.y > m_maxPoint.y) m_maxPoint.y = source_vertex.y;
if(source_vertex.z > m_maxz) m_maxz = source_vertex.z; if(source_vertex.z > m_maxPoint.z) m_maxPoint.z = source_vertex.z;
} }
if(uva.size() > iVertex) { if(uva.size() > iVertex) {
KRVector2 source_uva = uva[iVertex]; KRVector2 source_uva = uva[iVertex];
@@ -355,12 +327,12 @@ void KRMesh::LoadData(std::vector<KRVector3> vertices, std::vector<KRVector2> uv
pVertex++; pVertex++;
} }
pHeader->minx = m_minx; pHeader->minx = m_minPoint.x;
pHeader->miny = m_miny; pHeader->miny = m_minPoint.y;
pHeader->minz = m_minz; pHeader->minz = m_minPoint.z;
pHeader->maxx = m_maxx; pHeader->maxx = m_maxPoint.x;
pHeader->maxy = m_maxy; pHeader->maxy = m_maxPoint.y;
pHeader->maxz = m_maxz; pHeader->maxz = m_maxPoint.z;
// Calculate missing surface normals and tangents // Calculate missing surface normals and tangents
@@ -430,3 +402,10 @@ void KRMesh::LoadData(std::vector<KRVector3> vertices, std::vector<KRVector2> uv
} }
} }
KRVector3 KRMesh::getMinPoint() const {
return m_minPoint;
}
KRVector3 KRMesh::getMaxPoint() const {
return m_maxPoint;
}

View File

@@ -71,12 +71,9 @@ public:
void renderSubmesh(int iSubmesh, int *iPrevBuffer); void renderSubmesh(int iSubmesh, int *iPrevBuffer);
GLfloat getMaxDimension(); GLfloat getMaxDimension();
GLfloat getMinX();
GLfloat getMaxX(); KRVector3 getMinPoint() const;
GLfloat getMinY(); KRVector3 getMaxPoint() const;
GLfloat getMaxY();
GLfloat getMinZ();
GLfloat getMaxZ();
typedef struct { typedef struct {
GLint start_vertex; GLint start_vertex;
@@ -114,7 +111,7 @@ public:
} pack_material; } pack_material;
protected: protected:
GLfloat m_minx, m_miny, m_minz, m_maxx, m_maxy, m_maxz; KRVector3 m_minPoint, m_maxPoint;
int m_fdPackFile; int m_fdPackFile;
void *m_pPackData; void *m_pPackData;

View File

@@ -8,6 +8,7 @@
#include <iostream> #include <iostream>
#include <assert.h> #include <assert.h>
#include <limits>
#import "KRNode.h" #import "KRNode.h"
#import "KRPointLight.h" #import "KRPointLight.h"
@@ -17,7 +18,7 @@
#import "KRSkyBox.h" #import "KRSkyBox.h"
KRNode::KRNode(KRContext &context, std::string name) : KRContextObject(context) KRNode::KRNode(KRScene &scene, std::string name) : KRContextObject(scene.getContext())
{ {
m_pExtents = NULL; m_pExtents = NULL;
m_name = name; m_name = name;
@@ -25,10 +26,11 @@ KRNode::KRNode(KRContext &context, std::string name) : KRContextObject(context)
m_localRotation = KRVector3::Zero(); m_localRotation = KRVector3::Zero();
m_localTranslation = KRVector3::Zero(); m_localTranslation = KRVector3::Zero();
m_parentNode = NULL; m_parentNode = NULL;
m_pScene = &scene;
} }
KRNode::~KRNode() { KRNode::~KRNode() {
m_pContext->notify_sceneGraphDelete(this); getScene().notify_sceneGraphDelete(this);
for(std::vector<KRNode *>::iterator itr=m_childNodes.begin(); itr < m_childNodes.end(); ++itr) { for(std::vector<KRNode *>::iterator itr=m_childNodes.begin(); itr < m_childNodes.end(); ++itr) {
delete *itr; delete *itr;
} }
@@ -41,7 +43,7 @@ void KRNode::addChild(KRNode *child) {
child->m_parentNode = this; child->m_parentNode = this;
m_childNodes.push_back(child); m_childNodes.push_back(child);
clearExtents(); clearExtents();
m_pContext->notify_sceneGraphCreate(child); getScene().notify_sceneGraphCreate(child);
} }
tinyxml2::XMLElement *KRNode::saveXML(tinyxml2::XMLNode *parent) { tinyxml2::XMLElement *KRNode::saveXML(tinyxml2::XMLNode *parent) {
@@ -84,7 +86,7 @@ void KRNode::loadXML(tinyxml2::XMLElement *e) {
m_localRotation = KRVector3(x,y,z); m_localRotation = KRVector3(x,y,z);
for(tinyxml2::XMLElement *child_element=e->FirstChildElement(); child_element != NULL; child_element = child_element->NextSiblingElement()) { for(tinyxml2::XMLElement *child_element=e->FirstChildElement(); child_element != NULL; child_element = child_element->NextSiblingElement()) {
KRNode *child_node = KRNode::LoadXML(*m_pContext, child_element); KRNode *child_node = KRNode::LoadXML(getScene(), child_element);
if(child_node) { if(child_node) {
addChild(child_node); addChild(child_node);
} }
@@ -129,22 +131,22 @@ std::string KRNode::getElementName() {
return "node"; return "node";
} }
KRNode *KRNode::LoadXML(KRContext &context, tinyxml2::XMLElement *e) { KRNode *KRNode::LoadXML(KRScene &scene, tinyxml2::XMLElement *e) {
KRNode *new_node = NULL; KRNode *new_node = NULL;
const char *szElementName = e->Name(); const char *szElementName = e->Name();
const char *szName = e->Attribute("name"); const char *szName = e->Attribute("name");
if(strcmp(szElementName, "node") == 0) { if(strcmp(szElementName, "node") == 0) {
new_node = new KRNode(context, szName); new_node = new KRNode(scene, szName);
} else if(strcmp(szElementName, "point_light") == 0) { } else if(strcmp(szElementName, "point_light") == 0) {
new_node = new KRPointLight(context, szName); new_node = new KRPointLight(scene, szName);
} else if(strcmp(szElementName, "directional_light") == 0) { } else if(strcmp(szElementName, "directional_light") == 0) {
new_node = new KRDirectionalLight(context, szName); new_node = new KRDirectionalLight(scene, szName);
} else if(strcmp(szElementName, "spot_light") == 0) { } else if(strcmp(szElementName, "spot_light") == 0) {
new_node = new KRSpotLight(context, szName); new_node = new KRSpotLight(scene, szName);
} else if(strcmp(szElementName, "mesh") == 0) { } else if(strcmp(szElementName, "mesh") == 0) {
new_node = new KRInstance(context, szName, szName, KRMat4(), e->Attribute("light_map")); new_node = new KRInstance(scene, szName, szName, KRMat4(), e->Attribute("light_map"));
} else if(strcmp(szElementName, "sky_box") == 0) { } else if(strcmp(szElementName, "sky_box") == 0) {
new_node = new KRSkyBox(context, szName); new_node = new KRSkyBox(scene, szName);
} }
if(new_node) { if(new_node) {
@@ -202,3 +204,16 @@ const std::vector<KRNode *> &KRNode::getChildren() {
const std::string &KRNode::getName() { const std::string &KRNode::getName() {
return m_name; return m_name;
} }
KRScene &KRNode::getScene() {
return *m_pScene;
}
KRVector3 KRNode::getMinPoint() {
return KRVector3::Min();
}
KRVector3 KRNode::getMaxPoint() {
return KRVector3::Max();
}

View File

@@ -21,6 +21,7 @@ class KRMaterialManager;
class KRMat4; class KRMat4;
class KRTextureManager; class KRTextureManager;
class KRContext; class KRContext;
class KRScene;
class KRNode : public KRContextObject class KRNode : public KRContextObject
{ {
@@ -36,11 +37,11 @@ public:
RENDER_PASS_SKYBOX RENDER_PASS_SKYBOX
}; };
KRNode(KRContext &context, std::string name); KRNode(KRScene &scene, std::string name);
virtual ~KRNode(); virtual ~KRNode();
virtual tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent); virtual tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent);
static KRNode *LoadXML(KRContext &context, tinyxml2::XMLElement *e); static KRNode *LoadXML(KRScene &scene, tinyxml2::XMLElement *e);
virtual void loadXML(tinyxml2::XMLElement *e); virtual void loadXML(tinyxml2::XMLElement *e);
virtual std::string getElementName(); virtual std::string getElementName();
@@ -64,6 +65,11 @@ public:
void clearExtents(); void clearExtents();
virtual void calcExtents(KRContext *Context); virtual void calcExtents(KRContext *Context);
KRBoundingVolume getExtents(KRContext *pContext); KRBoundingVolume getExtents(KRContext *pContext);
virtual KRVector3 getMinPoint();
virtual KRVector3 getMaxPoint();
KRScene &getScene();
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
virtual void render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, RenderPass renderPass); virtual void render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, RenderPass renderPass);
@@ -83,6 +89,8 @@ private:
std::vector<KRNode *> m_childNodes; std::vector<KRNode *> m_childNodes;
KRNode *m_parentNode; KRNode *m_parentNode;
KRScene *m_pScene;
}; };

View File

@@ -34,10 +34,13 @@
KRNotified::KRNotified(KRContext &context) : KRContextObject(context) KRNotified::KRNotified(KRContext &context) : KRContextObject(context)
{ {
m_pSubscribedScene = NULL;
} }
KRNotified::~KRNotified() KRNotified::~KRNotified()
{ {
m_pContext->unregisterNotified(this); if(m_pSubscribedScene) {
m_pSubscribedScene->unregisterNotified(this);
m_pSubscribedScene = NULL;
}
} }

View File

@@ -36,6 +36,7 @@
class KRContext; class KRContext;
class KRNode; class KRNode;
class KRScene;
class KRNotified : public KRContextObject { class KRNotified : public KRContextObject {
@@ -46,6 +47,8 @@ public:
virtual void notify_sceneGraphCreate(KRNode *pNode) = 0; virtual void notify_sceneGraphCreate(KRNode *pNode) = 0;
virtual void notify_sceneGraphDelete(KRNode *pNode) = 0; virtual void notify_sceneGraphDelete(KRNode *pNode) = 0;
virtual void notify_sceneGraphModify(KRNode *pNode) = 0; virtual void notify_sceneGraphModify(KRNode *pNode) = 0;
private:
KRScene *m_pSubscribedScene;
}; };
#endif #endif

View File

@@ -0,0 +1,84 @@
//
// KROctree.cpp
// KREngine
//
// Created by Kearwood Gilbert on 2012-08-29.
// Copyright (c) 2012 Kearwood Software. All rights reserved.
//
#include "KROctree.h"
#include "KRNode.h"
KROctree::KROctree()
{
m_pRootNode = NULL;
}
KROctree::~KROctree()
{
if(m_pRootNode) {
delete m_pRootNode;
}
}
void KROctree::add(KRNode *pNode)
{
KRVector3 minPoint = pNode->getMinPoint();
KRVector3 maxPoint = pNode->getMaxPoint();
if(pNode->getMinPoint() == KRVector3::Min() && pNode->getMaxPoint() == KRVector3::Max()) {
// This item is infinitely large; we track it separately
m_outerSceneNodes.insert(pNode);
} else {
if(m_pRootNode == NULL) {
// First item inserted, create a node large enough to fit it
m_pRootNode = new KROctreeNode(pNode->getMinPoint(), pNode->getMaxPoint());
m_pRootNode->add(pNode);
} else {
// Keep encapsulating the root node until the new root contains the inserted node
bool bInsideRoot = false;
while(!bInsideRoot) {
KRVector3 rootMinPoint = m_pRootNode->getMinPoint();
KRVector3 rootMaxPoint = m_pRootNode->getMaxPoint();
KRVector3 rootSize = rootMaxPoint - rootMinPoint;
if(minPoint.x < rootMinPoint.x || minPoint.y < rootMinPoint.y || minPoint.z < rootMinPoint.z) {
m_pRootNode = new KROctreeNode(rootMinPoint - rootSize, rootMaxPoint, 7, m_pRootNode);
} else if(maxPoint.x > rootMaxPoint.x || maxPoint.y > rootMaxPoint.y || maxPoint.z > rootMaxPoint.z) {
m_pRootNode = new KROctreeNode(rootMaxPoint, rootMaxPoint + rootSize, 0, m_pRootNode);
} else {
bInsideRoot = true;
}
}
m_pRootNode->add(pNode);
}
}
}
void KROctree::remove(KRNode *pNode)
{
if(!m_outerSceneNodes.erase(pNode)) {
if(m_pRootNode) {
m_pRootNode->remove(pNode);
}
}
shrink();
}
void KROctree::update(KRNode *pNode)
{
// TODO: This may be more efficient as an incremental operation rather than removing and re-adding the node
remove(pNode);
add(pNode);
shrink();
}
void KROctree::shrink()
{
if(m_pRootNode) {
while(m_pRootNode->canShrinkRoot()) {
KROctreeNode *newRoot = m_pRootNode->stripChild();
delete m_pRootNode;
m_pRootNode = newRoot;
}
}
}

View File

@@ -0,0 +1,33 @@
//
// KROctree.h
// KREngine
//
// Created by Kearwood Gilbert on 2012-08-29.
// Copyright (c) 2012 Kearwood Software. All rights reserved.
//
#ifndef KRAABBTREE_H
#define KRAABBTREE_H
#import "KREngine-common.h"
#include "KROctreeNode.h"
class KRNode;
class KROctree {
public:
KROctree();
~KROctree();
void add(KRNode *pNode);
void remove(KRNode *pNode);
void update(KRNode *pNode);
private:
KROctreeNode *m_pRootNode;
std::set<KRNode *>m_outerSceneNodes;
void shrink();
};
#endif /* defined(KRAABBTREE_H) */

View File

@@ -0,0 +1,172 @@
//
// KROctreeNode.cpp
// KREngine
//
// Created by Kearwood Gilbert on 2012-08-29.
// Copyright (c) 2012 Kearwood Software. All rights reserved.
//
#include "KROctreeNode.h"
#include "KRNode.h"
KROctreeNode::KROctreeNode(const KRVector3 &minPoint, const KRVector3 &maxPoint)
{
m_minPoint = minPoint;
m_maxPoint = maxPoint;
for(int i=0; i<8; i++) m_children[i] = NULL;
}
KROctreeNode::KROctreeNode(const KRVector3 &minPoint, const KRVector3 &maxPoint, int iChild, KROctreeNode *pChild)
{
// This constructor is used when expanding the octree and replacing the root node with a new root that encapsulates it
m_minPoint = minPoint;
m_maxPoint = maxPoint;
for(int i=0; i<8; i++) m_children[i] = NULL;
m_children[iChild] = pChild;
}
KROctreeNode::~KROctreeNode()
{
for(int i=0; i<8; i++) {
if(m_children[i] != NULL) {
delete m_children[i];
}
}
}
void KROctreeNode::add(KRNode *pNode)
{
KRVector3 center = (m_minPoint + m_maxPoint) / 2.0f;
int iChild = getChildIndex(pNode);
if(iChild == -1) {
m_sceneNodes.insert(pNode);
} else {
if(m_children[iChild] == NULL) {
m_children[iChild] = new KROctreeNode(
KRVector3(
(iChild & 1) == 0 ? m_minPoint.x : center.x,
(iChild & 2) == 0 ? m_minPoint.y : center.y,
(iChild & 4) == 0 ? m_minPoint.z : center.z),
KRVector3(
(iChild & 1) == 0 ? center.x : m_maxPoint.x,
(iChild & 2) == 0 ? center.y : m_maxPoint.y,
(iChild & 4) == 0 ? center.z : m_maxPoint.z)
);
}
m_children[iChild]->add(pNode);
}
}
int KROctreeNode::getChildIndex(KRNode *pNode)
{
KRVector3 min = pNode->getMinPoint();
KRVector3 max = pNode->getMaxPoint();
// 0: max.x < center.x && max.y < center.y && max.z < center.z
// 1: min.x > center.x && max.y < center.y && max.z < center.z
// 2: max.x < center.x && min.y > center.y && max.z < center.z
// 3: min.x > center.x && min.y > center.y && max.z < center.z
// 4: max.x < center.x && max.y < center.y && min.z > center.z
// 5: min.x > center.x && max.y < center.y && min.z > center.z
// 6: max.x < center.x && min.y > center.y && min.z > center.z
// 7: min.x > center.x && min.y > center.y && min.z > center.z
KRVector3 center = (m_minPoint + m_maxPoint) / 2.0f;
int iChild = -1;
if(max.z < center.z) {
if(max.y < center.y) {
if(max.x < center.x) {
iChild = 0;
} else if(min.x > center.x) {
iChild = 1;
}
} else if(min.y > center.y) {
if(max.x < center.x) {
iChild = 2;
} else if(min.x > center.x) {
iChild = 3;
}
}
} else if(min.z > center.z) {
if(max.y < center.y) {
if(min.x > center.x) {
iChild = 4;
} else if(min.x > center.x) {
iChild = 5;
}
} else if(min.y > center.y) {
if(max.x < center.x) {
iChild = 6;
} else if(min.x > center.x) {
iChild = 7;
}
}
}
return iChild;
}
void KROctreeNode::remove(KRNode *pNode)
{
if(!m_sceneNodes.erase(pNode)) {
int iChild = getChildIndex(pNode);
if(m_children[iChild]) {
m_children[iChild]->remove(pNode);
if(m_children[iChild]->isEmpty()) {
delete m_children[iChild];
m_children[iChild] = NULL;
}
}
}
}
void KROctreeNode::update(KRNode *pNode)
{
}
KRVector3 KROctreeNode::getMinPoint()
{
return m_minPoint;
}
KRVector3 KROctreeNode::getMaxPoint()
{
return m_maxPoint;
}
bool KROctreeNode::isEmpty() const
{
for(int i=0; i<8; i++) {
if(m_children[i]) {
return false;
}
}
return m_sceneNodes.empty();
}
bool KROctreeNode::canShrinkRoot() const
{
int cChildren = 0;
for(int i=0; i<8; i++) {
if(m_children[i]) {
cChildren++;
}
}
return cChildren <= 1 && m_sceneNodes.empty();
}
KROctreeNode *KROctreeNode::stripChild()
{
// Return the first found child and update its reference to NULL so that the destructor will not free it. This is used for shrinking the octree
// NOTE: The caller of this function will be responsible for freeing the child object. It is also possible to return a NULL
for(int i=0; i<8; i++) {
if(m_children[i]) {
KROctreeNode *child = m_children[i];
m_children[i] = NULL;
return child;
}
}
return NULL;
}

View File

@@ -0,0 +1,47 @@
//
// KROctreeNode.h
// KREngine
//
// Created by Kearwood Gilbert on 2012-08-29.
// Copyright (c) 2012 Kearwood Software. All rights reserved.
//
#ifndef KRAABBTREENODE_H
#define KRAABBTREENODE_H
#import "KREngine-common.h"
#include "KRVector3.h"
class KRNode;
class KROctreeNode {
public:
KROctreeNode(const KRVector3 &minPoint, const KRVector3 &maxPoint);
KROctreeNode(const KRVector3 &minPoint, const KRVector3 &maxPoint, int iChild, KROctreeNode *pChild);
~KROctreeNode();
void add(KRNode *pNode);
void remove(KRNode *pNode);
void update(KRNode *pNode);
KRVector3 getMinPoint();
KRVector3 getMaxPoint();
void setChildNode(int iChild, KROctreeNode *pChild);
int getChildIndex(KRNode *pNode);
bool isEmpty() const;
bool canShrinkRoot() const;
KROctreeNode *stripChild();
private:
KRVector3 m_minPoint;
KRVector3 m_maxPoint;
KROctreeNode *m_children[8];
std::set<KRNode *>m_sceneNodes;
};
#endif /* defined(KRAABBTREENODE_H) */

View File

@@ -16,7 +16,7 @@
#import "KRContext.h" #import "KRContext.h"
#import "KRBoundingVolume.h" #import "KRBoundingVolume.h"
KRPointLight::KRPointLight(KRContext &context, std::string name) : KRLight(context, name) KRPointLight::KRPointLight(KRScene &scene, std::string name) : KRLight(scene, name)
{ {
m_sphereVertices = NULL; m_sphereVertices = NULL;
m_cVertices = 0; m_cVertices = 0;

View File

@@ -16,7 +16,7 @@ class KRPointLight : public KRLight {
public: public:
KRPointLight(KRContext &context, std::string name); KRPointLight(KRScene &scene, std::string name);
virtual ~KRPointLight(); virtual ~KRPointLight();
virtual std::string getElementName(); virtual std::string getElementName();

View File

@@ -42,7 +42,7 @@
KRScene::KRScene(KRContext &context, std::string name) : KRResource(context, name) { KRScene::KRScene(KRContext &context, std::string name) : KRResource(context, name) {
m_pContext = &context; m_pContext = &context;
m_pFirstDirectionalLight = NULL; m_pFirstDirectionalLight = NULL;
m_pRootNode = new KRNode(context, "scene_root"); m_pRootNode = new KRNode(*this, "scene_root");
sun_yaw = 4.333; // TODO - Remove temporary testing code sun_yaw = 4.333; // TODO - Remove temporary testing code
sun_pitch = 0.55; sun_pitch = 0.55;
@@ -56,6 +56,8 @@ KRScene::~KRScene() {
void KRScene::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass) { void KRScene::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass) {
updateOctree();
if(renderPass != KRNode::RENDER_PASS_SHADOWMAP) { if(renderPass != KRNode::RENDER_PASS_SHADOWMAP) {
if(cShadowBuffers > 0) { if(cShadowBuffers > 0) {
@@ -145,7 +147,7 @@ KRScene *KRScene::LoadXML(KRContext &context, const std::string& path)
doc.LoadFile(path.c_str()); doc.LoadFile(path.c_str());
KRScene *new_scene = new KRScene(context, KRResource::GetFileBase(path)); KRScene *new_scene = new KRScene(context, KRResource::GetFileBase(path));
KRNode *n = KRNode::LoadXML(context, doc.RootElement()->FirstChildElement()); KRNode *n = KRNode::LoadXML(*new_scene, doc.RootElement()->FirstChildElement());
if(n) { if(n) {
new_scene->getRootNode()->addChild(n); new_scene->getRootNode()->addChild(n);
} }
@@ -159,3 +161,57 @@ KRDirectionalLight *KRScene::getFirstDirectionalLight()
} }
return m_pFirstDirectionalLight; return m_pFirstDirectionalLight;
} }
void KRScene::registerNotified(KRNotified *pNotified)
{
m_notifiedObjects.insert(pNotified);
for(std::set<KRNode *>::iterator itr=m_allNodes.begin(); itr != m_allNodes.end(); itr++) {
pNotified->notify_sceneGraphCreate(*itr);
}
}
void KRScene::unregisterNotified(KRNotified *pNotified)
{
m_notifiedObjects.erase(pNotified);
}
void KRScene::notify_sceneGraphCreate(KRNode *pNode)
{
m_allNodes.insert(pNode);
m_newNodes.insert(pNode);
for(std::set<KRNotified *>::iterator itr = m_notifiedObjects.begin(); itr != m_notifiedObjects.end(); itr++) {
(*itr)->notify_sceneGraphCreate(pNode);
}
}
void KRScene::notify_sceneGraphDelete(KRNode *pNode)
{
for(std::set<KRNotified *>::iterator itr = m_notifiedObjects.begin(); itr != m_notifiedObjects.end(); itr++) {
(*itr)->notify_sceneGraphDelete(pNode);
}
m_allNodes.erase(pNode);
m_modifiedNodes.erase(pNode);
if(!m_newNodes.erase(pNode)) {
m_nodeTree.remove(pNode);
}
}
void KRScene::notify_sceneGraphModify(KRNode *pNode)
{
m_modifiedNodes.insert(pNode);
for(std::set<KRNotified *>::iterator itr = m_notifiedObjects.begin(); itr != m_notifiedObjects.end(); itr++) {
(*itr)->notify_sceneGraphModify(pNode);
}
}
void KRScene::updateOctree()
{
for(std::set<KRNode *>::iterator itr=m_newNodes.begin(); itr != m_newNodes.end(); itr++) {
m_nodeTree.add(*itr);
}
for(std::set<KRNode *>::iterator itr=m_modifiedNodes.begin(); itr != m_modifiedNodes.end(); itr++) {
m_nodeTree.update(*itr);
}
m_newNodes.clear();
m_modifiedNodes.clear();
}

View File

@@ -42,6 +42,7 @@
#import "KRCamera.h" #import "KRCamera.h"
#import "KRModelManager.h" #import "KRModelManager.h"
#import "KRNode.h" #import "KRNode.h"
#import "KROctree.h"
class KRBoundingVolume; class KRBoundingVolume;
class KRInstance; class KRInstance;
class KRDirectionalLight; class KRDirectionalLight;
@@ -69,6 +70,14 @@ public:
KRBoundingVolume getExtents(KRContext *pContext); KRBoundingVolume getExtents(KRContext *pContext);
double sun_pitch, sun_yaw; double sun_pitch, sun_yaw;
void registerNotified(KRNotified *pNotified);
void unregisterNotified(KRNotified *pNotified);
void notify_sceneGraphCreate(KRNode *pNode);
void notify_sceneGraphDelete(KRNode *pNode);
void notify_sceneGraphModify(KRNode *pNode);
private: private:
KRContext *m_pContext; KRContext *m_pContext;
KRDirectionalLight *findFirstDirectionalLight(KRNode &node); KRDirectionalLight *findFirstDirectionalLight(KRNode &node);
@@ -77,6 +86,14 @@ private:
KRBoundingVolume *m_pExtents; KRBoundingVolume *m_pExtents;
KRDirectionalLight *m_pFirstDirectionalLight; KRDirectionalLight *m_pFirstDirectionalLight;
std::set<KRNotified *> m_notifiedObjects;
std::set<KRNode *> m_allNodes;
std::set<KRNode *> m_newNodes;
std::set<KRNode *> m_modifiedNodes;
KROctree m_nodeTree;
void updateOctree();
}; };

View File

@@ -14,7 +14,7 @@
#import "KRMat4.h" #import "KRMat4.h"
#import "KRResource.h" #import "KRResource.h"
KRSkyBox::KRSkyBox(KRContext &context, std::string name) : KRNode(context, name) KRSkyBox::KRSkyBox(KRScene &scene, std::string name) : KRNode(scene, name)
{ {
m_frontTexture = ""; m_frontTexture = "";
m_backTexture = ""; m_backTexture = "";

View File

@@ -18,7 +18,7 @@ class KRSkyBox : public KRNode {
public: public:
KRSkyBox(KRContext &context, std::string name); KRSkyBox(KRScene &scene, std::string name);
virtual ~KRSkyBox(); virtual ~KRSkyBox();
virtual std::string getElementName(); virtual std::string getElementName();

View File

@@ -10,7 +10,7 @@
#import "KRSpotLight.h" #import "KRSpotLight.h"
KRSpotLight::KRSpotLight(KRContext &context, std::string name) : KRLight(context, name) KRSpotLight::KRSpotLight(KRScene &scene, std::string name) : KRLight(scene, name)
{ {
} }

View File

@@ -13,7 +13,7 @@
class KRSpotLight : public KRLight { class KRSpotLight : public KRLight {
public: public:
KRSpotLight(KRContext &context, std::string name); KRSpotLight(KRScene &scene, std::string name);
virtual ~KRSpotLight(); virtual ~KRSpotLight();
virtual std::string getElementName(); virtual std::string getElementName();

View File

@@ -31,6 +31,14 @@ KRVector2::KRVector2(const KRVector2 &v) {
y = v.y; y = v.y;
} }
KRVector2 KRVector2::Min() {
return KRVector2(-std::numeric_limits<float>::max());
}
KRVector2 KRVector2::Max() {
return KRVector2(std::numeric_limits<float>::max());
}
KRVector2 KRVector2::Zero() { KRVector2 KRVector2::Zero() {
return KRVector2(0.0f); return KRVector2(0.0f);
} }

View File

@@ -73,7 +73,8 @@ public:
static float Cross(const KRVector2 &v1, const KRVector2 &v2); static float Cross(const KRVector2 &v1, const KRVector2 &v2);
static float Dot(const KRVector2 &v1, const KRVector2 &v2); static float Dot(const KRVector2 &v1, const KRVector2 &v2);
static KRVector2 Min();
static KRVector2 Max();
static KRVector2 Zero(); static KRVector2 Zero();
static KRVector2 One(); static KRVector2 One();

View File

@@ -32,6 +32,7 @@
#include "KRVector3.h" #include "KRVector3.h"
#include <math.h> #include <math.h>
#include <limits.h>
//default constructor //default constructor
KRVector3::KRVector3() KRVector3::KRVector3()
@@ -47,6 +48,14 @@ KRVector3::KRVector3(const KRVector3 &v) {
z = v.z; z = v.z;
} }
KRVector3 KRVector3::Min() {
return KRVector3(-std::numeric_limits<float>::max());
}
KRVector3 KRVector3::Max() {
return KRVector3(std::numeric_limits<float>::max());
}
KRVector3 KRVector3::Zero() { KRVector3 KRVector3::Zero() {
return KRVector3(0.0f, 0.0f, 0.0f); return KRVector3(0.0f, 0.0f, 0.0f);
} }

View File

@@ -74,7 +74,8 @@ public:
static KRVector3 Cross(const KRVector3 &v1, const KRVector3 &v2); static KRVector3 Cross(const KRVector3 &v1, const KRVector3 &v2);
static float Dot(const KRVector3 &v1, const KRVector3 &v2); static float Dot(const KRVector3 &v1, const KRVector3 &v2);
static KRVector3 Min();
static KRVector3 Max();
static KRVector3 Zero(); static KRVector3 Zero();
static KRVector3 One(); static KRVector3 One();
static KRVector3 Forward(); static KRVector3 Forward();