コード例 #1
0
ファイル: Vertexer.cs プロジェクト: Cdrix/SM
    //it finds the closer vertex to it
    public Vector3 FindClosestVertex(Vector3 to, Vector3[] verticesP, float epsilon = 0.01f)
    {
        List <float> distances    = UMath.ReturnDistances(verticesP, to);
        List <int>   minimosIndex = UMath.ReturnTheIndexes(distances, 1, epsilon);

        return(verticesP[minimosIndex[0]]);
    }
コード例 #2
0
    void Update()
    {
        if (Time.time < lastCheck + randomTime)
        {
            return;
        }

        lastCheck = Time.time;
        if (_stageManager.IsSunsetOrLater() && _light.intensity == 0 && GameController.AreThereWhaleOil)
        {
            _light.intensity = 1.1f;
            TurnThisOneOn(_nightGlass);
            randomTime = UMath.GiveRandom(5f, 10f);
        }
        else if (_stageManager.IsDawnOrLater() && _light.intensity > 0)
        {
            _light.intensity = 0f;
            TurnThisOneOn(_dayGlass);

            if (Program.gameScene && Program.GameFullyLoaded())
            {
                GameController.ResumenInventory1.Remove(P.WhaleOil, 1f);
            }
        }
    }
コード例 #3
0
ファイル: UnitT.cs プロジェクト: naaturaz/SM
    private IEnumerator RandomSecUpdate()
    {
        while (true)
        {
            yield return(new WaitForSeconds(nextRand)); // wait

            if (IsGood)
            {
                if (Enemy == null || _enemyDist > 20)
                {
                    Enemy = Program.gameScene.EnemyManager.GiveMeClosestEnemy(transform.position);
                }
            }
            else
            {
                Enemy = Program.gameScene.UnitsManager.GiveMeClosestUnit(transform.position);
            }

            nextRand = UMath.GiveRandom(2, 3);

            if (Enemy != null)
            {
                _enemyDist = Vector3.Distance(transform.position, Enemy.position);
            }
        }
    }
コード例 #4
0
ファイル: Way.cs プロジェクト: Cdrix/SM
    void UpdateBigBoxesPrev()
    {
        InitializeBigBoxPrev();

        float diffYVertic = UMath.ReturnDiffBetwMaxAndMin(_verticPathNew, H.Y);
        float diffYHoriz  = UMath.ReturnDiffBetwMaxAndMin(_horPathNew, H.Y);
        float biggestDiff = UMath.ReturnMax(diffYVertic, diffYHoriz);

        List <float> yS = UList.ReturnAxisList(_verticPathNew, H.Y);

        yS.AddRange(UList.ReturnAxisList(_horPathNew, H.Y));
        float maxY = UMath.ReturnMax(yS);

        if (_dominantSide == H.Vertic)
        {
            var locVertBound = MakeListYVal(BoundsVertic, maxY);
            verticBigBox.UpdatePos(locVertBound, biggestDiff + 0.5f);
            verticBigBox.CheckAndSwitchColor(_isWayOK);
        }
        else if (_dominantSide == H.Horiz)
        {
            var locHorBound = MakeListYVal(BoundsHoriz, maxY);
            horizBigBox.UpdatePos(locHorBound, biggestDiff + 0.5f);
            horizBigBox.CheckAndSwitchColor(_isWayOK);
        }
        //this is for all but bridges and DraggableSquare. Dominant Side here is None
        else if (_dominantSide == H.None && !HType.ToString().Contains("Bridge") && Category != Ca.DraggableSquare)
        {
            UpdateBigBoxesPrevForAllButBridges(maxY, biggestDiff);
        }

        TogglePrevBigBoxesVisible();
    }
