• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Geometry.Segment类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中JigLibX.Geometry.Segment的典型用法代码示例。如果您正苦于以下问题:C# Segment类的具体用法?C# Segment怎么用?C# Segment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Segment类属于JigLibX.Geometry命名空间,在下文中一共展示了Segment类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: SegmentTriangleOverlap

        /// <summary>
        /// Indicates if a segment intersects a triangle
        /// </summary>
        /// <param name="seg"></param>
        /// <param name="triangle"></param>
        /// <returns>bool</returns>
        public static bool SegmentTriangleOverlap(Segment seg, Triangle triangle)
        {
            // the parameters - if hit then they get copied into the args
            float u, v, t;

            Vector3 e1 = triangle.Edge0;
            Vector3 e2 = triangle.Edge1;

            Vector3 p = Vector3.Cross(seg.Delta, e2);
            float a = Vector3.Dot(e1, p);

            if (a > -JiggleMath.Epsilon && a < JiggleMath.Epsilon)
                return false;

            float f = 1.0f / a;
            Vector3 s = seg.Origin - triangle.Origin;
            u = f * Vector3.Dot(s, p);

            if (u < 0.0f || u > 1.0f)
                return false;

            Vector3 q = Vector3.Cross(s, e1);
            v = f * Vector3.Dot(seg.Delta, q);

            if (v < 0.0f || (u + v) > 1.0f)
                return false;

            t = f * Vector3.Dot(e2, q);

            if (t < 0.0f || t > 1.0f)
                return false;

            return true;
        }
开发者ID:colbybhearn,项目名称:3DPhysics,代码行数:40,代码来源:Overlap.cs


示例2: PointSegmentDistance

        public static float PointSegmentDistance(out float t, Vector3 pt, Segment seg)
        {
            Vector3 kDiff;
            float fT;

            Vector3.Subtract(ref pt, ref seg.Origin, out kDiff);
            Vector3.Dot(ref kDiff, ref seg.Delta, out fT);

            if (fT <= 0.0f)
            {
                fT = 0.0f;
            }
            else
            {
                float sqrLen = seg.Delta.LengthSquared();
                if (fT >= sqrLen)
                {
                    fT = 1.0f;
                    kDiff = kDiff - seg.Delta;
                }
                else
                {
                    fT = fT / sqrLen;
                    kDiff = kDiff - (fT * seg.Delta);
                }
            }

            t = fT;

            return kDiff.Length();
        }
开发者ID:kaoabi,项目名称:GP3_CourseworkGame,代码行数:31,代码来源:Distance.cs


示例3: Intersects

 public bool Intersects(
     ref Vector3 position,
     ref Vector3 vector,
     out Vector3 resultPosition,
     out Vector3 resultNormal,
     out float resultFraction)
 {
     var segment = new Segment(position, vector);
     return SegmentIntersect(out resultFraction, out resultPosition, out resultNormal, segment);
 }
开发者ID:willcraftia,项目名称:WindowsGame,代码行数:10,代码来源:BoxCollisionShape.cs


示例4: CollDetect

        public override void CollDetect(CollDetectInfo info, float collTolerance, CollisionFunctor collisionFunctor)
        {
            Vector3 body0Pos = (info.Skin0.Owner != null) ? info.Skin0.Owner.OldPosition : Vector3.Zero;
            Vector3 body1Pos = (info.Skin1.Owner != null) ? info.Skin1.Owner.OldPosition : Vector3.Zero;

            // todo - proper swept test
            Capsule oldCapsule0 = (Capsule)info.Skin0.GetPrimitiveOldWorld(info.IndexPrim0);
            Capsule newCapsule0 = (Capsule)info.Skin0.GetPrimitiveNewWorld(info.IndexPrim0);
            Segment oldSeg0 = new Segment(oldCapsule0.Position, oldCapsule0.Length * oldCapsule0.Orientation.Backward);
            Segment newSeg0 = new Segment(newCapsule0.Position, newCapsule0.Length * newCapsule0.Orientation.Backward);

            Capsule oldCapsule1 = (Capsule)info.Skin1.GetPrimitiveOldWorld(info.IndexPrim1);
            Capsule newCapsule1 = (Capsule)info.Skin1.GetPrimitiveNewWorld(info.IndexPrim1);
            Segment oldSeg1 = new Segment(oldCapsule1.Position, oldCapsule1.Length * oldCapsule1.Orientation.Backward);
            Segment newSeg1 = new Segment(newCapsule1.Position, newCapsule1.Length * newCapsule1.Orientation.Backward);

            float radSum = newCapsule0.Radius + newCapsule1.Radius;

            float oldt0, oldt1;
            float newt0, newt1;
            float oldDistSq = Distance.SegmentSegmentDistanceSq(out oldt0, out oldt1, oldSeg0, oldSeg1);
            float newDistSq = Distance.SegmentSegmentDistanceSq(out newt0, out newt1, newSeg0, newSeg1);

            if (System.Math.Min(oldDistSq, newDistSq) < ((radSum + collTolerance) * (radSum + collTolerance)))
            {
                Vector3 pos0 = oldSeg0.GetPoint(oldt0);
                Vector3 pos1 = oldSeg1.GetPoint(oldt1);

                Vector3 delta = pos0 - pos1;

                float dist = (float)System.Math.Sqrt((float)oldDistSq);
                float depth = radSum - dist;

                if (dist > JiggleMath.Epsilon)
                {
                    delta /= dist;
                }
                else
                {
                    // todo - make this not random
                    delta = Vector3.Transform(Vector3.Backward, Matrix.CreateFromAxisAngle(Vector3.Up, MathHelper.ToRadians(random.Next(360))));
                }

                Vector3 worldPos = pos1 +
                    (oldCapsule1.Radius - 0.5f * depth) * delta;

                unsafe
                {
                    SmallCollPointInfo collInfo = new SmallCollPointInfo(worldPos - body0Pos, worldPos - body1Pos, depth);
                    collisionFunctor.CollisionNotify(ref info, ref delta, &collInfo, 1);
                }

            }
        }
