public Vector3f(Vector3f other) { x = other.x; y = other.y; h = other.h; }
static int DistanceToBlock( Map map, Vector3f coord, Vector3f vec, Block blockType, bool invert ) { coord += .5f; int iterations = 0; while( map.InBounds( new Vector3i( coord ) ) ) { byte blockAtPos = map.GetBlockByte( new Vector3i( coord ) ); if( (blockAtPos == (byte)blockType && !invert) || (blockAtPos != (byte)blockType && invert) ) { break; } else { coord += vec; iterations++; } } return iterations; }
public Vector3i(Vector3f other) { x = (int)other.x; z = (int)other.y; y = (int)other.h; }
void MakeRoots( RootBase[] rootbases ) { if( rootbases.Length == 0 ) return; 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; const float endsize = 1; if( Args.Roots == RootMode.ToStone || Args.Roots == RootMode.Hanging ) { float offlength = offset.Length; if( offlength < 1 ) continue; float rootmid = endsize; Vector3f vec = offset / offlength; Block searchIndex = Block.Air; if( Args.Roots == RootMode.ToStone ) { searchIndex = Block.Stone; } else if( Args.Roots == RootMode.Hanging ) { searchIndex = Block.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 remainingDist = offlength - dist; Vector3i bottomcord = endcoord; bottomcord[1] -= (int)remainingDist; TaperedLimb( endcoord, bottomcord, rootmid, endsize ); } } TaperedLimb( startcoord, endcoord, rootstartsize, rootmid ); } else { TaperedLimb( startcoord, endcoord, rootstartsize, endsize ); } } }
static int DistanceToBlock( Map map, Vector3f coord, Vector3f vec, Block blockType ) { return DistanceToBlock( map, coord, vec, blockType, false ); }
public static int DistanceToBlock(IMapStorage map, Vector3f coord, Vector3f vec, int blockType, bool invert) { coord += .5f; int iterations = 0; while (MapUtil.IsValidPos(map, (int)coord.x, (int)coord.y, (int)coord.h)) { byte blockAtPos = (byte)map.GetBlock((int)coord.x, (int)coord.y, (int)coord.h); if ((blockAtPos == (byte)blockType && !invert) || (blockAtPos != (byte)blockType && invert)) { break; } else { coord += vec; iterations++; } } return iterations; }
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); } } }
public static int DistanceToBlock(IMapStorage map, Vector3f coord, Vector3f vec, int blockType) { return DistanceToBlock(map, coord, vec, blockType, false); }
public Vector3i(Vector3f other) { X = (int)other.X; Z = (int)other.Y; Y = (int)other.Z; }
public int CompareTo(Vector3f other) { return(Math.Sign(LengthSquared - other.LengthSquared)); }