feat: rigidbody is now constructed using a PhysicsEntity rather than a Transformable
This commit is contained in:
parent
ece2a24a78
commit
163fac8f02
|
@ -6,7 +6,7 @@
|
|||
#include "transformable.h"
|
||||
|
||||
struct RigidBody {
|
||||
Transformable transformable;
|
||||
PhysicsEntity owner;
|
||||
|
||||
float mass;
|
||||
float bounce;
|
||||
|
@ -26,11 +26,11 @@ struct RigidBody {
|
|||
List contacts;
|
||||
};
|
||||
|
||||
RigidBody* rigidbody_make(Transformable transform) {
|
||||
RigidBody* rigidbody_make(PhysicsEntity owner) {
|
||||
RigidBody* self = malloc(sizeof(RigidBody));
|
||||
ASSERT_RETURN(self != NULL, NULL, "Failed to allocate space for rigidbody");
|
||||
*self = (RigidBody){
|
||||
.transformable = transform,
|
||||
.owner = owner,
|
||||
.mass = 1.0f,
|
||||
.bounce = 0.0f,
|
||||
|
||||
|
@ -38,7 +38,7 @@ RigidBody* rigidbody_make(Transformable transform) {
|
|||
.next_linear_force = ZeroVector,
|
||||
.last_linear_force = ZeroVector,
|
||||
|
||||
.internal_transform = *transform.tc->get_transform(transform.data),
|
||||
.internal_transform = *owner.transformable->get_transform(owner.data),
|
||||
|
||||
.layers = 0x1,
|
||||
.collision_mask = 0x1,
|
||||
|
@ -110,7 +110,8 @@ void rigidbody_integrate_forces(RigidBody* self) {
|
|||
|
||||
self->linear_velocity = velocity;
|
||||
self->internal_transform.position = position;
|
||||
transformable_set_position(self->transformable, position);
|
||||
Transform* owner_trans = self->owner.transformable->get_transform(self->owner.data);
|
||||
owner_trans->position = position;
|
||||
|
||||
self->last_linear_force = self->next_linear_force;
|
||||
self->next_linear_force = ZeroVector;
|
||||
|
|
|
@ -18,7 +18,7 @@ typedef struct PhysicsEntity PhysicsEntity;
|
|||
typedef void (*CollisionHandlerFn)(void* obj, List* collisions);
|
||||
|
||||
// Referenced transform is stored but not owned by the rigidbody.
|
||||
extern RigidBody* rigidbody_make(Transformable transform);
|
||||
extern RigidBody* rigidbody_make(PhysicsEntity owner);
|
||||
extern void rigidbody_destroy(RigidBody* self);
|
||||
|
||||
extern void rigidbody_add_contact(RigidBody* self, struct Collision hit);
|
||||
|
|
Loading…
Reference in a new issue