-
Notifications
You must be signed in to change notification settings - Fork 15
Bugfix/bounding box bracket iteration #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
6b12cfe
b5e325e
2f63866
5ce1797
cccde3a
32593d9
b9790b1
de0a05e
48d52ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| #include "EveEffectRoot2.h" | ||
|
|
||
| #include "Utilities/BoundingSphere.h" | ||
| #include "Utilities/BoundingBox.h" | ||
| #include "TriFrustum.h" | ||
| #include "Lights/Tr2PointLight.h" | ||
| #include "Tr2LightManager.h" | ||
|
|
@@ -13,8 +14,60 @@ | |
| #include "Eve/SpaceObject/EveSpaceObject2.h" | ||
| #include "Eve/SpaceObject/Children/EveChildContainer.h" | ||
|
|
||
| #include <cmath> | ||
|
|
||
| extern float g_eveSpaceObjectResourceUnloadingTimeThreshold; | ||
|
|
||
| namespace | ||
| { | ||
| bool IsFinite( const Vector3& v ) | ||
| { | ||
| return std::isfinite( v.x ) && std::isfinite( v.y ) && std::isfinite( v.z ); | ||
| } | ||
|
|
||
| bool IsValidBoundingSphere( const Vector4& sphere ) | ||
| { | ||
| return sphere.w > 0.0f && | ||
| std::isfinite( sphere.x ) && | ||
| std::isfinite( sphere.y ) && | ||
| std::isfinite( sphere.z ) && | ||
| std::isfinite( sphere.w ); | ||
| } | ||
|
|
||
| void IncludeWorldBounds( const Vector3& boundsMin, const Vector3& boundsMax, Vector3& min, Vector3& max, bool& valid ) | ||
| { | ||
| if( !IsFinite( boundsMin ) || !IsFinite( boundsMax ) ) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| if( !valid ) | ||
| { | ||
| min = boundsMin; | ||
| max = boundsMax; | ||
| valid = true; | ||
| } | ||
| else | ||
| { | ||
| BoundingBoxUpdate( min, max, boundsMin, boundsMax ); | ||
| } | ||
| } | ||
|
|
||
| void IncludeWorldSphereBounds( const Vector4& sphere, Vector3& min, Vector3& max, bool& valid ) | ||
| { | ||
| if( !IsValidBoundingSphere( sphere ) ) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| Vector3 sphereMin; | ||
| Vector3 sphereMax; | ||
| BoundingBoxInitialize( sphere, sphereMin, sphereMax ); | ||
| IncludeWorldBounds( sphereMin, sphereMax, min, max, valid ); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| EveEffectRoot2::EveEffectRoot2( IRoot* lockobj ) : | ||
| PARENTLOCK( m_observers ), | ||
| PARENTLOCK( m_lights ), | ||
|
|
@@ -398,8 +451,13 @@ void EveEffectRoot2::GetModelCenterWorldPosition( Vector3 &position ) const | |
|
|
||
| bool EveEffectRoot2::GetLocalBoundingBox( Vector3 &min, Vector3 &max ) | ||
| { | ||
| // If possible, return an AABB in local coordinates | ||
| return false; | ||
| if( !IsValidBoundingSphere( m_boundingSphere ) ) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| BoundingBoxInitialize( m_boundingSphere, min, max ); | ||
| return true; | ||
| } | ||
|
|
||
| void EveEffectRoot2::GetLocalToWorldTransform( Matrix &transform ) const | ||
|
|
@@ -408,6 +466,50 @@ void EveEffectRoot2::GetLocalToWorldTransform( Matrix &transform ) const | |
| transform = m_lastUpdateMatrix; | ||
| } | ||
|
|
||
| bool EveEffectRoot2::GetWorldBoundingBox( Vector3& min, Vector3& max ) const | ||
| { | ||
| bool valid = false; | ||
|
|
||
| if( IsValidBoundingSphere( m_boundingSphere ) ) | ||
| { | ||
| Vector3 rootMin; | ||
| Vector3 rootMax; | ||
| BoundingBoxInitialize( m_boundingSphere, rootMin, rootMax ); | ||
| BoundingBoxTransform( rootMin, rootMax, m_lastUpdateMatrix ); | ||
| IncludeWorldBounds( rootMin, rootMax, min, max, valid ); | ||
| } | ||
|
|
||
| for( auto it = m_effectChildren.begin(); it != m_effectChildren.end(); ++it ) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [inconsistency] Children ignore |
||
| { | ||
| Vector4 childBounds; | ||
| if( ( *it )->GetBoundingSphere( childBounds, EVE_BOUNDS_WITH_CHILDREN ) ) | ||
| { | ||
| IncludeWorldSphereBounds( childBounds, min, max, valid ); | ||
| } | ||
| } | ||
|
|
||
| return valid; | ||
| } | ||
|
|
||
| bool EveEffectRoot2::IsBoundingBoxReady() const | ||
| { | ||
| if( IsValidBoundingSphere( m_boundingSphere ) ) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| for( auto it = m_effectChildren.begin(); it != m_effectChildren.end(); ++it ) | ||
| { | ||
| Vector4 childBounds; | ||
| if( ( *it )->GetBoundingSphere( childBounds, EVE_BOUNDS_WITH_CHILDREN ) && IsValidBoundingSphere( childBounds ) ) | ||
| { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| void EveEffectRoot2::RegisterWithQuadRenderer( Tr2QuadRenderer& quadRenderer ) | ||
| { | ||
| for( auto it = m_effectChildren.begin(); it != m_effectChildren.end(); ++it ) | ||
|
|
@@ -994,4 +1096,4 @@ void EveEffectRoot2::SetProceduralContainerVariable( const char *name, float val | |
| auto child = *it; | ||
| child->SetProceduralContainerVariable( name, value ); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[file size + dup] This per-file helper toolkit is what pushes
EveEffectRoot2.cppfrom 996 -> 1099 lines (crosses the 1k smell threshold), and it duplicatesEveTransform.cpp's helpers with stricter validity rules. Sharing one accumulator (see theEveTransform.cppIncludeBoundscomment) removes the toolkit and keeps this file under 1k.