示例#1
0
        static bool cullTriangle(VInt3[] triVerts, VInt3 dir, VFixedPoint radius, VFixedPoint t, VFixedPoint dpc0)
        {
            // PT: project triangle on axis
            VFixedPoint dp0 = VInt3.Dot(triVerts[0], dir);
            VFixedPoint dp1 = VInt3.Dot(triVerts[1], dir);
            VFixedPoint dp2 = VInt3.Dot(triVerts[2], dir);

            // PT: keep min value = earliest possible impact distance
            VFixedPoint dp = dp0;

            dp = FMath.Min(dp, dp1); dp = FMath.Min(dp, dp2);

            // PT: make sure we keep triangles that are about as close as best current distance
            radius += Globals.EPS;

            // PT: if earliest possible impact distance for this triangle is already larger than
            // sphere's current best known impact distance, we can skip the triangle
            if (dp > dpc0 + t + radius)
            {
                return(false);
            }

            // PT: if triangle is fully located before the sphere's initial position, skip it too
            VFixedPoint dpc1 = dpc0 - radius;

            if (dp0 < dpc1 && dp1 < dpc1 && dp2 < dpc1)
            {
                return(false);
            }

            return(true);
        }
示例#2
0
        public static DbvtAabbMm FromVec(VInt3 from, VInt3 to, DbvtAabbMm output)
        {
            DbvtAabbMm box = output;

            box.mi.x = FMath.Min(from.x, to.x); box.mi.y = FMath.Min(from.y, to.y); box.mi.z = FMath.Min(from.z, to.z);
            box.mx.x = FMath.Max(from.x, to.x); box.mx.y = FMath.Max(from.y, to.y); box.mx.z = FMath.Max(from.z, to.z);
            return(box);
        }
示例#3
0
        static VFixedPoint squareDistance(VInt3 p0, VInt3 dir, VFixedPoint t, VInt3 point)
        {
            VInt3       diff = point - p0;
            VFixedPoint fT   = VInt3.Dot(diff, dir);

            fT    = FMath.Min(FMath.Max(fT, VFixedPoint.Zero), t);
            diff -= dir * fT;
            return(diff.sqrMagnitude);
        }
示例#4
0
        public static bool getSphereDistance(BoxShape boxShape, VIntTransform m44T, VInt3 sphereCenter, VFixedPoint radius, out VInt3 normal, out VFixedPoint penetrationDepth)
        {
            VInt3       boxHalfExtent = boxShape.getHalfExtent();
            VFixedPoint boxMargin     = boxShape.getMargin();

            penetrationDepth = VFixedPoint.Zero;

            // convert the sphere position to the box's local space
            VInt3 sphereRelPos = m44T.InverseTransformPoint(sphereCenter);

            // Determine the closest point to the sphere center in the box
            VInt3 closestPoint = sphereRelPos;

            closestPoint.x = (FMath.Min(boxHalfExtent.x, closestPoint.x));
            closestPoint.x = (FMath.Max(-boxHalfExtent.x, closestPoint.x));
            closestPoint.y = (FMath.Min(boxHalfExtent.y, closestPoint.y));
            closestPoint.y = (FMath.Max(-boxHalfExtent.y, closestPoint.y));
            closestPoint.z = (FMath.Min(boxHalfExtent.z, closestPoint.z));
            closestPoint.z = (FMath.Max(-boxHalfExtent.z, closestPoint.z));

            VFixedPoint intersectionDist = radius + boxMargin;
            VFixedPoint contactDist      = intersectionDist;

            normal = sphereRelPos - closestPoint;

            //if there is no penetration, we are done
            VFixedPoint dist2 = normal.sqrMagnitude;

            if (dist2 > contactDist * contactDist)
            {
                return(false);
            }

            VFixedPoint distance;

            //special case if the sphere center is inside the box
            if (dist2 <= Globals.EPS)
            {
                distance = -getSpherePenetration(boxHalfExtent, sphereRelPos, ref closestPoint, out normal);
            }
            else //compute the penetration details
            {
                distance = normal.magnitude;
                normal  /= distance;
            }

            //	v3PointOnSphere = sphereRelPos - (normal * fRadius);
            penetrationDepth = distance - intersectionDist;

            VInt3 tmp = m44T.TransformDirection(normal);

            normal = tmp;

            return(true);
        }
