protected override void OnInitializePhysics()
        {
            // collision configuration contains default setup for memory, collision setup
            CollisionConf = new DefaultCollisionConfiguration();
            Dispatcher = new CollisionDispatcher(CollisionConf);

            //Broadphase = new SimpleBroadphase();
            Broadphase = new AxisSweep3_32Bit(new Vector3(-10000, -10000, -10000), new Vector3(10000, 10000, 10000), 1024);

            Solver = new SequentialImpulseConstraintSolver();

            World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, Solver, CollisionConf);
            World.Gravity = new Vector3(0, -10, 0);


            // create trimesh model and shape
            InitGImpactCollision();

            // Create Scene
            float mass = 0.0f;

            CollisionShape staticboxShape1 = new BoxShape(200, 1, 200);//floor
            CollisionShapes.Add(staticboxShape1);
            LocalCreateRigidBody(mass, Matrix.Translation(0, -10, 0), staticboxShape1);

            CollisionShape staticboxShape2 = new BoxShape(1, 50, 200);//left wall
            CollisionShapes.Add(staticboxShape2);
            LocalCreateRigidBody(mass, Matrix.Translation(-200, 15, 0), staticboxShape2);

            CollisionShape staticboxShape3 = new BoxShape(1, 50, 200);//right wall
            CollisionShapes.Add(staticboxShape3);
            LocalCreateRigidBody(mass, Matrix.Translation(200, 15, 0), staticboxShape3);

            CollisionShape staticboxShape4 = new BoxShape(200, 50, 1);//front wall
            CollisionShapes.Add(staticboxShape4);
            LocalCreateRigidBody(mass, Matrix.Translation(0, 15, 200), staticboxShape4);

            CollisionShape staticboxShape5 = new BoxShape(200, 50, 1);//back wall
            CollisionShapes.Add(staticboxShape5);
            LocalCreateRigidBody(mass, Matrix.Translation(0, 15, -200), staticboxShape5);


            //static plane

            Vector3 normal = new Vector3(-0.5f, 0.5f, 0.0f);
            normal.Normalize();
            CollisionShape staticplaneShape6 = new StaticPlaneShape(normal, 0.5f);// A plane
            CollisionShapes.Add(staticplaneShape6);
            /*RigidBody staticBody2 =*/ LocalCreateRigidBody(mass, Matrix.Translation(0, -9, 0), staticplaneShape6);


            //another static plane

            normal = new Vector3(0.5f, 0.7f, 0.0f);
            //normal.Normalize();
            CollisionShape staticplaneShape7 = new StaticPlaneShape(normal, 0.0f);// A plane
            CollisionShapes.Add(staticplaneShape7);
            /*staticBody2 =*/ LocalCreateRigidBody(mass, Matrix.Translation(0, -10, 0), staticplaneShape7);


            // Create Static Torus
            float height = 28;
            const float step = 2.5f;
            const float massT = 1.0f;

            Matrix startTransform =
                Matrix.RotationQuaternion(Quaternion.RotationYawPitchRoll((float)Math.PI * 0.5f, 0, (float)Math.PI * 0.5f)) *
                Matrix.Translation(0, height, -5);

#if BULLET_GIMPACT
            kinematicTorus = LocalCreateRigidBody(0, startTransform, trimeshShape);
#else
                //kinematicTorus = LocalCreateRigidBody(0, startTransform, CreateTorusShape());
#endif

            //kinematicTorus.CollisionFlags = kinematicTorus.CollisionFlags | CollisionFlags.StaticObject;
            //kinematicTorus.ActivationState = ActivationState.IslandSleeping;

            kinematicTorus.CollisionFlags = kinematicTorus.CollisionFlags | CollisionFlags.KinematicObject;
            kinematicTorus.ActivationState = ActivationState.DisableDeactivation;

            // Kinematic
            //kinTorusTran = new Vector3(-0.1f, 0, 0);
            //kinTorusRot = Quaternion.RotationYawPitchRoll(0, (float)Math.PI * 0.01f, 0);


#if TEST_GIMPACT_TORUS

#if BULLET_GIMPACT
            // Create dynamic Torus
            for (int i = 0; i < 6; i++)
            {
                height -= step;
                startTransform =
                    Matrix.RotationQuaternion(Quaternion.RotationYawPitchRoll(0, 0, (float)Math.PI * 0.5f)) *
                    Matrix.Translation(0, height, -5);
                /*RigidBody bodyA =*/ LocalCreateRigidBody(massT, startTransform, trimeshShape);

                height -= step;
                startTransform =
                    Matrix.RotationQuaternion(Quaternion.RotationYawPitchRoll((float)Math.PI * 0.5f, 0, (float)Math.PI * 0.5f)) *
                    Matrix.Translation(0, height, -5);
                /*RigidBody bodyB =*/ LocalCreateRigidBody(massT, startTransform, trimeshShape);
            }
