本文整理汇总了C++中Plane3类的典型用法代码示例。如果您正苦于以下问题:C++ Plane3类的具体用法?C++ Plane3怎么用?C++ Plane3使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Plane3类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OVITO_ASSERT
/******************************************************************************
* Aligns the modifier's slicing plane to the three selected particles.
******************************************************************************/
void PickParticlePlaneInputMode::alignPlane(SliceModifier* mod)
{
OVITO_ASSERT(_pickedParticles.size() == 3);
try {
Plane3 worldPlane(_pickedParticles[0].worldPos, _pickedParticles[1].worldPos, _pickedParticles[2].worldPos, true);
if(worldPlane.normal.equals(Vector3::Zero(), FLOATTYPE_EPSILON))
throw Exception(tr("Cannot set the new slicing plane. The three selected particle are colinear."));
// Get the object to world transformation for the currently selected node.
ObjectNode* node = _pickedParticles[0].objNode;
TimeInterval interval;
const AffineTransformation& nodeTM = node->getWorldTransform(mod->dataset()->animationSettings()->time(), interval);
// Transform new plane from world to object space.
Plane3 localPlane = nodeTM.inverse() * worldPlane;
// Flip new plane orientation if necessary to align it with old orientation.
if(localPlane.normal.dot(mod->normal()) < 0)
localPlane = -localPlane;
localPlane.normalizePlane();
UndoableTransaction::handleExceptions(mod->dataset()->undoStack(), tr("Align plane to particles"), [mod, &localPlane]() {
mod->setNormal(localPlane.normal);
mod->setDistance(localPlane.dist);
});
}
catch(const Exception& ex) {
ex.showError();
}
}
示例2:
bool ConvexPolyhedron3<Real>::ComputeSilhouette (V3Array& rkTerminator,
const Vector3<Real>& rkEye, const Plane3<Real>& rkPlane,
const Vector3<Real>& rkU, const Vector3<Real>& rkV,
V2Array& rkSilhouette)
{
Real fEDist = rkPlane.DistanceTo(rkEye); // assert: fEDist > 0
// closest planar point to E is K = E-dist*N
Vector3<Real> kClosest = rkEye - fEDist*rkPlane.GetNormal();
// project polyhedron points onto plane
for (int i = 0; i < (int)rkTerminator.size(); i++)
{
Vector3<Real>& rkPoint = rkTerminator[i];
Real fVDist = rkPlane.DistanceTo(rkPoint);
if ( fVDist >= fEDist )
{
// cannot project vertex onto plane
return false;
}
// compute projected point Q
Real fRatio = fEDist/(fEDist-fVDist);
Vector3<Real> kProjected = rkEye + fRatio*(rkPoint - rkEye);
// compute (x,y) so that Q = K+x*U+y*V+z*N
Vector3<Real> kDiff = kProjected - kClosest;
rkSilhouette.push_back(Vector2<Real>(rkU.Dot(kDiff),rkV.Dot(kDiff)));
}
return true;
}
示例3: Plane3
// TODO: 最优分割面选择需要考虑到二叉树的平衡性
// weight = fabs(左数目-右数目)+分割数目
// 越小越优先考虑
int BspTree::BspNode::BestIndex( std::vector< BspTriangle >& polyList )
{
/**
* The current hueristic is blind least-split
*/
// run through the list, searching for the best one.
// the highest BspTriangle we'll bother testing (10% of total)
int maxCheck;
maxCheck = (int)(polyList.size() * percentageToCheck);
if( !maxCheck ) maxCheck = 1;
int bestSplits = 100000;
int bestIndex = -1;
int currSplits; // 这个平面总共分割了多少平面
int frontCount, backCount;
Plane3 currPlane;
for(int i=0; i<maxCheck; i++ )
{
currSplits = 0;
frontCount = backCount = 0;
currPlane = Plane3( polyList[i] );
PointListLoc res;
for(unsigned int i2=0; i2< polyList.size(); i2++ )
{
if( i == i2 ) continue;
res = currPlane.TestPoly( polyList[i2] );
switch(res)
{
case plistSplit:
currSplits++;
break;
case plistFront:
frontCount++;
break;
case plistBack:
backCount++;
break;
}
}
int weight = abs(frontCount - backCount) + currSplits;
//int weight = currSplits;
if( weight < bestSplits )
{
bestSplits = weight;
bestIndex = i;
}
}
assert( bestIndex >= 0 );
return bestIndex;
}
示例4: getFace
void FaceInstance::addLight(const Matrix4& localToWorld, const RendererLight& light)
{
const Plane3& facePlane = getFace().plane3();
Plane3 tmp = Plane3(facePlane.normal(), -facePlane.dist())
.transformed(localToWorld);
if (!tmp.testPoint(light.worldOrigin()) || !tmp.testPoint(light.getLightOrigin()))
{
m_lights.addLight(light);
}
}
示例5: Culled
bool Wml::Culled (const Plane3<Real>& rkPlane, const Box3<Real>& rkBox)
{
Real fTmp[3] =
{
rkBox.Extent(0)*(rkPlane.GetNormal().Dot(rkBox.Axis(0))),
rkBox.Extent(1)*(rkPlane.GetNormal().Dot(rkBox.Axis(1))),
rkBox.Extent(2)*(rkPlane.GetNormal().Dot(rkBox.Axis(2)))
};
Real fRadius = Math<Real>::FAbs(fTmp[0]) + Math<Real>::FAbs(fTmp[1]) +
Math<Real>::FAbs(fTmp[2]);
Real fPseudoDistance = rkPlane.DistanceTo(rkBox.Center());
return fPseudoDistance <= -fRadius;
}
示例6: transformLocked
void TextureProjection::transformLocked (std::size_t width, std::size_t height, const Plane3& plane,
const Matrix4& identity2transformed)
{
Vector3 normalTransformed(matrix4_transformed_direction(identity2transformed, plane.normal()));
// identity: identity space
// transformed: transformation
// stIdentity: base st projection space before transformation
// stTransformed: base st projection space after transformation
// stOriginal: original texdef space
// stTransformed2stOriginal = stTransformed -> transformed -> identity -> stIdentity -> stOriginal
Matrix4 identity2stIdentity;
basisForNormal(plane.normal(), identity2stIdentity);
Matrix4 transformed2stTransformed;
basisForNormal(normalTransformed, transformed2stTransformed);
Matrix4 stTransformed2identity(matrix4_affine_inverse(matrix4_multiplied_by_matrix4(transformed2stTransformed,
identity2transformed)));
Vector3 originalProjectionAxis(matrix4_affine_inverse(identity2stIdentity).z().getVector3());
Vector3 transformedProjectionAxis(stTransformed2identity.z().getVector3());
Matrix4 stIdentity2stOriginal = m_texdef.getTransform((float) width, (float) height);
Matrix4 identity2stOriginal(matrix4_multiplied_by_matrix4(stIdentity2stOriginal, identity2stIdentity));
double dot = originalProjectionAxis.dot(transformedProjectionAxis);
if (dot == 0) {
// The projection axis chosen for the transformed normal is at 90 degrees
// to the transformed projection axis chosen for the original normal.
// This happens when the projection axis is ambiguous - e.g. for the plane
// 'X == Y' the projection axis could be either X or Y.
Matrix4 identityCorrected = matrix4_reflection_for_plane45(plane, originalProjectionAxis,
transformedProjectionAxis);
identity2stOriginal = matrix4_multiplied_by_matrix4(identity2stOriginal, identityCorrected);
}
Matrix4 stTransformed2stOriginal = matrix4_multiplied_by_matrix4(identity2stOriginal, stTransformed2identity);
setTransform((float) width, (float) height, stTransformed2stOriginal);
m_texdef.normalise((float) width, (float) height);
}
示例7: centroid
Vector3 Winding::centroid(const Plane3& plane) const
{
Vector3 centroid(0,0,0);
float area2 = 0, x_sum = 0, y_sum = 0;
const ProjectionAxis axis = projectionaxis_for_normal(plane.normal());
const indexremap_t remap = indexremap_for_projectionaxis(axis);
for (std::size_t i = size() - 1, j = 0; j < size(); i = j, ++j)
{
const float ai = (*this)[i].vertex[remap.x]
* (*this)[j].vertex[remap.y] - (*this)[j].vertex[remap.x]
* (*this)[i].vertex[remap.y];
area2 += ai;
x_sum += ((*this)[j].vertex[remap.x] + (*this)[i].vertex[remap.x]) * ai;
y_sum += ((*this)[j].vertex[remap.y] + (*this)[i].vertex[remap.y]) * ai;
}
centroid[remap.x] = x_sum / (3 * area2);
centroid[remap.y] = y_sum / (3 * area2);
{
Ray ray(Vector3(0, 0, 0), Vector3(0, 0, 0));
ray.origin[remap.x] = centroid[remap.x];
ray.origin[remap.y] = centroid[remap.y];
ray.direction[remap.z] = 1;
centroid[remap.z] = ray.getDistance(plane);
}
return centroid;
}
示例8: Culled
bool Wml::Culled (const Plane3<Real>& rkPlane,
const Ellipsoid3<Real>& rkEllipsoid, bool bUnitNormal)
{
Vector3<Real> kNormal = rkPlane.GetNormal();
Real fConstant = rkPlane.GetConstant();
if ( !bUnitNormal )
{
Real fLength = kNormal.Normalize();
fConstant /= fLength;
}
Real fDiscr = kNormal.Dot(rkEllipsoid.InverseA()*kNormal);
Real fRoot = Math<Real>::Sqrt(Math<Real>::FAbs(fDiscr));
Real fSDist = kNormal.Dot(rkEllipsoid.Center()) - fConstant;
return fSDist <= -fRoot;
}
示例9: PlaneCullTest
bool PlaneCullTest(const Plane3& plane, const AABB3& box){
Vector3 testVertex;
// find the vertex with the greatest distance value
if(plane.n.x >= 0.f){
if(plane.n.y >= 0.f){
if(plane.n.z >= 0.f){
testVertex = box.max;
}else{
testVertex = MakeVector3(box.max.x, box.max.y, box.min.z);
}
}else{
if(plane.n.z >= 0.f){
testVertex = MakeVector3(box.max.x, box.min.y, box.max.z);
}else{
testVertex = MakeVector3(box.max.x, box.min.y, box.min.z);
}
}
}else{
if(plane.n.y >= 0.f){
if(plane.n.z >= 0.f){
testVertex = MakeVector3(box.min.x, box.max.y, box.max.z);
}else{
testVertex = MakeVector3(box.min.x, box.max.y, box.min.z);
}
}else{
if(plane.n.z >= 0.f){
testVertex = MakeVector3(box.min.x, box.min.y, box.max.z);
}else{
testVertex = box.min;
}
}
}
return plane.GetDistanceTo(testVertex) >= 0.f;
}
示例10: line_intersect_plane
/// \brief Returns the point at which \p line intersects \p plane, or an undefined value if there is no intersection.
inline DoubleVector3 line_intersect_plane(const DoubleLine& line, const Plane3& plane)
{
return line.origin + vector3_scaled(
line.direction,
-plane3_distance_to_point(plane, line.origin)
/ vector3_dot(line.direction, plane.normal())
);
}
示例11: whichSide
/* ------------------------------------------------------- */
int SphereVolume::whichSide(const Plane3& plane) const
{
float d = plane.distanceTo(m_center);
if (d > m_radius)
return 1;
else if (d < -m_radius)
return -1;
else
return 0;
}
示例12: TEST
/* see https://github.com/kduske/TrenchBroom/issues/1033
commented out because it breaks the release build process
*/
TEST(PlaneTest, planePointFinder) {
Plane3 plane;
const Vec3 points[3] = {Vec3(48, 16, 28), Vec3(16.0, 16.0, 27.9980487823486328125), Vec3(48, 18, 22)};
ASSERT_FALSE(points[1].isInteger());
ASSERT_TRUE(setPlanePoints(plane, points[0], points[1], points[2]));
// Some verts that should lie (very close to) on the plane
std::vector<Vec3> verts;
verts.push_back(Vec3(48, 18, 22));
verts.push_back(Vec3(48, 16, 28));
verts.push_back(Vec3(16, 16, 28));
verts.push_back(Vec3(16, 18, 22));
for (size_t i=0; i<verts.size(); i++) {
FloatType dist = Math::abs(plane.pointDistance(verts[i]));
ASSERT_LT(dist, 0.01);
}
// Now find a similar plane with integer points
Vec3 intpoints[3];
for (size_t i=0; i<3; i++)
intpoints[i] = points[i];
TrenchBroom::Model::PlanePointFinder::findPoints(plane, intpoints, 3);
ASSERT_TRUE(intpoints[0].isInteger());
ASSERT_TRUE(intpoints[1].isInteger());
ASSERT_TRUE(intpoints[2].isInteger());
Plane3 intplane;
ASSERT_TRUE(setPlanePoints(intplane, intpoints[0], intpoints[1], intpoints[2]));
// ASSERT_FALSE(intplane.equals(plane)); no longer fails
// Check that the verts are still close to the new integer plane
for (size_t i=0; i<verts.size(); i++) {
FloatType dist = Math::abs(intplane.pointDistance(verts[i]));
ASSERT_LT(dist, 0.01);
}
}
示例13: classifyPlane
BrushSplitType Winding::classifyPlane(const Plane3& plane) const
{
BrushSplitType split;
for (const_iterator i = begin(); i != end(); ++i)
{
++split.counts[classifyDistance(plane.distanceToPoint(i->vertex), ON_EPSILON)];
}
return split;
}
示例14: updatePolyhedron
void updatePolyhedron(const Vec3& current) {
const Grid& grid = m_tool->grid();
const Math::Axis::Type axis = m_plane.normal.firstComponent();
const Plane3 swizzledPlane(swizzle(m_plane.anchor(), axis), swizzle(m_plane.normal, axis));
const Vec3 theMin = swizzle(grid.snapDown(min(m_initialPoint, current)), axis);
const Vec3 theMax = swizzle(grid.snapUp (max(m_initialPoint, current)), axis);
const Vec2 topLeft2(theMin.x(), theMin.y());
const Vec2 topRight2(theMax.x(), theMin.y());
const Vec2 bottomLeft2(theMin.x(), theMax.y());
const Vec2 bottomRight2(theMax.x(), theMax.y());
const Vec3 topLeft3 = unswizzle(Vec3(topLeft2, swizzledPlane.zAt(topLeft2)), axis);
const Vec3 topRight3 = unswizzle(Vec3(topRight2, swizzledPlane.zAt(topRight2)), axis);
const Vec3 bottomLeft3 = unswizzle(Vec3(bottomLeft2, swizzledPlane.zAt(bottomLeft2)), axis);
const Vec3 bottomRight3 = unswizzle(Vec3(bottomRight2, swizzledPlane.zAt(bottomRight2)), axis);
Polyhedron3 polyhedron = m_oldPolyhedron;
polyhedron.addPoint(topLeft3);
polyhedron.addPoint(bottomLeft3);
polyhedron.addPoint(bottomRight3);
polyhedron.addPoint(topRight3);
m_tool->update(polyhedron);
}
示例15: dataset
/******************************************************************************
* Aligns the current viewing direction to the slicing plane.
******************************************************************************/
void SliceModifierEditor::onAlignViewToPlane()
{
TimeInterval interval;
Viewport* vp = dataset()->viewportConfig()->activeViewport();
if(!vp) return;
// Get the object to world transformation for the currently selected object.
ObjectNode* node = dynamic_object_cast<ObjectNode>(dataset()->selection()->front());
if(!node) return;
const AffineTransformation& nodeTM = node->getWorldTransform(dataset()->animationSettings()->time(), interval);
// Transform the current slicing plane to the world coordinate system.
SliceModifier* mod = static_object_cast<SliceModifier>(editObject());
if(!mod) return;
Plane3 planeLocal = mod->slicingPlane(dataset()->animationSettings()->time(), interval);
Plane3 planeWorld = nodeTM * planeLocal;
// Calculate the intersection point of the current viewing direction with the current slicing plane.
Ray3 viewportRay(vp->cameraPosition(), vp->cameraDirection());
FloatType t = planeWorld.intersectionT(viewportRay);
Point3 intersectionPoint;
if(t != FLOATTYPE_MAX)
intersectionPoint = viewportRay.point(t);
else
intersectionPoint = Point3::Origin() + nodeTM.translation();
if(vp->isPerspectiveProjection()) {
FloatType distance = (vp->cameraPosition() - intersectionPoint).length();
vp->setViewType(Viewport::VIEW_PERSPECTIVE);
vp->setCameraDirection(-planeWorld.normal);
vp->setCameraPosition(intersectionPoint + planeWorld.normal * distance);
}
else {
vp->setViewType(Viewport::VIEW_ORTHO);
vp->setCameraDirection(-planeWorld.normal);
}
vp->zoomToSelectionExtents();
}