Esempio n. 1
0
		void UpdateODEJoint()
		{
			bool needCreate = PushedToWorld && !Broken;
			bool created = jointID != dJointID.Zero;

			if( needCreate == created )
				return;

			if( needCreate )
			{
				ODEBody odeBody1 = (ODEBody)Body1;
				ODEBody odeBody2 = (ODEBody)Body2;

				jointID = Ode.dJointCreateFixed( ( (ODEPhysicsScene)Scene ).worldID, IntPtr.Zero );
				Ode.SetJointContactsEnabled( jointID, false );//ContactsEnabled );

				Ode.dJointAttach( jointID, odeBody1.bodyID, odeBody2.bodyID );

				Ode.dJointSetFixed( jointID );

				Ode.BodyDataAddJoint( odeBody1.bodyData, jointID );
				Ode.BodyDataAddJoint( odeBody2.bodyData, jointID );
			}
			else
			{
				DestroyODEJoint();
			}
		}
        void UpdateODEJoint()
        {
            bool needCreate = PushedToWorld && !Broken;
            bool created    = jointID != dJointID.Zero;

            if (needCreate == created)
            {
                return;
            }

            if (needCreate)
            {
                ODEBody odeBody1 = (ODEBody)Body1;
                ODEBody odeBody2 = (ODEBody)Body2;

                jointID = Ode.dJointCreateFixed(((ODEPhysicsScene)Scene).worldID, IntPtr.Zero);
                Ode.SetJointContactsEnabled(jointID, false);                  //ContactsEnabled );

                Ode.dJointAttach(jointID, odeBody1.bodyID, odeBody2.bodyID);

                Ode.dJointSetFixed(jointID);

                Ode.BodyDataAddJoint(odeBody1.bodyData, jointID);
                Ode.BodyDataAddJoint(odeBody2.bodyData, jointID);
            }
            else
            {
                DestroyODEJoint();
            }
        }
        void UpdateODEJoint()
        {
            bool needCreate = PushedToWorld && !Broken;
            bool created    = jointID != dJointID.Zero;

            if (needCreate == created)
            {
                return;
            }

            if (needCreate)
            {
                ODEBody odeBody1 = (ODEBody)Body1;
                ODEBody odeBody2 = (ODEBody)Body2;

                jointID = Ode.dJointCreateSlider(((ODEPhysicsScene)Scene).worldID, IntPtr.Zero);
                Ode.SetJointContactsEnabled(jointID, ContactsEnabled);

                Ode.dJointSetSliderParam(jointID, Ode.dJointParams.dParamFudgeFactor,
                                         Defines.jointFudgeFactor);

                Ode.dJointAttach(jointID, odeBody1.bodyID, odeBody2.bodyID);

                axis.UpdateToLibrary(true);

                Ode.BodyDataAddJoint(odeBody1.bodyData, jointID);
                Ode.BodyDataAddJoint(odeBody2.bodyData, jointID);
            }
            else
            {
                DestroyODEJoint();
            }
        }
