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