lod_group nodes now have a reference point attribute, enabling use of lod_groups containing objects with a centre that is not at the pivot point of the lod_group node.
Numerous small bug fixes.
This commit is contained in:
@@ -13,6 +13,7 @@ KRLODGroup::KRLODGroup(KRScene &scene, std::string name) : KRNode(scene, name)
|
||||
{
|
||||
m_min_distance = 0.0f;
|
||||
m_max_distance = 0.0f;
|
||||
m_referencePoint = KRVector3::Zero();
|
||||
}
|
||||
|
||||
KRLODGroup::~KRLODGroup()
|
||||
@@ -28,6 +29,10 @@ tinyxml2::XMLElement *KRLODGroup::saveXML( tinyxml2::XMLNode *parent)
|
||||
tinyxml2::XMLElement *e = KRNode::saveXML(parent);
|
||||
e->SetAttribute("min_distance", m_min_distance);
|
||||
e->SetAttribute("max_distance", m_max_distance);
|
||||
|
||||
e->SetAttribute("reference_x", m_referencePoint.x);
|
||||
e->SetAttribute("reference_y", m_referencePoint.y);
|
||||
e->SetAttribute("reference_z", m_referencePoint.z);
|
||||
return e;
|
||||
}
|
||||
|
||||
@@ -44,13 +49,49 @@ void KRLODGroup::loadXML(tinyxml2::XMLElement *e)
|
||||
if(e->QueryFloatAttribute("max_distance", &m_max_distance) != tinyxml2::XML_SUCCESS) {
|
||||
m_max_distance = 0.0f;
|
||||
}
|
||||
|
||||
|
||||
float x=0.0f, y=0.0f, z=0.0f;
|
||||
if(e->QueryFloatAttribute("reference_x", &x) != tinyxml2::XML_SUCCESS) {
|
||||
x = 0.0f;
|
||||
}
|
||||
if(e->QueryFloatAttribute("reference_y", &y) != tinyxml2::XML_SUCCESS) {
|
||||
y = 0.0f;
|
||||
}
|
||||
if(e->QueryFloatAttribute("reference_z", &z) != tinyxml2::XML_SUCCESS) {
|
||||
z = 0.0f;
|
||||
}
|
||||
m_referencePoint = KRVector3(x,y,z);
|
||||
}
|
||||
|
||||
|
||||
const KRVector3 KRLODGroup::getReferencePoint()
|
||||
{
|
||||
return m_referencePoint;
|
||||
}
|
||||
|
||||
void KRLODGroup::setReferencePoint(const KRVector3 &referencePoint)
|
||||
{
|
||||
m_referencePoint = referencePoint;
|
||||
}
|
||||
|
||||
const KRVector3 KRLODGroup::getWorldReferencePoint()
|
||||
{
|
||||
return localToWorld(m_referencePoint);
|
||||
}
|
||||
|
||||
bool KRLODGroup::getLODVisibility(const KRViewport &viewport)
|
||||
{
|
||||
// Compare square distances as sqrt is expensive
|
||||
float sqr_distance = (viewport.getCameraPosition() - getWorldTranslation()).sqrMagnitude();
|
||||
return ((sqr_distance >= m_min_distance * m_min_distance || m_min_distance == 0) && (sqr_distance < m_max_distance * m_max_distance || m_max_distance == 0));
|
||||
if(m_min_distance == 0 && m_max_distance == 0) {
|
||||
return true;
|
||||
} else {
|
||||
// return (m_max_distance == 0); // FINDME, HACK - Test code to enable only the lowest LOD group
|
||||
float lod_bias = 1.0f;
|
||||
|
||||
// Compare square distances as sqrt is expensive
|
||||
float sqr_distance = (viewport.getCameraPosition() - getWorldReferencePoint()).sqrMagnitude() * (lod_bias * lod_bias);
|
||||
return ((sqr_distance >= m_min_distance * m_min_distance || m_min_distance == 0) && (sqr_distance < m_max_distance * m_max_distance || m_max_distance == 0));
|
||||
}
|
||||
}
|
||||
|
||||
void KRLODGroup::updateLODVisibility(const KRViewport &viewport)
|
||||
|
||||
Reference in New Issue
Block a user