Esempio n. 4
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. 5
0
 public Joint(World world, dJointID ptr, OdeJoint.JointType type)
 {
     this.world = world;
     this.type  = type;
     this.ptr   = ptr;
     id         = InstanceMap.Add(this);
     ode.dJointSetData(ptr, (IntPtr)id);
 }
        void UpdateODEJoint()
        {
            bool needCreate = PushedToWorld && !Broken;
            bool created    = jointID != dJointID.Zero;

            if (needCreate == created)
            {
                return;
            }

            if (needCreate)
            {
                if (Math.Abs(Vec3.Dot(axis1.Direction, axis2.Direction)) > .095f)
                {
                    Log.Warning("UniversalJoint: Invalid axes.");
                    return;
                }
                if (Axis1.LimitsEnabled && Axis1.LimitLow > Axis1.LimitHigh)
                {
                    Log.Warning("UniversalJoint: Invalid axis1 limits (low > high).");
                    return;
                }
                if (Axis2.LimitsEnabled && Axis2.LimitLow > Axis2.LimitHigh)
                {
                    Log.Warning("UniversalJoint: Invalid axis2 limits (low > high).");
                    return;
                }

                ODEBody odeBody1 = (ODEBody)Body1;
                ODEBody odeBody2 = (ODEBody)Body2;

                jointID = Ode.dJointCreateUniversal(((ODEPhysicsScene)Scene).worldID, IntPtr.Zero);
                Ode.SetJointContactsEnabled(jointID, ContactsEnabled);

                Ode.dJointSetUniversalParam(jointID, Ode.dJointParams.dParamFudgeFactor,
                                            Defines.jointFudgeFactor);
                Ode.dJointSetUniversalParam(jointID, Ode.dJointParams.dParamFudgeFactor2,
                                            Defines.jointFudgeFactor);

                Ode.dJointAttach(jointID, odeBody1.bodyID, odeBody2.bodyID);

                Ode.dJointSetUniversalAnchor(jointID, Anchor.X, Anchor.Y, Anchor.Z);

                axis1.UpdateToLibrary(true);
                axis2.UpdateToLibrary(true);

                axis1LocalAxis = Body1.Rotation.GetInverse() * axis1.Direction;
                axis2LocalAxis = Body1.Rotation.GetInverse() * axis2.Direction;

                Ode.BodyDataAddJoint(odeBody1.bodyData, jointID);
                Ode.BodyDataAddJoint(odeBody2.bodyData, jointID);
            }
            else
            {
                DestroyODEJoint();
            }
        }
Esempio n. 7
0
File: Utils.cs Progetto: whztt07/SDK
		internal static void FreeJointFeedback( dJointID jointID )
		{
			IntPtr jointFeedback = Ode.dJointGetFeedbackAsIntPtr( jointID );
			if( jointFeedback != IntPtr.Zero )
			{
				Ode.dFree( jointFeedback, (uint)Marshal.SizeOf( typeof( Ode.dJointFeedback ) ) );
				jointFeedback = IntPtr.Zero;
			}
		}
Esempio n. 8
0
        internal static void FreeJointFeedback(dJointID jointID)
        {
            IntPtr jointFeedback = Ode.dJointGetFeedbackAsIntPtr(jointID);

            if (jointFeedback != IntPtr.Zero)
            {
                Ode.dFree(jointFeedback, (uint)Marshal.SizeOf(typeof(Ode.dJointFeedback)));
                jointFeedback = IntPtr.Zero;
            }
        }
Esempio n. 9
0
        internal Joint(dJointID joint, World world, JointGroup group)
        {
            id     = joint;
            handle = GCHandle.Alloc(this);
            NativeMethods.dJointSetData(id, GCHandle.ToIntPtr(handle));
            id.Owner = world;

            if (group != null)
            {
                group.Add(this);
            }
        }
Esempio n. 10
0
        internal void DestroyODEJoint()
        {
            if (jointID != dJointID.Zero)
            {
                ODEBody odeBody1 = (ODEBody)Body1;
                ODEBody odeBody2 = (ODEBody)Body2;

                Ode.BodyDataRemoveJoint(odeBody1.bodyData, jointID);
                Ode.BodyDataRemoveJoint(odeBody2.bodyData, jointID);

                Utils.FreeJointFeedback(jointID);
                Ode.dJointDestroy(jointID);
                jointID = dJointID.Zero;
            }
        }
Esempio n. 11
0
		internal void DestroyODEJoint()
		{
			if( jointID != dJointID.Zero )
			{
				ODEBody odeBody1 = (ODEBody)Body1;
				ODEBody odeBody2 = (ODEBody)Body2;

				Ode.BodyDataRemoveJoint( odeBody1.bodyData, jointID );
				Ode.BodyDataRemoveJoint( odeBody2.bodyData, jointID );

				Utils.FreeJointFeedback( jointID );
				Ode.dJointDestroy( jointID );
				jointID = dJointID.Zero;
			}
		}
