AABB
AlignmentBehavior
ArriveBehavior
AStar
BFS
BoundingSphere
BVH
BVHNode
Cell
CellSpacePartitioning
CohesionBehavior
CompositeGoal
ConvexHull
Corridor
CostTable
DFS
Dijkstra
Edge
EntityManager
EvadeBehavior
EventDispatcher
Behavior
FollowPathBehavior
FuzzyAND
FuzzyCompositeTerm
FuzzyFAIRLY
FuzzyModule
FuzzyOR
FuzzyRule
FuzzySet
FuzzyTerm
FuzzyVariable
FuzzyVERY
GameEntity
Goal
GoalEvaluator
Graph
GraphUtils
HalfEdge
HeuristicPolicyDijkstra
HeuristicPolicyEuclid
HeuristicPolicyEuclidSquared
HeuristicPolicyManhattan
InterposeBehavior
LeftSCurveFuzzySet
LeftShoulderFuzzySet
LineSegment
Logger
MathUtils
Matrix3
Matrix4
MemoryRecord
MemorySystem
MeshGeometry
MessageDispatcher
MovingEntity
NavEdge
NavMesh
NavMeshLoader
NavNode
Node
NormalDistFuzzySet
OBB
ObstacleAvoidanceBehavior
OffsetPursuitBehavior
OnPathBehavior
Path
Plane
Polygon
Polyhedron
PriorityQueue
PursuitBehavior
Quaternion
Ray
RectangleTriggerRegion
Regular
RightSCurveFuzzySet
RightShoulderFuzzySet
SAT
SeekBehavior
SeparationBehavior
SingletonFuzzySet
Smoother
SphericalTriggerRegion
State
StateMachine
SteeringBehavior
SteeringManager
Task
TaskQueue
Telegram
Think
Time
TriangularFuzzySet
Trigger
TriggerRegion
Vector3
Vehicle
Version
WanderBehavior

intersectOBB

函数intersectOBB用于检测一条光线是否与一个方向包围盒(OBB)相交。方向包围盒是一个矩形的体,可以通过中心点、尺寸以及旋转定义。

语法

intersectOBB(ray, obb)

参数

  • ray{ origin: Vector3, direction: Vector3 },一条光线对象,包含一个起点和一个单位方向向量。
  • obb{ center: Vector3, halfSize: Vector3, orientation: Quaternion },一个方向包围盒对象,包含中心点,半尺寸以及旋转。

返回值

  • 如果光线与OBB相交,返回最近的交点的到光线原点的距离,否则返回null

示例

import { Vector3, Quaternion } from 'three';
import { intersectOBB } from 'yuka';

const ray = {
  origin: new Vector3(0, 0, 0),
  direction: new Vector3(0, 0, -1)
};

const obb = {
  center: new Vector3(0, 0, -5),
  halfSize: new Vector3(1, 1, 1),
  orientation: new Quaternion().setFromEuler(0, 0, 0)
};

const distance = intersectOBB(ray, obb);
if (distance !== null) {
  console.log(`交点到光线原点的距离: ${distance}`);
} else {
  console.log('光线与方向包围盒没有相交。');
}

备注

  • 该函数假设ray始终指向正方向。如果不是,需要调整参数。
  • 该函数只检测OBB与光线的相交情况,不计算相交点。如需求解相交点,可以在返回的距离基础上使用ray.originray.direction来计算。