示例#5
0
        public static void Merge(DbvtAabbMm a, DbvtAabbMm b, DbvtAabbMm r)
        {
            r.mi.x = FMath.Min(a.mi.x, b.mi.x);
            r.mx.x = FMath.Max(a.mx.x, b.mx.x);

            r.mi.y = FMath.Min(a.mi.y, b.mi.y);
            r.mx.y = FMath.Max(a.mx.y, b.mx.y);

            r.mi.z = FMath.Min(a.mi.z, b.mi.z);
            r.mx.z = FMath.Max(a.mx.z, b.mx.z);
        }
示例#6
0
        public Bounds2 DrawTextDebug(string str, Vector2 bottom_left_start_pos, float char_height, bool draw = true, SpriteRenderer.ISpriteShader shader = null)
        {
            if (null == shader)
            {
                shader = this.m_default_font_shader;
            }
            float   num     = char_height / (float)EmbeddedDebugFontData.CharSizei.Y;
            Vector2 vector  = new Vector2(-1f, 1f);
            Vector2 vector2 = vector * num;
            TRS     tRS     = default(TRS);

            tRS.R = Math._10;
            tRS.S = EmbeddedDebugFontData.CharSizef * num;
            tRS.T = bottom_left_start_pos;
            Vector2 max = bottom_left_start_pos;
            float   x   = tRS.T.X;

            if (draw)
            {
                this.DefaultFontShader.SetUVTransform(ref Math.UV_TransformFlipV);
                this.BeginSprites(this.m_embedded_font_texture_info, this.DefaultFontShader, str.Length);
            }
            for (int i = 0; i < str.Length; i++)
            {
                if (str[i] == '\n')
                {
                    tRS.T  -= new Vector2(0f, tRS.S.Y + vector2.Y);
                    tRS.T.X = x;
                }
                else
                {
                    if (draw)
                    {
                        int num2 = (int)(str[i] - ' ');
                        if (num2 < 0 || num2 >= EmbeddedDebugFontData.NumChars)
                        {
                            num2 = 31;
                        }
                        this.AddSprite(ref tRS, new Vector2i(num2, 0));
                    }
                    tRS.T += new Vector2(tRS.S.X + vector2.X, 0f);
                    max.X  = FMath.Max(tRS.T.X, max.X);
                    max.Y  = FMath.Min(tRS.T.Y, max.Y);
                }
            }
            if (draw)
            {
                this.EndSprites();
            }
            return(Bounds2.SafeBounds(bottom_left_start_pos + new Vector2(0f, tRS.S.Y), max));
        }
示例#7
0
        public static bool RayAabb2(VInt3 rayFrom,
                                    VInt3 rayTo,
                                    VInt3 aabbMin, VInt3 aabbMax,
                                    ref VFixedPoint tmin,
                                    ref VFixedPoint tmax
                                    )
        {
            VInt3       d     = rayTo - rayFrom;
            VFixedPoint tminf = VFixedPoint.Zero;
            VFixedPoint tmaxf = VFixedPoint.One;

            for (int i = 0; i < 3; i++)
            {
                bool isParallel = d[i].Abs() < Globals.EPS;
                if (isParallel)
                {
                    if ((rayFrom[i] < aabbMin[i] || rayFrom[i] > aabbMax[i]))
                    {
                        return(false);
                    }
                    else
                    {
                        continue;
                    }
                }
                else
                {
                    VFixedPoint odd = VFixedPoint.One / d[i];
                    VFixedPoint t1  = (aabbMin[i] - rayFrom[i]) * odd;
                    VFixedPoint t2  = (aabbMax[i] - rayFrom[i]) * odd;
                    if (t1 > t2)
                    {
                        VFixedPoint tmp = t1;
                        t1 = t2;
                        t2 = tmp;
                    }

                    tminf = FMath.Max(tminf, t1);
                    tmaxf = FMath.Min(tmaxf, t2);
                }
            }

            tmin = tminf; tmax = tmaxf;
            return(!(tmin > tmax || tmin > VFixedPoint.One));
        }