开发者ID:bradleat,项目名称:trafps,代码行数:54,代码来源:CapsuleCapsule.cs


示例5: SegmentAABoxOverlap

        /// <summary>
        /// Indicates if a segment overlaps an AABox
        /// </summary>
        /// <param name="seg"></param>
        /// <param name="AABox"></param>
        /// <returns>bool</returns>
        public static bool SegmentAABoxOverlap(Segment seg, AABox AABox)
        {
            Vector3 p0 = seg.Origin;
            Vector3 p1 = seg.GetEnd();

            float[] faceOffsets = new float[2];

            // The AABox faces are aligned with the world directions. Loop
            // over the 3 directions and do the two tests.
            for (int iDir = 0; iDir < 3; iDir++)
            {
                int jDir = (iDir + 1) % 3;
                int kDir = (iDir + 2) % 3;

                // one plane goes through the origin, one is offset
                faceOffsets[0] = JiggleUnsafe.Get(AABox.MinPos, iDir);
                faceOffsets[1] = JiggleUnsafe.Get(AABox.MaxPos, iDir);

                for (int iFace = 0; iFace < 2; iFace++)
                {
                    // distance of each point from to the face plane
                    float dist0 = JiggleUnsafe.Get(ref p0, iDir) - faceOffsets[iFace];
                    float dist1 = JiggleUnsafe.Get(ref p1, iDir) - faceOffsets[iFace];
                    float frac = -1.0f;

                    if (dist0 * dist1 < -JiggleMath.Epsilon)
                        frac = -dist0 / (dist1 - dist0);
                    else if (System.Math.Abs(dist0) < JiggleMath.Epsilon)
                        frac = 0.0f;
                    else if (System.Math.Abs(dist1) < JiggleMath.Epsilon)
                        frac = 1.0f;

                    if (frac >= 0.0f)
                    {
                        //Assert(frac <= 1.0f);
                        Vector3 pt = seg.GetPoint(frac);

                        // check the point is within the face rectangle
                        if ((JiggleUnsafe.Get(ref pt, jDir) > JiggleUnsafe.Get(AABox.MinPos, jDir) - JiggleMath.Epsilon) &&
                            (JiggleUnsafe.Get(ref pt, jDir) < JiggleUnsafe.Get(AABox.MaxPos, jDir) + JiggleMath.Epsilon) &&
                            (JiggleUnsafe.Get(ref pt, kDir) > JiggleUnsafe.Get(AABox.MinPos, kDir) - JiggleMath.Epsilon) &&
                            (JiggleUnsafe.Get(ref pt, kDir) < JiggleUnsafe.Get(AABox.MaxPos, kDir) + JiggleMath.Epsilon))
                        {
                            return true;
                        }
                    }
                }
            }
            return false;
        }
开发者ID:colbybhearn,项目名称:3DPhysics,代码行数:56,代码来源:Overlap.cs


