25 lines
346 B
Markdown
25 lines
346 B
Markdown
|
|
# Box::Intersects (Ray)
|
||
|
|
|
||
|
|
```cpp
|
||
|
|
bool Intersects(const Ray& ray, float& t) const
|
||
|
|
```
|
||
|
|
|
||
|
|
检测盒是否与射线相交。
|
||
|
|
|
||
|
|
**参数:**
|
||
|
|
- `ray` - 射线
|
||
|
|
- `t` - 输出交点距离
|
||
|
|
|
||
|
|
**返回:** `bool` - true 表示相交
|
||
|
|
|
||
|
|
**复杂度:** O(1)
|
||
|
|
|
||
|
|
**示例:**
|
||
|
|
|
||
|
|
```cpp
|
||
|
|
float t;
|
||
|
|
if (box.Intersects(ray, t)) {
|
||
|
|
Vector3 hit = ray.GetPoint(t);
|
||
|
|
}
|
||
|
|
```
|