当前位置: 首页>>代码示例>>C++>>正文


C++ Sphere类代码示例

本文整理汇总了C++中Sphere的典型用法代码示例。如果您正苦于以下问题:C++ Sphere类的具体用法?C++ Sphere怎么用?C++ Sphere使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Sphere类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

void T71::sphereEnter(Sphere &s){

/**********************************/
if (related)
    s.setSize(3.f); // make the sphere bigger
  else
    s.setSize(1.f); //make the sphere smaller

/**********************************/

  this->texture=driver->getTexture(texturepath+"won.png");
 
  // build a block and paint it with texture
  block = smgr->addCubeSceneNode(fieldsize);
  block->setMaterialTexture(0,texture); 
  block->setPosition(cubePosition(x,y,true));
  block->setMaterialFlag(video::EMF_LIGHTING, false); 
  
 
  cerr<<"you have won";
}
开发者ID:Zkalf,项目名称:Enigma-c-,代码行数:21,代码来源:T71.cpp

示例2: ESpaceTri

bool Ellipsoid::SweepAgainst( const CollisionTriangle& t, const Vector& v, const AABB& SweepAABB, CollisionInfo* const pInfo ) const
{
	if( SweepAABB.Intersects( t.m_AABB ) )	// Broad phase: test sweep bounds against precomputed triangle bounds 
	{
		const Vector InvExtents = 1.0f / m_Extents;
		const Triangle ESpaceTri( t.m_Triangle.m_Vec1 * InvExtents, t.m_Triangle.m_Vec2 * InvExtents, t.m_Triangle.m_Vec3 * InvExtents );
		const Sphere UnitSphere( m_Center * InvExtents, 1.0f );
		const Vector ESpaceOffset = v * InvExtents;

		if( UnitSphere.SweepAgainst( ESpaceTri, ESpaceOffset, pInfo ) )
		{
			if( pInfo )
			{
				pInfo->m_Intersection *= m_Extents;
				pInfo->m_Plane = Plane( ( pInfo->m_Plane.m_Normal * InvExtents ).GetNormalized(), pInfo->m_Intersection );
			}
			return true;
		}
	}
	return false;
}
开发者ID:Johnicholas,项目名称:EldritchCopy,代码行数:21,代码来源:ellipsoid.cpp

示例3: SPHParticle

std::vector<SPHParticle*> PhysicsObject::createParticles(const Sphere<float>& sphere, const float divideLength)
{
	std::vector<SPHParticle*> newParticles;

	const auto points = sphere.toPoints(divideLength);
	for (const auto& pos : points) {
		SPHParticle* p = new SPHParticle(pos, divideLength*0.5f, &this->constant, nextId++);
		particles.push_back(p);
		newParticles.push_back(p);
	}
	return newParticles;
}
开发者ID:SatoshiMabuchi,项目名称:CGLib,代码行数:12,代码来源:PhysicsObject.cpp

示例4: 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);
}
开发者ID:jackhui,项目名称:GE,代码行数:21,代码来源:cdCollide.cpp

示例5: isVisible

    bool PCZFrustum::isVisible( const Sphere & bound) const
    {
        // Check originplane if told to
        if (mUseOriginPlane)
        {
            Plane::Side side = mOriginPlane.getSide(bound.getCenter());
            if (side == Plane::NEGATIVE_SIDE)
            {
				Real dist = mOriginPlane.getDistance(bound.getCenter());
				if (dist > bound.getRadius())
				{
					return false;
				}
            }
        }

        // For each extra active culling plane, see if the entire sphere is on the negative side
        // If so, object is not visible
        PCPlaneList::const_iterator pit = mActiveCullingPlanes.begin();
        while ( pit != mActiveCullingPlanes.end() )
        {
            PCPlane * plane = *pit;
            Plane::Side xside = plane->getSide(bound.getCenter());
            if (xside == Plane::NEGATIVE_SIDE)
            {
				Real dist = plane->getDistance(bound.getCenter());
				if (dist > bound.getRadius())
				{
					return false;
				}
            }
            pit++;
        }
		return true;
    }
开发者ID:j-rivero,项目名称:ogre-acornacorn,代码行数:35,代码来源:OgrePCZFrustum.cpp