示例#8
0
        void PlayPinStrikeSounds(AActor _other)
        {
            int   _settledPins = gamemode.lastSettledCount;
            float _center      = 50f;
            float _otherYLoc   = _other.GetActorLocation().Y;
            float _offset      = _otherYLoc >= 0 ?
                                 FMath.Abs(_otherYLoc - _center) : FMath.Abs(_otherYLoc + _center);
            float _highoffset = 350f;
            float _offsetAsPercentageDecimal = (_offset / _highoffset);
            float _highVelX = 2500f;
            float _lowVelX  = 1000f;
            float _velX     = FMath.Clamp(_other.GetVelocity().X, _lowVelX, _highVelX);
            float _velXAsPercentageDecimal = ((_velX - _lowVelX) / (_highVelX - _lowVelX));
            //The Less Pins, The Higher The Percentage
            float _pinSettledPenaltyAsPercentage = 1 - (_settledPins / 10);
            float _VelXMinusOffsetYDecimal       = _velXAsPercentageDecimal - (_offsetAsPercentageDecimal * offsetAsPercentageMultplier) - _pinSettledPenaltyAsPercentage;

            if (_offsetAsPercentageDecimal > 0.80f)
            {
                _VelXMinusOffsetYDecimal = FMath.Min(-0.5f, _VelXMinusOffsetYDecimal - 0.5f);
            }

            //MyOwner.PrintString($"Pin Strike. Vel: {_velX} VelAsPerc: {_velXAsPercentageDecimal} Off: {_offset} OffAsPerc: {_offsetAsPercentageDecimal} VelMinusOffset: {_VelXMinusOffsetYDecimal}", FLinearColor.Green, printToLog: true);
            Random _ran = new Random();

            if (_VelXMinusOffsetYDecimal <= -0.5)
            {
                MyAudioSourceComponent.Sound = _ran.Next(0, 2) == 0 ?
                                               PinStrikeSoundVolume1 : PinStrikeSoundVolume2;
            }
            else if (_VelXMinusOffsetYDecimal <= 0.2)
            {
                MyAudioSourceComponent.Sound = _ran.Next(0, 2) == 0 ?
                                               PinStrikeSoundVolume3 : PinStrikeSoundVolume4;
            }
            else
            {
                MyAudioSourceComponent.Sound = PinStrikeSoundVolume5;
            }

            MyAudioSourceComponent.Play();
        }
示例#9
0
        public Bounds2 DrawTextWithFontMap(string str, Vector2 bottom_left_start_pos, float char_height, bool draw, FontMap fontmap, SpriteRenderer.ISpriteShader shader)
        {
            float   num     = char_height / fontmap.CharPixelHeight;
            Vector2 vector  = new Vector2(1f, 1f);
            Vector2 vector2 = vector * num;
            Vector2 vector3 = bottom_left_start_pos;
            Vector2 max     = bottom_left_start_pos;
            float   x       = bottom_left_start_pos.X;

            if (draw)
            {
                shader.SetUVTransform(ref Math.UV_TransformFlipV);
                this.BeginSprites(new TextureInfo(fontmap.Texture), shader, str.Length);
            }
            for (int i = 0; i < str.Length; i++)
            {
                FontMap.CharData charData;
                if (str[i] == '\n')
                {
                    vector3  -= new Vector2(0f, char_height + vector2.Y);
                    vector3.X = x;
                }
                else if (fontmap.TryGetCharData(str[i], out charData))
                {
                    Vector2 vector4 = charData.PixelSize * num;
                    if (draw)
                    {
                        this.AddSprite(vector3, new Vector2(vector4.X, 0f), charData.UV);
                    }
                    vector3 += new Vector2(vector4.X + vector2.X, 0f);
                    max.X    = FMath.Max(vector3.X, max.X);
                    max.Y    = FMath.Min(vector3.Y, max.Y);
                }
            }
            if (draw)
            {
                this.EndSprites();
            }
            return(Bounds2.SafeBounds(bottom_left_start_pos + new Vector2(0f, char_height), max));
        }