コード例 #5
0
ファイル: Builder.cs プロジェクト: Cdrix/SM
    //so when using dummy on CryBrdigeRoute can find its spawner
    //private string dummySpawnerId;
    /// <summary>
    /// Will return the init point which is the place will go to build and execute the animation on a building
    /// </summary>
    /// <returns></returns>
    Vector3 FindFinRoutePoint()
    {
        //bridge
        if (_constructing.HType.ToString().Contains(H.Bridge.ToString()))
        {
            if (_constructing.Anchors.Count > 0)
            {
                //    dummySpawnerId = _person.Work.MyId;
                return(Brain.ReturnClosestVector3(_person.Work.transform.position, _constructing.Anchors));
            }
        }
        else if (IsAShoreOrTerraBuilding(_constructing))
        {
            if (_constructing.Anchors.Count > 0)
            {
                //return the closest anchor to SpawnPoint . must be the SpawnPoint so it always selects
                //the one on the shore
                var sp = (StructureParent)_constructing;

                //return _constructing.Anchors[UMath.GiveRandom(0, 4)];
                var closest = Brain.ReturnClosestVector3(sp.SpawnPoint.transform.position, _constructing.Anchors);
                return(Vector3.MoveTowards(closest, _constructing.transform.position, -.2f));
            }
        }

        //so will take a break
        if (_constructing.Anchors.Count == 0)
        {
            return(new Vector3());
        }

        //for all other cases
        //forcing geting the anchors was giving anchors really far appart sometimes
        return(_constructing.GetAnchors(true)[UMath.GiveRandom(0, 4)]);
    }
コード例 #6
0
    /// <summary>
    /// Only evaluates X and Z axis... only works for the type of 90 degrees abanico
    /// implementado aqui
    /// </summary>
    /// <param name="list"></param>
    /// <param name="stone"></param>
    /// <returns></returns>
    public static Vector3 FindClosestPos(List <Vector3> list, Vector3 stone)
    {
        List <float> distances = new List <float>();

        for (int i = 0; i < list.Count; i++)
        {
            float dist = Vector3.Distance(stone, list[i]);
            distances.Add(dist);
            //General cloneTexto = General.Create(Root.texto3d, list[i]);
            //cloneTexto.GetComponent<TextMesh>().text = i.ToString();
        }

        int   indexRes = -1;
        float min      = UMath.ReturnMinimum(distances);

        for (int i = 0; i < distances.Count; i++)
        {
            if (distances[i] == min)
            {
                indexRes = i;
            }
        }

        return(list[indexRes]);
    }
コード例 #7
0
ファイル: CrystalManager.cs プロジェクト: naaturaz/SM
    public Vector3 ReturnTownIniPos()
    {
        if (_inLands == null)
        {
            _inLands = CrystalRegions.Where(a => a.WhatAudioIReport == "InLand").ToList();
        }
        var indexA    = UMath.GiveRandom(0, _inLands.Count);
        var point     = _inLands[indexA].Position();
        var realIndex = _inLands[indexA].Index;

        //UVisHelp.CreateHelpers(point, Root.yellowCube);
        var inTerrain = UTerra.IsOnTerrainManipulateTerrainSize(point, -40f);//-1

        if (!inTerrain || !IsAdjacentToShore(realIndex))
        {
            if (count1 > 500)
            {
                throw new Exception("500 times ReturnTownIniPos() CrystalManager");
            }
            count1++;
            _inLands.RemoveAt(indexA);

            return(ReturnTownIniPos());
        }
        Debug.Log("Count1: " + count1 + " ..ReturnTownIniPos() CrystalManager");
        count1 = 0;
        _initialRegionIndex = realIndex;
        return(point);
    }
コード例 #8
0
    public static List <Vector3> FindVectorsOnSameRange(List <Vector3> list, float compare, H axis, float epsilon)
    {
        List <Vector3> res = new List <Vector3>();

        for (int i = 0; i < list.Count; i++)
        {
            if (axis == H.X)
            {
                if (UMath.nearlyEqual(list[i].x, compare, epsilon))
                {
                    res.Add(list[i]);
                }
            }
            else if (axis == H.Y)
            {
                if (UMath.nearlyEqual(list[i].y, compare, epsilon))
                {
                    res.Add(list[i]);
                }
            }
            else if (axis == H.Z)
            {
                if (UMath.nearlyEqual(list[i].z, compare, epsilon))
                {
                    res.Add(list[i]);
                }
            }
        }
        return(res);
    }