示例6: isFullyVisible

	/* special function that returns true only when sphere fully fits inside the frustum. */
	bool PCZFrustum::isFullyVisible(const Sphere& bound) const
	{
		// Check originplane if told to
		if (mUseOriginPlane)
		{
			if (mOriginPlane.getDistance(bound.getCenter()) <= bound.getRadius() ||
				mOriginPlane.getSide(bound.getCenter()) != Plane::POSITIVE_SIDE)
			{
				return false;
			}
		}

		// For each extra active culling plane,
		// see if the sphere is not on the positive side
		// If so, object is not fully visible
		PCPlaneList::const_iterator pit = mActiveCullingPlanes.begin();
		while ( pit != mActiveCullingPlanes.end() )
		{
			PCPlane* plane = *pit;

			if (plane->getDistance(bound.getCenter()) <= bound.getRadius() ||
				plane->getSide(bound.getCenter()) != Plane::POSITIVE_SIDE)
			{
				return false;
			}

			pit++;
		}
		return true;
	}
开发者ID:j-rivero,项目名称:ogre-acornacorn,代码行数:31,代码来源:OgrePCZFrustum.cpp

示例7: OptimalEnclosingSphere

Sphere Sphere::OptimalEnclosingSphere(const vec &a, const vec &b, const vec &c, const vec &d, const vec &e,
                                      int &redundantPoint)
{
	Sphere s = OptimalEnclosingSphere(b,c,d,e);
	if (s.Contains(a, sEpsilon))
	{
		redundantPoint = 0;
		return s;
	}
	s = OptimalEnclosingSphere(a,c,d,e);
	if (s.Contains(b, sEpsilon))
	{
		redundantPoint = 1;
		return s;
	}
	s = OptimalEnclosingSphere(a,b,d,e);
	if (s.Contains(c, sEpsilon))
	{
		redundantPoint = 2;
		return s;
	}
	s = OptimalEnclosingSphere(a,b,c,e);
	if (s.Contains(d, sEpsilon))
	{
		redundantPoint = 3;
		return s;
	}
	s = OptimalEnclosingSphere(a,b,c,d);
	mathassert(s.Contains(e, sEpsilon));
	redundantPoint = 4;
	return s;
}
开发者ID:juj,项目名称:MathGeoLib,代码行数:32,代码来源:Sphere.cpp

示例8: setupScene

void MyApp::setupScene()
{

	int N_SPHERES = 8;
	float SKY_HEIGHT = 175.0f;

	float MIN_RAD = 5;
	float MAX_RAD = 15;

	int MIN_TESSFACTOR = 2;
	int MAX_TESSFACTOR = 7;


	float spheres_area = GRID_WIDTH;

	for (int i=0; i<N_SPHERES; i++)
	{
		Sphere s;
		s.setPos(	rand() % (unsigned int)spheres_area - spheres_area / 2.0f,
					SKY_HEIGHT,
					rand() % (unsigned int)spheres_area - spheres_area / 2.0f
				);

		s.setTargetPos(s.getPos().x, 25.0f, s.getPos().z);
		float rnd = rand() / (float)RAND_MAX;
		s.radius = MIN_RAD + rnd * (MAX_RAD - MIN_RAD);
		s.tessFactor = rand() % (MAX_TESSFACTOR - MIN_TESSFACTOR + 1) + MIN_TESSFACTOR;

		m_spheres.push_back(s);
	}

	// tess objects parameters
	for (int i=0; i<4; i++) {
		tessObjects[i].bWireframe = false;
		tessObjects[i].iEdgeFactor = 10;
		tessObjects[i].iInsideFactor = 10;
		tessObjects[i].partitioning = TessPartitioning::INTEGER;
	}
}
开发者ID:s0n4m,项目名称:hlsl-rendering,代码行数:39,代码来源:MyApp.cpp

示例9: generate_shadow_cameras

