Skip to content

Commit

Permalink
Demo cleanup (2).
Browse files Browse the repository at this point in the history
  • Loading branch information
AndresTraks committed Oct 5, 2016
1 parent fb8f061 commit 18d53b2
Show file tree
Hide file tree
Showing 7 changed files with 284 additions and 313 deletions.
59 changes: 26 additions & 33 deletions BulletSharpPInvoke/demos/BasicDemo/BasicDemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@ namespace BasicDemo
{
class BasicDemo : Demo
{
Vector3 eye = new Vector3(30, 20, 10);
Vector3 target = new Vector3(0, 5, -4);
Vector3 eye = new Vector3(30, 20, 15);
Vector3 target = new Vector3(0, 3, 0);

// create 125 (5x5x5) dynamic objects
const int ArraySizeX = 5, ArraySizeY = 5, ArraySizeZ = 5;

// scaling of the objects (0.1 = 20 centimeter boxes )
const float StartPosX = -5;
const float StartPosY = -5;
const float StartPosZ = -3;
Vector3 startPosition = new Vector3(0, 2, 0);

protected override void OnInitialize()
{
Expand All @@ -36,48 +32,45 @@ protected override void OnInitializePhysics()
World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, null, CollisionConf);
World.Gravity = new Vector3(0, -10, 0);

// create the ground
BoxShape groundShape = new BoxShape(50, 1, 50);
CreateGround();
CreateBoxes();
}

private void CreateGround()
{
var groundShape = new BoxShape(50, 1, 50);
//groundShape.InitializePolyhedralFeatures();
//CollisionShape groundShape = new StaticPlaneShape(new Vector3(0,1,0), 50);
//var groundShape = new StaticPlaneShape(Vector3.UnitY, 1);

CollisionShapes.Add(groundShape);
CollisionObject ground = LocalCreateRigidBody(0, Matrix.Identity, groundShape);
ground.UserObject = "Ground";
}

// create a few dynamic rigidbodies
private void CreateBoxes()
{
const float mass = 1.0f;

BoxShape colShape = new BoxShape(1);
var colShape = new BoxShape(1);
CollisionShapes.Add(colShape);
Vector3 localInertia = colShape.CalculateLocalInertia(mass);

const float startX = StartPosX - ArraySizeX / 2;
const float startY = StartPosY;
const float startZ = StartPosZ - ArraySizeZ / 2;

RigidBodyConstructionInfo rbInfo =
new RigidBodyConstructionInfo(mass, null, colShape, localInertia);
var rbInfo = new RigidBodyConstructionInfo(mass, null, colShape, localInertia);

for (int k = 0; k < ArraySizeY; k++)
for (int y = 0; y < ArraySizeY; y++)
{
for (int i = 0; i < ArraySizeX; i++)
for (int x = 0; x < ArraySizeX; x++)
{
for (int j = 0; j < ArraySizeZ; j++)
for (int z = 0; z < ArraySizeZ; z++)
{
Matrix startTransform = Matrix.Translation(
2 * i + startX,
2 * k + startY,
2 * j + startZ
);

// using motionstate is recommended, it provides interpolation capabilities
// and only synchronizes 'active' objects
rbInfo.MotionState = new DefaultMotionState(startTransform);
RigidBody body = new RigidBody(rbInfo);
Vector3 position = startPosition + 2 * new Vector3(x, y, z);

// make it drop from a height
body.Translate(new Vector3(0, 20, 0));
position += new Vector3(0, 10, 0);

// using MotionState is recommended, it provides interpolation capabilities
// and only synchronizes 'active' objects
rbInfo.MotionState = new DefaultMotionState(Matrix.Translation(position));
var body = new RigidBody(rbInfo);

World.AddRigidBody(body);
}
Expand Down
Loading

0 comments on commit 18d53b2

Please sign in to comment.