Corrected bug in ray cast function which caused it return inaccurate results
Exposed the KRViewport from the KRCamera object Fixed crash that occurred if you deleted a KRNode KRNode children are now in an un-ordered std::set instead of an ordered std::vector
This commit is contained in:
@@ -1045,3 +1045,9 @@ std::string KRCamera::getDebugText()
|
|||||||
}
|
}
|
||||||
return stream.str();
|
return stream.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const KRViewport &KRCamera::getViewport()
|
||||||
|
{
|
||||||
|
return m_viewport;
|
||||||
|
}
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ public:
|
|||||||
void renderFrame(float deltaTime, GLint renderBufferWidth, GLint renderBufferHeight);
|
void renderFrame(float deltaTime, GLint renderBufferWidth, GLint renderBufferHeight);
|
||||||
|
|
||||||
KRRenderSettings settings;
|
KRRenderSettings settings;
|
||||||
|
|
||||||
|
const KRViewport &getViewport();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void createBuffers(GLint renderBufferWidth, GLint renderBufferHeight);
|
void createBuffers(GLint renderBufferWidth, GLint renderBufferHeight);
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ void KRLODGroup::updateLODVisibility(const KRViewport &viewport)
|
|||||||
getScene().notify_sceneGraphCreate(this);
|
getScene().notify_sceneGraphCreate(this);
|
||||||
m_lod_visible = true;
|
m_lod_visible = true;
|
||||||
}
|
}
|
||||||
for(std::vector<KRNode *>::iterator itr=m_childNodes.begin(); itr < m_childNodes.end(); ++itr) {
|
for(std::set<KRNode *>::iterator itr=m_childNodes.begin(); itr != m_childNodes.end(); ++itr) {
|
||||||
(*itr)->updateLODVisibility(viewport);
|
(*itr)->updateLODVisibility(viewport);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,17 +42,28 @@ KRNode::KRNode(KRScene &scene, std::string name) : KRContextObject(scene.getCont
|
|||||||
}
|
}
|
||||||
|
|
||||||
KRNode::~KRNode() {
|
KRNode::~KRNode() {
|
||||||
getScene().notify_sceneGraphDelete(this);
|
while(m_childNodes.size() > 0) {
|
||||||
for(std::vector<KRNode *>::iterator itr=m_childNodes.begin(); itr < m_childNodes.end(); ++itr) {
|
delete *m_childNodes.begin();
|
||||||
delete *itr;
|
|
||||||
}
|
}
|
||||||
m_childNodes.clear();
|
|
||||||
|
if(m_parentNode) {
|
||||||
|
m_parentNode->childDeleted(this);
|
||||||
|
}
|
||||||
|
getScene().notify_sceneGraphDelete(this);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void KRNode::childDeleted(KRNode *child_node)
|
||||||
|
{
|
||||||
|
m_childNodes.erase(child_node);
|
||||||
|
// InvalidateBounds();
|
||||||
|
getScene().notify_sceneGraphModify(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRNode::addChild(KRNode *child) {
|
void KRNode::addChild(KRNode *child) {
|
||||||
assert(child->m_parentNode == NULL);
|
assert(child->m_parentNode == NULL);
|
||||||
child->m_parentNode = this;
|
child->m_parentNode = this;
|
||||||
m_childNodes.push_back(child);
|
m_childNodes.insert(child);
|
||||||
if(m_lod_visible) {
|
if(m_lod_visible) {
|
||||||
// Child node inherits LOD visibility status from parent
|
// Child node inherits LOD visibility status from parent
|
||||||
child->showLOD();
|
child->showLOD();
|
||||||
@@ -73,7 +84,7 @@ tinyxml2::XMLElement *KRNode::saveXML(tinyxml2::XMLNode *parent) {
|
|||||||
e->SetAttribute("rotate_x", m_localRotation.x * 180 / M_PI);
|
e->SetAttribute("rotate_x", m_localRotation.x * 180 / M_PI);
|
||||||
e->SetAttribute("rotate_y", m_localRotation.y * 180 / M_PI);
|
e->SetAttribute("rotate_y", m_localRotation.y * 180 / M_PI);
|
||||||
e->SetAttribute("rotate_z", m_localRotation.z * 180 / M_PI);
|
e->SetAttribute("rotate_z", m_localRotation.z * 180 / M_PI);
|
||||||
for(std::vector<KRNode *>::iterator itr=m_childNodes.begin(); itr < m_childNodes.end(); ++itr) {
|
for(std::set<KRNode *>::iterator itr=m_childNodes.begin(); itr != m_childNodes.end(); ++itr) {
|
||||||
KRNode *child = (*itr);
|
KRNode *child = (*itr);
|
||||||
child->saveXML(n);
|
child->saveXML(n);
|
||||||
}
|
}
|
||||||
@@ -265,7 +276,7 @@ void KRNode::render(KRCamera *pCamera, std::vector<KRPointLight *> &point_lights
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<KRNode *> &KRNode::getChildren() {
|
const std::set<KRNode *> &KRNode::getChildren() {
|
||||||
return m_childNodes;
|
return m_childNodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,7 +292,7 @@ KRAABB KRNode::getBounds() {
|
|||||||
KRAABB bounds = KRAABB::Zero();
|
KRAABB bounds = KRAABB::Zero();
|
||||||
|
|
||||||
bool first_child = true;
|
bool first_child = true;
|
||||||
for(std::vector<KRNode *>::iterator itr=m_childNodes.begin(); itr < m_childNodes.end(); ++itr) {
|
for(std::set<KRNode *>::iterator itr=m_childNodes.begin(); itr != m_childNodes.end(); ++itr) {
|
||||||
KRNode *child = (*itr);
|
KRNode *child = (*itr);
|
||||||
if(child->getBounds() != KRAABB::Zero()) {
|
if(child->getBounds() != KRAABB::Zero()) {
|
||||||
if(first_child) {
|
if(first_child) {
|
||||||
@@ -300,11 +311,12 @@ void KRNode::invalidateModelMatrix()
|
|||||||
{
|
{
|
||||||
m_modelMatrixValid = false;
|
m_modelMatrixValid = false;
|
||||||
m_inverseModelMatrixValid = false;
|
m_inverseModelMatrixValid = false;
|
||||||
for(std::vector<KRNode *>::iterator itr=m_childNodes.begin(); itr < m_childNodes.end(); ++itr) {
|
for(std::set<KRNode *>::iterator itr=m_childNodes.begin(); itr != m_childNodes.end(); ++itr) {
|
||||||
KRNode *child = (*itr);
|
KRNode *child = (*itr);
|
||||||
child->invalidateModelMatrix();
|
child->invalidateModelMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InvalidateBounds
|
||||||
getScene().notify_sceneGraphModify(this);
|
getScene().notify_sceneGraphModify(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -312,7 +324,7 @@ void KRNode::invalidateBindPoseMatrix()
|
|||||||
{
|
{
|
||||||
m_bindPoseMatrixValid = false;
|
m_bindPoseMatrixValid = false;
|
||||||
m_inverseBindPoseMatrixValid = false;
|
m_inverseBindPoseMatrixValid = false;
|
||||||
for(std::vector<KRNode *>::iterator itr=m_childNodes.begin(); itr < m_childNodes.end(); ++itr) {
|
for(std::set<KRNode *>::iterator itr=m_childNodes.begin(); itr != m_childNodes.end(); ++itr) {
|
||||||
KRNode *child = (*itr);
|
KRNode *child = (*itr);
|
||||||
child->invalidateBindPoseMatrix();
|
child->invalidateBindPoseMatrix();
|
||||||
}
|
}
|
||||||
@@ -470,7 +482,7 @@ void KRNode::hideLOD()
|
|||||||
if(m_lod_visible) {
|
if(m_lod_visible) {
|
||||||
m_lod_visible = false;
|
m_lod_visible = false;
|
||||||
getScene().notify_sceneGraphDelete(this);
|
getScene().notify_sceneGraphDelete(this);
|
||||||
for(std::vector<KRNode *>::iterator itr=m_childNodes.begin(); itr < m_childNodes.end(); ++itr) {
|
for(std::set<KRNode *>::iterator itr=m_childNodes.begin(); itr != m_childNodes.end(); ++itr) {
|
||||||
(*itr)->hideLOD();
|
(*itr)->hideLOD();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -481,7 +493,7 @@ void KRNode::showLOD()
|
|||||||
if(!m_lod_visible) {
|
if(!m_lod_visible) {
|
||||||
getScene().notify_sceneGraphCreate(this);
|
getScene().notify_sceneGraphCreate(this);
|
||||||
m_lod_visible = true;
|
m_lod_visible = true;
|
||||||
for(std::vector<KRNode *>::iterator itr=m_childNodes.begin(); itr < m_childNodes.end(); ++itr) {
|
for(std::set<KRNode *>::iterator itr=m_childNodes.begin(); itr != m_childNodes.end(); ++itr) {
|
||||||
(*itr)->showLOD();
|
(*itr)->showLOD();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ public:
|
|||||||
const std::string &getName() const;
|
const std::string &getName() const;
|
||||||
|
|
||||||
void addChild(KRNode *child);
|
void addChild(KRNode *child);
|
||||||
const std::vector<KRNode *> &getChildren();
|
const std::set<KRNode *> &getChildren();
|
||||||
|
|
||||||
void setLocalTranslation(const KRVector3 &v, bool set_original = false);
|
void setLocalTranslation(const KRVector3 &v, bool set_original = false);
|
||||||
void setLocalScale(const KRVector3 &v, bool set_original = false);
|
void setLocalScale(const KRVector3 &v, bool set_original = false);
|
||||||
@@ -130,7 +130,7 @@ protected:
|
|||||||
float m_lod_max_coverage;
|
float m_lod_max_coverage;
|
||||||
|
|
||||||
KRNode *m_parentNode;
|
KRNode *m_parentNode;
|
||||||
std::vector<KRNode *> m_childNodes;
|
std::set<KRNode *> m_childNodes;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void invalidateModelMatrix();
|
void invalidateModelMatrix();
|
||||||
@@ -156,6 +156,7 @@ public:
|
|||||||
|
|
||||||
void removeFromOctreeNodes();
|
void removeFromOctreeNodes();
|
||||||
void addToOctreeNode(KROctreeNode *octree_node);
|
void addToOctreeNode(KROctreeNode *octree_node);
|
||||||
|
void childDeleted(KRNode *child_node);
|
||||||
|
|
||||||
template <class T> T *find()
|
template <class T> T *find()
|
||||||
{
|
{
|
||||||
@@ -164,7 +165,7 @@ public:
|
|||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(std::vector<KRNode *>::const_iterator itr=m_childNodes.begin(); itr < m_childNodes.end(); ++itr) {
|
for(std::set<KRNode *>::const_iterator itr=m_childNodes.begin(); itr != m_childNodes.end(); ++itr) {
|
||||||
match = (*itr)->find<T>();
|
match = (*itr)->find<T>();
|
||||||
if(match) {
|
if(match) {
|
||||||
return match;
|
return match;
|
||||||
@@ -183,7 +184,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(std::vector<KRNode *>::const_iterator itr=m_childNodes.begin(); itr < m_childNodes.end(); ++itr) {
|
for(std::set<KRNode *>::const_iterator itr=m_childNodes.begin(); itr != m_childNodes.end(); ++itr) {
|
||||||
match = (*itr)->find<T>(name);
|
match = (*itr)->find<T>(name);
|
||||||
if(match) {
|
if(match) {
|
||||||
return match;
|
return match;
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ bool KROctree::rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(m_pRootNode) {
|
if(m_pRootNode) {
|
||||||
if(m_pRootNode->lineCast(v0, dir, hitinfo, layer_mask)) hit_found = true;
|
if(m_pRootNode->rayCast(v0, dir, hitinfo, layer_mask)) hit_found = true;
|
||||||
}
|
}
|
||||||
return hit_found;
|
return hit_found;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user