示例#10
0
        private void setTexture()
        {
            float num;
            float num2;

            if (this.needPartialTexture)
            {
                num  = FMath.Min(this.frontPanel.Width, this.MaxTextureWidth) * UISystem.Scale;
                num2 = FMath.Min(this.frontPanel.Height, this.MaxTextureHeight) * UISystem.Scale;
            }
            else
            {
                num  = this.frontPanel.Width * UISystem.Scale;
                num2 = this.frontPanel.Height * UISystem.Scale;
            }
            if (this.cacheTexture == null || this.cacheTexture.Width != (int)num || this.cacheTexture.Height != (int)num2)
            {
                if (this.cacheTexture != null)
                {
                    this.cacheTexture.Dispose();
                }
                this.cacheTexture = new Texture2D((int)num, (int)num2, false, (PixelFormat)1, (PixelBufferOption)1);
            }
            Matrix4     matrix      = new Matrix4(1f, 0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 1f, 0f, -this.textureOffsetX, -this.textureOffsetY, 0f, 1f);
            FrameBuffer frameBuffer = new FrameBuffer();

            frameBuffer.SetColorTarget(this.cacheTexture, 0);
            this.frontPanel.RenderToFrameBuffer(frameBuffer, ref matrix, true);
            frameBuffer.Dispose();
            if (this.animationSprt.Image != null)
            {
                this.animationSprt.Image.Dispose();
            }
            this.animationSprt.Image = new ImageAsset(this.cacheTexture);
            this.animationSprt.Image.AdjustScaledSize = true;
            this.texImage = this.animationSprt.Image;
            this.animationSprt.Visible = true;
            this.frontPanel.Visible    = false;
        }
示例#11
0
 public static VInt3 Min(VInt3 a, VInt3 b)
 {
     return(new VInt3(FMath.Min(a.x, b.x), FMath.Min(a.y, b.y), FMath.Min(a.z, b.z)));
 }
示例#12
0
        private static float GetFunctionInterpolateRatio(int strength)
        {
            float num = (float)(-(float)strength) / 100f;

            return(Math.Abs(FMath.Max(-1f, FMath.Min(1f, num))));
        }
示例#13
0
        /// 壁の生成
        public void makeWall(int scrPosX, int scrPosY)
        {
            GameActorCollManager useCollMgr = actorDestination.GetMoveCollManager();

            Vector3 posStart = new Vector3(0, 0, 0);
            Vector3 posEnd   = new Vector3(0, 0, 0);

            /// チェックする開始座標と終了座標のセット
            ctrlResMgr.GraphDev.GetScreenToWorldPos(scrPosX, scrPosY, 0.0f, ref posStart);
            ctrlResMgr.GraphDev.GetScreenToWorldPos(scrPosX, scrPosY, 1.0f, ref posEnd);


            DemoGame.GeometryLine moveMoveLine = new DemoGame.GeometryLine(posStart, posEnd);

            /// 衝突対象の登録
            useCollMgr.TrgContainer.Clear();
            ctrlResMgr.CtrlTo.SetDestinationActor(useCollMgr.TrgContainer);
            useCollMgr.TrgContainer.Add(actorStg, actorStg.GetUseObj(0));


            /// 衝突判定
            calCollLook.SetMoveType(Data.CollTypeId.ChDestination);

            bool checkBound = calCollLook.Check(useCollMgr, moveMoveLine);

            if (checkBound)
            {
                /// マーカーのセット
//            actorDestination.Start();

                Matrix4 mtx = Matrix4.RotationY(0);
                destinationTrgActor = useCollMgr.TrgContainer.GetEntryObjParent(0);
                ShapeSphere bndSph = destinationTrgActor.GetBoundingShape();
                if (destinationTrgActor.CheckMoveTrgId() == 2)          //始点の建物に接触
                {
                    towerNowPos  = destinationTrgActor.BasePos;
                    TouchPostion = destinationTrgActor.BasePos;
                    if (towerPos.X != towerNowPos.X && towerPos.Z != towerNowPos.Z && !(towerPos.X == 0.0f && towerPos.Y == 0.0f && towerPos.Z == 0.0f))              //最初のタッチ以外もしくは前のタワー以外との接触の場合
                    {
                        if (bndSph != null)
                        {
                            towerNowPos.Y += bndSph.Sphre.R;
                        }
                        towerNowPos.Y         += 0.1f;
                        ctrlResMgr.AddWall     = true;
                        ctrlResMgr.AddWallPos1 = towerPos;
                        ctrlResMgr.AddWallPos2 = towerNowPos;
                        makeTowerFlag          = false;
                        Console.WriteLine("asdf");
                    }
                }
                else
                {
                    Console.WriteLine("fdsa");
                    towerNowPos    = calCollLook.NextPos;
                    TouchPostion   = calCollLook.NextPos;
                    towerNowPos.Y += 0.1f;
                    if (towerPos.X == 0.0f && towerPos.Y == 0.0f && towerPos.Z == 0.0f)
                    {
                        towerPos  = towerNowPos;
                        effectPos = towerNowPos;
                        //ctrlResMgr.CtrlTo.EntryAddTower( 1, 0.0f, towerNowPos, (int)StaticDataList.getRandom(0,5));
                    }
                    double dis2 = Common.VectorUtil.Distance(towerPos, towerNowPos);
                    if (dis2 > newTowerDis)
                    {
                        ctrlResMgr.AddWall     = true;
                        ctrlResMgr.AddWallPos1 = towerPos;
                        ctrlResMgr.AddWallPos2 = towerNowPos;

                        ctrlResMgr.AddTower    = true;
                        ctrlResMgr.AddTowerPos = towerNowPos;

                        TowerAreaNorth = FMath.Max(TowerAreaNorth, towerNowPos.X);
                        TowerAreaSouth = FMath.Min(TowerAreaSouth, towerNowPos.X);
                        TowerAreaEast  = FMath.Max(TowerAreaEast, towerNowPos.Z);
                        TowerAreaWest  = FMath.Min(TowerAreaWest, towerNowPos.Z);
                        //AppSound.GetInstance().PlaySeCamDis( AppSound.SeId.MakeMo, towerNowPos );

                        towerPos = towerNowPos;
                        //sumPos += towerPos;
                        //sumcount++;
                    }
                    dis2 = Common.VectorUtil.Distance(effectPos, towerNowPos);
                    if (dis2 > newEffectDis)
                    {
                        ctrlResMgr.AddEffectFromEnemy = true;
                        ctrlResMgr.AddEnemyEffectPos  = towerNowPos;
                        effectPos = towerNowPos;
                    }
                }
            }
        }
