void Start() { routes = new Vector3[100,100]; //if(TileSettings.canUseSave) Instantiate(Carro, routes[0,0],Carro.transform.rotation); }
public PreviewRenderer(BezierCurveCollection sideCurves, BezierCurveCollection topCurves, BezierCurveCollection backCurves) : base(new Rectangle( ScreenData.GetScreenValueX(0.5f), ScreenData.GetScreenValueY(0.5f), ScreenData.GetScreenValueX(0.5f), ScreenData.GetScreenValueY(0.5f) )) { _renderTarget = new RenderPanel( ScreenData.GetScreenValueX(0.5f), ScreenData.GetScreenValueY(0.5f), ScreenData.GetScreenValueX(0.5f), ScreenData.GetScreenValueY(0.5f) ); RenderPanel.BindRenderTarget(_renderTarget); _indicies = MeshHelper.CreateIndiceArray((_meshVertexWidth) * (_meshVertexWidth)); _verticies = MeshHelper.CreateTexcoordedVertexList((_meshVertexWidth) * (_meshVertexWidth)); _geometryBuffer = new ShipGeometryBuffer(_indicies.Count(), _verticies.Count(), (_meshVertexWidth) * (_meshVertexWidth) * 2, "HullEditorHullTex"); _geometryBuffer.DiffuseDirection = new Vector3(0, -1, 1); _mesh = new Vector3[_meshVertexWidth, _meshVertexWidth]; _sideCurves = sideCurves; _topCurves = topCurves; _backCurves = backCurves; _geometryBuffer.Indexbuffer.SetData(_indicies); }
public ErosionManager(TerrainGenerator terrain) { this.terrain = terrain; vertices = terrain.vertices; terrainSize = terrain.terrainSize; terrain.erosionManager = this; }
void Awake() { //Get size of sprite Renderer rend = (Renderer)Tile.GetComponent(typeof(Renderer)); tileSize = rend.bounds.size.x; //Debug.Log("TileSize: " + tileSize); //Create Arrays coordinates = new Vector3[4, 4]; tileGrid = new GameObject[4, 4]; //Initialize Arrays initArrays(); //Update edges BotLeft = coordinates[0, 0]; BotLeft.x -= (float)tileSize / 2; BotLeft.y -= (float)tileSize / 2; TopRight = coordinates[3, 3]; TopRight.x += (float)tileSize / 2; TopRight.y += (float)tileSize / 2; //The distance between two tile tileDistance = tileSize + margin; //Debug.Log("tileDistance: " + tileDistance); }
// Use this for initialization void Start () { kinect = devOrEmu.getKinect(); players = new Kinect.NuiSkeletonTrackingState[Kinect.Constants.NuiSkeletonCount]; trackedPlayers = new int[Kinect.Constants.NuiSkeletonMaxTracked]; trackedPlayers[0] = -1; trackedPlayers[1] = -1; bonePos = new Vector3[2,(int)Kinect.NuiSkeletonPositionIndex.Count]; rawBonePos = new Vector3[2,(int)Kinect.NuiSkeletonPositionIndex.Count]; boneVel = new Vector3[2,(int)Kinect.NuiSkeletonPositionIndex.Count]; boneState = new Kinect.NuiSkeletonPositionTrackingState[2,(int)Kinect.NuiSkeletonPositionIndex.Count]; boneLocalOrientation = new Quaternion[2, (int)Kinect.NuiSkeletonPositionIndex.Count]; boneAbsoluteOrientation = new Quaternion[2, (int)Kinect.NuiSkeletonPositionIndex.Count]; //create the transform matrix that converts from kinect-space to world-space Matrix4x4 trans = new Matrix4x4(); trans.SetTRS( new Vector3(-kinect.getKinectCenter().x, kinect.getSensorHeight()-kinect.getKinectCenter().y, -kinect.getKinectCenter().z), Quaternion.identity, Vector3.one ); Matrix4x4 rot = new Matrix4x4(); Quaternion quat = new Quaternion(); double theta = Mathf.Atan((kinect.getLookAt().y+kinect.getKinectCenter().y-kinect.getSensorHeight()) / (kinect.getLookAt().z + kinect.getKinectCenter().z)); float kinectAngle = (float)(theta * (180 / Mathf.PI)); quat.eulerAngles = new Vector3(-kinectAngle, 0, 0); rot.SetTRS( Vector3.zero, quat, Vector3.one); //final transform matrix offsets the rotation of the kinect, then translates to a new center kinectToWorld = flipMatrix*trans*rot; }
public OutputData(int width, int height) { this.width = width; this.height = height; data = new Vector3[width, height]; }
void Start() { for (var x = 0; x < (Size - 1); ++x) { for (var y = 0; y < (Size - 1); ++y) { var grid = new Grid() { Base = this, X = x, Y = y }; grid.Init(); _grids.Add(grid); } } _vertices = new Vector3[Size, Size]; for (var x = 0; x < Size; ++x) { for (var y = 0; y < Size; ++y) { _vertices[x, y] = new Vector3(0, 0); } } }
public void GenerateMap() { float x, y; gridPossitions = new Vector3[baseMap.GetLength(0), baseMap.GetLength(1)]; placedWalls = new GameObject[baseMap.GetLength(0), baseMap.GetLength(1)]; for (int i = 0; i < baseMap.GetLength(0); i++){ //new x coordinate with scale taken into account //y = i * scaleFactor + scaleFactor / 2 + mapPossition.y; y = mapPossition.y + i; for (int j = 0; j < baseMap.GetLength(1); j++){ //new y coordinate with scale taken into account //x = j * scaleFactor + scaleFactor / 2 + mapPossition.x; x = mapPossition.x + j; //saves the current coordinate in an accessable list for the purpose of spawning stuff later gridPossitions[i, j] = new Vector3(x, y, 0); //Adds a wall, according to values from the baseMap if (baseMap[i, j] == 1) { placedWalls[i, j] = (GameObject)Instantiate(wall, new Vector3(x, -y, 0), Quaternion.identity); } else { placedWalls[i, j] = null; } } } }
// Use this for initialization void Start() { Debug.Log ("I am alive!"); samples = new Vector3[h_division,v_division]; flag = false; cur = Time.time; text3d = new GameObject(); }
void OnEnable() { levelSelector = target as LevelSelector; handleTransform = levelSelector.transform; handleRotation = Quaternion.identity; tangents = new Vector3[levelSelector.availableLevels.Length,2]; }
// Use this for initialization void Start() { bonePos = new Vector3[2,(int)Kinect.NuiSkeletonPositionIndex.Count]; menu [0] = GameObject.Find ("GUI Text Recommencer"); menu [1] = GameObject.Find ("GUI Text Quitter"); listeGui = GameObject.FindGameObjectsWithTag ("GuiMenu"); guiChargement = GameObject.Find ("Affichage chargement"); guiChargement.guiText.text = ""; }
void Start() { // inicializacion del array multiDimensionalArray2 = new Vector3[(int)(fTamañoGrilla*fTamañoGrilla), (int)(fTamañoGrilla*fTamañoGrilla)]; fProporcionEnX =(fAnchoDeUnCuadro/200); fPDistanciaEntreRectas = fAltoDeUnCuadro/100; LLenarMatriz (); }
public NormalMap(HeightMapContent heightMap) { _heightMap = heightMap; m_nWidth = heightMap.Width; m_nHeight = heightMap.Height; m_pNormals = new Vector3[m_nWidth, m_nHeight]; for (int x = 0; x < m_nWidth; ++x) for (int y = 0; y < m_nHeight; ++y) m_pNormals[x, y] = CalculateNormal(x, y); }
private void generateVerts() { m_verts = new Vector3[m_width, m_height]; for (int x = 0; x < m_width; x++) { for (int y = 0; y < m_height; y++) { System.Drawing.Color pixelColor = m_bitmap.GetPixel(x, y); float height = (float)(pixelColor.R + pixelColor.G + pixelColor.B) / (3 * 255); m_verts[x, y] = new Vector3(x-m_width/2, height, y-m_height/2); } } }
void Awake() { //creates the array to reference tiles tiles = new GameObject[boardWidth, boardHeight]; tileLocations = new Vector3[boardWidth,boardHeight]; tileColors = new Color [boardWidth, boardHeight]; GameObject border; //creates the board and stores each tile within the array for (int x = 0; x<boardWidth; x++) { border = (GameObject) Instantiate(vertBorder, new Vector3 (x * 3 + 1.5F, 10.5F, -1), Quaternion.identity); border.transform.parent = borderParent.transform; border = (GameObject) Instantiate(horBorder, new Vector3 (10.5F, x*3 + 1.5F, -1), Quaternion.identity); border.transform.parent = borderParent.transform; for (int y = 0; y < boardHeight; y++) { tiles [x,y] = (GameObject) Instantiate(tileCube, new Vector3 (x *3, y * 3, 0), Quaternion.identity); tiles [x,y].transform.parent = tileParent.transform; (tiles [x,y].GetComponent("Halo") as Behaviour).enabled = false; tileLocations [x,y] = tiles[x,y].transform.position; pieceLocation = tiles[x,y].GetComponent<positionScript>(); pieceLocation.xPos = x; pieceLocation.yPos = y; tileColors [x,y] = Color.white; tiles[x,y].tag = "No Piece"; } } border = (GameObject) Instantiate(vertBorder, new Vector3 (-1.5F, 10.5F, -1), Quaternion.identity); border.transform.parent = borderParent.transform; border = (GameObject) Instantiate(horBorder, new Vector3 (10.5F, -1.5F, -1), Quaternion.identity); border.transform.parent = borderParent.transform; //turns the even squares black for (int x = 1; x<boardWidth; x+=2) { for (int y = 1; y < boardHeight; y+=2) { tiles [x,y].transform.renderer.material.color = Color.black; tileColors [x,y] = Color.black; } } //turns the odd squares black for (int x = 0; x<boardWidth; x+=2) { for (int y = 0; y < boardHeight; y+=2) { tiles [x,y].transform.renderer.material.color = Color.black; tileColors [x,y] = Color.black; } } }
public Grid(int rawsCount, int columnsCount, float cellXSize, float cellZSize, Vector3 gridCenter) { if (_instance != null) return; _instance = this; RawsCount = rawsCount; ColumnsCount = columnsCount; CellXSize = cellXSize; CellZSize = cellZSize; GridCenter = gridCenter; Nodes = new Vector3[RawsCount, ColumnsCount]; CreateGrid(rawsCount, columnsCount, cellXSize, cellZSize, gridCenter); }
public void StartPlane(int[] at, Vector3[,] allOtherCords, int[] depotAt, int[] start) { GetComponent<Renderer> ().material.color = Color.red; depot = depotAt; allCords = allOtherCords; cordsStart = start;// if I set it to = at, it changes, this seemed like an easy fix newCords = at; cargo = 0; cords = at; Vector3 newCordsVect = allCords [newCords [0], newCords [1]]; newCordsVect.z = -1f; // so it's above the grid transform.position = newCordsVect; }
public static Mesh GenerateGridMesh(Mesh mesh, Vector3 transformPosition, Vector3[,] points) { if (points == null) { throw new UnityException("No Points! Points not initialized?"); } mesh.Clear(); List <Vector3> vertices = new List <Vector3>(); List <Vector2> uvs = new List <Vector2>(); List <int> triangles = new List <int>(); int width = points.GetLength(0); int height = points.GetLength(1); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { Vector3 point = points[x, y]; vertices.Add(point - transformPosition); uvs.Add(new Vector2(point.x, point.z)); } } for (int x = 0; x < width - 1; x++) { for (int y = 0; y < height - 1; y++) { triangles.Add(x * height + y); triangles.Add(x * height + y + 1); triangles.Add((x + 1) * height + y); triangles.Add((x + 1) * height + y); triangles.Add(x * height + y + 1); triangles.Add((x + 1) * height + y + 1); } } mesh.vertices = vertices.ToArray(); mesh.triangles = triangles.ToArray(); mesh.uv = uvs.ToArray(); mesh.RecalculateNormals(); mesh.RecalculateBounds(); ; return(mesh); }
void Start() { //input validation for number of herds if (numHerds < 1) { numHerds = 1; } else if (numHerds > 9) //limiting the maximum number of herds to 9 makes it easier to handle input for the camera { numHerds = 9; } //initializing everything terrainWidth = (int)terrain.terrainData.size.z; terrainLength = (int)terrain.terrainData.size.x; BOUNDS_CENTER = new Vector3(terrainLength / 2, 0, terrainWidth / 2); BOUNDS_ZRAD = 200.0f; BOUNDS_XRAD = 100.0f; obstacles = new List <GameObject>(); deerStart = new List <GameObject>(); flowField = new Vector3[terrainLength, terrainWidth]; createFlowField(); determineStartingLocations(); wolves = new Flock(Random.Range(minWolves, maxWolves + 1), wolfStart, wolfPrefab, numHerders); herds = new List <Flock>(); int index; List <int> usedIndices = new List <int>(); for (int i = 0; i < numHerds; i++) { //make the herds do { index = Random.Range(0, deerStart.Count); }while(usedIndices.Contains(index)); Vector3[] seekpoints; List <Vector3> seekList = new List <Vector3>(); foreach (Transform t in deerStart[index].transform) { seekList.Add(t.position); } seekpoints = seekList.ToArray(); herds.Add(new Flock(Random.Range(minDeer, maxDeer + 1), deerStart[index].transform.position, deerPrefab, seekpoints)); usedIndices.Add(index); } //set camera to follow the game manager myCamera.enabled = true; myCamera.transform.position = new Vector3(wolfStart.x, 50, wolfStart.z); }
int resolution; //网络的分辨率,与屏幕宽高有关 // Use this for initialization void Start() { velocity2.Set(0, 0, 0); acceleration2.Set(0, 0, 0); location2 = transform.localPosition; //流场屏幕设置 resolution = 100; cols = Screen.width / resolution; rows = Screen.height / resolution; //流场数据结构 field = new Vector3[cols, rows]; init(); }
public Chunk(int blocksCount, int blockSize, Vector2i position) { BlockSize = blockSize; BlocksCount = blocksCount; Position = position; GridSize = BlocksCount + 1; HeightMap = new float[GridSize, GridSize]; Influence = new ZoneRatio[GridSize, GridSize]; BlockType = new BlockType[BlocksCount, BlocksCount]; NormalMap = new Vector3[BlocksCount, BlocksCount]; //Debug Test(); }
public static Vector3[] ToArray(this Vector3[,] matrix) { var array = new Vector3[matrix.GetLength(0) * matrix.GetLength(1)]; for (int i = 0; i < matrix.GetLength(0); i++) { for (int j = 0; j < matrix.GetLength(1); j++) { array[i * matrix.GetLength(0) + j] = matrix[i, j]; } } return(array); }
void CreateGrid() { //initialize grid cells = new Vector3[numOfColumns, numOfRows]; //populate grid for (int i = 0; i < numOfColumns; i++) { for (int j = 0; j < numOfRows; j++) { cells[i, j] = new Vector3(i * spaceBetweenCells, j * spaceBetweenCells, zDepth); } //end for numOfRows } //end for numOfColumns } //end Create Grid
private static Stopwatch NotInline(Vector3[] pointCloud, Vector3[,] result2) { var sw2 = Stopwatch.StartNew(); for (int x = 0; x < textureSize; x++) { for (int y = 0; y < textureSize; y++) { Computation(pointCloud, result2, x, y); } } sw2.Stop(); return(sw2); }
private void CreateVerticesFromVectors(Vector3[,] lla, Vector3 refr, Vector3 refe) { for (int x = 0; x <= LatRows; x++) { for (int z = 0; z <= LongColumns; z++) { int ix = z * (LatRows + 1) + x; Vector3 e = EarthConverter.LatLongAltToECEF(lla[x, z]); Vector3 d = e - refe; Vector3 loc = EarthConverter.RotateECEF(d, refr.X, refr.Y); Vertices[ix] = loc; } } }
public Chunk(int blocksCount, int blockSize, Vector2i position) { BlockSize = blockSize; BlocksCount = blocksCount; Position = position; GridSize = BlocksCount + 1; HeightMap = new float[GridSize, GridSize]; Influence = new ZoneRatio[GridSize, GridSize]; BlockType = new BlockType[BlocksCount, BlocksCount]; NormalMap = new Vector3[BlocksCount, BlocksCount]; //Debug Test(); }
// Use this for initialization void Start() { BFSCredentials = GameObject.FindObjectOfType <BFSMesh> (); //Get the matrix created by bfs if (BFSCredentials.isGenerated) { map = BFSCredentials.matrix; } else { throw new UnityException("Failed to generate mesh"); } }
// Use this for initialization void Start() { Debug.Log("Der Wandgenerator wurde gestartet"); int maximaleRaumzahl = raumGenerator.maximaleRaumzahlPublic; Vector3[,] wandpositionenArrayWandgenerator = raumGenerator.wandpositionenArray; Vector3 endraumPosition = quizGeneratorSkript.positionEndraum; int ausrichtungDesEndraums = quizGeneratorSkript.ausrichtungDesEndraums; int zahlDesAmWeitestenEntferntenRaums = quizGeneratorSkript.zahlDesAmWeitestenEntferntenRaums; int anzahlWaende = WaendeGenerieren(maximaleRaumzahl, wandpositionenArrayWandgenerator, endraumPosition, ausrichtungDesEndraums, zahlDesAmWeitestenEntferntenRaums); //Debug.Log("Anzahl platzierter Waende: " + anzahlWaende); }
void Awake() { // Create a layer mask for the floor layer. floorMask = LayerMask.GetMask("Floor"); // Set up references. anim = GetComponent <Animator> (); playerRigidbody = GetComponent <Rigidbody> (); nav = GetComponent <NavMeshAgent>(); nav.updateRotation = false; PlacesCost = new float[5, 5]; PosCost = new Vector3[5, 5]; clearCosts(); StartCoroutine(startMovement()); }
// Use this for initialization void Awake() { riverPathNoiseSeed = 3; riverPathNoise = new PerlinNoise(riverPathNoiseSeed); RiverStartPointsPerPolygon = 4; HexagonRadius = 20000; HexagonApothem = HexagonRadius * (Mathf.Cos(30 * Mathf.Deg2Rad)); tribLength = 2000; //Maximum distance between tributary endPoints maximumTributaries = Mathf.RoundToInt((HexagonRadius * 2) / tribLength); offsets = new float[,] { {0, 2}, //North {1.5f, 1}, //north East {1.5f, -1}, //South East {0, -2}, //South {-1.5f, -1}, //South West {-1.5f, 1}, //North West }; hexagonCentres = new Vector3[7]; adjacentHexagonCentres = new Vector3[3]; platePoints = new int[3, 2]; riverMouths = new Vector3[3, 4]; hexagonVertices = new Vector3[3, 6]; riverStartPoints = new Vector3[3, RiverStartPointsPerPolygon]; riverMidpoints = new Vector3[3, 4]; activeRiverMidpoints = new bool[3, 4]; riverStartToMid = new int[3, 4]; closestContinentCentres = new Vector3[3]; hexagonClassifications = new int[3,5]; tribEndStartMid = new Vector3[RiverStartPointsPerPolygon][,]; for (int i = 0; i < RiverStartPointsPerPolygon; i++) { tribEndStartMid[i] = new Vector3[maximumTributaries,2]; } /* Classifications: One for each adjacent Hexagon 0 - Landmass (central(0) or outer(1)), ocean(2), large island(3), small islands(4) 1 - No mountains (0), Central Mountains(1), Mountain Range (2) 2 - Desert(0), Tropical (1), Temperate (2) etc (add later) */ tectonicNoise = new PerlinNoise(plateRatioSeed); getPlayerPosition(); calculateHexagons(); }
private static bool CheckResults(Vector3[,] lhs, Vector3[,] rhs) { for (int x = 0; x < textureSize; x++) { for (int y = 0; y < textureSize; y++) { if (!lhs[x, y].Equals(rhs[x, y])) { return(false); } } } return(true); }
/// <summary> /// Construye los vértices a partir del mapa de alturas especificado /// </summary> /// <param name="cellSize">Tamaño de la celda</param> /// <param name="pLevel1">Proporción de textura del nivel 1</param> /// <param name="pLevel1">Proporción de textura del nivel 2</param> /// <param name="pLevel1">Proporción de textura del nivel 3</param> /// <returns>Devuelve la colección de vértices</returns> public VertexMultitextured[] BuildVertices(float cellSize, float pLevel1, float pLevel2, float pLevel3) { // Contador de vértices int vertexCountX = this.Width; int vertexCountZ = this.Deep; int vertexCount = vertexCountX * vertexCountZ; float level0 = this.Min; float level1 = this.Max * pLevel1; float level2 = this.Max * pLevel2; float level3 = this.Max * pLevel3; float level4 = this.Max; // Crear los vértices List <VertexMultitextured> vertList = new List <VertexMultitextured>(vertexCount); Vector3[,] normals = this.CreateNormals(cellSize); for (int width = 0; width < vertexCountX; width++) { for (int deep = 0; deep < vertexCountZ; deep++) { VertexMultitextured newVertex = new VertexMultitextured(); float posX = width * cellSize; float posY = this.m_Data[deep, width]; float posZ = deep * cellSize; newVertex.Position = new Vector3(posX, posY, posZ); newVertex.Normal = normals[deep, width]; newVertex.TextureCoordinate.X = (float)width / 10.0f; newVertex.TextureCoordinate.Y = (float)deep / 10.0f; float twX = (posY < level1) ? (posY / level1) : 0.0f; float twY = (posY < level2) ? (posY / level2) : 0.0f; float twZ = (posY < level3) ? (posY / level3) : 0.0f; float twW = (posY < level4) ? (posY / level4) : 0.0f; float totalWeight = twX + twY + twZ + twW; newVertex.TexWeights.X = twX / totalWeight; newVertex.TexWeights.Y = twY / totalWeight; newVertex.TexWeights.Z = twZ / totalWeight; newVertex.TexWeights.W = twW / totalWeight; vertList.Add(newVertex); } } return(vertList.ToArray()); }
void Start() { positions = new Vector3[height, width]; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { GameObject go = Instantiate(Tile, this.transform); Vector3 pos = new Vector3(i, -j, 0); go.transform.Translate(pos - offset); positions[i, j] = pos - offset; } } }
private static Stopwatch Parallelized(Vector3[] pointCloud, Vector3[,] result3) { var sw3 = Stopwatch.StartNew(); Parallel.For(0, textureSize, x => { for (int y = 0; y < textureSize; y++) { Computation(pointCloud, result3, x, y); } }); sw3.Stop(); return(sw3); }
protected void InsertBlankMap(Vector3[,] tile, Vector2 southWestLatLong) { short alt = 0; for (int h = 0; h < TileHeight; h++) { for (int w = 0; w < TileWidth; w++) { Vector2 latLong = CreateLatLongFromTileOffsets(southWestLatLong, h, w); tile[h, w] = new Vector3(latLong.X, latLong.Y, alt); } } }
public override void Calculate() { base.Calculate(); if (!verified) { return; } CTextureNode m1 = (CTextureNode)getNode(Inputs, 0); if (m1 == null) { verified = false; return; } m1.Calculate(); if (!changed) { return; } float curvtype = getValue("curvtype"); float scale = getValue("scale"); Color c1 = getColor("color1"); if (normals == null) { normals = new Vector3[C2DMap.sizeX, C2DMap.sizeY]; } if (normals.GetLength(0) != C2DMap.sizeX) { normals = new Vector3[C2DMap.sizeX, C2DMap.sizeY]; } m1.map.calculateNormals(100, normals); for (int i = 0; i < C2DMap.sizeX; i++) { for (int j = 0; j < C2DMap.sizeY; j++) { colors.colors [i, j] = c1 * Mathf.Pow(m1.map.getCurvature(i, j, scale, (int)curvtype, normals), 1); } } colors.Smooth(1); updateTexture = true; CNodeManager.Progress(); changed = false; }
/// <summary> /// Evaluate the surface at the given U and V parameters. /// </summary> /// <param name="u">U parameter.</param> /// <param name="v">V parameter.</param> /// <param name="direction">The evaluate direction required as result.</param> /// <returns>The unitized tangent vector in the direction selected.</returns> public Vector3 EvaluateAt(double u, double v, EvaluateSurfaceDirection direction) { if (direction != EvaluateSurfaceDirection.Normal) { return((direction == EvaluateSurfaceDirection.U) ? Evaluate.Surface.RationalDerivatives(this, u, v)[1, 0].Unitize() : Evaluate.Surface.RationalDerivatives(this, u, v)[0, 1].Unitize()); } Vector3[,] derivatives = Evaluate.Surface.RationalDerivatives(this, u, v); Vector3 normal = Vector3.CrossProduct(derivatives[1, 0], derivatives[0, 1]); return(normal.Unitize()); }
private void button3_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { Vector3[,] val = Procedurs.Medium(openFileDialog1.FileName); Morf morf = Morf.GenerateKMean(val, 5); morf.RemoveEmptyRegions(); for (int i = 0; i < morf.regions.Count; i++) { morf.regions[i].Fill(morf.regions[i].GetAverage(val), val); } var proc = new ImageProcessing(val.GetImage()); } }
public PInfo[,] RenderImage() { Stopwatch watch = new Stopwatch(); Vector3[,] rays = GetRays(); List <Task> tasks = new List <Task>(); watch.Start(); int boxCount = 0; for (int x = 0; x < ScreenWidth; x++) { int tx = x; tasks.Add(Task.Run(() => { try { for (int y = 0; y < ScreenHeight; y++) { int ty = y; RayHit hit = MarchRay(rays[tx, ty], MaxLength, Position); RayHit skyHit = MarchRay(new Vector3(0, 1, 0), LightHeight - hit.Position.Y, hit.Position + new Vector3(0, MarchPrecission * 2, 0)); if (hit.Object != null) { if (hit.Object.Type == Geometry.GType.Box) { boxCount++; } } ScreenBuffer[tx, ty] = new PInfo().SetBg(skyHit.Object == null ? hit.color : Shade(hit.color)); } } catch (Exception) { } })); } Task.WaitAll(tasks.ToArray()); watch.Stop(); Debug.WriteLine("Final Render Time: " + watch.ElapsedMilliseconds); Debug.WriteLine("Boxes: " + boxCount); return(ScreenBuffer); }
void CreateGrid() { //initialize grid cells = new Vector3[numOfColumns, numOfRows]; //populate grid for(int i = 0; i < numOfColumns; i++){ for(int j = 0; j < numOfRows; j ++){ cells[i,j] = new Vector3( i * spaceBetweenCells, j * spaceBetweenCells, zDepth); }//end for numOfRows }//end for numOfColumns }
public Game(IGameView view, bool useTouch = true) : base(view) { _useTouch = useTouch; _board = new int[BoardSize, BoardSize]; _boardMask = new bool[BoardSize, BoardSize]; _offsets = new Vector3[BoardSize, BoardSize]; _velocities = new float[BoardSize, BoardSize]; _rand = new Random(); _numbers = new Dictionary <char, Sprite>(); _score = 0; _scoreStr = _score.ToString(); _isNewGame = true; view.EnableGesture(GestureType.Tap); }
void PrepareFlowField() { directions = new Vector3[xSize, ySize]; Weights = new int[xSize, ySize]; for (int i = 0; i < Weights.GetLength(0); i++) { for (int j = 0; j < Weights.GetLength(1); j++) { Weights[i, j] = 1000000000; } } }
public void Init() { pointsHandler = new PointFieldHandler(); this.field = ComputeFieldPoints(Singlton.settings.constants.dimensionOfLevel, Singlton.settings.graphic.placeOfAlgo.transform.renderer.bounds.min, Singlton.settings.graphic.offset, Singlton.settings.graphic.scale ); pointsHandler.Init(); pointsHandler.Bind(field,ref points); //ConnectTwoPoints(field[0,0],field[5,5],Singlton.settings.graphic.connectorPrefab); this.RedrawConnections(); }
/// <summary>Creates a 2D array of tiles from the positions provided.</summary> /// <param name="positions">A 2D array of positions in the world.</param> private void AssignPositionsToTiles(Vector3[,] positions) { int width = positions.GetLength(0); int height = positions.GetLength(1); tiles = new Tile[width, height]; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { tiles[x, y] = new Tile(positions[x, y]); } } }
private float tempTimer; //Used to time the saved as message void Start() { gameData = GetComponent <GameData>(); rows = gameData.Rows; cols = gameData.Cols; cameraSound = Audio.GetComponent <AudioSource>(); fullViewCamera = FullViewCamera.GetComponent <Camera>(); savedAsText = SavedAsUIText.GetComponent <Text>(); //Get the positions of each cube to control the player's movement cubePositions = new Vector3[rows, cols]; cubeProperties = new CubeProperties[rows, cols]; GetCubeProperties(); }
public void CreateScalp(Vector3[,] grid, int NI, int NJ) { Debug.Log("Creating Scalp"); surface = GameObject.Find("ScalpSurface"); GameObject head = GameObject.Find("Head"); surface.AddComponent<MeshFilter>(); surface.AddComponent<MeshCollider>(); mySurface = new BSplineSurface(); mySurface.setControlGrid(NI-1, NJ-1); mySurface.Init(); mySurface.InitRandomGrid(); mySurface.InitGrid(grid); mySurface.Calculate(); resultGrid = mySurface.outputGrid; controlGrid = mySurface.controlGrid; generateMesh(); updateMesh(); MeshRenderer renderer = surface.AddComponent<MeshRenderer>(); renderer.material = GameObject.Find("Tracker").GetComponent<MeshRenderer>().material; surface.transform.parent = GameObject.Find("Head").transform; GameObject underSurface = GameObject.Instantiate(surface); Destroy(underSurface.GetComponent<ScalpGenerator>()); underSurface.transform.position = surface.transform.position; underSurface.transform.rotation = surface.transform.rotation; underSurface.transform.parent = surface.transform.parent; MeshFilter filter = underSurface.GetComponent<MeshFilter>(); if (filter != null) { Mesh mesh = filter.mesh; Vector3[] normals = mesh.normals; for (int i = 0; i < normals.Length; i++) normals[i] = -normals[i]; mesh.normals = normals; for (int m = 0; m < mesh.subMeshCount; m++) { int[] triangles = mesh.GetTriangles(m); for (int i = 0; i < triangles.Length; i += 3) { int temp = triangles[i + 0]; triangles[i + 0] = triangles[i + 1]; triangles[i + 1] = temp; } mesh.SetTriangles(triangles, m); } } //drawn = true; }
public TerrainSaveObject(Vector3[,] map, float[,] biomeMap, Vector3 chunkLoc) { MyVector3[,] myVec = new MyVector3[map.GetLength(0), map.GetLength(1)]; for (int i = 0; i < map.GetLength(0); i++) { for (int j = 0; j < map.GetLength(1); j++) { myVec[i, j] = new MyVector3(map[i, j]); } } this.map = myVec; this.biomeMap = biomeMap; this.chunkLoc = new MyVector3(chunkLoc); }
//----------------------------------------------------------------- // Makes sure mass conservation is preserved across all volume public void Project(Vector3[,] v, Vector3[,] div) { // Creating divirgenece field for (int i = 1; i <= c_Size; i++) { for (int j = 1; j <= c_Size; j++) { // Store divirgence field in X component of the vector div[i, j] = new Vector3( -0.5f * (v[i + 1, j].x - v[i - 1, j].x + v[i, j + 1].y - v[i, j - 1].y) / c_Size, 0, 0); } } UpdateBounds(div); // Smooth divirgence field for (int it = 0; it < m_IterAmount; it++) { for (int i = 1; i <= c_Size; i++) { for (int j = 1; j <= c_Size; j++) { // Store smoothed field in Y component of the vector div[i, j] = new Vector3( div[i, j].x, (div[i, j].x + (div[i - 1, j].y + div[i + 1, j].y + div[i, j - 1].y + div[i, j + 1].y)) / 4.0f, 0); } } UpdateBounds(div); } // Normalize speed so there is no divirgence in the field for (int i = 1; i <= c_Size; i++) { for (int j = 1; j <= c_Size; j++) { v[i, j] = new Vector3( v[i, j].x - 0.5f * c_Size * (div[i + 1, j].y - div[i - 1, j].y), v[i, j].y - 0.5f * c_Size * (div[i, j + 1].y - div[i, j - 1].y), 0); } } UpdateBounds(v); }
void Awake() { helperMethods = new HelperMethods(); //Float RiverStartPointsPerPolygon = 4; HexagonRadius = 10000; //Using value 2582258 is equivalent to earth in size PentagonRadius = HexagonRadius / ((float)Math.Sin(36 * Mathf.Deg2Rad) * 2); PentagonApothem = PentagonRadius * (Mathf.Cos(36 * Mathf.Deg2Rad)); HexagonApothem = HexagonRadius * (Mathf.Cos(30 * Mathf.Deg2Rad)); PentagonEdgeLength = (2 * PentagonRadius * (Mathf.Sin(180 / 5))); //int plateRatioSeed = 1; //Array PolygonVertices = new Vector3[32, 6]; continentVertices = new Vector3[32, 7]; PolygonYIntercepts = new float[32, 6]; //list PentagonSlopes = new List<float>(); HexagonSlopes = new List<float>(); FPentagonSlopes = new List<float>(); tectonicNoise = new PerlinNoise(plateRatioSeed); PolygonPlatePoints = new int[32, 2]; RiverMouths = new int[32, 4]; RiverStartPoints = new Vector3[32, RiverStartPointsPerPolygon]; RiverStartDirection = new int[32, RiverStartPointsPerPolygon]; RiverMidpoints = new Vector3[32, 4]; ActiveRiverMidpoints = new bool[32, 3]; PolygonNeighbours = new int[32, 4]; RiverStartToMid = new int[32, 4]; RiverMidToMouth = new int[32, 4]; generateStaticValues(); generatePentagons(); generateHexagons(); generateFPentagons(); generateContinentVertices(); generateTectonicPoints(); generateRiverStartpoints(); generateRiverMouths(); generateRiverMidpoints(); linkRiverStartToMid(); }
private Mesh GenerateMesh(Vector3 position, int size) { Vector3[,] heightMap = GenerateHeightMap(position, size); Vector3[] verts = new Vector3[size * size]; Vector3[] normals = new Vector3[size * size]; Vector2[] uv = new Vector2[size * size]; List <int> triangles = new List <int>(); for (int x = 0; x < size; x++) { for (int z = 0; z < size; z++) { int index = x % size + z * size; verts[index] = heightMap[x, z]; normals[index] = Vector3.up; if (x > size - 2 || z > size - 2) { continue; } // triangle 1 triangles.Add(index); triangles.Add(index + size); triangles.Add(index + size + 1); // triangle 2 triangles.Add(index); triangles.Add(index + size + 1); triangles.Add(index + 1); } } Mesh mesh = new Mesh { name = "planeMesh", vertices = verts, triangles = triangles.ToArray(), uv = uv, normals = normals }; mesh.RecalculateBounds(); mesh.RecalculateNormals(); mesh.RecalculateTangents(); return(mesh); }
static Vector3[,] GetBandPos(Vector3[,] cornerPos, int dirXNum, int dirYNum) { Vector3[,] bandPos = new Vector3[2, 2 * (dirXNum + dirYNum)]; // dir_X for (int i = 0; i < dirXNum; i++) { for (int j = 0; j < 2; j++) { if (i == 0) { bandPos[j, 2 * i] = cornerPos[j, 1]; bandPos[j, 2 * i + 1] = cornerPos[j, 2]; } else if (i == dirXNum - 1) { bandPos[j, 2 * i] = cornerPos[j, 4]; bandPos[j, 2 * i + 1] = cornerPos[j, 3]; } else { bandPos[j, 2 * i] = Vector3.Lerp(cornerPos[j, 1], cornerPos[j, 4], 1f / (dirXNum - 1) * i); bandPos[j, 2 * i + 1] = Vector3.Lerp(cornerPos[j, 2], cornerPos[j, 3], 1f / (dirXNum - 1) * i); } } } // dir_Y for (int i = dirXNum; i < dirXNum + dirYNum; i++) { for (int j = 0; j < 2; j++) { if (i == 0) { bandPos[j, 2 * i] = cornerPos[j, 1]; bandPos[j, 2 * i + 1] = cornerPos[j, 4]; } else if (i == dirXNum + dirYNum - 1) { bandPos[j, 2 * i] = cornerPos[j, 2]; bandPos[j, 2 * i + 1] = cornerPos[j, 3]; } else { bandPos[j, 2 * i] = Vector3.Lerp(cornerPos[j, 1], cornerPos[j, 2], 1f / (dirYNum - 1) * (i - dirXNum)); bandPos[j, 2 * i + 1] = Vector3.Lerp(cornerPos[j, 4], cornerPos[j, 3], 1f / (dirYNum - 1) * (i - dirXNum)); } } } return(bandPos); }
public static Vector3[,] HSV(this Vector3[,] array) { int width = array.GetLength(0); int height = array.GetLength(1); Vector3[,] hsv = new Vector3[width, height]; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { Vector3 now = new Vector3(); Vector3 input = array[x, y]; float max = Math.Max(input.x, Math.Max(input.y, input.z)); float min = Math.Min(input.x, Math.Min(input.y, input.z)); if (min == max) { now.x = 0; } else if (max == input.x && input.y >= input.z) { now.x = 60 * (input.y - input.z) / (max - min); } else if (max == input.x && input.y < input.z) { now.x = 60 * (input.y - input.z) / (max - min) + 360; } else if (max == input.y) { now.x = 60 * (input.z - input.x) / (max - min) + 120; } else if (max == input.z) { now.x = 60 * (input.x - input.y) / (max - min) + 240; } if (max != 0) { now.y = 1 - min / max; } now.z = max; hsv[x, y] = now; } } return(hsv); }
private static Texture2D WriteConfigurationImage(Vector3[,] norms) { Texture2D ret = new Texture2D(256, 256, TextureFormat.RGBAFloat, false); for (int i = 0; i < 256; ++i) { for (int j = 0; j < 256; ++j) { //ret.SetPixel(i, j, GetColorFromFloat((norms[i,j].x + 1.0) * 0.5)); //ret.SetPixel(i, j + 256, GetColorFromFloat((norms[i, j].y + 1.0) * 0.5)); //ret.SetPixel(i, j + 512, GetColorFromFloat((norms[i, j].z + 1.0) * 0.5)); float fTheta = Mathf.Acos(norms[i, j].z); while (fTheta < 0.0f) { fTheta += Mathf.PI; } while (fTheta > 2.0f * Mathf.PI) { fTheta -= 2.0f * Mathf.PI; } if (fTheta > Mathf.PI) { fTheta = 2.0f * Mathf.PI - fTheta; } fTheta = fTheta / Mathf.PI; float fPhi = Mathf.Atan2(norms[i, j].y, norms[i, j].x); while (fPhi < 0.0f) { fPhi += Mathf.PI * 2.0f; } while (fPhi > Mathf.PI * 2.0f) { fPhi -= Mathf.PI * 2.0f; } fPhi = fPhi / (Mathf.PI * 2.0f); ret.SetPixel(i, j, new Color( Mathf.Clamp01(fTheta), Mathf.Clamp01(fPhi), 0.0F)); //ret.SetPixel(i, j + 256, new Color(fPhi, fPhi, fPhi)); } } ret.Apply(false); return(ret); }
// Use this for initialization void Start() { mySurface = new BSplineSurface(); mySurface.NI = 16; mySurface.NJ = 12; mySurface.RESOLUTIONI = 32; mySurface.RESOLUTIONJ = 24; mySurface.Init(); mySurface.InitRandomGrid(); mySurface.Calculate(); resultGrid = mySurface.outputGrid; controlGrid = mySurface.controlGrid; generateMesh(); updateMesh(); }
//Constructor for HeightMap. DETAIL specifies the resolution of this HeightMap. public HeightMap(int detail) { size = (int) Math.Pow(2.0d, (double)detail) + 1; max = size - 1; map = new float[size,size]; vertexNormals = new Vector3[size, size]; colors = new Color[size, size]; //Value to set the corners of map seed = max / 2; maxHeight = seed; //Roughness determines steepness of terrain roughness = .23f; rand = new Random(); GenerateMap(); GenerateVertexNormals(); }
void Start() { indikatorLayer = GameObject.Find ("IndikatorLayer").GetComponent<IndikatorLayer> (); mountainHandler = GameObject.Find ("Map").GetComponent<MountainHandler> (); mainCameraHandler = gameObject.GetComponent<MainCameraHandler> (); allWindParticles = GameObject.Find ("Main Camera/Wind Particle System").GetComponent<AllWindParticles> (); ui = GameObject.Find ("UI Root").GetComponent<globalUIHandler> (); // FIXME Besser wäre: Nochmal händisch auslesen und eintragen for (int n = 0; n<16; n++) for (int i = 0; i<3; i++) { sourcePositions[n,i] = rotationMiddlePositions[i]-(Quaternion.Euler (0,22.5f*n,0) * new Vector3(0f, -2f,12f)); } indikatorSourcePositions = sourcePositions; // Initial: Mittleren Berg auswählen changePieceTo (1); }
//Initialisation void Start() { //References to the geometry conducted by PolygonManager polygonVertices = PolygonManager.PolygonVertices; polygonYIntercepts = PolygonManager.PolygonYIntercepts; pentagonSlopes = PolygonManager.PentagonSlopes; hexagonSlopes = PolygonManager.HexagonSlopes; hexagonRadius = PolygonManager.HexagonRadius; pentagonRadius = PolygonManager.PentagonRadius; pentagonApothem = PolygonManager.PentagonApothem; hexagonApothem = PolygonManager.HexagonApothem; pentagonEdgeLength = PolygonManager.PentagonEdgeLength; polygonSides = PolygonManager.PolygonSides; polygonID = PolygonManager.PolygonID; fPentagonSlopes = PolygonManager.FPentagonSlopes; //List thats hold unique ID's for each tile terrainUsage = new Dictionary<string, int>(); //list that holds terrainData for each tile ID terrainUsageData = new Dictionary<string, TerrainData>(); currentTerrainID = new int[2]; terrainBuffer = new Terrain[TERRAIN_BUFFER_COUNT]; usedTiles = new BitArray(TERRAIN_BUFFER_COUNT, false); touchedTiles = new BitArray(TERRAIN_BUFFER_COUNT, false); /*--------Terrain Location References----------*/ referencePosition = referenceTerrain.transform.position; referenceRotation = referenceTerrain.transform.rotation; referenceSize = new Vector2(referenceTerrain.terrainData.size.x, referenceTerrain.terrainData.size.z); /*------------This loads 50 instances/ objects of the terrainData for placement----------*/ for (int i = 0; i < TERRAIN_BUFFER_COUNT; i++) { TerrainData tData = new TerrainData(); CopyTerrainDataFromTo(referenceTerrain.terrainData, ref tData); terrainBuffer[i] = Terrain.CreateTerrainGameObject(tData).GetComponent<Terrain>(); terrainBuffer[i].gameObject.SetActive(false); } }
public void CreateScalp(Vector3[,] grid, int NI, int NJ) { Debug.Log("Creating Scalp"); surface = GameObject.Find("ScalpSurface"); surface.AddComponent<MeshFilter>(); surface.AddComponent<MeshCollider>(); mySurface = new BSplineSurface(); mySurface.setControlGrid(NI, NJ); mySurface.Init(); //mySurface.InitRandomGrid(); mySurface.InitGrid(grid); mySurface.Calculate(); resultGrid = mySurface.outputGrid; controlGrid = mySurface.controlGrid; generateMesh(); updateMesh(); drawn = true; }
public static void CalculateRaycastPoints(Vector2 cellSize) { float areaSize = Vector3.Distance(areaPoints[0], areaPoints[1]); int rowPointsCount = Mathf.CeilToInt(areaSize / cellSize.y) + 1; int colPointsCount = Mathf.CeilToInt(areaSize / cellSize.x) + 1; points = new Vector3[rowPointsCount, colPointsCount]; for (int i = 0; i < rowPointsCount; i++) { for (int j = 0; j < colPointsCount; j++) { points[i, j] = new Vector3(j * cellSize.x, 0, i * cellSize.y) + areaPoints[0]; } } if (PointsChanged != null) PointsChanged(points); }
// Use this for initialization void Start() { grid = new Vector3[10,10]; gameObjectGrid = new GameObject[10,10]; for(int i = 0; i < 10; i ++) { for(int j = 0; j < 10; j++) { grid[i,j] = new Vector3(50 + (50 * i), 0, 50 + (50*j)); Instantiate(marker, grid[i,j], Quaternion.identity); } } samplePath = new Vector3[] {grid[ 4,4], grid[5,5], grid [7,5], grid[ 8, 2]}; }