//static Vector3 red = new Vector3(1.0f, 0.0f, 0.0f); public override void OnUpdate() { base.OnUpdate(); rotation += FrameDelta; rotBody.CenterOfMassTransform = Matrix.RotationX(rotation) * rotBodyPosition; GjkPairDetector detector = new GjkPairDetector(colShape0, colShape1, sGjkSimplexSolver, null); detector.CachedSeparatingAxis = new Vector3(0.00000000f, 0.059727669f, 0.29259586f); DiscreteCollisionDetectorInterface.ClosestPointInput input = new DiscreteCollisionDetectorInterface.ClosestPointInput(); input.TransformA = rotBody.CenterOfMassTransform; input.TransformB = body2Position; PointCollector result = new PointCollector(); detector.GetClosestPoints(input, result, null); /* * if (result.HasResult && IsDebugDrawEnabled) * { * distanceFrom = result.PointInWorld; * distanceTo = result.PointInWorld + result.NormalOnBInWorld * result.Distance; * distance = result.Distance; * //World.DebugDrawer.DrawLine(ref distanceFrom, ref distanceTo, ref red); * } */ }
public override void OnUpdate() { base.OnUpdate(); rotation += FrameDelta; rotBody.CenterOfMassTransform = Matrix.RotationX(rotation) * rotBodyPosition; var input = new DiscreteCollisionDetectorInterface.ClosestPointInput { TransformA = rotBody.CenterOfMassTransform, TransformB = body2Position }; var result = new PointCollector(); using (var detector = new GjkPairDetector(colShape0, colShape1, sGjkSimplexSolver, null)) { detector.CachedSeparatingAxis = new Vector3(0.00000000f, 0.059727669f, 0.29259586f); detector.GetClosestPoints(input, result, null); } if (result.HasResult) { distanceFrom = result.PointInWorld; distanceTo = result.PointInWorld + result.NormalOnBInWorld * result.Distance; distance = result.Distance; World.DebugDrawer.DrawLine(ref distanceFrom, ref distanceTo, Color.White); } result.Dispose(); }
public void DrawDistance() { var input = new DiscreteCollisionDetectorInterface.ClosestPointInput { TransformA = _rotatingBody.CenterOfMassTransform, TransformB = _staticBody.CenterOfMassTransform }; using (var result = new PointCollector()) { using (var detector = new GjkPairDetector(_rotatingShape, _staticShape, _gjkSimplexSolver, null)) { detector.CachedSeparatingAxis = new Vector3(0.00000000f, 0.059727669f, 0.29259586f); detector.GetClosestPoints(input, result, null); } if (result.HasResult) { Vector3 distanceFrom = result.PointInWorld; Vector3 distanceTo = result.PointInWorld + result.NormalOnBInWorld * result.Distance; World.DebugDrawer.DrawLine(ref distanceFrom, ref distanceTo, ref _red); } } input.Dispose(); }
public override int Update(float elapsedTime) { int subSteps = base.Update(elapsedTime); rotation += elapsedTime; rotBody.CenterOfMassTransform = Matrix.RotationX(rotation) * rotBodyPosition; var input = new DiscreteCollisionDetectorInterface.ClosestPointInput { TransformA = rotBody.CenterOfMassTransform, TransformB = body2Position }; var result = new PointCollector(); using (var detector = new GjkPairDetector(colShape0, colShape1, sGjkSimplexSolver, null)) { detector.CachedSeparatingAxis = new Vector3(0.00000000f, 0.059727669f, 0.29259586f); detector.GetClosestPoints(input, result, null); } if (result.HasResult) { HasDistanceResult = true; distanceFrom = result.PointInWorld; distanceTo = result.PointInWorld + result.NormalOnBInWorld * result.Distance; distance = result.Distance; } else { HasDistanceResult = false; } result.Dispose(); return(subSteps); }