public float GetValue(float x, float y, float z) { x *= Frequency; y *= Frequency; z *= Frequency; return(Primitive3D.GetValue(x, y, z)); }
public float GetValue(float x, float y, float z) { float signal; int curOctave; x *= Frequency; y *= Frequency; z *= Frequency; // Initialize value : get first octave of function; later octaves are weighted var value = Primitive3D.GetValue(x, y, z) + Offset; var weight = Gain * value; x *= Lacunarity; y *= Lacunarity; z *= Lacunarity; // inner loop of spectral construction, where the fractal is built for (curOctave = 1; weight > 0.001 && curOctave < OctaveCount; curOctave++) { // prevent divergence if (weight > 1.0) { weight = 1.0f; } // get next higher frequency signal = (Offset + Primitive3D.GetValue(x, y, z)) * SpectralWeights[curOctave]; // The weighting from the previous octave is applied to the signal. signal *= weight; // Add the signal to the output value. value += signal; // update the (monotonically decreasing) weighting value weight *= Gain * signal; // Go to the next octave. x *= Lacunarity; y *= Lacunarity; z *= Lacunarity; } //take care of remainder in OctaveCount var remainder = OctaveCount - (int)OctaveCount; if (remainder > 0.0f) { signal = Primitive3D.GetValue(x, y, z); signal *= SpectralWeights[curOctave]; signal *= remainder; value += signal; } return(value); }
public void SelectFaceByNumberOfSides(int sides) { foreach (Primitive3D primitive in childPrimitives) { primitive.SelectFaceByNumberOfSides(sides); if (primitive.SelectedFace != null) { ActivePrimitive = primitive; return; } } ActivePrimitive = null; }
public float GetValue(float x, float y, float z) { float signal; int curOctave; x *= Frequency; y *= Frequency; z *= Frequency; // Initialize value : first unscaled octave of function; later octaves are scaled var value = Offset + Primitive3D.GetValue(x, y, z); x *= Lacunarity; y *= Lacunarity; z *= Lacunarity; // inner loop of spectral construction, where the fractal is built for (curOctave = 1; curOctave < OctaveCount; curOctave++) { // obtain displaced noise value. signal = Offset + Primitive3D.GetValue(x, y, z); //scale amplitude appropriately for this frequency signal *= SpectralWeights[curOctave]; // scale increment by current altitude of function signal *= value; // Add the signal to the output value. value += signal; // Go to the next octave. x *= Lacunarity; y *= Lacunarity; z *= Lacunarity; } //take care of remainder in OctaveCount var remainder = OctaveCount - (int)OctaveCount; if (remainder > 0.0f) { signal = Offset + Primitive3D.GetValue(x, y, z); signal *= SpectralWeights[curOctave]; signal *= value; signal *= remainder; value += signal; } return(value); }
public float GetValue(float x, float y, float z) { int curOctave; var ox = x; x *= Frequency; y *= Frequency; z *= Frequency; // Initialize value, fBM starts with 0 float value = 0; // Inner loop of spectral construction, where the fractal is built for (curOctave = 0; curOctave < OctaveCount; curOctave++) { // Get the coherent-noise value. var signal = Primitive3D.GetValue(x, y, z) * SpectralWeights[curOctave]; if (signal < 0.0) { signal = -signal; } // Add the signal to the output value. value += signal; // Go to the next octave. x *= Lacunarity; y *= Lacunarity; z *= Lacunarity; } //take care of remainder in OctaveCount var remainder = OctaveCount - (int)OctaveCount; if (remainder > 0.0f) { value += remainder * Primitive3D.GetValue(x, y, z) * SpectralWeights[curOctave]; } return((float)Math.Sin(ox + value)); }
private void Awake() { foreach (Primitive3D primitive in GetComponentsInChildren <Primitive3D>()) { childPrimitives.Add(primitive); ActivePrimitive = primitive; // hacky solution to get any primitive primitive.ParentSolid = this; } ParentSolid = null; Children = new HashSet <Solid3D>(); if (isStatic) { isPowered = isIntiallyPowered; } else { IsPowered = isIntiallyPowered; SetLight(LIGHTING.DEFAULT); } }
public float GetValue(float x, float y, float z) { int curOctave; x *= Frequency; y *= Frequency; z *= Frequency; // Initialize value var value = 1.0f; // inner loop of spectral construction, where the fractal is built for (curOctave = 0; curOctave < OctaveCount; curOctave++) { // Get the coherent-noise value. var signal = Offset + Primitive3D.GetValue(x, y, z) * SpectralWeights[curOctave]; // Add the signal to the output value. value *= signal; // Go to the next octave. x *= Lacunarity; y *= Lacunarity; z *= Lacunarity; } //take care of remainder in OctaveCount var remainder = OctaveCount - (int)OctaveCount; if (remainder > 0.0f) { value += remainder * Primitive2D.GetValue(x, y) * SpectralWeights[curOctave]; } return(value); }
public float GetValue(float x, float y, float z) { return(Primitive3D.GetValue(x * XScale, y * YScale, z * ZScale)); }
public float GetValue(float x, float y, float z) { int curOctave; x *= Frequency; y *= Frequency; z *= Frequency; // Initialize value : 1st octave var signal = Primitive3D.GetValue(x, y, z); // get absolute value of signal (this creates the ridges) if (signal < 0.0) { signal = -signal; } // invert and translate (note that "offset" should be ~= 1.0) signal = Offset - signal; // Square the signal to increase the sharpness of the ridges. signal *= signal; // Add the signal to the output value. var value = signal; var weight = 1.0f; for (curOctave = 1; weight > 0.001 && curOctave < OctaveCount; curOctave++) { x *= Lacunarity; y *= Lacunarity; z *= Lacunarity; // Weight successive contributions by the previous signal. weight = Libnoise.Clamp01(signal * Gain); // Get the coherent-noise value. signal = Primitive3D.GetValue(x, y, z); // Make the ridges. if (signal < 0.0f) { signal = -signal; } signal = Offset - signal; // Square the signal to increase the sharpness of the ridges. signal *= signal; // The weighting from the previous octave is applied to the signal. // Larger values have higher weights, producing sharp points along the // ridges. signal *= weight; // Add the signal to the output value. value += signal * SpectralWeights[curOctave]; } return(value); }
public float GetValue(float x, float y, float z) { //TODO This method could be more efficient by caching the seed values. x *= Frequency; y *= Frequency; z *= Frequency; var xInt = x > 0.0f ? (int)x : (int)x - 1; var yInt = y > 0.0f ? (int)y : (int)y - 1; var zInt = z > 0.0f ? (int)z : (int)z - 1; var minDist = 2147483647.0f; var xCandidate = 0.0f; var yCandidate = 0.0f; var zCandidate = 0.0f; // Inside each unit cube, there is a seed point at a random position. Go // through each of the nearby cubes until we find a cube with a seed point // that is closest to the specified position. for (var zCur = zInt - 2; zCur <= zInt + 2; zCur++) { for (var yCur = yInt - 2; yCur <= yInt + 2; yCur++) { for (var xCur = xInt - 2; xCur <= xInt + 2; xCur++) { // Calculate the position and distance to the seed point inside of // this unit cube. var xPos = xCur + Primitive3D.GetValue(xCur, yCur, zCur); var yPos = yCur + Primitive3D.GetValue(xCur, yCur, zCur); var zPos = zCur + Primitive3D.GetValue(xCur, yCur, zCur); var xDist = xPos - x; var yDist = yPos - y; var zDist = zPos - z; var dist = xDist * xDist + yDist * yDist + zDist * zDist; if (dist < minDist) { // This seed point is closer to any others found so far, so record // this seed point. minDist = dist; xCandidate = xPos; yCandidate = yPos; zCandidate = zPos; } } } } float value; if (Distance) { // Determine the distance to the nearest seed point. var xDist = xCandidate - x; var yDist = yCandidate - y; var zDist = zCandidate - z; value = (float)Math.Sqrt(xDist * xDist + yDist * yDist + zDist * zDist) * Libnoise.Sqrt3 - 1.0f; } else { value = 0.0f; } // Return the calculated distance with the displacement value applied. return(value + Displacement * Primitive3D.GetValue( (int)Math.Floor(xCandidate), (int)Math.Floor(yCandidate), (int)Math.Floor(zCandidate))); }
Object3D RandomPrimitive(double x, double y, double z, Brush brush1, Brush brush2) { Primitive3D obj = null; double angle1 = 180 * randy.NextDouble(); double angle2 = 180 * (1 + randy.NextDouble()); int index = count > 150 ? 2 : ++count % 10; switch (index) { case 0: //--- more cubes, please :-) case 1: obj = new Cube(); break; case 2: obj = new Balloon(z); break; case 3: obj = new Cone { IsClosed = true }; break; case 4: obj = new Cylinder { IsClosed = true }; break; case 5: obj = new Cylinder { StartDegrees = angle1, StopDegrees = angle2, IsClosed = true }; break; case 6: obj = new Disk(); break; case 7: obj = new Disk { StartDegrees = angle1, StopDegrees = angle2 }; break; case 8: obj = new Square(); break; case 9: obj = new Triangle(); break; } obj.ScaleZ = z; obj.Position = new Point3D(x, y, z); obj.DiffuseMaterial.Brush = GetRandomBrush(); if (index > 5) { //--- flat objects need a BackMaterial and are rotated obj.BackMaterial = obj.Material; obj.Rotation1 = Math3D.RotationX(angle1); obj.Rotation2 = Math3D.RotationY(angle2); } else if (index < 2)//--- cubes { obj.DiffuseMaterial.Brush = brush1; obj.Position = new Point3D(x, y, z + 0.01); //--- avoid z fighting with the ground } else if (index == 2) //--- balloon { obj.ScaleZ = obj.ScaleX * 1.2; } else if (index == 4 || index == 5)//--- cylinder { obj.DiffuseMaterial.Brush = brush2; obj.Rotation1 = new Quaternion(Math3D.UnitZ, angle1); } return(obj); }
// Update is called once per frame void Update() { if (false) { if (!isCameraLocked) { if (Input.touchCount == 1) { Touch touch = Input.GetTouch(0); if (secondTouchInitiated) { touchStart = touch.position; secondTouchInitiated = false; } switch (touch.phase) { case TouchPhase.Began: touchStart = touch.position; break; case TouchPhase.Moved: if ((touch.position - touchStart).sqrMagnitude > INPUT.DRAG_THRESHOLD) { isDragging = true; } if (isDragging) { transform.Translate((touchStart - touch.position) * lookDistance * INPUT.ROTATION_SPEED, Space.Self); touchStart = touch.position; } break; case TouchPhase.Ended: if (isDragging) { } else { Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out RaycastHit hit)) { Primitive3D hitPrimitive = hit.collider.gameObject.GetComponent <CollisionHandler>().ParentPrimitive; hitPrimitive.SelectFaceByNormal(hit.normal); LevelManager.Current.SelectFace(hitPrimitive.SelectedFace); } } isDragging = false; break; } } else if (Input.touchCount == 2) { float touchDistance = (Input.GetTouch(1).position - Input.GetTouch(0).position).magnitude; if (!secondTouchInitiated) { initialTouchDistance = touchDistance; isDragging = true; secondTouchInitiated = true; } lookDistance = Mathf.Clamp(lookDistance + ((touchDistance - initialTouchDistance) * INPUT.ZOOM_SPEED), INPUT.MIN_LOOK_DISTANCE, INPUT.MAX_LOOK_DISTANCE); } if (!isCameraLocked) { transform.LookAt(LookTarget); transform.position = transform.position.normalized * lookDistance; } } } else { if (!isCameraLocked) { if (Input.GetMouseButtonDown(0)) { mousePosition = Input.mousePosition; lastMousePosition = Input.mousePosition; } if (Input.GetMouseButton(0)) { if (isDragging) { transform.Translate((Input.mousePosition - lastMousePosition).normalized * 0.1f, Space.Self); lastMousePosition = Input.mousePosition; } else { if (Vector3.Distance(Input.mousePosition, mousePosition) > 10) { isDragging = true; } } } if (Input.GetMouseButtonUp(0) && Vector3.Distance(Input.mousePosition, mousePosition) < 10) { if (isDragging) { isDragging = false; } else { Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out RaycastHit hit)) { Primitive3D hitPrimitive = hit.collider.gameObject.GetComponent <CollisionHandler>().ParentPrimitive; hitPrimitive.SelectFaceByNormal(hit.normal); LevelManager.Current.SelectFace(hitPrimitive.SelectedFace); } } } if (!isCameraLocked) { transform.LookAt(LookTarget); transform.position = transform.position.normalized * 12; } } } }