private void LinkCookieWithAllRopes() { SphereRigid cookie = StaticData.EngineManager.CookieRB; List <SpringService> allRopes = StaticData.EngineManager.SpringsManagerEngine.ListOfServices; for (int i = 0; i < allRopes.Count; i++) { if (!(allRopes[i] is CatchableRopeService)) { allRopes[i].ApplyServiceOnRigid(cookie); } } }
public Rod(Vector3 positionXNA, Vector3 gravityVector, int spacing, int rigidHalfSize, float rodLinkHeight, float forgivingFactor) { SphereRigid rigidOne = DefaultAdder.GetDefaultSphere(positionXNA, Material.Steel, rigidHalfSize, gravityVector, null, null, 0, false); SphereRigid rigidTwo = DefaultAdder.GetDefaultSphere(positionXNA + new Vector3(spacing, 0, 0), Material.Steel, rigidHalfSize, gravityVector, null, null, 0, false); MakeRod(rigidOne, rigidTwo, spacing, rodLinkHeight, forgivingFactor); }
public SphereRigid AddSphereRigidToEngine() { SphereRigid SphereRigidCreated = DefaultAdder.GetDefaultSphere( new Vector3(mouseState.X - 3, (mouseState.Y - 3), 0), Material.Steel, StaticData.CircleDefaultSize, new Vector3(0, -9.8f, 0), null, null, 0, false); StaticData.EngineManager.RigidsManagerEngine.ListOfSphereRigids.Add(SphereRigidCreated); return(SphereRigidCreated); }
public static bool sphereAndHalfSpace( SphereRigid sphere, CollisionPlane plane, ref CollisionData data ) { // Make sure we have contacts if (data.contactsLeft <= 0) { return(false); } // Cache the sphere position Vector3 position = sphere.PositionCenterEngine; // Find the distance from the plane float ballDistance = Vector3.Dot(plane.Direction, position) - sphere.Radius - plane.Offset; if (ballDistance >= 0) { return(false); } Contact c = new Contact(); c.ContactNormal = plane.Direction; c.Penetration = -ballDistance; c.ContactPoint = position - plane.Direction * (ballDistance + sphere.Radius); c.SetBodyData(sphere, null, data.friction, data.restitution); c.ContactToWorld.M11 = plane.Direction.X; c.ContactToWorld.M12 = -plane.Direction.Y; c.ContactToWorld.M21 = plane.Direction.Y; c.ContactToWorld.M22 = plane.Direction.X; data.contacts.Add(c); sphere.SetCanSleep(true); data.addContacts(1); return(true); }
public static bool sphereAndSphere( SphereRigid one, SphereRigid two, ref CollisionData data ) { // Cache the sphere positions Vector3 positionOne = one.PositionCenterEngine; Vector3 positionTwo = two.PositionCenterEngine; // Find the vector between the objects Vector3 midline = positionOne - positionTwo; float size = midline.Length(); // See if it is large enough. if (size <= 0.0f || size >= one.Radius + two.Radius) { return(false); } // We manually create the normal, because we have the // size to hand. Vector3 normal = midline * (((float)1.0) / size); Contact c = new Contact(); c.ContactNormal = normal; c.ContactPoint = positionTwo + midline * (float)0.5; c.Penetration = (one.Radius + two.Radius - size); c.SetBodyData(one, two, data.friction, data.restitution); c.ContactToWorld.M11 = normal.X; c.ContactToWorld.M12 = -normal.Y; c.ContactToWorld.M21 = normal.Y; c.ContactToWorld.M22 = normal.X; data.contacts.Add(c); one.SetCanSleep(true); two.SetCanSleep(true); data.addContacts(1); return(true); }
private void ManipulateAddingSpheres() { if (mouseState.LeftButton == ButtonState.Pressed) { if (_sphereRigidAdded == null) { _sphereRigidAdded = AddSphereRigidToEngine(); } } else { if (_sphereRigidAdded != null && mouseState.LeftButton == ButtonState.Released) { _sphereRigidAdded = null; } } }
public static SphereRigid GetDefaultSphere( Vector3 positionXNA, Material material, float radius, Vector3?acc, Vector3?initialForce, Vector3?initialTorque, float orientationValue = 0, bool obInertia = false) { SphereRigid rectToReturn = new SphereRigid(positionXNA, material, radius); // Inertia if (obInertia) { rectToReturn.SetObInertia(); // Awaking rectToReturn.SetAwake(true); return(rectToReturn); } // Acc Vector3 accVector = acc ?? new Vector3(0, 0, 0); rectToReturn.SetAcceleration(accVector); // Forece Vector3 forceIn = initialForce ?? new Vector3(0, 0, 0); rectToReturn.AddForce(forceIn); // Torque Vector3 torqueIn = initialTorque ?? new Vector3(0, 0, 0); rectToReturn.AddTorque(torqueIn, MathHelperModule.GetInverseYPosition(rectToReturn.PositionCenterEngine)); // Orientation rectToReturn.SetOrientation(orientationValue); // Awaking rectToReturn.SetAwake(true); return(rectToReturn); }
public static bool boxAndSphere( BoxRigid box, SphereRigid sphere, ref CollisionData data ) { // Transform the centre of the sphere into box coordinates Vector3 centre = sphere.PositionCenterEngine; Vector3 relCentre = centre - box.PositionCenterEngine; //box.transform.transformInverse(centre); relCentre = Matrix2.M_V(relCentre, -box.GetOrientation()); // Early out check to see if we can exclude the contact if (Math.Abs(relCentre.X) - sphere.Radius > box.HalfSize.X || Math.Abs(relCentre.Y) - sphere.Radius > box.HalfSize.Y ) { return(false); } Vector3 closestPt = new Vector3(0, 0, 0); float dist; // Clamp each coordinate to the box. dist = relCentre.X; if (dist > box.HalfSize.X) { dist = box.HalfSize.X; } if (dist < -box.HalfSize.X) { dist = -box.HalfSize.X; } closestPt.X = dist; dist = relCentre.Y; if (dist > box.HalfSize.Y) { dist = box.HalfSize.Y; } if (dist < -box.HalfSize.Y) { dist = -box.HalfSize.Y; } closestPt.Y = dist; // Check we're in contact Vector3 temp1 = closestPt - relCentre; if (temp1 == Vector3.Zero) { return(true); } float temp2 = temp1.Length(); double temp3 = temp2; dist = (float)Math.Pow(temp3, 2); if (dist > sphere.Radius * sphere.Radius) { return(false); } // Compile the contact Vector3 closestPtWorld = closestPt;//box.transform.transform(closestPt); closestPtWorld = Matrix2.M_V(closestPtWorld, box.GetOrientation()); closestPtWorld += box.PositionCenterEngine; //Contact* contact = data->contacts; // Create the contact data Vector3 temp = closestPtWorld - centre; temp.Normalize(); Contact c = new Contact(); c.ContactNormal = temp; c.Penetration = (float)(sphere.Radius - Math.Sqrt(dist)); c.ContactPoint = closestPtWorld; c.SetBodyData(box, sphere, data.friction, data.restitution); c.Friction = StaticData.FrictionTable[(int)sphere.GetMaterial()][(int)box.GetMaterial()]; // between bump and cookie c.Restitution = 1f; // StaticData.RestitutionTable[(int)sphere.GetMaterial()][(int)box.GetMaterial()]; c.ContactToWorld.M11 = c.ContactNormal.X; c.ContactToWorld.M12 = -c.ContactNormal.Y; c.ContactToWorld.M21 = c.ContactNormal.Y; c.ContactToWorld.M22 = c.ContactNormal.X; data.addContacts(1); data.contacts.Add(c); return(true); }
private void SpheresCD() { List <BoxRigid> ListOfBoxRigids = StaticData.EngineManager.RigidsManagerEngine.ListOfBoxRigids; List <SphereRigid> ListOfSphereRigids = StaticData.EngineManager.RigidsManagerEngine.ListOfSphereRigids; List <CollisionPlane> ListOfPlanes = null; if (RyseAgent.WithWalls) { ListOfPlanes = StaticData.EngineManager.PlanesManagerEngine.ListOfPlanes; } for (int i = 0; i < ListOfSphereRigids.Count; i++) { // Cash the sphere SphereRigid sphere = ListOfSphereRigids[i]; // sphereAndHalfSpace if (RyseAgent.WithWalls) { foreach (var plane in ListOfPlanes) { bool isCollide = CollisionDetector.sphereAndHalfSpace(sphere, plane, ref _data); } } if (sphere.IsCollidable) { // sphereAndSphere for (int j = 0; j < ListOfSphereRigids.Count; j++) { // Cash the sphere SphereRigid sphere2 = ListOfSphereRigids[j]; if (sphere != sphere2) { if (sphere2.IsCollidable) { if (!IsPairOfNonCollidableRigids(sphere, sphere2)) { CollisionDetector.sphereAndSphere(sphere, sphere2, ref _data); } } } } // boxAndSphere for (int j = 0; j < ListOfBoxRigids.Count; j++) { // Cash the box var box = ListOfBoxRigids[j]; if (box.IsCollidable) { if (!IsPairOfNonCollidableRigids(box, sphere)) { bool collided = CollisionDetector.boxAndSphere(box, sphere, ref _data); if (collided) { if (box is BumpRigid) { ((BumpRigid)box).IsCollidedWithCookie = true; if (StaticData.RyseComponentsUsageHelper != null) { if (!StaticData.RyseComponentsUsageHelper.CollidedBumps.Contains(box)) { StaticData.RyseComponentsUsageHelper.CollidedBumps.Add(box as BumpRigid); } } } } } } } } } }
private void ReIntitializeTag4Circle(Vector3 positionCenter, float distanceX, SphereRigid circleIn) { (circleIn).ReInitializeData ( MathHelperModule.GetPositionXNA(positionCenter, distanceX / 2, circleIn.Radius), circleIn.GetMaterial(), (distanceX / 2) ); }