本文整理汇总了C++中Point2f::reset方法的典型用法代码示例。如果您正苦于以下问题:C++ Point2f::reset方法的具体用法?C++ Point2f::reset怎么用?C++ Point2f::reset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Point2f
的用法示例。
在下文中一共展示了Point2f::reset方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: polyPegCollision_p
//.........这里部分代码省略.........
rebound._x = normal._x;
rebound._y = normal._y;
}
}
}
//if Edge don't collision and check corner collision
if(collisionDist == INFINITY)
{
for(int i = 0; i < subs; i++)
{
Point2f cornerToBall;
cornerToBall = trans - vertices[i];
cornerDist = cornerToBall.magnitude() - ball.radius;
if(cornerDist < collisionDist)
{
cornerIndex = i;
nextCornerIndex = i + 1;
if(i == 0)
prevCornerIndex = subs - 1;
else
prevCornerIndex = i - 1;
collisionDist = cornerDist;
cornerToBall.normalize();
rebound._x = cornerToBall._x;
rebound._y = cornerToBall._y;
//calculate cornerNomral_1 and cornerNomral_2
if(dotProduct(rebound, transVel) > 0.0)
{
//check a segment line from current corner and previous corner
cornerNormal_1 = vertices[cornerIndex] - vertices[prevCornerIndex];
cornerNormal_1.normalize();
//check a segment line from current corner and next corner
cornerNormal_2 = vertices[cornerIndex] - vertices[nextCornerIndex];
cornerNormal_2.normalize();
if(dotProduct(cornerNormal_1, transVel) < 0.0)
{
rebound = cornerNormal_1;
}
else if(dotProduct(cornerNormal_2, transVel) < 0.0)
{
rebound = cornerNormal_2;
}
else
{
rebound.reset();
collisionDist = INFINITY;
}
}
}
}
//normalize rebound
rebound.normalize();
}
if(collisionDist > 0.0f)
{
return false;
}
else
{
//calcuate component that gets mirrored
orthogBallVelMag= dotProduct(rebound, transVel);
transVel._x -= 2.0f * orthogBallVelMag * rebound._x;
transVel._y -= 2.0f * orthogBallVelMag * rebound._y;
//calculate transVelocity
transPolyVelDotReb = dotProduct(rebound, transPegPolyVel);
transVel._x += transPolyVelDotReb * rebound._x;
transVel._y += transPolyVelDotReb * rebound._y;
//setting ball's velocity with new velocity
ball.velocity_p._x = cosf(rotation) * transVel._x - sinf(rotation) * transVel._y;
ball.velocity_p._y = sin(rotation) * transVel._x + cosf(rotation) * transVel._y;
//relocation ball
trans._x -= 2.0 * collisionDist * rebound._x;
trans._y -= 2.0 * collisionDist * rebound._y;
orig._x = cosf(rotation) * trans._x - sinf(rotation) * trans._y;
orig._y = sinf(rotation) * trans._x + cosf(rotation) * trans._y;
ball.position_p = orig + position;
return true;
}
}
示例2: polyPegCollision
//.........这里部分代码省略.........
cornerDist = cornerToBall.magnitude() - ball.radius;
if(cornerDist < collisionDist)
{
cornerIndex = i;
nextCornerIndex = i + 1;
if(i == 0)
prevCornerIndex = subs - 1;
else
prevCornerIndex = i - 1;
collisionDist = cornerDist;
cornerToBall.normalize();
rebound._x = cornerToBall._x;
rebound._y = cornerToBall._y;
//calculate cornerNomral_1 and cornerNomral_2
if(dotProduct(rebound, transVel) > 0.0)
{
//check a segment line from current corner and previous corner
cornerNormal_1 = vertices[cornerIndex] - vertices[prevCornerIndex];
cornerNormal_1.normalize();
//check a segment line from current corner and next corner
cornerNormal_2 = vertices[cornerIndex] - vertices[nextCornerIndex];
cornerNormal_2.normalize();
if(dotProduct(cornerNormal_1, transVel) < 0.0)
{
rebound = cornerNormal_1;
}
else if(dotProduct(cornerNormal_2, transVel) < 0.0)
{
rebound = cornerNormal_2;
}
else
{
rebound.reset();
collisionDist = INFINITY;
}
}
}
}
//normalize rebound
rebound.normalize();
//visual Debug Mode
if(visualDebug)
{
glPushMatrix();
glTranslatef(position.getX(), position.getY(), 0.0);
glRotatef(180.0f * rotation / PI_F, 0.0f, 0.0f, 1.0f);
glColor3f(1,0,0);
glPointSize(3);
glBegin(GL_POINTS);
glVertex2f(
vertices[cornerIndex]._x,
vertices[cornerIndex]._y);
glEnd();
glPopMatrix();
}
}
if(collisionDist > 0.0f)
{
return false;
}
else
{
//calcuate component that gets mirrored
orthogBallVelMag= dotProduct(rebound, transVel);
transVel._x -= 2.0f * orthogBallVelMag * rebound._x;
transVel._y -= 2.0f * orthogBallVelMag * rebound._y;
//calculate transVelocity
transPolyVelDotReb = dotProduct(rebound, transPegPolyVel);
transVel._x += transPolyVelDotReb * rebound._x;
transVel._y += transPolyVelDotReb * rebound._y;
//setting ball's velocity with new velocity
ball.velocity._x = cosf(rotation) * transVel._x - sinf(rotation) * transVel._y;
ball.velocity._y = sin(rotation) * transVel._x + cosf(rotation) * transVel._y;
//relocation ball
trans._x -= 2.0 * collisionDist * rebound._x;
trans._y -= 2.0 * collisionDist * rebound._y;
orig._x = cosf(rotation) * trans._x - sinf(rotation) * trans._y;
orig._y = sinf(rotation) * trans._x + cosf(rotation) * trans._y;
ball.position = orig + position;
return true;
}
}