Esempio n. 12
0
File: Utils.cs Progetto: whztt07/SDK
		internal static bool UpdateJointBreakState( Joint joint, dJointID jointID )
		{
			if( jointID == dJointID.Zero )
				return false;

			float force;
			float torque;
			CalculateJointStress( jointID, out force, out torque );

			if( joint.BreakMaxForce != 0 && force >= joint.BreakMaxForce )
				return true;
			if( joint.BreakMaxTorque != 0 && torque >= joint.BreakMaxTorque )
				return true;
			return false;
		}
Esempio n. 13
0
        void UpdateODEJoint()
        {
            bool needCreate = PushedToWorld && !Broken;
            bool created    = jointID != dJointID.Zero;

            if (needCreate == created)
            {
                return;
            }

            if (needCreate)
            {
                if (Axis.LimitsEnabled && Axis.LimitLow > Axis.LimitHigh)
                {
                    Log.Warning("HingeJoint: Invalid axis limits (low > high).");
                    return;
                }

                ODEBody odeBody1 = (ODEBody)Body1;
                ODEBody odeBody2 = (ODEBody)Body2;

                jointID = Ode.dJointCreateHinge(((ODEPhysicsScene)Scene).worldID, IntPtr.Zero);
                Ode.SetJointContactsEnabled(jointID, ContactsEnabled);

                Ode.dJointSetHingeParam(jointID, Ode.dJointParams.dParamFudgeFactor,
                                        Defines.jointFudgeFactor);

                Ode.dJointAttach(jointID, odeBody1.bodyID, odeBody2.bodyID);

                Ode.dJointSetHingeAnchor(jointID, Anchor.X, Anchor.Y, Anchor.Z);

                axis.UpdateToLibrary(true);

                Ode.BodyDataAddJoint(odeBody1.bodyData, jointID);
                Ode.BodyDataAddJoint(odeBody2.bodyData, jointID);
            }
            else
            {
                DestroyODEJoint();
            }
        }
Esempio n. 14
0
        internal static bool UpdateJointBreakState(Joint joint, dJointID jointID)
        {
            if (jointID == dJointID.Zero)
            {
                return(false);
            }

            float force;
            float torque;

            CalculateJointStress(jointID, out force, out torque);

            if (joint.BreakMaxForce != 0 && force >= joint.BreakMaxForce)
            {
                return(true);
            }
            if (joint.BreakMaxTorque != 0 && torque >= joint.BreakMaxTorque)
            {
                return(true);
            }
            return(false);
        }
Esempio n. 15
0
File: Utils.cs Progetto: whztt07/SDK
		unsafe internal static void CalculateJointStress( dJointID jointID,
			out float force, out float torque )
		{
			IntPtr jointFeedback = Ode.dJointGetFeedbackAsIntPtr( jointID );

			if( jointFeedback == IntPtr.Zero )
			{
				//create jointFeedback and begin use on next simulation step

				jointFeedback = Ode.dAlloc( (uint)Marshal.SizeOf( typeof( Ode.dJointFeedback ) ) );

				//zero memory
				unsafe
				{
					Ode.dJointFeedback* p = (Ode.dJointFeedback*)jointFeedback;
					p->f1 = new Ode.dVector3();
					p->t1 = new Ode.dVector3();
					p->f2 = new Ode.dVector3();
					p->t2 = new Ode.dVector3();
				}
				Ode.dJointSetFeedbackAsIntPtr( jointID, jointFeedback );

				force = 0;
				torque = 0;
				return;
			}

			Ode.dJointFeedback* ptr = (Ode.dJointFeedback*)jointFeedback;
			Vec3 f1 = Convert.ToNet( ptr->f1 );
			Vec3 t1 = Convert.ToNet( ptr->t1 );
			Vec3 f2 = Convert.ToNet( ptr->f2 );
			Vec3 t2 = Convert.ToNet( ptr->t2 );

			// This is a simplification, but it should still work.
			force = ( f1 - f2 ).Length();
			torque = ( t1 - t2 ).Length();
		}
