コード例 #1
0
ファイル: b2Body.cpp プロジェクト: leosurwiki/protectcarrot
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);
        }
    }
}
コード例 #2
0
ファイル: Body.hpp プロジェクト: ZhuangChun/Box2D
inline void Body::SetAngularVelocity(float32 w)
{
	if (m_type == staticBody)
	{
		return;
	}

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

	m_angularVelocity = w;
}
コード例 #3
0
ファイル: Body.hpp プロジェクト: ZhuangChun/Box2D
inline void Body::SetLinearVelocity(const Vec2& v)
{
	if (m_type == staticBody)
	{
		return;
	}

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

	m_linearVelocity = v;
}
コード例 #4
0
ファイル: Body.hpp プロジェクト: ZhuangChun/Box2D
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;
	}
}
コード例 #5
0
ファイル: Body.hpp プロジェクト: ZhuangChun/Box2D
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;
	}
}
コード例 #6
0
ファイル: Body.hpp プロジェクト: ZhuangChun/Box2D
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;
	}
}
コード例 #7
0
ファイル: Body.hpp プロジェクト: ZhuangChun/Box2D
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);
	}
}
コード例 #8
0
ファイル: Body.hpp プロジェクト: ZhuangChun/Box2D
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);
	}
}
コード例 #9
0
ファイル: b2Body.cpp プロジェクト: KRSSG/robocupssl_old
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();
  }
}