Optimize collider cached scale
This commit is contained in:
@@ -162,7 +162,7 @@ void BoxCollider::UpdateBounds()
|
|||||||
|
|
||||||
void BoxCollider::GetGeometry(CollisionShape& collision)
|
void BoxCollider::GetGeometry(CollisionShape& collision)
|
||||||
{
|
{
|
||||||
Float3 size = _size * _cachedScale;
|
Float3 size = _size * _transform.Scale;
|
||||||
const float minSize = 0.001f;
|
const float minSize = 0.001f;
|
||||||
size = Float3::Max(size.GetAbsolute() * 0.5f, Float3(minSize));
|
size = Float3::Max(size.GetAbsolute() * 0.5f, Float3(minSize));
|
||||||
collision.SetBox(size.Raw);
|
collision.SetBox(size.Raw);
|
||||||
|
|||||||
@@ -43,10 +43,9 @@ void CapsuleCollider::DrawPhysicsDebug(RenderView& view)
|
|||||||
return;
|
return;
|
||||||
Quaternion rotation;
|
Quaternion rotation;
|
||||||
Quaternion::Multiply(_transform.Orientation, Quaternion::Euler(0, 90, 0), rotation);
|
Quaternion::Multiply(_transform.Orientation, Quaternion::Euler(0, 90, 0), rotation);
|
||||||
const float scaling = _cachedScale.GetAbsolute().MaxValue();
|
|
||||||
const float minSize = 0.001f;
|
const float minSize = 0.001f;
|
||||||
const float radius = Math::Max(Math::Abs(_radius) * scaling, minSize);
|
const float radius = Math::Max(Math::Abs(_radius) * _cachedScale, minSize);
|
||||||
const float height = Math::Max(Math::Abs(_height) * scaling, minSize);
|
const float height = Math::Max(Math::Abs(_height) * _cachedScale, minSize);
|
||||||
if (view.Mode == ViewMode::PhysicsColliders && !GetIsTrigger())
|
if (view.Mode == ViewMode::PhysicsColliders && !GetIsTrigger())
|
||||||
DEBUG_DRAW_CAPSULE(_transform.LocalToWorld(_center), rotation, radius, height, _staticActor ? Color::CornflowerBlue : Color::Orchid, 0, true);
|
DEBUG_DRAW_CAPSULE(_transform.LocalToWorld(_center), rotation, radius, height, _staticActor ? Color::CornflowerBlue : Color::Orchid, 0, true);
|
||||||
else
|
else
|
||||||
@@ -57,10 +56,9 @@ void CapsuleCollider::OnDebugDrawSelected()
|
|||||||
{
|
{
|
||||||
Quaternion rotation;
|
Quaternion rotation;
|
||||||
Quaternion::Multiply(_transform.Orientation, Quaternion::Euler(0, 90, 0), rotation);
|
Quaternion::Multiply(_transform.Orientation, Quaternion::Euler(0, 90, 0), rotation);
|
||||||
const float scaling = _cachedScale.GetAbsolute().MaxValue();
|
|
||||||
const float minSize = 0.001f;
|
const float minSize = 0.001f;
|
||||||
const float radius = Math::Max(Math::Abs(_radius) * scaling, minSize);
|
const float radius = Math::Max(Math::Abs(_radius) * _cachedScale, minSize);
|
||||||
const float height = Math::Max(Math::Abs(_height) * scaling, minSize);
|
const float height = Math::Max(Math::Abs(_height) * _cachedScale, minSize);
|
||||||
const Vector3 position = _transform.LocalToWorld(_center);
|
const Vector3 position = _transform.LocalToWorld(_center);
|
||||||
DEBUG_DRAW_WIRE_CAPSULE(position, rotation, radius, height, Color::GreenYellow, 0, false);
|
DEBUG_DRAW_WIRE_CAPSULE(position, rotation, radius, height, Color::GreenYellow, 0, false);
|
||||||
|
|
||||||
@@ -92,9 +90,8 @@ void CapsuleCollider::UpdateBounds()
|
|||||||
|
|
||||||
void CapsuleCollider::GetGeometry(CollisionShape& collision)
|
void CapsuleCollider::GetGeometry(CollisionShape& collision)
|
||||||
{
|
{
|
||||||
const float scaling = _cachedScale.GetAbsolute().MaxValue();
|
|
||||||
const float minSize = 0.001f;
|
const float minSize = 0.001f;
|
||||||
const float radius = Math::Max(Math::Abs(_radius) * scaling, minSize);
|
const float radius = Math::Max(Math::Abs(_radius) * _cachedScale, minSize);
|
||||||
const float height = Math::Max(Math::Abs(_height) * scaling, minSize);
|
const float height = Math::Max(Math::Abs(_height) * _cachedScale, minSize);
|
||||||
collision.SetCapsule(radius, height * 0.5f);
|
collision.SetCapsule(radius, height * 0.5f);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -215,8 +215,7 @@ void CharacterController::CreateController()
|
|||||||
{
|
{
|
||||||
// Create controller
|
// Create controller
|
||||||
ASSERT(_controller == nullptr && _shape == nullptr);
|
ASSERT(_controller == nullptr && _shape == nullptr);
|
||||||
_cachedScale = GetScale();
|
_cachedScale = GetScale().GetAbsolute().MaxValue();
|
||||||
const float scaling = _cachedScale.GetAbsolute().MaxValue();
|
|
||||||
const Vector3 position = _transform.LocalToWorld(_center);
|
const Vector3 position = _transform.LocalToWorld(_center);
|
||||||
_controller = PhysicsBackend::CreateController(GetPhysicsScene()->GetPhysicsScene(), this, this, _contactOffset, position, _slopeLimit, (int32)_nonWalkableMode, Material, Math::Abs(_radius) * scaling, Math::Abs(_height) * scaling, _stepOffset, _shape);
|
_controller = PhysicsBackend::CreateController(GetPhysicsScene()->GetPhysicsScene(), this, this, _contactOffset, position, _slopeLimit, (int32)_nonWalkableMode, Material, Math::Abs(_radius) * scaling, Math::Abs(_height) * scaling, _stepOffset, _shape);
|
||||||
|
|
||||||
@@ -334,7 +333,7 @@ void CharacterController::UpdateGeometry()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Setup shape geometry
|
// Setup shape geometry
|
||||||
_cachedScale = GetScale();
|
_cachedScale = GetScale().GetAbsolute().MaxValue();
|
||||||
UpdateSize();
|
UpdateSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -398,7 +397,7 @@ void CharacterController::OnTransformChanged()
|
|||||||
if (!_isUpdatingTransform && _controller)
|
if (!_isUpdatingTransform && _controller)
|
||||||
{
|
{
|
||||||
PhysicsBackend::SetControllerPosition(_controller, position);
|
PhysicsBackend::SetControllerPosition(_controller, position);
|
||||||
const Float3 scale = GetScale();
|
const float scale = GetScale().GetAbsolute().MaxValue();
|
||||||
if (_cachedScale != scale)
|
if (_cachedScale != scale)
|
||||||
UpdateGeometry();
|
UpdateGeometry();
|
||||||
UpdateBounds();
|
UpdateBounds();
|
||||||
|
|||||||
@@ -205,7 +205,7 @@ void Collider::CreateShape()
|
|||||||
ASSERT(_shape == nullptr);
|
ASSERT(_shape == nullptr);
|
||||||
|
|
||||||
// Setup shape geometry
|
// Setup shape geometry
|
||||||
_cachedScale = GetScale();
|
_cachedScale = GetScale().GetAbsolute().MaxValue();
|
||||||
CollisionShape shape;
|
CollisionShape shape;
|
||||||
GetGeometry(shape);
|
GetGeometry(shape);
|
||||||
|
|
||||||
@@ -222,7 +222,7 @@ void Collider::UpdateGeometry()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Setup shape geometry
|
// Setup shape geometry
|
||||||
_cachedScale = GetScale();
|
_cachedScale = GetScale().GetAbsolute().MaxValue();
|
||||||
CollisionShape shape;
|
CollisionShape shape;
|
||||||
GetGeometry(shape);
|
GetGeometry(shape);
|
||||||
|
|
||||||
@@ -427,7 +427,7 @@ void Collider::OnTransformChanged()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const Float3 scale = GetScale();
|
const float scale = GetScale().GetAbsolute().MaxValue();
|
||||||
if (_cachedScale != scale)
|
if (_cachedScale != scale)
|
||||||
UpdateGeometry();
|
UpdateGeometry();
|
||||||
UpdateBounds();
|
UpdateBounds();
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ protected:
|
|||||||
bool _isTrigger;
|
bool _isTrigger;
|
||||||
void* _shape;
|
void* _shape;
|
||||||
void* _staticActor;
|
void* _staticActor;
|
||||||
Float3 _cachedScale;
|
float _cachedScale;
|
||||||
float _contactOffset;
|
float _contactOffset;
|
||||||
Vector3 _cachedLocalPosePos;
|
Vector3 _cachedLocalPosePos;
|
||||||
Quaternion _cachedLocalPoseRot;
|
Quaternion _cachedLocalPoseRot;
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ void MeshCollider::UpdateBounds()
|
|||||||
void MeshCollider::GetGeometry(CollisionShape& collision)
|
void MeshCollider::GetGeometry(CollisionShape& collision)
|
||||||
{
|
{
|
||||||
// Prepare scale
|
// Prepare scale
|
||||||
Float3 scale = _cachedScale;
|
Float3 scale = _transform.Scale;
|
||||||
const float minSize = 0.001f;
|
const float minSize = 0.001f;
|
||||||
Float3 scaleAbs = scale.GetAbsolute();
|
Float3 scaleAbs = scale.GetAbsolute();
|
||||||
if (scaleAbs.X < minSize)
|
if (scaleAbs.X < minSize)
|
||||||
|
|||||||
@@ -67,8 +67,7 @@ void SphereCollider::UpdateBounds()
|
|||||||
|
|
||||||
void SphereCollider::GetGeometry(CollisionShape& collision)
|
void SphereCollider::GetGeometry(CollisionShape& collision)
|
||||||
{
|
{
|
||||||
const float scaling = _cachedScale.GetAbsolute().MaxValue();
|
const float radius = Math::Abs(_radius) * _cachedScale;
|
||||||
const float radius = Math::Abs(_radius) * scaling;
|
|
||||||
const float minSize = 0.001f;
|
const float minSize = 0.001f;
|
||||||
collision.SetSphere(Math::Max(radius, minSize));
|
collision.SetSphere(Math::Max(radius, minSize));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -259,8 +259,7 @@ void SplineCollider::GetGeometry(CollisionShape& collision)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Prepare scale
|
// Prepare scale
|
||||||
Float3 scale = _cachedScale;
|
Float3 scale = Float3::Max(_transform.Scale.GetAbsolute(), minSize);
|
||||||
scale = Float3::Max(scale.GetAbsolute(), minSize);
|
|
||||||
|
|
||||||
// TODO: add support for cooking collision for static splines in editor and reusing it in game
|
// TODO: add support for cooking collision for static splines in editor and reusing it in game
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user