/// <summary> /// Performs a bounce collision (a collision which modifies velocity and acceleration), and separates the objects if so. /// </summary> /// <param name="sphere">The Sphere to perform collision against.</param> /// <param name="thisMass">The mass of this instance.</param> /// <param name="otherMass">Th e mass of the argument cube.</param> /// <param name="elasticity">The ratio of velocity to preserve.</param> /// <returns>Whether a collision occurred.</returns> public bool CollideAgainstBounce(Sphere sphere, float thisMass, float otherMass, float elasticity) { #if DEBUG if (thisMass == 0 && otherMass == 0) { throw new ArgumentException("Both masses cannot be 0. For equal masses pick a non-zero value"); } #endif if (CollideAgainstMove(sphere, thisMass, otherMass)) { // Get the relative velocity of this circle to the argument circle: Vector3 relativeVelocity = new Vector3( this.TopParent.XVelocity - sphere.TopParent.XVelocity, this.TopParent.YVelocity - sphere.TopParent.YVelocity, this.TopParent.ZVelocity - sphere.TopParent.ZVelocity); #if FRB_MDX float velocityNormalDotResult = Vector3.Dot(relativeVelocity, LastMoveCollisionReposition); #else float velocityNormalDotResult; Vector3.Dot(ref relativeVelocity, ref LastMoveCollisionReposition, out velocityNormalDotResult); #endif if (velocityNormalDotResult >= 0) { return(true); } #if FRB_MDX //Vector2 tangentVector = new Vector2((float)mLastCollisionTangent.X, (float)mLastCollisionTangent.Y); // Perform the bounce if the relative velocity and the tangent are the opposite direction. Vector3 reverseNormal = -Vector3.Normalize(LastMoveCollisionReposition); float length = Vector3.Dot(relativeVelocity, reverseNormal); Vector3 velocityOnNormal = Vector3.Multiply(reverseNormal, length); #else Vector3 reverseNormal = -LastMoveCollisionReposition; reverseNormal.Normalize(); float length = Vector3.Dot(relativeVelocity, reverseNormal); Vector3 velocityOnNormal; Vector3.Multiply(ref reverseNormal, length, out velocityOnNormal); #endif sphere.TopParent.Velocity.X += (1 + elasticity) * thisMass / (thisMass + otherMass) * velocityOnNormal.X; sphere.TopParent.Velocity.Y += (1 + elasticity) * thisMass / (thisMass + otherMass) * velocityOnNormal.Y; sphere.TopParent.Velocity.Z += (1 + elasticity) * thisMass / (thisMass + otherMass) * velocityOnNormal.Z; this.TopParent.Velocity.X -= (1 + elasticity) * otherMass / (thisMass + otherMass) * velocityOnNormal.X; this.TopParent.Velocity.Y -= (1 + elasticity) * otherMass / (thisMass + otherMass) * velocityOnNormal.Y; this.TopParent.Velocity.Z -= (1 + elasticity) * otherMass / (thisMass + otherMass) * velocityOnNormal.Z; return(true); } return(false); }
/// <summary> /// Executes the command. /// Gets a number of segments and divides all selected line elements in equal length segments. /// </summary> /// <param name="services">CommandServices object to interact with the system</param> public override void Run(Canguro.Controller.CommandServices services) { List <Item> selection = services.GetSelection(); if (selection.Count == 0) { return; } List <LineElement> lineList = new List <LineElement>(); foreach (Item item in selection) { if (item != null && item is LineElement) { lineList.Add((LineElement)item); } } if (lineList.Count == 0) { lineList.Add(services.GetLine()); } int parts = (int)services.GetSingle(Culture.Get("getSplitParts") + " [2-100]"); parts = (parts < 2) ? 2 : (parts > 100) ? 100 : parts; foreach (LineElement line in lineList) { Joint ji = line.I; Joint jj = line.J; Joint last = jj; Microsoft.DirectX.Vector3 v = new Microsoft.DirectX.Vector3(jj.X - ji.X, jj.Y - ji.Y, jj.Z - ji.Z); v.Multiply(1.0f / parts); if (parts > 1 && v.LengthSq() > 0) { LineElement newLine = line; for (int i = 0; i < parts - 1; i++) { jj = new Joint(ji.X + v.X, ji.Y + v.Y, ji.Z + v.Z); services.Model.JointList.Add(jj); newLine = Split(newLine, jj, services.Model); services.Model.LineList.Add(newLine); ji = jj; } } } }
/// <summary> /// Executes the command. /// Gets a number of segments and divides all selected line elements in equal length segments. /// </summary> /// <param name="services">CommandServices object to interact with the system</param> public override void Run(Canguro.Controller.CommandServices services) { List<Item> selection = services.GetSelection(); if (selection.Count == 0) return; List<LineElement> lineList = new List<LineElement>(); foreach (Item item in selection) if (item != null && item is LineElement) lineList.Add((LineElement)item); if (lineList.Count == 0) lineList.Add(services.GetLine()); int parts = (int)services.GetSingle(Culture.Get("getSplitParts") + " [2-100]"); parts = (parts < 2) ? 2 : (parts > 100) ? 100 : parts; foreach (LineElement line in lineList) { Joint ji = line.I; Joint jj = line.J; Joint last = jj; Microsoft.DirectX.Vector3 v = new Microsoft.DirectX.Vector3(jj.X - ji.X, jj.Y - ji.Y, jj.Z - ji.Z); v.Multiply(1.0f / parts); if (parts > 1 && v.LengthSq() > 0) { LineElement newLine = line; for (int i = 0; i < parts - 1; i++) { jj = new Joint(ji.X + v.X, ji.Y + v.Y, ji.Z + v.Z); services.Model.JointList.Add(jj); newLine = Split(newLine, jj, services.Model); services.Model.LineList.Add(newLine); ji = jj; } } } }