Raycasts now returns the body instance it collided with + serialize spot light cones
This commit is contained in:
@@ -538,9 +538,11 @@ namespace Nuake
|
||||
_JoltBodyInterface->MoveKinematic(bodyId, newPosition, newRotation, Engine::GetFixedTimeStep());
|
||||
break;
|
||||
}
|
||||
case JPH::EMotionType::Dynamic:
|
||||
case JPH::EMotionType::Static:
|
||||
{
|
||||
_JoltBodyInterface->SetPositionAndRotation(bodyId, newPosition, newRotation, JPH::EActivation::DontActivate);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -579,16 +581,18 @@ namespace Nuake
|
||||
// Format result
|
||||
for (int i = 0; i < num_hits; ++i)
|
||||
{
|
||||
const float hitFraction = results[i].mFraction;
|
||||
const JPH::Vec3& hitPosition = ray.GetPointOnRay(results[i].mFraction);
|
||||
auto bodyId = static_cast<JPH::BodyID>(results[i].mBodyID);
|
||||
const float hitFraction = collector.mHits[i].mFraction;
|
||||
const JPH::Vec3& hitPosition = ray.GetPointOnRay(collector.mHits[i].mFraction);
|
||||
auto bodyId = static_cast<JPH::BodyID>(collector.mHits[i].mBodyID);
|
||||
auto layer = _JoltBodyInterface->GetObjectLayer(bodyId);
|
||||
int userData = static_cast<int>(_JoltBodyInterface->GetUserData(bodyId));
|
||||
ShapeCastResult result
|
||||
{
|
||||
Vector3(hitPosition.GetX(), hitPosition.GetY(), hitPosition.GetZ()),
|
||||
hitFraction,
|
||||
Vector3(0, 0, 0),
|
||||
layer
|
||||
layer,
|
||||
userData
|
||||
};
|
||||
|
||||
raycastResults.push_back(std::move(result));
|
||||
@@ -637,12 +641,14 @@ namespace Nuake
|
||||
|
||||
auto layer = _JoltBodyInterface->GetObjectLayer(bodyId);
|
||||
|
||||
int userData = static_cast<int>(_JoltBodyInterface->GetUserData(bodyId));
|
||||
ShapeCastResult result
|
||||
{
|
||||
Vector3(hitPosition.GetX(), hitPosition.GetY(), hitPosition.GetZ()),
|
||||
hitFraction,
|
||||
Vector3(surfaceNormal.GetX(), surfaceNormal.GetY(), surfaceNormal.GetZ()),
|
||||
static_cast<float>(layer)
|
||||
static_cast<float>(layer),
|
||||
userData
|
||||
};
|
||||
|
||||
shapecastResults.push_back(std::move(result));
|
||||
|
||||
@@ -20,5 +20,6 @@ namespace Nuake
|
||||
float Fraction;
|
||||
Vector3 ImpactNormal;
|
||||
float Layer;
|
||||
int EntityID;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -171,6 +171,8 @@ namespace Nuake
|
||||
SERIALIZE_VAL(Strength);
|
||||
SERIALIZE_VAL(SyncDirectionWithSky);
|
||||
SERIALIZE_VAL(CastShadows);
|
||||
SERIALIZE_VAL(Cutoff);
|
||||
SERIALIZE_VAL(OuterCutoff);
|
||||
END_SERIALIZE();
|
||||
}
|
||||
|
||||
@@ -196,6 +198,9 @@ namespace Nuake
|
||||
this->Direction = Vector3(x, y, z);
|
||||
}
|
||||
|
||||
DESERIALIZE_VAL(Cutoff);
|
||||
DESERIALIZE_VAL(OuterCutoff);
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -73,6 +73,7 @@ namespace Nuake {
|
||||
results.push_back(hit.ImpactNormal.z);
|
||||
results.push_back(hit.Fraction);
|
||||
results.push_back(hit.Layer);
|
||||
results.push_back(hit.EntityID);
|
||||
|
||||
}
|
||||
return Coral::Array<float>::New(results);
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include <Coral/Array.hpp>
|
||||
#include <src/Scene/Components/NavMeshVolumeComponent.h>
|
||||
#include <src/Scene/Components/RigidbodyComponent.h>
|
||||
|
||||
|
||||
namespace Nuake {
|
||||
@@ -316,7 +317,7 @@ namespace Nuake {
|
||||
PhysicsManager::Get().SetCharacterControllerPosition(entity, { x, y, z });
|
||||
}
|
||||
|
||||
if (entity.HasComponent<BSPBrushComponent>())
|
||||
if (entity.HasComponent<BSPBrushComponent>() || entity.HasComponent<RigidBodyComponent>())
|
||||
{
|
||||
PhysicsManager::Get().SetBodyTransform(entity, { x, y, z }, component.GetGlobalRotation());
|
||||
}
|
||||
@@ -343,7 +344,7 @@ namespace Nuake {
|
||||
if (entity.IsValid() && entity.HasComponent<TransformComponent>())
|
||||
{
|
||||
auto& component = entity.GetComponent<TransformComponent>();
|
||||
const auto& globalPosition = component.GetGlobalPosition();
|
||||
const Vector3& globalPosition = component.GlobalTransform[3];
|
||||
Coral::Array<float> result = Coral::Array<float>::New({ globalPosition.x, globalPosition.y, globalPosition.z });
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user