Files
FlaxEngine/Source/Engine/Physics/Actors/PhysicsActor.cpp
Wojtek Figat 37e11a4b1f Merge remote-tracking branch 'origin/master'
# Conflicts:
#	Source/Engine/Physics/Physics.Queries.cpp
#	Source/Engine/Physics/Utilities.h
2022-01-20 23:29:59 +01:00

55 lines
1.3 KiB
C++

// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
#include "PhysicsActor.h"
#include "../PhysicsBackend.h"
PhysicsActor::PhysicsActor(const SpawnParams& params)
: Actor(params)
, _cachedScale(1.0f)
, _isUpdatingTransform(false)
{
}
void PhysicsActor::OnActiveTransformChanged()
{
// Change actor transform (but with locking)
ASSERT(!_isUpdatingTransform);
_isUpdatingTransform = true;
Transform transform;
PhysicsBackend::GetRigidActorPose(GetPhysicsActor(), transform.Translation, transform.Orientation);
transform.Scale = _transform.Scale;
if (_parent)
{
_parent->GetTransform().WorldToLocal(transform, _localTransform);
}
else
{
_localTransform = transform;
}
OnTransformChanged();
_isUpdatingTransform = false;
}
void PhysicsActor::OnTransformChanged()
{
// Base
Actor::OnTransformChanged();
UpdateBounds();
}
void PhysicsActor::UpdateBounds()
{
void* actor = GetPhysicsActor();
if (actor)
PhysicsBackend::GetActorBounds(actor, _box);
else
_box = BoundingBox(_transform.Translation);
BoundingSphere::FromBox(_box, _sphere);
}
bool PhysicsActor::IntersectsItself(const Ray& ray, float& distance, Vector3& normal)
{
return _box.Intersects(ray, distance, normal);
}