diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-02-25 09:43:03 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-02-25 09:43:03 +0300 |
commit | c77af311665d230ed933138cd20962d021ad5c2b (patch) | |
tree | 5c2f89032fb773a046aab0a7a6c9a17162260b99 /source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp | |
parent | 2eb85c01f3e0ea2ba9dd129ae70e8b370953d7b5 (diff) |
Minor speedups for the BGE
* Where possible use vec.setValue(x,y,z) to assign values to a vector instead of vec= MT_Vector3(x,y,z), for MT_Point and MT_Matrix types too.
* Comparing TexVerts was creating 10 MT_Vector types - instead compare as floats.
* Added SG_Spatial::SetWorldFromLocalTransform() since the local transform is use for world transform in some cases.
* removed some unneeded vars from UpdateChildCoordinates functions
* Py API - Mouse, Ray, Radar sensors - use PyObjectFrom(vec) rather then filling the lists in each function. Use METH_NOARGS for get*() functions.
Diffstat (limited to 'source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp')
-rw-r--r-- | source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp | 80 |
1 files changed, 16 insertions, 64 deletions
diff --git a/source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp b/source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp index 0c8e7e28771..0729ec8a902 100644 --- a/source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp +++ b/source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp @@ -55,43 +55,21 @@ UpdateChildCoordinates( ){ MT_assert(child != NULL); - // This way of accessing child coordinates is a bit cumbersome - // be nice to have non constant reference access to these values. - - const MT_Vector3 & child_scale = child->GetLocalScale(); - const MT_Point3 & child_pos = child->GetLocalPosition(); - const MT_Matrix3x3 & child_rotation = child->GetLocalOrientation(); - - // the childs world locations which we will update. - - MT_Vector3 child_w_scale; - MT_Point3 child_w_pos; - MT_Matrix3x3 child_w_rotation; - - if (parent) { - + if (parent==NULL) { /* Simple case */ + child->SetWorldFromLocalTransform(); + return false; + } + else { + // the childs world locations which we will update. const MT_Vector3 & p_world_scale = parent->GetWorldScaling(); const MT_Point3 & p_world_pos = parent->GetWorldPosition(); const MT_Matrix3x3 & p_world_rotation = parent->GetWorldOrientation(); - child_w_scale = p_world_scale * child_scale; - child_w_rotation = p_world_rotation * child_rotation; - - child_w_pos = p_world_pos + p_world_scale * - (p_world_rotation * child_pos); - - } else { - - child_w_scale = child_scale; - child_w_pos = child_pos; - child_w_rotation = child_rotation; + child->SetWorldScale(p_world_scale * child->GetLocalScale()); + child->SetWorldOrientation(p_world_rotation * child->GetLocalOrientation()); + child->SetWorldPosition(p_world_pos + p_world_scale * (p_world_rotation * child->GetLocalPosition())); + return true; } - - child->SetWorldScale(child_w_scale); - child->SetWorldPosition(child_w_pos); - child->SetWorldOrientation(child_w_rotation); - - return parent != NULL; } SG_ParentRelation * @@ -138,40 +116,14 @@ UpdateChildCoordinates( ){ MT_assert(child != NULL); - - const MT_Vector3 & child_scale = child->GetLocalScale(); - const MT_Point3 & child_pos = child->GetLocalPosition(); - const MT_Matrix3x3 & child_rotation = child->GetLocalOrientation(); - - // the childs world locations which we will update. + child->SetWorldScale(child->GetLocalScale()); - MT_Vector3 child_w_scale; - MT_Point3 child_w_pos; - MT_Matrix3x3 child_w_rotation; - - if (parent) { - - // This is a vertex parent so we do not inherit orientation - // information. - - // const MT_Vector3 & p_world_scale = parent->GetWorldScaling(); /*unused*/ - const MT_Point3 & p_world_pos = parent->GetWorldPosition(); - // const MT_Matrix3x3 & p_world_rotation = parent->GetWorldOrientation(); /*unused*/ - - child_w_scale = child_scale; - child_w_rotation = child_rotation; - child_w_pos = p_world_pos + child_pos; - } else { - - child_w_scale = child_scale; - child_w_pos = child_pos; - child_w_rotation = child_rotation; - } - - child->SetWorldScale(child_w_scale); - child->SetWorldPosition(child_w_pos); - child->SetWorldOrientation(child_w_rotation); + if (parent) + child->SetWorldPosition(child->GetLocalPosition()+parent->GetWorldPosition()); + else + child->SetWorldPosition(child->GetLocalPosition()); + child->SetWorldOrientation(child->GetLocalOrientation()); return parent != NULL; } |