コード例 #1
0
void ShapeVisitor_Comparator::visit (Shape_Plane & shape) {
    QSharedPointer<Shape_Plane> otherShape = otherShape_.dynamicCast<Shape_Plane> ();
    if (! otherShape.isNull ()) {
        comparisonResult_ =
            (shape.getNormalVector () == otherShape->getNormalVector ())
            &&
            (shape.getD () == otherShape->getD ())
            ;
    } else {
        comparisonResult_ = false;
    }
}
コード例 #2
0
void ShapeVisitor_RestrictedPositionGetter::visit( Shape_Plane& shape )
{
	float t;
	float m = - shape.getD() - shape.getNormalVector().x() * mOriginalPosition.x() - shape.getNormalVector().y() * mOriginalPosition.y() - shape.getNormalVector().z() * mOriginalPosition.z();

	double shapeX= static_cast<double>( shape.getNormalVector().x() );
	double shapeY= static_cast<double>( shape.getNormalVector().y() );
	double shapeZ= static_cast<double>( shape.getNormalVector().z() );
	double n = pow( shapeX, 2.0 ) + pow( shapeY, 2.0 ) + pow( shapeZ, 2.0 );
	if ( !qFuzzyCompare( n,0.0 ) )
		//if (n != 0.0)
	{
		t = m / static_cast<float>( n );
	}
	else {
		t = 0.f;
	}

	mRestrictedPosition = osg::Vec3f(
							  mOriginalPosition.x() + t * shape.getNormalVector().x(),
							  mOriginalPosition.y() + t * shape.getNormalVector().y(),
							  mOriginalPosition.z() + t * shape.getNormalVector().z()
						  );
}