static void generate_shadow_cameras(
	Slice<ShadowCamera> out,
	const PlayerCamera &view, float near, float far, float fov, float aspect,
	const Vec3 &lightdir, float ratio)
{
	Sphere spheres[4];
	generate_frustum_split_spheres(spheres, fov, aspect, near, far, ratio);
	for (int i = 0; i < 4; i++) {
		const Sphere sphere = transform(spheres[i], view.transform);

		ShadowCamera &outcam = out[i];
		outcam.transform.orientation = Quat_LookAt(lightdir);
		const Vec2 texel = Vec2(sphere.diameter()) / Vec2(1024);
		Vec3 center = inverse(outcam.transform.orientation).rotate(sphere.center);
		center.x = std::floor(center.x / texel.x) * texel.x;
		center.y = std::floor(center.y / texel.y) * texel.y;
		center.z += sphere.radius + sphere.radius;
		outcam.transform.translation = outcam.transform.orientation.rotate(center);
		outcam.set_from_sphere(sphere, sphere.radius);
		outcam.apply_transform();
	}
}
开发者ID:nsf,项目名称:nextgame,代码行数:22,代码来源:main.cpp

示例10: getWindowAspectRatio

void ArcballTestApp::setup()
{
	gl::enableDepthRead();
	gl::enableDepthWrite();

	mZLookAt = 0.5f;
	mCam.setPerspective( 45.0f, getWindowAspectRatio(), 0.1f, 1000.0f );
	mCam.lookAt( vec3( 0,3, 5 ), vec3( mZLookAt ) );

	mDebugCam = mCam;

	mEarthSphere = Sphere( vec3( 0, 0, -3 ), 1.5f );
	mEarth = gl::Batch::create( geom::Sphere( Sphere( vec3(0), mEarthSphere.getRadius() ) ).subdivisions( 50 ), gl::getStockShader( gl::ShaderDef().texture() ) );
	mEarthTex = gl::Texture::create( loadImage( loadResource( EARTH_TEX_RES ) ) );

	mMarker = gl::Batch::create( geom::Sphere().radius(0.1f).subdivisions( 50 ), gl::getStockShader( gl::ShaderDef().color() ) );
	auto cylinder = geom::Cylinder().radius(0.05f).height( mEarthSphere.getRadius() * 3.5 ) >> geom::Translate( 0, -1.75 * mEarthSphere.getRadius(), 0 );
	mConstraintAxis = gl::Batch::create( cylinder, gl::getStockShader( gl::ShaderDef().color() ) );

	mArcball = Arcball( &mCam, mEarthSphere );
	mCamUi = CameraUi( &mDebugCam );
}
开发者ID:AbdelghaniDr,项目名称:Cinder,代码行数:22,代码来源:ArcballTestApp.cpp

示例11: Exhaustive

inline void Exhaustive(vector<BoundedRay> &rays, vector<int> &rayIndices, const int indexOffset, const int indexCount,
                       const vector<Sphere> &spheres, vector<int> &sphereIDs, const int sphereOffset, const int sphereCount,
                       vector<Hit> &hits) {

    for (int i = indexOffset; i < indexOffset + indexCount; ++i) {
        const int rayID = rayIndices[i];
        const Ray charles = rays[rayID].ToRay();
        float tHit = rays[rayID].t == 0.0f ? 1e30 : rays[rayID].t;
        Hit hit = hits[rayID];
        for (int s = sphereOffset; s < sphereOffset + sphereCount; ++s) {
            ++exhaustives;
            const Sphere sphere = spheres[sphereIDs[s]];
            const float t = sphere.Intersect(charles);
            if (0 < t && t < tHit) {
                hit = Hit(sphereIDs[s]);
                tHit = t;
            }
        }
        hits[rayID] = hit;
        rays[rayID].t = tHit;
    }
}
开发者ID:papaboo,项目名称:smalldacrt,代码行数:22,代码来源:smallplane.cpp

示例12: sphereAABBIntersection

//static
bool Intersections::sphereAABBIntersection(Sphere s, AABB a){

    Vector3 sphere_pos = s.getPos();
    double sphere_radius = s.getRadius();

    Vector3 aabb_bmin = a.getBmin();
    Vector3 aabb_bmax = a.getBmax();

    double r2 = sphere_radius * sphere_radius;
    double dmin = 0.0;

    //3 dimensions
    for( int i = 0; i < 3; i++ ) {
      if( sphere_pos[i] < aabb_bmin[i] ) {
          dmin += square( sphere_pos[i] - aabb_bmin[i] );
      }
      else if( sphere_pos[i] > aabb_bmax[i] ) {
          dmin += square( sphere_pos[i] - aabb_bmax[i] );
      }
    }
    return dmin <= r2;
}
开发者ID:AJ92,项目名称:Math,代码行数:23,代码来源:intersections.cpp

