private UTIL.EPosition GetCameraPositionToCenterTerrain(Vector3 _position) { Vector2 pos2D = StaticMaths.ThreeDTo2D(_position, StaticMaths.EPlane.E_XZ); UTIL.EPosition pos = UTIL.EPosition.ECenter; int halfDim = GetTerrainDimCenter(); if (StaticMaths.WithinBoundingBox(pos2D, StaticMaths.ThreeDTo2D(StaticMaths.MultiplyVector3D(terrainChunks[halfDim, halfDim].GetCenter(), TILES.Offset), StaticMaths.EPlane.E_XZ), planetData.GetTerrainSize() + StaticMaths.ThreeDTo2D(TILES.Offset, StaticMaths.EPlane.E_XZ) * 2)) { } else { if (pos2D.y < terrainChunks[halfDim, halfDim].GetCenter().z - planetData.GetTerrainSize().y / 2) { pos = UTIL.EPosition.EAbove; } else if (pos2D.y > terrainChunks[halfDim, halfDim].GetCenter().z + planetData.GetTerrainSize().y / 2) { pos = UTIL.EPosition.EBelow; } else if (pos2D.x < terrainChunks[halfDim, halfDim].GetCenter().x - planetData.GetTerrainSize().x / 2) { pos = UTIL.EPosition.ELeft; } else if (pos2D.x > terrainChunks[halfDim, halfDim].GetCenter().x + planetData.GetTerrainSize().x / 2) { pos = UTIL.EPosition.ERight; } } return(pos); }
private UTIL.EPosition GetCameraPositionToCenterMap(Vector3 _position) { Vector2 pos2D = StaticMaths.ThreeDTo2D(_position, StaticMaths.EPlane.E_XZ); UTIL.EPosition pos = UTIL.EPosition.ECenter; if (StaticMaths.WithinBoundingBox(pos2D, StaticMaths.ThreeDTo2D(map.GetActualCenter(), StaticMaths.EPlane.E_XZ), new Vector2(chunkTileCountX * TILES.Offset.x, chunkTileCountZ * TILES.Offset.z) + StaticMaths.ThreeDTo2D(TILES.Offset, StaticMaths.EPlane.E_XZ) * 2)) { pos = UTIL.EPosition.ECenter; } else { if (pos2D.y < mapObject.transform.position.z + (chunkTileCountZ * TILES.Offset.z)) { pos = UTIL.EPosition.EAbove; } else if (pos2D.y > mapObject.transform.position.z - (chunkTileCountZ * TILES.Offset.z)) { pos = UTIL.EPosition.EBelow; } else if (pos2D.x < mapObject.transform.position.x + (chunkTileCountX * TILES.Offset.x)) { pos = UTIL.EPosition.ELeft; } else if (pos2D.x > mapObject.transform.position.x - (chunkTileCountX * TILES.Offset.x)) { pos = UTIL.EPosition.ERight; } } return(pos); }
void LookAtTarget() { Quaternion look = StaticMaths.GetLookRotation(target.transform.position, transform.position, transform.forward, out bool rotate, 1); if (rotate) { transform.rotation = Quaternion.Slerp(transform.rotation, look, Time.deltaTime * aISettings.rotSpeed); } }
public TerrainChunkData GetData() { TerrainChunkData d = new TerrainChunkData(); d.height = terrainData.GetHeight(); d.position = StaticMaths.ThreeDTo2D(center, StaticMaths.EPlane.E_XZ); d.smoothness = terrainData.GetSmoothness(); return(d); }
void RotateToTarget() { Transform player = playerAnim.transform.parent; Vector3 target = _lastEndPos; target.y = player.position.y; Quaternion rot = StaticMaths.GetLookRotation(target, player.position, player.forward, out bool shouldRotate, 1); if (shouldRotate) { player.rotation = Quaternion.Slerp(player.rotation, rot, Time.deltaTime * playerTurnSpeed); } }
public TerrainData(int _frequency, float _baseSmoothness, Color _baseColor, float _baseHeight) { frequency = _frequency; smoothness = _baseSmoothness + StaticMaths.GetRandomFloat(-TERRAIN.smoothnessVariance, TERRAIN.smoothnessVariance); color = new Color( _baseColor.r + StaticMaths.GetRandomFloat(-TERRAIN.colorVariance, TERRAIN.colorVariance), _baseColor.g + StaticMaths.GetRandomFloat(-TERRAIN.colorVariance, TERRAIN.colorVariance), _baseColor.b + StaticMaths.GetRandomFloat(-TERRAIN.colorVariance, TERRAIN.colorVariance) ); height = _baseHeight + StaticMaths.GetRandomFloat(-TERRAIN.heightVariance, TERRAIN.heightVariance); }
private Vector3 GetHeightAt(Vector2 _pos, float[] _heights, float[] smoothnesses, int _x, int _z) { float y = StaticMaths.Cap( Mathf.PerlinNoise(_pos.x * granularity + seedOffset.x, _pos.y * granularity + seedOffset.y) * 10f / smoothnesses[_z * tileCountX + _x] + _heights[_z * tileCountX + _x], -tileCountY, tileCountY); float heightStep = mapGenerator.GetDiscreteHeightStep(); if (heightStep != -1) { y = StaticMaths.Discretize(y, heightStep); } return(new Vector3(_pos.x, y, _pos.y)); }
private Vector3[,] GenerateComplexHeightMap() { Vector3 centerTemp = StaticMaths.DivideVector3D(center, TILES.Offset); Vector3[,] heightMap = new Vector3[tileCountX, tileCountZ]; Vector2[] tilePositions = GetAllTilePositions(centerTemp); TerrainChunk.TerrainChunkData[] chunkData = GetAllChunkData(); float[] heights = CalculateAllHeights(tilePositions, chunkData); float[] smoothnesses = CalculateAllSmoothnesses(tilePositions, chunkData); for (int x = 0; x < tileCountX; x++) { for (int z = 0; z < tileCountZ; z++) { heightMap[x, z] = GetHeightAt(tilePositions[z * tileCountX + x], heights, smoothnesses, x, z); } } return(heightMap); }
public override void OnGui() { GUILayout.BeginArea(new Rect(20f, 20f, 500f, 350f), "Propulsion Block GUI", GUI.skin.window); float num = 150f; bool flag = false; bool flag2 = false; if (!this._focus.User.IsOnSubConstructable) { if (this._focus.OrientationWithRespectToConstruct == enumBlockOrientations.forwards || this._focus.OrientationWithRespectToConstruct == enumBlockOrientations.backwards) { this._focus.DriveMode = enumPropulsionDriveModes.main; } else { flag = GUI.Toggle(new Rect(40f, 40f, num, 30f), this._focus.DriveMode == enumPropulsionDriveModes.thruster, "Thruster"); flag2 = GUI.Toggle(new Rect(40f + num, 40f, num, 30f), this._focus.DriveMode == enumPropulsionDriveModes.thrusterreverse, "Thruster reverse"); } } bool flag3 = GUI.Toggle(new Rect(40f + num + num, 40f, num, 30f), this._focus.DriveMode == enumPropulsionDriveModes.main, "Main"); bool flag4 = false; bool flag5 = false; if (!this._focus.User.IsOnSubConstructable && (this._focus.OrientationWithRespectToConstruct == enumBlockOrientations.up || this._focus.OrientationWithRespectToConstruct == enumBlockOrientations.down)) { flag4 = GUI.Toggle(new Rect(40f + num * 0.5f, 70f, num, 30f), this._focus.DriveMode == enumPropulsionDriveModes.roll, "roll (LHS)"); flag5 = GUI.Toggle(new Rect(40f + num * 0.5f + num, 70f, num, 30f), this._focus.DriveMode == enumPropulsionDriveModes.rollreverse, "roll reverse (RHS)"); } if (flag && this._focus.DriveMode != enumPropulsionDriveModes.thruster) { this._focus.DriveMode = enumPropulsionDriveModes.thruster; } else if (flag2 && this._focus.DriveMode != enumPropulsionDriveModes.thrusterreverse) { this._focus.DriveMode = enumPropulsionDriveModes.thrusterreverse; } else if (flag3 && this._focus.DriveMode != enumPropulsionDriveModes.main) { this._focus.DriveMode = enumPropulsionDriveModes.main; } else if (flag4 && this._focus.DriveMode != enumPropulsionDriveModes.roll) { this._focus.DriveMode = enumPropulsionDriveModes.roll; } else if (flag5 && this._focus.DriveMode != enumPropulsionDriveModes.rollreverse) { this._focus.DriveMode = enumPropulsionDriveModes.rollreverse; } string text = null; enumPropulsionDriveModes driveMode = this._focus.DriveMode; if (driveMode == enumPropulsionDriveModes.thruster) { text = this.ThrusterDescription(); } else if (driveMode == enumPropulsionDriveModes.thrusterreverse) { text = this.ThrusterReverseDescription(); } else if (driveMode == enumPropulsionDriveModes.roll) { text = this.RollDescription(); } else if (driveMode == enumPropulsionDriveModes.rollreverse) { text = this.RollReverseDescription(); } else if (driveMode == enumPropulsionDriveModes.main) { text = "Runs with the main forwards facing propulsion systems"; } string text2 = string.Concat(new object[] { StaticMaths.R2(this._focus.DirectForceFraction * 100f), " % applied directly behind the centre of mass.\n", StaticMaths.R2((1f - this._focus.DirectForceFraction) * 100f), "% applied from the block's position" }); string text3 = StaticMaths.R2(this._focus.PlacementForceFraction * 100f) + "% of maximum force attainable due to placement of this block"; GUI.Label(new Rect(40f, 100f, 400f, 100f), text); GUI.Label(new Rect(40f, 180f, 400f, 100f), text2); GUI.Label(new Rect(40f, 280f, 400f, 100f), text3); GUISliders.TotalWidthOfWindow = 500; GUISliders.TextWidth = 180; GUISliders.DecimalPlaces = 1; GUISliders.UpperMargin = 320; this._focus.PowerScale = GUISliders.DisplaySlider(0, "Drive fraction:", this._focus.PowerScale, 0f, 1f, enumMinMax.none, new ToolTip("Adjust the thrust (and power usage) of this engine. Useful for fine balancing of aircraft", 12, false)); if (GUI.Button(new Rect(40f, 470f, 100f, 60f), "Copy to clipboard")) { PropulsionModuleClipboard.CopyPropulsionToClipboard(this._focus); } if (PropulsionModuleClipboard.default_propulsion_set) { if (GUI.Button(new Rect(160f, 470f, 100f, 60f), "Paste from clipboard")) { PropulsionModuleClipboard.PastePropulsionFromClipboard(this._focus); } } else { GUI.Button(new Rect(160f, 470f, 100f, 60f), "Paste from clipboard", "buttongrey"); } if (GUI.Button(new Rect(380f, 470f, 100f, 60f), "Exit")) { this.DeactivateGui(GuiDeactivateType.Standard); } GUILayout.EndArea(); /* * //WheelSettingsGUI.WheelSettingsGui( ); * * * //GUILayout.BeginArea(new Rect(20f, 20f, 500f, 450f), "Propulsion Block GUI", GUI.skin.window); * GUILayout.BeginArea(new Rect(20f, 500f, 500f, 300f), "Whhel Settings GUI: " + this._focus.User.name, GUI.skin.window); * //GUILayout.BeginArea(new Rect(10f, 40f, 600, 300f), "Color", GUI.skin.window) ; * * GUISliders.TotalWidthOfWindow = 500; * GUISliders.TextWidth = 100; * GUISliders.UpperMargin = 40; * GUISliders.DecimalPlaces = 2; * //float OtherVal = 0.1f ; * //this.SetBlue (GUISliders.DisplaySlider (2, "Blue: ", this._blue, 0f, 1f, enumMinMax.none, null), true); * //this.imaginary (GUISliders.DisplaySlider (2, "Blue: ", this.imaginary, 0f, 1f, enumMinMax.none, null), true); * * int GUISIndex = 0; * * float SuspensionDistance = this._focus.User.GetParameters1().x ; * //this.anc = this._focus. * * this.anc.MaxThrustMultipler = GUISliders.DisplaySlider (GUISIndex, "MaxThrustMultipler: ", this.anc.MaxThrustMultipler, 0f, 100f, enumMinMax.none, null) ; * GUISIndex++; * this.anc.Spring = GUISliders.DisplaySlider (GUISIndex, "Spring: ", this.anc.Spring, 0f, 100f, enumMinMax.none, null) ; * GUISIndex++; * SuspensionDistance = GUISliders.DisplaySlider (GUISIndex, "Suspension Distance: ", SuspensionDistance, 0f, 100f, enumMinMax.none, null) ; * GUISIndex++; * * this._focus.User.SetParameters1(new Vector4 (SuspensionDistance, this._focus.User.GetParameters1().y, this._focus.User.GetParameters1().z, this._focus.User.GetParameters1().w)) ; * * * //bool result = false ; * * //this.ApplySuspentionParam () ; * * //if (GuiCommon.DisplayCloseButton(360)) * //{ * // result = true ; * //} * * * GUILayout.EndArea() ; * //return result ; */ /* * if (_focus.User.ExtraGUI()) * { * DeactivateGui() ; * return ; * } */ if (this._focus.OptionalControlModule != null && ControllableBlockGUIPanel.InputPanel(this._focus.OptionalControlModule, true)) { this.DeactivateGui(GuiDeactivateType.Standard); } }
public void CreateAndAttachChildNode(ENodePosition _ePosition) { Vector3 childPos = Vector3.zero; Quaternion childRot = Quaternion.Euler(Vector3.zero); ENodeType eChildType = ENodeType.ENormal; if (eType != ENodeType.EBase) { List <Node_CellEditor> armNodes = GetAllNodesOfArm(); //this node is also in there as the last node so we have to take the node at index lenth -2 Node_CellEditor parentNode = armNodes[armNodes.Count - 2]; if (parentNode != null) { Vector3 pos = transform.position; Vector3 parPos = parentNode.transform.position; Vector3 dir = (pos - parPos).normalized; childPos = dir * DISTANCE_AVERAGE; float rot = StaticMaths.FindLookAtAngle2D(pos, parPos); //maybe pos and childPos or parPos and childPos childRot = Quaternion.Euler(0f, rot, 0f); //childRot = gameObject.transform.rotation; if ((ePositionToParent == ENodePosition.ERight && _ePosition == ENodePosition.EAbove) || (ePositionToParent == ENodePosition.ELeft && _ePosition == ENodePosition.EBelow)) { childPos = new Vector3(-childPos.z, childPos.y, childPos.x); } else if ((ePositionToParent == ENodePosition.EAbove && _ePosition == ENodePosition.ELeft) || (ePositionToParent == ENodePosition.EBelow && _ePosition == ENodePosition.ERight)) { childPos = new Vector3(-childPos.z, childPos.y, childPos.x); } else if ((ePositionToParent == ENodePosition.ERight && _ePosition == ENodePosition.EBelow) || (ePositionToParent == ENodePosition.ELeft && _ePosition == ENodePosition.EAbove)) { childPos = new Vector3(childPos.z, childPos.y, -childPos.x); } else if ((ePositionToParent == ENodePosition.EAbove && _ePosition == ENodePosition.ERight) || (ePositionToParent == ENodePosition.EBelow && _ePosition == ENodePosition.ELeft)) { childPos = new Vector3(childPos.z, childPos.y, -childPos.x); } } else { Debug.Log("FATAL ERROR : non-base node doesn't have parent node. "); } } else { childPos = transform.position; eChildType = ENodeType.ESingle; switch (_ePosition) { case ENodePosition.EAbove: childPos.z += DISTANCE_AVERAGE; break; case ENodePosition.EBelow: childPos.z -= DISTANCE_AVERAGE; break; case ENodePosition.ERight: childPos.x += DISTANCE_AVERAGE; break; case ENodePosition.ELeft: childPos.x -= DISTANCE_AVERAGE; break; } } childPos += transform.position; //These ifs make sure that you can't create a child node on the socket where a parent node is attached if (_ePosition == ENodePosition.EAbove && ePositionToParent != ENodePosition.EBelow) { GameObject chA = Instantiate(NODE_TEMPLATE, childPos, childRot); chA.transform.parent = transform; childAbove = chA.GetComponent <Node_CellEditor>(); childAbove.PostConstructor(eChildType, _ePosition, this); if (arrowUp != null) { Destroy(arrowUp.gameObject); arrowUp = null; } } else if (_ePosition == ENodePosition.ERight && ePositionToParent != ENodePosition.ELeft) { GameObject chR = Instantiate(NODE_TEMPLATE, childPos, childRot); chR.transform.parent = transform; childRight = chR.GetComponent <Node_CellEditor>(); childRight.PostConstructor(eChildType, _ePosition, this); if (arrowRight != null) { Destroy(arrowRight.gameObject); arrowRight = null; } } else if (_ePosition == ENodePosition.EBelow && ePositionToParent != ENodePosition.EAbove) { GameObject chB = Instantiate(NODE_TEMPLATE, childPos, childRot); chB.transform.parent = transform; childBelow = chB.GetComponent <Node_CellEditor>(); childBelow.PostConstructor(eChildType, _ePosition, this); if (arrowDown != null) { Destroy(arrowDown.gameObject); arrowDown = null; } } else if (_ePosition == ENodePosition.ELeft && ePositionToParent != ENodePosition.ERight) { GameObject chL = Instantiate(NODE_TEMPLATE, childPos, childRot); chL.transform.parent = transform; childLeft = chL.GetComponent <Node_CellEditor>(); childLeft.PostConstructor(eChildType, _ePosition, this); if (arrowLeft != null) { Destroy(arrowLeft.gameObject); arrowLeft = null; } } if (eType != ENodeType.EBase) { parentNode.UpdateNodeType(); } else { UpdateNodeType(); } }
public void GenerateMesh(float[] _charges) { if (cs_MarchingCubes == null) { cs_MarchingCubes = Resources.Load <ComputeShader>("Shaders/cs_MarchingCubes"); } int numThreadsPerX = Mathf.CeilToInt(resolution.x / (float)threadGroupSize); int numThreadsPerY = Mathf.CeilToInt(resolution.y / (float)threadGroupSize); int numThreadsPerZ = Mathf.CeilToInt(resolution.z / (float)threadGroupSize); float isoLevel = Meta_CellEditor.SCULPTING.MARCHING_CUBES.ISOLEVEL; int kernel = cs_MarchingCubes.FindKernel("CSMain"); triangleBuffer.SetCounterValue(0); pointsBuffer.SetData(_charges); cs_MarchingCubes.SetBuffer(kernel, "points", pointsBuffer); cs_MarchingCubes.SetBuffer(kernel, "triangles", triangleBuffer); cs_MarchingCubes.SetInt("numPointsPerX", (int)resolution.x); cs_MarchingCubes.SetInt("numPointsPerY", (int)resolution.y); cs_MarchingCubes.SetInt("numPointsPerZ", (int)resolution.z); cs_MarchingCubes.SetFloat("scale", Meta_CellEditor.SCULPTING.GRID.SCALE); cs_MarchingCubes.SetVector("center", transform.position); cs_MarchingCubes.SetFloat("isoLevel", isoLevel); cs_MarchingCubes.Dispatch(kernel, numThreadsPerX, numThreadsPerY, numThreadsPerZ); // Get number of triangles in the triangle buffer ComputeBuffer.CopyCount(triangleBuffer, triCountBuffer, 0); int[] triCountArray = { 0 }; triCountBuffer.GetData(triCountArray); int numTris = triCountArray[0]; // Get triangle data from shader Triangle[] tris = new Triangle[numTris]; triangleBuffer.GetData(tris, 0, 0, numTris); mesh.Clear(); var vertices = new Vector3[numTris * 3]; var meshTriangles = new int[numTris * 3]; if (editor) { for (int i = 0; i < numTris; i++) { for (int j = 0; j < 3; j++) { meshTriangles[i * 3 + j] = i * 3 + j; vertices[i * 3 + j] = tris[i][j]; } } } else { for (int i = 0; i < numTris; i++) { for (int j = 2; j >= 0; j--) { meshTriangles[i * 3 + j] = i * 3 + j; vertices[i * 3 + j] = tris[i][2 - j]; } } } //generating uv coordiantes Vector2[] uv = new Vector2[vertices.Length]; for (int i = 0; i < vertices.Length; i++) { uv[i] = StaticMaths.ThreeDTo2D(vertices[i], StaticMaths.EPlane.E_XZ); } mesh.vertices = vertices; mesh.triangles = meshTriangles; mesh.RecalculateNormals(); mesh.uv = uv; }
public Vector3 GetHeightAt(float _x, float _z, float _smoothness) { float y = StaticMaths.Cap(Mathf.PerlinNoise(_x * granularity, _z * granularity) * 10f / _smoothness, -heightCap, heightCap); return(new Vector3(_x * spacingX, y, _z * spacingZ)); }