void CGolfer::Throw() { CPlayer* p=(CPlayer*)parent; D3DMATRIX m; D3DVECTOR v=D3DVECTOR(0,0,2); D3DUtil_SetRotateYMatrix(m,-p->ang.y); D3DMath_VectorMatrixMultiply(v,v,m); pos=p->pos+v; if (!world->IsInside(pos))world->MakeInside(pos); pos.y=world->HeightAtPoint(pos.x,pos.z); box->SetPos(pos); CObject* akt=chain->GetFirst(); while (akt) { if (GetType(akt->id)==IDStall) { Rebound(((CStall*)akt)->box); Rebound(((CStall*)akt)->eingang); } if (GetType(akt->id)==IDTree) Rebound(((CTree*)akt)->box); if (GetType(akt->id)==IDDrescher) Rebound(((CDrescher*)akt)->box2); akt=akt->next; } schlag.phase=0.0f; parent=NULL; ejecttime=3.0f; }
void PhysicalObj::Collide(collision_t collision, PhysicalObj* collided_obj, const Point2d& position) { Point2d contactPos; Double contactAngle; switch (collision) { case NO_COLLISION: // Nothing more to do! return; case COLLISION_ON_GROUND: ContactPointAngleOnGround(position, contactPos, contactAngle); ASSERT(!collided_obj); break; case COLLISION_ON_OBJECT: contactPos = position; contactAngle = - GetSpeedAngle(); // Compute the new speed norm of this and collided_obj, new speed angle will be set // thanks to Rebound() // Get the current speed Double v1, v2, mass1, angle1, angle2, mass2; collided_obj->GetSpeed(v1, angle1); GetSpeed(v2, angle2); mass1 = GetMass(); mass2 = collided_obj->GetMass(); // Give speed to the other object // thanks to physic and calculations about chocs, we know that : // // v'1 = ((m1 - m2) * v1 + 2m1 *v2) / (m1 + m2) // v'2 = ((m2 - m1) * v2 + 2m1 *v1) / (m1 + m2) collided_obj->SetSpeed(abs(((mass1 - mass2) * v1 + 2 * mass1 *v2 * m_cfg.m_rebound_factor) / (mass1 + mass2)), angle1); SetSpeed(abs(((mass2 - mass1) * v2 + 2 * mass1 *v1 * m_cfg.m_rebound_factor) / (mass1 + mass2)), angle2); break; } // Mark it as last collided object m_last_collided_object = collided_obj; // Make it rebound!! MSG_DEBUG("physic.state", "%s rebounds at %.3f,%.3f", GetName().c_str(), contactPos.x.tofloat(), contactPos.y.tofloat()); Rebound(contactPos, contactAngle); CheckRebound(); }