public DefaultCollisionConfiguration(DefaultCollisionConstructionInfo constructionInfo)
        {
            m_simplexSolver = BulletGlobals.VoronoiSimplexSolverPool.Get();
            //m_pdSolver = new GjkEpaPenetrationDepthSolver();
            m_pdSolver = new MinkowskiPenetrationDepthSolver();
            m_useEpaPenetrationAlgorithm = true;

            //default CreationFunctions, filling the m_doubleDispatch table
            m_convexConvexCreateFunc         = new ConvexConvexCreateFunc(m_simplexSolver, m_pdSolver);
            m_convexConcaveCreateFunc        = new ConvexConcaveCreateFunc();
            m_swappedConvexConcaveCreateFunc = new SwappedConvexConcaveCreateFunc();
            m_compoundCreateFunc             = new CompoundCreateFunc();
            m_swappedCompoundCreateFunc      = new SwappedCompoundCreateFunc();
            m_emptyCreateFunc = new EmptyCreateFunc();

            m_sphereSphereCF = new SphereSphereCreateFunc();
            m_sphereBoxCF    = new SphereBoxCreateFunc();
            m_boxSphereCF    = new SwappedSphereBoxCreateFunc();

            m_convexAlgo2DCF             = new Convex2dConvex2dCreateFunc(m_simplexSolver, m_pdSolver);
            m_sphereTriangleCF           = new SphereTriangleCreateFunc();
            m_triangleSphereCF           = new SphereTriangleCreateFunc();
            m_triangleSphereCF.m_swapped = true;

            m_boxBoxCF = new BoxBoxCreateFunc();

            //convex versus plane
            m_convexPlaneCF           = new ConvexPlaneCreateFunc();
            m_planeConvexCF           = new ConvexPlaneCreateFunc();
            m_planeConvexCF.m_swapped = true;
        }
	public DefaultCollisionConfiguration(DefaultCollisionConstructionInfo constructionInfo)
    {
        m_simplexSolver = BulletGlobals.VoronoiSimplexSolverPool.Get();
        //m_pdSolver = new GjkEpaPenetrationDepthSolver();
        m_pdSolver = new MinkowskiPenetrationDepthSolver();
        m_useEpaPenetrationAlgorithm = true;

	    //default CreationFunctions, filling the m_doubleDispatch table
	    m_convexConvexCreateFunc = new ConvexConvexCreateFunc(m_simplexSolver,m_pdSolver);
	    m_convexConcaveCreateFunc = new ConvexConcaveCreateFunc();
	    m_swappedConvexConcaveCreateFunc = new SwappedConvexConcaveCreateFunc();
	    m_compoundCreateFunc = new CompoundCreateFunc();
	    m_swappedCompoundCreateFunc = new SwappedCompoundCreateFunc();
	    m_emptyCreateFunc = new EmptyCreateFunc();
	
    	m_sphereSphereCF = new SphereSphereCreateFunc();
        m_sphereBoxCF = new SphereBoxCreateFunc();
        m_boxSphereCF = new SwappedSphereBoxCreateFunc();

        m_convexAlgo2DCF = new Convex2dConvex2dCreateFunc(m_simplexSolver, m_pdSolver);
	    m_sphereTriangleCF = new SphereTriangleCreateFunc();
	    m_triangleSphereCF = new SphereTriangleCreateFunc();
	    m_triangleSphereCF.m_swapped = true;
    	
	    m_boxBoxCF = new BoxBoxCreateFunc();

	    //convex versus plane
	    m_convexPlaneCF = new ConvexPlaneCreateFunc();
	    m_planeConvexCF = new ConvexPlaneCreateFunc();
	    m_planeConvexCF.m_swapped = true;
    	
    }
Beispiel #3
0
        public BenchmarkDemoSimulation()
        {
            using (var cci = new DefaultCollisionConstructionInfo()
            {
                DefaultMaxPersistentManifoldPoolSize = 32768
            })
            {
                CollisionConfiguration = new DefaultCollisionConfiguration(cci);
            }

            Dispatcher = new CollisionDispatcher(CollisionConfiguration);
            Dispatcher.DispatcherFlags = DispatcherFlags.DisableContactPoolDynamicAllocation;

            // The maximum size of the collision world. Make sure objects stay within these boundaries
            // Don't make the world AABB size too large, it will harm simulation quality and performance
            var worldAabbMin = new Vector3(-1000, -1000, -1000);
            var worldAabbMax = new Vector3(1000, 1000, 1000);

            Broadphase = new AxisSweep3(worldAabbMin, worldAabbMax, 3500);
            //Broadphase = new DbvtBroadphase();

            World = new DiscreteDynamicsWorld(Dispatcher, Broadphase, null, CollisionConfiguration);
            World.SolverInfo.SolverMode   |= SolverModes.EnableFrictionDirectionCaching;
            World.SolverInfo.NumIterations = 5;

            _scenes = new Action[] {
                Create3KBoxes, CreateStructures, CreateTaruStack, CreateShapesGravity, CreateTaruGravity
            };
            _scenes[_scene]();
        }
