本文整理汇总了C++中Plane::SignedDistance方法的典型用法代码示例。如果您正苦于以下问题:C++ Plane::SignedDistance方法的具体用法?C++ Plane::SignedDistance怎么用?C++ Plane::SignedDistance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Plane
的用法示例。
在下文中一共展示了Plane::SignedDistance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: IsConvex
bool Polyhedron::IsConvex() const
{
// This function is O(n^2).
/** @todo Real-Time Collision Detection, p. 64:
A faster O(n) approach is to compute for each face F of P the centroid C of F,
and for all neighboring faces G of F test if C lies behind the supporting plane of
G. If some C fails to lie behind the supporting plane of one or more neighboring
faces, P is concave, and is otherwise assumed convex. However, note that just as the
corresponding polygonal convexity test may fail for a pentagram this test may fail for,
for example, a pentagram extruded out of its plane and capped at the ends. */
for(int f = 0; f < NumFaces(); ++f)
{
Plane p = FacePlane(f);
for(int i = 0; i < NumVertices(); ++i)
{
float d = p.SignedDistance(Vertex(i));
if (d > 1e-3f) // Tolerate a small epsilon error.
{
printf("Distance of vertex %d from plane %d: %f", i, f, d);
return false;
}
}
}
return true;
}
示例2: Intersects
bool Polygon::Intersects(const Plane &plane) const
{
// Project the points of this polygon onto the 1D axis of the plane normal.
// If there are points on both sides of the plane, then the polygon intersects the plane.
float minD = inf;
float maxD = -inf;
for(size_t i = 0; i < p.size(); ++i)
{
float d = plane.SignedDistance(p[i]);
minD = Min(minD, d);
maxD = Max(maxD, d);
}
// Allow a very small epsilon tolerance.
return minD <= 1e-4f && maxD >= -1e-4f;
}
示例3: MergeConvex
void Polyhedron::MergeConvex(const float3 &point)
{
// LOGI("mergeconvex.");
std::set<std::pair<int, int> > deletedEdges;
std::map<std::pair<int, int>, int> remainingEdges;
for(size_t i = 0; i < v.size(); ++i)
if (point.DistanceSq(v[i]) < 1e-3f)
return;
// bool hadDisconnectedHorizon = false;
for(int i = 0; i < (int)f.size(); ++i)
{
// Delete all faces that don't contain the given point. (they have point in their positive side)
Plane p = FacePlane(i);
Face &face = f[i];
if (p.SignedDistance(point) > 1e-5f)
{
bool isConnected = (deletedEdges.empty());
int v0 = face.v.back();
for(size_t j = 0; j < face.v.size() && !isConnected; ++j)
{
int v1 = face.v[j];
if (deletedEdges.find(std::make_pair(v1, v0)) != deletedEdges.end())
{
isConnected = true;
break;
}
v0 = v1;
}
if (isConnected)
{
v0 = face.v.back();
for(size_t j = 0; j < face.v.size(); ++j)
{
int v1 = face.v[j];
deletedEdges.insert(std::make_pair(v0, v1));
// LOGI("Edge %d,%d is to be deleted.", v0, v1);
v0 = v1;
}
// LOGI("Deleting face %d: %s. Distance to vertex %f", i, face.ToString().c_str(), p.SignedDistance(point));
std::swap(f[i], f.back());
f.pop_back();
--i;
continue;
}
// else
// hadDisconnectedHorizon = true;
}
int v0 = face.v.back();
for(size_t j = 0; j < face.v.size(); ++j)
{
int v1 = face.v[j];
remainingEdges[std::make_pair(v0, v1)] = i;
// LOGI("Edge %d,%d is to be deleted.", v0, v1);
v0 = v1;
}
}
// The polyhedron contained our point, nothing to merge.
if (deletedEdges.empty())
return;
// Add the new point to this polyhedron.
// if (!v.back().Equals(point))
v.push_back(point);
/*
// Create a look-up index of all remaining uncapped edges of the polyhedron.
std::map<std::pair<int,int>, int> edgesToFaces;
for(size_t i = 0; i < f.size(); ++i)
{
Face &face = f[i];
int v0 = face.v.back();
for(size_t j = 0; j < face.v.size(); ++j)
{
int v1 = face.v[j];
edgesToFaces[std::make_pair(v1, v0)] = i;
v0 = v1;
}
}
*/
// Now fix all edges by adding new triangular faces for the point.
// for(size_t i = 0; i < deletedEdges.size(); ++i)
for(std::set<std::pair<int, int> >::iterator iter = deletedEdges.begin(); iter != deletedEdges.end(); ++iter)
{
std::pair<int, int> opposite = std::make_pair(iter->second, iter->first);
if (deletedEdges.find(opposite) != deletedEdges.end())
continue;
// std::map<std::pair<int,int>, int>::iterator iter = edgesToFaces.find(deletedEdges[i]);
// std::map<std::pair<int,int>, int>::iterator iter = edgesToFaces.find(deletedEdges[i]);
// if (iter != edgesToFaces.end())
{
// If the adjoining face is planar to the triangle we'd like to add, instead extend the face to enclose
//.........这里部分代码省略.........