示例#14
0
        public static PxGJKStatus calcPenDepth(CollisionShape a, CollisionShape b, VIntTransform transformA, VIntTransform transformB,
                                               ref VInt3 pa, ref VInt3 pb, ref VInt3 normal, ref VFixedPoint penDepth)
        {
            simplexSolver.reset();
            //Do simple GJK
            VFixedPoint minMargin        = FMath.Min(a.getMargin(), b.getMargin());
            VInt3       initialSearchDir = transformA.position - transformB.position;
            VInt3       v             = initialSearchDir.sqrMagnitude > Globals.EPS2 ? initialSearchDir : VInt3.right;
            bool        notTerminated = true;
            VFixedPoint sDist         = VFixedPoint.MaxValue;
            VFixedPoint minDist       = sDist;
            int         iter          = 0;

            while (notTerminated && iter < MaxGJKIteration)
            {
                minDist = sDist;
                VInt3 supportA = transformA.TransformPoint(a.support(transformA.InverseTransformDirection(v)));
                VInt3 supportB = transformB.TransformPoint(b.support(transformB.InverseTransformDirection(-v)));
                VInt3 support  = supportA - supportB;
                simplexSolver.addVertex(support, supportA, supportB);
                VInt3 p0, p1;
                bool  con = !simplexSolver.compute_points(out p0, out p1);
                v             = p1 - p0;
                sDist         = v.sqrMagnitude;
                notTerminated = con && sDist < minDist;
                iter++;
            }

            if (notTerminated)
            {
                return(PxGJKStatus.EPA_FAIL);
            }

            simplexSolver.getSimplex(aBuf, bBuf, Q);

            VFixedPoint upper_bound = VFixedPoint.MaxValue;
            VFixedPoint lower_bound = VFixedPoint.MinValue;

            int numVertsLocal = 0;

            heap.Clear();
            facetManager.freeAll();

            switch (simplexSolver.numVertices())
            {
            case 1:
                if (!expandPoint(a, b, transformA, transformB, ref numVertsLocal, lower_bound, upper_bound))
                {
                    return(PxGJKStatus.EPA_FAIL);
                }
                break;

            case 2:
                if (!expandSegment(a, b, transformA, transformB, ref numVertsLocal, lower_bound, upper_bound))
                {
                    return(PxGJKStatus.EPA_FAIL);
                }
                break;

            case 3:
                if (!expandTriangle(a, b, transformA, transformB, ref numVertsLocal, lower_bound, upper_bound))
                {
                    return(PxGJKStatus.EPA_FAIL);
                }
                break;

            case 4:
                //check for input face normal. All face normals in this tetrahedron should be all pointing either inwards or outwards. If all face normals are pointing outward, we are good to go. Otherwise, we need to
                //shuffle the input vertexes and make sure all face normals are pointing outward
                VFixedPoint planeDist0 = calculatePlaneDist(0, 1, 2, aBuf, bBuf);
                if (planeDist0 < VFixedPoint.Zero)
                {
                    //shuffle the input vertexes
                    VInt3 tempA = aBuf[2];
                    VInt3 tempB = bBuf[2];
                    aBuf[2] = aBuf[1];
                    bBuf[2] = bBuf[1];
                    aBuf[1] = tempA;
                    bBuf[1] = tempB;
                }

                Facet f0 = addFacet(0, 1, 2, lower_bound, upper_bound);
                Facet f1 = addFacet(0, 3, 1, lower_bound, upper_bound);
                Facet f2 = addFacet(0, 2, 3, lower_bound, upper_bound);
                Facet f3 = addFacet(1, 3, 2, lower_bound, upper_bound);

                if ((f0 == null) || (f1 == null) || (f2 == null) || (f3 == null) || heap.IsEmpty())
                {
                    return(PxGJKStatus.EPA_FAIL);
                }

                f0.link(0, f1, 2);
                f0.link(1, f3, 2);
                f0.link(2, f2, 0);
                f1.link(0, f2, 2);
                f1.link(1, f3, 0);
                f2.link(1, f3, 1);
                numVertsLocal = 4;
                break;
            }

            Facet facet     = null;
            Facet bestFacet = null;

            bool  hasMoreFacets = false;
            VInt3 tempa;
            VInt3 tempb;
            VInt3 q;


            do
            {
                facetManager.processDeferredIDs();
                facet          = heap.pop(); //get the shortest distance triangle of origin from the list
                facet.m_inHeap = false;

                if (!facet.isObsolete())
                {
                    bestFacet = facet;
                    VInt3       planeNormal = facet.getPlaneNormal();
                    VFixedPoint planeDist   = facet.getPlaneDist();

                    doSupport(a, b, transformA, transformB, planeNormal, out tempa, out tempb, out q);

                    //calculate the distance from support point to the origin along the plane normal. Because the support point is search along
                    //the plane normal, which means the distance should be positive. However, if the origin isn't contained in the polytope, dist
                    //might be negative
                    VFixedPoint dist = VInt3.Dot(q, planeNormal);
                    //update the upper bound to the minimum between exisiting upper bound and the distance if distance is positive
                    upper_bound = dist >= VFixedPoint.Zero ? FMath.Min(upper_bound, dist) : upper_bound;
                    //lower bound is the plane distance, which will be the smallest among all the facets in the prority queue
                    lower_bound = planeDist;
                    //if the plane distance and the upper bound is within a small tolerance, which means we found the MTD
                    bool con0 = upper_bound != VFixedPoint.MaxValue && lower_bound != VFixedPoint.MinValue && (upper_bound - lower_bound) <= Globals.EPS2;
                    if (con0)
                    {
                        calculateContactInformation(aBuf, bBuf, facet, a, b, ref pa, ref pb, ref normal, ref penDepth);
                        return(PxGJKStatus.EPA_CONTACT);
                    }
                    //if planeDist is the same as dist, which means the support point we get out from the Mincowsky sum is one of the point
                    //in the triangle facet, we should exist because we can't progress further.
                    VFixedPoint dif = dist - planeDist;
                    bool        degeneratedCondition = dif < Globals.EPS;

                    if (degeneratedCondition)
                    {
                        return(PxGJKStatus.EPA_DEGENERATE);
                    }

                    aBuf[numVertsLocal] = tempa;
                    bBuf[numVertsLocal] = tempb;

                    int index = numVertsLocal++;

                    // Compute the silhouette cast by the new vertex
                    // Note that the new vertex is on the positive side
                    // of the current facet, so the current facet will
                    // not be in the polytope. Start local search
                    // from this facet.
                    edgeBuffer.MakeEmpty();
                    facet.silhouette(q, aBuf, bBuf, edgeBuffer, facetManager);
                    Edge edge       = edgeBuffer.Get(0);
                    int  bufferSize = edgeBuffer.Size();
                    //check to see whether we have enough space in the facet manager to create new facets
                    if (bufferSize > facetManager.getNumRemainingIDs())
                    {
                        return(PxGJKStatus.EPA_DEGENERATE);
                    }

                    Facet firstFacet = addFacet(edge.getTarget(), edge.getSource(), index, lower_bound, upper_bound);
                    firstFacet.link(0, edge.getFacet(), edge.getIndex());
                    Facet lastFacet = firstFacet;

                    bool degenerate = false;
                    for (int i = 1; (i < bufferSize) && (!degenerate); ++i)
                    {
                        edge = edgeBuffer.Get(i);
                        Facet newFacet = addFacet(edge.getTarget(), edge.getSource(), index, lower_bound, upper_bound);
                        bool  b0       = newFacet.link(0, edge.getFacet(), edge.getIndex());
                        bool  b1       = newFacet.link(2, lastFacet, 1);
                        degenerate = degenerate || !b0 || !b1;
                        lastFacet  = newFacet;
                    }

                    if (degenerate)
                    {
                        return(PxGJKStatus.EPA_DEGENERATE);
                    }
                    firstFacet.link(2, lastFacet, 1);
                }
                hasMoreFacets = (heap.size() > 0);

                if (hasMoreFacets && heap.peak().getPlaneDist() > upper_bound)
                {
                    calculateContactInformation(aBuf, bBuf, bestFacet, a, b, ref pa, ref pb, ref normal, ref penDepth);
                    return(PxGJKStatus.EPA_CONTACT);
                }
            } while (hasMoreFacets && numVertsLocal != MaxSupportPoints);

            return(PxGJKStatus.EPA_DEGENERATE);
        }