コード例 #9
0
ファイル: Jumping.cs プロジェクト: masterchop/uraider
    private bool TryReachLedge(PlayerController player, float zVel, ref float yVel, bool allowClearingBoost = true)
    {
        // Doing standing jump, allow player to grab if close
        if (zVel < 0.5f)
        {
            zVel = 0.5f;
        }

        // Need to check where player will be relative to ledge
        float   timeAtPeak   = yVel / player.Gravity; // v = u + at
        Vector3 relative     = ledgeInfo.Point - player.transform.position;
        float   displacement = UMath.GetHorizontalMag(relative);
        // Maximum to account for when player hits wall but keeps moving up
        float timeAtLedge = Mathf.Max(UMath.TimeAtHorizontalPoint(zVel, displacement), timeAtPeak);
        float vertPos     = UMath.PredictDisplacement(yVel, timeAtLedge, -player.Gravity);

        if (vertPos >= relative.y - 2.6f && vertPos <= relative.y - 0.8f) // Distance is great, do auto-grab
        {
            player.StateMachine.GoToState <AutoGrabbing>(ledgeInfo);
            return(true);
        }
        else if (allowClearingBoost && vertPos < relative.y && vertPos > relative.y - 0.8f) // she hits it around the hip just adjust up velocity to clear it
        {
            float   time;
            Vector3 adjustedVel = UMath.VelocityToReachPoint(player.transform.position,
                                                             ledgeInfo.Point, zVel, player.Gravity, out time);
            yVel = adjustedVel.y;
        }

        return(false);
    }
コード例 #10
0
ファイル: WaterBound.cs プロジェクト: naaturaz/SM
    /// <summary>
    /// This are the vertices that create the marine bound
    /// </summary>
    private void FindVertexUnderNeathWater()
    {
        var   yS         = UList.FindYAxisCommonValues(m.AllVertexs, H.Descending);
        float firstUnder = UList.FindFirstYBelow(yS, Program.gameScene.WaterBody.transform.position.y);

        _marineBounds = UList.FindVectorsOnSameHeight(m.AllVertexs, firstUnder, 0.05f); //0.07f
        _marineBounds = UList.EliminateDuplicatesByDist(_marineBounds, 0.3f);           //0.2

        float firstClos = UList.FindFirstYBelow(yS, m.IniTerr.MathCenter.y - 1f);
        var   closer    = UList.FindVectorsOnSameHeight(m.AllVertexs, firstClos, 0.02f); //0.07f

        closer = UList.EliminateDuplicatesByDist(closer, 0.3f);                          //0.2

        _marineBounds.AddRange(closer);

        float lowest = UMath.ReturnMinimumDifferentThanZero(yS) + 1f;
        var   low    = UList.FindVectorsOnSameHeight(m.AllVertexs, lowest, 0.01f); //0.07f

        low = UList.EliminateDuplicatesByDist(low, 0.4f);                          //0.2

        _marineBounds.AddRange(low);

        //RenderMarineBounds();
        Debug.Log(_marineBounds.Count + " _marineBounds");
        //AddMarinePositions();

        DefineSeaPath(_marineBounds);
        addMarine = true;

        //AddMarineBoundsToCrystal();
    }
コード例 #11
0
    public virtual bool Act(double x, double y, double z, ref Voxel voxel)
    {
        var vpos            = new Vector3d(x, y, z);
        var distanceSquared = position.DistanceSquared(vpos);

        if (distanceSquared < radiusSquared)
        {
            var px = (int)((x - (position.x - radius)) * stepInverse);
            var py = (int)((y - (position.y - radius)) * stepInverse);
            var pz = (int)((z - (position.z - radius)) * stepInverse);
            if (px >= 0 && px < size - 1 && py >= 0 && py < size - 1 && pz >= 0 && pz < size - 1)
            {
                var pointInCell = vpos - new Vector3d(px * step + (position.x - radius),
                                                      py * step + (position.y - radius),
                                                      pz * step + (position.z - radius));
                pointInCell *= stepInverse;

                var interpolated = UMath.TrilinearInterpolate(
                    GetVoxelValue(voxelValues, px, py, pz),
                    GetVoxelValue(voxelValues, px, py, pz + 1),
                    GetVoxelValue(voxelValues, px, py + 1, pz),
                    GetVoxelValue(voxelValues, px, py + 1, pz + 1),
                    GetVoxelValue(voxelValues, px + 1, py, pz),
                    GetVoxelValue(voxelValues, px + 1, py, pz + 1),
                    GetVoxelValue(voxelValues, px + 1, py + 1, pz),
                    GetVoxelValue(voxelValues, px + 1, py + 1, pz + 1),
                    pointInCell
                    );

                voxel.Value = UMath.Lerp(interpolated, voxel.Value, distanceSquared * radiusSquaredInverse);
            }
        }

        return(false);
    }