示例6: SegmentCapsuleIntersection

        public static bool SegmentCapsuleIntersection(out float tS, Segment seg, Capsule capsule)
        {
            float bestFrac = float.MaxValue;

            tS = 0;

            // do the main sides
            float sideFrac = float.MaxValue;
            if (!SegmentInfiniteCylinderIntersection(out sideFrac, seg,
                    new Segment(capsule.Position, capsule.Orientation.Backward),
                    capsule.Radius))
                return false; // check this

            // only keep this if the side intersection point is within the capsule segment ends
            Vector3 sidePos = seg.GetPoint(sideFrac);
            if (Vector3.Dot(sidePos - capsule.Position, capsule.Orientation.Backward) < 0.0f)
                sideFrac = float.MaxValue;
            else if (Vector3.Dot(sidePos - capsule.GetEnd(), capsule.Orientation.Backward) > 0.0f)
                sideFrac = float.MaxValue;

            // do the two ends
            float originFrac = float.MaxValue;
            SegmentSphereIntersection(out originFrac, seg, new Sphere(capsule.Position, capsule.Radius));
            float endFrac = float.MaxValue; // Check this!
            SegmentSphereIntersection(out endFrac, seg, new Sphere(capsule.Position, capsule.Radius));

            bestFrac = MathHelper.Min(sideFrac, originFrac);
            bestFrac = MathHelper.Min(bestFrac, endFrac);

            if (bestFrac <= 1.0f)
            {
                tS = bestFrac;
                return true;
            }

            return false;
        }
开发者ID:bradleat,项目名称:trafps,代码行数:37,代码来源:Intersection.cs


示例7: OnFire

        public void OnFire(Vector3 muzzlePosition, Vector3 muzzleDir)
        {
            if (coolDownTimeRemaining <= 0)
            {
                //fpsModel.SetAnimationLayer("Pistol_Idle", 0.0f);
                fpsModel.GetAnimationLayer().AddAnimation("Pistol_Fire", true);
                //fpsModel.SetAnimationLayer("Pistol_Fire", 1.0f);
                coolDownTimeRemaining = ResourceManager.Inst.GetAnimation("Pistol_Fire").EndTime;
                float dist;
                CollisionSkin skin;
                Vector3 pos, normal;

                Segment seg = new Segment(muzzlePosition, muzzleDir * 50);

                scene.GetPhysicsEngine().CollisionSystem.SegmentIntersect(out dist, out skin, out pos, out normal, seg, ignorePred);
                if (skin != null)
                {
                    Decal decal = new Decal();
                    decal.SetMaterial("BulletMetal1");
                    decal.Normal = normal;
                    decal.Scale = new Vector2(0.25f, 0.25f);
                    Vector3 posNew = seg.Origin + seg.Delta * dist;
                    decal.Transformation.SetPosition(posNew);
                    decal.IsPersistent = false;
                    scene.AddEntity("bullet", decal);
                    ParticleEffect bulletEffect = ResourceManager.Inst.GetParticleEffect("BulletEffect");
                    ParticleEmitter collideEmitter = new ParticleEmitter(bulletEffect, 16);
                    collideEmitter.EmitOnce = true;
                    NormalTransform newTransform = new NormalTransform();
                    newTransform.ConformToNormal(normal);
                    newTransform.SetPosition(pos);
                    collideEmitter.Transformation = newTransform;
                    scene.AddEntity("bulletEmitter", collideEmitter);
                }
            }
        }
开发者ID:MattVitelli,项目名称:IslandAdventure,代码行数:36,代码来源:Weapon.cs


示例8: SegmentIntersect

 /// <summary>
 /// Intersect a segment with the world. If non-zero the predicate
 /// allows certain skins to be excluded
 /// </summary>
 /// <param name="seg"></param>
 /// <param name="collisionPredicate"></param>
 /// <returns></returns>
 public abstract bool SegmentIntersect(out float fracOut, out CollisionSkin skinOut, out Vector3 posOut, out Vector3 normalOut,
     Segment seg, CollisionSkinPredicate1 collisionPredicate);
开发者ID:bradleat,项目名称:trafps,代码行数:9,代码来源:CollisionSystem.cs


示例9: SegmentTriangleDistanceSq

        /// <summary>
        /// SegmentTriangleDistanceSq
        /// </summary>
        /// <param name="segT"></param>
        /// <param name="triT0"></param>
        /// <param name="triT1"></param>
        /// <param name="seg"></param>
        /// <param name="triangle"></param>
        /// <returns>float</returns>
        public static float SegmentTriangleDistanceSq(out float segT, out float triT0, out float triT1, Segment seg, Triangle triangle)
        {
            // compare segment to all three edges of the triangle
            float distSq = float.MaxValue;

            if (Intersection.SegmentTriangleIntersection(out segT, out triT0, out triT1, seg, triangle))
            {
                segT = triT0 = triT1 = 0.0f;
                return 0.0f;
            }

            float s, t, u;
            float distEdgeSq;
            distEdgeSq = SegmentSegmentDistanceSq(out s, out t, seg, new Segment(triangle.Origin, triangle.Edge0));
            if (distEdgeSq < distSq)
            {
                distSq = distEdgeSq;
                segT = s;
                triT0 = t;
                triT1 = 0.0f;
            }
            distEdgeSq = SegmentSegmentDistanceSq(out s, out t, seg, new Segment(triangle.Origin, triangle.Edge1));
            if (distEdgeSq < distSq)
            {
                distSq = distEdgeSq;
                segT = s;
                triT0 = 0.0f;
                triT1 = t;
            }
            distEdgeSq = SegmentSegmentDistanceSq(out s, out t, seg, new Segment(triangle.Origin + triangle.Edge0, triangle.Edge2));
            if (distEdgeSq < distSq)
            {
                distSq = distEdgeSq;
                segT = s;
                triT0 = 1.0f - t;
                triT1 = t;
            }

            // compare segment end points to triangle interior
            float startTriSq = PointTriangleDistanceSq(out t, out u, seg.Origin, triangle);
            if (startTriSq < distSq)
            {
                distSq = startTriSq;
                segT = 0.0f;
                triT0 = t;
                triT1 = u;
            }
            float endTriSq = PointTriangleDistanceSq(out t, out u, seg.GetEnd(), triangle);
            if (endTriSq < distSq)
            {
                distSq = endTriSq;
                segT = 1.0f;
                triT0 = t;
                triT1 = u;
            }
            return distSq;
        }
