Exemple #1
0
void b2Body::SetType(b2BodyType type)
{
    b2Assert(m_world->IsLocked() == false);
    if (m_world->IsLocked() == true)
    {
        return;
    }

    if (m_type == type)
    {
        return;
    }

    m_type = type;

    ResetMassData();

    if (m_type == b2_staticBody)
    {
        m_linearVelocity.SetZero();
        m_angularVelocity = 0.0f;
        m_sweep.a0 = m_sweep.a;
        m_sweep.c0 = m_sweep.c;
        SynchronizeFixtures();
    }

    SetAwake(true);

    m_force.SetZero();
    m_torque = 0.0f;

    // Delete the attached contacts.
    b2ContactEdge* ce = m_contactList;
    while (ce)
    {
        b2ContactEdge* ce0 = ce;
        ce = ce->next;
        m_world->m_contactManager.Destroy(ce0->contact);
    }
    m_contactList = NULL;

    // Touch the proxies so that new contacts will be created (when appropriate)
    b2BroadPhase* broadPhase = &m_world->m_contactManager.m_broadPhase;
    for (b2Fixture* f = m_fixtureList; f; f = f->m_next)
    {
        int32 proxyCount = f->m_proxyCount;
        for (int32 i = 0; i < proxyCount; ++i)
        {
            broadPhase->TouchProxy(f->m_proxies[i].proxyId);
        }
    }
}
Exemple #2
0
inline void Body::SetAngularVelocity(float32 w)
{
	if (m_type == staticBody)
	{
		return;
	}

	if (w * w > 0.0f)
	{
		SetAwake(true);
	}

	m_angularVelocity = w;
}
Exemple #3
0
inline void Body::SetLinearVelocity(const Vec2& v)
{
	if (m_type == staticBody)
	{
		return;
	}

	if (Dot(v,v) > 0.0f)
	{
		SetAwake(true);
	}

	m_linearVelocity = v;
}
Exemple #4
0
inline void Body::ApplyAngularImpulse(float32 impulse, bool wake)
{
	if (m_type != dynamicBody)
	{
		return;
	}

	if (wake && (m_flags & e_awakeFlag) == 0)
	{
		SetAwake(true);
	}

	// Don't accumulate velocity if the body is sleeping
	if (m_flags & e_awakeFlag)
	{
		m_angularVelocity += m_invI * impulse;
	}
}
Exemple #5
0
inline void Body::ApplyTorque(float32 torque, bool wake)
{
	if (m_type != dynamicBody)
	{
		return;
	}

	if (wake && (m_flags & e_awakeFlag) == 0)
	{
		SetAwake(true);
	}

	// Don't accumulate a force if the body is sleeping
	if (m_flags & e_awakeFlag)
	{
		m_torque += torque;
	}
}
Exemple #6
0
inline void Body::ApplyForceToCenter(const Vec2& force, bool wake)
{
	if (m_type != dynamicBody)
	{
		return;
	}

	if (wake && (m_flags & e_awakeFlag) == 0)
	{
		SetAwake(true);
	}

	// Don't accumulate a force if the body is sleeping
	if (m_flags & e_awakeFlag)
	{
		m_force += force;
	}
}
Exemple #7
0
inline void Body::ApplyLinearImpulse(const Vec2& impulse, const Vec2& point, bool wake)
{
	if (m_type != dynamicBody)
	{
		return;
	}

	if (wake && (m_flags & e_awakeFlag) == 0)
	{
		SetAwake(true);
	}

	// Don't accumulate velocity if the body is sleeping
	if (m_flags & e_awakeFlag)
	{
		m_linearVelocity += m_invMass * impulse;
		m_angularVelocity += m_invI * Cross(point - m_sweep.c, impulse);
	}
}
Exemple #8
0
inline void Body::ApplyForce(const Vec2& force, const Vec2& point, bool wake)
{
	if (m_type != dynamicBody)
	{
		return;
	}

	if (wake && (m_flags & e_awakeFlag) == 0)
	{
		SetAwake(true);
	}

	// Don't accumulate a force if the body is sleeping.
	if (m_flags & e_awakeFlag)
	{
		m_force += force;
		m_torque += Cross(point - m_sweep.c, force);
	}
}
Exemple #9
0
void b2Body::SetType(b2BodyType type)
{
  b2Assert(m_world->IsLocked() == false);
  if (m_world->IsLocked() == true)
  {
    return;
  }

  if (m_type == type)
  {
    return;
  }

  m_type = type;

  ResetMassData();

  if (m_type == b2_staticBody)
  {
    m_linearVelocity.SetZero();
    m_angularVelocity = 0.0f;
    m_sweep.a0 = m_sweep.a;
    m_sweep.c0 = m_sweep.c;
    SynchronizeFixtures();
  }

  SetAwake(true);

  m_force.SetZero();
  m_torque = 0.0f;

  // Since the body type changed, we need to flag contacts for filtering.
  for (b2Fixture* f = m_fixtureList; f; f = f->m_next)
  {
    f->Refilter();
  }
}