コード例 #12
0
ファイル: WaterBound.cs プロジェクト: naaturaz/SM
    private void DefineMountPath(List <float> yS)
    {
        float highest = UMath.ReturnMax(yS);

        _mountainPath = UList.FindVectorsOnSameHeight(m.AllVertexs, highest, 0.03f); //0.03f
        _mountainPath = UList.EliminateDuplicatesByDist(_mountainPath, 0.4f);        //0.2
    }
コード例 #13
0
    // Update is called once per frame
    public void Update()
    {
        //correcting bug where kids stay in front of storage with path completed
        if ((_destWasSet && _agent.isOnNavMesh && _agent.enabled && !_person.IsMajor &&
             !UMath.nearEqualByDistance(_agent.destination, Destiny, 0.1f) &&
             _agent.pathStatus == NavMeshPathStatus.PathComplete)
            ||
            (_agent.pathStatus == NavMeshPathStatus.PathInvalid && _agent.enabled && _agent.isOnNavMesh)
            )
        {
            //so i set the destination again to the real one so they move towards it
            _agent.SetDestination(Destiny);
        }

        if (_nextDest != new Vector3() && !_destWasSet && _agent.isOnNavMesh && _agent.enabled)
        {
            _destWasSet = true;
            _agent.SetDestination(Destiny);
            _startDate = Program.gameScene.GameTime1.CurrentDate();
        }
        CheckIfGoingIntoBuild();
        RadiusForHeavyLoaders();

        CheckVelocity();
        CheckIfTempSpeed();
        CheckIfPathPending();

        CheckIfStuck();
    }
コード例 #14
0
ファイル: DeltaCapsule.cs プロジェクト: Cdrix/SM
 List <CheckPoint> validCheckPoints          = new List <CheckPoint>(); //checkpoint validated they will be used for last result
 private void DeltaQualityCheck()
 {
     for (int i = 0; i < bucketCheckPoints.Count - 1; i++)
     {
         //if is not the same
         if (!UMath.nearEqualByDistance(bucketCheckPoints[i].Point, bucketCheckPoints[i + 1].Point, 0.1f))
         {
             if (!RouterManager.IsWaterOrMountainBtw(bucketCheckPoints[i].Point, bucketCheckPoints[i + 1].Point))
             {
                 validCheckPoints.Add(bucketCheckPoints[i]);
             }
             //if is in water wont add the current one
             else
             {
                 RestartDeltaRouter(bucketCheckPoints[i].Point);
                 Init();
                 deltaRouted = false;
                 return;
             }
         }
     }
     //add the last one
     validCheckPoints.Add(bucketCheckPoints[bucketCheckPoints.Count - 1]);
     DoneDelta();
 }
コード例 #15
0
ファイル: UPoly.cs プロジェクト: Cdrix/SM
    //will even 1 poly  in Y.
    private List <Vector3> EvenInYPoly(List <Vector3> poly, ref Vector3[] vertices)
    {
        float maxY       = UMath.ReturnMax(poly[0].y, poly[1].y, poly[2].y, poly[3].y);
        float minY       = UMath.ReturnMinimum(poly[0].y, poly[1].y, poly[2].y, poly[3].y);
        float heightDiff = maxY - minY;

        //print(heightDiff + " heightDiff");

        for (int i = 0; i < poly.Count; i++)
        {
            Vector3 newModifiedYPos = poly[i];
            newModifiedYPos.y = minY;
            poly[i]           = newModifiedYPos;
        }

        float epsilon = 0.1f;

        for (int i = 0; i < vertices.Length; i++)
        {
            for (int j = 0; j < poly.Count; j++)
            {
                //if this are the same in X and Z we are updating
                bool x = UMath.nearlyEqual(vertices[i].x, poly[j].x, epsilon);
                bool z = UMath.nearlyEqual(vertices[i].z, poly[j].z, epsilon);
                if (x && z)
                {   //updating the whole vertices matrix
                    vertices[i] = poly[j];
                }
            }
        }
        return(poly);
    }
