- Scene Demo: cube + sphere + ground plane with proper lighting - Audio: XAudio2 dynamic loading + WAV playback - Physics: expanded collision system - Renderer: improved pipeline with materials - UI: extended widget system - VisualScript: enhanced serializer + block interactions - ASM: optimized math/memory/profiling routines - Window: mouse input + scroll support
75 lines
2.3 KiB
C
75 lines
2.3 KiB
C
#pragma once
|
|
|
|
// ============================================================================
|
|
// physics.h - 物理引擎 (碰撞检测, 调用ASM数学)
|
|
// ============================================================================
|
|
|
|
#include "../include/engine_api.h"
|
|
#include "../ASM/math_c_fallback.h"
|
|
#include <stdint.h>
|
|
|
|
#define MAX_COLLIDERS 1024
|
|
|
|
typedef enum {
|
|
COLLIDER_AABB,
|
|
COLLIDER_SPHERE,
|
|
COLLIDER_PLANE,
|
|
} ColliderType;
|
|
|
|
typedef struct {
|
|
Vec3 velocity;
|
|
Vec3 acceleration;
|
|
float mass;
|
|
float restitution;
|
|
float friction;
|
|
int is_kinematic;
|
|
} RigidBody;
|
|
|
|
typedef struct {
|
|
uint32_t entity_id;
|
|
ColliderType type;
|
|
union {
|
|
struct { Vec3 min; Vec3 max; } aabb;
|
|
struct { Vec3 center; float radius; } sphere;
|
|
struct { Vec3 normal; float distance; } plane;
|
|
};
|
|
int is_trigger;
|
|
int is_static;
|
|
RigidBody body;
|
|
} Collider;
|
|
|
|
typedef struct {
|
|
Collider colliders[MAX_COLLIDERS];
|
|
uint32_t collider_count;
|
|
int gravity_enabled;
|
|
Vec3 gravity;
|
|
} PhysicsWorld;
|
|
|
|
// 碰撞回调
|
|
typedef void (*CollisionCallback)(uint32_t entity_a, uint32_t entity_b, Vec3 normal, float depth);
|
|
|
|
// 创建/销毁
|
|
PhysicsWorld* physics_create(void);
|
|
void physics_destroy(PhysicsWorld* world);
|
|
|
|
// 碰撞体
|
|
uint32_t physics_add_aabb(PhysicsWorld* world, uint32_t entity, Vec3 min, Vec3 max);
|
|
uint32_t physics_add_sphere(PhysicsWorld* world, uint32_t entity, Vec3 center, float radius);
|
|
uint32_t physics_add_plane(PhysicsWorld* world, uint32_t entity, Vec3 normal, float distance);
|
|
void physics_remove_collider(PhysicsWorld* world, uint32_t index);
|
|
void physics_update_collider(PhysicsWorld* world, uint32_t index, Vec3 position);
|
|
|
|
// 碰撞检测
|
|
int physics_check_collision(const Collider* a, const Collider* b, Vec3* normal, float* depth);
|
|
int physics_raycast(PhysicsWorld* world, Vec3 origin, Vec3 direction, float max_dist,
|
|
uint32_t* hit_entity, Vec3* hit_point, Vec3* hit_normal);
|
|
|
|
// 刚体
|
|
RigidBody* physics_get_body(PhysicsWorld* world, uint32_t index);
|
|
void physics_apply_force(PhysicsWorld* world, uint32_t index, Vec3 force);
|
|
void physics_apply_impulse(PhysicsWorld* world, uint32_t index, Vec3 impulse);
|
|
|
|
// 模拟
|
|
void physics_step(PhysicsWorld* world, float dt);
|
|
void physics_set_gravity(PhysicsWorld* world, Vec3 gravity);
|