public override void UpdateNode() { if (!Initialized) { GetPosition(TargetPosition); Initialized = true; } KeyDown(); MouseWheel(); MouseButtons(); MouseMotion(); double dt = Time.deltaTime * 1000.0; // If animation requried interpolate from start to end position // NOTE : has not been tested and not currently used if (AnimationValue >= 0.0) { AnimationValue = View.Interpolate(StartPosition, EndPosition, AnimationValue); if (BrainFuckMath.NearlyEqual(AnimationValue, 1.0)) { GetPosition(TargetPosition); AnimationValue = -1.0; } } else { UpdateController(dt); } }
private void Update() { Vector3 temp = Vector3.zero; using (new Timer("CalculatePatchCubeCenter")) { for (int i = 0; i < 1000000; i++) { BrainFuckMath.CalculatePatchCubeCenter(0, Vector3.zero, ref temp); } } }
public static bool operator !=(Matrix4x4d m1, Matrix4x4d m2) { for (byte iRow = 0; iRow < 4; iRow++) { for (byte iCol = 0; iCol < 4; iCol++) { if (!BrainFuckMath.NearlyEqual(m1.m[iRow, iCol], m2.m[iRow, iCol])) { return(true); } } } return(false); }
public Vector3 CalculateMiddlePoint(Vector3 topLeft, Vector3 bottomRight, Vector3 topRight, Vector3 bottomLeft) { var size = bottomLeft - topLeft; bool staticX = false, staticY = false, staticZ = false; float tempStatic = 0; BrainFuckMath.DefineAxis(ref staticX, ref staticY, ref staticZ, size); var middle = ((topLeft + bottomRight) * (1.0f / Mathf.Abs(LODLevel))).NormalizeToRadius(Planetoid.PlanetRadius); BrainFuckMath.LockAxis(ref tempStatic, ref middle, staticX, staticY, staticZ); BrainFuckMath.UnlockAxis(ref middle, ref tempStatic, staticX, staticY, staticZ); return(middle); }
public Vector3 GetPatchCubeCenter(QuadPosition quadPosition) { // NOTE : So, here i will construct vector with specific parameters. // I need unit axis vector, depending on Quad Orientation [QuadPosition] with positive or negative value [Planet Radius]. // "Sign" will represent 'Is value negative or positive?' // "Axis" will represent one component of vector, which should be 'valued' [X or Y or Z]. Other vector components will be zero... // TOP (0.0, r, 0.0) SIGN 0 AXIS 0 Y // BUTTOM (0.0, -r, 0.0) SIGN 1 AXIS 0 Y // LEFT (-r, 0.0, 0.0) SIGN 1 AXIS 2 X // RIGHT (r, 0.0, 0.0) SIGN 0 AXIS 2 X // FRONT (0.0, 0.0, r) SIGN 0 AXIS 1 Z // BACK (0.0, 0,0, -r) SIGN 1 AXIS 1 Z var sign = new byte[] { 0, 1, 1, 0, 0, 1 }; var axis = new byte[] { 1, 1, 0, 0, 2, 2 }; return(BrainFuckMath.FromQuadPositionMask(Planetoid.PlanetRadius, sign, axis, quadPosition)); }
private IEnumerator Split() { var id = 0; var subTopLeft = Vector3.zero; var subBottomRight = Vector3.zero; var subTopRight = Vector3.zero; var subBottomLeft = Vector3.zero; var size = quadCorners.bottomRightCorner - quadCorners.topLeftCorner; var step = size / 2.0f; bool staticX = false, staticY = false, staticZ = false; BrainFuckMath.DefineAxis(ref staticX, ref staticY, ref staticZ, size); Planetoid.Working = true; Splitting = true; Unsplitted = false; for (byte sY = 0; sY < 2; sY++) { for (byte sX = 0; sX < 2; sX++, id++) { if (staticX) { subTopLeft = new Vector3(quadCorners.topLeftCorner.x, quadCorners.topLeftCorner.y + step.y * sY, quadCorners.topLeftCorner.z + step.z * sX); subBottomRight = new Vector3(quadCorners.topLeftCorner.x, quadCorners.topLeftCorner.y + step.y * (sY + 1), quadCorners.topLeftCorner.z + step.z * (sX + 1)); subTopRight = new Vector3(quadCorners.topLeftCorner.x, quadCorners.topLeftCorner.y + step.y * sY, quadCorners.topLeftCorner.z + step.z * (sX + 1)); subBottomLeft = new Vector3(quadCorners.topLeftCorner.x, quadCorners.topLeftCorner.y + step.y * (sY + 1), quadCorners.topLeftCorner.z + step.z * sX); } else if (staticY) { subTopLeft = new Vector3(quadCorners.topLeftCorner.x + step.x * sX, quadCorners.topLeftCorner.y, quadCorners.topLeftCorner.z + step.z * sY); subBottomRight = new Vector3(quadCorners.topLeftCorner.x + step.x * (sX + 1), quadCorners.topLeftCorner.y, quadCorners.topLeftCorner.z + step.z * (sY + 1)); subTopRight = new Vector3(quadCorners.topLeftCorner.x + step.x * (sX + 1), quadCorners.topLeftCorner.y, quadCorners.topLeftCorner.z + step.z * sY); subBottomLeft = new Vector3(quadCorners.topLeftCorner.x + step.x * sX, quadCorners.topLeftCorner.y, quadCorners.topLeftCorner.z + step.z * (sY + 1)); } else if (staticZ) { subTopLeft = new Vector3(quadCorners.topLeftCorner.x + step.x * sX, quadCorners.topLeftCorner.y + step.y * sY, quadCorners.topLeftCorner.z); subBottomRight = new Vector3(quadCorners.topLeftCorner.x + step.x * (sX + 1), quadCorners.topLeftCorner.y + step.y * (sY + 1), quadCorners.topLeftCorner.z); subTopRight = new Vector3(quadCorners.topLeftCorner.x + step.x * (sX + 1), quadCorners.topLeftCorner.y + step.y * sY, quadCorners.topLeftCorner.z); subBottomLeft = new Vector3(quadCorners.topLeftCorner.x + step.x * sX, quadCorners.topLeftCorner.y + step.y * (sY + 1), quadCorners.topLeftCorner.z); } var quad = Planetoid.SetupSubQuad(Position); quad.Splitting = true; quad.ShouldDraw = false; quad.InitCorners(subTopLeft, subBottomRight, subTopRight, subBottomLeft); quad.Parent = this; quad.LODLevel = quad.Parent.LODLevel + 1; quad.ID = (QuadID)id; quad.SetupVectors(quad, id, staticX, staticY, staticZ); if (quad.Parent.transform != null) { quad.transform.parent = quad.Parent.transform; } quad.gameObject.name = string.Format("{0}_ID{1}_LOD{2}", quad.gameObject.name, id, quad.LODLevel); Subquads.Add(quad); if (Planetoid.WaitOnSplit) { for (var wait = 0; wait < Planetoid.DispatchSkipFramesCount; wait++) { yield return(Yielders.EndOfFrame); } } } } //Dispatch one by one with intervals. for (byte i = 0; i < Subquads.Count; i++) { Subquads[i].ReadyForDispatch = true; for (var wait = 0; wait < Planetoid.DispatchSkipFramesCount; wait++) { yield return(Yielders.EndOfFrame); } } for (byte i = 0; i < Subquads.Count; i++) { Subquads[i].Splitting = false; Subquads[i].ShouldDraw = true; } ShouldDraw = false; Splitting = false; Planetoid.Working = false; }
private Vector3 GetPatchCubeCenterSplitted_Old(QuadPosition quadPosition, int id, bool staticX, bool staticY, bool staticZ) { var temp = Vector3.zero; var r = Planetoid.PlanetRadius; var v = Planetoid.PlanetRadius / 2; var tempStatic = 0.0f; var sign = new byte[][] { new byte[] { 4, 0, 5, 1 }, new byte[] { 7, 3, 6, 2 }, new byte[] { 4, 5, 6, 7 }, new byte[] { 1, 0, 3, 2 }, new byte[] { 0, 4, 2, 6 }, new byte[] { 5, 1, 7, 3 } }; var axis = new byte[] { 2, 2, 4, 4, 1, 1 }; var sideSign = sign[(int)quadPosition][id]; var sideAxis = axis[(int)quadPosition]; var maskVector = BrainFuckMath.MakeBitMask(sideSign); var maskAxisVector = BrainFuckMath.MakeBitMask(sideAxis); var vector = BrainFuckMath.ApplyBitMask(maskAxisVector, r, v); var output = BrainFuckMath.ApplyBitMask(vector, maskVector); temp = output; // NOTE : So, here i will construct vector with specific parameters. Much slower than switch { ... }, but F**K OFF! I wanna brainfucking stuff, cuz i can! // "Sign" will represent 'Wich component of vector what sign have?' // "Axis" will represent 'What value shoud i use for vector component? Left or right? 1.0 or 0.0?' // Example [Sign] - 110 - [-X, -Y, Z] // Example [Axis] - 010 - [0.0, 1.0, 0.0] // Example [Together] - - [-0.0, -0.0, 0.0] // AXIS [2, 2, 4, 4, 1, 1] // TOP (-v, r, v) :0 SIGN 100-4 AXIS 010-2 [4, 0, 5, 1] // TOP (v, r, v) :1 SIGN 000-0 AXIS 010-2 // TOP (-v, r, -v) :2 SIGN 101-5 AXIS 010-2 // TOP (v, r, -v) :3 SIGN 001-1 AXIS 010-2 // --------------------------------------------------- // BUTTOM (-v, -r, -v):0 SIGN 111-7 AXIS 010-2 [7, 3, 6, 2] // BUTTOM (v, -r, -v) :1 SIGN 011-3 AXIS 010-2 // BUTTOM (-v, -r, v) :2 SIGN 110-6 AXIS 010-2 // BUTTOM (v, -r, v) :3 SIGN 010-2 AXIS 010-2 // --------------------------------------------------- // LEFT (-r, v, v) :0 SIGN 100-4 AXIS 100-4 [4, 5, 6, 7] // LEFT (-r, v, -v) :1 SIGN 101-5 AXIS 100-4 // LEFT (-r, -v, v) :2 SIGN 110-6 AXIS 100-4 // LEFT (-r, -v, -v):3 SIGN 111-7 AXIS 100-4 // --------------------------------------------------- // RIGHT (r, v, -v) :0 SIGN 001-1 AXIS 100-4 [1, 0, 3, 2] // RIGHT (r, v, v) :1 SIGN 000-0 AXIS 100-4 // RIGHT (r, -v, -v) :2 SIGN 011-3 AXIS 100-4 // RIGHT (r, -v, v) :3 SIGN 010-2 AXIS 100-4 // --------------------------------------------------- // FRONT (v, v, r) :0 SIGN 000-0 AXIS 001-1 [0, 4, 2, 6] // FRONT (-v, v, r) :1 SIGN 100-4 AXIS 001-1 // FRONT (v, -v, r) :2 SIGN 010-2 AXIS 001-1 // FRONT (-v, -v, r) :3 SIGN 110-6 AXIS 001-1 // --------------------------------------------------- // BACK (-v, v, -r) :0 SIGN 101-5 AXIS 001-1 [5, 1, 7, 3] // BACK (v, v, -r) :1 SIGN 001-1 AXIS 001-1 // BACK (-v, -v, -r):2 SIGN 111-7 AXIS 001-1 // BACK (v, -v, -r) :3 SIGN 011-3 AXIS 001-1 BrainFuckMath.LockAxis(ref tempStatic, ref temp, staticX, staticY, staticZ); BrainFuckMath.CalculatePatchCubeCenter(LODLevel, Parent.generationConstants.patchCubeCenter, ref temp); BrainFuckMath.UnlockAxis(ref temp, ref tempStatic, staticX, staticY, staticZ); //Just make sure that our vector values is rounded... //if(Planetoid.PlanetRadius % 2 == 0) temp = temp.RoundToInt(); //NOTE : FLOATING POINT PRECISION ANYWAY! return(temp); }
private Vector3 GetPatchCubeCenterSplitted_New(QuadPosition quadPosition, int id, bool staticX, bool staticY, bool staticZ) { // NOTE : Yaaahuuu! var temp = Vector3.zero; var tempStatic = 0.0f; var pcc = Parent.generationConstants.patchCubeCenter; var fed = Parent.generationConstants.cubeFaceEastDirection / 2.0f; var fnd = Parent.generationConstants.cubeFaceNorthDirection / 2.0f; switch (quadPosition) { case QuadPosition.Top: { if (id == 0) { temp = new Vector3(-fnd.x, pcc.y, -fed.z); } else if (id == 1) { temp = new Vector3(fnd.x, pcc.y, -fed.z); } else if (id == 2) { temp = new Vector3(-fnd.x, pcc.y, fed.z); } else if (id == 3) { temp = new Vector3(fnd.x, pcc.y, fed.z); } } break; case QuadPosition.Bottom: { if (id == 0) { temp = new Vector3(fnd.x, pcc.y, fed.z); } else if (id == 1) { temp = new Vector3(-fnd.x, pcc.y, fed.z); } else if (id == 2) { temp = new Vector3(fnd.x, pcc.y, -fed.z); } else if (id == 3) { temp = new Vector3(-fnd.x, pcc.y, -fed.z); } } break; case QuadPosition.Left: { if (id == 0) { temp = new Vector3(pcc.x, -fed.y, -fnd.z); } else if (id == 1) { temp = new Vector3(pcc.x, -fed.y, fnd.z); } else if (id == 2) { temp = new Vector3(pcc.x, fed.y, -fnd.z); } else if (id == 3) { temp = new Vector3(pcc.x, fed.y, fnd.z); } } break; case QuadPosition.Right: { if (id == 0) { temp = new Vector3(pcc.x, -fed.y, -fnd.z); } else if (id == 1) { temp = new Vector3(pcc.x, -fed.y, fnd.z); } else if (id == 2) { temp = new Vector3(pcc.x, fed.y, -fnd.z); } else if (id == 3) { temp = new Vector3(pcc.x, fed.y, fnd.z); } } break; case QuadPosition.Front: { if (id == 0) { temp = new Vector3(fed.x, -fnd.y, pcc.z); } else if (id == 1) { temp = new Vector3(-fed.x, -fnd.y, pcc.z); } else if (id == 2) { temp = new Vector3(fed.x, fnd.y, pcc.z); } else if (id == 3) { temp = new Vector3(-fed.x, fnd.y, pcc.z); } } break; case QuadPosition.Back: { if (id == 0) { temp = new Vector3(-fed.x, fnd.y, pcc.z); } else if (id == 1) { temp = new Vector3(fed.x, fnd.y, pcc.z); } else if (id == 2) { temp = new Vector3(-fed.x, -fnd.y, pcc.z); } else if (id == 3) { temp = new Vector3(fed.x, -fnd.y, pcc.z); } } break; } BrainFuckMath.LockAxis(ref tempStatic, ref temp, staticX, staticY, staticZ); temp += Parent.generationConstants.patchCubeCenter; BrainFuckMath.UnlockAxis(ref temp, ref tempStatic, staticX, staticY, staticZ); return(temp); }
private double Mix(double x, double y, double t) { return BrainFuckMath.NearlyEqual(x, y) ? y : x * (1.0 - t) + y * t; }
public Vector3 GetPatchCubeCenterSplitted(QuadPosition quadPosition, int id, bool staticX, bool staticY, bool staticZ) { var temp = Vector3.zero; var r = Planetoid.PlanetRadius; var v = Planetoid.PlanetRadius / 2; var tempStatic = 0.0f; switch (quadPosition) { case QuadPosition.Top: if (id == 0) { temp += new Vector3(-v, r, v); } else if (id == 1) { temp += new Vector3(v, r, v); } else if (id == 2) { temp += new Vector3(-v, r, -v); } else if (id == 3) { temp += new Vector3(v, r, -v); } break; case QuadPosition.Bottom: if (id == 0) { temp += new Vector3(-v, -r, -v); } else if (id == 1) { temp += new Vector3(v, -r, -v); } else if (id == 2) { temp += new Vector3(-v, -r, v); } else if (id == 3) { temp += new Vector3(v, -r, v); } break; case QuadPosition.Left: if (id == 0) { temp += new Vector3(-r, v, v); } else if (id == 1) { temp += new Vector3(-r, v, -v); } else if (id == 2) { temp += new Vector3(-r, -v, v); } else if (id == 3) { temp += new Vector3(-r, -v, -v); } break; case QuadPosition.Right: if (id == 0) { temp += new Vector3(r, v, -v); } else if (id == 1) { temp += new Vector3(r, v, v); } else if (id == 2) { temp += new Vector3(r, -v, -v); } else if (id == 3) { temp += new Vector3(r, -v, v); } break; case QuadPosition.Front: if (id == 0) { temp += new Vector3(v, v, r); } else if (id == 1) { temp += new Vector3(-v, v, r); } else if (id == 2) { temp += new Vector3(v, -v, r); } else if (id == 3) { temp += new Vector3(-v, -v, r); } break; case QuadPosition.Back: if (id == 0) { temp += new Vector3(-v, v, -r); } else if (id == 1) { temp += new Vector3(v, v, -r); } else if (id == 2) { temp += new Vector3(-v, -v, -r); } else if (id == 3) { temp += new Vector3(v, -v, -r); } break; default: throw new ArgumentOutOfRangeException("quadPosition", quadPosition, null); } BrainFuckMath.LockAxis(ref tempStatic, ref temp, staticX, staticY, staticZ); BrainFuckMath.CalculatePatchCubeCenter(LODLevel, Parent.generationConstants.patchCubeCenter, ref temp); BrainFuckMath.UnlockAxis(ref temp, ref tempStatic, staticX, staticY, staticZ); //Just make sure that our vector values is rounded... //if(Planetoid.PlanetRadius % 2 == 0) temp = temp.RoundToInt(); //NOTE : FLOATING POINT PRECISION ANYWAY! return(temp); }
public static bool operator ==(Vector3d v1, Vector3d v2) { return(BrainFuckMath.NearlyEqual(v1.x, v2.x) || BrainFuckMath.NearlyEqual(v1.y, v2.y) || BrainFuckMath.NearlyEqual(v1.z, v2.z)); }
private void ProduceTile(int level, int tx, int ty, ref long offset, long[] offsets, string file) { var tileSize = Mathf.Min(TopLevelSize << level, this.Size); Logger.Log(string.Format("HeightMipmap.ProduceTile: Producing tile {0}:{1}:{2}!", level, tx, ty)); if (level == 0) { CurrentLevel = 0; Reset(tileSize, tileSize, tileSize); for (int j = 0; j <= tileSize + 4; ++j) { for (int i = 0; i <= tileSize + 4; ++i) { var index = i + j * (tileSize + 5); TileData[index] = GetTileHeight(i - 2, j - 2) / Scale; } } } else { LoadTile("Residual", level, tx, ty, TileData); } int tileid; if (level < MinLevel) { tileid = level; } else { var levelLength = Mathf.Max(level - MinLevel, 0); tileid = MinLevel + tx + ty * (1 << levelLength) + ((1 << (2 * levelLength)) - 1) / 3; } var isConstant = true; for (int i = 0; i < (tileSize + 5) * (tileSize + 5) * 1; ++i) { if (!BrainFuckMath.AlmostEquals(TileData[i], 0.0f)) { isConstant = false; break; } } if (isConstant && ConstantTile != -1) { Logger.Log("HeightMipmap.ProduceTile: tile is const (All zeros)!"); offsets[2 * tileid] = offsets[2 * ConstantTile]; offsets[2 * tileid + 1] = offsets[2 * ConstantTile + 1]; } else { var data = new byte[TileData.Length * 2]; for (int i = 0; i < TileData.Length; i++) { short z = (short)Mathf.Round(TileData[i] / MaxR[level] * (float)short.MaxValue); data[2 * i] = (byte)(z & 0xFF); data[2 * i + 1] = (byte)(z >> 8); } using (Stream stream = new FileStream(file, FileMode.Open)) { stream.Seek(offset, SeekOrigin.Begin); stream.Write(data, 0, data.Length); } offsets[2 * tileid] = offset; offset += data.Length; offsets[2 * tileid + 1] = offset; } if (isConstant && ConstantTile == -1) { ConstantTile = tileid; } }
public static float Divide(float a, float b) { return(!BrainFuckMath.AlmostEquals(b, 0.0f) ? a / b : 0.0f); }