コード例 #16
0
ファイル: Decoration.cs プロジェクト: Cdrix/SM
    private void SpawnDecorObj()
    {
        if (_roots.Count == 0)
        {
            return;
        }

        _spwnedObj = General.Create(Root.classesContainer, _building.transform.position, "", _building.transform,
                                    H.Decoration);

        _spwnedObj.Category = _spwnedObj.DefineCategory(H.Decoration);

        for (int i = 0; i < _positionsToSpawnDecor.Count; i++)
        {
            var root = _roots[UMath.GiveRandom(0, _roots.Count)];

            //moving a bit away from  buildings
            //var iniPos = Vector3.MoveTowards(_positionsToSpawnDecor[i], _building.transform.position, -.2f);

            var spwnObj = General.Create(root, _positionsToSpawnDecor[i], container: _building.transform, name: "Decora");
            RandomizeRotAndScale(spwnObj.gameObject, root);

            var subs = General.FindAllChildsGameObjectInHierarchy(spwnObj.gameObject);

            //will make all subs child of '_spwnedObj'
            for (int j = 0; j < subs.Length; j++)
            {
                subs[j].transform.SetParent(_spwnedObj.transform);
            }
            //bz they are useless. I got the subObjects already
            spwnObj.Destroy();
        }
    }
コード例 #17
0
    /// <summary>
    /// now user wont select terrain will be always at random
    ///
    /// to remember would nt work in Standalone bz in StandAlone the root was:
    /// C:/GitHub/SM/10.05/SugarMill_Data\Bay_And_Mountain_1_River.Spawned.xml
    /// and the additional dot in '10.05' will mess below code
    ///
    /// READ if is failing needs the Developer = true
    /// </summary>
    /// <returns></returns>
    private string ReturnRandomTerraRoot()
    {
        _dataPath = Application.dataPath;

        //gets all xml files
        var           xmls        = Directory.GetFiles(_dataPath, "*.xml").ToList();
        List <string> validTerras = new List <string>();

        for (int i = 0; i < xmls.Count; i++)
        {
            var splitArray = xmls[i].Split('.');
            Debug.Log("xmls: " + xmls[i]);

            if (splitArray.Length > 1 && splitArray[1] == "Spawned")
            {
                //confirms that they have a terra file tht has the same name
                if (ConfirmThisIsATerraFile(splitArray[0], xmls))
                {
                    validTerras.Add(splitArray[0]);
                    Debug.Log("validTerras: " + splitArray[0]);
                }
            }
        }

        var rand      = validTerras[UMath.GiveRandom(0, validTerras.Count)];
        var cleanRand = RemoveDataPath(rand, _dataPath);

        return(AddPrefabTerrainRoot(cleanRand));
    }
コード例 #18
0
    public bool Act(double x, double y, double z, ref Voxel voxel)
    {
        double distance;
        var    pos = new Vector3d(x, y, z);
        var    orthogonalOntoLine = UMath.OrthogonalProjectionOntoLineNormalized(pos, start, direction);

        var orthoDistanceToStart = Vector3d.Dot(direction, orthogonalOntoLine - start);

        if (orthoDistanceToStart > 0 && orthoDistanceToStart < length)
        {
            distance = (orthogonalOntoLine - pos).Magnitude;
        }
        else
        {
            distance = Math.Min((start - pos).Magnitude, (end - pos).Magnitude);
        }

        if (dig)
        {
            voxel.Value = Math.Max(voxel.Value, (radius - distance) * voxelSizeInverse);
        }
        else
        {
            voxel.Value = Math.Min(voxel.Value, (distance - radius) * voxelSizeInverse);
        }

        if (voxelType != null && distance <= radius + 0.1)
        {
            voxel.VoxelType = voxelType;
            return(true);
        }

        return(false);
    }
