public ProjectionToSurfaceExpression ProjectToSurface(ASurfaceExpression surface) { var surfaceNormal = surface.Normal; return(new ProjectionToSurfaceExpression() { Position = (Position - surface.Position).ProjectToNormalVector(surfaceNormal), Speed = (Speed - surface.Speed).ProjectToNormalVector(surfaceNormal) }); }
public void ProcessHit(ASurfaceExpression surface, double horizontalHitCoeff, double verticalHitCoeff) { var surfaceNormal = surface.Normal; var projection = ProjectToSurface(surface); projection.Position.Vertical = 2 * Constants.BallRadius * surfaceNormal - projection.Position.Vertical; projection.Speed.Vertical *= -verticalHitCoeff; var ballPoint = -Constants.BallRadius * surfaceNormal; var fullPerpendicularSpeed = projection.Speed.Horizontal + Point3DExpression.VectorMult(ballPoint, AngularSpeed); var force = -horizontalHitCoeff * fullPerpendicularSpeed; projection.Speed.Horizontal += force; AngularSpeed += Point3DExpression.VectorMult(force, ballPoint.Normal) / Constants.BallRadius; RestoreFromSurfaceProjection(surface, projection); }
public void RestoreFromSurfaceProjection(ASurfaceExpression surface, ProjectionToSurfaceExpression projection) { Position = surface.Position + projection.Position.Full; Speed = surface.Speed + projection.Speed.Full; }