Exemplo n.º 1
0
        public void Create()
        {
            MaxIterationCount = ODEPhysicsWorld.Instance.defaultMaxIterationCount;

            worldID = Ode.dWorldCreate();

            //Ode.dVector3 center = new Ode.dVector3( 0, 0, 0 );
            //Ode.dVector3 extents = new Ode.dVector3( 1000, 1000, 1000 );
            //rootSpaceID = Ode.dQuadTreeSpaceCreate( dSpaceID.Zero, ref center, ref extents, 10 );
            rootSpaceID = Ode.dHashSpaceCreate(dSpaceID.Zero);
            Ode.dHashSpaceSetLevels(rootSpaceID, ODEPhysicsWorld.Instance.hashSpaceMinLevel,
                                    ODEPhysicsWorld.Instance.hashSpaceMaxLevel);

            // Create the ODE contact joint group.
            contactJointGroupID = Ode.dJointGroupCreate(0);

            // Set the ODE global CFM value that will be used by all Joints
            // (including contacts).  This affects normal Joint constraint
            // operation and Joint limits.  The user cannot adjust CFM, but
            // they can adjust ERP (a.k.a. bounciness/restitution) for materials
            // (i.e. contact settings) and Joint limits.
            Ode.dWorldSetCFM(worldID, Defines.globalCFM);

            // Set the ODE global ERP value.  This will only be used for Joints
            // under normal conditions, not at their limits.  Also, it will not
            // affect contacts at all since they use material properties to
            // calculate ERP.
            Ode.dWorldSetERP(worldID, 0.5f * (Defines.maxERP + Defines.minERP));

            Ode.dWorldSetContactSurfaceLayer(worldID, Defines.surfaceLayer);

            //MaxIterationCount = maxIterationCount;

            //ray for RayCast
            rayCastGeomID = Ode.dCreateRay(rootSpaceID, 1);
            Ode.dGeomSetData(rayCastGeomID, IntPtr.Zero);

            rayCastResultDistanceComparer = new Comparison <RayCastResult>(SortRayCastResultsMethod);

            unsafe
            {
                Ode.CheckEnumAndStructuresSizes(sizeof(Ode.CollisionEventData),
                                                sizeof(Ode.RayCastResult));
            }

            neoAxisAdditionsID = Ode.NeoAxisAdditions_Init(Defines.maxContacts, Defines.minERP,
                                                           Defines.maxERP, Defines.maxFriction, Defines.bounceThreshold, worldID, rootSpaceID,
                                                           rayCastGeomID, contactJointGroupID);

            UpdateMaxIterationCount();
            UpdateGravity();
            UpdateMaxAngularSpeed();

            for (int group0 = 0; group0 < 32; group0++)
            {
                for (int group1 = 0; group1 < 32; group1++)
                {
                    OnUpdateContactGroups(group0, group1, IsContactGroupsContactable(group0, group1));
                }
            }
        }