Esempio n. 16
0
        unsafe internal static void CalculateJointStress(dJointID jointID,
                                                         out float force, out float torque)
        {
            IntPtr jointFeedback = Ode.dJointGetFeedbackAsIntPtr(jointID);

            if (jointFeedback == IntPtr.Zero)
            {
                //create jointFeedback and begin use on next simulation step

                jointFeedback = Ode.dAlloc((uint)Marshal.SizeOf(typeof(Ode.dJointFeedback)));

                //zero memory
                unsafe
                {
                    Ode.dJointFeedback *p = (Ode.dJointFeedback *)jointFeedback;
                    p->f1 = new Ode.dVector3();
                    p->t1 = new Ode.dVector3();
                    p->f2 = new Ode.dVector3();
                    p->t2 = new Ode.dVector3();
                }
                Ode.dJointSetFeedbackAsIntPtr(jointID, jointFeedback);

                force  = 0;
                torque = 0;
                return;
            }

            Ode.dJointFeedback *ptr = (Ode.dJointFeedback *)jointFeedback;
            Vec3 f1 = Convert.ToNet(ptr->f1);
            Vec3 t1 = Convert.ToNet(ptr->t1);
            Vec3 f2 = Convert.ToNet(ptr->f2);
            Vec3 t2 = Convert.ToNet(ptr->t2);

            // This is a simplification, but it should still work.
            force  = (f1 - f2).Length();
            torque = (t1 - t2).Length();
        }
Esempio n. 17
0
		public extern static int dJointGetAMotorAxisRel( dJointID joint, int anum );
Esempio n. 18
0
		public extern static void dJointSetAMotorAxis( dJointID joint, int anum, int rel,
			dReal x, dReal y, dReal z );
Esempio n. 19
0
		public extern static void dJointSetAMotorNumAxes( dJointID joint, int num );
Esempio n. 20
0
		public extern static void dJointSetAMotorMode( dJointID joint, int mode );
Esempio n. 21
0
		public extern static dReal dJointGetUniversalAngle2Rate( dJointID joint );
Esempio n. 22
0
		public extern static dReal dJointGetUniversalParam( dJointID joint, dJointParams parameter );
Esempio n. 23
0
		public extern static void BodyDataRemoveJoint( IntPtr bodyData, dJointID jointID );
Esempio n. 24
0
 internal override dReal GetParam(dJointID id, dJointParam parameter)
 {
     return(NativeMethods.dJointGetPistonParam(id, parameter));
 }
Esempio n. 25
0
 internal abstract dReal GetParam(dJointID id, dJointParam parameter);
Esempio n. 26
0
 internal abstract void SetParam(dJointID id, dJointParam parameter, dReal value);
Esempio n. 27
0
 public UniversalJoint(World world, dJointID ptr) : base(world, ptr, OdeJoint.JointType.Universal)
 {
 }
Esempio n. 28
0
 public AMotor(World world, dJointID ptr) : base(world, ptr, OdeJoint.JointType.AMotor)
 {
 }
Esempio n. 29
0
 public BallJoint(World world, dJointID ptr) : base(world, ptr, OdeJoint.JointType.Ball)
 {
 }
Esempio n. 30
0
		public extern static dReal dJointGetAMotorAngleRate( dJointID joint, int anum );
Esempio n. 31
0
		public extern static dReal dJointGetAMotorParam( dJointID joint, dJointParams parameter );
Esempio n. 32
0
 internal override void SetParam(dJointID id, dJointParam parameter, dReal value)
 {
     NativeMethods.dJointSetPistonParam(id, parameter, value);
 }
Esempio n. 33
0
 public HingeJoint(World world, dJointID ptr) : base(world, ptr, OdeJoint.JointType.Hinge)
 {
 }
Esempio n. 34
0
 internal JointLimitMotor(Joint joint, int axis)
 {
     id    = joint.id;
     index = axis;
 }
Esempio n. 35
0
		public extern static void dJointAddUniversalTorques( dJointID joint, dReal torque1, dReal torque2 );
