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


C++ BoundingSphere::GetCenter方法代码示例

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


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

示例1: Enclose

bool AxisAlignedBoundingBox::Enclose(const BoundingSphere& a_oBoundingShere) const
{
	return (a_oBoundingShere.GetCenter().x + a_oBoundingShere.GetRadius() <= m_vCenter.x + m_fHalfWidth)	&&
		   (a_oBoundingShere.GetCenter().x - a_oBoundingShere.GetRadius() >= m_vCenter.x - m_fHalfWidth)	&&

		   (a_oBoundingShere.GetCenter().y + a_oBoundingShere.GetRadius() <= m_vCenter.y + m_fHalfHeight)	&&
		   (a_oBoundingShere.GetCenter().y - a_oBoundingShere.GetRadius() >= m_vCenter.y - m_fHalfHeight)	&&

		   (a_oBoundingShere.GetCenter().z + a_oBoundingShere.GetRadius() <= m_vCenter.z + m_fHalfDepth)	&&
		   (a_oBoundingShere.GetCenter().z - a_oBoundingShere.GetRadius() >= m_vCenter.z - m_fHalfDepth);
}
开发者ID:IcedLeon,项目名称:TSPhysicEngine,代码行数:11,代码来源:AxisAlignedBoundingBox.cpp

示例2: IntersectingSegmentAgainstSphere

int BasicPrimitiveTests::IntersectingSegmentAgainstSphere(const LineSegment & segment, const BoundingSphere & sphere, float & rtn_t1, float & rtn_t2)
{
	
	Eigen::Vector3f m = segment.GetPointA() - sphere.GetCenter();
	float b = (m).dot(segment.GetPointB() - segment.GetPointA());
	float c = m.dot(m);
	float discriminant = b * b - c;

	int intersection_count = 0;
	float t1 = -b - sqrt(discriminant);
	float t2 = -b + sqrt(discriminant);
	if (t1 >= 0.0f && t1 <= 1.0f && t2 >= 0.0f && t2 <= 1.0f)
	{
		rtn_t1 = t1;
		rtn_t2 = t2;	
		return 2;
	}
	else if (t1 >= 0.0f && t1 <= 1.0f)
	{
		rtn_t1 = t1;
		return 1;
	}
	else if (t2 >= 0.0f && t2 <= 1.0f)
	{
		rtn_t1 = t2;
		return 1;
	}
	
	return 0;
}
开发者ID:Akranar,项目名称:daguerreo,代码行数:30,代码来源:BPT_IntersectingLineRaysSegments.cpp

示例3: IntersectingRayAgainstSphere

bool BasicPrimitiveTests::IntersectingRayAgainstSphere(const Ray & ray, const BoundingSphere & sphere, float & rtn_t)
{
	/*
		Main idea:
            - Ray is substituted into sphere equation. Then solve quadratic formula for intersection.
                - Test if intersection is within segment/ray endpoints

        -> Use dot(X-C, X-C) = exp(r, 2)
            -> As sphere equation.

        Solving for "t":
            -> Quadratic equation in "t" encountered.
                    -> where b = dot(m, d)
                    -> where c = dot(m, m) - r*r
						-> where m = P-C
                -> t = -b + sqrt(exp(b, 2) - c)
                -> t = -b - sqrt(exp(b, 2) - c)

        Notes:
            -> Number of real roots => number of intersections:
                -> Categorized by discriminant d = exp(b, 2) - c

            -> May have false intersection with t < 0 when ray starts from inside sphere.
	*/
	
	Eigen::Vector3f m = ray.GetOrigin() - sphere.GetCenter();
	float b = (m).dot(ray.GetDirection());
	float c = m.dot(m);
	if (c > 0.0f && b > 0.0f)
	{
		//Case: Ray origin outside of sphere and points away. => No Intersections.
		return false;
	}
	float discriminant = b * b - c;
	if (discriminant < 0.0f)
	{
		//Case: Misses sphere
		return false;
	}
	else
	{
		//Case: Hits sphere. Calculate smallest t.
		rtn_t = -b - sqrt(discriminant);
		if (rtn_t < 0.0f)
		{
			rtn_t = 0.0f;
		}
		return true;
	}
	
}
开发者ID:Akranar,项目名称:daguerreo,代码行数:51,代码来源:BPT_IntersectingLineRaysSegments.cpp

示例4: yAxis

