Beispiel #1
0
        public void NearCallback(IntPtr data, IntPtr Geom1, IntPtr Geom2)
        {
            int    MAX_COLLISIONS = 20;
            IntPtr body1          = Ode.dGeomGetBody(Geom1);
            IntPtr body2          = Ode.dGeomGetBody(Geom2);

            if (body1 != IntPtr.Zero &&
                body2 != IntPtr.Zero &&
                Ode.dAreConnectedExcluding(body1, body2, (int)Ode.dJointTypes.dJointTypeContact) == 1)
            {
                return;
            }

            Ode.dContactGeom[] contactGeoms = new Ode.dContactGeom[MAX_COLLISIONS];

            int numContacts = Ode.dCollide(Geom1, Geom2, MAX_COLLISIONS, contactGeoms,
                                           System.Runtime.InteropServices.Marshal.SizeOf(contactGeoms[0]));

            Ode.dContact[] contacts = new Ode.dContact[numContacts];
            for (int i = 0; i < numContacts; i++)
            {
                contacts[i].surface.mode       = (int)(Ode.dContactFlags.dContactApprox1);
                contacts[i].surface.mu         = Ode.dInfinity;
                contacts[i].surface.mu2        = 0;
                contacts[i].surface.bounce     = 0.01f;
                contacts[i].surface.bounce_vel = 0.01f;
                //contacts[i].surface.soft_erp = 0.5f;
                contacts[i].surface.soft_cfm = 0.001f;
                contacts[i].geom             = contactGeoms[i];

                IntPtr joint = Ode.dJointCreateContact(hostWorld.getID(), contactGroup, ref contacts[i]);
                Ode.dJointAttach(joint, body1, body2);
            }
        }
Beispiel #2
0
        public BodyBox(World hostWorld, Space space, Vector3f position, Vector3f size, Vector3f force)
        {
            this.hostWorld = hostWorld;
            this.space = space;

            bodyID = Ode.dBodyCreate(hostWorld.getID());

            // create a mass object, in this case a box of size 50 x 0.2 x 50
            Ode.dMass mass = new Ode.dMass();
            //Ode.dMassSetBox(ref mass, 200.0f, radius, radius, radius);
            Ode.dMassSetBoxTotal(ref mass, 200.0f, size.x, size.y, size.z);
            // set it's mass to 1000.0f. If this value is too low,
            // you'll get some wierd collisions
            //mass.mass = 1000.0f;

            // set the mass object on the body
            Ode.dBodySetMass(bodyID, ref mass);

            // Set the body's position
            Ode.dBodySetPosition(bodyID, position.x, position.y, position.z);

            // Set an initial force on the body. This will be
            // wiped to zero after the first frame.
            Ode.dBodyAddForce( bodyID, force.x, force.y, force.z );

            // create a collion geometry to go with our rigid body.
            // without this, the rigid body will not collide with anything.
            geomID = Ode.dCreateBox(space.getSpaceID(), size.x, size.y, size.z);

            // assign a rigid body to the collision geometry. If we didn't do this,
            // the object would be a static object much like our ground plane.
            Ode.dGeomSetBody(geomID, bodyID);

            this.position = position.copy();
            this.rotationOGL = new Color4f(0.0f, 0.0f, 0.0f, 0.0f);
        }
Beispiel #3
0
        public BodyBox(World hostWorld, Space space, Vector3f position, Vector3f size, Vector3f force)
        {
            this.hostWorld = hostWorld;
            this.space     = space;

            bodyID = Ode.dBodyCreate(hostWorld.getID());

            // create a mass object, in this case a box of size 50 x 0.2 x 50
            Ode.dMass mass = new Ode.dMass();
            //Ode.dMassSetBox(ref mass, 200.0f, radius, radius, radius);
            Ode.dMassSetBoxTotal(ref mass, 200.0f, size.x, size.y, size.z);
            // set it's mass to 1000.0f. If this value is too low,
            // you'll get some wierd collisions
            //mass.mass = 1000.0f;

            // set the mass object on the body
            Ode.dBodySetMass(bodyID, ref mass);

            // Set the body's position
            Ode.dBodySetPosition(bodyID, position.x, position.y, position.z);

            // Set an initial force on the body. This will be
            // wiped to zero after the first frame.
            Ode.dBodyAddForce(bodyID, force.x, force.y, force.z);

            // create a collion geometry to go with our rigid body.
            // without this, the rigid body will not collide with anything.
            geomID = Ode.dCreateBox(space.getSpaceID(), size.x, size.y, size.z);

            // assign a rigid body to the collision geometry. If we didn't do this,
            // the object would be a static object much like our ground plane.
            Ode.dGeomSetBody(geomID, bodyID);

            this.position    = position.copy();
            this.rotationOGL = new Color4f(0.0f, 0.0f, 0.0f, 0.0f);
        }