コード例 #19
0
ファイル: SubPolyr.cs プロジェクト: Cdrix/SM
    //Returns first row list based on the rotation facer
    private List <Vector3> ReturnFirstRow(List <Vector3> listSelected, int rotationFacer)
    {
        List <Vector3> res = new List <Vector3>();

        if (rotationFacer == 0)
        {
            List <float> allZ = UList.ReturnAxisList(listSelected, H.Z);
            float        zMax = UMath.ReturnMax(allZ);
            res = FirstRowLoop(listSelected, zMax, H.Z);
        }
        else if (rotationFacer == 1)
        {
            List <float> allX = UList.ReturnAxisList(listSelected, H.X);
            float        xMax = UMath.ReturnMax(allX);
            res = FirstRowLoop(listSelected, xMax, H.X);
        }
        else if (rotationFacer == 2)
        {
            List <float> allZ = UList.ReturnAxisList(listSelected, H.Z);
            float        zMin = UMath.ReturnMinimum(allZ);
            res = FirstRowLoop(listSelected, zMin, H.Z);
        }
        else if (rotationFacer == 3)
        {
            List <float> allX = UList.ReturnAxisList(listSelected, H.X);
            float        xMin = UMath.ReturnMinimum(allX);
            res = FirstRowLoop(listSelected, xMin, H.X);
        }
        return(res);
    }
コード例 #20
0
 /// <summary>
 /// 5 % of them will get rocket as Target
 /// </summary>
 void StartTargetAdquired()
 {
     if (UMath.GiveRandom(1, 101) > 50)//or 20 % of the time
     {
         TargetRocket();
     }
 }
コード例 #21
0
ファイル: Way.cs プロジェクト: Cdrix/SM
    /// <summary>
    /// Define with path of a bridge is the longest used
    /// </summary>
    void DefineBridgeDominantSide()
    {
        if (_verticPathNew.Count == 0 || _horPathNew.Count == 0)
        {
            return;
        }

        float verticYDiff = UMath.ReturnDiffBetwMaxAndMin(_verticPathNew, H.Y);
        float horYDiff    = UMath.ReturnDiffBetwMaxAndMin(_horPathNew, H.Y);

        if (verticYDiff > horYDiff)
        {
            _dominantSide = H.Vertic;
        }
        else if (verticYDiff < horYDiff)
        {
            _dominantSide = H.Horiz;
        }
        else
        {
            _dominantSide = H.Same_Length_Both_Sides;
            IsWayEven     = false;
            print("Unable to place bridge here Way.cs both side are the same or bridge is on the floor");
        }
    }
コード例 #22
0
ファイル: AutoGrabbing.cs プロジェクト: masterchop/uraider
    public override void Update(PlayerController player)
    {
        if (Time.time - timeTracker >= grabTime)
        {
            if (ledgeInfo.Type == LedgeType.Monkey || (UMath.GetHorizontalMag(player.Velocity) > 2f && HasFeetRoom()))
            {
                player.Anim.SetTrigger("DeepGrab");
            }
            if (UMath.GetHorizontalMag(player.Velocity) > 0.2f)
            {
                player.Anim.SetTrigger("Grab");
            }
            else
            {
                player.Anim.SetTrigger("StandGrab");
            }

            player.transform.position = grabPoint;

            if (ledgeInfo.Type == LedgeType.Free)
            {
                player.StateMachine.GoToState <Freeclimb>();
            }
            else if (ledgeInfo.Type == LedgeType.Monkey)
            {
                player.StateMachine.GoToState <MonkeySwing>();
            }
            else
            {
                player.StateMachine.GoToState <Climbing>();
            }
        }
    }
