//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);

            GjkPairDetector.ClosestPointInput input = new GjkPairDetector.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);
            }
            */
        }
Example #2
0
        public override int Update(float elapsedTime)
        {
            int subSteps = base.Update(elapsedTime);

            rotation += elapsedTime;
            rotBody.CenterOfMassTransform = Matrix.RotationX(rotation) * rotBodyPosition;

            GjkPairDetector detector = new GjkPairDetector(colShape0, colShape1, sGjkSimplexSolver, null);
            detector.CachedSeparatingAxis = new Vector3(0.00000000f, 0.059727669f, 0.29259586f);

            GjkPairDetector.ClosestPointInput input = new GjkPairDetector.ClosestPointInput();
            input.TransformA = rotBody.CenterOfMassTransform;
            input.TransformB = body2Position;

            PointCollector result = new PointCollector();
            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;
            }

            return subSteps;
        }
 public unsafe static void GetCachedSeparatingAxis(this GjkPairDetector obj, out OpenTK.Vector3 value)
 {
     fixed(OpenTK.Vector3 *valuePtr = &value)
     {
         *(BulletSharp.Math.Vector3 *)valuePtr = obj.CachedSeparatingAxis;
     }
 }
 public unsafe static void SetCachedSeparatingAxis(this GjkPairDetector obj, ref OpenTK.Vector3 seperatingAxis)
 {
     fixed(OpenTK.Vector3 *seperatingAxisPtr = &seperatingAxis)
     {
         obj.CachedSeparatingAxis = *(BulletSharp.Math.Vector3 *)seperatingAxisPtr;
     }
 }
Example #5
0
        /// <summary>
        /// 2つのコリジョン オブジェクトの距離
        /// </summary>
        /// <param name="colA">コリジョンA</param>
        /// <param name="colB">コリジョンB</param>
        /// <returns></returns>
        public static float Distance(CollisionObject colA, CollisionObject colB)
        {
            if (colA == null || colA.Shape == null || colB == null || colB.Shape == null ||
                colA.Data == null || colB.Data == null) {
                // 距離が定義できない場合は
                // NaNを返す
                return Single.NaN;
            }

            var shpA = colA.Data.CollisionShape as ConvexShape;
            var shpB = colB.Data.CollisionShape as ConvexShape;
            var solver = new VoronoiSimplexSolver ();

            var detector = new GjkPairDetector (shpA, shpB, solver, null);

            var traA = Matrix4x4.CreateFromTranslation (colA.Offset) * colA.Node.GlobalTransform;
            var traB = Matrix4x4.CreateFromTranslation (colB.Offset) * colB.Node.GlobalTransform;

            var input = new GjkPairDetector.ClosestPointInput ();
            input.TransformA = traA.ToBullet ();
            input.TransformB = traB.ToBullet ();
            input.MaximumDistanceSquared = Single.MaxValue;

            var output = new PointCollector ();

            detector.GetClosestPoints (input, output, null);

            if (!output.HasResult) {
                // 重なっていた場合は
                // 0を返す
                return 0;
            }

            // 正常な距離は0以上
            return output.Distance;
        }
        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, ref red);
            }
            result.Dispose();
        }
 public static OpenTK.Vector3 GetCachedSeparatingAxis(this GjkPairDetector obj)
 {
     OpenTK.Vector3 value;
     GetCachedSeparatingAxis(obj, out value);
     return(value);
 }