BoundingCone::BoundingCone(const BoundingBox& box, const D3DXMATRIX& projection, const D3DXVECTOR3& apex)
{
	const D3DXVECTOR3 yAxis(0.f, 1.f, 0.f);
    const D3DXVECTOR3 zAxis(0.f, 0.f, 1.f);
    const D3DXVECTOR3 negZAxis(0.f, 0.f, -1.f);

    //  compute a tight bounding sphere for the vertices of the bounding boxes.
    //  the vector from the apex to the center of the sphere is the optimized view direction
    //  start by xforming all points to post-projective space
    D3DXVECTOR3 ppPts[ box.CornerCount ];
	box.GetCorners( ppPts );

	for( int index=0; index<box.CornerCount; index++)
    {
        D3DXVec3TransformCoord( &ppPts[index], &ppPts[index], &projection );
    }

    //  get minimum bounding sphere
	BoundingSphere bSphere = BoundingSphere::CreateFromPoints( ppPts,box.CornerCount );

    float min_cosTheta = 1.f;
    
    m_direction = bSphere.GetCenter() - apex;
    D3DXVec3Normalize(&m_direction, &m_direction);

    D3DXVECTOR3 axis = yAxis;

    if( fabsf(D3DXVec3Dot(&yAxis, &m_direction)) > 0.99f )
	{
        axis = zAxis;
	}

    D3DXMatrixLookAtLH(&m_lookAt, &apex, &(apex+m_direction), &axis);

    m_near = 1e32f;
    m_far = 0.f;

    float maxx=0.f, maxy=0.f;
    for( int index=0; index<box.CornerCount; index++ )
    {
        D3DXVECTOR3 tmp;
        D3DXVec3TransformCoord(&tmp, &ppPts[index], &m_lookAt);
        maxx = max(maxx, fabsf(tmp.x / tmp.z));
        maxy = max(maxy, fabsf(tmp.y / tmp.z));
        m_near = min(m_near, tmp.z);
        m_far  = max(m_far, tmp.z);
    }

    m_fovx = atanf(maxx);
	m_fovy = atanf(maxy);
}
开发者ID:ZeusAFK,项目名称:MikuMikuGameEngine,代码行数:51,代码来源:BoundingCone.cpp

示例5: IntersectBoundingSphere

IntersectData BoundingSphere::IntersectBoundingSphere(const BoundingSphere& other) const
{
	//The radius is the distance from any point on the sphere to the center.
	//
	//Therefore, by adding the radius of two spheres together, the result is
	//the distance between the centers of the spheres when they are touching.
	float radiusDistance = m_radius + other.GetRadius();
	float centerDistance = (other.GetCenter() - m_center).Length();

	//Since the radiusDistance is the distance bwteen the centers of the 
	//spheres are when they're touching, you can subtract that from the
	//distance between the centers of the spheres to get the actual distance
	//between the two spheres.
	float distance = centerDistance - radiusDistance;

	//Spheres can only be intersecting if the distance between them is less
	//than 0.
	return IntersectData(distance < 0, distance);
}
开发者ID:IAmYourSerperior,项目名称:3DEngineCpp,代码行数:19,代码来源:boundingSphere.cpp

示例6: IntersectSphere

IntersectData Plane::IntersectSphere(const BoundingSphere& other) const
{
	//Calculating the dot product between the Plane's normal and the Sphere's 
	//center gets how far the sphere's center is along the Plane's normal.
	//
	//Adding the distance adjusts this value based on how far the Plane itself
	//is along the normal.
	//
	//The end result of this is how far the Sphere's center is from the Plane.
	//The absolute value is taken so that this result is always positive.
	float distanceFromSphereCenter = 
		(float)fabs(m_normal.Dot(other.GetCenter()) + m_distance);

	//As long as the distanceFromSphereCenter is valid and positive, then
	//the distance from the sphere can be calculated simply by subtracting
	//it's radius.
	float distanceFromSphere = distanceFromSphereCenter - other.GetRadius();

	//The only time the plane can be intersecting the sphere is if the sphere
	//has less than 0 distance from the plane. Otherwise, if there is distance
	//between the plane and sphere, then there must be a gap between the
	//plane and sphere, and they cannot be intersecting.
	return IntersectData(distanceFromSphere < 0, m_normal * distanceFromSphere);
}
开发者ID:MrShedman,项目名称:GL-Dev,代码行数:24,代码来源:plane.cpp


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