コード例 #23
0
ファイル: Way.cs プロジェクト: Cdrix/SM
    /// <summary>
    /// If the minimun of the both path is higher than _minHeightToSpawn is true
    /// </summary>
    bool FindIFWayAboveWater()
    {
        bool  res      = false;
        float minYVert = 0;
        float minYHor  = 0;

        if (_verticPathNew.Count > 0)
        {
            var vertYs = UList.ReturnAxisList(_verticPathNew, H.Y);
            minYVert = UMath.ReturnMinimum(vertYs);
            if (minYVert > _minHeightToSpawn)
            {
                res = true;
            }
        }
        if (_horPathNew.Count > 0)
        {
            var horYs = UList.ReturnAxisList(_horPathNew, H.Y);
            minYHor = UMath.ReturnMinimum(horYs);
            if (minYHor > _minHeightToSpawn)
            {
                res = true;
            }
        }
        if (_verticPathNew.Count > 0 && _horPathNew.Count > 0)
        {
            var min = UMath.ReturnMinimum(minYVert, minYHor);
            if (min > _minHeightToSpawn)
            {
                res = true;
            }
        }

        return(res);
    }
コード例 #24
0
    /// <summary>
    /// Create The sequence of a bridge is 1,2,3,4,1,2,3,4,1... ,  1 is the tallest part and 3 the middle one
    /// </summary>
    private List <int> CreateUnEvenSequence(int amount)
    {
        List <int> res        = new List <int>();
        List <int> firstHalf  = new List <int>();
        List <int> secondHalf = new List <int>();

        //1st half
        int current = 3;

        firstHalf.Add(current);
        for (int i = 0; i < (amount - 1) / 2; i++)
        {
            current = UMath.GoAround(-1, current, 1, 4);
            firstHalf.Add(current);
        }
        firstHalf.Reverse();

        //2nd half
        current = 4;
        secondHalf.Add(current);
        for (int i = 0; i < (amount - 2) / 2; i++)
        {
            current = UMath.GoAround(1, current, 1, 4);
            secondHalf.Add(current);
        }

        res.AddRange(firstHalf);
        res.AddRange(secondHalf);
        return(res);
    }
コード例 #25
0
ファイル: Registro.cs プロジェクト: Cdrix/SM
    /// <summary>
    /// Taken a list of vectors 3 will find NW, NE, and SW and from there will create a new rectangle
    /// Returns a rectangle in our system where North is on the higher Y value always
    ///
    /// Y val flipped at the end
    /// </summary>
    public static Rect FromALotOfVertexToRect(List <Vector3> list)
    {
        List <float> xS = UList.ReturnAxisList(list, H.X);
        List <float> zS = UList.ReturnAxisList(list, H.Z);

        float minX = UMath.ReturnMinimum(xS);
        float maxX = UMath.ReturnMax(xS);

        float minZ = UMath.ReturnMinimum(zS);
        float maxZ = UMath.ReturnMax(zS);

        //Poly List that only need a valid NW, NE, and SW
        Vector3 NW = new Vector3(minX, 0, maxZ);
        Vector3 NE = new Vector3(maxX, 0, maxZ);
        Vector3 SE = new Vector3(maxX, 0, minZ);
        Vector3 SW = new Vector3(minX, 0, minZ);

        List <Vector3> poly = new List <Vector3>()
        {
            NW, NE, SE, SW
        };

        //here i find the Rect from this poly and then
        // I invert the Y of the recatangle... other wise this big rectangle
        //is not overlapping anything will be far off in the Cordinates...
        //Due to North(up) is bigger here say 100,, and South(down) less say 0 all this on World Z axis
        //As long as MeshManager Hover Current Vertices is big as is its now 9 Lots (each lot 5x5 real polys)
        //the Rect of the buildings will work flawlessly
        return(U2D.ReturnRectYInverted(U2D.FromPolyToRect(poly)));
    }
コード例 #26
0
            public static LabelWithConfidence LabelWithConfidence(NeuralNet model, NNInstrumentation instr, double[] datum, bool crop)
            {
                Vector <double> datum_v = DenseVector.OfArray(datum);

                if (crop)
                {
                    datum_v = model.CropMaybe(datum_v);
                }

                double[] outs = model.EvaluateNNConcretePostCrop(datum_v, instr);

//                Console.WriteLine("Outs = {0}", DenseVector.OfArray(outs));


                Tuple <double, int> max    = UMath.Max(outs);
                Tuple <double, int> secmax = UMath.MaxExcluding(max.Item2, outs);

                UMath.SoftMax(outs);

                var result = new LabelWithConfidence
                {
                    datum              = datum,
                    actualLabel        = max.Item2,
                    secBestLabel       = secmax.Item2,
                    softMaxValue       = outs[max.Item2],
                    diffFromSecondBest = Math.Abs(outs[max.Item2] - outs[secmax.Item2])
                };

                return(result);
            }