Esempio n. 36
0
        void UpdateODEJoint()
        {
            bool needCreate = PushedToWorld && !Broken;
            bool created    = jointID != dJointID.Zero;

            ODEBody odeBody1 = (ODEBody)Body1;
            ODEBody odeBody2 = (ODEBody)Body2;

            if (needCreate && (odeBody1.bodyID == dBodyID.Zero || odeBody2.bodyID == dBodyID.Zero))
            {
                Log.Warning("ODEHinge2Joint: It is necessary that both bodies were not static.");
                needCreate = false;
            }

            if (needCreate == created)
            {
                return;
            }

            if (needCreate)
            {
                if (Math.Abs(Vec3.Dot(axis1.Direction, axis2.Direction)) > .095f)
                {
                    Log.Warning("Hinge2Joint: Invalid axes.");
                    return;
                }
                if (Axis1.LimitsEnabled && Axis1.LimitLow > Axis1.LimitHigh)
                {
                    Log.Warning("Hinge2Joint: Invalid axis1 limits (low > high).");
                    return;
                }
                if (Axis2.LimitsEnabled && Axis2.LimitLow > Axis2.LimitHigh)
                {
                    Log.Warning("Hinge2Joint: Invalid axis2 limits (low > high).");
                    return;
                }

                jointID = Ode.dJointCreateHinge2(((ODEPhysicsScene)Scene).worldID, IntPtr.Zero);
                Ode.SetJointContactsEnabled(jointID, ContactsEnabled);

                Ode.dJointSetHinge2Param(jointID, Ode.dJointParams.dParamFudgeFactor,
                                         Defines.jointFudgeFactor);
                Ode.dJointSetHinge2Param(jointID, Ode.dJointParams.dParamFudgeFactor2,
                                         Defines.jointFudgeFactor);

                Ode.dJointAttach(jointID, odeBody1.bodyID, odeBody2.bodyID);

                Ode.dJointSetHinge2Anchor(jointID, Anchor.X, Anchor.Y, Anchor.Z);

                axis1.UpdateToLibrary(true);
                axis2.UpdateToLibrary(true);

                UpdateSuspension();

                Ode.BodyDataAddJoint(odeBody1.bodyData, jointID);
                Ode.BodyDataAddJoint(odeBody2.bodyData, jointID);
            }
            else
            {
                DestroyODEJoint();
            }
        }
Esempio n. 37
0
		public extern static void dJointSetFixed( dJointID joint );
Esempio n. 38
0
		public extern static void dJointGetHinge2Axis2( dJointID joint, ref dVector3 result );
Esempio n. 39
0
		public extern static int dJointGetAMotorMode( dJointID joint );
Esempio n. 40
0
		public extern static dReal dJointGetHinge2Angle2Rate( dJointID joint );
Esempio n. 41
0
		public extern static int dJointGetAMotorNumAxes( dJointID joint );
Esempio n. 42
0
		public extern static dReal dJointGetHinge2Param( dJointID joint, dJointParams parameter );
Esempio n. 43
0
		public extern static void dJointGetAMotorAxis( dJointID joint, int anum, ref dVector3 result );
Esempio n. 44
0
		public extern static void dJointAddHinge2Torques( dJointID joint, dReal torque1, dReal torque2 );
Esempio n. 45
0
		public extern static void dJointSetAMotorAngle( dJointID joint, int anum, dReal angle );
Esempio n. 46
0
		public extern static void dJointSetUniversalAxis2( dJointID joint, dReal x, dReal y, dReal z );
Esempio n. 47
0
		public extern static void dJointSetAMotorParam( dJointID joint, dJointParams parameter, dReal value );
Esempio n. 48
0
		public extern static void dJointGetUniversalAxis2( dJointID joint, ref dVector3 result );
Esempio n. 49
0
		public extern static void dJointAddAMotorTorques( dJointID joint, dReal torque1, dReal torque2, dReal torque3 );
Esempio n. 50
0
		public extern static void dJointSetUniversalParam( dJointID joint, dJointParams parameter, dReal value );
Esempio n. 51
0
		public extern static void SetJointContactsEnabled( dJointID jointID,
			[MarshalAs( UnmanagedType.U1 )] bool contactsEnabled );
Esempio n. 52
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);
        }