Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Szepe <HG1_public@gmx.net>2015-05-14 10:40:03 +0300
committerThomas Szepe <HG1_public@gmx.net>2015-05-14 10:40:03 +0300
commit687f6a9752fd2009f67dd0b66208777cd203bde1 (patch)
tree235aeebe087aac4668d70b6a5d13d2f632f4586a /source/gameengine/Ketsji/KX_GameObject.cpp
parent434086dc53aa03205714bb0415550bb158edcf43 (diff)
BGE: Code Cleanup: LOD hysteresis calculation
* Cleanup duplicated code. * Remove unnecessary "this->" Reviewers: kupoman, lordloki Reviewed By: kupoman, lordloki Differential Revision: https://developer.blender.org/D1293
Diffstat (limited to 'source/gameengine/Ketsji/KX_GameObject.cpp')
-rw-r--r--source/gameengine/Ketsji/KX_GameObject.cpp90
1 files changed, 48 insertions, 42 deletions
diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp
index 44d9bfa0cf4..14a7324d2b9 100644
--- a/source/gameengine/Ketsji/KX_GameObject.cpp
+++ b/source/gameengine/Ketsji/KX_GameObject.cpp
@@ -806,68 +806,74 @@ void KX_GameObject::AddLodMesh(RAS_MeshObject* mesh)
m_lodmeshes.push_back(mesh);
}
+
+static float calcHysteresis(KX_Scene *kxscene, LodLevel *lod)
+{
+ float hystvariance = 0.0f;
+
+ if (!kxscene->IsActivedLodHysteresis())
+ return hystvariance;
+
+ short hysteresis = 0;
+ // if exists, LoD level hysteresis will override scene hysteresis
+ if (lod->next->flags & OB_LOD_USE_HYST)
+ hysteresis = lod->next->obhysteresis;
+ else
+ hysteresis = kxscene->GetLodHysteresisValue();
+
+ return hystvariance = MT_abs(lod->next->distance - lod->distance) * hysteresis / 100;
+}
+
void KX_GameObject::UpdateLod(MT_Vector3 &cam_pos)
{
// Handle dupligroups
- if (this->m_pInstanceObjects) {
- KX_GameObject * instob;
- int count = this->m_pInstanceObjects->GetCount();
+ if (m_pInstanceObjects) {
+ KX_GameObject *instob;
+ int count = m_pInstanceObjects->GetCount();
for (int i = 0; i < count; i++) {
- instob = (KX_GameObject*)this->m_pInstanceObjects->GetValue(i);
+ instob = (KX_GameObject*)m_pInstanceObjects->GetValue(i);
instob->UpdateLod(cam_pos);
}
}
- if (this->m_lodmeshes.empty()) return;
+ if (m_lodmeshes.empty())
+ return;
- MT_Vector3 delta = this->NodeGetWorldPosition() - cam_pos;
+ MT_Vector3 delta = NodeGetWorldPosition() - cam_pos;
float distance2 = delta.length2();
int level = 0;
- Object *bob = this->GetBlenderObject();
- LodLevel *lod = (LodLevel*) bob->lodlevels.first;
- KX_Scene *kxscene = this->GetScene();
+ float hystvariance = 0.0f;
+ Object *bob = GetBlenderObject();
+ LodLevel *lod = (LodLevel *)bob->lodlevels.first;
+ KX_Scene *kxscene = GetScene();
for (; lod; lod = lod->next, level++) {
- if (!lod->source || lod->source->type != OB_MESH) level--;
- if (!lod->next) break;
- if (level == (this->m_previousLodLevel) || (level == (this->m_previousLodLevel + 1))) {
- short hysteresis = 0;
- if (kxscene->IsActivedLodHysteresis()) {
- // if exists, LoD level hysteresis will override scene hysteresis
- if (lod->next->flags & OB_LOD_USE_HYST) {
- hysteresis = lod->next->obhysteresis;
- }
- else {
- hysteresis = kxscene->GetLodHysteresisValue();
- }
- }
- float hystvariance = MT_abs(lod->next->distance - lod->distance) * hysteresis / 100;
- if ((lod->next->distance + hystvariance) * (lod->next->distance + hystvariance) > distance2)
+ if (!lod->source || lod->source->type != OB_MESH)
+ level--;
+
+ if (!lod->next)
+ break;
+
+ if (level == m_previousLodLevel || level == (m_previousLodLevel + 1)) {
+ hystvariance = calcHysteresis(kxscene, lod);
+ float newdistance = lod->next->distance + hystvariance;
+ if (newdistance * newdistance > distance2)
break;
}
- else if (level == (this->m_previousLodLevel - 1)) {
- short hysteresis = 0;
- if (kxscene->IsActivedLodHysteresis()) {
- // if exists, LoD level hysteresis will override scene hysteresis
- if (lod->next->flags & OB_LOD_USE_HYST) {
- hysteresis = lod->next->obhysteresis;
- }
- else {
- hysteresis = kxscene->GetLodHysteresisValue();
- }
- }
- float hystvariance = MT_abs(lod->next->distance - lod->distance) * hysteresis / 100;
- if ((lod->next->distance - hystvariance) * (lod->next->distance - hystvariance) > distance2)
+ else if (level == (m_previousLodLevel - 1)) {
+ hystvariance = calcHysteresis(kxscene, lod);
+ float newdistance = lod->next->distance - hystvariance;
+ if (newdistance * newdistance > distance2)
break;
}
}
- RAS_MeshObject *mesh = this->m_lodmeshes[level];
- this->m_currentLodLevel = level;
- if (mesh != this->m_meshes[0]) {
- this->m_previousLodLevel = level;
- this->GetScene()->ReplaceMesh(this, mesh, true, false);
+ RAS_MeshObject *mesh = m_lodmeshes[level];
+ m_currentLodLevel = level;
+ if (mesh != m_meshes[0]) {
+ m_previousLodLevel = level;
+ GetScene()->ReplaceMesh(this, mesh, true, false);
}
}