核心热路径(数学/内存/字符串/性能分析)用MASM汇编(SSE/AVX2) 外围系统(窗口/渲染/ECS/音频/UI/脚本)用C语言 含自研编辑器、VisualScript积木编程、中文渲染(glyph_atlas)
69 lines
2.0 KiB
C
69 lines
2.0 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 {
|
|
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;
|
|
} Collider;
|
|
|
|
typedef struct {
|
|
Vec3 velocity;
|
|
Vec3 acceleration;
|
|
float mass;
|
|
float restitution;
|
|
float friction;
|
|
int is_kinematic;
|
|
} RigidBody;
|
|
|
|
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);
|
|
|
|
// 模拟
|
|
void physics_step(PhysicsWorld* world, float dt);
|
|
void physics_set_gravity(PhysicsWorld* world, Vec3 gravity);
|