Example #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Body"/> class on the
 /// specified world.
 /// </summary>
 /// <param name="world">The world on which to place the body.</param>
 public Body(World world)
 {
     handle = GCHandle.Alloc(this);
     id     = NativeMethods.dBodyCreate(world.Id);
     NativeMethods.dBodySetData(id, GCHandle.ToIntPtr(handle));
     id.Owner = world;
 }
Example #2
0
        void PopFromWorld()
        {
            //destroy ODE joints
            if (RelatedJoints != null)
            {
                for (int n = 0; n < RelatedJoints.Count; n++)
                {
                    ODEPhysicsWorld.Instance.DestroyODEJoint(RelatedJoints[n]);
                }
            }

            DestroyGeomDatas();

            if (bodyID != IntPtr.Zero)
            {
                Ode.dBodyDestroy(bodyID);
                bodyID = IntPtr.Zero;
            }

            if (bodyData != IntPtr.Zero)
            {
                Ode.DestroyBodyData(bodyData);
                bodyData = IntPtr.Zero;
            }
        }
Example #3
0
    void nearCallback(IntPtr data, dGeomID o1, dGeomID o2)
    {
        dBodyID b1 = ode.dGeomGetBody(o1);
        dBodyID b2 = ode.dGeomGetBody(o2);

        const int MAX_CONTACTS = 5;

        ode.dContact[] contact = new ode.dContact[MAX_CONTACTS];

        for (int i = 0; i < MAX_CONTACTS; i++)
        {
            contact[i].surface.mode       = (int)(ode.dContactType.Bounce | ode.dContactType.SoftCFM);
            contact[i].surface.mu         = Mathf.Infinity;
            contact[i].surface.mu2        = 0;
            contact[i].surface.bounce     = 0.01f;
            contact[i].surface.bounce_vel = 0.1f;
            contact[i].surface.soft_cfm   = 0.01f;
        }

        int numc = ode.dCollide(o1, o2, MAX_CONTACTS, ref contact[0].geom, System.Runtime.InteropServices.Marshal.SizeOf(typeof(ode.dContact)));

        if (numc > 0)
        {
            for (int i = 0; i < numc; i++)
            {
                dJointID c = ode.dJointCreateContact(world, contactgroup, ref contact[i]);
                ode.dJointAttach(c, b1, b2);
            }
        }
    }
Example #4
0
 public Body(World world)
 {
     this.world = world;
     world.AddBody(this);
     ptr = ode.dBodyCreate(world.ptr);
     id  = InstanceMap.Add(this);
     ode.dBodySetData(ptr, (IntPtr)id);
 }
Example #5
0
        void PushToWorld()
        {
            if (!Static)
            {
                bodyID = Ode.dBodyCreate(scene.worldID);

                UpdateSleepiness();

                Ode.dBodySetPosition(bodyID, Position.X, Position.Y, Position.Z);

                Ode.dQuaternion odeQuat;
                Convert.ToODE(Rotation, out odeQuat);
                Ode.dBodySetQuaternion(bodyID, ref odeQuat);

                Ode.dBodySetLinearVel(bodyID, LinearVelocity.X, LinearVelocity.Y, LinearVelocity.Z);
                Ode.dBodySetAngularVel(bodyID, AngularVelocity.X, AngularVelocity.Y, AngularVelocity.Z);

                if (Sleeping)
                {
                    Ode.dBodyDisable(bodyID);
                }
                else
                {
                    Ode.dBodyEnable(bodyID);
                }

                if (!EnableGravity)
                {
                    Ode.dBodySetGravityMode(bodyID, 0);
                }
            }

            bodyData = Ode.CreateBodyData(bodyID);

            CreateGeomDatas();

            //no shapes
            if (geomDatas == null || geomDatas.Length == 0)
            {
                PopFromWorld();
                return;
            }

            if (!Static)
            {
                CalculateBodyMass();
            }

            RecreateAttachedJoints();
        }
Example #6
0
		public extern static int dConnectingJointList( dBodyID body1, dBodyID body2, out dJointID[] connectingJoints );
