// This function gets the inertia tensor for a solid cone public static Matrix4x4 GetSolidConeIntertiaTensor(Particle3D particle) { return(new Matrix4x4(new Vector4((3.0f / 5.0f * particle.mass * (particle.height * particle.height)) + (3.0f / 20.0f * particle.mass * (particle.radius * particle.radius)), 0, 0, 0), new Vector4(0, (3.0f / 5.0f * particle.mass * (particle.height * particle.height)) + (3.0f / 20.0f * particle.mass * (particle.radius * particle.radius)), 0, 0), new Vector4(0, 0, (3.0f / 10.0f) * particle.mass * (particle.radius * particle.radius), 0), new Vector4(0, 0, 0, 1))); }
// This function gets the inertia tensor for a solid cylinder public static Matrix4x4 GetSolidCylinderInertiaTensor(Particle3D particle) { return(new Matrix4x4(new Vector4(-(1.0f / 12.0f) * particle.mass * (3 * (particle.radius * particle.radius) + (particle.height * particle.height)), 0, 0, 0), new Vector4(0, -(1.0f / 12.0f) * particle.mass * (3 * (particle.radius * particle.radius) + (particle.height * particle.height)), 0, 0), new Vector4(0, 0, -(1.0f / 2.0f) * particle.mass * (particle.radius * particle.radius), 0), new Vector4(0, 0, 0, 1))); }
// This function gets the inertia tensor for a hollow cube public static Matrix4x4 GetHollowCubeInertiaTensor(Particle3D particle) { return(new Matrix4x4(new Vector4(5.0f / 3.0f * particle.mass * ((particle.height * particle.height) + (particle.depth * particle.depth)), 0, 0, 0), new Vector4(0, 5.0f / 3.0f * particle.mass * ((particle.depth * particle.depth) + (particle.width * particle.width)), 0, 0), new Vector4(0, 0, 5.0f / 3.0f * particle.mass * ((particle.width * particle.width) + (particle.height * particle.height)), 0), new Vector4(0, 0, 0, 1))); }
// This function gets the inertia tensor for a hollow cube public static Matrix4x4 GetHollowSphereInertiaTensor(Particle3D particle) { return(new Matrix4x4(new Vector4(2.0f / 3.0f * particle.mass * particle.radius, 0, 0, 0), new Vector4(0, 2.0f / 3.0f * particle.mass * particle.radius, 0, 0), new Vector4(0, 0, 2.0f / 3.0f * particle.mass * particle.radius, 0), new Vector4(0, 0, 0, 1))); }
// This function is called whenever the state is entered public override void OnEnterState() { // Set the player and ready the throw player = GameObject.Find("Player"); player.GetComponent <Particle3D>().isUsingGravity = false; player.GetComponent <PlayerScript>().isProne = true; GetComponentInParent <KingBobomb>().bossAnimator.SetTrigger("Pickup"); playerParticle = player.GetComponent <Particle3D>(); StartCoroutine(ConductThrowingSequence()); }
public override void Render() { SpriteMain.Begin(SpriteFlags.AlphaBlend); SpriteMain.Draw2D(TextureObjectDictionary["MenuBackground"], 0.625f, 0.0f, new PointF(320f, 240f), byte.MaxValue); DXFont.DrawString(SpriteMain.sprite, "ver 1.00", 560, 460, Color.Black); SpriteMain.End(); Background3D.Show(); SpriteMain.Begin(SpriteFlags.AlphaBlend); DeviceMain.SetRenderState(RenderState.SourceBlend, 5); DeviceMain.SetRenderState(RenderState.DestinationBlend, 2); Background2.Show(true); SpriteMain.End(); SpriteMain.Begin(SpriteFlags.AlphaBlend); Background2.Show(false); EffectList.ForEach(x => { if (x.Active) { return; } x.Show(); }); StageData.MenuGroupList.ForEach(x => x.Show()); SpriteMain.End(); SpriteMain.Begin(SpriteFlags.AlphaBlend); DeviceMain.SetRenderState(RenderState.SourceBlend, 5); DeviceMain.SetRenderState(RenderState.DestinationBlend, 2); EffectList.ForEach(x => { if (!x.Active) { return; } x.Show(); }); SpriteMain.End(); Particle3D.Show(); if (TimeMain >= 126) { return; } GlobalData.ScreenTexMan.Begin(); GlobalData.LastState.Render(); GlobalData.ScreenTexMan.End(); SpriteMain.Begin(SpriteFlags.AlphaBlend); GlobalData.SpriteMain.Draw2D(GlobalData.ScreenTexMan.RenderTexture, new Point(0, 0), 0.0f, new PointF(0.0f, 0.0f), Color.FromArgb(byte.MaxValue - TimeMain * 2, Color.White)); SpriteMain.End(); }
/* * ReadOML * * Read an OML or ZML file. * Takes in the path of the file, an array of OilIDs, a reference to 3D particles, and a pointer to which record in the array * of OilIDs should be used. * * Copied whole-cloth from code originally provided by ASA. * */ public static string ReadOML(string file,OilID[] recs, ref Particle3D[] parts, int trjver, int oilptr) { int fpos = 0; FileStream fs_oml = null; BinaryReader reader = null; try { fs_oml = File.Open(file,FileMode.Open,FileAccess.Read); reader = new BinaryReader(fs_oml); System.Array.Resize(ref parts, recs[oilptr].nRecs); fpos = (recs[oilptr].rec-1)*40; reader.BaseStream.Seek(fpos,SeekOrigin.Begin); for(int i = 0; i < recs[oilptr].nRecs;i++) { parts[i] = new Particle3D(reader.ReadSingle(),reader.ReadSingle(),reader.ReadSingle(),reader.ReadInt32(),reader.ReadSingle(),reader.ReadSingle(),reader.ReadSingle(),reader.ReadSingle(),reader.ReadSingle(),reader.ReadSingle()); } reader.Close(); fs_oml.Close(); fs_oml.Dispose(); } catch (Exception ex) { return "Error: ReadOML: " + ex.Message; } finally { if(reader != null) reader.Close(); if(fs_oml != null) { fs_oml.Close(); } } return "READ OK"; }
public static void SphereSphereCollision(CollisionManager.HullCollision col) { // *IMPORTANT* for circle and square the collision only wirks with obejct1 - object 2 and not viceversa, must be a prob in clollision resolution SphereHull hull1 = col.a.GetComponent <SphereHull>(); SphereHull hull2 = col.b.GetComponent <SphereHull>(); Vector3 range = (hull2.transform.position + hull2.localCenter) - (hull1.transform.position + hull1.localCenter); // make sure offsets arent screwing things up float overlap = (hull2.radius + hull1.radius) - range.magnitude; //HullCollision col = new CollisionManager.HullCollision(); //col.a = hull1; //col.b = hull2; col.penetration = range * overlap; CollisionManager.HullCollision.Contact con0 = new CollisionManager.HullCollision.Contact(); con0.point = (range.normalized * hull1.radius) + hull1.transform.position; con0.normal = range.normalized; con0.restitution = Mathf.Min(hull1.restitution, hull2.restitution); col.contacts[0] = con0; Particle3D c1 = hull1.GetComponentInParent <Particle3D>(); Particle3D c2 = hull2.GetComponentInParent <Particle3D>(); Vector3 closingVel = c2.velocity - c1.velocity; // started as c1 -c2 col.closingVelocity = closingVel; if (overlap >= 0) { col.status = true; //Debug.Log("touch"); } else { col.status = false; } }
// This function attempts to find an intertia tensor for a given shape type public static Matrix4x4 GetInertiaTensor(Particle3D particle, ThirdDimensionalShapeType shape, bool isHollow) { // Go through shape types and get the inertia type based on if the shape is hollow or not switch (shape) { case ThirdDimensionalShapeType.Cube: if (isHollow) { return(GetHollowCubeInertiaTensor(particle)); } else { return(GetSolidCubeInertiaTensor(particle)); } case ThirdDimensionalShapeType.Sphere: if (isHollow) { return(GetHollowSphereInertiaTensor(particle)); } else { return(GetSolidSphereInertiaTensor(particle)); } case ThirdDimensionalShapeType.Cylinder: return(GetSolidCylinderInertiaTensor(particle)); case ThirdDimensionalShapeType.Cone: return(GetSolidConeIntertiaTensor(particle)); default: // If nothing is found, return an empty matrix return(Matrix4x4.zero); } }
//public hullType hull; public static void ResolveCollision(CollisionManager.HullCollision col) { //Debug.Log("Trying to resolve collision"); Particle3D A = col.a.GetComponent <Particle3D>(); Particle3D B = col.b.GetComponent <Particle3D>(); /* * if(col.a.GetHullType() == hullType.OBB && col.b.GetHullType() == hullType.Sphere) * { * A = col.a.GetComponent<Particle3D>(); * B = col.b.GetComponent<Particle3D>(); * } * else if (col.a.GetHullType() == hullType.Sphere && col.b.GetHullType() == hullType.OBB) * { * A = col.b.GetComponent<Particle3D>(); * B = col.a.GetComponent<Particle3D>(); * }*/ float invAMass; float invBMass; if (A.mass == 0) { invAMass = 0; } else { invAMass = 1 / A.mass; } if (B.mass == 0) { invBMass = 0; } else { invBMass = 1 / B.mass; } float velAlongNormal = Vector3.Dot(col.contacts[0].normal, col.closingVelocity.normalized); //Debug.Log("velAlongNormal " + velAlongNormal); if (velAlongNormal > 0) { return; // > makes square work properly } //Debug.Log(velAlongNormal); // restitustion float e = col.contacts[0].restitution; // impulse scalar float j = -(1 + e) * velAlongNormal; j /= invAMass + invBMass; //Debug.Log(j); Vector3 impulse = j * col.contacts[0].normal; //Debug.Log("impules = " + impulse); // Positional Correction if (col.status) { //A.velocity = new Vector3(0.0f, 0.0f, 0.0f); //B.velocity = new Vector3(0.0f, 0.0f, 0.0f); A.velocity -= invAMass * impulse; B.velocity += invBMass * impulse; float percent = 0.2f; float slop = 0.01f; Vector3 correction = Mathf.Max(velAlongNormal - slop, 0) / (invAMass + invBMass) * percent * col.contacts[0].normal; A.position -= invAMass * correction; // started - B.position += invBMass * correction; // started + //col.resolved = true; } if (col.wasStatus && !col.status) { col.resolved = true; } col.wasStatus = col.status; }
private void Awake() { particle = GetComponent <Particle3D>(); }
protected CollisionHull3D(CollisionHullType3D collisionType) { particle = GetComponent <Particle3D>(); type = collisionType; }
public static string ReadTR3(string file, SiSpillets[] recs, ref Particle3D[] parts,int recNum) { int fpos = 0; FileStream fs_tr3 = null; BinaryReader reader = null; try { fs_tr3 = File.Open(file,FileMode.Open,FileAccess.Read); reader = new BinaryReader(fs_tr3); System.Array.Resize(ref parts, (recs[recNum].rec2end-recs[recNum].rec2st)+1); fpos = (recs[recNum].rec2st-1)*40; reader.BaseStream.Seek(fpos,SeekOrigin.Begin); for(int i = 0; i < parts.Length; i++) { parts[i] = new Particle3D(reader.ReadSingle(),reader.ReadSingle(),reader.ReadSingle(),reader.ReadSingle(),reader.ReadSingle(),reader.ReadInt32(),reader.ReadSingle(),reader.ReadSingle(),reader.ReadSingle(),reader.ReadSingle()); } reader.Close(); fs_tr3.Close(); fs_tr3.Dispose(); } catch (Exception ex) { return "Error: ReadTR3: " + ex.Message; } finally { if(reader != null) reader.Close(); if(fs_tr3 != null) { fs_tr3.Close(); } } return "READ OK"; }