Beispiel #4
0
        protected override void OnInitializePhysics()
        {
            // collision configuration contains default setup for memory, collision setup
            using (var cci = new DefaultCollisionConstructionInfo()
            {
                DefaultMaxPersistentManifoldPoolSize = 32768
            })
            {
                CollisionConf = new DefaultCollisionConfiguration(cci);
            }

            Dispatcher = new CollisionDispatcher(CollisionConf);
            Dispatcher.DispatcherFlags = DispatcherFlags.DisableContactPoolDynamicAllocation;

            // the maximum size of the collision world. Make sure objects stay within these boundaries
            // Don't make the world AABB size too large, it will harm simulation quality and performance
            Vector3 worldAabbMin = new Vector3(-1000, -1000, -1000);
            Vector3 worldAabbMax = new Vector3(1000, 1000, 1000);

            Broadphase = new AxisSweep3(worldAabbMin, worldAabbMax, 3500);
            //Broadphase = new DbvtBroadphase();

            Solver = new SequentialImpulseConstraintSolver();

            World         = new DiscreteDynamicsWorld(Dispatcher, Broadphase, Solver, CollisionConf);
            World.Gravity = new Vector3(0, -10, 0);
            World.SolverInfo.SolverMode   |= SolverModes.EnableFrictionDirectionCaching;
            World.SolverInfo.NumIterations = 5;

            _scenes[SceneIndex]();
        }
