Esempio n. 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;
 }
Esempio n. 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;
            }
        }
Esempio n. 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);
            }
        }
    }
Esempio n. 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);
 }
Esempio n. 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();
        }
Esempio n. 6
0
		public extern static int dConnectingJointList( dBodyID body1, dBodyID body2, out dJointID[] connectingJoints );
Esempio n. 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;
			}
		}
Esempio n. 8
0
		public extern static void dBodySetAutoDisableDefaults( dBodyID body );
Esempio n. 9
0
		public extern static void dBodySetAutoDisableTime( dBodyID body, dReal time );
Esempio n. 10
0
		public extern static void dBodySetAutoDisableSteps( dBodyID body, int steps );
Esempio n. 11
0
		public extern static void dBodySetAutoDisableAngularThreshold( dBodyID body, dReal angular_threshold );
Esempio n. 12
0
		public extern static int dBodyGetFiniteRotationMode( dBodyID body );
Esempio n. 13
0
		public extern static void dBodySetFiniteRotationMode( dBodyID body, int mode );
Esempio n. 14
0
		public extern static IntPtr dBodyGetData( dBodyID body );
Esempio n. 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);
        }
Esempio n. 16
0
		public extern static int dAreConnectedExcluding( dBodyID body1, dBodyID body2, int joint_type );
Esempio n. 17
0
		public extern static bool DoCCDCast( dNeoAxisAdditionsID additions, dBodyID checkBodyID,
			int contactGroup, out float minDistance );
Esempio n. 18
0
		public extern static void dBodySetFiniteRotationAxis( dBodyID body, dReal x, dReal y, dReal z );
Esempio n. 19
0
		public extern static void dBodySetAutoDisableLinearThreshold( dBodyID body, dReal linear_threshold );
Esempio n. 20
0
		public extern static void dBodyGetFiniteRotationAxis( dBodyID body, ref dVector3 result );
Esempio n. 21
0
		public extern static dReal dBodyGetAutoDisableAngularThreshold( dBodyID body );
Esempio n. 22
0
		public extern static int dBodyGetNumJoints( dBodyID b );
Esempio n. 23
0
		public extern static int dBodyGetAutoDisableSteps( dBodyID body );
Esempio n. 24
0
		public extern static dJointID dBodyGetJoint( dBodyID body, int index );
Esempio n. 25
0
		public extern static dReal dBodyGetAutoDisableTime( dBodyID body );
Esempio n. 26
0
		public extern static void dBodySetGravityMode( dBodyID b, int mode );
Esempio n. 27
0
		public extern static void dJointAttach( dJointID joint, dBodyID body1, dBodyID body2 );
Esempio n. 28
0
		public extern static int dBodyGetGravityMode( dBodyID b );
Esempio n. 29
0
		public extern static dJointID dConnectingJoint( dBodyID body1, dBodyID body2 );
Esempio n. 30
0
		public extern static void dBodyDisable( dBodyID body );
Esempio n. 31
0
		public extern static int dAreConnected( dBodyID body1, dBodyID body2 );
Esempio n. 32
0
		public extern static int dBodyIsEnabled( dBodyID body );
Esempio n. 33
0
		public extern static void dGeomSetBody( dGeomID geom, dBodyID body );
Esempio n. 34
0
		public extern static void dBodySetAutoDisableFlag( dBodyID body, int do_auto_disable );
Esempio n. 35
0
		public extern static IntPtr CreateBodyData( dBodyID bodyID );
Esempio n. 36
0
		public extern static int dBodyGetAutoDisableFlag( dBodyID body );