/// <summary> /// Normalize the angles. /// </summary> public void Normalize() { FP d = FP.PiTimes2 * FP.Floor((A0 / FP.PiTimes2)); A0 -= d; A -= d; }
public void Normalize() { FP y = MathHelper.TwoPi * FP.Floor(this.A0 / MathHelper.TwoPi); this.A0 -= y; this.A -= y; }
public Vector2Int WorldPosFloorGridPoint(TSVector2 pos) { pos -= SDF.Origin; pos /= SDF.Grain; ushort x = (ushort)FP.Floor(pos.x); ushort y = (ushort)FP.Floor(pos.y); return(new Vector2Int(x, y)); }
/// <summary> /// Passes a axis aligned bounding box to the shape where collision /// could occour. /// </summary> /// <param name="box">The bounding box where collision could occur.</param> /// <returns>The upper index with which <see cref="SetCurrentShape"/> can be /// called.</returns> public override int Prepare(ref TSBBox box) { // simple idea: the terrain is a grid. x and z is the position in the grid. // y the height. we know compute the min and max grid-points. All quads // between these points have to be checked. // including overflow exception prevention if (box.min.x < boundings.min.x) { minX = 0; } else { minX = (int)FP.Floor(((box.min.x - sphericalExpansion) / scaleX)); minX = (int)TSMath.Max(minX, 0); } if (box.max.x > boundings.max.x) { maxX = heightsLength0 - 1; } else { maxX = (int)FP.Ceiling(((box.max.x + sphericalExpansion) / scaleX)); maxX = (int)TSMath.Min(maxX, heightsLength0 - 1); } if (box.min.z < boundings.min.z) { minZ = 0; } else { minZ = (int)FP.Floor(((box.min.z - sphericalExpansion) / scaleZ)); minZ = (int)TSMath.Max(minZ, 0); } if (box.max.z > boundings.max.z) { maxZ = heightsLength1 - 1; } else { maxZ = (int)FP.Ceiling((FP)((box.max.z + sphericalExpansion) / scaleZ)); maxZ = (int)TSMath.Min(maxZ, heightsLength1 - 1); } numX = maxX - minX; numZ = maxZ - minZ; // since every quad contains two triangles we multiply by 2. return(numX * numZ * 2); }
/** * @brief Returns a {@link FP} between a min value [inclusive] and a max value [inclusive]. **/ public FP Next(float minValue, float maxValue) { int minValueInt = (int)(minValue * 1000), maxValueInt = (int)(maxValue * 1000); if (minValueInt > maxValueInt) { int tmp = maxValueInt; maxValueInt = minValueInt; minValueInt = tmp; } return((FP.Floor((maxValueInt - minValueInt + 1) * NextFP() + minValueInt)) / 1000); }
public FP Sample(TSVector2 pos) { pos /= Grain; int x = (int)FP.Floor(pos.x); int y = (int)FP.Floor(pos.y); int idx = x + y * Width; FP rx = pos.x - x; FP ry = pos.y - y; //2 3 //0 1 FP v0 = this[idx]; FP v1 = this[idx + 1]; FP v2 = this[idx + Width]; FP v3 = this[idx + Width + 1]; return((v0 * (1 - rx) + v1 * rx) * (1 - ry) + (v2 * (1 - rx) + v3 * rx) * ry); }
/// <summary> /// SDF 采样 /// </summary> /// <param name="sdf">sdf数据</param> /// <param name="pos">相对于sdf原点的位置</param> /// <returns>采样后对应位置的SD值</returns> public static FP Sample(this SDFRawData sdf, TSVector2 pos) { pos /= sdf.Grain; int x = (int)FP.Floor(pos.x); int y = (int)FP.Floor(pos.y); int idx = x + y * sdf.Width; FP rx = pos.x - x; FP ry = pos.y - y; //2 3 //0 1 FP v0 = sdf[idx]; FP v1 = sdf[idx + 1]; FP v2 = sdf[idx + sdf.Width]; FP v3 = sdf[idx + sdf.Width + 1]; return((v0 * (1 - rx) + v1 * rx) * (1 - ry) + (v2 * (1 - rx) + v3 * rx) * ry); }
/// <summary> /// Returns the largest integer less than or equal to the specified number. /// </summary> public static FP Floor(FP value) { return(FP.Floor(value)); }
public static Vector2Int FloorToGrid(this SDFRawData sdf, TSVector2 positin) { positin /= sdf.Grain; return(new Vector2Int((int)FP.Floor(positin.x), (int)FP.Floor(positin.y))); }