本文整理汇总了C++中math::Vector3::Normalize方法的典型用法代码示例。如果您正苦于以下问题:C++ Vector3::Normalize方法的具体用法?C++ Vector3::Normalize怎么用?C++ Vector3::Normalize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类math::Vector3
的用法示例。
在下文中一共展示了Vector3::Normalize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RayCast
bool PolyhedronColliderGeometry::RayCast(const Ray3 &ray, float maxDistance, float &t, Math::Vector3 &n) const
{
Ray3 localRay;
auto &body = mParent->Parent();
localRay.pos = body.GlobalToLocal(ray.pos);
localRay.dir = body.GlobalToLocalVec(ray.dir);
const Math::Vector3 &p = localRay.pos;
const Math::Vector3 &d = maxDistance * localRay.dir;
const Math::Vector3 q = p + d;
float tEnter = 0.0f;
float tExit = 1.0f;
auto &verts = mAdjacency.Verts();
auto &edges = mAdjacency.Edges();
auto &faces = mAdjacency.Faces();
for (auto &face : faces)
{
if (!face.active)
continue;
// triangle edges
auto &edge0 = edges[face.edge];
auto &edge1 = edges[edge0.next];
auto &edge2 = edges[edge1.next];
// triangle verts & normal
const Math::Vector3 &a = verts[edge0.vert].position;
const Math::Vector3 &b = verts[edge1.vert].position;
const Math::Vector3 &c = verts[edge2.vert].position;
const Math::Vector3 normal = (b - a).Cross(c - a);
float denom = normal.Dot(d);
float dist = normal.Dot(p - a); // positive: outside plane
// test if segment runs parallel to the plane
if (std::fabs(denom) < EPSILON && dist > 0.0f)
return false;
const float tempT = -dist / denom;
if (denom < -EPSILON)
{
if (tempT > tEnter)
{
n = normal;
tEnter = tempT;
}
}
else if (denom > EPSILON)
{
tExit = (tExit < tempT) ? tExit : tempT;
}
// early out
if (tEnter > tExit) return false;
}
n = body.LocalToGlobalVec(n);
n.Normalize();
t = tEnter;
return true;
}