Beispiel #1
0
    /// <summary>
    /// Will create the poly small. on the direction and will find if is coliiding with another
    /// </summary>
    /// <param name="dir"></param>
    /// <returns></returns>
    private List <Vector3> ReturnPolyToEval(Tile dir)
    {
        var x   = m.SubDivide.XSubStep;
        var z   = m.SubDivide.ZSubStep;
        var pos = new Vector3();

        if (dir == Tile.N)
        {
            pos = new Vector3(transform.position.x, transform.position.y, transform.position.z + z);
        }
        else if (dir == Tile.S)
        {
            pos = new Vector3(transform.position.x, transform.position.y, transform.position.z - z);
        }
        else if (dir == Tile.W)
        {
            pos = new Vector3(transform.position.x - x, transform.position.y, transform.position.z);
        }
        else if (dir == Tile.E)
        {
            pos = new Vector3(transform.position.x + x, transform.position.y, transform.position.z);
        }
        //UVisHelp.CreateHelpers(pos, Root.blueCube);
        return(UPoly.CreatePolyFromVector3(pos, 0.01f, 0.01f));
    }
Beispiel #2
0
    private void CreateBasePlane()
    {
        var dimen = _fieldFarm.SpaceBtwPlants - 0.5f;

        var locPoly   = UPoly.CreatePolyFromVector3(transform.position, dimen, dimen);
        var basePlane = CreatePlane.CreatePlan(Root.createPlane, Root.matFarmSoil, raiseFromFloor: 0.08f, container: transform);

        basePlane.UpdatePos(locPoly);
    }
Beispiel #3
0
    /// <summary>
    /// Returns Random position from origin. If fell inside a building will find another spot
    /// until is in a clear zone
    /// If origin is not specified will assume is CamControl.CAMRTS.hitFront.point the center of terrain
    /// </summary>
    /// <param name="howFar">How far will go</param>
    Vector3 AssignAnimalRandomIniPosition(Vector3 origin, Rect area, float howFar, float animalDim)
    {
        float x           = UMath.Random(-howFar, howFar);
        float z           = UMath.Random(-howFar, howFar);
        var   originMoved = new Vector3(origin.x + x, origin.y, origin.z + z);
        var   _bounds     = UPoly.CreatePolyFromVector3(originMoved, animalDim, animalDim);

        if (!area.Contains(new Vector2(originMoved.x, originMoved.z)) ||
            Spawner.CollideWithExistingAnimal(originMoved, Id, animalDim)
            )
        {
            aniCount++;
            if (aniCount > 1000)
            {
                return(new Vector3());
            }
            originMoved = AssignAnimalRandomIniPosition(origin, area, howFar, animalDim);
        }
        return(originMoved);
    }
Beispiel #4
0
    /// <summary>
    /// Will return position if 'oringin' was not contained in a building ...
    /// other wise will recurse keep moving towards target... until a spot is find it that
    /// is not contained in a building or 'origin' is equals 'target'
    /// </summary>
    public Vector3 AssignIniPositionIfNotInBuild(Vector3 origin, Vector3 target)
    {
        var personBounds = UPoly.CreatePolyFromVector3(origin, _person.PersonDim, _person.PersonDim);

        //if bound collide will recurse
        if (BuildingPot.Control.Registro.IsCollidingWithExisting(personBounds))
        {
            //if both are the same they the origin was moved all the way untli the target
            //so no more recursion is needed... i couldnt find a point where was not building
            //this is covering a infinite loop, should nt happen ever
            if (UMath.nearEqualByDistance(origin, target, 0.1f))
            {
                throw new Exception("origin reach target on AssignIniPositionIfNotInBuild() DeltaRouter");
            }

            origin = Vector3.MoveTowards(origin, target, 0.04f);
            origin = AssignIniPositionIfNotInBuild(origin, target);
        }
        return(origin);
    }
Beispiel #5
0
    /// <summary>
    /// Returns Random position from origin. If fell inside a building will find another spot
    /// until is in a clear zone
    ///
    /// If origin is not specified will use MeshController.AllVertexs.Count
    ///
    /// Will throw new Exception("Cant be use if MeshController.AllVertexs.Count == 0");
    /// </summary>
    /// <param name="howFar">How far will go</param>
    Vector3 AssignRandomIniPosition(Vector3 origin = new Vector3(), float howFar = 1)
    {
        if (origin == new Vector3())
        {
            origin = ReturnIniPos();
        }

        //so origin is not changed in every recursive
        if (originalPoint == new Vector3())
        {
            originalPoint = origin;
            origin        = ReturnRandomPos(origin, howFar);
        }
        else
        {
            origin = ReturnRandomPos(originalPoint, howFar);
        }
        //will add one unit to how far so can move further
        //doesnt matter that is positive bz in ReturnRandomPos goes in the range of the same number negative and positive
        howFar += .1f;//.1f

        //to check if the poly ard it is free of obstacles
        var polyToCheck = UPoly.CreatePolyFromVector3(origin, 1f, 1f);//1, 1

        if (MeshController.CrystalManager1.IntersectAnyLine(polyToCheck, origin) || !IsOnTerrain(origin) ||
            !ComplyWithTerraRules(origin))
        {
            secCount++;
            if (secCount > 1000)
            {
                throw new Exception("Infinite loop terraSpawContrl");
            }
            //UVisHelp.CreateText(origin, "R" + "");
            origin = AssignRandomIniPosition(origin, howFar);
        }

        originalPoint = new Vector3();
        secCount      = 0;
        return(origin);
    }