开发者ID:tuannsofta,项目名称:kinect4bag,代码行数:66,代码来源:Distance.cs


示例10: GetInteractNode

        InteractNode GetInteractNode(Microsoft.Xna.Framework.Ray lookRay)
        {
            float collisionDist;
            CollisionSkin skin = null;
            Vector3 pos, normal;
            Segment seg = new Segment(lookRay.Position, lookRay.Direction * MAX_INTERACT_DIST);
            scene.GetPhysicsEngine().CollisionSystem.SegmentIntersect(out collisionDist, out skin, out pos, out normal, seg, pred);

            float bestDist = (skin != null) ? collisionDist : float.PositiveInfinity;
            InteractNode bestNode = null;
            for (int i = 0; i < interactables.Count; i++)
            {
                InteractObject interactObj = interactables[i].GetInteractObject();

                BoundingBox bounds =  interactObj.Transformation.TransformBounds(interactObj.GetMesh().GetBounds());
                float? intersection = lookRay.Intersects(bounds);
                if (intersection.HasValue)
                {
                    float dist = intersection.Value;
                    if (dist < bestDist && dist <= MAX_INTERACT_DIST)
                    {
                        InteractNode node = interactObj.GetInteractNode();
                        if (node.IsEnabled())
                        {
                            bestDist = dist;
                            bestNode = interactObj.GetInteractNode();
                        }
                    }
                }
            }
            return bestNode;
        }
开发者ID:MattVitelli,项目名称:Nosferatu,代码行数:32,代码来源:PlayerScreen.cs


示例11: CollDetect

        /// <summary>
        /// CollDetect
        /// </summary>
        /// <param name="infoOrig"></param>
        /// <param name="collTolerance"></param>
        /// <param name="collisionFunctor"></param>
        public override void CollDetect(CollDetectInfo infoOrig, float collTolerance, CollisionFunctor collisionFunctor)
        {
            CollDetectInfo info = infoOrig;

            // get the skins in the order that we're expecting
            if (info.Skin0.GetPrimitiveOldWorld(info.IndexPrim0).Type == this.Type1)
            {
                CollisionSkin skinSwap = info.Skin0;
                info.Skin0 = info.Skin1;
                info.Skin1 = skinSwap;
                int primSwap = info.IndexPrim0;
                info.IndexPrim0 = info.IndexPrim1;
                info.IndexPrim1 = primSwap;
            }

            Vector3 body0Pos = (info.Skin0.Owner != null) ? info.Skin0.Owner.OldPosition : Vector3.Zero;
            Vector3 body1Pos = (info.Skin1.Owner != null) ? info.Skin1.Owner.OldPosition : Vector3.Zero;

            // todo - proper swept test
            Sphere oldSphere = info.Skin0.GetPrimitiveOldWorld(info.IndexPrim0) as Sphere;
            Sphere newSphere = info.Skin0.GetPrimitiveNewWorld(info.IndexPrim0) as Sphere;

            Capsule oldCapsule = info.Skin1.GetPrimitiveOldWorld(info.IndexPrim1) as Capsule;
            Capsule newCapsule = info.Skin1.GetPrimitiveNewWorld(info.IndexPrim1) as Capsule;

            Segment oldSeg = new Segment(oldCapsule.Position, oldCapsule.Length * oldCapsule.Orientation.Backward());
            Segment newSeg = new Segment(oldCapsule.Position, newCapsule.Length * newCapsule.Orientation.Backward());

            float radSum = newCapsule.Radius + newSphere.Radius;

            float oldt, newt;
            float oldDistSq = Distance.PointSegmentDistanceSq(out oldt, oldSphere.Position, oldSeg);
            float newDistSq = Distance.PointSegmentDistanceSq(out newt, newSphere.Position, newSeg);

            if (OpenTKHelper.Min(oldDistSq, newDistSq) < (radSum + collTolerance) * (radSum + collTolerance))
            {
                Vector3 segPos = oldSeg.GetPoint(oldt);
                Vector3 delta = oldSphere.Position - segPos;

                float dist = (float)System.Math.Sqrt((float)oldDistSq);
                float depth = radSum - dist;

                if (dist > JiggleMath.Epsilon)
                {
                    delta /= dist;
                }
                else
                {
                    // todo - make this not random
                    delta = Vector3Extensions.TransformNormal(Vector3Extensions.Backward, Matrix4.CreateFromAxisAngle(Vector3Extensions.Up, OpenTKHelper.ToRadians(random.Next(360))));
                }

                Vector3 worldPos = segPos +
                    ((oldCapsule.Radius - 0.5f * depth) * delta);
                unsafe
                {
                    SmallCollPointInfo collInfo = new SmallCollPointInfo(worldPos - body0Pos,
                        worldPos - body1Pos, depth);

                    collisionFunctor.CollisionNotify(ref info, ref delta, &collInfo, 1);
                }
            }
        }