Beispiel #5
0
        public PhysicsEngine()
        {
            //CreateSchedulers();
            //NextTaskScheduler();
            using (var collisionConfigurationInfo = new DefaultCollisionConstructionInfo
            {
                DefaultMaxPersistentManifoldPoolSize = 800,
                DefaultMaxCollisionAlgorithmPoolSize = 800
            })
            {
                collisionConf = new DefaultCollisionConfiguration(collisionConfigurationInfo);
            };
            dispatcher = new CollisionDispatcher(collisionConf);
            broadphase = new DbvtBroadphase();
            var solver = new SequentialImpulseConstraintSolver();

            //var Solver = new NncgConstraintSolver();
            //DiscreteDynamicsWorldMultiThreaded(dispatcher, broadphase, Solver, collisionConf);
            World = new DiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConf);

            //dispatcher = new CollisionDispatcherMultiThreaded(collisionConf);
            //Solver = new ConstraintSolverPoolMultiThreaded(MaxThreadCount);
            //World = new DiscreteDynamicsWorldMultiThreaded(dispatcher, broadphase, Solver, null, collisionConf);
            //World.SolverInfo.SolverMode = SolverModes.Simd | SolverModes.UseWarmStarting;

            //World = new DiscreteDynamicsWorldMultiThreaded(dispatcher, broadphase, cspm, csM, collisionConf);
            //World.Gravity = new Vector3(0, 0f, 0);
            // CreateFloor();
            //World.LatencyMotionStateInterpolation = false;

            //for character controllers
            broadphase.OverlappingPairCache.SetInternalGhostPairCallback(new GhostPairCallback());

            World.DebugDrawer = new PhysicsDebugDraw(World);
        }
        public MultiThreadedDemoSimulation()
        {
            CreateSchedulers();
            NextTaskScheduler();

            using (var collisionConfigurationInfo = new DefaultCollisionConstructionInfo
            {
                DefaultMaxPersistentManifoldPoolSize = 80000,
                DefaultMaxCollisionAlgorithmPoolSize = 80000
            })
            {
                CollisionConfiguration = new DefaultCollisionConfiguration(collisionConfigurationInfo);
            };
            Dispatcher                  = new CollisionDispatcherMultiThreaded(CollisionConfiguration);
            Broadphase                  = new DbvtBroadphase();
            _constraintSolver           = new ConstraintSolverPoolMultiThreaded(MaxThreadCount);
            World                       = new DiscreteDynamicsWorldMultiThreaded(Dispatcher, Broadphase, _constraintSolver, CollisionConfiguration);
            World.SolverInfo.SolverMode = SolverModes.Simd | SolverModes.UseWarmStarting;

            CreateGround();
            CreateBoxes();
        }
        protected override void OnInitializePhysics()
        {
            // collision configuration contains default setup for memory, collision setup
            DefaultCollisionConstructionInfo cci = new DefaultCollisionConstructionInfo();

            cci.DefaultMaxPersistentManifoldPoolSize = 32768;
            CollisionConf = new DefaultCollisionConfiguration(cci);

            Dispatcher = new CollisionDispatcher(CollisionConf);
            Dispatcher.DispatcherFlags = DispatcherFlags.DisableContactPoolDynamicAllocation;

            // the maximum size of the collision world. Make sure objects stay within these boundaries
            // Don't make the world AABB size too large, it will harm simulation quality and performance
            Vector3 worldAabbMin = new Vector3(-1000, -1000, -1000);
            Vector3 worldAabbMax = new Vector3(1000, 1000, 1000);

            HashedOverlappingPairCache pairCache = new HashedOverlappingPairCache();

            Broadphase = new AxisSweep3(worldAabbMin, worldAabbMax, 3500, pairCache);
            //Broadphase = new DbvtBroadphase();

            Solver = new SequentialImpulseConstraintSolver();

            World         = new DiscreteDynamicsWorld(Dispatcher, Broadphase, Solver, CollisionConf);
            World.Gravity = new Vector3(0, -10, 0);
            World.SolverInfo.SolverMode   |= SolverModes.EnableFrictionDirectionCaching;
            World.SolverInfo.NumIterations = 5;

            if (benchmark < 5)
            {
                // create the ground
                CollisionShape groundShape = new BoxShape(250, 50, 250);
                CollisionShapes.Add(groundShape);
                CollisionObject ground = base.LocalCreateRigidBody(0, Matrix.Translation(0, -50, 0), groundShape);
                ground.UserObject = "Ground";
            }

            float   cubeSize = 1.0f;
            float   spacing  = cubeSize;
            float   mass     = 1.0f;
            int     size     = 8;
            Vector3 pos      = new Vector3(0.0f, cubeSize * 2, 0.0f);
            float   offset   = -size * (cubeSize * 2.0f + spacing) * 0.5f;

            switch (benchmark)
            {
            case 1:
                // 3000

                BoxShape blockShape = new BoxShape(cubeSize - collisionRadius);
                mass = 2.0f;

                for (int k = 0; k < 20; k++)
                {
                    for (int j = 0; j < size; j++)
                    {
                        pos[2] = offset + (float)j * (cubeSize * 2.0f + spacing);
                        for (int i = 0; i < size; i++)
                        {
                            pos[0] = offset + (float)i * (cubeSize * 2.0f + spacing);
                            RigidBody cmbody = LocalCreateRigidBody(mass, Matrix.Translation(pos), blockShape);
                        }
                    }
                    offset -= 0.05f * spacing * (size - 1);
                    // spacing *= 1.01f;
                    pos[1] += (cubeSize * 2.0f + spacing);
                }
                break;

            case 2:
                CreatePyramid(new Vector3(-20, 0, 0), 12, new Vector3(cubeSize));
                CreateWall(new Vector3(-2.0f, 0.0f, 0.0f), 12, new Vector3(cubeSize));
                CreateWall(new Vector3(4.0f, 0.0f, 0.0f), 12, new Vector3(cubeSize));
                CreateWall(new Vector3(10.0f, 0.0f, 0.0f), 12, new Vector3(cubeSize));
                CreateTowerCircle(new Vector3(25.0f, 0.0f, 0.0f), 8, 24, new Vector3(cubeSize));
                break;

            case 3:
                // TODO: Ragdolls
                break;

            case 4:
                cubeSize = 1.5f;

                ConvexHullShape convexHullShape = new ConvexHullShape();

                float scaling = 1;

                convexHullShape.LocalScaling = new Vector3(scaling);

                for (int i = 0; i < Taru.Vtx.Length / 3; i++)
                {
                    Vector3 vtx = new Vector3(Taru.Vtx[i * 3], Taru.Vtx[i * 3 + 1], Taru.Vtx[i * 3 + 2]);
                    convexHullShape.AddPoint(vtx * (1.0f / scaling));
                }

                //this will enable polyhedral contact clipping, better quality, slightly slower
                convexHullShape.InitializePolyhedralFeatures();

                for (int k = 0; k < 15; k++)
                {
                    for (int j = 0; j < size; j++)
                    {
                        pos[2] = offset + (float)j * (cubeSize * 2.0f + spacing);
                        for (int i = 0; i < size; i++)
                        {
                            pos[0] = offset + (float)i * (cubeSize * 2.0f + spacing);
                            LocalCreateRigidBody(mass, Matrix.Translation(pos), convexHullShape);
                        }
                    }
                    offset  -= 0.05f * spacing * (size - 1);
                    spacing *= 1.01f;
                    pos[1]  += (cubeSize * 2.0f + spacing);
                }
                break;

            case 5:
                Vector3 boxSize       = new Vector3(1.5f);
                float   boxMass       = 1.0f;
                float   sphereRadius  = 1.5f;
                float   sphereMass    = 1.0f;
                float   capsuleHalf   = 2.0f;
                float   capsuleRadius = 1.0f;
                float   capsuleMass   = 1.0f;

                size = 10;
                int height = 10;

                cubeSize = boxSize[0];
                spacing  = 2.0f;
                pos      = new Vector3(0.0f, 20.0f, 0.0f);
                offset   = -size * (cubeSize * 2.0f + spacing) * 0.5f;

                int numBodies = 0;

                Random random = new Random();

                for (int k = 0; k < height; k++)
                {
                    for (int j = 0; j < size; j++)
                    {
                        pos[2] = offset + (float)j * (cubeSize * 2.0f + spacing);
                        for (int i = 0; i < size; i++)
                        {
                            pos[0] = offset + (float)i * (cubeSize * 2.0f + spacing);
                            Vector3 bpos  = new Vector3(0, 25, 0) + new Vector3(5.0f * pos.X, pos.Y, 5.0f * pos.Z);
                            int     idx   = random.Next(10);
                            Matrix  trans = Matrix.Translation(bpos);

                            switch (idx)
                            {
                            case 0:
                            case 1:
                            case 2:
                            {
                                float    r        = 0.5f * (idx + 1);
                                BoxShape boxShape = new BoxShape(boxSize * r);
                                LocalCreateRigidBody(boxMass * r, trans, boxShape);
                            }
                            break;

                            case 3:
                            case 4:
                            case 5:
                            {
                                float       r           = 0.5f * (idx - 3 + 1);
                                SphereShape sphereShape = new SphereShape(sphereRadius * r);
                                LocalCreateRigidBody(sphereMass * r, trans, sphereShape);
                            }
                            break;

                            case 6:
                            case 7:
                            case 8:
                            {
                                float        r            = 0.5f * (idx - 6 + 1);
                                CapsuleShape capsuleShape = new CapsuleShape(capsuleRadius * r, capsuleHalf * r);
                                LocalCreateRigidBody(capsuleMass * r, trans, capsuleShape);
                            }
                            break;
                            }

                            numBodies++;
                        }
                    }
                    offset  -= 0.05f * spacing * (size - 1);
                    spacing *= 1.1f;
                    pos[1]  += (cubeSize * 2.0f + spacing);
                }

                //CreateLargeMeshBody();

                break;

            case 6:
                boxSize = new Vector3(1.5f, 1.5f, 1.5f);

                convexHullShape = new ConvexHullShape();

                for (int i = 0; i < Taru.Vtx.Length / 3; i++)
                {
                    Vector3 vtx = new Vector3(Taru.Vtx[i * 3], Taru.Vtx[i * 3 + 1], Taru.Vtx[i * 3 + 2]);
                    convexHullShape.AddPoint(vtx);
                }

                size   = 10;
                height = 10;

                cubeSize = boxSize[0];
                spacing  = 2.0f;
                pos      = new Vector3(0.0f, 20.0f, 0.0f);
                offset   = -size * (cubeSize * 2.0f + spacing) * 0.5f;


                for (int k = 0; k < height; k++)
                {
                    for (int j = 0; j < size; j++)
                    {
                        pos[2] = offset + (float)j * (cubeSize * 2.0f + spacing);
                        for (int i = 0; i < size; i++)
                        {
                            pos[0] = offset + (float)i * (cubeSize * 2.0f + spacing);
                            Vector3 bpos = new Vector3(0, 25, 0) + new Vector3(5.0f * pos.X, pos.Y, 5.0f * pos.Z);

                            LocalCreateRigidBody(mass, Matrix.Translation(bpos), convexHullShape);
                        }
                    }
                    offset  -= 0.05f * spacing * (size - 1);
                    spacing *= 1.1f;
                    pos[1]  += (cubeSize * 2.0f + spacing);
                }

                //CreateLargeMeshBody();

                break;

            case 7:
                // TODO
                //CreateTest6();
                //InitRays();
                break;
            }
        }
