本文整理汇总了C++中Ball::Collide2DWall方法的典型用法代码示例。如果您正苦于以下问题:C++ Ball::Collide2DWall方法的具体用法?C++ Ball::Collide2DWall怎么用?C++ Ball::Collide2DWall使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ball
的用法示例。
在下文中一共展示了Ball::Collide2DWall方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Collide
void LineSegSlingshot::Collide(CollisionEvent* coll)
{
Ball *pball = coll->ball;
const Vertex3Ds& hitnormal = coll->hitnormal;
const float dot = pball->m_vel.x * hitnormal.x + pball->m_vel.y * hitnormal.y; // normal velocity to slingshot
const bool threshold = (dot <= -m_psurface->m_d.m_slingshot_threshold); // normal greater than threshold?
if (!m_psurface->m_fDisabled && threshold) // enabled and if velocity greater than threshold level
{
const float len = (v2.x - v1.x)*hitnormal.y - (v2.y - v1.y)*hitnormal.x; // length of segment, Unit TAN points from V1 to V2
const Vertex2D vhitpoint(pball->m_pos.x - hitnormal.x * pball->m_radius, //project ball radius along norm
pball->m_pos.y - hitnormal.y * pball->m_radius);
// vhitpoint will now be the point where the ball hits the line
// Calculate this distance from the center of the slingshot to get force
const float btd = (vhitpoint.x - v1.x)*hitnormal.y - (vhitpoint.y - v1.y)*hitnormal.x; // distance to vhit from V1
float force = (len != 0.0f) ? ((btd+btd)/len - 1.0f) : -1.0f; // -1..+1
force = 0.5f *(1.0f-force*force); //!! maximum value 0.5 ...I think this should have been 1.0...oh well
// will match the previous physics
force *= m_force;//-80;
pball->m_vel.x -= hitnormal.x * force; // boost velocity, drive into slingshot (counter normal)
pball->m_vel.y -= hitnormal.y * force; // allow CollideWall to handle the remainder
}
pball->Collide2DWall(hitnormal, m_elasticity, m_elasticityFalloff, m_friction, m_scatter);
if (m_pfe && !m_psurface->m_fDisabled && threshold)
{
// is this the same place as last event? if same then ignore it
const Vertex3Ds dist = pball->m_Event_Pos - pball->m_pos;
pball->m_Event_Pos = pball->m_pos; //remember last collide position
if (dist.LengthSquared() > 0.25f) // must be a new place if only by a little
{
m_pfe->FireGroupEvent(DISPID_SurfaceEvents_Slingshot);
m_slingshotanim.m_TimeReset = g_pplayer->m_time_msec + 100;
}
}
}