开发者ID:cody82,项目名称:spacewar-arena,代码行数:69,代码来源:SphereCapsule.cs


示例12: SegmentIntersect

 /// <summary>
 /// Must support intersection with a segment (ray cast)
 /// </summary>
 /// <param name="frac"></param>
 /// <param name="pos"></param>
 /// <param name="normal"></param>
 /// <param name="seg"></param>
 /// <returns>bool</returns>
 public abstract bool SegmentIntersect(out float frac,out Vector3 pos,
     out Vector3 normal,Segment seg);
开发者ID:cody82,项目名称:spacewar-arena,代码行数:10,代码来源:Primitive.cs


示例13: SegmentIntersect

        /// <summary>
        /// SegmentIntersect
        /// </summary>
        /// <param name="frac"></param>
        /// <param name="pos"></param>
        /// <param name="normal"></param>
        /// <param name="seg"></param>
        /// <returns>bool</returns>
        public override bool SegmentIntersect(out float frac, out Vector3 pos, out Vector3 normal, Segment seg)
        {
            // move segment into octree space
            seg.Origin = Vector3.Transform(seg.Origin, invTransform);
            seg.Delta = Vector3.TransformNormal(seg.Delta, invTransform);

            BoundingBox segBox = BoundingBoxHelper.InitialBox;
            BoundingBoxHelper.AddSegment(seg, ref segBox);

            unsafe
            {
            #if USE_STACKALLOC
                int* potentialTriangles = stackalloc int[MaxLocalStackTris];
                {
            #else
                int[] potTriArray = DetectFunctor.IntStackAlloc();
                fixed (int* potentialTriangles = potTriArray)
                {
            #endif
                    int numTriangles = GetTrianglesIntersectingtAABox(potentialTriangles, DetectFunctor.MaxLocalStackTris, ref segBox);

                    float tv1, tv2;

                    pos = Vector3.Zero;
                    normal = Vector3.Zero;

                    float bestFrac = float.MaxValue;
                    for (int iTriangle = 0; iTriangle < numTriangles; ++iTriangle)
                    {
                        IndexedTriangle meshTriangle = GetTriangle(potentialTriangles[iTriangle]);
                        float thisFrac;
                        Triangle tri = new Triangle(GetVertex(meshTriangle.GetVertexIndex(0)),
                          GetVertex(meshTriangle.GetVertexIndex(1)),
                          GetVertex(meshTriangle.GetVertexIndex(2)));

                        if (Intersection.SegmentTriangleIntersection(out thisFrac, out tv1, out tv2, seg, tri))
                        {
                            if (thisFrac < bestFrac)
                            {
                                bestFrac = thisFrac;
                                // re-project
                                pos = Vector3.Transform(seg.GetPoint(thisFrac), transformMatrix);
                                normal = Vector3.TransformNormal(meshTriangle.Plane.Normal, transformMatrix);
                            }
                        }
                    }

                    frac = bestFrac;
                    if (bestFrac < float.MaxValue)
                    {
                        DetectFunctor.FreeStackAlloc(potTriArray);
                        return true;
                    }
                    else
                    {
                        DetectFunctor.FreeStackAlloc(potTriArray);
                        return false;
                    }
            #if USE_STACKALLOC
                }
            #else
                }
            #endif
            }
        }
开发者ID:colbybhearn,项目名称:3DPhysics,代码行数:73,代码来源:TriangleMesh.cs


