#pragma once
#include "Stdafx.h"
#include "Vector.cpp"
#include "Shape.cpp"
#include "ShapeDef.cpp"
namespace Box2D
{
namespace Net
{
///
/// A rigid body. Internal computation are done in terms
/// of the center of mass position. The center of mass may
/// be offset from the body's origin.
///
public ref class Body
{
internal:
b2Body *body;
Body(b2Body *bodyRef) : body(bodyRef) { }
public:
///
/// Set the position of the body's origin and rotation (radians).
/// This breaks any contacts and wakes the other bodies.
///
void SetXForm(Vector^ position, float32 rotation)
{
body->SetXForm(position->getVec2(), rotation);
}
///
/// Get the position of the body's origin. The body's origin does not
/// necessarily coincide with the center of mass. It depends on how the
/// shapes are created.
///
XForm^ GetXForm()
{
return gcnew XForm(body->GetXForm());
}
///Accesses the linear velocity of the center of mass.
property Vector^ LinearVelocity
{
Vector^ get()
{
return gcnew Vector(body->GetLinearVelocity());
}
void set(Vector^ value)
{
body->SetLinearVelocity(value->getVec2());
}
}
///Accesses the angular velocity.
property float32 AngularVelocity
{
float32 get()
{
return body->GetAngularVelocity();
}
void set(float32 value)
{
body->SetAngularVelocity(value);
}
}
/// Apply a force at a world point. Additive.
void ApplyForce(Vector^ Force, Vector^ Point)
{
body->ApplyForce(Force->getVec2(), Point->getVec2());
}
/// Apply a torque. Additive.
void ApplyTorque(float32 Torque)
{
body->ApplyTorque(Torque);
}
/// Apply an impulse at a point. This immediately modifies the velocity.
void ApplyImpulse(Vector^ Impulse, Vector^ Point)
{
body->ApplyImpulse(Impulse->getVec2(), Point->getVec2());
}
///Accesses the Mass.
property float32 Mass
{
float32 get()
{
return body->GetMass();
}
}
///Accesses the Mass.
property float32 Inertia
{
float32 get()
{
return body->GetInertia();
}
}
///
/// Get the world coordinates of a point give the local coordinates
/// relative to the body's center of mass.
///
Vector^ GetWorldPoint(Vector^ LocalPoint)
{
return gcnew Vector(body->GetWorldPoint(LocalPoint->getVec2()));
}
///
/// Get the world coordinates of a vector given the local coordinates.
///
Vector^ GetWorldVector(Vector^ LocalVector)
{
return gcnew Vector(body->GetWorldVector(LocalVector->getVec2()));
}
///
/// Returns a local point relative to the center of mass given a world point.
///
Vector^ GetLocalPoint(Vector^ WorldPoint)
{
return gcnew Vector(body->GetLocalPoint(WorldPoint->getVec2()));
}
///
/// Returns a local vector given a world vector.
///
Vector^ GetLocalVector(Vector^ WorldVector)
{
return gcnew Vector(body->GetLocalVector(WorldVector->getVec2()));
}
///Is this body static (immovable)
property bool Static
{
bool get()
{
return body->IsStatic();
}
}
///Is this body frozen
property bool Frozen
{
bool get()
{
return body->IsFrozen();
}
}
///Is this body sleeping
property bool Sleeping
{
bool get()
{
return body->IsSleeping();
}
}
///You can disable sleeping on this particular body.
property bool AllowSleeping
{
bool get()
{
return body->IsSleeping();
}
void set(bool value)
{
body->AllowSleeping(value);
}
}
property bool Bullet
{
bool get()
{
return body->IsBullet();
}
void set(bool value)
{
body->SetBullet(value);
}
}
void WakeUp()
{
body->WakeUp();
}
/// Get the list of all shapes attached to this body.
property IList^ Shapes
{
IList^ get()
{
List^ list = gcnew List();
for(b2Shape *shape = body->GetShapeList(); shape; shape = shape->GetNext())
list->Add(gcnew Shape(shape));
return list;
}
}
void CreateShape(ShapeDef^ def)
{
body->CreateShape(def->def);
}
void DestroyShape(Shape^ shape)
{
body->DestroyShape(shape->shape);
}
void SetMassFromShapes()
{
body->SetMassFromShapes();
}
//TODO:
//void* GetUserData();
//const b2Mat22& GetRotationMatrix() const;
};
}
}
/*
TODO:
public:
// Get the list of all contacts attached to this body.
b2ContactNode* GetContactList();
// Get the list of all joints attached to this body.
b2JointNode* GetJointList();
*/