2012-04-12 00:43:53 +00:00
|
|
|
//
|
|
|
|
|
// KRNode.h
|
|
|
|
|
// KREngine
|
|
|
|
|
//
|
|
|
|
|
// Created by Kearwood Gilbert on 12-04-11.
|
|
|
|
|
// Copyright (c) 2012 Kearwood Software. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
2012-11-02 20:50:45 +00:00
|
|
|
#ifndef KRNODE_H
|
|
|
|
|
#define KRNODE_H
|
2012-04-12 00:43:53 +00:00
|
|
|
|
2013-01-11 03:21:19 +00:00
|
|
|
#include "KRResource.h"
|
|
|
|
|
#include "KRVector3.h"
|
|
|
|
|
#include "KRViewport.h"
|
|
|
|
|
#include "tinyxml2.h"
|
2013-02-21 16:22:56 -08:00
|
|
|
#include "KROctreeNode.h"
|
2012-06-14 19:33:17 +00:00
|
|
|
|
2012-04-12 06:04:15 +00:00
|
|
|
class KRCamera;
|
|
|
|
|
class KRShaderManager;
|
2013-01-09 22:37:23 +00:00
|
|
|
class KRMeshManager;
|
2012-04-12 06:04:15 +00:00
|
|
|
class KRMaterialManager;
|
|
|
|
|
class KRMat4;
|
|
|
|
|
class KRTextureManager;
|
2012-04-12 19:43:08 +00:00
|
|
|
class KRContext;
|
2012-08-29 21:43:11 +00:00
|
|
|
class KRScene;
|
2012-09-11 03:06:35 +00:00
|
|
|
class KRAABB;
|
2013-01-23 12:43:43 -08:00
|
|
|
class KRNode;
|
2012-04-12 00:43:53 +00:00
|
|
|
|
2012-08-17 01:04:49 +00:00
|
|
|
class KRNode : public KRContextObject
|
2012-04-12 00:43:53 +00:00
|
|
|
{
|
|
|
|
|
public:
|
2012-06-14 19:33:17 +00:00
|
|
|
enum RenderPass {
|
|
|
|
|
RENDER_PASS_FORWARD_OPAQUE,
|
|
|
|
|
RENDER_PASS_DEFERRED_GBUFFER,
|
|
|
|
|
RENDER_PASS_DEFERRED_LIGHTS,
|
|
|
|
|
RENDER_PASS_DEFERRED_OPAQUE,
|
|
|
|
|
RENDER_PASS_FORWARD_TRANSPARENT,
|
2013-01-17 19:27:17 -08:00
|
|
|
RENDER_PASS_PARTICLE_OCCLUSION,
|
2012-11-02 20:50:45 +00:00
|
|
|
RENDER_PASS_ADDITIVE_PARTICLES,
|
2012-11-15 22:05:25 +00:00
|
|
|
RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE,
|
|
|
|
|
RENDER_PASS_GENERATE_SHADOWMAPS,
|
2012-10-25 18:48:25 +00:00
|
|
|
RENDER_PASS_SHADOWMAP
|
2012-06-14 19:33:17 +00:00
|
|
|
};
|
|
|
|
|
|
2012-08-29 21:43:11 +00:00
|
|
|
KRNode(KRScene &scene, std::string name);
|
2012-04-12 00:43:53 +00:00
|
|
|
virtual ~KRNode();
|
|
|
|
|
|
|
|
|
|
virtual tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent);
|
2012-08-29 21:43:11 +00:00
|
|
|
static KRNode *LoadXML(KRScene &scene, tinyxml2::XMLElement *e);
|
2012-04-12 01:27:30 +00:00
|
|
|
virtual void loadXML(tinyxml2::XMLElement *e);
|
|
|
|
|
|
2012-04-12 00:43:53 +00:00
|
|
|
virtual std::string getElementName();
|
2012-04-26 09:06:45 +00:00
|
|
|
const std::string &getName();
|
2012-04-12 00:43:53 +00:00
|
|
|
|
|
|
|
|
void addChild(KRNode *child);
|
2012-04-19 23:39:32 +00:00
|
|
|
const std::vector<KRNode *> &getChildren();
|
2012-04-12 00:43:53 +00:00
|
|
|
|
2012-12-07 20:11:21 +00:00
|
|
|
void setLocalTranslation(const KRVector3 &v, bool set_original = false);
|
|
|
|
|
void setLocalScale(const KRVector3 &v, bool set_original = false);
|
|
|
|
|
void setLocalRotation(const KRVector3 &v, bool set_original = false);
|
2012-04-12 00:43:53 +00:00
|
|
|
|
|
|
|
|
const KRVector3 &getLocalTranslation();
|
|
|
|
|
const KRVector3 &getLocalScale();
|
|
|
|
|
const KRVector3 &getLocalRotation();
|
|
|
|
|
|
2012-12-14 20:45:16 +00:00
|
|
|
const KRVector3 &getInitialLocalTranslation();
|
|
|
|
|
const KRVector3 &getInitialLocalScale();
|
|
|
|
|
const KRVector3 &getInitialLocalRotation();
|
|
|
|
|
|
2013-01-03 21:42:50 +00:00
|
|
|
const KRVector3 getWorldTranslation();
|
|
|
|
|
const KRVector3 getWorldScale();
|
|
|
|
|
const KRVector3 getWorldRotation();
|
2012-04-19 23:39:32 +00:00
|
|
|
|
2013-01-03 23:12:39 +00:00
|
|
|
void setWorldTranslation(const KRVector3 &v);
|
|
|
|
|
void setWorldScale(const KRVector3 &v);
|
|
|
|
|
void setWorldRotation(const KRVector3 &v);
|
|
|
|
|
|
2012-09-11 03:06:35 +00:00
|
|
|
virtual KRAABB getBounds();
|
2012-11-03 02:57:35 +00:00
|
|
|
const KRMat4 &getModelMatrix();
|
2012-12-15 01:39:32 +00:00
|
|
|
const KRMat4 &getInverseModelMatrix();
|
2012-12-13 18:32:02 +00:00
|
|
|
const KRMat4 &getBindPoseMatrix();
|
|
|
|
|
const KRMat4 &getInverseBindPoseMatrix();
|
2012-08-29 21:43:11 +00:00
|
|
|
|
2012-12-07 00:20:06 +00:00
|
|
|
enum node_attribute_type {
|
|
|
|
|
KRENGINE_NODE_ATTRIBUTE_NONE,
|
|
|
|
|
KRENGINE_NODE_ATTRIBUTE_TRANSLATE_X,
|
|
|
|
|
KRENGINE_NODE_ATTRIBUTE_TRANSLATE_Y,
|
|
|
|
|
KRENGINE_NODE_ATTRIBUTE_TRANSLATE_Z,
|
|
|
|
|
KRENGINE_NODE_ATTRIBUTE_SCALE_X,
|
|
|
|
|
KRENGINE_NODE_ATTRIBUTE_SCALE_Y,
|
|
|
|
|
KRENGINE_NODE_ATTRIBUTE_SCALE_Z,
|
|
|
|
|
KRENGINE_NODE_ATTRIBUTE_ROTATE_X,
|
|
|
|
|
KRENGINE_NODE_ATTRIBUTE_ROTATE_Y,
|
|
|
|
|
KRENGINE_NODE_ATTRIBUTE_ROTATE_Z
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void SetAttribute(node_attribute_type attrib, float v);
|
|
|
|
|
|
2012-08-29 21:43:11 +00:00
|
|
|
KRScene &getScene();
|
2012-04-12 06:04:15 +00:00
|
|
|
|
2012-11-16 02:58:23 +00:00
|
|
|
virtual void render(KRCamera *pCamera, std::vector<KRLight *> &lights, const KRViewport &viewport, RenderPass renderPass);
|
2012-04-12 06:04:15 +00:00
|
|
|
|
2012-11-09 09:18:38 +00:00
|
|
|
virtual void physicsUpdate(float deltaTime);
|
|
|
|
|
virtual bool hasPhysics();
|
|
|
|
|
|
2012-04-12 06:04:15 +00:00
|
|
|
protected:
|
2012-04-12 00:43:53 +00:00
|
|
|
KRVector3 m_localTranslation;
|
|
|
|
|
KRVector3 m_localScale;
|
|
|
|
|
KRVector3 m_localRotation;
|
|
|
|
|
|
2012-12-13 18:32:02 +00:00
|
|
|
KRVector3 m_initialLocalTranslation;
|
|
|
|
|
KRVector3 m_initialLocalScale;
|
|
|
|
|
KRVector3 m_initialLocalRotation;
|
2012-12-07 20:11:21 +00:00
|
|
|
|
2013-01-17 19:27:17 -08:00
|
|
|
KRNode *m_parentNode;
|
|
|
|
|
|
2012-10-04 22:29:01 +00:00
|
|
|
private:
|
2012-11-03 02:57:35 +00:00
|
|
|
void invalidateModelMatrix();
|
2012-12-13 21:04:37 +00:00
|
|
|
void invalidateBindPoseMatrix();
|
2012-11-03 02:57:35 +00:00
|
|
|
KRMat4 m_modelMatrix;
|
2012-12-15 01:39:32 +00:00
|
|
|
KRMat4 m_inverseModelMatrix;
|
2012-12-13 18:32:02 +00:00
|
|
|
KRMat4 m_bindPoseMatrix;
|
|
|
|
|
KRMat4 m_inverseBindPoseMatrix;
|
2012-11-03 02:57:35 +00:00
|
|
|
bool m_modelMatrixValid;
|
2012-12-15 01:39:32 +00:00
|
|
|
bool m_inverseModelMatrixValid;
|
2012-12-13 18:32:02 +00:00
|
|
|
bool m_bindPoseMatrixValid;
|
|
|
|
|
bool m_inverseBindPoseMatrixValid;
|
2012-09-13 20:09:19 +00:00
|
|
|
|
2012-04-12 00:43:53 +00:00
|
|
|
std::string m_name;
|
|
|
|
|
|
|
|
|
|
std::vector<KRNode *> m_childNodes;
|
2012-04-12 06:04:15 +00:00
|
|
|
|
2012-08-29 21:43:11 +00:00
|
|
|
KRScene *m_pScene;
|
|
|
|
|
|
2013-02-21 16:22:56 -08:00
|
|
|
std::set<KROctreeNode *> m_octree_nodes;
|
|
|
|
|
|
2012-12-20 22:08:41 +00:00
|
|
|
public:
|
|
|
|
|
|
2013-02-21 16:22:56 -08:00
|
|
|
void removeFromOctreeNodes();
|
|
|
|
|
void addToOctreeNode(KROctreeNode *octree_node);
|
|
|
|
|
|
2012-12-20 22:08:41 +00:00
|
|
|
template <class T> T *find()
|
|
|
|
|
{
|
|
|
|
|
T *match = dynamic_cast<T *>(this);
|
|
|
|
|
if(match) {
|
|
|
|
|
return match;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(std::vector<KRNode *>::const_iterator itr=m_childNodes.begin(); itr < m_childNodes.end(); ++itr) {
|
|
|
|
|
match = (*itr)->find<T>();
|
|
|
|
|
if(match) {
|
|
|
|
|
return match;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <class T> T *find(const std::string &name)
|
|
|
|
|
{
|
|
|
|
|
T *match = dynamic_cast<T *>(this);
|
|
|
|
|
if(match) {
|
2013-01-12 05:12:51 +00:00
|
|
|
if(name.compare(match->getName()) == 0) {
|
2012-12-20 22:08:41 +00:00
|
|
|
return match;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(std::vector<KRNode *>::const_iterator itr=m_childNodes.begin(); itr < m_childNodes.end(); ++itr) {
|
2013-01-12 05:12:51 +00:00
|
|
|
match = (*itr)->find<T>(name);
|
2012-12-20 22:08:41 +00:00
|
|
|
if(match) {
|
|
|
|
|
return match;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2012-04-12 00:43:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|