示例14: SegmentIntersect

        /// <summary>
        /// Every skin must support a ray/segment intersection test -
        /// operates on the new value of the primitives
        /// </summary>
        /// <param name="frac"></param>
        /// <param name="pos"></param>
        /// <param name="normal"></param>
        /// <param name="seg"></param>
        /// <returns>bool</returns>
        public bool SegmentIntersect(out float frac, out Vector3 pos, out Vector3 normal, Segment seg)
        {
            Vector3 segEnd = seg.GetEnd();
            frac = float.MaxValue;

            float thisSegLenRelToOrig = 1.0f;
            Segment segCopy = seg;

            pos = normal = Vector3.Zero;

            for (int prim = primitivesNewWorld.Count; prim-- != 0; )
            {
                float thisFrac;
                Vector3 newPosition = pos;

                if (primitivesNewWorld[prim].SegmentIntersect(out thisFrac, out newPosition, out normal, segCopy))
                {
                    pos = newPosition;
                    frac = thisFrac * thisSegLenRelToOrig;
                    segCopy.Delta *= thisFrac;
                    thisSegLenRelToOrig *= frac;
                }
            }

            //System.Diagnostics.Debug.WriteLineIf(frac <= 1.0f, pos);

            return (frac <= 1.0f);
        }
开发者ID:tuannsofta,项目名称:kinect4bag,代码行数:37,代码来源:CollisionSkin.cs


