本文整理汇总了C++中Sphere::getY方法的典型用法代码示例。如果您正苦于以下问题:C++ Sphere::getY方法的具体用法?C++ Sphere::getY怎么用?C++ Sphere::getY使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sphere
的用法示例。
在下文中一共展示了Sphere::getY方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: collision
bool Frustum::collision(const CollisionObject * pCollisionObject, bool calculateNormal)
{
calculateNormal;
if(pCollisionObject->getCollisionType()==CollisionType_Sphere)
{
Sphere * pSphere = (Sphere*) pCollisionObject;
float x = pSphere->getX();
float y = pSphere->getY();
float z = pSphere->getZ();
float r = pSphere->getR();
for(int i=0;i<6;i++)
{
if(mPlanes[i].a * x + mPlanes[i].b * y + mPlanes[i].c * z + mPlanes[i].d <= -r)
{
return false;
}
}
return true;
}
else if(pCollisionObject->getCollisionType()==CollisionType_AABB)
{
AABB * pAABB = (AABB*) pCollisionObject;
for(unsigned int j=0;j<6;j++)
{
unsigned int cornersInside = 8;
for(unsigned int i=0;i<8;i++)
{
D3DXVECTOR3 corner = pAABB->getCorner(i);
/*
if(mPlanes[j].a * corner.x + mPlanes[j].b * corner.y + mPlanes[j].c * corner.z + mPlanes[j].d <= 0)
{
cornersInside--;
}
*/
if(D3DXPlaneDotNormal(&mPlanes[j], &corner) + mPlanes[j].d <= 0)
{
cornersInside--;
}
}
if(cornersInside==0)
{
return false;
}
}
return true;
}
if(pCollisionObject->getCollisionType()==CollisionType_OBB)
{
OBB * pOBB = (OBB*)pCollisionObject;
for(unsigned int j=0;j<6;j++)
{
unsigned int cornersInside = 8;
for(unsigned int i=0; i<8; i++)
{
D3DXVECTOR3 corner = pOBB->getCorner(i);
if(D3DXPlaneDotNormal(&mPlanes[j], &corner) + mPlanes[j].d <= 0)
{
cornersInside--;
}
}
if(cornersInside==0)
{
return false;
}
}
return true;
}
return false;
}
示例2: collision
//.........这里部分代码省略.........
}
}
if(max1 < min2 || max2 < min1)
{
return false;
}
}
if(calculateNormal)
{
setCollisionNormal(pAABB->getCenter() - mCenter);
pAABB->setCollisionNormal(mCenter - pAABB->getCenter());
}
return true;
}
else if(pCollisionObject->getCollisionType()==CollisionType_Sphere)
{
Sphere * pSphere = (Sphere*) pCollisionObject;
for(int aIndex=0;aIndex<3;aIndex++)
{
float min1 = 1000000;
float max1 = -1000000;
float min2 = 1000000;
float max2 = -1000000;
for(int cIndex=0;cIndex<8;cIndex++)
{
float pos = mAxis[aIndex].x * mCorners[cIndex].x + mAxis[aIndex].y * mCorners[cIndex].y + mAxis[aIndex].z * mCorners[cIndex].z;
if(pos < min1)
{
min1 = pos;
}
else if(pos > max1)
{
max1 = pos;
}
}
min2 = mAxis[aIndex].x * pSphere->getX() + mAxis[aIndex].y * pSphere->getY() + mAxis[aIndex].z * pSphere->getZ() - pSphere->getR();
max2 = mAxis[aIndex].x * pSphere->getX() + mAxis[aIndex].y * pSphere->getY() + mAxis[aIndex].z * pSphere->getZ() + pSphere->getR();
if(max1 < min2 || min1 > max2)
{
return false;
}
}
D3DXVECTOR3 obbToSphere = D3DXVECTOR3(pSphere->getX(),pSphere->getY(),pSphere->getZ());
obbToSphere -= mCenter;
float length = obbToSphere.x * obbToSphere.x + obbToSphere.y * obbToSphere.y + obbToSphere.z * obbToSphere.z;
length = sqrt(length);
obbToSphere /= length;
float min1 = 1000000;
float max1 = -1000000;
float min2 = 1000000;
float max2 = -1000000;
for(int cIndex=0;cIndex<8;cIndex++)
{
float pos = obbToSphere.x * mCorners[cIndex].x + obbToSphere.y * mCorners[cIndex].y + obbToSphere.z * mCorners[cIndex].z;
if(pos < min1)
{
min1 = pos;
}
else if(pos > max1)
{
max1 = pos;
}
}
min2 = obbToSphere.x * pSphere->getX() + obbToSphere.y * pSphere->getY() + obbToSphere.z * pSphere->getZ() - pSphere->getR();
max2 = obbToSphere.x * pSphere->getX() + obbToSphere.y * pSphere->getY() + obbToSphere.z * pSphere->getZ() + pSphere->getR();
if(max1 < min2 || min1 > max2)
{
return false;
}
if(calculateNormal)
{
D3DXVECTOR3 sphereCenter = D3DXVECTOR3(pSphere->getX(), pSphere->getY(), pSphere->getZ());
setCollisionNormal(sphereCenter - mCenter);
pSphere->setCollisionNormal(mCenter - sphereCenter);
}
return true;
}
return false;
}