Refactor engine to support double-precision vectors
This commit is contained in:
@@ -10,11 +10,10 @@ BoxCollider::BoxCollider(const SpawnParams& params)
|
||||
{
|
||||
}
|
||||
|
||||
void BoxCollider::SetSize(const Vector3& value)
|
||||
void BoxCollider::SetSize(const Float3& value)
|
||||
{
|
||||
if (Vector3::NearEqual(value, _size))
|
||||
if (Float3::NearEqual(value, _size))
|
||||
return;
|
||||
|
||||
_size = value;
|
||||
|
||||
UpdateGeometry();
|
||||
@@ -54,12 +53,12 @@ namespace
|
||||
{
|
||||
OrientedBoundingBox box;
|
||||
const Vector3 vec = max - min;
|
||||
const Vector3 dir = Vector3::Normalize(vec);
|
||||
const Vector3 dir = Float3::Normalize(vec);
|
||||
Quaternion orientation;
|
||||
if (Vector3::Dot(dir, Vector3::Up) >= 0.999f)
|
||||
Quaternion::RotationAxis(Vector3::Left, PI_HALF, orientation);
|
||||
if (Vector3::Dot(dir, Float3::Up) >= 0.999f)
|
||||
Quaternion::RotationAxis(Float3::Left, PI_HALF, orientation);
|
||||
else
|
||||
Quaternion::LookRotation(dir, Vector3::Cross(Vector3::Cross(dir, Vector3::Up), dir), orientation);
|
||||
Quaternion::LookRotation(dir, Float3::Cross(Float3::Cross(dir, Float3::Up), dir), orientation);
|
||||
const Vector3 up = orientation * Vector3::Up;
|
||||
Matrix::CreateWorld(min + vec * 0.5f, dir, up, box.Transformation);
|
||||
Matrix inv;
|
||||
@@ -101,7 +100,7 @@ void BoxCollider::OnDebugDrawSelected()
|
||||
|
||||
#endif
|
||||
|
||||
bool BoxCollider::IntersectsItself(const Ray& ray, float& distance, Vector3& normal)
|
||||
bool BoxCollider::IntersectsItself(const Ray& ray, Real& distance, Vector3& normal)
|
||||
{
|
||||
return _bounds.Intersects(ray, distance, normal);
|
||||
}
|
||||
@@ -135,8 +134,8 @@ void BoxCollider::UpdateBounds()
|
||||
|
||||
void BoxCollider::GetGeometry(CollisionShape& collision)
|
||||
{
|
||||
Vector3 size = _size * _cachedScale;
|
||||
Float3 size = _size * _cachedScale;
|
||||
const float minSize = 0.001f;
|
||||
size = Vector3::Max(size.GetAbsolute() * 0.5f, Vector3(minSize));
|
||||
size = Float3::Max(size.GetAbsolute() * 0.5f, Float3(minSize));
|
||||
collision.SetBox(size.Raw);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ API_CLASS() class FLAXENGINE_API BoxCollider : public Collider
|
||||
DECLARE_SCENE_OBJECT(BoxCollider);
|
||||
private:
|
||||
|
||||
Vector3 _size;
|
||||
Float3 _size;
|
||||
OrientedBoundingBox _bounds;
|
||||
|
||||
public:
|
||||
@@ -26,7 +26,7 @@ public:
|
||||
/// The box size will be scaled by the actor's world scale.
|
||||
/// </remarks>
|
||||
API_PROPERTY(Attributes="EditorOrder(100), DefaultValue(typeof(Vector3), \"100,100,100\"), EditorDisplay(\"Collider\")")
|
||||
FORCE_INLINE Vector3 GetSize() const
|
||||
FORCE_INLINE Float3 GetSize() const
|
||||
{
|
||||
return _size;
|
||||
}
|
||||
@@ -37,7 +37,7 @@ public:
|
||||
/// <remarks>
|
||||
/// The box size will be scaled by the actor's world scale.
|
||||
/// </remarks>
|
||||
API_PROPERTY() void SetSize(const Vector3& value);
|
||||
API_PROPERTY() void SetSize(const Float3& value);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the volume bounding box (oriented).
|
||||
@@ -54,7 +54,7 @@ public:
|
||||
void OnDebugDraw() override;
|
||||
void OnDebugDrawSelected() override;
|
||||
#endif
|
||||
bool IntersectsItself(const Ray& ray, float& distance, Vector3& normal) override;
|
||||
bool IntersectsItself(const Ray& ray, Real& distance, Vector3& normal) override;
|
||||
void Serialize(SerializeStream& stream, const void* otherObj) override;
|
||||
void Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) override;
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ void CapsuleCollider::OnDebugDrawSelected()
|
||||
|
||||
#endif
|
||||
|
||||
bool CapsuleCollider::IntersectsItself(const Ray& ray, float& distance, Vector3& normal)
|
||||
bool CapsuleCollider::IntersectsItself(const Ray& ray, Real& distance, Vector3& normal)
|
||||
{
|
||||
return _orientedBox.Intersects(ray, distance, normal);
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public:
|
||||
#if USE_EDITOR
|
||||
void OnDebugDrawSelected() override;
|
||||
#endif
|
||||
bool IntersectsItself(const Ray& ray, float& distance, Vector3& normal) override;
|
||||
bool IntersectsItself(const Ray& ray, Real& distance, Vector3& normal) override;
|
||||
void Serialize(SerializeStream& stream, const void* otherObj) override;
|
||||
void Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) override;
|
||||
|
||||
|
||||
@@ -360,8 +360,8 @@ void CharacterController::OnTransformChanged()
|
||||
if (!_isUpdatingTransform && _controller)
|
||||
{
|
||||
PhysicsBackend::SetControllerPosition(_controller, _transform.Translation);
|
||||
const Vector3 scale = GetScale();
|
||||
if (!Vector3::NearEqual(_cachedScale, scale))
|
||||
const Float3 scale = GetScale();
|
||||
if (!Float3::NearEqual(_cachedScale, scale))
|
||||
UpdateGeometry();
|
||||
UpdateBounds();
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
Collider::Collider(const SpawnParams& params)
|
||||
: PhysicsColliderActor(params)
|
||||
, _center(Vector3::Zero)
|
||||
, _center(Float3::Zero)
|
||||
, _isTrigger(false)
|
||||
, _shape(nullptr)
|
||||
, _staticActor(nullptr)
|
||||
@@ -442,8 +442,8 @@ void Collider::OnTransformChanged()
|
||||
}
|
||||
}
|
||||
|
||||
const Vector3 scale = GetScale();
|
||||
if (!Vector3::NearEqual(_cachedScale, scale))
|
||||
const Float3 scale = GetScale();
|
||||
if (!Float3::NearEqual(_cachedScale, scale))
|
||||
UpdateGeometry();
|
||||
UpdateBounds();
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ protected:
|
||||
bool _isTrigger;
|
||||
void* _shape;
|
||||
void* _staticActor;
|
||||
Vector3 _cachedScale;
|
||||
Float3 _cachedScale;
|
||||
float _contactOffset;
|
||||
Vector3 _cachedLocalPosePos;
|
||||
Quaternion _cachedLocalPoseRot;
|
||||
|
||||
@@ -73,7 +73,7 @@ void MeshCollider::DrawPhysicsDebug(RenderView& view)
|
||||
return;
|
||||
if (view.Mode == ViewMode::PhysicsColliders && !GetIsTrigger())
|
||||
{
|
||||
Array<Vector3>* vertexBuffer;
|
||||
Array<Float3>* vertexBuffer;
|
||||
Array<int32>* indexBuffer;
|
||||
CollisionData->GetDebugTriangles(vertexBuffer, indexBuffer);
|
||||
DebugDraw::DrawTriangles(*vertexBuffer, *indexBuffer, _transform.GetWorld(), _staticActor ? Color::CornflowerBlue : Color::Orchid, 0, true);
|
||||
@@ -90,7 +90,7 @@ void MeshCollider::OnDebugDrawSelected()
|
||||
if (CollisionData && CollisionData->IsLoaded())
|
||||
{
|
||||
const auto& debugLines = CollisionData->GetDebugLines();
|
||||
DEBUG_DRAW_LINES(Span<Vector3>(debugLines.Get(), debugLines.Count()), _transform.GetWorld(), Color::GreenYellow, 0, false);
|
||||
DEBUG_DRAW_LINES(Span<Float3>(debugLines.Get(), debugLines.Count()), _transform.GetWorld(), Color::GreenYellow, 0, false);
|
||||
}
|
||||
|
||||
// Base
|
||||
@@ -99,7 +99,7 @@ void MeshCollider::OnDebugDrawSelected()
|
||||
|
||||
#endif
|
||||
|
||||
bool MeshCollider::IntersectsItself(const Ray& ray, float& distance, Vector3& normal)
|
||||
bool MeshCollider::IntersectsItself(const Ray& ray, Real& distance, Vector3& normal)
|
||||
{
|
||||
// Use detailed hit
|
||||
if (_shape)
|
||||
@@ -149,9 +149,9 @@ void MeshCollider::UpdateBounds()
|
||||
void MeshCollider::GetGeometry(CollisionShape& collision)
|
||||
{
|
||||
// Prepare scale
|
||||
Vector3 scale = _cachedScale;
|
||||
Float3 scale = _cachedScale;
|
||||
const float minSize = 0.001f;
|
||||
scale = Vector3::Max(scale.GetNegative(), minSize);
|
||||
scale = Float3::Max(scale.GetAbsolute(), minSize);
|
||||
|
||||
// Setup shape (based on type)
|
||||
CollisionDataType type = CollisionDataType::None;
|
||||
|
||||
@@ -34,7 +34,7 @@ public:
|
||||
#if USE_EDITOR
|
||||
void OnDebugDrawSelected() override;
|
||||
#endif
|
||||
bool IntersectsItself(const Ray& ray, float& distance, Vector3& normal) override;
|
||||
bool IntersectsItself(const Ray& ray, Real& distance, Vector3& normal) override;
|
||||
void Serialize(SerializeStream& stream, const void* otherObj) override;
|
||||
void Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) override;
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ void SphereCollider::OnDebugDrawSelected()
|
||||
|
||||
#endif
|
||||
|
||||
bool SphereCollider::IntersectsItself(const Ray& ray, float& distance, Vector3& normal)
|
||||
bool SphereCollider::IntersectsItself(const Ray& ray, Real& distance, Vector3& normal)
|
||||
{
|
||||
return _sphere.Intersects(ray, distance, normal);
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
#if USE_EDITOR
|
||||
void OnDebugDrawSelected() override;
|
||||
#endif
|
||||
bool IntersectsItself(const Ray& ray, float& distance, Vector3& normal) override;
|
||||
bool IntersectsItself(const Ray& ray, Real& distance, Vector3& normal) override;
|
||||
void Serialize(SerializeStream& stream, const void* otherObj) override;
|
||||
void Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) override;
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ void SplineCollider::SetPreTransform(const Transform& value)
|
||||
UpdateGeometry();
|
||||
}
|
||||
|
||||
void SplineCollider::ExtractGeometry(Array<Vector3>& vertexBuffer, Array<int32>& indexBuffer) const
|
||||
void SplineCollider::ExtractGeometry(Array<Float3>& vertexBuffer, Array<int32>& indexBuffer) const
|
||||
{
|
||||
vertexBuffer.Add(_vertexBuffer);
|
||||
indexBuffer.Add(_indexBuffer);
|
||||
@@ -106,7 +106,7 @@ void SplineCollider::OnDebugDrawSelected()
|
||||
|
||||
#endif
|
||||
|
||||
bool SplineCollider::IntersectsItself(const Ray& ray, float& distance, Vector3& normal)
|
||||
bool SplineCollider::IntersectsItself(const Ray& ray, Real& distance, Vector3& normal)
|
||||
{
|
||||
// Use detailed hit
|
||||
if (_shape)
|
||||
@@ -195,7 +195,7 @@ void SplineCollider::GetGeometry(CollisionShape& collision)
|
||||
|
||||
// Extract collision geometry
|
||||
// TODO: cache memory allocation for dynamic colliders
|
||||
Array<Vector3> collisionVertices;
|
||||
Array<Float3> collisionVertices;
|
||||
Array<int32> collisionIndices;
|
||||
CollisionData->ExtractGeometry(collisionVertices, collisionIndices);
|
||||
if (collisionIndices.IsEmpty())
|
||||
@@ -244,15 +244,15 @@ void SplineCollider::GetGeometry(CollisionShape& collision)
|
||||
for (int32 i = 0; i < collisionVertices.Count(); i++)
|
||||
{
|
||||
Vector3 v = srcVertices[i];
|
||||
const float alpha = Math::Saturate((v.Z - localModelBounds.Minimum.Z) / localModelBoundsSize.Z);
|
||||
const Real alpha = Math::Saturate((v.Z - localModelBounds.Minimum.Z) / localModelBoundsSize.Z);
|
||||
v.Z = alpha;
|
||||
|
||||
// Evaluate transformation at the curve
|
||||
AnimationUtils::Bezier(start.Value, leftTangent, rightTangent, end.Value, alpha, curveTransform);
|
||||
AnimationUtils::Bezier(start.Value, leftTangent, rightTangent, end.Value, (float)alpha, curveTransform);
|
||||
|
||||
// Apply spline direction (from position 1st derivative)
|
||||
Vector3 direction;
|
||||
AnimationUtils::BezierFirstDerivative(start.Value.Translation, leftTangent.Translation, rightTangent.Translation, end.Value.Translation, alpha, direction);
|
||||
AnimationUtils::BezierFirstDerivative(start.Value.Translation, leftTangent.Translation, rightTangent.Translation, end.Value.Translation, (float)alpha, direction);
|
||||
direction.Normalize();
|
||||
Quaternion orientation;
|
||||
if (direction.IsZero())
|
||||
@@ -279,8 +279,8 @@ void SplineCollider::GetGeometry(CollisionShape& collision)
|
||||
}
|
||||
|
||||
// Prepare scale
|
||||
Vector3 scale = _cachedScale;
|
||||
scale = Vector3::Max(scale.GetAbsolute(), minSize);
|
||||
Float3 scale = _cachedScale;
|
||||
scale = Float3::Max(scale.GetAbsolute(), minSize);
|
||||
|
||||
// TODO: add support for cooking collision for static splines in editor and reusing it in game
|
||||
|
||||
@@ -311,6 +311,7 @@ void SplineCollider::GetGeometry(CollisionShape& collision)
|
||||
}
|
||||
|
||||
// Transform vertices back to world space for debug shapes drawing and navmesh building
|
||||
// TODO: large-worlds (keep data in local-space and transform on-the-fly)
|
||||
for (int32 i = 0; i < _vertexBuffer.Count(); i++)
|
||||
_vertexBuffer[i] = colliderTransform.LocalToWorld(_vertexBuffer[i]);
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ DECLARE_SCENE_OBJECT(SplineCollider);
|
||||
private:
|
||||
Spline* _spline = nullptr;
|
||||
void* _triangleMesh = nullptr;
|
||||
Array<Vector3> _vertexBuffer;
|
||||
Array<Float3> _vertexBuffer;
|
||||
Array<int32> _indexBuffer;
|
||||
Transform _preTransform = Transform::Identity;
|
||||
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
/// </summary>
|
||||
/// <param name="vertexBuffer">The output vertex buffer.</param>
|
||||
/// <param name="indexBuffer">The output index buffer.</param>
|
||||
void ExtractGeometry(Array<Vector3>& vertexBuffer, Array<int32>& indexBuffer) const;
|
||||
void ExtractGeometry(Array<Float3>& vertexBuffer, Array<int32>& indexBuffer) const;
|
||||
|
||||
private:
|
||||
|
||||
@@ -63,7 +63,7 @@ public:
|
||||
#if USE_EDITOR
|
||||
void OnDebugDrawSelected() override;
|
||||
#endif
|
||||
bool IntersectsItself(const Ray& ray, float& distance, Vector3& normal) override;
|
||||
bool IntersectsItself(const Ray& ray, Real& distance, Vector3& normal) override;
|
||||
void Serialize(SerializeStream& stream, const void* otherObj) override;
|
||||
void Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) override;
|
||||
void OnParentChanged() override;
|
||||
|
||||
Reference in New Issue
Block a user