Beispiel #8
0
    private static DiscreteDynamicsWorld Initialize2(Vector3 worldExtent,
                        ConfigurationParameters[] o,
                        int mMaxCollisionsPerFrame, ref CollisionDesc[] collisionArray,
                        int mMaxUpdatesPerFrame, ref EntityProperties[] updateArray,
                        object mDebugLogCallbackHandle)
    {
        CollisionWorld.WorldData.ParamData p = new CollisionWorld.WorldData.ParamData();

        p.angularDamping = BSParam.AngularDamping;
        p.defaultFriction = o[0].defaultFriction;
        p.defaultFriction = o[0].defaultFriction;
        p.defaultDensity = o[0].defaultDensity;
        p.defaultRestitution = o[0].defaultRestitution;
        p.collisionMargin = o[0].collisionMargin;
        p.gravity = o[0].gravity;

        p.linearDamping = BSParam.LinearDamping;
        p.angularDamping = BSParam.AngularDamping;
        p.deactivationTime = BSParam.DeactivationTime;
        p.linearSleepingThreshold = BSParam.LinearSleepingThreshold;
        p.angularSleepingThreshold = BSParam.AngularSleepingThreshold;
        p.ccdMotionThreshold = BSParam.CcdMotionThreshold;
        p.ccdSweptSphereRadius = BSParam.CcdSweptSphereRadius;
        p.contactProcessingThreshold = BSParam.ContactProcessingThreshold;

        p.terrainImplementation = BSParam.TerrainImplementation;
        p.terrainFriction = BSParam.TerrainFriction;

        p.terrainHitFraction = BSParam.TerrainHitFraction;
        p.terrainRestitution = BSParam.TerrainRestitution;
        p.terrainCollisionMargin = BSParam.TerrainCollisionMargin;

        p.avatarFriction = BSParam.AvatarFriction;
        p.avatarStandingFriction = BSParam.AvatarStandingFriction;
        p.avatarDensity = BSParam.AvatarDensity;
        p.avatarRestitution = BSParam.AvatarRestitution;
        p.avatarCapsuleWidth = BSParam.AvatarCapsuleWidth;
        p.avatarCapsuleDepth = BSParam.AvatarCapsuleDepth;
        p.avatarCapsuleHeight = BSParam.AvatarCapsuleHeight;
        p.avatarContactProcessingThreshold = BSParam.AvatarContactProcessingThreshold;

        p.vehicleAngularDamping = BSParam.VehicleAngularDamping;

        p.maxPersistantManifoldPoolSize = o[0].maxPersistantManifoldPoolSize;
        p.maxCollisionAlgorithmPoolSize = o[0].maxCollisionAlgorithmPoolSize;
        p.shouldDisableContactPoolDynamicAllocation = o[0].shouldDisableContactPoolDynamicAllocation;
        p.shouldForceUpdateAllAabbs = o[0].shouldForceUpdateAllAabbs;
        p.shouldRandomizeSolverOrder = o[0].shouldRandomizeSolverOrder;
        p.shouldSplitSimulationIslands = o[0].shouldSplitSimulationIslands;
        p.shouldEnableFrictionCaching = o[0].shouldEnableFrictionCaching;
        p.numberOfSolverIterations = o[0].numberOfSolverIterations;

        p.linksetImplementation = BSParam.LinksetImplementation;
        p.linkConstraintUseFrameOffset = BSParam.NumericBool(BSParam.LinkConstraintUseFrameOffset);
        p.linkConstraintEnableTransMotor = BSParam.NumericBool(BSParam.LinkConstraintEnableTransMotor);
        p.linkConstraintTransMotorMaxVel = BSParam.LinkConstraintTransMotorMaxVel;
        p.linkConstraintTransMotorMaxForce = BSParam.LinkConstraintTransMotorMaxForce;
        p.linkConstraintERP = BSParam.LinkConstraintERP;
        p.linkConstraintCFM = BSParam.LinkConstraintCFM;
        p.linkConstraintSolverIterations = BSParam.LinkConstraintSolverIterations;
        p.physicsLoggingFrames = o[0].physicsLoggingFrames;
        DefaultCollisionConstructionInfo ccci = new DefaultCollisionConstructionInfo();

        DefaultCollisionConfiguration cci = new DefaultCollisionConfiguration();
        CollisionDispatcher m_dispatcher = new CollisionDispatcher(cci);


        if (p.maxPersistantManifoldPoolSize > 0)
            cci.m_persistentManifoldPoolSize = (int)p.maxPersistantManifoldPoolSize;
        if (p.shouldDisableContactPoolDynamicAllocation !=0)
            m_dispatcher.SetDispatcherFlags(DispatcherFlags.CD_DISABLE_CONTACTPOOL_DYNAMIC_ALLOCATION);
        //if (p.maxCollisionAlgorithmPoolSize >0 )

        DbvtBroadphase m_broadphase = new DbvtBroadphase();
        //IndexedVector3 aabbMin = new IndexedVector3(0, 0, 0);
        //IndexedVector3 aabbMax = new IndexedVector3(256, 256, 256);

        //AxisSweep3Internal m_broadphase2 = new AxisSweep3Internal(ref aabbMin, ref aabbMax, Convert.ToInt32(0xfffe), 0xffff, ushort.MaxValue/2, null, true);
        m_broadphase.GetOverlappingPairCache().SetInternalGhostPairCallback(new GhostPairCallback());

        SequentialImpulseConstraintSolver m_solver = new SequentialImpulseConstraintSolver();

        DiscreteDynamicsWorld world = new DiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_solver, cci);

        world.LastCollisionDesc = 0;
        world.LastEntityProperty = 0;

        world.WorldSettings.Params = p;
        world.SetForceUpdateAllAabbs(p.shouldForceUpdateAllAabbs != 0);
        world.GetSolverInfo().m_solverMode = SolverMode.SOLVER_USE_WARMSTARTING | SolverMode.SOLVER_SIMD;
        if (p.shouldRandomizeSolverOrder != 0)
            world.GetSolverInfo().m_solverMode |= SolverMode.SOLVER_RANDMIZE_ORDER;

        world.GetSimulationIslandManager().SetSplitIslands(p.shouldSplitSimulationIslands != 0);
        //world.GetDispatchInfo().m_enableSatConvex Not implemented in C# port

        if (p.shouldEnableFrictionCaching != 0)
            world.GetSolverInfo().m_solverMode |= SolverMode.SOLVER_ENABLE_FRICTION_DIRECTION_CACHING;

        if (p.numberOfSolverIterations > 0)
            world.GetSolverInfo().m_numIterations = (int) p.numberOfSolverIterations;


        world.GetSolverInfo().m_damping = world.WorldSettings.Params.linearDamping;
        world.GetSolverInfo().m_restitution = world.WorldSettings.Params.defaultRestitution;
        world.GetSolverInfo().m_globalCfm = 0.0f;
        world.GetSolverInfo().m_tau = 0.6f;
        world.GetSolverInfo().m_friction = 0.3f;
        world.GetSolverInfo().m_maxErrorReduction = 20f;
        world.GetSolverInfo().m_numIterations = 10;
        world.GetSolverInfo().m_erp = 0.2f;
        world.GetSolverInfo().m_erp2 = 0.1f;
        world.GetSolverInfo().m_sor = 1.0f;
        world.GetSolverInfo().m_splitImpulse = false;
        world.GetSolverInfo().m_splitImpulsePenetrationThreshold = -0.02f;
        world.GetSolverInfo().m_linearSlop = 0.0f;
        world.GetSolverInfo().m_warmstartingFactor = 0.85f;
        world.GetSolverInfo().m_restingContactRestitutionThreshold = 2;
        world.SetForceUpdateAllAabbs(true);

        //BSParam.TerrainImplementation = 0;
        world.SetGravity(new IndexedVector3(0,0,p.gravity));

        // Turn off Pooling since globals and pooling are bad for threading.
        BulletGlobals.VoronoiSimplexSolverPool.SetPoolingEnabled(false);
        BulletGlobals.SubSimplexConvexCastPool.SetPoolingEnabled(false);
        BulletGlobals.ManifoldPointPool.SetPoolingEnabled(false);
        BulletGlobals.CastResultPool.SetPoolingEnabled(false);
        BulletGlobals.SphereShapePool.SetPoolingEnabled(false);
        BulletGlobals.DbvtNodePool.SetPoolingEnabled(false);
        BulletGlobals.SingleRayCallbackPool.SetPoolingEnabled(false);
        BulletGlobals.SubSimplexClosestResultPool.SetPoolingEnabled(false);
        BulletGlobals.GjkPairDetectorPool.SetPoolingEnabled(false);
        BulletGlobals.DbvtTreeColliderPool.SetPoolingEnabled(false);
        BulletGlobals.SingleSweepCallbackPool.SetPoolingEnabled(false);
        BulletGlobals.BroadphaseRayTesterPool.SetPoolingEnabled(false);
        BulletGlobals.ClosestNotMeConvexResultCallbackPool.SetPoolingEnabled(false);
        BulletGlobals.GjkEpaPenetrationDepthSolverPool.SetPoolingEnabled(false);
        BulletGlobals.ContinuousConvexCollisionPool.SetPoolingEnabled(false);
        BulletGlobals.DbvtStackDataBlockPool.SetPoolingEnabled(false);

        BulletGlobals.BoxBoxCollisionAlgorithmPool.SetPoolingEnabled(false);
        BulletGlobals.CompoundCollisionAlgorithmPool.SetPoolingEnabled(false);
        BulletGlobals.ConvexConcaveCollisionAlgorithmPool.SetPoolingEnabled(false);
        BulletGlobals.ConvexConvexAlgorithmPool.SetPoolingEnabled(false);
        BulletGlobals.ConvexPlaneAlgorithmPool.SetPoolingEnabled(false);
        BulletGlobals.SphereBoxCollisionAlgorithmPool.SetPoolingEnabled(false);
        BulletGlobals.SphereSphereCollisionAlgorithmPool.SetPoolingEnabled(false);
        BulletGlobals.SphereTriangleCollisionAlgorithmPool.SetPoolingEnabled(false);
        BulletGlobals.GImpactCollisionAlgorithmPool.SetPoolingEnabled(false);
        BulletGlobals.GjkEpaSolver2MinkowskiDiffPool.SetPoolingEnabled(false);
        BulletGlobals.PersistentManifoldPool.SetPoolingEnabled(false);
        BulletGlobals.ManifoldResultPool.SetPoolingEnabled(false);
        BulletGlobals.GJKPool.SetPoolingEnabled(false);
        BulletGlobals.GIM_ShapeRetrieverPool.SetPoolingEnabled(false);
        BulletGlobals.TriangleShapePool.SetPoolingEnabled(false);
        BulletGlobals.SphereTriangleDetectorPool.SetPoolingEnabled(false);
        BulletGlobals.CompoundLeafCallbackPool.SetPoolingEnabled(false);
        BulletGlobals.GjkConvexCastPool.SetPoolingEnabled(false);
        BulletGlobals.LocalTriangleSphereCastCallbackPool.SetPoolingEnabled(false);
        BulletGlobals.BridgeTriangleRaycastCallbackPool.SetPoolingEnabled(false);
        BulletGlobals.BridgeTriangleConcaveRaycastCallbackPool.SetPoolingEnabled(false);
        BulletGlobals.BridgeTriangleConvexcastCallbackPool.SetPoolingEnabled(false);
        BulletGlobals.MyNodeOverlapCallbackPool.SetPoolingEnabled(false);
        BulletGlobals.ClosestRayResultCallbackPool.SetPoolingEnabled(false);
        BulletGlobals.DebugDrawcallbackPool.SetPoolingEnabled(false);

        return world;
    }