示例15: SegmentSegmentDistanceSq

        /// <summary>
        /// Returns the distance of two segments.
        /// </summary>
        /// <param name="t0">Parametric representation of nearest point on seg0.</param>
        /// <param name="t1">Parametric representation of nearest point on seg0.</param>
        /// <param name="seg0">First segment to test.</param>
        /// <param name="seg1">Second segment to test.</param>
        /// <returns>float</returns>
        public static float SegmentSegmentDistanceSq(out float t0, out float t1, Segment seg0, Segment seg1)
        {
            Vector3 kDiff = seg0.Origin - seg1.Origin;
            float fA00 = seg0.Delta.LengthSquared();
            float fA01 = -Vector3.Dot(seg0.Delta, seg1.Delta);
            float fA11 = seg1.Delta.LengthSquared();
            float fB0 = Vector3.Dot(kDiff, seg0.Delta);
            float fC = kDiff.LengthSquared();
            float fDet = System.Math.Abs(fA00 * fA11 - fA01 * fA01);
            float fB1, fS, fT, fSqrDist, fTmp;

            if (fDet >= JiggleMath.Epsilon)
            {
                // line segments are not parallel
                fB1 = -Vector3.Dot(kDiff, seg1.Delta);
                fS = fA01 * fB1 - fA11 * fB0;
                fT = fA01 * fB0 - fA00 * fB1;

                if (fS >= 0.0f)
                {
                    if (fS <= fDet)
                    {
                        if (fT >= 0.0f)
                        {
                            if (fT <= fDet)  // region 0 (interior)
                            {
                                // minimum at two interior points of 3D lines
                                float fInvDet = 1.0f / fDet;
                                fS *= fInvDet;
                                fT *= fInvDet;
                                fSqrDist = fS * (fA00 * fS + fA01 * fT + 2.0f * fB0) +
                                  fT * (fA01 * fS + fA11 * fT + 2.0f * fB1) + fC;
                            }
                            else  // region 3 (side)
                            {
                                fT = 1.0f;
                                fTmp = fA01 + fB0;
                                if (fTmp >= 0.0f)
                                {
                                    fS = 0.0f;
                                    fSqrDist = fA11 + (2.0f) * fB1 + fC;
                                }
                                else if (-fTmp >= fA00)
                                {
                                    fS = 1.0f;
                                    fSqrDist = fA00 + fA11 + fC + (2.0f) * (fB1 + fTmp);
                                }
                                else
                                {
                                    fS = -fTmp / fA00;
                                    fSqrDist = fTmp * fS + fA11 + (2.0f) * fB1 + fC;
                                }
                            }
                        }
                        else  // region 7 (side)
                        {
                            fT = 0.0f;
                            if (fB0 >= 0.0f)
                            {
                                fS = 0.0f;
                                fSqrDist = fC;
                            }
                            else if (-fB0 >= fA00)
                            {
                                fS = 1.0f;
                                fSqrDist = fA00 + (2.0f) * fB0 + fC;
                            }
                            else
                            {
                                fS = -fB0 / fA00;
                                fSqrDist = fB0 * fS + fC;
                            }
                        }
                    }
                    else
                    {
                        if (fT >= 0.0f)
                        {
                            if (fT <= fDet)  // region 1 (side)
                            {
                                fS = 1.0f;
                                fTmp = fA01 + fB1;
                                if (fTmp >= 0.0f)
                                {
                                    fT = 0.0f;
                                    fSqrDist = fA00 + (2.0f) * fB0 + fC;
                                }
                                else if (-fTmp >= fA11)
                                {
                                    fT = 1.0f;
                                    fSqrDist = fA00 + fA11 + fC + (2.0f) * (fB0 + fTmp);
                                }
//.........这里部分代码省略.........
开发者ID:tuannsofta,项目名称:kinect4bag,代码行数:101,代码来源:Distance.cs


示例16: OnUpdate

        public void OnUpdate()
        {
            fpsModel.OnUpdate();

            if (coolDownTimeRemaining > 0)
            {
                coolDownTimeRemaining -= Time.GameTime.ElapsedTime;
            }
            if (timeTilFire > 0)
                timeTilFire -= Time.GameTime.ElapsedTime;
            if (timeTilFire <= 0 && !hasFired)
            {
                hasFired = true;
                if(!datablock.IsMelee)
                    new Sound3D(datablock.GetSoundEffect((ammo > 0)?WeaponAnimations.Fire:WeaponAnimations.Empty), muzzlePos);
                if (ammo > 0 || datablock.IsMelee)
                {
                    ammo--;
                    float dist;
                    CollisionSkin skin;
                    Vector3 pos, normal;

                    Segment seg = new Segment(muzzlePos, muzzleDir * datablock.FireDistance);
                    Microsoft.Xna.Framework.Ray shootRay = new Microsoft.Xna.Framework.Ray(muzzlePos, muzzleDir);
                    bool anyActorHit = false;
                    scene.GetPhysicsEngine().CollisionSystem.SegmentIntersect(out dist, out skin, out pos, out normal, seg, ignorePred);
                    float segDist = (skin != null) ? Vector3.Distance(seg.Delta * dist, Vector3.Zero): float.PositiveInfinity;
                    for (int i = 0; i < scene.Actors.Count; i++)
                    {
                        Actor currActor = scene.Actors[i];
                        if (currActor != scene.MainPlayer)
                        {
                            float shootDist;
                            HitType hit = currActor.GetHit(shootRay, datablock.FireDistance, out shootDist);
                            if (hit != HitType.None)
                            {
                                if (skin == null || (shootDist <= segDist))
                                {
                                    currActor.ApplyDamage(datablock.Damage);
                                    ParticleEffect bloodEffect = ResourceManager.Inst.GetParticleEffect("BloodEffect");
                                    ParticleEmitter collideEmitter = new ParticleEmitter(bloodEffect, 16);
                                    collideEmitter.EmitOnce = true;
                                    NormalTransform newTransform = new NormalTransform();
                                    newTransform.ConformToNormal(-muzzleDir);
                                    newTransform.SetPosition(muzzlePos + muzzleDir*shootDist);
                                    collideEmitter.Transformation = newTransform;
                                    scene.AddEntity("bloodEmitter", collideEmitter);
                                    anyActorHit = true;
                                }
                            }
                        }
                    }
                    if (skin != null)
                    {
                        ParticleEffect bulletEffect = ResourceManager.Inst.GetParticleEffect("BulletEffect");
                        ParticleEmitter collideEmitter = new ParticleEmitter(bulletEffect, 16);
                        collideEmitter.EmitOnce = true;
                        NormalTransform newTransform = new NormalTransform();
                        newTransform.ConformToNormal(normal);
                        newTransform.SetPosition(pos);
                        collideEmitter.Transformation = newTransform;
                        scene.AddEntity("bulletEmitter", collideEmitter);
                    }
                    if(datablock.IsMelee)
                        new Sound3D(datablock.GetSoundEffect((anyActorHit) ? WeaponAnimations.SuccessHit : WeaponAnimations.Fire), muzzlePos);
                }
            }
        }
开发者ID:MattVitelli,项目名称:Nosferatu,代码行数:68,代码来源:Weapon.cs


示例17: CollDetect

        /// <summary>
        /// CollDetect
        /// </summary>
        /// <param name="infoOrig"></param>
        /// <param name="collTolerance"></param>
        /// <param name="collisionFunctor"></param>
        public override void CollDetect(CollDetectInfo infoOrig, float collTolerance, CollisionFunctor collisionFunctor)
        {
            // get the skins in the order that we're expectiing
            CollDetectInfo info = infoOrig;
            if (info.Skin0.GetPrimitiveOldWorld(info.IndexPrim0).Type == this.Type1)
            {
                CollisionSkin skinSwap = info.Skin0;
                info.Skin0 = info.Skin1;
                info.Skin1 = skinSwap;
                int primSwap = info.IndexPrim0;
                info.IndexPrim0 = info.IndexPrim1;
                info.IndexPrim1 = primSwap;
            }

            Vector3 body0Pos = (info.Skin0.Owner != null) ? info.Skin0.Owner.OldPosition : Vector3.Zero;
            Vector3 body1Pos = (info.Skin1.Owner != null) ? info.Skin1.Owner.OldPosition : Vector3.Zero;

            // todo - proper swept test
            Capsule oldCapsule = info.Skin0.GetPrimitiveOldWorld(info.IndexPrim0) as Capsule;
            Capsule newCapsule = info.Skin0.GetPrimitiveNewWorld(info.IndexPrim0) as Capsule;
            Segment oldSeg = new Segment(oldCapsule.Position, oldCapsule.Length * oldCapsule.Orientation.Backward);
            Segment newSeg = new Segment(newCapsule.Position, newCapsule.Length * newCapsule.Orientation.Backward);

            float radius = oldCapsule.Radius;

            Box oldBox = info.Skin1.GetPrimitiveOldWorld(info.IndexPrim1) as Box;
            Box newBox = info.Skin1.GetPrimitiveNewWorld(info.IndexPrim1) as Box;

            float oldSegT;
            float oldBoxT0, oldBoxT1, oldBoxT2;
            float oldDistSq = Distance.SegmentBoxDistanceSq(out oldSegT, out oldBoxT0, out oldBoxT1, out oldBoxT2,oldSeg, oldBox);
            float newSegT;
            float newBoxT0, newBoxT1, newBoxT2;
            float newDistSq = Distance.SegmentBoxDistanceSq(out newSegT, out newBoxT0, out newBoxT1, out newBoxT2,newSeg, newBox);

            if (MathHelper.Min(oldDistSq, newDistSq) < ((radius + collTolerance) * (radius + collTolerance)))
            {
                Vector3 segPos = oldSeg.GetPoint(oldSegT);
                Vector3 boxPos = oldBox.GetCentre() + oldBoxT0 * oldBox.Orientation.Right +
                    oldBoxT1 * oldBox.Orientation.Up + oldBoxT2 * oldBox.Orientation.Backward;

                float dist = (float)System.Math.Sqrt((float)oldDistSq);
                float depth = radius - dist;

                Vector3 dir;

                if (dist > JiggleMath.Epsilon)
                {
                    dir = segPos - boxPos;
                    JiggleMath.NormalizeSafe(ref dir);
                }
                else if ((segPos - oldBox.GetCentre()).LengthSquared() > JiggleMath.Epsilon)
                {
                    dir = segPos - oldBox.GetCentre();
                    JiggleMath.NormalizeSafe(ref dir);
                }
                else
                {
                    // todo - make this not random
                    dir = Vector3.Transform(Vector3.Backward, Matrix.CreateFromAxisAngle(Vector3.Up, MathHelper.ToRadians(random.Next(360))));
                }

                unsafe
                {
                    SmallCollPointInfo collInfo = new SmallCollPointInfo(boxPos - body0Pos, boxPos - body1Pos, depth);

                    collisionFunctor.CollisionNotify(ref info, ref dir, &collInfo, 1);
                }

            }
        }
开发者ID:tuannsofta,项目名称:kinect4bag,代码行数:77,代码来源:CapsuleBox.cs


示例18: SegmentIntersect

        public override bool SegmentIntersect(out float fracOut, out CollisionSkin skinOut, out Vector3 posOut, out Vector3 normalOut, Segment seg, CollisionSkinPredicate1 collisionPredicate)
        {
            int numSkins = skins.Count;
            BoundingBox segBox = BoundingBoxHelper.InitialBox;
            BoundingBoxHelper.AddSegment(seg, ref segBox);

            //initialise the outputs
            fracOut = float.MaxValue;
            skinOut = null;
            posOut = normalOut = Vector3.Zero;

            // working vars
            float frac;
            Vector3 pos;
            Vector3 normal;

            for (int iskin = 0; iskin < numSkins; ++iskin)
            {
                CollisionSkin skin = skins[iskin];
                if ((collisionPredicate == null) ||
                    collisionPredicate.ConsiderSkin(skin))
                {
                    // basic bbox test
                    if (BoundingBoxHelper.OverlapTest(ref skin.WorldBoundingBox, ref segBox))
                    {
                        if (skin.SegmentIntersect(out frac, out pos, out normal, seg))
                        {
                            if (frac < fracOut)
                            {
                                posOut = pos;
                                normalOut = normal;
                                skinOut = skin;
                                fracOut = frac;
                            }
                        }

                    }
                }
            }

            if (fracOut > 1.0f) return false;
            fracOut = MathHelper.Clamp(fracOut, 0.0f, 1.0f);
            return true;
        }
开发者ID:kaoabi,项目名称:GP3_CourseworkGame,代码行数:44,代码来源:CollisionSystemGrid.cs


示例19: CollDetectCapsuleStaticMeshOverlap


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Physics.Body类代码示例发布时间:2022-05-26
下一篇:
C# Collision.CollisionSkin类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap