public void ApplySurfaceImpulse(Vertex3D rotI, Vertex3D impulse) { Vel.Add(impulse.Clone().MultiplyScalar(InvMass)); AngularMomentum.Add(rotI); var angularMomentum = AngularMomentum.Clone(); AngularVelocity.Set(angularMomentum.DivideScalar(Inertia)); }
public CollisionEvent Set(CollisionEvent coll) { Ball = coll.Ball; Obj = coll.Obj; IsContact = coll.IsContact; HitTime = coll.HitTime; HitDistance = coll.HitDistance; HitNormal.Set(coll.HitNormal); HitVel.Set(coll.HitVel.X, coll.HitVel.Y); HitOrgNormalVelocity = coll.HitOrgNormalVelocity; HitMomentBit = coll.HitMomentBit; HitFlag = coll.HitFlag; return(this); }
private void GetRelativeVelocity(Vertex3D normal, Ball.Ball ball, Vertex3D vRel, Vertex3D rB, Vertex3D rF) { rB.Set(normal.Clone().MultiplyScalar(-ball.Data.Radius)); var hitPos = ball.State.Pos.Clone().Add(rB); var cF = new Vertex3D( _mover.HitCircleBase.Center.X, _mover.HitCircleBase.Center.Y, ball.State.Pos.Z // make sure collision happens in same z plane where ball is ); rF.Set(hitPos.Clone().Sub(cF)); // displacement relative to flipper center var vB = ball.Hit.SurfaceVelocity(rB); var vF = _mover.SurfaceVelocity(rF); vRel.Set(vB.Clone().Sub(vF)); }
public HitLine3D(Vertex3D v1, Vertex3D v2, ItemType itemType, IItem item) : base(new Vertex2D(), itemType, item) { var vLine = v2.Clone().Sub(v1); vLine.Normalize(); // Axis of rotation to make 3D cylinder a cylinder along the z-axis var transAxis = new Vertex3D(vLine.Y, -vLine.X, 0); var l = transAxis.LengthSq(); if (l <= 1e-6) { // line already points in z axis? transAxis.Set(1, 0, 0); // choose arbitrary rotation vector } else { transAxis.DivideScalar(MathF.Sqrt(l)); } // Angle to rotate the line into the z-axis var dot = vLine.Z; //vLine.Dot(&vup); Matrix.RotationAroundAxis(transAxis, -MathF.Sqrt(1 - dot * dot), dot); var vTrans1 = v1.Clone().ApplyMatrix2D(Matrix); var vTrans2 = v2.Clone().ApplyMatrix2D(Matrix); var vTrans2Z = vTrans2.Z; // set up HitLineZ parameters Xy.Set(vTrans1.X, vTrans1.Y); ZLow = MathF.Min(vTrans1.Z, vTrans2Z); ZHigh = MathF.Max(vTrans1.Z, vTrans2Z); V1 = v1; V2 = v2; HitBBox.Left = MathF.Min(v1.X, v2.X); HitBBox.Right = MathF.Max(v1.X, v2.X); HitBBox.Top = MathF.Min(v1.Y, v2.Y); HitBBox.Bottom = MathF.Max(v1.Y, v2.Y); HitBBox.ZLow = MathF.Min(v1.Z, v2.Z); HitBBox.ZHigh = MathF.Max(v1.Z, v2.Z); }