1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
|
#pragma once
#include "Stdafx.h"
#include "Vector.cpp"
#include "Shape.cpp"
#include "ShapeDef.cpp"
namespace Box2D
{
namespace Net
{
/// <summary>
/// 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.
/// </summary>
public ref class Body
{
internal:
b2Body *body;
Body(b2Body *bodyRef) : body(bodyRef) { }
public:
/// <summary>
/// Set the position of the body's origin and rotation (radians).
/// This breaks any contacts and wakes the other bodies.
/// </summary>
void SetXForm(Vector^ position, float32 rotation)
{
body->SetXForm(position->getVec2(), rotation);
}
/// <summary>
/// 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.
/// </summary>
XForm^ GetXForm()
{
return gcnew XForm(body->GetXForm());
}
///<summary>Accesses the linear velocity of the center of mass.</summary>
property Vector^ LinearVelocity
{
Vector^ get()
{
return gcnew Vector(body->GetLinearVelocity());
}
void set(Vector^ value)
{
body->SetLinearVelocity(value->getVec2());
}
}
///<summary>Accesses the angular velocity.</summary>
property float32 AngularVelocity
{
float32 get()
{
return body->GetAngularVelocity();
}
void set(float32 value)
{
body->SetAngularVelocity(value);
}
}
///<summary> Apply a force at a world point. Additive. </summary>
void ApplyForce(Vector^ Force, Vector^ Point)
{
body->ApplyForce(Force->getVec2(), Point->getVec2());
}
///<summary> Apply a torque. Additive. </summary>
void ApplyTorque(float32 Torque)
{
body->ApplyTorque(Torque);
}
///<summary> Apply an impulse at a point. This immediately modifies the velocity. </summary>
void ApplyImpulse(Vector^ Impulse, Vector^ Point)
{
body->ApplyImpulse(Impulse->getVec2(), Point->getVec2());
}
///<summary>Accesses the Mass.</summary>
property float32 Mass
{
float32 get()
{
return body->GetMass();
}
}
///<summary>Accesses the Mass.</summary>
property float32 Inertia
{
float32 get()
{
return body->GetInertia();
}
}
/// <summary>
/// Get the world coordinates of a point give the local coordinates
/// relative to the body's center of mass.
/// </summary>
Vector^ GetWorldPoint(Vector^ LocalPoint)
{
return gcnew Vector(body->GetWorldPoint(LocalPoint->getVec2()));
}
/// <summary>
/// Get the world coordinates of a vector given the local coordinates.
/// </summary>
Vector^ GetWorldVector(Vector^ LocalVector)
{
return gcnew Vector(body->GetWorldVector(LocalVector->getVec2()));
}
/// <summary>
/// Returns a local point relative to the center of mass given a world point.
/// </summary>
Vector^ GetLocalPoint(Vector^ WorldPoint)
{
return gcnew Vector(body->GetLocalPoint(WorldPoint->getVec2()));
}
/// <summary>
/// Returns a local vector given a world vector.
/// </summary>
Vector^ GetLocalVector(Vector^ WorldVector)
{
return gcnew Vector(body->GetLocalVector(WorldVector->getVec2()));
}
///<summary>Is this body static (immovable)</summary>
property bool Static
{
bool get()
{
return body->IsStatic();
}
}
///<summary>Is this body frozen</summary>
property bool Frozen
{
bool get()
{
return body->IsFrozen();
}
}
///<summary>Is this body sleeping</summary>
property bool Sleeping
{
bool get()
{
return body->IsSleeping();
}
}
///<summary>You can disable sleeping on this particular body.</summary>
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();
}
///<summary> Get the list of all shapes attached to this body.</summary>
property IList<Shape^>^ Shapes
{
IList<Shape^>^ get()
{
List<Shape^>^ list = gcnew List<Shape^>();
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();
*/
|