void InitializeBoard() { int dotsNumber = boardWidth * boardHeight; boardPositions = new Vector2[boardWidth, boardHeight]; startX = dotDistance * (boardWidth / 2); startY = dotDistance * (boardHeight / 2); startX -= (boardWidth % 2) == 0 ? (dotDistance/2f) : 0f; startY -= (boardHeight % 2) == 0 ? (dotDistance/2f): 0f; for(int y = 0; y < boardHeight; y++) { for(int x = 0; x < boardWidth; x++) { Vector2 position = new Vector2(x * dotDistance - startX, y * dotDistance - startY); boardPositions[x,y] = position; Dot dot = ((GameObject)GameObject.Instantiate(dotSprite, new Vector3(position.x, position.y, 0f), Quaternion.identity)).GetComponent<Dot>(); dot.transform.parent = transform; dot.boardPosition = new Vector2(x,y); dot.name = dot.name + x*y; boardDots.Add (dot); } } //Debug.Log(dotSprite.GetComponent<SpriteRenderer>().sprite.bounds); }
public Creature (Rectangle bounds, Texture2D texture, Color tint) { Brain = new NeuralNetwork(0, 4, 4, 3); Bounds = bounds; Position = new Vector2(Rand.Next(Bounds.Left, Bounds.Right), Rand.Next(Bounds.Top, Bounds.Bottom)); _edges = new[,] { {new Vector2(bounds.Left, bounds.Top), new Vector2(bounds.Right, bounds.Top)}, {new Vector2(bounds.Right, bounds.Top), new Vector2(bounds.Right, bounds.Bottom)}, {new Vector2(bounds.Right, bounds.Bottom), new Vector2(bounds.Left, bounds.Bottom)}, {new Vector2(bounds.Left, bounds.Bottom), new Vector2(bounds.Left, bounds.Top)} }; _edgeLengths = new[] { Vector2.DistanceSquared(_edges[0, 0], _edges[0, 1]), Vector2.DistanceSquared(_edges[1, 0], _edges[1, 1]), Vector2.DistanceSquared(_edges[2, 0], _edges[2, 1]), Vector2.DistanceSquared(_edges[3, 0], _edges[3, 1]) }; Angle = Rand.Next(0, 360); Frame = Rand.Next(0, _stripWidth); Life = 100; Texture = texture; Tint = tint; }
/** * */ private void initBuffers() { int N1 = this.settings.N; int N2 = (int)(this.settings.N * this.settings.N); // --------------------- // // spectrum: this.m_spectrumBuffer = new Vector2[N1,N1]; // --------------------- // this.m_heightBuffer = new Vector2[2, N2]; this.m_slopeBuffer = new Vector4[2, N2]; this.m_displaceBuffer = new Vector4[2, N2]; // --------------------- // this.m_dispertion.init(); this.m_spectrum.init(); this.m_fourier.init( N1 ); // --------------------- // this.m_grid = new OceanGrid( 8, 8, this.settings.N + 1, this.settings ); }
void Start() { isInventoryPositionFilled = GameObject.FindGameObjectWithTag("Canvas").GetComponent<InventoryData>().isInventoryPositionFilled; itemPositions = GameObject.FindGameObjectWithTag("Canvas").GetComponent<InventoryData>().itemPositions; ItemIncreased(); itemPosition = itemPositions[(int)itemIndex.x, (int)itemIndex.y]; }
public void SetRenderableArray(Vector2[,] vectorArray /*, float[,] floatArray*/) { width = vectorArray.GetLength(0); height = vectorArray.GetLength(1); renderShader.SetInt("Width", width); renderShader.SetInt("Height", height); arrayBuffer = new ComputeBuffer(width * height, sizeof(float) * 2); }
// // Allocation des deux tableaux // 1) celui contenant les points de sommet (les points uniques), // 2) celui contenant les sommets servant à dessiner les triangles void AllouerTableaux() { //TabPtsSommet = new Vector3[NbColonnes, NbRangées]; //Sommets = new VertexPositionTexture[NbSommets]; PtsTexture = new Vector2[NbColonnes + 1, NbRangées + 1]; TabPtsSommet = new Vector3[NbColonnes + 1, NbRangées + 1]; Sommets = new VertexPositionTexture[NbSommets]; }
public GameProcess() { Way = new List <Vector2>(); GameFild = new Vector2[35, 35]; Towers = new Tower[35, 35]; GetWay(); //enemy = new Enemy1(); }
public void Multiply() { Vector2[,] expected = MakeResult(size, size, new Vector2(375, 375)); FastMatrix <Vector2> matrix = MakeMatrix(size, size, fifteen); FastMatrix <Vector2> matrix2 = MakeMatrix(size, size, five); VerifyResults(cpu.Multiply(matrix, matrix2), expected); }
public void Subtract() { Vector2[,] expected = MakeResult(size, size, fifteen); FastMatrix <Vector2> matrix = MakeMatrix(size, size, twenty); FastMatrix <Vector2> matrix2 = MakeMatrix(size, size, five); VerifyResults(cpu.Subtract(matrix, matrix2), expected); }
// Use this for initialization void Start() { pillarCellData = new Vector2[xNumberOfCells, yNumberOfCells]; BuildGrid(); FillCells(); }
public Model(Vector3[] voxelVerts, Vector3[] faceChecks, int[,] voxelTris, List <int> tintedFaces, Vector2[,] voxelUvs) { this.voxelVerts = voxelVerts; this.faceChecks = faceChecks; this.voxelTris = voxelTris; this.voxelUvs = voxelUvs; this.tintedFaces = tintedFaces; }
public Dictionary <FaceDirections, Vector2[]> GenerateExtremeCellPositions(Vector2[,] generatedTilePositions) { return(new Dictionary <FaceDirections, Vector2[]> { { FaceDirections.Top, TopFaceCellIndices.Select(index => generatedTilePositions[index.x, index.y]).ToArray() }, { FaceDirections.Right, RightFaceCellIndices.Select(index => generatedTilePositions[index.x, index.y]).ToArray() } }); }
/// Create a sampler with the following parameters: /// /// width: each sample's x coordinate will be between [0, width] /// height: each sample's y coordinate will be between [0, height] /// radius: each sample will be at least `radius` units away from any other sample, and at most 2 * `radius`. public PoissonDiscSampler(float width, float height, float radius) { rect = new Rect(0, 0, width, height); radius2 = radius * radius; cellSize = radius / Mathf.Sqrt(2); grid = new Vector2[Mathf.CeilToInt(width / cellSize), Mathf.CeilToInt(height / cellSize)]; }
//is in the final path public Brain() { closed = new bool[80, 48]; cost = new float[80, 48]; link = new Vector2[80, 48]; inPath = new bool[80, 48]; path = new List <Vector2>(); }
protected override void GetDeformation(out Vector2[,] deformation, out float multiplier, bool inverse) { deformation = Deformation; multiplier = CustomDeformationParams.Frequency <= 0.0f ? CustomDeformationParams.Amplitude : (float)Math.Sin(inverse ? -phase : phase) * CustomDeformationParams.Amplitude; multiplier *= Params.Strength; }
public void Generate() { bool[,] map = new bool[width, height]; FillMap(map); for (int i = 0; i < 5; i++) { map = CellularAutomataPass(map); } RemoveUnconnectedParts(map); nearestTiles = new Vector2[width, height]; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { if (map[x, y]) { InstantiateFloorTile(map, x, y); if (IsFloor(map, x, y + 1) && IsFloor(map, x, y - 1) && IsFloor(map, x + 1, y) && IsFloor(map, x - 1, y)) { nearestTiles[x, y] = new Vector2(x, y); } else { nearestTiles[x, y] = -Vector2.one; } } else { nearestTiles[x, y] = -Vector2.one; } } } PrefillNearestTiles(map); if (topDoor == null) { GameObject door = Instantiate(doorPrefab, fallbackTopDoorPosition, Quaternion.identity, transform) as GameObject; topDoor = door.GetComponent <Door>(); Debug.LogWarning("Top door in fallback position"); } topDoor.room = this; if (bottomDoor == null) { GameObject door = Instantiate(doorPrefab, fallbackBottomDoorPosition, Quaternion.identity, transform) as GameObject; bottomDoor = door.GetComponent <Door>(); Debug.LogWarning("Bottom door in fallback position"); } bottomDoor.room = this; bottomDoor.doorToHub = true; RoomPlan = RoomPlanFactory.getInstance().getRoomPlan(this.ID, this); }
public void PostConstruct() { //TODO: use actual block def count count - BlockDefs.GetAllDefinitions().Length //not that important for lookup tho, and introduces the need to pass block def count to chunk render job, so f**k-it pile for now WorldUvLookup = new Vector2[MAX_BLOCKDEF_COUNT, FACES_PER_VOXEL, 4]; WorldUvLookupNative = new NativeArray <float2>(WorldUvLookup.Length, Allocator.Persistent); //TODO fix voxel type determination so we rely on actual enum in the voxel def not array index //zero is only marker for no data so we dont need to generate uv lookup //(we actually also don't need to do that for Air) var blockDefs = BlockDefs.GetAllDefinitions(); int uvId; for (var iVoxelType = 1; iVoxelType < blockDefs.Length; iVoxelType++) { var voxelDef = blockDefs[iVoxelType]; for (var iFace = 0; iFace < voxelDef.FaceTextures.Length; iFace++) { var textureId = voxelDef.FaceTextures[iFace]; float x = textureId % BLOCKS_PER_SIDE_WORLD * NORMALIZED_BLOCK_SIZE_WORLD; float y = (int)(textureId / BLOCKS_PER_SIDE_WORLD) * NORMALIZED_BLOCK_SIZE_WORLD; WorldUvLookup[iVoxelType, iFace, 0] = new Vector2(x, y); WorldUvLookup[iVoxelType, iFace, 1] = new Vector2(x, y + NORMALIZED_BLOCK_SIZE_WORLD); WorldUvLookup[iVoxelType, iFace, 2] = new Vector2(x + NORMALIZED_BLOCK_SIZE_WORLD, y); WorldUvLookup[iVoxelType, iFace, 3] = new Vector2(x + NORMALIZED_BLOCK_SIZE_WORLD, y + NORMALIZED_BLOCK_SIZE_WORLD); uvId = ArrayHelper.To1D(iVoxelType, iFace, 0, MAX_BLOCKDEF_COUNT, FACES_PER_VOXEL); WorldUvLookupNative[uvId] = new Vector2(x, y); uvId = ArrayHelper.To1D(iVoxelType, iFace, 1, MAX_BLOCKDEF_COUNT, FACES_PER_VOXEL); WorldUvLookupNative[uvId] = new Vector2(x, y + NORMALIZED_BLOCK_SIZE_WORLD); uvId = ArrayHelper.To1D(iVoxelType, iFace, 2, MAX_BLOCKDEF_COUNT, FACES_PER_VOXEL); WorldUvLookupNative[uvId] = new Vector2(x + NORMALIZED_BLOCK_SIZE_WORLD, y); uvId = ArrayHelper.To1D(iVoxelType, iFace, 3, MAX_BLOCKDEF_COUNT, FACES_PER_VOXEL); WorldUvLookupNative[uvId] = new Vector2(x + NORMALIZED_BLOCK_SIZE_WORLD, y + NORMALIZED_BLOCK_SIZE_WORLD); } } UtilsUvLookup = new Vector2[BLOCKS_PER_TEXTURE_UTILS, 4]; for (var i = 0; i < BLOCKS_PER_TEXTURE_UTILS; i++) { float x = i % BLOCKS_PER_SIDE_UTILS * NORMALIZED_BLOCK_SIZE_UTILS; float y = (int)(i / BLOCKS_PER_SIDE_UTILS) * NORMALIZED_BLOCK_SIZE_UTILS; UtilsUvLookup[i, 0] = new Vector2(x, y); UtilsUvLookup[i, 1] = new Vector2(x, y + NORMALIZED_BLOCK_SIZE_UTILS); UtilsUvLookup[i, 2] = new Vector2(x + NORMALIZED_BLOCK_SIZE_UTILS, y); UtilsUvLookup[i, 3] = new Vector2(x + NORMALIZED_BLOCK_SIZE_UTILS, y + NORMALIZED_BLOCK_SIZE_UTILS); } }
private Vector3 getFFT(int x, int z, out Vector3 normal) { if (!hasDoneFFT) { hasDoneFFT = true; FFT_H = new Vector2[edgelen, edgelen]; FFT_Dx = new Vector2[edgelen, edgelen]; FFT_Dz = new Vector2[edgelen, edgelen]; FFT_Nx = new Vector2[edgelen, edgelen]; FFT_Nz = new Vector2[edgelen, edgelen]; int halfedgelen = edgelen / 2; float kx, kz; Vector2 k; Vector2 ht; int uaddh; int vaddh; for (int u = -halfedgelen; u < halfedgelen; u++) { kx = 2 * Mathf.PI * u / edgelen; for (int v = -halfedgelen; v < halfedgelen; v++) { kz = 2 * Mathf.PI * v / edgelen; k = new Vector2(kx, kz); uaddh = u + halfedgelen; vaddh = v + halfedgelen; ht = Htildes[uaddh, vaddh]; FFT_H[uaddh, vaddh] = new Vector2(ht.x, ht.y); if (k.magnitude < Min) { FFT_Nx[uaddh, vaddh] = new Vector2(0, 0); FFT_Nz[uaddh, vaddh] = new Vector2(0, 0); FFT_Dx[uaddh, vaddh] = new Vector2(0, 0); FFT_Dz[uaddh, vaddh] = new Vector2(0, 0); } else { FFT_Nx[uaddh, vaddh] = new Vector2(-ht.y * kx, ht.x * kx); FFT_Nz[uaddh, vaddh] = new Vector2(-ht.y * kz, ht.x * kz); FFT_Dx[uaddh, vaddh] = new Vector2(ht.y * kx / k.magnitude, -ht.x * kx / k.magnitude); FFT_Dz[uaddh, vaddh] = new Vector2(ht.y * kz / k.magnitude, -ht.x * kz / k.magnitude); } FFT_H[uaddh, vaddh].y *= -1; FFT_Nx[uaddh, vaddh].y *= -1; FFT_Nz[uaddh, vaddh].y *= -1; FFT_Dx[uaddh, vaddh].y *= -1; FFT_Dz[uaddh, vaddh].y *= -1; } } FFTHelper.FFT(FFT_H, edgelen); FFTHelper.FFT(FFT_Nx, edgelen); FFTHelper.FFT(FFT_Nz, edgelen); FFTHelper.FFT(FFT_Dx, edgelen); FFTHelper.FFT(FFT_Dz, edgelen); } normal = new Vector3(0, 1, 0) - new Vector3(FFT_Nx[x, z].x, 0, FFT_Nz[x, z].x); return(new Vector3(FFT_Dx[x, z].x * -Q, FFT_H[x, z].x, FFT_Dz[x, z].x * -Q)); }
public Tube(Mesh mesh, Vector3[,] vertex2DRepresentation, Vector3[,] normal2DRepresentation, Vector2[,] uv2DRepresentation, Transform[] bones, BoxCollider[] boxColliders) { this.mesh = mesh; this.vertex2DRepresentation = vertex2DRepresentation; this.normal2DRepresentation = normal2DRepresentation; this.uv2DRepresentation = uv2DRepresentation; this.bones = bones; this.boxColliders = boxColliders; }
public TerrainData(TiledTerrainConfig config, BinaryReader reader) { Config = config; Reader = reader; Heights = new float[Config.PatchHeightRes, Config.PatchHeightRes]; Normals = new Vector3[Config.PatchHeightRes, Config.PatchHeightRes]; Splats = new Vector2[Config.PatchSplatRes, Config.PatchSplatRes]; }
public override void Create(GameObject createdObject) { if (createdObject == this) { if (_ANSIrepresentations == null || _side == 0 || _spacing == 0 || _squareSide == 0) //This means that the object isnt initialized properly { throw new NullReferenceException(); } Objects = new GameObject[_side, _side]; _positions = new Vector2[_side, _side]; int doubleSpacing = _spacing * 2; //This is used so there is space for lines left #region Calculate square positions float yPosition = Sprite.Position.Y + _spacing; for (int i = 0; i < _side; i++) { for (int j = 0; j < _side; j++) { _positions[i, j] = new Vector2(yPosition, _squareSide * j + Sprite.Position.X + _spacing + doubleSpacing * j); } yPosition += _squareSide + doubleSpacing; } #endregion #region Calculate line positions _verticalLinePoints = new Vector2[2, _side + 1]; _horizontalLinePoints = new Vector2[2, _side + 1]; int lineLenght = _spacing * 2 + _squareSide * _side + doubleSpacing * (_side - 1); int lineSpacing = _spacing * 2 + _squareSide; for (int i = 0; i <= _side; i++) { Vector2 horizontalFirstPoint = new Vector2(Sprite.Position.X, Sprite.Position.Y + lineSpacing * i); Vector2 horizontalSecondPoint = new Vector2(horizontalFirstPoint.X + lineLenght, horizontalFirstPoint.Y); _horizontalLinePoints[0, i] = horizontalFirstPoint; _horizontalLinePoints[1, i] = horizontalSecondPoint; Vector2 verticalFirstPoint = new Vector2(Sprite.Position.X + lineSpacing * i, Sprite.Position.Y); Vector2 verticalSecondPoint = new Vector2(verticalFirstPoint.X, verticalFirstPoint.Y + lineLenght); _verticalLinePoints[0, i] = verticalFirstPoint; _verticalLinePoints[1, i] = verticalSecondPoint; } #endregion } }
/** * */ public void init() { Debug.Log( "init spectrum" ); this.spectrum_norm = new Vector2[ this.settings.N + 1, this.settings.N + 1 ]; this.spectrum_conj = new Vector2[ this.settings.N + 1, this.settings.N + 1 ]; this.update(); }
//[Serializable] //[StructLayout(LayoutKind.Sequential, Pack = 4)] //public struct Test //{ // public int msg_type; // [MarshalAs(UnmanagedType.ByValArray, SizeConst = 11)] // public char[] str; // public Test(int msg_type, string msg_date) // { // this.msg_type = msg_type; // this.str = msg_date.PadRight(11, '\0').ToCharArray(); // } //} //public byte[] StructToBytes(Object obj) //{ //} void Start() { // 先连接服务器 //NetWorkScript.Instance.Init(); chesspos = new Vector2[15, 15]; chessstate = new int[15, 15]; chessturn = turn.black; }
// Use this for initialization void Start() { //初始化可以落子的位置 chessPos = new Vector2[15, 15]; //游戏开始时是黑方先下 chessTurn = turn.black; //初始化棋盘状态 chessState = new int[15, 15]; }
private Vector2[,] grid; // a 2D array to store the position of cells (midpoint) public GridMap(Vector3 origin, float x_width, float z_width, int x_numCells, int z_numCells) { this.x_cellWidth = x_width; this.z_cellWidth = z_width; this.x_numCells = x_numCells; this.z_numCells = z_numCells; grid = new Vector2[this.x_numCells, this.z_numCells]; // construct the 2D grid array constructGrid(origin.x, origin.z); }
public Fluid(float viscosity, int size) { this.size = size; visc = viscosity; velocity = new Vector2[size, size]; velocity0 = new Vector2[size, size]; }
/// <summary> /// 床を配置する /// </summary> void SetMapFloorImage() { _mapSize = _miniMapSystem.MapSize; _mapImages = new Image[_mapSize.Y, _mapSize.X]; _imagePositions = new Vector2[_mapSize.Y, _mapSize.X]; var delta = (RoomSize + AisleLength) * 0.5f; Vector2 position = new Vector2(); for (int i = 0; i < _mapSize.Y; i++) { for (int j = 0; j < _mapSize.X; j++) { //床も廊下もない空間 if (i % 2 != 0 && j % 2 != 0) { position.x += delta; continue; } var image = Instantiate(FloorImagePre, MapParent); //両方偶数の時は床 if (i % 2 == 0 && j % 2 == 0) { image.rectTransform.sizeDelta = new Vector2(RoomSize, RoomSize); } //そのほかは廊下 else { Vector2 aisleSize; //横方向の接続 if (i % 2 == 0) { aisleSize = new Vector2(AisleLength, AisleWidth); } else { aisleSize = new Vector2(AisleWidth, AisleLength); } image.rectTransform.sizeDelta = aisleSize; } image.rectTransform.anchoredPosition = position; image.color = MiniMapColor; _imagePositions[i, j] = position; _mapImages[i, j] = image; position.x += delta; } position.x = 0.0f; position.y += delta; } }
public Grid(int sizex, int sizez) { gridsizex = sizex; gridsizez = sizez; arr = new int[gridsizez, gridsizex]; obsticles = new List <Obsticle> (); vectorfield = new Vector2[gridsizez, gridsizex]; list = new Queue(gridsizex * gridsizez * 3); }
public DC(GraphicsDevice device, int resolution, int Size) : base(device, resolution, Size, false) { map = new float[resolution, resolution]; vertices = new Vector2[resolution, resolution]; vertex_indexes = new int[resolution, resolution]; InitData(); }
private void Awake() { block = new Transform[m, n]; blockPos = new Vector2[m, n]; map = new int[m, n]; isSquare = new bool[m, n]; num = m - 1; }
public DC(GraphicsDevice device, int resolution, int Size) : base(device, resolution, Size, false) { map = new float[resolution, resolution]; vertices = new Vector2[resolution, resolution]; vertex_indexes = new int[resolution, resolution]; InitData(); }
public int PeformFFT(int startIdx, Vector2[,] data0, Vector4[,] data1, Vector4[,] data2) { int x; int y; int i; int idx = 0; int idx1; int bftIdx; int X; int Y; Vector2 w; int j = startIdx; for (i = 0; i < m_passes; i++, j++) { idx = j % 2; idx1 = (j + 1) % 2; for (x = 0; x < m_size; x++) { for (y = 0; y < m_size; y++) { bftIdx = 4 * (x + i * m_size); X = (int)m_butterflyLookupTable[bftIdx + 0]; Y = (int)m_butterflyLookupTable[bftIdx + 1]; w.x = m_butterflyLookupTable[bftIdx + 2]; w.y = m_butterflyLookupTable[bftIdx + 3]; data0[idx, x + y * m_size] = FFT(w, data0[idx1, X + y * m_size], data0[idx1, Y + y * m_size]); data1[idx, x + y * m_size] = FFT(w, data1[idx1, X + y * m_size], data1[idx1, Y + y * m_size]); data2[idx, x + y * m_size] = FFT(w, data2[idx1, X + y * m_size], data2[idx1, Y + y * m_size]); } } } for (i = 0; i < m_passes; i++, j++) { idx = j % 2; idx1 = (j + 1) % 2; for (x = 0; x < m_size; x++) { for (y = 0; y < m_size; y++) { bftIdx = 4 * (y + i * m_size); X = (int)m_butterflyLookupTable[bftIdx + 0]; Y = (int)m_butterflyLookupTable[bftIdx + 1]; w.x = m_butterflyLookupTable[bftIdx + 2]; w.y = m_butterflyLookupTable[bftIdx + 3]; data0[idx, x + y * m_size] = FFT(w, data0[idx1, x + X * m_size], data0[idx1, x + Y * m_size]); data1[idx, x + y * m_size] = FFT(w, data1[idx1, x + X * m_size], data1[idx1, x + Y * m_size]); data2[idx, x + y * m_size] = FFT(w, data2[idx1, x + X * m_size], data2[idx1, x + Y * m_size]); } } } return(idx); }
/// <summary> /// Initialize Grid object /// </summary> /// <param name="Origin">Coordinates of the top left corner of the grid</param> /// <param name="Size">Size of the grid</param> /// <param name="CellSize">Size of each cell</param> public Grid(Vector2 Origin, Vector2 Size, Vector2 CellSize) { columns = (int)(Size.X / CellSize.X); rows = (int)(Size.Y / CellSize.Y); //To be used outside the scope of this method grid_array = new Vector2[columns, rows]; // Now that we got all the relevant information we can start constructing the grid. PopulateArray(columns, rows, CellSize, Origin); }
public Map_Data_Package(float[,] h, float[,] g, Vector2[,] dh) { this._h = h; this._g = g; this._dh = dh; this._xdim = _h.GetLength(0); this._ydim = _h.GetLength(1); }
private void GenerateLattices() { lattices = new Vector2[lSize, lSize]; for (int x = 0; x < lSize; x++) { for (int y = 0; y < lSize; y++) { lattices[x, y] = new Vector2(Random.value, Random.value).normalized; } } }
public void Clear() { ChessPos = new Vector2[19, 19]; ChessState = new int[19, 19]; isPlaying = false; Ui = false; Camera.main.transform.position = CameraPoint.transform.position; Camera.main.transform.rotation = CameraPoint.transform.rotation; PanelMgr.instance.OpenPanel <TitlePanel>(""); }
void Start() { validPos = new Vector2[size, size]; fields = new Field[size, size]; desk = new char[size, size]; FillLocation(); ai = new ChessAI(fields); StartNewGame(); }
public AStar(Vector2 s, Vector2 e, Vector2 d) { start = s; end = e; gScore = new int[(int) d.X, (int) d.Y]; hScore = new int[(int) d.X, (int) d.Y]; fScore = new int[(int) d.X, (int) d.Y]; cameFrom = new Vector2[(int) d.X, (int) d.Y]; }
public static double[,] CalculateAngles(Bitmap originalBitmap) { int[,] sobelOperator = { { -1, 0, 1 }, { -2, 0, 2 }, { -1, 0, 1 } }; int[,] sobelOperator90Degree = { { -1, -2, -1 }, { 0, 0, 0 }, { 1, 2, 1 } }; int[,] sobelArray = CalculateBitmapWithMask(originalBitmap, sobelOperator); int[,] sobel90DegreeArray = CalculateBitmapWithMask(originalBitmap, sobelOperator90Degree); Vector2[,] gradient = CreateGradient(sobelArray, sobel90DegreeArray); double[,] angles = CreateAngleArray(gradient); return(AverageAngles(angles, originalBitmap)); }
/// Create a sampler with the following parameters: /// /// width: each sample's x coordinate will be between [0, width] /// height: each sample's y coordinate will be between [0, height] /// radius: each sample will be at least `radius` units away from any other sample, and at most 2 * `radius`. public PoissonDiscSampler(float width, float height, float radius) { rect = new Rectangle(0, 0, (int)width, (int)height); radius2 = radius * radius; cellSize = (float)(radius / Math.Sqrt(2)); grid = new Vector2[(int)Math.Ceiling(width / cellSize), (int)Math.Ceiling(height / cellSize)]; _random = new Random(Guid.NewGuid().GetHashCode()); }
private void generateVectorField() { vectorField = new Vector2[map.Height, map.Width]; for (int r = 0; r < map.Height; r++) { for (int c = 0; c < map.Width; c++) { #region old stuff, half working if (heatmap[r, c] == -1) continue; float left_dist = heatmap[r, c <= 0 ? c : c - 1]; float right_dist = heatmap[r, c >= map.Width - 1 ? c : c + 1]; float top_dist = heatmap[r <= 0 ? r : r - 1, c]; float bot_dist = heatmap[r >= map.Height - 1 ? r : r + 1, c]; //if (left_dist == -1) left_dist = right_dist;// heatmap[r, c]; //if (right_dist == -1) right_dist = left_dist;// heatmap[r, c]; //if (top_dist == -1) top_dist = bot_dist;// heatmap[r, c]; //if (bot_dist == -1) bot_dist = top_dist;// heatmap[r, c]; if (left_dist == -1) left_dist = heatmap[r, c]; if (right_dist == -1) right_dist = heatmap[r, c]; if (top_dist == -1) top_dist = heatmap[r, c]; if (bot_dist == -1) bot_dist = heatmap[r, c]; vectorField[r, c].x = left_dist - right_dist; vectorField[r, c].y = top_dist - bot_dist; vectorField[r, c].Normalize(); #endregion // find the lowest valued neighbor (>= 0) // set the vector to the direction to that neighbor //if (heatmap[r, c] == -1) continue; //int lowest = heatmap[r, c]; //Vector2 dir = Vector2.zero; //for (int roff = (r > 0 ? -1 : 0); roff <= (r < map.Height-1 ? 1 : 0); roff++) //{ // for (int coff = (c > 0 ? -1 : 0); coff <= (c < map.Width-1 ? 1 : 0); coff++) // { // //if (coff == 0 && roff == 0) continue; // if (heatmap[r + roff, c + coff] < lowest && heatmap[r + roff, c + coff] >= 0) // { // lowest = heatmap[r + roff, c + coff]; // dir = new Vector2(coff, roff); // } // } //} //vectorField[r, c] = dir; //vectorField[r, c].Normalize(); } } }
void Awake() { _pixels = new Vector2[Screen.width, Screen.height]; for (int i = 0; i < Screen.width; i++) for (int j = 0; j < Screen.height; j++) _pixels[i, j] = new Vector2(i, j); _parts = new List<List<Vector2>>(); _clones = GameObject.FindGameObjectWithTag("GameManager").GetComponent<Clones>(); }
/// Create a sampler with the following parameters: /// /// width: each sample's x coordinate will be between [0, width] /// height: each sample's y coordinate will be between [0, height] /// radius: each sample will be at least `radius` units away from any other sample, and at most 2 * `radius`. public PoissonDiscSampler(float width, float height, float radius, Vector2 _clusterRange, int seed) { clusterRange = _clusterRange; Random.seed = seed; rect = new Rect(0, 0, width, height); radius2 = radius * radius; cellSize = radius / CustomMathf.sqrt2; // Debug.Log("Cell Size: " + cellSize); grid = new Vector2[Mathf.CeilToInt(width / cellSize), Mathf.CeilToInt(height / cellSize)]; }
public Grid(int width = 128, int height = 128) { if (width < 1) width = 1; if (height < 1) height = 1; gridArray = new Color[width+1, height+1]; gridWidth = width; gridHeight = height; gridPositions = new Vector2[gridColumns,gridLines]; }
public void Init() { _k = new Vector2[N,N]; _kNormalized = new Vector2[N,N]; for (var y = 0; y < N; y++) { for (var x = 0; x < N; x++) { var k = _k[x, y] = Calc(x, y); _kNormalized[x, y] = k.normalized; } } }
/// <summary> /// Initialize Grid object /// </summary> /// <param name="Origin">Coordinates of the top left corner of the grid</param> /// <param name="Size">Size of the grid</param> /// <param name="Columns">Number of columns</param> /// <param name="Rows">Number of rows</param> public Grid(Vector2 Origin, Vector2 Size, int Columns, int Rows) { columns = Columns; rows = Rows; //To be used outside the scope of this method. //Figure out the size of each cell, basically just divide size by Columns/Rows Vector2 cell_size = new Vector2(Size.X / Columns, Size.Y / Rows); grid_array = new Vector2[Columns, Rows]; //2D array that holds coordinates to every cell in the grid //Now that we got all the relevant information, we can start constructing the grid. PopulateArray(Columns, Rows, cell_size, Origin); }
static AvatarControl() { AvatarControl.s_BonePositions = new Vector2[4, HumanTrait.BoneCount]; int num = 0; AvatarControl.s_BonePositions[num, 0] = new Vector2(0f, 0.08f); AvatarControl.s_BonePositions[num, 1] = new Vector2(0.16f, 0.01f); AvatarControl.s_BonePositions[num, 2] = new Vector2(-0.16f, 0.01f); AvatarControl.s_BonePositions[num, 3] = new Vector2(0.21f, -0.4f); AvatarControl.s_BonePositions[num, 4] = new Vector2(-0.21f, -0.4f); AvatarControl.s_BonePositions[num, 5] = new Vector2(0.23f, -0.8f); AvatarControl.s_BonePositions[num, 6] = new Vector2(-0.23f, -0.8f); AvatarControl.s_BonePositions[num, 7] = new Vector2(0f, 0.25f); AvatarControl.s_BonePositions[num, 8] = new Vector2(0f, 0.43f); AvatarControl.s_BonePositions[num, 9] = new Vector2(0f, 0.66f); AvatarControl.s_BonePositions[num, 10] = new Vector2(0f, 0.76f); AvatarControl.s_BonePositions[num, 11] = new Vector2(0.14f, 0.6f); AvatarControl.s_BonePositions[num, 12] = new Vector2(-0.14f, 0.6f); AvatarControl.s_BonePositions[num, 13] = new Vector2(0.3f, 0.57f); AvatarControl.s_BonePositions[num, 14] = new Vector2(-0.3f, 0.57f); AvatarControl.s_BonePositions[num, 15] = new Vector2(0.48f, 0.3f); AvatarControl.s_BonePositions[num, 16] = new Vector2(-0.48f, 0.3f); AvatarControl.s_BonePositions[num, 17] = new Vector2(0.66f, 0.03f); AvatarControl.s_BonePositions[num, 18] = new Vector2(-0.66f, 0.03f); AvatarControl.s_BonePositions[num, 19] = new Vector2(0.25f, -0.89f); AvatarControl.s_BonePositions[num, 20] = new Vector2(-0.25f, -0.89f); num = 1; AvatarControl.s_BonePositions[num, 9] = new Vector2(-0.2f, -0.62f); AvatarControl.s_BonePositions[num, 10] = new Vector2(-0.15f, -0.3f); AvatarControl.s_BonePositions[num, 21] = new Vector2(0.63f, 0.16f); AvatarControl.s_BonePositions[num, 22] = new Vector2(0.15f, 0.16f); AvatarControl.s_BonePositions[num, 23] = new Vector2(0.45f, -0.4f); num = 2; AvatarControl.s_BonePositions[num, 24] = new Vector2(-0.35f, 0.11f); AvatarControl.s_BonePositions[num, 27] = new Vector2(0.19f, 0.11f); AvatarControl.s_BonePositions[num, 30] = new Vector2(0.22f, 0f); AvatarControl.s_BonePositions[num, 33] = new Vector2(0.16f, -0.12f); AvatarControl.s_BonePositions[num, 36] = new Vector2(0.09f, -0.23f); AvatarControl.s_BonePositions[num, 26] = new Vector2(-0.03f, 0.33f); AvatarControl.s_BonePositions[num, 29] = new Vector2(0.65f, 0.16f); AvatarControl.s_BonePositions[num, 32] = new Vector2(0.74f, 0f); AvatarControl.s_BonePositions[num, 35] = new Vector2(0.66f, -0.14f); AvatarControl.s_BonePositions[num, 38] = new Vector2(0.45f, -0.25f); for (int i = 0; i < 5; i++) { AvatarControl.s_BonePositions[num, 25 + i * 3] = Vector2.Lerp(AvatarControl.s_BonePositions[num, 24 + i * 3], AvatarControl.s_BonePositions[num, 26 + i * 3], 0.58f); } num = 3; for (int j = 0; j < 15; j++) { AvatarControl.s_BonePositions[num, 24 + j + 15] = Vector2.Scale(AvatarControl.s_BonePositions[num - 1, 24 + j], new Vector2(-1f, 1f)); } }
public AStar(Vector2 s, Vector2 e, bool[,] a, bool c) { start = s; end = e; walls = a; cutCorners = c; int w = a.GetLength(0); int h = a.GetLength(1); gScore = new int[w, h]; hScore = new int[w, h]; fScore = new int[w, h]; cameFrom = new Vector2[w, h]; }
public LayoutDropdownWindow(SerializedObject so) { this.m_AnchorMin = so.FindProperty("m_AnchorMin"); this.m_AnchorMax = so.FindProperty("m_AnchorMax"); this.m_Position = so.FindProperty("m_Position"); this.m_SizeDelta = so.FindProperty("m_SizeDelta"); this.m_Pivot = so.FindProperty("m_Pivot"); this.m_InitValues = new Vector2[so.targetObjects.Length, 4]; for (int i = 0; i < so.targetObjects.Length; i++) { RectTransform transform = so.targetObjects[i] as RectTransform; this.m_InitValues[i, 0] = transform.anchorMin; this.m_InitValues[i, 1] = transform.anchorMax; this.m_InitValues[i, 2] = transform.anchoredPosition; this.m_InitValues[i, 3] = transform.sizeDelta; } }
private void init() { N = P.N; _h0 = new Vector2[N, N]; for (var y = 0; y < N; y++) for (var x = 0; x < N; x++) _h0[x, y] = calc(x, y); _h0Conj = new Vector2[N, N]; for (var y = 0; y < N; y++) { for (var x = 0; x < N; x++) { var h = _h0[(-x + N) % N, (-y + N) % N]; _h0Conj[x, y] = new Vector2(h.x, -h.y); } } }
public void GenerateField(int _mapWidth, int _MapHeight, int DesX, int DesY) { FeildNodes = new Node[_mapWidth, _MapHeight]; Vectors = new Vector2[_mapWidth, _MapHeight]; for (int x = 0; x < _mapWidth; x++) { for (int y = 0; y < _mapWidth; y++) { FeildNodes[x, y] = new Node(); FeildNodes[x, y].gridX = x; FeildNodes[x, y].gridY = y; } } Update(_mapWidth, _MapHeight, DesX, DesY); }
public Map() { monstre = new List<NPC>(); prev_coffre = new Coffre(new Vector2(0, 0)); tiles = new Vector2[25, 18]; objet = new Vector2[25, 18]; Coffres = new Coffre[25, 18]; for (int i = 0; i < objet.GetLength(0); i++) for (int j = 0; j < objet.GetLength(1); j++) objet[i, j] = new Vector2(15, 15); tilelist = new Tile[25, 18]; colision = new int[25, 18]; mob = new Vector2[25, 18]; iscreate = false; visited = false; message = ""; isfirst = false; }
/// <summary> /// Constructs a new perlin noise instance for filling a bitmap /// of the specified size, broken down into a smaller grid of the /// passed size. /// </summary> /// <param name="bitmapSize"> /// Size of the bitmap to generate. /// </param> /// <param name="gridSize"> /// Size of the grid imposed on the bitmap. /// </param> public PerlinNoise(int bitmapSize, int gridSize) { // Store cell size. this.gridCellSize = bitmapSize / gridSize; // Compute pseudo-random gradients. var random = new Random(); this.gradients = new Vector2[gridSize + 1,gridSize + 1]; for (int i = 0; i < gridSize + 1; i++) { for (int j = 0; j < gridSize + 1; j++) { this.gradients[i, j] = this.RandomVector(random); } } }
public Level(ContentManager Content) { currentLevel = 0; levelLoaded = false; levelRec = new List<Rectangle>(); eventRec = new List<Rectangle>(); damageRec = new List<Rectangle>(); objectRec = new List<Rectangle>(); int maxAantalLagen = 0; int maxAantalVlakken = 0; aantalLevels = Directory.GetDirectories(@"Content/Levels/").Length; aantalLagen = new int[aantalLevels]; for (int i = 0; i < aantalLevels; i++) { aantalLagen[i] = Directory.GetDirectories(@"Content/Levels/Level" + Convert.ToString(i)).Length; if (maxAantalLagen < aantalLagen[i]) { maxAantalLagen = aantalLagen[i]; } } aantalVlakken = new int[aantalLevels, maxAantalLagen]; for (int i = 0; i < aantalLevels; i++) { for (int y = 0; y < aantalLagen[i]; y++) { aantalVlakken[i, y] = Directory.GetFiles(@"Content/Levels/Level" + Convert.ToString(i) + "/" + "Laag" + Convert.ToString(y)).Length; if (maxAantalVlakken < aantalVlakken[i, y]) { maxAantalVlakken = aantalVlakken[i, y]; } } } objecten = new Texture2D[Directory.GetFiles(@"Content/Objecten").Length]; levelSegment = new Texture2D[maxAantalLagen, maxAantalVlakken]; levelSegmentPos = new Vector2[maxAantalLagen, maxAantalVlakken]; levelSegmentSpeed = new int[maxAantalLagen]; LoadLevel(Content); }
// Update is called once per frame void FixedUpdate() { if (Input.GetButtonDown("Fire1")){ Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition); RaycastHit hit; if (Physics.Raycast (ray, out hit)) { Vector3 pos = new Vector3(hit.point.x, 0.5f, hit.point.z); transform.position = pos; } } if (Input.GetButtonDown("Fire2")){ Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition); RaycastHit hit; if (Physics.Raycast (ray, out hit)) { target = hit.point; flowField = map.FloodFill(target, transform.position); } } Move(); }
public Grid(Vector2 position, int side, int squareSide) { _side = side; _squareSide = squareSide; _position = position; Objects = new GameObject[_side, _side]; _positions = new Vector2[_side, _side]; // Calculate square positions: float yPosition = _position.Y; for (int i = 0; i < _side; i++) { for (int j = 0; j < _side; j++) { _positions[i, j] = new Vector2(_squareSide * j + _position.X, yPosition); } yPosition += _squareSide; } }
public Level(ContentManager Content, SpriteBatch Sprite) { content = Content; sprite = Sprite; currentLevel = 0; levelLoaded = false; int maxAantalLagen = 0; int maxAantalVlakken = 0; aantalLevels = Directory.GetDirectories(@"Content/Levels/").Length; aantalLagen = new int[aantalLevels]; for (int i = 0; i < aantalLevels; i++) { aantalLagen[i] = Directory.GetDirectories(@"Content/Levels/Level" + Convert.ToString(i)).Length; if (maxAantalLagen < aantalLagen[i]) { maxAantalLagen = aantalLagen[i]; } } aantalVlakken = new int[aantalLevels, maxAantalLagen]; for (int i= 0; i < aantalLevels; i++) { for (int y = 0; y < aantalLagen[i]; y++) { aantalVlakken[i,y] = Directory.GetFiles(@"Content/Levels/Level" + Convert.ToString(i) + "/" + "Laag" + Convert.ToString(y)).Length; if (maxAantalVlakken < aantalVlakken[i,y]) { maxAantalVlakken = aantalVlakken[i,y]; } } } levelSegment = new Texture2D[maxAantalLagen, maxAantalVlakken]; levelSegmentPos = new Vector2[maxAantalLagen, maxAantalVlakken]; levelSegmentSpeed = new int[maxAantalLagen]; }
public bool OuvrirMap(string MapName) { try { // Read the file and display it line by line. string line; int longueur = 0; int hauteur = 0; StreamReader file = new StreamReader(SceneEngine2.Editor.baseDirectory + "Maps/" + MapName + ".txt"); // On regarde quel type de sol c'est grace au header switch (int.Parse(file.ReadLine())) { case 1: textureStart = TextureStart.Herbe; Palette = PaletteEte; break; case 2: textureStart = TextureStart.Desert; Palette = PaletteEte; break; case 3: textureStart = TextureStart.Hiver; Palette = PaletteHiver; break; case 4: textureStart = TextureStart.Volcanique; Palette = PaletteVolcanique; break; default: textureStart = TextureStart.Herbe; Palette = PaletteEte; break; } // On établit la longueur et la hauteur while ((line = file.ReadLine()) != null) { char[] splitchar = { '|' }; if (line != null) longueur = line.Split(splitchar).Length - 1; hauteur++; } // Creation de la carte Map = new Vector2[longueur, hauteur]; // Reset file.Close(); file = new StreamReader(SceneEngine2.Editor.baseDirectory + "Maps/" + MapName + ".txt"); int j = 0; file.ReadLine(); // pour passer le header while ((line = file.ReadLine()) != null) { char[] splitchar = { '|' }; string[] tiles = line.Split(splitchar); for (int i = 0; i < longueur; i++) { char[] splitchar2 = { ',' }; int x = int.Parse((tiles[i].Split(splitchar2))[0]); int y = int.Parse((tiles[i].Split(splitchar2))[1]); Map[i, j] = new Vector2(x, y); } j++; } file.Close(); return true; } catch { return false; } }
public Map(string path) { tiles = new Vector2[25, 19]; tilelist = new Tile[25, 19]; init(path); }
//---------------- // Constructor and model initialization //---------------- //Strictly speaking, this function *does* have a certain amount of code that //shouldn't really be executed repeatedly. I'll factor that out into a separate //one-time function eventually. public override void Initialize() { randomGenerator = new Random(); hero = new Player(.25f, .5f, 50f, GameConstants.BASEHEALTH); //Load up enemy positions and statuses. Also load up enemy hit rectangles. enemiesLeft = enemyProperties.XCount * enemyProperties.YCount; enemyCurrentY = 0f; enemyYMovementDirection = 1; enemyBasePositions = new Vector2[enemyProperties.XCount, enemyProperties.YCount]; enemyStates = new EnemyStates[enemyProperties.XCount, enemyProperties.YCount]; enemyXRectangles = new Rectangle[enemyProperties.XCount]; enemyYRectangles = new Rectangle[enemyProperties.YCount]; for (int i = 0; i < enemyProperties.XCount; i++) { for (int j = 0; j < enemyProperties.YCount; j++) { enemyBasePositions[i, j] = new Vector2(enemyProperties.InitialX + enemyProperties.XInterval * i, enemyProperties.InitialY + enemyProperties.YInterval * j); enemyStates[i, j] = EnemyStates.Healthy; } enemyXRectangles[i] = new Rectangle((int)(enemyProperties.InitialX + enemyProperties.XInterval * i), (int)enemyProperties.InitialY, (int)(spriteSize.X), (int)(enemyProperties.YInterval * (enemyProperties.YCount - 1) + spriteSize.Y + enemyProperties.YMovementRange)); } for (int j = 0; j < enemyProperties.YCount; j++) { enemyYRectangles[j] = new Rectangle((int)enemyProperties.InitialX, (int)(enemyProperties.InitialY + enemyProperties.YInterval * j), (int)(enemyProperties.XInterval * (enemyProperties.XCount - 1) + spriteSize.X), (int)spriteSize.Y); } //Load up player position and status. playerCurrentY = 240f - spriteSize.Y / 2; //playerState = PlayerStates.Healthy; }