work on physics begun
This commit is contained in:
62
public/iphysics.h
Normal file
62
public/iphysics.h
Normal file
@@ -0,0 +1,62 @@
|
||||
#ifndef PHYSICS_H
|
||||
#define PHYSICS_H
|
||||
|
||||
#include "tier0/platform.h"
|
||||
#include "trig.h"
|
||||
|
||||
struct BallShape_t
|
||||
{
|
||||
float m_fRadius;
|
||||
};
|
||||
|
||||
struct CuboidShape_t
|
||||
{
|
||||
float m_fExtentX;
|
||||
float m_fExtentY;
|
||||
float m_fExtentZ;
|
||||
};
|
||||
|
||||
typedef void *HShape;
|
||||
typedef void *HCollider;
|
||||
|
||||
enum EPhysicsBodyType
|
||||
{
|
||||
k_EPhysics_Static,
|
||||
k_EPhysics_Dynamic,
|
||||
k_EPhysics_KinematicPositionBased,
|
||||
k_EPhysics_KinematicRotationBased,
|
||||
};
|
||||
|
||||
abstract_class IPhysicsBody
|
||||
{
|
||||
public:
|
||||
virtual void SetPosition( Vector vPosition ) = 0;
|
||||
virtual void SetRotation( Quat vRotation ) = 0;
|
||||
virtual void SetGravityScale( float fScale ) = 0;
|
||||
};
|
||||
|
||||
abstract_class IPhysicsWorld
|
||||
{
|
||||
public:
|
||||
virtual void SetGravity( float fGravity ) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
abstract_class IPhysics
|
||||
{
|
||||
public:
|
||||
virtual HShape CreateBall( BallShape_t ball ) = 0;
|
||||
virtual HShape CreateCube( CuboidShape_t ball ) = 0;
|
||||
virtual void DestroyShape( HShape hShape ) = 0;
|
||||
|
||||
virtual HCollider CreateCollider( HShape hShape ) = 0;
|
||||
|
||||
virtual IPhysicsWorld *CreateWorld() = 0;
|
||||
virtual void DestroyWorld( IPhysicsWorld *pWorld ) = 0;
|
||||
|
||||
virtual IPhysicsBody *CreateRigidBody( HCollider hCollider, EPhysicsBodyType eType) = 0;
|
||||
virtual void DestroyPhysicsBody( IPhysicsBody *pBody ) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -3,98 +3,17 @@
|
||||
|
||||
|
||||
|
||||
typedef struct funnyphysics funnyphysics;
|
||||
typedef struct RapierShape_t RapierShape_t;
|
||||
|
||||
typedef struct px_collider_params {
|
||||
float friction;
|
||||
} px_collider_params;
|
||||
|
||||
typedef struct px_vec3 {
|
||||
float m[3];
|
||||
} px_vec3;
|
||||
|
||||
typedef struct px_cast_result {
|
||||
int8_t hit;
|
||||
float time;
|
||||
struct px_vec3 witness1;
|
||||
struct px_vec3 witness2;
|
||||
struct px_vec3 normal1;
|
||||
struct px_vec3 normal2;
|
||||
} px_cast_result;
|
||||
|
||||
typedef struct px_matrix {
|
||||
float m[16];
|
||||
} px_matrix;
|
||||
|
||||
typedef struct px_rigidbody_params {
|
||||
float velocity[3];
|
||||
float angular_velocity[3];
|
||||
float gravity_scale;
|
||||
float linear_damping;
|
||||
float angular_damping;
|
||||
uint8_t continous;
|
||||
uint8_t sleeping;
|
||||
uint8_t lockrotx;
|
||||
uint8_t lockroty;
|
||||
uint8_t lockrotz;
|
||||
uint8_t lockposx;
|
||||
uint8_t lockposy;
|
||||
uint8_t lockposz;
|
||||
int8_t dominance;
|
||||
} px_rigidbody_params;
|
||||
typedef struct BallShape_t {
|
||||
float m_fRadius;
|
||||
} BallShape_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
Collider *px_ball(float radius, struct px_collider_params params);
|
||||
|
||||
Collider *px_box(float x, float y, float z, struct px_collider_params params);
|
||||
|
||||
struct px_cast_result px_box_cast(struct funnyphysics *px_world,
|
||||
float x,
|
||||
float y,
|
||||
float z,
|
||||
struct px_vec3 pos,
|
||||
struct px_vec3 rot,
|
||||
struct px_vec3 vel,
|
||||
float time);
|
||||
|
||||
void px_fixedbody(struct funnyphysics *px_world, Collider *collider);
|
||||
|
||||
void px_frame(struct funnyphysics *px_world, float delta);
|
||||
|
||||
struct px_matrix px_getmatrix(struct funnyphysics *px_world, RigidBodyHandle *body);
|
||||
|
||||
struct px_vec3 px_getposition(struct funnyphysics *px_world, RigidBodyHandle *body);
|
||||
|
||||
struct px_vec3 px_getvelocity(struct funnyphysics *px_world, RigidBodyHandle *body);
|
||||
|
||||
struct funnyphysics *px_init(void);
|
||||
|
||||
RigidBodyHandle *px_kinematic_position_body(struct funnyphysics *px_world,
|
||||
Collider *collider,
|
||||
struct px_matrix m,
|
||||
struct px_rigidbody_params params);
|
||||
|
||||
RigidBodyHandle *px_rigidbody(struct funnyphysics *px_world,
|
||||
Collider *collider,
|
||||
struct px_matrix m,
|
||||
struct px_rigidbody_params params);
|
||||
|
||||
void px_setposition(struct funnyphysics *px_world, RigidBodyHandle *body, struct px_vec3 vec);
|
||||
|
||||
void px_setvelocity(struct funnyphysics *px_world, RigidBodyHandle *body, struct px_vec3 vec);
|
||||
|
||||
RigidBodyHandle *px_staticbody(struct funnyphysics *px_world,
|
||||
Collider *collider,
|
||||
struct px_matrix m);
|
||||
|
||||
Collider *px_trimesh(const Point<float> *ptr_vert,
|
||||
size_t len_vert,
|
||||
const uint32_t (*ptr_ind)[3],
|
||||
size_t len_ind,
|
||||
struct px_collider_params params);
|
||||
struct RapierShape_t *CRapierPhysics_CreateBall(struct BallShape_t ball);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
|
||||
Reference in New Issue
Block a user