游戏引擎中的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);
}
相关推荐
玖玥拾15 小时前
Unity 3D 基础(一)Unity基础架构、物理系统、视觉渲染、空间变换与对象查询
笔记·游戏·3d·unity·游戏引擎
玖玥拾3 天前
C# 语言进阶(十四)Unity UI界面开发 + 网络消息联动
服务器·开发语言·网络·ui·unity·c#·游戏引擎
野区捕龙为宠3 天前
Unity 持久化数据
unity·游戏引擎·lucene
郝学胜-神的一滴3 天前
[简化版 GAMES 101] 计算机图形学 17:纹理技术从基础原理到多场景实战应用
c++·unity·游戏引擎·图形渲染·three.js·opengl·unreal
_ZHOURUI_H_3 天前
MyFramework: 同样是 Unity 游戏开发框架,和 HTFramework 的设计取向有什么不同?(下)
unity·游戏引擎·游戏开发·游戏ui·手游开发
丁小未5 天前
基于MVVM框架的XUUI HelloWorld 新手教程
unity·性能优化·c#·游戏引擎
松树戈6 天前
【Godot4精进之路】03~Godot编辑器常用界面介绍
编辑器·游戏引擎·godot
YigAin6 天前
Unity Spine 资源出现白边的解决办法
unity·游戏引擎·spine
郝学胜-神的一滴6 天前
中级OpenGL教程 013:渲染器类架构设计与逐帧渲染流程详解
开发语言·c++·unity·游戏引擎·图形渲染·opengl·unreal