コード例 #27
0
    public void Update()
    {
        if (_vertexes == null && _building != null &&
            !UMath.nearEqualByDistance(_building.transform.position, new Vector3(), 1f))
        {
            _vertexes = _building.Geometry.GetComponent <MeshFilter>().mesh.vertices;
            _diff     = _building.transform.position - new Vector3();
        }

        if (_count < _vertexes.Length)
        {
            var        cube = UVisHelp.CreateHelpers(_vertexes[_count] + _diff, Root.cube);
            GameObject go   = new GameObject();
            go.transform.SetParent(_container.transform);
            go.transform.localPosition = new Vector3();

            cube.transform.SetParent(go.transform);

            go.transform.localScale    = _building.Geometry.transform.localScale;
            go.transform.localRotation = _building.Geometry.transform.localRotation;
            go.transform.localPosition = _building.Geometry.transform.localPosition;

            _show.Add(cube);
            _empties.Add(go);

            _count++;
        }
    }
コード例 #28
0
    public void MoveGrounded(float speed)
    {
        Vector3 targetVector = RawTargetVector(speed);

        targetAngle = Vector3.SignedAngle(Vector3.forward, targetVector.normalized, Vector3.up);
        targetSpeed = UMath.GetHorizontalMag(targetVector);

        anim.SetFloat("SignedTargetAngle", targetAngle);
        anim.SetFloat("TargetAngle", Mathf.Abs(targetAngle));
        anim.SetFloat("TargetSpeed", targetSpeed);

        // Allows Lara to smoothly take off
        if (localVelocity.sqrMagnitude == 0f && targetVector.magnitude > 0.1f)
        {
            Vector3 camForward = cam.forward;
            camForward.y = 0f;
            camForward.Normalize();

            // Finds correct forward direction for local velocity
            localVelocity = Quaternion.FromToRotation(camForward, transform.forward) * (Vector3.forward * 0.1f);
        }

        localVelocity = Vector3.Slerp(localVelocity, targetVector, Time.deltaTime * speedChangeRate);

        velocity = Quaternion.Euler(0f, cam.eulerAngles.y, 0f) * localVelocity;

        float actualSpeed = direction * UMath.GetHorizontalMag(velocity);

        anim.SetFloat("Speed", actualSpeed);
    }
コード例 #29
0
    protected override double ExecuteFilter(double x, double y, double z, CallableNode flow, double inputValue)
    {
        var v01 = UMath.Clamp(0, 1, UMath.InverseLerp(inMin, inMax, inputValue));
        var vC  = curve.Evaluate((float)v01);

        return(UMath.Lerp(outMin, outMax, vC));
    }
コード例 #30
0
ファイル: UpperCombat.cs プロジェクト: facybenbook/uraider
    public override void Update(PlayerController player)
    {
        if (player.StateMachine.IsInState <Dead>() ||
            (!Input.GetKey(player.Inputf.drawWeapon) && Input.GetAxisRaw("CombatTrigger") < 0.1f))
        {
            player.UpperStateMachine.GoToState <Empty>();
            return;
        }

        if (player.Weapons.target == null)
        {
            CheckForTargets(player);
        }

        Vector3 aimDirection = player.Weapons.target != null ?
                               (player.Weapons.target.position - player.transform.position).normalized
            : UMath.ZeroYInVector(player.Cam.forward).normalized;

        float aimAngle = Vector3.SignedAngle(aimDirection, player.transform.forward, Vector3.up);

        player.Anim.SetFloat("AimAngle", aimAngle);
        player.Anim.SetBool("isFiring", Input.GetKey(player.Inputf.fireWeapon));

        // Stops player's waist wobbling
        player.WaistRotation = player.transform.rotation;
    }