Example #7
0
		/// <summary>
		/// Get the jointfeedback structure from the joint to get information about
		/// the forces applied by each joint.
		///
		/// 	The feedback information structure is defined as follows (NOTE: C# version listed here):
		/// 			public struct dJointFeedback {
		///					public dVector3 f1;		/* force that joint applies to body 1  */
		///					public dVector3 t1;		/* torque that joint applies to body 1 */
		///					public dVector3 f2;		/* force that joint applies to body 2  */
		///					public dVector3 t2;		/* torque that joint applies to body 2 */
		///				};
		///
		/// 	The dJointGetFeedback() function returns the current feedback structure pointer,
		/// 	or 0 if none is used (this is the default).
		/// 	TODO: Will passing 0 work or does something special have to be done?
		/// </summary>
		/// <returns>A dJointFeedback</returns>
		/// <param name="body">A  dBodyID</param>
		public static dJointFeedback dJointGetFeedback( dBodyID body )
		{
			unsafe
			{
				dJointFeedback* v = (dJointFeedback*)dJointGetFeedback_( body );
				return *v;
			}
		}
Example #8
0
		public extern static void dBodySetAutoDisableDefaults( dBodyID body );
Example #9
0
		public extern static void dBodySetAutoDisableTime( dBodyID body, dReal time );
Example #10
0
		public extern static void dBodySetAutoDisableSteps( dBodyID body, int steps );
Example #11
0
		public extern static void dBodySetAutoDisableAngularThreshold( dBodyID body, dReal angular_threshold );
Example #12
0
		public extern static int dBodyGetFiniteRotationMode( dBodyID body );
Example #13
0
		public extern static void dBodySetFiniteRotationMode( dBodyID body, int mode );
Example #14
0
		public extern static IntPtr dBodyGetData( dBodyID body );
Example #15
0
        void OnNewContact(ref ode.dContact contact, dBodyID body1, dBodyID body2)
        {
            dJointID c = ode.dJointCreateContact(world.ptr, world.contactgroup, ref contact);

            ode.dJointAttach(c, body1, body2);
        }
Example #16
0
		public extern static int dAreConnectedExcluding( dBodyID body1, dBodyID body2, int joint_type );
Example #17
0
		public extern static bool DoCCDCast( dNeoAxisAdditionsID additions, dBodyID checkBodyID,
			int contactGroup, out float minDistance );
Example #18
0
		public extern static void dBodySetFiniteRotationAxis( dBodyID body, dReal x, dReal y, dReal z );
Example #19
0
		public extern static void dBodySetAutoDisableLinearThreshold( dBodyID body, dReal linear_threshold );
Example #20
0
		public extern static void dBodyGetFiniteRotationAxis( dBodyID body, ref dVector3 result );
Example #21
0
		public extern static dReal dBodyGetAutoDisableAngularThreshold( dBodyID body );
Example #22
0
		public extern static int dBodyGetNumJoints( dBodyID b );
Example #23
0
		public extern static int dBodyGetAutoDisableSteps( dBodyID body );
Example #24
0
		public extern static dJointID dBodyGetJoint( dBodyID body, int index );
Example #25
0
		public extern static dReal dBodyGetAutoDisableTime( dBodyID body );
Example #26
0
		public extern static void dBodySetGravityMode( dBodyID b, int mode );
Example #27
0
		public extern static void dJointAttach( dJointID joint, dBodyID body1, dBodyID body2 );
Example #28
0
		public extern static int dBodyGetGravityMode( dBodyID b );
Example #29
0
		public extern static dJointID dConnectingJoint( dBodyID body1, dBodyID body2 );
Example #30
0
		public extern static void dBodyDisable( dBodyID body );
Example #31
0
		public extern static int dAreConnected( dBodyID body1, dBodyID body2 );
Example #32
0
		public extern static int dBodyIsEnabled( dBodyID body );
Example #33
0
		public extern static void dGeomSetBody( dGeomID geom, dBodyID body );
Example #34
0
		public extern static void dBodySetAutoDisableFlag( dBodyID body, int do_auto_disable );
Example #35
0
		public extern static IntPtr CreateBodyData( dBodyID bodyID );
Example #36
0
		public extern static int dBodyGetAutoDisableFlag( dBodyID body );