Beispiel #9
0
    private static object Initialize2(Vector3 worldExtent, 
                        ConfigurationParameters[] o,
                        int mMaxCollisionsPerFrame, ref List<BulletXNA.CollisionDesc> collisionArray,
                        int mMaxUpdatesPerFrame, ref List<BulletXNA.EntityProperties> updateArray, 
                        object mDebugLogCallbackHandle)
    {
        CollisionWorld.WorldData.ParamData p = new CollisionWorld.WorldData.ParamData();

        p.angularDamping = o[0].XangularDamping;
        p.defaultFriction = o[0].defaultFriction;
        p.defaultFriction = o[0].defaultFriction;
        p.defaultDensity = o[0].defaultDensity;
        p.defaultRestitution = o[0].defaultRestitution;
        p.collisionMargin = o[0].collisionMargin;
        p.gravity = o[0].gravity;

        p.linearDamping = o[0].XlinearDamping;
        p.angularDamping = o[0].XangularDamping;
        p.deactivationTime = o[0].XdeactivationTime;
        p.linearSleepingThreshold = o[0].XlinearSleepingThreshold;
        p.angularSleepingThreshold = o[0].XangularSleepingThreshold;
        p.ccdMotionThreshold = o[0].XccdMotionThreshold;
        p.ccdSweptSphereRadius = o[0].XccdSweptSphereRadius;
        p.contactProcessingThreshold = o[0].XcontactProcessingThreshold;

        p.terrainImplementation = o[0].XterrainImplementation;
        p.terrainFriction = o[0].XterrainFriction;

        p.terrainHitFraction = o[0].XterrainHitFraction;
        p.terrainRestitution = o[0].XterrainRestitution;
        p.terrainCollisionMargin = o[0].XterrainCollisionMargin;

        p.avatarFriction = o[0].XavatarFriction;
        p.avatarStandingFriction = o[0].XavatarStandingFriction;
        p.avatarDensity = o[0].XavatarDensity;
        p.avatarRestitution = o[0].XavatarRestitution;
        p.avatarCapsuleWidth = o[0].XavatarCapsuleWidth;
        p.avatarCapsuleDepth = o[0].XavatarCapsuleDepth;
        p.avatarCapsuleHeight = o[0].XavatarCapsuleHeight;
        p.avatarContactProcessingThreshold = o[0].XavatarContactProcessingThreshold;
       
        p.vehicleAngularDamping = o[0].XvehicleAngularDamping;
        
        p.maxPersistantManifoldPoolSize = o[0].maxPersistantManifoldPoolSize;
        p.maxCollisionAlgorithmPoolSize = o[0].maxCollisionAlgorithmPoolSize;
        p.shouldDisableContactPoolDynamicAllocation = o[0].shouldDisableContactPoolDynamicAllocation;
        p.shouldForceUpdateAllAabbs = o[0].shouldForceUpdateAllAabbs;
        p.shouldRandomizeSolverOrder = o[0].shouldRandomizeSolverOrder;
        p.shouldSplitSimulationIslands = o[0].shouldSplitSimulationIslands;
        p.shouldEnableFrictionCaching = o[0].shouldEnableFrictionCaching;
        p.numberOfSolverIterations = o[0].numberOfSolverIterations;

        p.linksetImplementation = o[0].XlinksetImplementation;
        p.linkConstraintUseFrameOffset = o[0].XlinkConstraintUseFrameOffset;
        p.linkConstraintEnableTransMotor = o[0].XlinkConstraintEnableTransMotor;
        p.linkConstraintTransMotorMaxVel = o[0].XlinkConstraintTransMotorMaxVel;
        p.linkConstraintTransMotorMaxForce = o[0].XlinkConstraintTransMotorMaxForce;
        p.linkConstraintERP = o[0].XlinkConstraintERP;
        p.linkConstraintCFM = o[0].XlinkConstraintCFM;
        p.linkConstraintSolverIterations = o[0].XlinkConstraintSolverIterations;
        p.physicsLoggingFrames = o[0].XphysicsLoggingFrames;
        DefaultCollisionConstructionInfo ccci = new DefaultCollisionConstructionInfo();
        
        DefaultCollisionConfiguration cci = new DefaultCollisionConfiguration();
        CollisionDispatcher m_dispatcher = new CollisionDispatcher(cci);


        if (p.maxPersistantManifoldPoolSize > 0)
            cci.m_persistentManifoldPoolSize = (int)p.maxPersistantManifoldPoolSize;
        if (p.shouldDisableContactPoolDynamicAllocation !=0)
            m_dispatcher.SetDispatcherFlags(DispatcherFlags.CD_DISABLE_CONTACTPOOL_DYNAMIC_ALLOCATION);
        //if (p.maxCollisionAlgorithmPoolSize >0 )

        DbvtBroadphase m_broadphase = new DbvtBroadphase();
        //IndexedVector3 aabbMin = new IndexedVector3(0, 0, 0);
        //IndexedVector3 aabbMax = new IndexedVector3(256, 256, 256);

        //AxisSweep3Internal m_broadphase2 = new AxisSweep3Internal(ref aabbMin, ref aabbMax, Convert.ToInt32(0xfffe), 0xffff, ushort.MaxValue/2, null, true);
        m_broadphase.GetOverlappingPairCache().SetInternalGhostPairCallback(new GhostPairCallback());

        SequentialImpulseConstraintSolver m_solver = new SequentialImpulseConstraintSolver();

        DiscreteDynamicsWorld world = new DiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_solver, cci);
        world.UpdatedObjects = updateArray;
        world.UpdatedCollisions = collisionArray;
        world.WorldSettings.Params = p;
        world.SetForceUpdateAllAabbs(p.shouldForceUpdateAllAabbs != 0);
        world.GetSolverInfo().m_solverMode = SolverMode.SOLVER_USE_WARMSTARTING | SolverMode.SOLVER_SIMD;
        if (p.shouldRandomizeSolverOrder != 0)
            world.GetSolverInfo().m_solverMode |= SolverMode.SOLVER_RANDMIZE_ORDER;

        world.GetSimulationIslandManager().SetSplitIslands(p.shouldSplitSimulationIslands != 0);
        //world.GetDispatchInfo().m_enableSatConvex Not implemented in C# port

        if (p.shouldEnableFrictionCaching != 0)
            world.GetSolverInfo().m_solverMode |= SolverMode.SOLVER_ENABLE_FRICTION_DIRECTION_CACHING;

        if (p.numberOfSolverIterations > 0)
            world.GetSolverInfo().m_numIterations = (int) p.numberOfSolverIterations;


        world.GetSolverInfo().m_damping = world.WorldSettings.Params.linearDamping;
        world.GetSolverInfo().m_restitution = world.WorldSettings.Params.defaultRestitution;
        world.GetSolverInfo().m_globalCfm = 0.0f;
        world.GetSolverInfo().m_tau = 0.6f;
        world.GetSolverInfo().m_friction = 0.3f;
        world.GetSolverInfo().m_maxErrorReduction = 20f;
        world.GetSolverInfo().m_numIterations = 10;
        world.GetSolverInfo().m_erp = 0.2f;
        world.GetSolverInfo().m_erp2 = 0.1f;
        world.GetSolverInfo().m_sor = 1.0f;
        world.GetSolverInfo().m_splitImpulse = false;
        world.GetSolverInfo().m_splitImpulsePenetrationThreshold = -0.02f;
        world.GetSolverInfo().m_linearSlop = 0.0f;
        world.GetSolverInfo().m_warmstartingFactor = 0.85f;
        world.GetSolverInfo().m_restingContactRestitutionThreshold = 2;
        world.SetForceUpdateAllAabbs(true);


        world.SetGravity(new IndexedVector3(0,0,p.gravity));

        return world;
    }
	public DefaultCollisionConfiguration(DefaultCollisionConstructionInfo constructionInfo)
    {
    	m_simplexSolver = new VoronoiSimplexSolver();
        m_pdSolver = new GjkEpaPenetrationDepthSolver();
        //m_pdSolver = new MinkowskiPenetrationDepthSolver();
        m_useEpaPenetrationAlgorithm = true;
//#define USE_EPA 1
//#ifdef USE_EPA
//    mem = btAlignedAlloc(sizeof(btGjkEpaPenetrationDepthSolver),16);
//    m_pdSolver = new (mem)btGjkEpaPenetrationDepthSolver;
//#else
//    mem = btAlignedAlloc(sizeof(btMinkowskiPenetrationDepthSolver),16);
//    m_pdSolver = new (mem)btMinkowskiPenetrationDepthSolver;
//#endif//USE_EPA	
	

	    //default CreationFunctions, filling the m_doubleDispatch table
	    m_convexConvexCreateFunc = new ConvexConvexCreateFunc(m_simplexSolver,m_pdSolver);
	    m_convexConcaveCreateFunc = new ConvexConcaveCreateFunc();
	    m_swappedConvexConcaveCreateFunc = new SwappedConvexConcaveCreateFunc();
	    m_compoundCreateFunc = new CompoundCreateFunc();
	    m_swappedCompoundCreateFunc = new SwappedCompoundCreateFunc();
	    m_emptyCreateFunc = new EmptyCreateFunc();
	
    	m_sphereSphereCF = new SphereSphereCreateFunc();
//#ifdef USE_BUGGY_SPHERE_BOX_ALGORITHM
//    mem = btAlignedAlloc(sizeof(btSphereBoxCollisionAlgorithm::CreateFunc),16);
//    m_sphereBoxCF = new(mem) btSphereBoxCollisionAlgorithm::CreateFunc;
//    mem = btAlignedAlloc(sizeof(btSphereBoxCollisionAlgorithm::CreateFunc),16);
//    m_boxSphereCF = new (mem)btSphereBoxCollisionAlgorithm::CreateFunc;
//    m_boxSphereCF->m_swapped = true;
//#endif //USE_BUGGY_SPHERE_BOX_ALGORITHM

	    m_sphereTriangleCF = new SphereTriangleCreateFunc();
	    m_triangleSphereCF = new SphereTriangleCreateFunc();
	    m_triangleSphereCF.m_swapped = true;
    	
	    m_boxBoxCF = new BoxBoxCreateFunc();

	    //convex versus plane
	    m_convexPlaneCF = new ConvexPlaneCreateFunc();
	    m_planeConvexCF = new ConvexPlaneCreateFunc();
	    m_planeConvexCF.m_swapped = true;
    	
	    ///calculate maximum element size, big enough to fit any collision algorithm in the memory pool
        //int maxSize = sizeof(btConvexConvexAlgorithm);
        //int maxSize2 = sizeof(btConvexConcaveCollisionAlgorithm);
        //int maxSize3 = sizeof(btCompoundCollisionAlgorithm);
        //int sl = sizeof(btConvexSeparatingDistanceUtil);
        //sl = sizeof(btGjkPairDetector);
        //int	collisionAlgorithmMaxElementSize = btMax(maxSize,maxSize2);
        //collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize,maxSize3);

        //if (constructionInfo.m_stackAlloc)
        //{
        //    m_ownsStackAllocator = false;
        //    this->m_stackAlloc = constructionInfo.m_stackAlloc;
        //} else
        //{
        //    m_ownsStackAllocator = true;
        //    void* mem = btAlignedAlloc(sizeof(btStackAlloc),16);
        //    m_stackAlloc = new(mem)btStackAlloc(constructionInfo.m_defaultStackAllocatorSize);
        //}
    		
        //if (constructionInfo.m_persistentManifoldPool)
        //{
        //    m_ownsPersistentManifoldPool = false;
        //    m_persistentManifoldPool = constructionInfo.m_persistentManifoldPool;
        //} else
        //{
        //    m_ownsPersistentManifoldPool = true;
        //    void* mem = btAlignedAlloc(sizeof(btPoolAllocator),16);
        //    m_persistentManifoldPool = new (mem) btPoolAllocator(sizeof(btPersistentManifold),constructionInfo.m_defaultMaxPersistentManifoldPoolSize);
        //}
    	
        //if (constructionInfo.m_collisionAlgorithmPool)
        //{
        //    m_ownsCollisionAlgorithmPool = false;
        //    m_collisionAlgorithmPool = constructionInfo.m_collisionAlgorithmPool;
        //} else
        //{
        //    m_ownsCollisionAlgorithmPool = true;
        //    void* mem = btAlignedAlloc(sizeof(btPoolAllocator),16);
        //    m_collisionAlgorithmPool = new(mem) btPoolAllocator(collisionAlgorithmMaxElementSize,constructionInfo.m_defaultMaxCollisionAlgorithmPoolSize);
        //}
    }
        //Initialize the physics world
        private void InitializeWorld(DynamicsWorld.InternalTickCallback tickCallBack)
        {
            //Collision configuration and dispatcher
            var collisionConfigInfo = new DefaultCollisionConstructionInfo {
                DefaultMaxCollisionAlgorithmPoolSize = 80000,
                DefaultMaxPersistentManifoldPoolSize = 80000
            };

            _collisionConfig = new DefaultCollisionConfiguration(collisionConfigInfo);

            //Solver Type Config
            switch (_solverType)
            {
            case WorldSolverType.SequentialImpulse:
                _constraintSolver    = new MultiBodyConstraintSolver();
                _collisionDispatcher = new CollisionDispatcher(_collisionConfig);
                break;

            case WorldSolverType.NonSmoothNonLinearConjugate:
                _constraintSolver    = new NncgConstraintSolver();
                _collisionDispatcher = new CollisionDispatcher(_collisionConfig);
                break;

            case WorldSolverType.ExperimentalMultiThreaded:     //EXPERIMENTAL
                switch (_schedulerType)
                {
                case TaskSchedulerType.Sequential:
                    Threads.TaskScheduler = Threads.GetSequentialTaskScheduler();
                    break;

                case TaskSchedulerType.OpenMp:
                    Threads.TaskScheduler = Threads.GetOpenMPTaskScheduler();
                    break;

                case TaskSchedulerType.Ppl:
                    Threads.TaskScheduler = Threads.GetPplTaskScheduler();
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                _threadedSolver = new ConstraintSolverPoolMultiThreaded(_solverThreads);
                Threads.TaskScheduler.NumThreads = _threadPoolSize;
                _collisionDispatcher             = new CollisionDispatcherMultiThreaded(_collisionConfig);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            //Broadphase Type COnfig
            switch (_broadphaseType)
            {
            case WorldBroadphaseType.DynamicAabb:
                _broadphaseInterface = new DbvtBroadphase();
                break;

            case WorldBroadphaseType.AxisSweep:
                _broadphaseInterface = new AxisSweep3(-_axisSweepMargin.ToBullet(), _axisSweepMargin.ToBullet());
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            //Create the physics world
            if (_solverType == WorldSolverType.ExperimentalMultiThreaded)
            {
                _dynamicsWorld = new DiscreteDynamicsWorldMultiThreaded(_collisionDispatcher, _broadphaseInterface, _threadedSolver, _collisionConfig);
            }
            else
            {
                _dynamicsWorld = new DiscreteDynamicsWorld(_collisionDispatcher, _broadphaseInterface, _constraintSolver, _collisionConfig);
            }

            //Configure the physics world
            _dynamicsWorld.SolverInfo.NumIterations = _solverIterations;
            _dynamicsWorld.SolverInfo.SolverMode    = SolverModes.Simd | SolverModes.UseWarmStarting;
            _dynamicsWorld.SetInternalTickCallback(tickCallBack);
            _btGravity = _gravity.ToBullet();
            _dynamicsWorld.SetGravity(ref _btGravity);
            _initlialized = true;
            if (_debugging)
            {
                Debug.Log("<b>Bullet4Unity:</b> Initialized Bullet Physics World");
            }
        }