@@ -7,16 +7,12 @@ namespace BasicDemo
77{
88 class BasicDemo : Demo
99 {
10- Vector3 eye = new Vector3 ( 30 , 20 , 10 ) ;
11- Vector3 target = new Vector3 ( 0 , 5 , - 4 ) ;
10+ Vector3 eye = new Vector3 ( 30 , 20 , 15 ) ;
11+ Vector3 target = new Vector3 ( 0 , 3 , 0 ) ;
1212
1313 // create 125 (5x5x5) dynamic objects
1414 const int ArraySizeX = 5 , ArraySizeY = 5 , ArraySizeZ = 5 ;
15-
16- // scaling of the objects (0.1 = 20 centimeter boxes )
17- const float StartPosX = - 5 ;
18- const float StartPosY = - 5 ;
19- const float StartPosZ = - 3 ;
15+ Vector3 startPosition = new Vector3 ( 0 , 2 , 0 ) ;
2016
2117 protected override void OnInitialize ( )
2218 {
@@ -36,48 +32,45 @@ protected override void OnInitializePhysics()
3632 World = new DiscreteDynamicsWorld ( Dispatcher , Broadphase , null , CollisionConf ) ;
3733 World . Gravity = new Vector3 ( 0 , - 10 , 0 ) ;
3834
39- // create the ground
40- BoxShape groundShape = new BoxShape ( 50 , 1 , 50 ) ;
35+ CreateGround ( ) ;
36+ CreateBoxes ( ) ;
37+ }
38+
39+ private void CreateGround ( )
40+ {
41+ var groundShape = new BoxShape ( 50 , 1 , 50 ) ;
4142 //groundShape.InitializePolyhedralFeatures();
42- //CollisionShape groundShape = new StaticPlaneShape(new Vector3(0,1,0), 50 );
43+ //var groundShape = new StaticPlaneShape(Vector3.UnitY, 1 );
4344
4445 CollisionShapes . Add ( groundShape ) ;
4546 CollisionObject ground = LocalCreateRigidBody ( 0 , Matrix . Identity , groundShape ) ;
4647 ground . UserObject = "Ground" ;
48+ }
4749
48- // create a few dynamic rigidbodies
50+ private void CreateBoxes ( )
51+ {
4952 const float mass = 1.0f ;
50-
51- BoxShape colShape = new BoxShape ( 1 ) ;
53+ var colShape = new BoxShape ( 1 ) ;
5254 CollisionShapes . Add ( colShape ) ;
5355 Vector3 localInertia = colShape . CalculateLocalInertia ( mass ) ;
5456
55- const float startX = StartPosX - ArraySizeX / 2 ;
56- const float startY = StartPosY ;
57- const float startZ = StartPosZ - ArraySizeZ / 2 ;
58-
59- RigidBodyConstructionInfo rbInfo =
60- new RigidBodyConstructionInfo ( mass , null , colShape , localInertia ) ;
57+ var rbInfo = new RigidBodyConstructionInfo ( mass , null , colShape , localInertia ) ;
6158
62- for ( int k = 0 ; k < ArraySizeY ; k ++ )
59+ for ( int y = 0 ; y < ArraySizeY ; y ++ )
6360 {
64- for ( int i = 0 ; i < ArraySizeX ; i ++ )
61+ for ( int x = 0 ; x < ArraySizeX ; x ++ )
6562 {
66- for ( int j = 0 ; j < ArraySizeZ ; j ++ )
63+ for ( int z = 0 ; z < ArraySizeZ ; z ++ )
6764 {
68- Matrix startTransform = Matrix . Translation (
69- 2 * i + startX ,
70- 2 * k + startY ,
71- 2 * j + startZ
72- ) ;
73-
74- // using motionstate is recommended, it provides interpolation capabilities
75- // and only synchronizes 'active' objects
76- rbInfo . MotionState = new DefaultMotionState ( startTransform ) ;
77- RigidBody body = new RigidBody ( rbInfo ) ;
65+ Vector3 position = startPosition + 2 * new Vector3 ( x , y , z ) ;
7866
7967 // make it drop from a height
80- body . Translate ( new Vector3 ( 0 , 20 , 0 ) ) ;
68+ position += new Vector3 ( 0 , 10 , 0 ) ;
69+
70+ // using MotionState is recommended, it provides interpolation capabilities
71+ // and only synchronizes 'active' objects
72+ rbInfo . MotionState = new DefaultMotionState ( Matrix . Translation ( position ) ) ;
73+ var body = new RigidBody ( rbInfo ) ;
8174
8275 World . AddRigidBody ( body ) ;
8376 }
0 commit comments