/// <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; }
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; } }
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); } } }
public Body(World world) { this.world = world; world.AddBody(this); ptr = ode.dBodyCreate(world.ptr); id = InstanceMap.Add(this); ode.dBodySetData(ptr, (IntPtr)id); }
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(); }
public extern static int dConnectingJointList( dBodyID body1, dBodyID body2, out dJointID[] connectingJoints );
/// <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; } }
public extern static void dBodySetAutoDisableDefaults( dBodyID body );
public extern static void dBodySetAutoDisableTime( dBodyID body, dReal time );
public extern static void dBodySetAutoDisableSteps( dBodyID body, int steps );
public extern static void dBodySetAutoDisableAngularThreshold( dBodyID body, dReal angular_threshold );
public extern static int dBodyGetFiniteRotationMode( dBodyID body );
public extern static void dBodySetFiniteRotationMode( dBodyID body, int mode );
public extern static IntPtr dBodyGetData( dBodyID body );
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); }
public extern static int dAreConnectedExcluding( dBodyID body1, dBodyID body2, int joint_type );
public extern static bool DoCCDCast( dNeoAxisAdditionsID additions, dBodyID checkBodyID, int contactGroup, out float minDistance );
public extern static void dBodySetFiniteRotationAxis( dBodyID body, dReal x, dReal y, dReal z );
public extern static void dBodySetAutoDisableLinearThreshold( dBodyID body, dReal linear_threshold );
public extern static void dBodyGetFiniteRotationAxis( dBodyID body, ref dVector3 result );
public extern static dReal dBodyGetAutoDisableAngularThreshold( dBodyID body );
public extern static int dBodyGetNumJoints( dBodyID b );
public extern static int dBodyGetAutoDisableSteps( dBodyID body );
public extern static dJointID dBodyGetJoint( dBodyID body, int index );
public extern static dReal dBodyGetAutoDisableTime( dBodyID body );
public extern static void dBodySetGravityMode( dBodyID b, int mode );
public extern static void dJointAttach( dJointID joint, dBodyID body1, dBodyID body2 );
public extern static int dBodyGetGravityMode( dBodyID b );
public extern static dJointID dConnectingJoint( dBodyID body1, dBodyID body2 );
public extern static void dBodyDisable( dBodyID body );
public extern static int dAreConnected( dBodyID body1, dBodyID body2 );
public extern static int dBodyIsEnabled( dBodyID body );
public extern static void dGeomSetBody( dGeomID geom, dBodyID body );
public extern static void dBodySetAutoDisableFlag( dBodyID body, int do_auto_disable );
public extern static IntPtr CreateBodyData( dBodyID bodyID );
public extern static int dBodyGetAutoDisableFlag( dBodyID body );