示例13: Assembly

Assembly *GraspGLObjects::CreateRoom( void ) {

	Assembly *structure = new Assembly();
	structure->SetColor( BLACK );

	// Tunnel
	tunnel = new Assembly();
	Cylinder *cylinder = new Cylinder( room_radius, room_radius, room_length, room_facets );
	cylinder->SetColor( WHITE );
	cylinder->SetTexture( wall_texture );
	cylinder->SetOrientation( 90.0, 0.0, 0.0 );
	tunnel->AddComponent( cylinder );
	// Reference Bars 
	double bar_length = room_length - 5.0 * reference_bar_radius;
	for (int i=0; i < reference_bars; i++ ){ 
		Cylinder *referenceBar = new Cylinder( reference_bar_radius, reference_bar_radius, bar_length, reference_bar_facets );
		referenceBar->SetOffset( room_radius, 0.0, 0.0 );
		referenceBar->SetOrientation( 90.0 + 180 * (float) i / (float) reference_bars, referenceBar->kVector );
		referenceBar->SetColor(  1.0 - (double) i / reference_bars, 1.0f - (double) i / reference_bars, 1.0f - (double) i / reference_bars, 1.0 );
		// The texturing on the bars may be commented out for the moment because it lengthens the rendering time too much.
		referenceBar->SetTexture( references_texture );
		tunnel->AddComponent( referenceBar );
		referenceBar = new Cylinder( reference_bar_radius, reference_bar_radius, bar_length, reference_bar_facets );
		referenceBar->SetOffset( room_radius, 0.0, 0.0 );
		referenceBar->SetOrientation( - 90.0 + 180 * (float) i / (float) reference_bars, referenceBar->kVector );
		referenceBar->SetColor(  (double) i / reference_bars, (double) i / reference_bars, (double) i / reference_bars, 1.0 );
		// See above.
		referenceBar->SetTexture( references_texture );
		tunnel->AddComponent( referenceBar );
	}
	structure->AddComponent( tunnel );

	Sphere *sphere = new Sphere( target_ball_radius );
	sphere->SetPosition( 0.0, 0.0, room_length / 2.0 );
	sphere->SetColor( RED );
	structure->AddComponent( sphere );

	return structure;
}
开发者ID:PsyPhy,项目名称:GRASPonISS,代码行数:39,代码来源:GraspGLObjects.cpp

示例14: Sphere_Enclose

void Sphere_Enclose(Sphere &s, const T &obj)
{
	PointWithDistance corners[n];
	for(int i = 0; i < n; ++i)
	{
		corners[i].pt = obj.CornerPoint(i);
		corners[i].d = s.pos.DistanceSq(corners[i].pt);
	}
	std::sort(corners, corners+n);

	for(int i = n-1; i >= 0; --i)
		s.Enclose(corners[i].pt);
}
开发者ID:juj,项目名称:MathGeoLib,代码行数:13,代码来源:Sphere.cpp

示例15: isHit

//-----------------------------------------------------------------------------
//! 衝突計算
//! 視錐台 vs 球
//! @param	[in]	sphere 当たり判定のしたい球
//-----------------------------------------------------------------------------
bool Frustum::isHit(Sphere& sphere)
{
	// 視錐台の面の更新
	updateFrustumPlane();
	// 球の座標
	Vector3 spherePos = sphere.getPosition();
	// 球の半径
	f32		sphereRad = sphere.getRadius();

	// 面との距離がすべての面の内側にあればあたっている
	for (s32 i = 0; i < 6; ++i){
		f32 distance = _plane[i].getDistance(spherePos);

		// 裏面の場合距離はマイナスなので半径を足しても
		// 負の場合視錐台の外側で且つ半径以上離れている
		if (distance + sphereRad < 0.0f){
			return false;
		}
	}

	return true;
}
开发者ID:EKISUKE,项目名称:GitHubTest,代码行数:27,代码来源:gmGeometry.cpp


注:本文中的Sphere类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。