mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-04 11:35:06 +03:00
Added transform to rigidbody
This commit is contained in:
@@ -312,14 +312,18 @@ namespace Nuake
|
||||
|
||||
JPH::TriangleList triangles;
|
||||
triangles.reserve(indices.size());
|
||||
|
||||
Matrix4 transform = rb->_transform;
|
||||
transform[3] = Vector4(0, 0, 0, 1.0f);
|
||||
for (int i = 0; i < indices.size() - 3; i += 3)
|
||||
{
|
||||
const Vector3& p1 = vertices[indices[i]].position;
|
||||
const Vector3& p2 = vertices[indices[i + 1]].position;
|
||||
const Vector3& p3 = vertices[indices[i + 2]].position;
|
||||
|
||||
triangles.push_back(JPH::Triangle(JPH::Float3(p1.x, p1.y, p1.z), JPH::Float3(p2.x, p2.y, p2.z), JPH::Float3(p3.x, p3.y, p3.z)));
|
||||
const Vector4& tp1 = transform * Vector4(p1, 1.0f);
|
||||
const Vector4& tp2 = transform * Vector4(p2, 1.0f);
|
||||
const Vector4& tp3 = transform * Vector4(p3, 1.0f);
|
||||
triangles.push_back(JPH::Triangle(JPH::Float3(tp1.x, tp1.y, tp1.z), JPH::Float3(tp2.x, tp2.y, tp2.z), JPH::Float3(tp3.x, tp3.y, tp3.z)));
|
||||
}
|
||||
|
||||
JPH::MeshShapeSettings shapeSettings(std::move(triangles));
|
||||
|
||||
@@ -16,10 +16,11 @@ namespace Nuake
|
||||
Entity _entity;
|
||||
public:
|
||||
float _mass;
|
||||
Matrix4 _transform;
|
||||
|
||||
RigidBody();
|
||||
RigidBody(glm::vec3 position, Entity handle);
|
||||
RigidBody(float mass, glm::vec3 position, Ref<PhysicShape> shape, Entity entity, glm::vec3 initialVel = glm::vec3(0, 0, 0));
|
||||
RigidBody(float mass, glm::vec3 position, Matrix4 _transform, Ref<PhysicShape> shape, Entity entity, glm::vec3 initialVel = glm::vec3(0, 0, 0));
|
||||
|
||||
void UpdateTransform();
|
||||
|
||||
|
||||
@@ -18,11 +18,12 @@ namespace Nuake
|
||||
|
||||
}
|
||||
|
||||
RigidBody::RigidBody(float mass, glm::vec3 position, Ref<PhysicShape> shape, Entity entity, glm::vec3 initialVel) :
|
||||
RigidBody::RigidBody(float mass, glm::vec3 position, Matrix4 transform, Ref<PhysicShape> shape, Entity entity, glm::vec3 initialVel) :
|
||||
_position(position),
|
||||
_collisionShape(shape),
|
||||
_mass(mass),
|
||||
_entity(entity)
|
||||
_entity(entity),
|
||||
_transform(transform)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -25,28 +25,28 @@ namespace Nuake
|
||||
auto view = m_Scene->m_Registry.view<TransformComponent, RigidBodyComponent>();
|
||||
for (auto e : view)
|
||||
{
|
||||
auto [transform, rigidbody] = view.get<TransformComponent, RigidBodyComponent>(e);
|
||||
auto [transform, rigidBodyComponent] = view.get<TransformComponent, RigidBodyComponent>(e);
|
||||
Entity ent = Entity({ e, m_Scene });
|
||||
Ref<Physics::RigidBody> rigidBody;
|
||||
if (ent.HasComponent<BoxColliderComponent>())
|
||||
{
|
||||
float mass = rigidbody.Mass;
|
||||
float mass = rigidBodyComponent.Mass;
|
||||
|
||||
BoxColliderComponent& boxComponent = ent.GetComponent<BoxColliderComponent>();
|
||||
Ref<Physics::Box> boxShape = CreateRef<Physics::Box>(boxComponent.Size);
|
||||
|
||||
rigidBody = CreateRef<Physics::RigidBody>(mass, transform.GetGlobalPosition(), boxShape, ent);
|
||||
rigidBody = CreateRef<Physics::RigidBody>(rigidBodyComponent.Mass, transform.GetGlobalPosition(), transform.GetGlobalTransform(), boxShape, ent);
|
||||
PhysicsManager::Get()->RegisterBody(rigidBody);
|
||||
}
|
||||
|
||||
if (ent.HasComponent<SphereColliderComponent>())
|
||||
{
|
||||
float mass = rigidbody.Mass;
|
||||
float mass = rigidBodyComponent.Mass;
|
||||
|
||||
const auto& component = ent.GetComponent<SphereColliderComponent>();
|
||||
auto shape = CreateRef<Physics::Sphere>(component.Radius);
|
||||
|
||||
rigidBody = CreateRef<Physics::RigidBody>(mass, transform.GetGlobalPosition(), shape, ent);
|
||||
rigidBody = CreateRef<Physics::RigidBody>(rigidBodyComponent.Mass, transform.GetGlobalPosition(), transform.GetGlobalTransform(), shape, ent);
|
||||
PhysicsManager::Get()->RegisterBody(rigidBody);
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace Nuake
|
||||
}
|
||||
Ref<Mesh> mesh = submeshes[subMeshId];
|
||||
auto shape = CreateRef<Physics::MeshShape>(mesh);
|
||||
rigidBody = CreateRef<Physics::RigidBody>(1.0f, transform.GetGlobalPosition(), shape, ent);
|
||||
rigidBody = CreateRef<Physics::RigidBody>(rigidBodyComponent.Mass, transform.GetGlobalPosition(), transform.GetGlobalTransform(), shape, ent);
|
||||
PhysicsManager::Get()->RegisterBody(rigidBody);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user