void Hit3DPoly::Collide(const CollisionEvent& coll) { Ball * const pball = coll.m_ball; const Vertex3Ds& hitnormal = coll.m_hitnormal; if (m_ObjType != eTrigger) { const float dot = -(hitnormal.Dot(pball->m_vel)); pball->Collide3DWall(m_normal, m_elasticity, m_elasticityFalloff, m_friction, m_scatter); if (m_obj && m_fe && dot >= m_threshold) { if (m_ObjType == ePrimitive) { m_obj->m_currentHitThreshold = dot; FireHitEvent(pball); } else if (m_ObjType == eHitTarget && ((HitTarget*)m_obj)->m_d.m_isDropped == false) { ((HitTarget*)m_obj)->m_hitEvent = true; m_obj->m_currentHitThreshold = dot; FireHitEvent(pball); } } } else // trigger: { if (!pball->m_vpVolObjs) return; const int i = FindIndexOf(*(pball->m_vpVolObjs), m_obj); // if -1 then not in objects volume set (i.e not already hit) if ((!coll.m_hitflag) == (i < 0)) // Hit == NotAlreadyHit { pball->m_pos += STATICTIME * pball->m_vel; //move ball slightly forward if (i < 0) { pball->m_vpVolObjs->push_back(m_obj); ((Trigger*)m_obj)->FireGroupEvent(DISPID_HitEvents_Hit); } else { pball->m_vpVolObjs->erase(pball->m_vpVolObjs->begin() + i); ((Trigger*)m_obj)->FireGroupEvent(DISPID_HitEvents_Unhit); } } } }
void HitGate::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; if (dot > 0.0f && !m_twoWay) return; //hit from back doesn't count const float h = m_pgate->m_d.m_height; //linear speed = ball speed //angular speed = linear/radius (height of hit) // h is the height of the gate axis. m_gateanim.m_anglespeed = fabsf(dot); // use this until a better value comes along if (fabsf(h - pball->m_radius) > 1.0f) // avoid divide by zero m_gateanim.m_anglespeed /= h - pball->m_radius; // We encoded which side of the spinner the ball hit if (coll->hitvelocity.x==0.0f && m_twoWay) m_gateanim.m_anglespeed = -m_gateanim.m_anglespeed; FireHitEvent(pball); }
void HitGate::Collide(const CollisionEvent& coll) { Ball * const pball = coll.m_ball; const Vertex3Ds& hitnormal = coll.m_hitnormal; const float dot = coll.m_hitnormal.Dot(coll.m_ball->m_vel); const float h = m_pgate->m_d.m_height*0.5f; //linear speed = ball speed //angular speed = linear/radius (height of hit) float speed = fabsf(dot); // h is the height of the gate axis. if (fabsf(h) > 1.0f) // avoid divide by zero speed /= h; m_gateMover.m_anglespeed = speed; if (!coll.m_hitflag && !m_twoWay) { m_gateMover.m_anglespeed *= (float)(1.0/8.0); // Give a little bounce-back. return; // hit from back doesn't count if not two-way } // We encoded which side of the spinner the ball hit if (coll.m_hitflag && m_twoWay) m_gateMover.m_anglespeed = -m_gateMover.m_anglespeed; FireHitEvent(pball); }
void HitPoint::Collide(CollisionEvent *coll) { const float dot = coll->hitnormal.Dot(coll->ball->m_vel); coll->ball->Collide3DWall(coll->hitnormal, m_elasticity, m_elasticityFalloff, m_friction, m_scatter); if (dot <= -m_threshold) FireHitEvent(coll->ball); }
void LineSeg::Collide(CollisionEvent *coll) { const float dot = coll->hitnormal.x * coll->ball->m_vel.x + coll->hitnormal.y * coll->ball->m_vel.y; coll->ball->Collide2DWall(coll->hitnormal, m_elasticity, m_elasticityFalloff, m_friction, m_scatter); if (dot <= -m_threshold) FireHitEvent(coll->ball); }
void HitLine3D::Collide(CollisionEvent* coll) { Ball *pball = coll->ball; const Vertex3Ds& hitnormal = coll->hitnormal; const float dot = hitnormal.Dot(pball->m_vel); pball->Collide3DWall(hitnormal, m_elasticity, m_elasticityFalloff, m_friction, m_scatter); if (m_ObjType == ePrimitive && dot <= -m_threshold) FireHitEvent(pball); }
void HitLine3D::Collide(const CollisionEvent& coll) { Ball *const pball = coll.m_ball; const Vertex3Ds& hitnormal = coll.m_hitnormal; const float dot = -(hitnormal.Dot(pball->m_vel)); pball->Collide3DWall(hitnormal, m_elasticity, m_elasticityFalloff, m_friction, m_scatter); if (m_obj && m_fe && dot >= m_threshold) { if (m_ObjType == ePrimitive) { m_obj->m_currentHitThreshold = dot; FireHitEvent(pball); } else if (m_ObjType == eHitTarget && ((HitTarget*)m_obj)->m_d.m_isDropped == false) { ((HitTarget*)m_obj)->m_hitEvent = true; m_obj->m_currentHitThreshold = dot; FireHitEvent(pball); } } }
void Hit3DPoly::Collide(CollisionEvent *coll) { Ball *pball = coll->ball; const Vertex3Ds& hitnormal = coll->hitnormal; if (m_ObjType != eTrigger) { const float dot = hitnormal.x * pball->m_vel.x + hitnormal.y * pball->m_vel.y; pball->Collide3DWall(normal, m_elasticity, m_elasticityFalloff, m_friction, m_scatter); if (m_ObjType == ePrimitive && dot <= -m_threshold) FireHitEvent(pball); } else { if (!pball->m_vpVolObjs) return; const int i = pball->m_vpVolObjs->IndexOf(m_pObj); // if -1 then not in objects volume set (i.e not already hit) if ((coll->hitvelocity.x != 1.0f) == (i < 0)) // Hit == NotAlreadyHit { pball->m_pos += STATICTIME * pball->m_vel; //move ball slightly forward if (i < 0) { pball->m_vpVolObjs->AddElement(m_pObj); ((Trigger*)m_pObj)->FireGroupEvent(DISPID_HitEvents_Hit); } else { pball->m_vpVolObjs->RemoveElementAt(i); ((Trigger*)m_pObj)->FireGroupEvent(DISPID_HitEvents_Unhit); } } } }