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;
|
||||
}
|
||||
|
||||
@@ -95,6 +95,7 @@ namespace Nuake.Net
|
||||
public Vector3 ImpactNormal;
|
||||
public float Fraction;
|
||||
public Layers Layer;
|
||||
public Entity Collider;
|
||||
}
|
||||
public struct BoxInternal
|
||||
{
|
||||
@@ -131,15 +132,29 @@ namespace Nuake.Net
|
||||
unsafe
|
||||
{
|
||||
NativeArray<float> resultICall = RayCastIcall(from.X, from.Y, from.Z, to.X, to.Y, to.Z);
|
||||
for (int i = 0; i < resultICall.Length / 7; i++)
|
||||
for (int i = 0; i < resultICall.Length / 9; i++)
|
||||
{
|
||||
int index = i * 7;
|
||||
int index = i * 9;
|
||||
int entityId = (int)resultICall[index + 8];
|
||||
|
||||
bool hasInstance = Entity.EntityHasManagedInstanceIcall(entityId);
|
||||
Entity entityInstance;
|
||||
if (hasInstance)
|
||||
{
|
||||
entityInstance = Scene.GetEntity<Entity>(entityId);
|
||||
}
|
||||
else
|
||||
{
|
||||
entityInstance = new Entity(entityId);
|
||||
}
|
||||
|
||||
ShapeCastResult shapeCastResult = new()
|
||||
{
|
||||
ImpactPosition = new Vector3(resultICall[index + 0], resultICall[index + 1], resultICall[index + 2]),
|
||||
ImpactNormal = new Vector3(resultICall[index + 3], resultICall[index + 4], resultICall[index + 5]),
|
||||
Fraction = resultICall[index + 6],
|
||||
Layer = (Layers)resultICall[index + 7]
|
||||
Layer = (Layers)resultICall[index + 7],
|
||||
Collider = entityInstance
|
||||
};
|
||||
|
||||
result.Add(shapeCastResult);
|
||||
@@ -164,15 +179,15 @@ namespace Nuake.Net
|
||||
{
|
||||
NativeArray<float> resultICall = ShapeCastBoxIcall(from.X, from.Y, from.Z, to.X, to.Y, to.Z, boxInternal);
|
||||
|
||||
for (int i = 0; i < resultICall.Length / 7; i++)
|
||||
for (int i = 0; i < resultICall.Length / 8; i++)
|
||||
{
|
||||
int index = i * 7;
|
||||
int index = i * 8;
|
||||
ShapeCastResult shapeCastResult = new()
|
||||
{
|
||||
ImpactPosition = new Vector3(resultICall[index + 0], resultICall[index + 1], resultICall[index + 2]),
|
||||
ImpactNormal = new Vector3(resultICall[index + 3], resultICall[index + 4], resultICall[index + 5]),
|
||||
Fraction = resultICall[index + 6],
|
||||
Layer = (Layers)resultICall[index + 7]
|
||||
Layer = (Layers)resultICall[index + 7],
|
||||
};
|
||||
|
||||
result.Add(shapeCastResult);
|
||||
|
||||
Reference in New Issue
Block a user