#else
            /*
            // Create dynamic Torus
            for (int i = 0; i < 6; i++)
            {
                height -= step;
                startTransform.setOrigin(btVector3(0, height, -5));
                startTransform.setRotation(btQuaternion(0, 0, 3.14159265 * 0.5));

                btRigidBody* bodyA = localCreateRigidBody(massT, startTransform, createTorusShape());

                height -= step;
                startTransform.setOrigin(btVector3(0, height, -5));
                startTransform.setRotation(btQuaternion(3.14159265 * 0.5, 0, 3.14159265 * 0.5));
                btRigidBody* bodyB = localCreateRigidBody(massT, startTransform, createTorusShape());
            }
            */
#endif
#endif

            // Create Dynamic Boxes
            for (int i = 0; i < 8; i++)
            {
                CollisionShape boxShape = new BoxShape(new Vector3(1, 1, 1));
                CollisionShapes.Add(boxShape);
                LocalCreateRigidBody(1, Matrix.Translation(2 * i - 5, 2, -3), boxShape);
            }
        }
        /*
        Does not set any local variables. Is safe to use to create duplicate physics worlds for independant simulation.
        */
        public bool CreatePhysicsWorld( out CollisionWorld world, 
            out CollisionConfiguration collisionConfig,
            out CollisionDispatcher dispatcher,
            out BroadphaseInterface broadphase,
            out SequentialImpulseConstraintSolver solver,
            out SoftBodyWorldInfo softBodyWorldInfo)
        {
            bool success = true;
            if (m_worldType == WorldType.SoftBodyAndRigidBody && m_collisionType == CollisionConfType.DefaultDynamicsWorldCollisionConf)
            {
                BDebug.LogError(debugType, "For World Type = SoftBodyAndRigidBody collisionType must be collisionType=SoftBodyRigidBodyCollisionConf. Switching");
                m_collisionType = CollisionConfType.SoftBodyRigidBodyCollisionConf;
                success = false;
            }

            collisionConfig = null;
            if (m_collisionType == CollisionConfType.DefaultDynamicsWorldCollisionConf)
            {
                collisionConfig = new DefaultCollisionConfiguration();
            }
            else if (m_collisionType == CollisionConfType.SoftBodyRigidBodyCollisionConf)
            {
                collisionConfig = new SoftBodyRigidBodyCollisionConfiguration();
            }

            dispatcher = new CollisionDispatcher(collisionConfig);

            if (m_broadphaseType == BroadphaseType.DynamicAABBBroadphase)
            {
                broadphase = new DbvtBroadphase();
            }
            else if (m_broadphaseType == BroadphaseType.Axis3SweepBroadphase)
            {
                broadphase = new AxisSweep3(m_axis3SweepBroadphaseMin.ToBullet(), m_axis3SweepBroadphaseMax.ToBullet(), axis3SweepMaxProxies);
            }
            else if (m_broadphaseType == BroadphaseType.Axis3SweepBroadphase_32bit)
            {
                broadphase = new AxisSweep3_32Bit(m_axis3SweepBroadphaseMin.ToBullet(), m_axis3SweepBroadphaseMax.ToBullet(), axis3SweepMaxProxies);
            }
            else
            {
                broadphase = null;
            }
            world = null;
            softBodyWorldInfo = null;
            solver = null;
            if (m_worldType == WorldType.CollisionOnly)
            {
                world = new CollisionWorld(dispatcher, broadphase, collisionConfig);
            }
            else if (m_worldType == WorldType.RigidBodyDynamics)
            {
                world = new DiscreteDynamicsWorld(dispatcher, broadphase, null, collisionConfig);
            }
            else if (m_worldType == WorldType.MultiBodyWorld)
            {
                world = new MultiBodyDynamicsWorld(dispatcher, broadphase, null, collisionConfig);
            }
            else if (m_worldType == WorldType.SoftBodyAndRigidBody)
            {
                solver = new SequentialImpulseConstraintSolver();
                solver.RandSeed = sequentialImpulseConstraintSolverRandomSeed;
                softBodyWorldInfo = new SoftBodyWorldInfo
                {
                    AirDensity = 1.2f,
                    WaterDensity = 0,
                    WaterOffset = 0,
                    WaterNormal = BulletSharp.Math.Vector3.Zero,
                    Gravity = UnityEngine.Physics.gravity.ToBullet(),
                    Dispatcher = dispatcher,
                    Broadphase = broadphase
                };
                softBodyWorldInfo.SparseSdf.Initialize();

                world = new SoftRigidDynamicsWorld(dispatcher, broadphase, solver, collisionConfig);

                world.DispatchInfo.EnableSpu = true;
                softBodyWorldInfo.SparseSdf.Reset();
                softBodyWorldInfo.AirDensity = 1.2f;
                softBodyWorldInfo.WaterDensity = 0;
                softBodyWorldInfo.WaterOffset = 0;
                softBodyWorldInfo.WaterNormal = BulletSharp.Math.Vector3.Zero;
                softBodyWorldInfo.Gravity = m_gravity.ToBullet();
            }
            if (world is DiscreteDynamicsWorld)
            {
                ((DiscreteDynamicsWorld)world).Gravity = m_gravity.ToBullet();
            }
            if (_doDebugDraw)
            {
                DebugDrawUnity db = new DebugDrawUnity();
                db.DebugMode = _debugDrawMode;
                world.DebugDrawer = db;
            }
            return success;
        }