游戏引擎中的BoundingBox

一.AABB包围盒

<1.包围盒定义

以长方体盒子形状,长方体顶点为描述的包围盒,在模型,碰撞体创建时同时创建,以实现物理碰撞,特殊shader渲染等常用功能.

center = (min + max) / 2

radius = min到max距离/2

复制代码
public class AABBBoundingBox
{
    public Vector4 min = Vector4.Zero;

    public Vector4 max = Vector4.Zero;

    public Vector4 center = Vector4.Zero;

    public float radius = 0f;
}

<2.包围盒相交物理检测

复制代码
public bool PointInsideBox(Vec3 point, float epsilon)
{
	return point.x + epsilon <= this.max.x 
            && point.x - epsilon >= this.min.x 
            && point.y + epsilon <= this.max.y 
            && point.y - epsilon >= this.min.y 
            && point.z + epsilon <= this.max.z 
            && point.z - epsilon >= this.min.z;
}

二.OBB包围盒

<1.包围盒定义

以长方体盒子形状,局部坐标系三个坐标轴向量进行描述的包围盒.

复制代码
public class OBBBoundingBox
{
   public Vector4 s = new Vector4(1f, 0f, 0f, 0f);

   public Vector4 f = new Vector4(0f, 1f, 0f, 0f);

   public Vector4 u = new Vector4(0f, 0f, 1f, 0f);
}
相关推荐
zdr尽职尽责2 天前
UnityCli 兼容2022版本
ui·unity·ai·c#·游戏引擎
zdr尽职尽责5 天前
Unity 3C 动画系统:从「蜘蛛网」到可维护的动画架构
unity·架构·游戏引擎
国家一级摸鱼选手5 天前
[Unity]几何碰撞检测:SAT 分离轴定理详解(从数学原理到 C# 实现)
unity·c#·游戏引擎·分离轴定理(sat)·多边形相交
暴走约伯7 天前
【VFX工具链源码拆解 09】终极工业化闭环:基于 ID 规则驱动的全自动场景建档、骨骼挂载与男转女场景迁移
unity·c#·游戏引擎·材质
寂寞的船8 天前
【Unity知识速递】第13期 Unity 内存泄漏排查实战:从 Memory Profiler 到 Lua 引用泄漏的生产级全链路诊断
unity·junit·c#·游戏引擎·lua
寂寞的船9 天前
【Unity Bug挑战】第12期 Awaitable 二次 await 死锁之谜 —— 为什么同一个异步操作等两次就卡死?
unity·c#·游戏引擎·bug
探求虚无10 天前
用 AI 在 Unity 里做一款 RTS:最难的不是生成代码,而是证明它真的能玩
人工智能·unity·游戏引擎
寂寞的船12 天前
【Unity知识速递】第10期 Unity GC 零分配实战:从 UnityEngine.Pool 到手动 GC 控制的全链路优化
jvm·unity·c#·游戏引擎·lucene
Martina_032113 天前
AI生成3D场景的霓虹灯一开就糊成光团?用6步检查Emissive、Bloom与曝光
人工智能·3d·ai·自然语言处理·游戏引擎·材质·贴图
寂寞的船14 天前
【Unity知识速递】第8期 IL2CPP 托管堆内存碎片与原生堆交互机制深度解析
unity·游戏引擎·交互