示例#15
0
        private float CalculateExternalAcceleration(LiveSpringPanel.WidgetInfo info, SpringType type)
        {
            float acceleration = 0f;

            switch (type)
            {
            case SpringType.AngleAxisX:
            case SpringType.PositionY:
                acceleration = this.sensorAcceleration.Y + this.moveAcceleration.Y + this.userAcceleration.Y;
                break;

            case SpringType.AngleAxisY:
                acceleration = -(this.sensorAcceleration.X + this.moveAcceleration.X + this.userAcceleration.X);
                break;

            case SpringType.AngleAxisZ:
            {
                bool   flag = false;
                bool[] useSpecifiedValues = info.useSpecifiedValues;
                for (int i = 0; i < useSpecifiedValues.Length; i++)
                {
                    bool flag2 = useSpecifiedValues[i];
                    flag |= flag2;
                }
                if (!flag)
                {
                    float num  = info.displacements[3];
                    float num2 = info.displacements[4];
                    float num3 = FMath.Abs(num);
                    float num4 = FMath.Abs(num2);
                    bool  flag3;
                    if (num * num2 > 0f)
                    {
                        flag3 = (num3 > num4);
                    }
                    else
                    {
                        flag3 = (num3 < num4);
                    }
                    float num5  = FMath.Min(FMath.Abs(num3 - num4), FMath.Min(num3, num4)) / 200f;
                    float num6  = flag3 ? num5 : (-num5);
                    float num7  = info.displacements[0];
                    float num8  = info.displacements[1];
                    float num9  = FMath.Abs(num7);
                    float num10 = FMath.Abs(num8);
                    if (-num7 * num8 > 0f)
                    {
                        flag3 = (num9 < num10);
                    }
                    else
                    {
                        flag3 = (num9 > num10);
                    }
                    num5 = FMath.Min(FMath.Abs(num9 - num10), FMath.Min(num9, num10)) / 20f;
                    float num11 = flag3 ? num5 : (-num5);
                    acceleration = num6 + num11;
                }
                break;
            }

            case SpringType.PositionX:
                acceleration = this.sensorAcceleration.X + this.moveAcceleration.X + this.userAcceleration.X;
                break;

            case SpringType.PositionZ:
                acceleration = this.sensorAcceleration.Z + this.moveAcceleration.Z + this.userAcceleration.Z;
                break;
            }
            if (type == SpringType.PositionX || type == SpringType.PositionY || type == SpringType.PositionZ)
            {
                return(this.ClipAcceleration(acceleration));
            }
            return(this.ClipAcceleration(acceleration) * 0.0125663709f);
        }