本文整理汇总了C++中Sphere::getCenter方法的典型用法代码示例。如果您正苦于以下问题:C++ Sphere::getCenter方法的具体用法?C++ Sphere::getCenter怎么用?C++ Sphere::getCenter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sphere
的用法示例。
在下文中一共展示了Sphere::getCenter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: intersect
/** Checks how the box intersects with the sphere.
*/
Intersection intersect( const Sphere &one, const AxisAlignedBox &two )
{
// Null box?
if (two.isNull()) return OUTSIDE;
if (two.isInfinite()) return INTERSECT;
float sradius = one.getRadius();
sradius *= sradius;
Vector3 scenter = one.getCenter();
const Vector3& twoMin = two.getMinimum();
const Vector3& twoMax = two.getMaximum();
float s, d = 0;
Vector3 mndistance = ( twoMin - scenter );
Vector3 mxdistance = ( twoMax - scenter );
if ( mndistance.squaredLength() < sradius &&
mxdistance.squaredLength() < sradius )
{
return INSIDE;
}
//find the square of the distance
//from the sphere to the box
for ( int i = 0 ; i < 3 ; i++ )
{
if ( scenter[ i ] < twoMin[ i ] )
{
s = scenter[ i ] - twoMin[ i ];
d += s * s;
}
else if ( scenter[ i ] > twoMax[ i ] )
{
s = scenter[ i ] - twoMax[ i ];
d += s * s;
}
}
bool partial = ( d <= sradius );
if ( !partial )
{
return OUTSIDE;
}
else
{
return INTERSECT;
}
}
示例2: draw
void ArcballTestApp::draw()
{
CameraPersp &cam = ( mUsingCameraUi ) ? mDebugCam : mCam;
gl::clear( Color( 0, 0.0f, 0.15f ) );
gl::setMatrices( cam );
// draw the earth
gl::enableDepthRead();
gl::enableDepthWrite();
gl::translate( mEarthSphere.getCenter() );
gl::rotate( mArcball.getQuat() );
mEarthTex->bind();
mEarth->draw();
// draw constraint axis
if( mArcball.isUsingConstraint() ) {
gl::setMatrices( cam );
gl::color( 1, 1, 0 );
gl::translate( mEarthSphere.getCenter() );
gl::rotate( glm::rotation( vec3( 0, 1, 0 ), mArcball.getConstraintAxis() ) );
mConstraintAxis->draw();
}
gl::disableDepthRead();
// draw from vector marker
gl::setMatrices( cam );
gl::color( 0, 1, 0.25f );
gl::translate( mEarthSphere.getCenter() + mArcball.getFromVector() * mEarthSphere.getRadius() );
mMarker->draw();
// draw to vector marker
gl::setMatrices( cam );
gl::color( 1, 0.5f, 0.25f );
gl::translate( mEarthSphere.getCenter() + mArcball.getToVector() * mEarthSphere.getRadius() );
mMarker->draw();
// draw the elliptical axes
gl::setMatricesWindow( getWindowSize() );
gl::color( 1, 0, 0 );
vec2 center, axisA, axisB;
mCam.calcScreenProjection( mEarthSphere, getWindowSize(), ¢er, &axisA, &axisB );
gl::drawLine( center - axisA, center + axisA );
gl::drawLine( center - axisB, center + axisB );
}
示例3:
ContainmentResult TestPointSphere ( Vector const & V,
Sphere const & S )
{
real radiusSquared = S.getRadius() * S.getRadius();
real distanceSquared = (V-S.getCenter()).magnitudeSquared();
return Containment1d::TestFloatLess(distanceSquared,radiusSquared);
}
示例4: EncloseABox
AxialBox EncloseABox ( Sphere const & sphere )
{
float r = sphere.getRadius();
Vector c = sphere.getCenter();
Vector d(r,r,r);
return AxialBox( c + d, c - d );
}
示例5: EncloseSphere
Sphere EncloseSphere ( Sphere const & A, Sphere const & B )
{
if( Containment::isContainment(TestSphereSphere(A,B)) ) return B;
if( Containment::isContainment(TestSphereSphere(B,A)) ) return A;
// ----------
Vector normal = B.getCenter() - A.getCenter();
IGNORE_RETURN( normal.normalize() );
Vector pointA = A.getCenter() - normal * A.getRadius();
Vector pointB = B.getCenter() + normal * B.getRadius();
Vector center = Vector::midpoint(pointA,pointB);
real radius = (pointB - pointA).magnitude() / 2.0f;
return Sphere(center,radius);
}
示例6: View
static void View(Camera* camera, const AxisAlignedBox& aabb, const Sphere& sphere)
{
float nearClip = (sphere.getRadius() > 1)? 1 : 0.05;
float farClip = sphere.getRadius()*10000.0f;
camera->setNearClipDistance(nearClip);
camera->setFarClipDistance(farClip);
// tan (fov/2.0) = r/d => d = r/tan(fov/2.0)
float distance = sphere.getRadius()/Math::Tan(camera->getFOVy()/2.0f);
camera->setPosition(sphere.getCenter() - (camera->getDirection().normalisedCopy()*distance));
}
示例7: getCenterOfInterest
CameraPersp CameraPersp::getFrameSphere( const Sphere &worldSpaceSphere, int maxIterations ) const
{
CameraPersp result = *this;
result.setEyePoint( worldSpaceSphere.getCenter() - result.mViewDirection * getCenterOfInterest() );
float minDistance = 0.01f, maxDistance = 100000.0f;
float curDistance = getCenterOfInterest();
for( int i = 0; i < maxIterations; ++i ) {
float curRadius = result.getScreenRadius( worldSpaceSphere, 2.0f, 2.0f );
if( curRadius < 1.0f ) { // we should get closer
maxDistance = curDistance;
curDistance = ( curDistance + minDistance ) * 0.5f;
}
else { // we should get farther
minDistance = curDistance;
curDistance = ( curDistance + maxDistance ) * 0.5f;
}
result.setEyePoint( worldSpaceSphere.getCenter() - result.mViewDirection * curDistance );
}
result.setCenterOfInterest( result.getEyePoint().distance( worldSpaceSphere.getCenter() ) );
return result;
}
示例8: intersected
bool Math::intersected(const Plane& plane, const Sphere& sphere)
{
Vector3 point = sphere.getCenter();
Real dis = plane.getDistance(point);
if(dis < sphere.getRadius())
{
return true;
}
else
{
return false;
}
}
示例9: add
void ParticleObject::add(const Sphere<float>& sphere, const float diameter, const float charge)
{
const auto bb = sphere.getBoundingBox();
for (auto x = bb.getMinX(); x <= bb.getMaxX(); x+= diameter) {
for (auto y = bb.getMinY(); y <= bb.getMaxY(); y += diameter) {
for (auto z = bb.getMinZ(); z <= bb.getMaxZ(); z+= diameter) {
const Vector3d<float> pos(x, y, z);
if (sphere.isInner(pos)) {
const auto density = (sphere.getRadius() - sphere.getCenter().getDistance(pos)) * charge;
particles.push_back(new Particle(pos, density, diameter * 0.5f));
}
}
}
}
sort();
}
示例10: pointSphereCollide
void Collide::pointSphereCollide(const Body * point_, const Body * sphere_)
{
Point *point = (Point*)point_;
Sphere *sphere = (Sphere*)sphere_;
float distance = 0.0f;
distance = (point->getPoint() - sphere->getCenter()).Length();
setCollide(distance < sphere->getRadius());
setDistance(distance - sphere->getRadius());
// compute the response vectors
Vector3 responseObject1 = point_->getCenter() - sphere_->getCenter();
Vector3 responseObject2 = sphere_->getCenter() - point_->getCenter();
setResponseObject1(responseObject1);
setResponseObject2(responseObject2);
}
示例11: setShaderVariables
void setShaderVariables(GLuint shaderProg)
{
GLfloat projMatrix[16];
GLfloat viewMatrix[16];
glGetFloatv(GL_PROJECTION_MATRIX, projMatrix);
glGetFloatv(GL_MODELVIEW_MATRIX, viewMatrix);
double *center = ball.getCenter();
if(GL20Support)
{
glUniform3f(glGetUniformLocation(shaderProg, "ballPos"),center[0], center[1], center[2]);
}
else
{
//glUniform3fvARB(glGetUniformLocationARB(shaderProg, "ballPos"), 3, (float*)ball.getCenter());
}
}
示例12:
//-----------------------------------------------------------------------
std::pair<bool, Real> Math::intersects(const Ray& ray, const Sphere& sphere,
bool discardInside)
{
const Vector3& raydir = ray.getDirection();
// Adjust ray origin relative to sphere center
const Vector3& rayorig = ray.getOrigin() - sphere.getCenter();
Real radius = sphere.getRadius();
// Check origin inside first
if (rayorig.squaredLength() <= radius*radius && discardInside)
{
return std::pair<bool, Real>(true, (Real)0);
}
// Mmm, quadratics
// Build coeffs which can be used with std quadratic solver
// ie t = (-b +/- sqrt(b*b + 4ac)) / 2a
Real a = raydir.dotProduct(raydir);
Real b = 2 * rayorig.dotProduct(raydir);
Real c = rayorig.dotProduct(rayorig) - radius*radius;
// Calc determinant
Real d = (b*b) - (4 * a * c);
if (d < 0)
{
// No intersection
return std::pair<bool, Real>(false, (Real)0);
}
else
{
// BTW, if d=0 there is one intersection, if d > 0 there are 2
// But we only want the closest one, so that's ok, just use the
// '-' version of the solver
Real t = ( -b - Math::Sqrt(d) ) / (2 * a);
if (t < 0)
t = ( -b + Math::Sqrt(d) ) / (2 * a);
return std::pair<bool, Real>(true, (Real)t);
}
}
示例13: raySphereCollide
void Collide::raySphereCollide(const Body * ray_, const Body * sphere_)
{
Ray *ray = (Ray*)ray_;
Sphere *sphere = (Sphere*)sphere_;
Vector3 vec = ray->getStart() - sphere->getCenter();
setCollide(true);
setDistance(0.0f);
float fB = vec.Dot(ray->getDir());
float fC = vec.Dot(vec) - sphere->getRadius()*sphere->getRadius();
if (fC > 0.0f && fB > 0.0f)
setCollide(false);
float fDisc = fB*fB - fC;
if (fDisc < 0.0f)
setCollide(false);
// compute the response vectors
Vector3 responseObject1 = ray_->getCenter()- sphere_->getCenter();
Vector3 responseObject2 = sphere_->getCenter() - ray_->getCenter();
setResponseObject1(responseObject1);
setResponseObject2(responseObject2);
}
示例14: test
//==============================================================================
static Bool test(const Aabb& aabb, const Sphere& s)
{
const Vec4& c = s.getCenter();
// find the box's closest point to the sphere
Vec4 cp(0.0); // Closest Point
for(U i = 0; i < 3; i++)
{
// if the center is greater than the max then the closest
// point is the max
if(c[i] > aabb.getMax()[i])
{
cp[i] = aabb.getMax()[i];
}
else if(c[i] < aabb.getMin()[i]) // relative to the above
{
cp[i] = aabb.getMin()[i];
}
else
{
// the c lies between min and max
cp[i] = c[i];
}
}
F32 rsq = s.getRadius() * s.getRadius();
// if the c lies totally inside the box then the sub is the zero,
// this means that the length is also zero and thus its always smaller
// than rsq
Vec4 sub = c - cp;
if(sub.getLengthSquared() <= rsq)
{
return true;
}
return false;
}
示例15: TestSphereCylinder
ContainmentResult TestSphereCylinder ( Sphere const & S,
Cylinder const & C )
{
Vector delta = C.getBase() - S.getCenter();
delta.y = 0;
real dist = delta.magnitude();
Range SD( dist - S.getRadius(), dist + S.getRadius() );
Range CD( -C.getRadius(), C.getRadius() );
ContainmentResult hTest = Containment1d::TestRangeRange( SD, CD );
ContainmentResult hTest2 = Containment1d::TestFloatRange( dist, CD );
ContainmentResult vTest = Containment1d::TestRangeRange( S.getRangeY(), C.getRangeY() );
ContainmentResult cTest = Containment1d::TestFloatRange( S.getCenter().y, C.getRangeY() );
// ----------
if(hTest == CR_Outside)
{
// Sphere can't possibly touch the cylinder
return CR_Outside;
}
else if((hTest == CR_TouchingOutside) || (hTest == CR_Boundary))
{
// Sphere is touching the outside of the cylinder's tube if its
// center is inside the vertical range of the cylinder
if((cTest == CR_Inside) || (cTest == CR_Boundary))
{
return CR_TouchingOutside;
}
else
{
return CR_Outside;
}
}
else if((hTest == CR_Inside) || (hTest == CR_TouchingInside))
{
// Sphere is in the tube of the cylinder. It touches the cylinder
// if its vertical range touches the vertical range of the cylinder
return Containment::ComposeAxisTests(hTest,vTest);
}
else
{
// hTest == CR_Overlap
if(vTest == CR_Outside)
{
return CR_Outside;
}
else if((vTest == CR_Inside) || (vTest == CR_TouchingInside))
{
return CR_Overlap;
}
else if (vTest == CR_Boundary)
{
// This really shouldn't be happening
return CR_Boundary;
}
else if (vTest == CR_TouchingOutside)
{
if(hTest2 == CR_Inside)
{
// Sphere is touching a cap of the cylinder
return CR_TouchingOutside;
}
else if(hTest2 == CR_Boundary)
{
// Sphere is touching the edge of the cap of the cylinder
return CR_TouchingOutside;
}
else
{
// Sphere isn't touching the cap
return CR_Outside;
}
}
else
{
// vTest == CR_Overlap
if((cTest == CR_Inside) || (cTest == CR_Boundary))
{
// The ranges overlap vertically and horizontally, and the center of
// the sphere is inside the vertical range - the sphere overlaps the
// cylinder
return CR_Overlap;
}
else
{
// The sphere is inside both ranges, but its center is outside both
// ranges. The sphere overlaps the cylinder if the closest point
// on the cylinder is inside the sphere.
//.........这里部分代码省略.........