fCraft.Vector3f.GetLength C# (CSharp) Method

GetLength() public method

public GetLength ( ) : float
return float
        public float GetLength()
        {
            return (float)Math.Sqrt(x * x + y * y + h * h);
        }

Usage Example

Example #1
0
            void MakeRoots(RootBase[] rootbases)
            {
                foreach (Vector3i coord in foliageCoords)
                {
                    float dist = (float)Math.Sqrt(Sqr(coord[0] - pos[0]) + Sqr(coord[2] - pos[2]));
                    float ydist = coord[1] - pos[1];
                    float value = (branchDensity * 220 * height) / Cub(ydist + dist);
                    if (value < args.rand.NextDouble()) continue;

                    RootBase rootbase = rootbases[args.rand.Next(0, rootbases.Length)];
                    int rootx = rootbase.x;
                    int rootz = rootbase.z;
                    float rootbaseradius = rootbase.radius;

                    float rndr = (float)(Math.Sqrt(args.rand.NextDouble()) * rootbaseradius * .618);
                    float rndang = (float)(args.rand.NextDouble() * 2 * Math.PI);
                    int rndx = (int)(rndr * Math.Sin(rndang) + .5);
                    int rndz = (int)(rndr * Math.Cos(rndang) + .5);
                    int rndy = (int)(args.rand.NextDouble() * rootbaseradius * .5);
                    Vector3i startcoord = new Vector3i
                    {
                        x = rootx + rndx,
                        z = rootz + rndz,
                        y = pos[1] + rndy
                    };
                    Vector3f offset = new Vector3f(startcoord - coord);

                    if (args.SHAPE == TreeShape.Mangrove)
                    {
                        offset = offset * 1.618f - 1.5f;
                    }

                    Vector3i endcoord = startcoord + new Vector3i(offset);
                    float rootstartsize = (float)(rootbaseradius * .618 * Math.Abs(offset[1]) / (height * .618));

                    if (rootstartsize < 1) rootstartsize = 1;
                    float endsize = 1;

                    if (args.ROOTS == RootMode.ToStone ||
                        args.ROOTS == RootMode.Hanging)
                    {
                        float offlength = offset.GetLength();
                        if (offlength < 1) continue;
                        float rootmid = endsize;
                        Vector3f vec = offset / offlength;

                        int searchIndex = TILETYPE_AIR;
                        if (args.ROOTS == RootMode.ToStone)
                        {
                            searchIndex = TILETYPE_STONE;
                        }
                        else if (args.ROOTS == RootMode.Hanging)
                        {
                            searchIndex = TILETYPE_AIR;
                        }

                        int startdist = (int)(args.rand.NextDouble() * 6 * Math.Sqrt(rootstartsize) + 2.8);
                        Vector3i searchstart = new Vector3i(startcoord + vec * startdist);

                        dist = startdist + DistanceToBlock(args.inMap, new Vector3f(searchstart), vec, searchIndex);

                        if (dist < offlength)
                        {
                            rootmid += (rootstartsize - endsize) * (1 - dist / offlength);
                            endcoord = new Vector3i(startcoord + vec * dist);
                            if (args.ROOTS == RootMode.Hanging)
                            {
                                float remaining_dist = offlength - dist;
                                Vector3i bottomcord = endcoord;
                                bottomcord[1] -= (int)remaining_dist;
                                TaperedLimb(endcoord, bottomcord, rootmid, endsize);
                            }
                        }
                        TaperedLimb(startcoord, endcoord, rootstartsize, rootmid);
                    }
                    else
                    {
                        TaperedLimb(startcoord, endcoord, rootstartsize, endsize);
                    }
                }
            }
All Usage Examples Of fCraft.Vector3f::GetLength