2.0 KiB
2.0 KiB
Plane
命名空间: XCEngine::Math
类型: struct
头文件: XCEngine/Math/Plane.h
描述: 平面,用于 3D 空间中的平面表示和相交测试
概述
Plane 结构体用于表示 3D 空间中的平面,通过法线向量(normal)和距离值(distance)定义。平面方程为 dot(normal, point) + distance = 0。常用于碰撞检测、视锥体裁剪、射线投射等图形学基础运算。
默认构造创建一个朝上(y 轴正方向)的单位平面。
结构体成员
| 成员 | 类型 | 描述 | 默认值 |
|---|---|---|---|
normal |
Vector3 |
平面法线向量 | Vector3::Up() |
distance |
float |
原点到平面的有符号距离 | 0.0f |
公共方法
| 方法 | 描述 |
|---|---|
Plane() |
默认构造函数,创建 y=0 平面 |
Plane(normal, distance) |
从法线和距离构造平面 |
FromPoints |
从三个不共线点创建平面 |
GetDistanceToPoint |
计算点到平面的有符号距离 |
GetClosestPoint |
计算平面上最接近给定点的点 |
GetSide |
判断点在平面的哪一侧 |
Intersects |
检测与球体是否相交 |
使用示例
#include <XCEngine/Math/Plane.h>
#include <XCEngine/Math/Vector3.h>
#include <XCEngine/Math/Sphere.h>
using namespace XCEngine::Math;
void PlaneExample() {
Plane plane(Vector3::Up(), 0.0f);
Vector3 point(1.0f, 2.0f, 0.0f);
float dist = plane.GetDistanceToPoint(point);
Vector3 closest = plane.GetClosestPoint(point);
bool onNormalSide = plane.GetSide(point);
Sphere sphere(Vector3(1.0f, 0.5f, 0.0f), 1.0f);
bool intersects = plane.Intersects(sphere);
}