// This is executed by the Unity main thread when the job is finished protected override void OnFinished() { OutData = htmap; //Debug.Log("tileCreationThread.OutData: " + OutData.GetValue(0, 0)); OutTileID = tileX.ToString() + ":" + tileZ.ToString(); OutTerrainClassification = outTerrainClassification; }
// Use this for initialization public void generate() { Terrain terrain = GetComponent<Terrain>(); if (terrain == null) return; TerrainData terrainData = terrain.terrainData; if (terrainData == null) return; int resolution = terrainData.alphamapResolution; heightArray = terrainData.GetHeights(0, 0, terrainData.heightmapWidth, terrainData.heightmapHeight); Vector3[,] normalAry = createNormalAry(resolution, resolution); //saveNormalPng(normalAry, resolution, pathNormalMap); float[,,] textureAry = new float[resolution, resolution, 5]; float[] alphas = new float[5]; for(int y = 0; y < resolution; ++y) { for(int x = 0; x < resolution; ++x) { calcAlphas(heightArray[x, y], 1 - normalAry[x, y].z, alphas); for(int i = 0; i < 5; i++) { textureAry[x, y, i] = alphas[i]; } } } terrainData.SetAlphamaps(0, 0, textureAry); }
private int[] _previous, _incomming, _outgoing; //connect with the left and right #endregion Fields #region Constructors /// <summary> /// BipartiteMatcher /// </summary> public BipartiteMatcher(string[] left, string[] right, float[ , ] cost) { if (left == null || right == null || cost == null) { _errorOccured=true; return; } _leftTokens=left; _rightTokens=right; //swap if (_leftTokens.Length > _rightTokens.Length) { float [ , ] tmpCost=new float[_rightTokens.Length , _leftTokens.Length] ; for(int i=0; i < _rightTokens.Length ; i++) for(int j=0; j < _leftTokens.Length ; j++) tmpCost[i, j]=cost[j, i]; _cost=(float[ , ]) tmpCost.Clone() ; string[] tmp=_leftTokens; _leftTokens=_rightTokens; _rightTokens=tmp; } else _cost=(float[ , ]) cost.Clone() ; MyInit(); Make_Matching(); }
/** * Reuses existing bars, if possible. */ public void RegenerateGraph() { data = new RandomDataProvider().GetData(); var isInitialised = (ingameBars != null); var hasSameDimensions = (isInitialised && ingameBars.GetLength(0) == data.GetLength(0) && ingameBars.GetLength(1) == data.GetLength(1)); if (isInitialised && hasSameDimensions) { for (int x = 0; x < data.GetLength(0); x++) { for (int y = 0; y < data.GetLength(1); y++) { var dataPoint = ingameBars[x, y].GetComponent<DataPointOld>(); if (!dataPoint) { print("Error: Attach DataPointOld script to graph prefab object!"); } else { dataPoint.TargetHeight = data[x, y]; } } } } else { GenerateGraph(); } }
void init(float self, int nvis, int nhid) { this.sig = 0.2; this.epsW = 0.5; this.epsA = 0.5; this.nvis = nvis; this.nhid = nhid; this.Ndat = 500; this.cost = 0.00001; this.moment = 0.90; this.Svis0 = new float[nvis+1]; this.Svis0[nvis] = 1.0f; this.Svis = new float[nvis+1]; this.Svis[nvis] = 1.0f; this.Shid = new float[nhid+1];//zeros( nhid+1, dtype=float32); this.W = standard_normal(nvis+1, nhid+1,10); this.dW = standard_normal(nvis+1, nhid+1,1000); this.Avis = new float[nvis+1 ] ; ones(Avis, 0.1f); this.Ahid = new float[nhid+1];// dtype=float32); ones(Ahid, 1); this.dA = new float[nvis + 1];//dtype=float32); this.dat = this.genData(); }
//float[,] gF_R_Mat = new float[m * n, u * v]; //float[,] gF_I_Mat = new float[m * n, u * v]; private void button2_Click(object sender, EventArgs e) { for (int j = 0; j <u*v; j++) { for (int i = 0; i < m*n ; i++) { gF_R = singleGaborFilter_Real(u, v, i, j); gF_I = singleGaborFilter_Imag(u, v, i, j); gF_R_one = TwoToOneFloat(gF_R); gF_I_one = TwoToOneFloat(gF_I); gF_R_Mat[ i , j ] = gF_R_one[ i ]; gF_I_Mat[ i , j ] = gF_I_one[ i ]; System.Console.WriteLine(" gF_R_Mat[" + i +"," + j + "] = " + gF_R_Mat[ i , j ] ); System.Console.WriteLine("gF_R_one[" + i + "] = " + gF_R_one[ i ] ); // Matrix<float> gF_R_Mat = new Matrix<float>(25, 12); } } Image<Gray, Byte> I = new Image<Gray, Byte>(m, n); gF_R_Mat.Convert<Byte>().CopyTo(I[0]); I.Save(@"D:\程式區\testFilter2\output.bmp"); pictureBox2.Image = Image.FromFile(@"D:\程式區\testFilter2\output.bmp"); System.Console.WriteLine(" END!!!!!!!!!!!"); //pictureBox2.Image = I.ToBitmap(); //Matrix<double> M = new Matrix<double>(m, n); //I.Bytes = gF_R_Mat; // Train_Img = Train_I.Convert<Gray,double>() ; // }
//--Public Methods public Sample(string filename) { if (PlatformHelper.FileExists(filename) == false) throw new System.IO.FileNotFoundException("Sample not found: " + Path.GetFileNameWithoutExtension(filename)); name = Path.GetFileNameWithoutExtension(filename); WaveFileReader WaveReader = new WaveFileReader(filename); IChunk[] chunks = WaveReader.ReadAllChunks(); WaveReader.Close(); //Close the reader and the underlying stream. DataChunk dChunk = null; FormatChunk fChunk = null; for (int x = 0; x < chunks.Length; x++) { if (chunks[x].GetChunkType() == WaveHelper.WaveChunkType.Format) fChunk = (FormatChunk)chunks[x]; else if (chunks[x].GetChunkType() == WaveHelper.WaveChunkType.Data) dChunk = (DataChunk)chunks[x]; } if (fChunk == null || dChunk == null) throw new ArgumentException("Wave file is in unrecognized format!"); if (fChunk.wBitsPerSample != 16) WaveHelper.ChangeBitsPerSample(fChunk, dChunk, 16); int channels = fChunk.nChannels; sampleRate = fChunk.nSamplesPerSec; originalRate = sampleRate; data = WaveHelper.GetSampleData(fChunk, dChunk); }
void Start() { tData = myTerrain.terrainData; xResolution = tData.heightmapWidth; zResolution = tData.heightmapHeight; heights = tData.GetHeights(0, 0, xResolution, zResolution); }
public ScoreDisplay(ref GameData gameData) { this.currentRound = gameData.CurrentRound; playerList = gameData.CurrentPlayerList; scoreArray = gameData.score; InitializeComponent(); }
void GenerateTexture() { switch(type) { case NoiseType.Noise: pixels = Noise(); break; case NoiseType.SmoothNoise: pixels = Noise (); float[,] tempPix = pixels; for(int x = 0; x < sizeX; x++){ for(int y = 0; y < sizeY; y++){ //to avoid blurring over blur tempPix[x,y] = SmoothNoise(x/zoom, y/zoom); } } pixels = tempPix; break; case NoiseType.Turbulence: break; case NoiseType.Marble: break; } for(int x = 0; x < sizeX; x++){ for(int y = 0; y < sizeY; y++){ Color col = Color.Lerp(color1, color2, pixels[x,y]); texture.SetPixel(x, y, col); } } texture.Apply(); }
//Adds a vertex to the matrix, which internally adds a new row and column //Fills the row and column associated with the vertex to the default float value public void AddVertex() { if (count >= capacity) { capacity *= 2; float[,] newArray = new float[capacity,capacity]; for (int i = 0; i <= array.GetUpperBound(0); i++) { for (int j = 0; j <= array.GetUpperBound(1); j++) { newArray[i, j] = array[i, j]; } } array = newArray; } count++; for (int i = 0; i < count; i++) { array[i, count - 1] = defaultValue; array[count - 1, i] = defaultValue; } }
public void serialize() { height = GetComponent<Background>().height; width = GetComponent<Background>().width; start = GetComponent<Background>().start; end = GetComponent<Background>().end; dangerMap = GetComponent<DangerMap>().getDangerMap(); var = GetComponent<DangerMap>().var; enemies = GetComponent<Enemies>().getEnemy(); trace = GetComponent<Player>().getTrace(); filteredTrace_a = GetComponent<Player>().get_filteredTrace_a(); filteredTrace_b = GetComponent<Player>().get_filteredTrace_b(); stepsize = GetComponent<Player>().stepsize; forecast_d = GetComponent<Forecast>().get_forecast_d(); angle = GetComponent<Forecast>().angle; SerialObject obj = new SerialObject(width, height, start, end, dangerMap, var, enemies, trace, filteredTrace_a, filteredTrace_b, stepsize, forecast_d, angle); string file = dir + filePrefix + "_serial.xml"; Stream stream = File.Open(file, FileMode.Create); BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, obj); stream.Close(); }
void Start() { _attrRelationsArray = DataController.instance.LoadFloatArrFromXML ("AttrRelations", 18, 18); // float result = CheckAttrRelation (Attr.Fire, Attr.Bug, Attr.Grass); // Debug.Log ("attr result " + result); // 4f }
void Start() { terr = (Terrain) GetComponent(typeof(Terrain)); terr.name = "Terrain"; Tw = terr.terrainData.heightmapWidth; Th = terr.terrainData.heightmapHeight; heightMapBackup = terr.terrainData.GetHeights(0, 0, Tw, Th); initHeightMap = terr.terrainData.GetHeights(0, 0, Tw, Th); for (int i=0; i<Tw; i++) { for (int j=0; j<Th; j++) { initHeightMap[i,j] = 0;//desiredHeight;//desiredHeight; } } Debug.Log("START TERRAIN"); terr.terrainData.SetHeights(0,0,initHeightMap); Debug.Log(terr.detailObjectDistance.ToString()); Terrain.activeTerrain.detailObjectDistance = 10000; Terrain.activeTerrain.basemapDistance = 1000; //terr.detailObjectDistance = 1000; instance = this; //generateTerrain.instance.UpdateTerrainHeight(0, 0, 8.0f); //generateTerrain.instance.UpdateTerrainHeight(128, 128, 8.0f); }
void DrawLinesAnim() { foreach(GameObject go in GameObject.FindObjectsOfType(typeof(GameObject))) { if(go.name == "line") { Destroy (go); } } c1 = new Color( 0, 1, 0, 255); c2 = c1; int xRes = tData.heightmapWidth; int yRes = tData.heightmapHeight; heights = tData.GetHeights (0, 0, xRes, yRes); DrawLines(512, terrainWidth - 512, Axis.XAxis); DrawLines(512, terrainHeight - 512, Axis.YAxis); if(changingG < 100) { changingG += 2; } else { changingG = 0; } }
public Mesh(Scene _scene) { this.scene = _scene; this.graphicsDevice = _scene.GraphicsDevice; this.mySilverlightEffect = _scene.ContentManager.Load<SilverlightEffect>("CustomEffect"); //init map for mesh mapWidth = 128; mapHeight = 128; //cache effect parameters worldViewProjectionParameter = mySilverlightEffect.Parameters["WorldViewProjection"]; worldParameter = mySilverlightEffect.Parameters["World"]; lightPositionParameter = mySilverlightEffect.Parameters["LightPosition"]; this.LightPosition = new Vector3(0, 10, 0); //init vertices/indices vertices = new VertexPositionNormalTexture[mapWidth * mapHeight]; indices = new ushort[(mapWidth - 1) * (mapHeight - 1) * 6]; Canvas _canvas = new Canvas(); _canvas.Width = _canvas.Height = 128; _canvas.Background = new SolidColorBrush(Colors.Blue); WriteableBitmap _map = new WriteableBitmap(_canvas, null); heightData = LoadHeightDataFromMap(_map); texture = new Texture2D(graphicsDevice, _map.PixelWidth, _map.PixelHeight); texture.SetData(_map.Pixels); // SetupVertices(); SetupIndices(); CalculateNormals(); }
//--Public Methods public Sample(string filename) { //UnitySynth - remove non Unity file path check //if (System.IO.File.Exists(filename) == false) // throw new System.IO.FileNotFoundException("Sample not found: " + Path.GetFileNameWithoutExtension(filename)); name = Path.GetFileNameWithoutExtension(filename); if (CSharpSynth.Unity.EditorConfiguration.DEBUG_SAMPLE_LOAD_VERBOSE) Debug.Log("filename: " + filename + " name " + name); WaveFileReader WaveReader = new WaveFileReader(filename); IChunk[] chunks = WaveReader.ReadAllChunks(); WaveReader.Close(); //Close the reader and the underlying stream. DataChunk dChunk = null; FormatChunk fChunk = null; for (int x = 0; x < chunks.Length; x++) { if (chunks[x].GetChunkType() == WaveHelper.WaveChunkType.Format) fChunk = (FormatChunk)chunks[x]; else if (chunks[x].GetChunkType() == WaveHelper.WaveChunkType.Data) dChunk = (DataChunk)chunks[x]; } if (fChunk == null || dChunk == null) throw new ArgumentException("Wave file is in unrecognized format!"); if (fChunk.wBitsPerSample != 16) WaveHelper.ChangeBitsPerSample(fChunk, dChunk, 16); //currently unused: //int channels = fChunk.nChannels; sampleRate = fChunk.nSamplesPerSec; originalRate = sampleRate; data = WaveHelper.GetSampleData(fChunk, dChunk); }
public TerrainData(uint positionX, uint positionY) { this.positionX = positionX; this.positionY = positionY; heightData = TerrainData.GetDefaultHeightData(); patch_flag = new bool[PATCH_MAX]; }
public VoxelVolumeData(SerializationInfo info, StreamingContext ctxt) { data = (byte[])info.GetValue("data", typeof(byte[])); colors = (float[,])info.GetValue("colors", typeof(float[,])); dimensions = (ushort[])info.GetValue("dimensions", typeof(ushort[])); voxelScale = (float)info.GetValue("voxelScale", typeof(float)); centerOffset = (int[])info.GetValue("centerOffset", typeof(int[])); }
/// <summary> /// Constructs a new matrix as a clone of an existing matrix. /// </summary> /// <param name="matrix">The source matrix to clone.</param> /// <exception cref="ArgumentNullException">Thrown if the supplied matrix is null.</exception> public Matrix(Matrix matrix) { Platform.CheckForNullReference(matrix, "matrix"); _rows = matrix._rows; _columns = matrix._columns; _matrix = (float[,])matrix._matrix.Clone(); }
private void GenerateRawNoise() { _worldNoise = new WorldNoiseGenerator(Random.Range(1, 65536)); _currentNoise = _worldNoise.GenerateRawNoise(Width, Height); _currentTexture = GenerateTexture(Width, Height, _currentNoise); Canvas.GetComponent<Renderer>().material.mainTexture = _currentTexture; }
public Control(Texture2D _texture, QuadTree quad) { this.texture = _texture; this.heights = quad.Vertices.heightData; double a = Math.Sqrt(heights.Length); this.width = (int)a; this.length = (int)a; }
public void DoSomething() { imported_model = ReadPointCloudFile.stored_point_cloud; for (int i = 0; i < 100; i++) { Debug.Log(imported_model[i, 2]); } }
public void Awake() { waterScript = (WaterToolScript)target as WaterToolScript; terComponent = (Terrain) waterScript.GetComponent(typeof(Terrain)); if(terComponent == null) Debug.LogError("This script must be attached to a terrain object - Null reference will be thrown"); terData = terComponent.terrainData; terrainHeights = terData.GetHeights(0, 0, terData.heightmapResolution, terData.heightmapResolution); }
void Update() { if (shouldBeIterating && !this.GetComponent<MakeTerrainBlocks>().GetShouldIterate()){ newHeightMap = this.GetComponent<MakeTerrainBlocks>().GetPoints(); terr.terrainData.SetHeights(0, 0, newHeightMap); terr.Flush(); shouldBeIterating = false; } }
public CloudLayer(int octave, int ttl, int width, int height, int seed) { this.octave = octave; this.ttl = ttl; this.width = width; this.height = height; upperBoundMap = GenerateNoiseMap(); rand = new Random(seed); }
// Use this for initialization void Start() { hmWidth = terr.terrainData.heightmapWidth; hmHeight = terr.terrainData.heightmapHeight; if (Debug.isDebugBuild) { heightMapBackup = terr.terrainData.GetHeights(0, 0, hmWidth, hmHeight); alphaMapBackup = terr.terrainData.GetAlphamaps(0, 0, alphaMapWidth, alphaMapHeight); } }
public void SetUp() { _gpu = CudafyHost.CreateDevice(CudafyModes.Target); _blas = GPGPUBLAS.Create(_gpu); _hostInput = new float[ciROWS, ciCOLS]; _hostInput2 = new float[ciROWS, ciCOLS]; _hostOutput = new float[ciROWS, ciCOLS]; _devPtr = _gpu.Allocate<float>(_hostInput); _devPtr2 = _gpu.Allocate<float>(_hostOutput); }
// Use this for initialization void Start () { //fishes.Initialize (new Vector3 (1000, -2, 1000), 10); //int fishCount = 5; int fishCount = 0; int goatCount = 0; int birdCount = 0; hm = gen.heightMap; step = gen.step; int meshSide = gen.meshSideLength; int featureSize = gen.featureSize; // positio in world space veector3 ( x * step, hm[x,z], z*step) //goats for (int x = 0; x < meshSide; x++) { for (int z = 0; z < meshSide; z++) { if(hm[x, z] >= 10f && Random.value < 0.01 && goatCount<=nbGoats) { //spawn goats Goat g = (Goat) (Instantiate (goat)) as Goat; g.transform.position = new Vector3 (x*step, hm[x, z]+2f, z*step); goatCount++; } } } //fishes while (fishCount <= nbFishSchools) { int x = Random.Range(0, meshSide); int z = Random.Range(0, meshSide); if(hm[x, z] < 0f) { //spawn fishes fishes.Initialize (new Vector3 (x*step, -2, z*step), 5); fishCount++; } } //birds for (int x = 0; x < meshSide; x += featureSize) { for (int z = 0; z < meshSide; z += featureSize) { if(hm[x, z] > step && Random.value < 0.4 && birdCount<=nbFlocks) { //spawn birds birds.Initialize (new Vector3 (x*step, hm[x,z] + 10f, z*step), 4); birdCount++; } } } }
public void StartRecognition(RangeImage rangeImage) { rangeData = rangeImage; height = rangeImage.Height; width = rangeImage.Width; bm = new Bitmap(width, height); g = Graphics.FromImage(bm); image.BackgroundImage = bm; image.BackgroundImageLayout = ImageLayout.None; image.Size = new Size(width, height); g.Clear(Color.White); SphereRecognition sr = new SphereRecognition(); //System.Windows.Forms.MessageBox.Show("W/H = " + width + "/" + height); image.Bounds = new Rectangle(0, 0, width, height); paintImage(); edges = sr.detectEdges(rangeData, float.Parse(conf1.Text)); //doFix(); /**/ paintEdges(); List<Sphere> spheres = sr.FindSpheres(rangeData, edges, int.Parse(maxRadius.Text), int.Parse(minRadius.Text), float.Parse(conf1.Text), float.Parse(conf2.Text)); Sphere actual; for (int i = 0; i < spheres.Count; i++) { actual = spheres[i]; //int tmp = actual.center.X; actual.center.Y = height - actual.center.Y; //actual.center.Y = tmp; //actual.center.X += (int)(actual.radius*1.35f); g.DrawEllipse(Pens.Blue, (int)actual.center.X - actual.radius, ((int)actual.center.Y - actual.radius), (int)actual.radius * 2, (int)actual.radius * 2); g.DrawLine(Pens.Blue, (actual.center.X - 1), (actual.center.Y - 1) - 5, (actual.center.X - 1), (actual.center.Y - 1) + 5); g.DrawLine(Pens.Blue, (actual.center.X - 1) - 5, (actual.center.Y - 1), (actual.center.X - 1) + 5, (actual.center.Y - 1)); image.Refresh(); //g.DrawEllipse(Pens.Blue, (int)actual.center.Y - actual.radius, ((int)actual.center.X - actual.radius), (int)actual.radius * 2, (int)actual.radius * 2); //g.DrawLine(Pens.Blue, (actual.center.Y - 1), (actual.center.X - 1) - 5, (actual.center.Y - 1), (actual.center.X - 1) + 5); //g.DrawLine(Pens.Blue, (actual.center.Y - 1) - 5, (actual.center.X - 1), (actual.center.Y - 1) + 5, (actual.center.X - 1)); float formula2 = ((17f / 9 * (float)actual.radius) - 94f / 9f) / 1000f; String algo = "haha " + actual.radius * (Math.Cos(89.9 * (Math.PI / 180)) * actual.avgDistance) + "\n" + (actual.midPoints - actual.avgDistance) + "\n" + Math.Abs(actual.midPoints - actual.avgDistance) + "\n" + formula2 + "\n" + (Math.Abs(actual.midPoints - actual.avgDistance) - formula2); //System.Windows.Forms.MessageBox.Show("ABSOLUTE=\nX="+actual.absolutePosition.X+"\nY="+actual.absolutePosition.Y+"\nZ="+actual.absolutePosition.Z+"\n\nx=" + actual.center.X + "\ny=" + actual.center.Y + "\n\nR=" + actual.radius + "\nDiffC=" + actual.diffCircumference + "\nS=" + actual.score + "\nAVGD=" + actual.avgDistance + "\nAVGM=" + actual.midPoints + "\nAVGE=" + actual.avgEdges + "\n\n\n" + algo); //paintImage(); //paintEdges(); } /**/ }
public Matrix(int rows, int cols) { this.rows = rows; this.cols = cols; data = new float[rows, cols]; }
/// <summary> /// Process the image filter. /// </summary> /// protected override void ProcessFilter(UnmanagedImage sourceData, UnmanagedImage destinationData) { // Locks the overlay image BitmapData overlayData = overlayImage.LockBits( new Rectangle(0, 0, overlayImage.Width, overlayImage.Height), ImageLockMode.ReadOnly, overlayImage.PixelFormat); // get source image size int width = sourceData.Width; int height = sourceData.Height; // get destination image size int newWidth = destinationData.Width; int newHeight = destinationData.Height; int srcPixelSize = System.Drawing.Image.GetPixelFormatSize(sourceData.PixelFormat) / 8; int orgPixelSize = System.Drawing.Image.GetPixelFormatSize(overlayData.PixelFormat) / 8; int srcStride = sourceData.Stride; int dstOffset = destinationData.Stride - newWidth * 4; // destination always 32bpp argb // Get center of first image Point center1 = new Point((int)(overlayImage.Width / 2f), (int)(overlayImage.Height / 2f)); // Get center of second image Point center2 = this.center; // Compute maximum center distances float dmax1 = Math.Min( distance(center1.X, center1.Y, center2.X - imageSize.Width / 2f, center1.Y), distance(center1.X, center1.Y, center1.X, center1.Y + overlayImage.Height / 2f)); float dmax2 = Math.Min( distance(center2.X, center2.Y, center2.X + imageSize.Width / 2f, center2.Y), distance(center2.X, center2.Y, center2.X, center2.Y + imageSize.Height / 2f)); float dmax = -System.Math.Abs(dmax2 - dmax1); // fill values byte fillR = fillColor.R; byte fillG = fillColor.G; byte fillB = fillColor.B; byte fillA = 0;//fillColor.A; // Retrieve homography matrix as float array float[,] H = (float[, ])homography; // do the job unsafe { byte *org = (byte *)overlayData.Scan0.ToPointer(); byte *src = (byte *)sourceData.ImageData.ToPointer(); byte *dst = (byte *)destinationData.ImageData.ToPointer(); // destination pixel's coordinate relative to image center double cx, cy; // destination pixel's homogenous coordinate double hx, hy, hw; // source pixel's coordinates int ox, oy; // Copy the overlay image for (int y = 0; y < newHeight; y++) { for (int x = 0; x < newWidth; x++, dst += 4) { ox = (int)(x + offset.X); oy = (int)(y + offset.Y); // validate source pixel's coordinates if ((ox < 0) || (oy < 0) || (ox >= overlayData.Width) || (oy >= overlayData.Height)) { // fill destination image with filler dst[0] = fillB; dst[1] = fillG; dst[2] = fillR; dst[3] = fillA; } else { int c = oy * overlayData.Stride + ox * orgPixelSize; // fill destination image with pixel from original image if (orgPixelSize == 3) { // 24 bpp dst[0] = org[c + 0]; dst[1] = org[c + 1]; dst[2] = org[c + 2]; dst[3] = (byte)255; } else if (orgPixelSize == 4) { // 32 bpp dst[0] = org[c + 0]; dst[1] = org[c + 1]; dst[2] = org[c + 2]; dst[3] = org[c + 3]; } else { // 8 bpp dst[0] = org[c]; dst[1] = org[c]; dst[2] = org[c]; dst[3] = org[c]; } } } dst += dstOffset; } org = (byte *)overlayData.Scan0.ToPointer(); src = (byte *)sourceData.ImageData.ToPointer(); dst = (byte *)destinationData.ImageData.ToPointer(); // Project and blend the second image for (int y = 0; y < newHeight; y++) { for (int x = 0; x < newWidth; x++, dst += 4) { cx = x + offset.X; cy = y + offset.Y; // projection using homogenous coordinates hw = (H[2, 0] * cx + H[2, 1] * cy + H[2, 2]); hx = (H[0, 0] * cx + H[0, 1] * cy + H[0, 2]) / hw; hy = (H[1, 0] * cx + H[1, 1] * cy + H[1, 2]) / hw; // coordinate of the nearest point ox = (int)(hx); oy = (int)(hy); // validate source pixel's coordinates if ((ox >= 0) && (oy >= 0) && (ox < width) && (oy < height)) { int c = oy * srcStride + ox * srcPixelSize; // fill destination image with pixel from source image if (srcPixelSize == 4 && src[c + 3] == 0) { // source pixel is fully transparent, nothing to copy } else if (dst[3] > 0) { float f1 = 0.5f, f2 = 0.5f; if (Gradient) { // there is a pixel from the other image here, blend float d1 = distance(x, y, center1.X, center1.Y); float d2 = distance(x, y, center2.X, center2.Y); f1 = Vector.Scale(d1 - d2, 0, dmax, 0, 1); if (f1 < 0) { f1 = 0f; } if (f1 > 1) { f1 = 1f; } f2 = (1f - f1); } if (!AlphaOnly) { if (srcPixelSize == 3) { // 24 bpp dst[0] = (byte)(src[c + 0] * f2 + dst[0] * f1); dst[1] = (byte)(src[c + 1] * f2 + dst[1] * f1); dst[2] = (byte)(src[c + 2] * f2 + dst[2] * f1); dst[3] = (byte)255; } else if (srcPixelSize == 4) { // 32 bpp dst[0] = (byte)(src[c + 0] * f2 + dst[0] * f1); dst[1] = (byte)(src[c + 1] * f2 + dst[1] * f1); dst[2] = (byte)(src[c + 2] * f2 + dst[2] * f1); dst[3] = (byte)(src[c + 3] * f2 + dst[3] * f1); } else { // 8 bpp dst[0] = (byte)(src[c] * f2 + dst[0] * f1); dst[1] = (byte)(src[c] * f2 + dst[1] * f1); dst[2] = (byte)(src[c] * f2 + dst[2] * f1); dst[3] = (byte)255; } } else { if (srcPixelSize == 3) { // 24 bpp dst[0] = (byte)(src[c + 0]); dst[1] = (byte)(src[c + 1]); dst[2] = (byte)(src[c + 2]); } else if (srcPixelSize == 4) { // 32 bpp dst[0] = (byte)(src[c + 0]); dst[1] = (byte)(src[c + 1]); dst[2] = (byte)(src[c + 2]); } else { // 8 bpp dst[0] = (byte)(src[c]); dst[1] = (byte)(src[c]); dst[2] = (byte)(src[c]); } } } else { // just copy the source into the destination image if (srcPixelSize == 3) { // 24bpp dst[0] = src[c + 0]; dst[1] = src[c + 1]; dst[2] = src[c + 2]; dst[3] = (byte)255; } else if (srcPixelSize == 4) { // 32bpp dst[0] = src[c + 0]; dst[1] = src[c + 1]; dst[2] = src[c + 2]; dst[3] = src[c + 3]; } else { // 8bpp dst[0] = src[c]; dst[1] = src[c]; dst[2] = src[c]; dst[3] = 0; } } } } dst += dstOffset; } } overlayImage.UnlockBits(overlayData); }
/// <summary> /// Builds a composited terrain texture given the region texture /// and heightmap settings /// </summary> /// <param name="instance">Radegast Instance</param> /// <param name="heightmap">Terrain heightmap</param> /// <param name="textureIDs"></param> /// <param name="startHeights"></param> /// <param name="heightRanges"></param> /// <returns>A composited 256x256 RGB texture ready for rendering</returns> /// <remarks>Based on the algorithm described at http://opensimulator.org/wiki/Terrain_Splatting /// </remarks> public static Bitmap Splat(RadegastInstance instance, float[,] heightmap, UUID[] textureIDs, float[] startHeights, float[] heightRanges) { Debug.Assert(textureIDs.Length == 4); Debug.Assert(startHeights.Length == 4); Debug.Assert(heightRanges.Length == 4); int outputSize = 2048; Bitmap[] detailTexture = new Bitmap[4]; // Swap empty terrain textureIDs with default IDs for (int i = 0; i < textureIDs.Length; i++) { if (textureIDs[i] == UUID.Zero) { textureIDs[i] = DEFAULT_TERRAIN_DETAIL[i]; } } #region Texture Fetching for (int i = 0; i < 4; i++) { AutoResetEvent textureDone = new AutoResetEvent(false); UUID textureID = textureIDs[i]; instance.Client.Assets.RequestImage(textureID, TextureDownloadCallback(detailTexture, i, textureDone)); textureDone.WaitOne(60 * 1000, false); } #endregion Texture Fetching // Fill in any missing textures with a solid color for (int i = 0; i < 4; i++) { if (detailTexture[i] == null) { // Create a solid color texture for this layer detailTexture[i] = new Bitmap(outputSize, outputSize, PixelFormat.Format24bppRgb); using (Graphics gfx = Graphics.FromImage(detailTexture[i])) { using (SolidBrush brush = new SolidBrush(DEFAULT_TERRAIN_COLOR[i])) gfx.FillRectangle(brush, 0, 0, outputSize, outputSize); } } else if (detailTexture[i].Width != outputSize || detailTexture[i].Height != outputSize) { detailTexture[i] = ResizeBitmap(detailTexture[i], 256, 256); } } #region Layer Map int diff = heightmap.GetLength(0) / RegionSize; float[] layermap = new float[RegionSize * RegionSize]; for (int y = 0; y < heightmap.GetLength(0); y += diff) { for (int x = 0; x < heightmap.GetLength(1); x += diff) { int newX = x / diff; int newY = y / diff; float height = heightmap[newX, newY]; float pctX = (float)newX / 255f; float pctY = (float)newY / 255f; // Use bilinear interpolation between the four corners of start height and // height range to select the current values at this position float startHeight = ImageUtils.Bilinear( startHeights[0], startHeights[2], startHeights[1], startHeights[3], pctX, pctY); startHeight = Utils.Clamp(startHeight, 0f, 255f); float heightRange = ImageUtils.Bilinear( heightRanges[0], heightRanges[2], heightRanges[1], heightRanges[3], pctX, pctY); heightRange = Utils.Clamp(heightRange, 0f, 255f); // Generate two frequencies of perlin noise based on our global position // The magic values were taken from http://opensimulator.org/wiki/Terrain_Splatting Vector3 vec = new Vector3 ( newX * 0.20319f, newY * 0.20319f, height * 0.25f ); float lowFreq = Perlin.noise2(vec.X * 0.222222f, vec.Y * 0.222222f) * 6.5f; float highFreq = Perlin.turbulence2(vec.X, vec.Y, 2f) * 2.25f; float noise = (lowFreq + highFreq) * 2f; // Combine the current height, generated noise, start height, and height range parameters, then scale all of it float layer = ((height + noise - startHeight) / heightRange) * 4f; if (Single.IsNaN(layer)) { layer = 0f; } layermap[newY * RegionSize + newX] = Utils.Clamp(layer, 0f, 3f); } } #endregion Layer Map #region Texture Compositing Bitmap output = new Bitmap(outputSize, outputSize, PixelFormat.Format24bppRgb); BitmapData outputData = output.LockBits(new Rectangle(0, 0, outputSize, outputSize), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb); unsafe { // Get handles to all of the texture data arrays BitmapData[] datas = new BitmapData[] { detailTexture[0].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[0].PixelFormat), detailTexture[1].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[1].PixelFormat), detailTexture[2].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[2].PixelFormat), detailTexture[3].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[3].PixelFormat) }; int[] comps = new int[] { (datas[0].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3, (datas[1].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3, (datas[2].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3, (datas[3].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3 }; int[] strides = new int[] { datas[0].Stride, datas[1].Stride, datas[2].Stride, datas[3].Stride }; IntPtr[] scans = new IntPtr[] { datas[0].Scan0, datas[1].Scan0, datas[2].Scan0, datas[3].Scan0 }; int ratio = outputSize / RegionSize; for (int y = 0; y < outputSize; y++) { for (int x = 0; x < outputSize; x++) { float layer = layermap[(y / ratio) * RegionSize + x / ratio]; float layerx = layermap[(y / ratio) * RegionSize + Math.Min(outputSize - 1, (x + 1)) / ratio]; float layerxx = layermap[(y / ratio) * RegionSize + Math.Max(0, (x - 1)) / ratio]; float layery = layermap[Math.Min(outputSize - 1, (y + 1)) / ratio * RegionSize + x / ratio]; float layeryy = layermap[(Math.Max(0, (y - 1)) / ratio) * RegionSize + x / ratio]; // Select two textures int l0 = (int)Math.Floor(layer); int l1 = Math.Min(l0 + 1, 3); byte *ptrA = (byte *)scans[l0] + (y % 256) * strides[l0] + (x % 256) * comps[l0]; byte *ptrB = (byte *)scans[l1] + (y % 256) * strides[l1] + (x % 256) * comps[l1]; byte *ptrO = (byte *)outputData.Scan0 + y * outputData.Stride + x * 3; float aB = *(ptrA + 0); float aG = *(ptrA + 1); float aR = *(ptrA + 2); int lX = (int)Math.Floor(layerx); byte *ptrX = (byte *)scans[lX] + (y % 256) * strides[lX] + (x % 256) * comps[lX]; int lXX = (int)Math.Floor(layerxx); byte *ptrXX = (byte *)scans[lXX] + (y % 256) * strides[lXX] + (x % 256) * comps[lXX]; int lY = (int)Math.Floor(layery); byte *ptrY = (byte *)scans[lY] + (y % 256) * strides[lY] + (x % 256) * comps[lY]; int lYY = (int)Math.Floor(layeryy); byte *ptrYY = (byte *)scans[lYY] + (y % 256) * strides[lYY] + (x % 256) * comps[lYY]; float bB = *(ptrB + 0); float bG = *(ptrB + 1); float bR = *(ptrB + 2); float layerDiff = layer - l0; float xlayerDiff = layerx - layer; float xxlayerDiff = layerxx - layer; float ylayerDiff = layery - layer; float yylayerDiff = layeryy - layer; // Interpolate between the two selected textures *(ptrO + 0) = (byte)Math.Floor(aB + layerDiff * (bB - aB) + xlayerDiff * (*ptrX - aB) + xxlayerDiff * (*(ptrXX) - aB) + ylayerDiff * (*ptrY - aB) + yylayerDiff * (*(ptrYY) - aB)); *(ptrO + 1) = (byte)Math.Floor(aG + layerDiff * (bG - aG) + xlayerDiff * (*(ptrX + 1) - aG) + xxlayerDiff * (*(ptrXX + 1) - aG) + ylayerDiff * (*(ptrY + 1) - aG) + yylayerDiff * (*(ptrYY + 1) - aG)); *(ptrO + 2) = (byte)Math.Floor(aR + layerDiff * (bR - aR) + xlayerDiff * (*(ptrX + 2) - aR) + xxlayerDiff * (*(ptrXX + 2) - aR) + ylayerDiff * (*(ptrY + 2) - aR) + yylayerDiff * (*(ptrYY + 2) - aR)); } } for (int i = 0; i < 4; i++) { detailTexture[i].UnlockBits(datas[i]); detailTexture[i].Dispose(); } } layermap = null; output.UnlockBits(outputData); output.RotateFlip(RotateFlipType.Rotate270FlipNone); #endregion Texture Compositing return(output); }
public static void SetAllHeights(float[,] newHeights) { SetHeights(0, 0, newHeights, false); }
void Export() { string fileName = EditorUtility.SaveFilePanel("Export .obj file", "", "Terrain", "obj"); int w = terrain.heightmapResolution; int h = terrain.heightmapResolution; Vector3 meshScale = terrain.size; int tRes = (int)Mathf.Pow(2, (int)saveResolution); meshScale = new Vector3(meshScale.x / (w - 1) * tRes, meshScale.y, meshScale.z / (h - 1) * tRes); Vector2 uvScale = new Vector2(1.0f / (w - 1), 1.0f / (h - 1)); float[,] tData = terrain.GetHeights(0, 0, w, h); w = (w - 1) / tRes + 1; h = (h - 1) / tRes + 1; Vector3[] tVertices = new Vector3[w * h]; Vector2[] tUV = new Vector2[w * h]; int[] tPolys; if (saveFormat == SaveFormat.Triangles) { tPolys = new int[(w - 1) * (h - 1) * 6]; } else { tPolys = new int[(w - 1) * (h - 1) * 4]; } // Build vertices and UVs for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { tVertices[y * w + x] = Vector3.Scale(meshScale, new Vector3(-y, tData[x * tRes, y * tRes], x)) + terrainPos; tUV[y * w + x] = Vector2.Scale(new Vector2(x * tRes, y * tRes), uvScale); } } int index = 0; if (saveFormat == SaveFormat.Triangles) { // Build triangle indices: 3 indices into vertex array for each triangle for (int y = 0; y < h - 1; y++) { for (int x = 0; x < w - 1; x++) { // For each grid cell output two triangles tPolys[index++] = (y * w) + x; tPolys[index++] = ((y + 1) * w) + x; tPolys[index++] = (y * w) + x + 1; tPolys[index++] = ((y + 1) * w) + x; tPolys[index++] = ((y + 1) * w) + x + 1; tPolys[index++] = (y * w) + x + 1; } } } else { // Build quad indices: 4 indices into vertex array for each quad for (int y = 0; y < h - 1; y++) { for (int x = 0; x < w - 1; x++) { // For each grid cell output one quad tPolys[index++] = (y * w) + x; tPolys[index++] = ((y + 1) * w) + x; tPolys[index++] = ((y + 1) * w) + x + 1; tPolys[index++] = (y * w) + x + 1; } } } // Export to .obj StreamWriter sw = new StreamWriter(fileName); try { sw.WriteLine("# Unity terrain OBJ File"); // Write vertices System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); counter = tCount = 0; totalCount = (tVertices.Length * 2 + (saveFormat == SaveFormat.Triangles ? tPolys.Length / 3 : tPolys.Length / 4)) / progressUpdateInterval; for (int i = 0; i < tVertices.Length; i++) { UpdateProgress(); StringBuilder sb = new StringBuilder("v ", 20); // StringBuilder stuff is done this way because it's faster than using the "{0} {1} {2}"etc. format // Which is important when you're exporting huge terrains. sb.Append(tVertices[i].x.ToString()).Append(" "). Append(tVertices[i].y.ToString()).Append(" "). Append(tVertices[i].z.ToString()); sw.WriteLine(sb); } // Write UVs for (int i = 0; i < tUV.Length; i++) { UpdateProgress(); StringBuilder sb = new StringBuilder("vt ", 22); sb.Append(tUV[i].x.ToString()).Append(" "). Append(tUV[i].y.ToString()); sw.WriteLine(sb); } if (saveFormat == SaveFormat.Triangles) { // Write triangles for (int i = 0; i < tPolys.Length; i += 3) { UpdateProgress(); StringBuilder sb = new StringBuilder("f ", 43); sb.Append(tPolys[i] + 1).Append("/").Append(tPolys[i] + 1).Append(" "). Append(tPolys[i + 1] + 1).Append("/").Append(tPolys[i + 1] + 1).Append(" "). Append(tPolys[i + 2] + 1).Append("/").Append(tPolys[i + 2] + 1); sw.WriteLine(sb); } } else { // Write quads for (int i = 0; i < tPolys.Length; i += 4) { UpdateProgress(); StringBuilder sb = new StringBuilder("f ", 57); sb.Append(tPolys[i] + 1).Append("/").Append(tPolys[i] + 1).Append(" "). Append(tPolys[i + 1] + 1).Append("/").Append(tPolys[i + 1] + 1).Append(" "). Append(tPolys[i + 2] + 1).Append("/").Append(tPolys[i + 2] + 1).Append(" "). Append(tPolys[i + 3] + 1).Append("/").Append(tPolys[i + 3] + 1); sw.WriteLine(sb); } } } catch (Exception err) { Debug.Log("Error saving file: " + err.Message); } sw.Close(); terrain = null; EditorUtility.DisplayProgressBar("Saving file to disc.", "This might take a while...", 1f); EditorWindow.GetWindow <ExportTerrain>().Close(); EditorUtility.ClearProgressBar(); }
public void GenerateMap() { float[,] noiseMap = Noise.GenNoiseMap(mapWidth, mapHeight, seed, noiseScale, octaves, persistance, lacunarity); BorderMap(); Color[] colorMap = new Color[mapWidth * mapHeight]; for (int y = 0; y < mapHeight; y++) { for (int x = 0; x < mapWidth; x++) { if (borderStyle == BorderStyle.IsleMap) { noiseMap[x, y] = Mathf.Clamp01(noiseMap[x, y] - borderMap[x, y]); } else if (borderStyle == BorderStyle.ClosedMap) { noiseMap[x, y] = Mathf.Clamp01(noiseMap[x, y] + borderMap[x, y]); } float currentHeight = noiseMap[x, y]; for (int i = 0; i < regions.Length; i++) { if (currentHeight <= regions[i].height) { colorMap[y * mapWidth + x] = regions[i].color; break; } } } } MapDisplay display = FindObjectOfType <MapDisplay>(); if (drawMode == DrawMode.NoiseMap) { display.DrawTexture(TextureGenerator.TextureFromHeightMap(noiseMap)); } else if (drawMode == DrawMode.ColorMap) { display.DrawTexture(TextureGenerator.TextureFromColorMap(colorMap, mapWidth, mapHeight)); } else if (drawMode == DrawMode.Mesh) { display.DrawMesh(MashGenerator.GenerateTerrainMesh(noiseMap, meshGeightMultiplier, meshHeightCurve), TextureGenerator.TextureFromColorMap(colorMap, mapWidth, mapHeight)); } else if (drawMode == DrawMode.IsleMap) { display.DrawTexture(TextureGenerator.TextureFromHeightMap(IslMapGenerator.GenerateIslMap(mapWidth, mapHeight))); } else if (drawMode == DrawMode.ClosedMap) { display.DrawTexture(TextureGenerator.TextureFromHeightMap(IslMapGenerator.GenerateIslMap(mapWidth, mapHeight))); } #region Check (Проверка на входящие данные) if (mapWidth < 1) { mapWidth = 1; } if (mapHeight < 1) { mapHeight = 1; } if (lacunarity < 1) { lacunarity = 1; } if (octaves < 0) { octaves = 0; } if (noiseScale < 1) { noiseScale = 1; } if (seed < 0) { seed = 0; } #endregion Validate }
private extern void Internal_GetInterpolatedHeights(float[,] results, int resultXDimension, int resultXOffset, int resultYOffset, float xBase, float yBase, int xCount, int yCount, float xInterval, float yInterval);
void PaintSegment(TerrainPaintPoint fromPoint, TerrainPaintPoint toPoint, ref float[,] layer, ref float[,] alphaLayer, bool writeAlpha = true, bool overWriteHeight = true) { //Flip the points if the forward one has a bigger radius so the lerp can work well if (Vector2.Distance(fromPoint.leftPoint.vector, fromPoint.rightPoint.vector) < Vector2.Distance(toPoint.leftPoint.vector, toPoint.rightPoint.vector)) { TerrainPaintPoint temp = fromPoint; fromPoint = toPoint; toPoint = temp; } List <Point> drawn = new List <Point>(); Vector2 currentPosition = fromPoint.leftPoint.vector; Vector2 fromRight = fromPoint.rightPoint.vector; float alphaStartPercent = 0f; float alphaEndPercent = 1f; if (feather > 0) { currentPosition += (fromPoint.leftPoint.vector - fromPoint.center.vector).normalized * feather * 4f; fromRight += (fromPoint.rightPoint.vector - fromPoint.center.vector).normalized * feather * 4f; float span = (fromPoint.leftPoint.vector - fromPoint.rightPoint.vector).magnitude / (fromRight - currentPosition).magnitude; float rest = (1f - span) / 2f; alphaStartPercent = rest; alphaEndPercent = 1f - rest; } float armLength = Vector2.Distance(currentPosition, fromRight); if (armLength < 1f) { return; } while (true) { float armDistance = Vector2.Distance(currentPosition, fromRight); float armPercent = 1f - armDistance / armLength; //This can be optimized, take it outside of the cycle Point fromPos = new Point(currentPosition); Vector2 leftvector = toPoint.leftPoint.vector; Vector2 rightVector = toPoint.rightPoint.vector; if (feather > 0) { leftvector += (toPoint.leftPoint.vector - toPoint.center.vector).normalized * feather * 4f; rightVector += (toPoint.rightPoint.vector - toPoint.center.vector).normalized * feather * 4f; } Vector2 toArm = Vector2.Lerp(leftvector, rightVector, armPercent); Point toPos = new Point(toArm); int dx = Mathf.Abs(toPos.x - fromPos.x), sx = fromPos.x < toPos.x ? 1 : -1; int dy = -Mathf.Abs(toPos.y - fromPos.y), sy = fromPos.y < toPos.y ? 1 : -1; int err = dx + dy, e2; Point current = fromPos; Vector2 target = new Vector2(toPos.x - fromPos.x, toPos.y - fromPos.y); float fromHeight = fromPoint.GetHeight(armPercent); float toHeight = toPoint.GetHeight(armPercent); while (true) { if (current.x >= 0 && current.x < layer.GetLength(0) && current.y >= 0 && current.y < layer.GetLength(1)) { if (overWriteHeight || layer[current.x, current.y] == 0f) { if (!ContainsPoint(ref drawn, current)) { Vector2 currentDist = new Vector2(current.x - fromPos.x, current.y - fromPos.y); float positionPercent = Mathf.Clamp01(currentDist.magnitude / target.magnitude); float height = Mathf.Lerp(fromHeight, toHeight, positionPercent); float alphaValue = 0f; if (armPercent >= alphaStartPercent && armPercent <= alphaEndPercent) { alphaValue = 1f; } if (writeAlpha) { Plot(current.x, current.y, height, alphaValue, ref alphaLayer, ref layer); } else { Plot(current.x, current.y, height, alphaLayer[current.x, current.y], ref alphaLayer, ref layer); } drawn.Add(current); } } } if (current.x == toPos.x && current.y == toPos.y) { break; } e2 = 2 * err; if (e2 > dy) { err += dy; current.x += sx; } else if (e2 < dx) { err += dx; current.y += sy; } } if (currentPosition == fromRight) { break; } currentPosition = Vector2.MoveTowards(currentPosition, fromRight, 1f); } }
public void RequestMesh(float[,] values, MeshSettings meshSettings) { hasRequestedMesh = true; ThreadedDataRequester.RequestData(() => MeshGenerator.GenerateTerrainMesh(values, meshSettings, lod), OnMeshDataReceived); }
extern private void Internal_SetHeightsDelayLOD(int xBase, int yBase, int width, int height, float[,] heights);
public void updateStick() { int sticklive, k, s, t, u, supStick, crowdNum, onlyNum; sticklive = sticknum; supStick = 0; crowdNum = 0; onlyNum = 0; k = 0; s = 0; t = 0; u = 0; int p; for (int j = 0; j < sticknum; j++) { owner = stickList[j].getOwner(); if (owner != "neutral") { sticklive--; } if (stickList[j].sumpow <= thresholdSpeed && owner == "neutral") { supStick++; } if (owner == "neutral" && stickList[j].sumpow > crowdPowLevel && stickList[j].whitepow != 0) { crowdNum++; } if (owner == "neutral" && stickList[j].whitepow == 0) { onlyNum++; } } xy = new float[sticklive, 2]; supxy = new float[supStick, 2]; crowdStick = new int[crowdNum]; onlyStick = new int[onlyNum]; for (int j = 0; j < sticknum; j++) { owner = stickList[j].getOwner(); if (owner == "neutral") { xy[k, 0] = stickList[j].getX(); xy[k, 1] = stickList[j].getY(); k++; if (supStick > 0) { if (stickList[j].sumpow <= thresholdSpeed) { supxy[s, 0] = stickList[j].getX(); supxy[s, 1] = stickList[j].getY(); s++; } } if (crowdNum > 0) { if (stickList[j].sumpow > crowdPowLevel) { //crowdStick[t] = stickList[j].No; t++; } } if (onlyNum > 0) { if (stickList[j].whitepow == 0) { onlyStick[u] = stickList[j].No; u++; } } } } }
public void BorderMap() { borderMap = IslMapGenerator.GenerateIslMap(mapHeight, mapWidth); }
void PaintHeightMap(Terrain terrain, SplineComputer computer, ref float[,] drawLayer, ref float[,] alphaLayer) { if (heights == null) { GetBase(); } SplineResult[] results = new SplineResult[computer.iterations]; computer.Evaluate(ref results, clipFrom, clipTo); /* * for(int i = 0; i < results.Length; i++) * { * float percent = (float)i/(results.Length-1); * results[i] = computer.Evaluate(percent); * } */ Draw(results, ref drawLayer, ref alphaLayer); }
protected override float intensityFor(float[,] heightmapData, int i, int j) { return(Intensity); }
public void ProjectileDraw(float[,] splashMask, Color targetColor, Vector2 texcoord) { MyProjectileDraw(splashMask, targetColor, texcoord); }
private void Plot(int x, int y, float value, float alpha, ref float[,] alphaTarget, ref float[,] target) { if (x < 0 || x >= target.GetLength(0)) { return; } if (y < 0 || y >= target.GetLength(1)) { return; } if (value > target[x, y]) { target[x, y] = value; alphaTarget[x, y] = alpha; } }
private meshData generateDeveloperMeshData(float[,] heightMap, float step) { meshData devMesh; devMesh.vertices = new Vector3[3 * 2 * (heightMap.GetLength(0) - 1) * (heightMap.GetLength(0) - 1)]; devMesh.uvs = new Vector2[3 * 2 * (heightMap.GetLength(0) - 1) * (heightMap.GetLength(0) - 1)]; devMesh.triangles = new int[3 * 2 * (heightMap.GetLength(0) - 1) * (heightMap.GetLength(0) - 1)]; for (int i = 0; i < heightMap.GetLength(0) - 1; i++) { for (int j = 0; j < heightMap.GetLength(0) - 1; j++) { int rectCnt = i * 3 * 2 * (heightMap.GetLength(0) - 1) + j * 3 * 2; if ((heightMap[i + 0, j + 0] >= heightMap[i + 1, j + 1] && heightMap[i + 0, j + 0] >= heightMap[i + 0, j + 1] && heightMap[i + 0, j + 0] >= heightMap[i + 1, j + 0]) || (heightMap[i + 1, j + 1] >= heightMap[i + 0, j + 0] && heightMap[i + 1, j + 1] >= heightMap[i + 0, j + 1] && heightMap[i + 1, j + 1] >= heightMap[i + 1, j + 0])) { devMesh.vertices[rectCnt + 0] = new Vector3((i + 1) * step, heightMap[i + 1, j + 0], (j + 0) * step); devMesh.vertices[rectCnt + 1] = new Vector3((i + 1) * step, heightMap[i + 1, j + 1], (j + 1) * step); devMesh.vertices[rectCnt + 2] = new Vector3((i + 0) * step, heightMap[i + 0, j + 0], (j + 0) * step); devMesh.vertices[rectCnt + 3] = new Vector3((i + 0) * step, heightMap[i + 0, j + 1], (j + 1) * step); devMesh.vertices[rectCnt + 4] = new Vector3((i + 0) * step, heightMap[i + 0, j + 0], (j + 0) * step); devMesh.vertices[rectCnt + 5] = new Vector3((i + 1) * step, heightMap[i + 1, j + 1], (j + 1) * step); } else if ((heightMap[i + 1, j + 0] >= heightMap[i + 1, j + 1] && heightMap[i + 1, j + 0] >= heightMap[i + 0, j + 1] && heightMap[i + 1, j + 0] >= heightMap[i + 0, j + 0]) || (heightMap[i + 0, j + 1] >= heightMap[i + 0, j + 0] && heightMap[i + 0, j + 1] >= heightMap[i + 1, j + 1] && heightMap[i + 0, j + 1] >= heightMap[i + 1, j + 0])) { devMesh.vertices[rectCnt + 0] = new Vector3((i + 0) * step, heightMap[i + 0, j + 0], (j + 0) * step); devMesh.vertices[rectCnt + 1] = new Vector3((i + 1) * step, heightMap[i + 1, j + 0], (j + 0) * step); devMesh.vertices[rectCnt + 2] = new Vector3((i + 0) * step, heightMap[i + 0, j + 1], (j + 1) * step); devMesh.vertices[rectCnt + 3] = new Vector3((i + 1) * step, heightMap[i + 1, j + 1], (j + 1) * step); devMesh.vertices[rectCnt + 4] = new Vector3((i + 0) * step, heightMap[i + 0, j + 1], (j + 1) * step); devMesh.vertices[rectCnt + 5] = new Vector3((i + 1) * step, heightMap[i + 1, j + 0], (j + 0) * step); } if ((heightMap[i + 0, j + 0] == heightMap[i + 0, j + 1] && heightMap[i + 1, j + 1] == heightMap[i + 1, j + 0]) || (heightMap[i + 0, j + 0] == heightMap[i + 1, j + 0] && heightMap[i + 1, j + 1] == heightMap[i + 0, j + 1])) { devMesh.uvs[rectCnt + 0] = new Vector2(0.5f, 0); devMesh.uvs[rectCnt + 1] = new Vector2(0.5f, 1); devMesh.uvs[rectCnt + 2] = new Vector2(1, 0); devMesh.uvs[rectCnt + 3] = new Vector2(0.5f, 0); devMesh.uvs[rectCnt + 4] = new Vector2(0.5f, 1); devMesh.uvs[rectCnt + 5] = new Vector2(1, 0); } else { devMesh.uvs[rectCnt + 0] = new Vector2(0, 0); devMesh.uvs[rectCnt + 1] = new Vector2(0, 1); devMesh.uvs[rectCnt + 2] = new Vector2(0.5f, 0); devMesh.uvs[rectCnt + 3] = new Vector2(0, 0); devMesh.uvs[rectCnt + 4] = new Vector2(0, 1); devMesh.uvs[rectCnt + 5] = new Vector2(0.5f, 0); } } } for (int i = 0; i < devMesh.triangles.Length / 3; i++) { devMesh.triangles[i * 3 + 0] = i * 3 + 2; devMesh.triangles[i * 3 + 1] = i * 3 + 1; devMesh.triangles[i * 3 + 2] = i * 3 + 0; } return(devMesh); }
/// <summary> /// Gets the square root of the sum of squares for all elements in a matrix. /// </summary> /// public static float Frobenius(this float[,] a) { return(Euclidean(a)); }
/// <summary> /// Gets the Euclidean norm for a matrix. /// </summary> /// public static float Euclidean(this float[,] a) { return((float)Math.Sqrt(SquareEuclidean(a))); }
void Populate() { NumberToCreate(); Turbines = new GameObject[numberToCreate]; AllSmokes = new GameObject[numberToCreate]; GameObject newObj; // Create GameObject instance float j = 0; int k = 0; GridLineHorizontal = k; bool IsEven = true; float scale = 0.5f; float lastScale = 0; GameObject Grid = GameObject.Find("Cube"); float TurbineSizeY = ((FromPreviousScene.Radius * 2) * PopulateGrid.YDiaValue); GeneratedPower = new float[numberToCreate]; GeneratedPowerSet = new float[100, 5]; List <string> Lines = new List <string>(); for (int i = 0; i < numberToCreate; i++) { TurbineCount++; Point = Instantiate(Point, panel.transform); // newObj = (GameObject)Instantiate(Prefab, transform); // newObj.transform.gameObject.name = i.ToString(); // newObj.GetComponent<Button>().onClick.AddListener( () => Grid.GetComponent<GridButtons>().OnclickButton() ); // AllSmokes[i] = Instantiate(Smoke) as GameObject; Turbines[i] = Instantiate(TurbinePrefab) as GameObject; //Turbines[i].transform.localScale = new Vector3(1f, 1f, 1f); Turbines[i].GetComponent <canvasLook>().TurbineNo = i; // Turbines[i].GetComponent<canvasLook>().Turbines =Turbines; if (IsEven) { if (Xlocation > (Cube.transform.localScale.x - ((getTrubineHeight((int)(k + 1)) / 1.5f) * 2) * PopulateGrid.XDiaValue)) { // LatestTurbinePosition = Turbines[i].transform.position.z; j = 0; k++; scale += 0.5f; if (!FromPreviousScene.IsSameHeight) { FromPreviousScene.TurbineSize += 73; //if (k <= 3) //{ // TurbineSizeY =(((30f / 1.5f) * 2f) * 7f); //} //else //{ // TurbineSizeY = ((((k * 10f) / 1.5f) * 2f) * 7f); //} // TurbineSizeEven = TurbineSizeY; } else { //TurbineSizeY = (((80f / 1.5f) * 2f) * 7f); //TurbineSizeEven = TurbineSizeOdd; FromPreviousScene.TurbineSize = 424; } IsEven = false; } } else { if (Xlocation > (Cube.transform.localScale.x - ((getTrubineHeight((int)(k + 1)) / 1.5f) * 2) * PopulateGrid.XDiaValue)) { Debug.Log("reached"); //LatestTurbinePosition = Turbines[i].transform.position.z; j = 0; k++; if (!FromPreviousScene.IsSameHeight) { FromPreviousScene.TurbineSize += 73; //if (k <= 3) //{ // TurbineSizeY = (((30f / 1.5f) * 2f) * 8f); //} //else //{ // TurbineSizeY = ((((k * 10f) / 1.5f) * 2f) * 8f); //} // TurbineSizeOdd = TurbineSizeY; } else { FromPreviousScene.TurbineSize = 424; // TurbineSizeY = (((80f / 1.5f) * 2f) * 8f); // TurbineSizeOdd = TurbineSizeY; } scale += 0.5f; IsEven = true; } } if (k + 1 < 8 && (!FromPreviousScene.IsSameHeight)) { Turbines[i].transform.localScale = new Vector3(scale, scale, scale); } else { if (FromPreviousScene.IsSameHeight) { scale = 4; } else { scale = 4; } Turbines[i].transform.localScale = new Vector3(scale, scale, scale); } // Turbines[i].transform.Find("Cone").transform.localScale = new Vector3(1f,FromPreviousScene.Radius,FromPreviousScene.Radius); // Turbines[i].transform.Find("Cone.2").transform.localScale = new Vector3(1f, FromPreviousScene.Radius, FromPreviousScene.Radius); // Turbines[i].transform.Find("Cone.3").transform.localScale = new Vector3(1f, FromPreviousScene.Radius, FromPreviousScene.Radius); Turbines[i].GetComponent <canvasLook>().TurbineRow = k + 1; if (k != lastScale) { lastScale = k; if (FromPreviousScene.IsGrid) { Xlocation = 0f;// ((getTrubineHeight((int)(k + 1)) / 1.5f) * 2) * PopulateGrid.XDiaValue; ZLocation += ((getTrubineHeight((int)(k)) / 1.5f) * 2) * PopulateGrid.XDiaValue; } else { if ((k + 1) % 2 == 0) { Xlocation = 0f; ZLocation += ((getTrubineHeight((int)(k)) / 1.5f) * 2) * (PopulateGrid.YDiaValue); } else { Xlocation = ((getTrubineHeight((int)(k + 1)) / 1.5f) * 2) * PopulateGrid.XDiaValue; ZLocation += ((getTrubineHeight((int)(k)) / 1.5f) * 2) * (PopulateGrid.YDiaValue); } } } if (FromPreviousScene.IsGrid) { Xlocation += ((getTrubineHeight((int)(k + 1)) / 1.5f) * 2) * PopulateGrid.XDiaValue; } else { if ((k + 1) % 2 != 0) { Xlocation += ((getTrubineHeight((int)(k + 1)) / 1.5f) * 2) * PopulateGrid.XDiaValue; } else { Xlocation += ((getTrubineHeight((int)(k + 1)) / 1.5f) * 2) * (PopulateGrid.XDiaValue); } } if (FromPreviousScene.IsGrid) { Turbines[i].transform.position = new Vector3(Xlocation, 0f, (ZLocation)); } else { if (IsEven) { // Debug.Log("K " + k); if (k == 0) { // Turbines[i].transform.position = new Vector3(((j * FromPreviousScene.TurbineSize) + (FromPreviousScene.TurbineSize / 2.0f)), 0, (ZLocation)); Turbines[i].transform.position = new Vector3(Xlocation - ((((getTrubineHeight((int)(k + 1)) / 1.5f) * 2) * PopulateGrid.XDiaValue) / 2), 0, (ZLocation)); } else { // Turbines[i].transform.position = new Vector3(((j * FromPreviousScene.TurbineSize) + (FromPreviousScene.TurbineSize / 2.0f)), 0, ( ZLocation)); Turbines[i].transform.position = new Vector3(Xlocation - ((((getTrubineHeight((int)(k + 1)) / 1.5f) * 2) * PopulateGrid.XDiaValue) / 2), 0, (ZLocation)); } } else { // Debug.Log("K " + k); // Turbines[i].transform.position = new Vector3(((j * FromPreviousScene.TurbineSize) + (FromPreviousScene.TurbineSize)), 0f, (ZLocation)); Turbines[i].transform.position = new Vector3(Xlocation, 0f, (ZLocation)); } } j++; // Debug.Log(Cube.transform.localScale.x / 10); // Point.transform.position = new Vector2( ((Cube.transform.localScale.x/10)) , (Turbines[i].transform.position.z/10f)); // Point.rectTransform.localPosition = new Vector3((Turbines[i].transform.position.x/10) - ((Cube.transform.localScale.x/10)/2), -((Turbines[i].transform.position.z / 10) - ((Cube.transform.localScale.z / 10) / 2)), 0); float pointx = (Turbines[i].transform.position.x / 10) - ((Cube.transform.localScale.x / 10) / 2); float pointy = -((Turbines[i].transform.position.z / 10) - ((Cube.transform.localScale.z / 10) / 2)); Point.rectTransform.localPosition = new Vector3(pointx, pointy, 0); if (k == 0) { GridLineY = Instantiate(GridLineY, panel.transform); GridLineY.rectTransform.localPosition = new Vector3(Point.rectTransform.localPosition.x + 2f, Point.rectTransform.localPosition.y); // GridLine.rectTransform.localScale = new Vector3(GridLine.rectTransform.localPosition.x, Cube.transform.localScale.z / 10f); GridLineY.rectTransform.sizeDelta = new Vector2(GridLineY.rectTransform.sizeDelta.x, Cube.transform.localScale.z / 10f); GridLineHeight = (int)(GridLineY.rectTransform.localPosition.y - GridLineY.rectTransform.sizeDelta.y); FirstPointPosition = (int)(Point.rectTransform.localPosition.y); } if (FirstPointPosition >= GridLineHeight) { GridLineHorizontal = k; GridLineX = Instantiate(GridLineX, panel.transform); if (RotateGridForFirst == 0) { //GridLineX.rectTransform.Rotate(0f, 0f, 90f); RotateGridForFirst = 1; } GridLineX.rectTransform.sizeDelta = new Vector2(Cube.transform.localScale.x / 10f, GridLineX.rectTransform.sizeDelta.y); GridLineX.rectTransform.localPosition = new Vector3(-((Cube.transform.localScale.x / 10) / 2), FirstPointPosition); if (FromPreviousScene.IsSameHeight) { FirstPointPosition = (int)-((Turbines[i].transform.position.z / 10) - ((Cube.transform.localScale.z / 10) / 2)); } else { FirstPointPosition -= (int)(((YDiaValue * getTrubineHeight((int)(1))) / 10)) + (YDiaValue * 2); } } Point.rectTransform.localPosition = new Vector3(pointx, pointy, 0); //if ((k % 2 == 0) && (j % 2 == 0) && i!=0) //{ // Turbines[i].SetActive(false); //} //if (((k % 2) != 0) && ((j % 2) != 0) &&i!=0) //{ // Turbines[i].SetActive(false); //} // newObj.GetComponentInChildren<Text>().text = i.ToString(); // newObj.GetComponent<Button>().onClick.AddListener(() => Turbines[i].GetComponent<canvasLook>().Update()); //Transform obj = Turbines[i].transform.Find("head"); //AllSmokes[i].transform.localPosition= new Vector3(obj.position.x, obj.position.y, obj.position.z); if (Turbines[i].transform.position.z > Cube.transform.localScale.z) { Destroy(Turbines[i]); TurbineCount--; //Destroy(AllSmokes[i]); Destroy(Point); GeneratedPowerSet[k + 1, 3]--; break; } else { // Debug.Log("X:"+Xlocation+":Y:"+ZLocation); Lines.Add("X:" + Xlocation + ":Y:" + ZLocation); } } using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"D:\\Coordinates.txt")) { foreach (string line in Lines) { // If the line doesn't contain the word 'Second', write the line to the file. file.WriteLine(line); } } // Grid.GetComponent<GridButtons>().OnclickButton(); // Debug.Log("reached"); // Debug.Log(this.transform.parent.parent.gameObject.name); //this.transform.parent.parent.gameObject.SetActive(false); }
public void setLandVertexHeights(float[,] landVertexHeights) { this.landVertexHeights = landVertexHeights; }
public MatrixFilter(float[,] kernel) { this.kernel = kernel; }
static void Main(string[] args) { int[,] intMatrix; float[,] floatMatrix; string[,,] stringCube; int[,] intMatrix2 = new int[3, 4]; float[,] floatMatrix2 = new float[8, 2]; string[,,] stringCube2 = new string[5, 5, 5]; int[,] intMatrix3 = { { 1, 2, 3, 4 }, { 5, 6, 7, 8 } }; int im3 = intMatrix3[0, 3]; Console.WriteLine(im3); float[,] floatMatrix3 = { { 2.5f, 6.12f, 65.23f, 5.111f }, { 2.12f, 78.11f, 43.66f, 453.1f } }; float f3 = floatMatrix3[1, 2]; Console.WriteLine(f3); string[,,] stringMatrix3 = { { { "a1", "a2", "a3", "a4", "a5" }, { "a6", "a7", "a8", "a9", "a10" } }, { { "b1", "b2", "b3", "b4", "b5" }, { "b6", "b7", "b8", "b9", "b10" } }, { { "c1", "c2", "c3", "c4", "c5" }, { "c6", "c7", "c8", "c9", "c10" } } }; string sm3 = stringMatrix3[1, 0, 3]; Console.WriteLine(sm3); sm3 = "b555"; Console.WriteLine(sm3); Console.WriteLine(); Console.WriteLine("Print Matrix:"); int[,] matrixToPrint = { { 1, 2, 3, 4, 5 }, { 6, 7, 8, 9, 10 }, { 11, 12, 13, 14, 15 } }; for (int row = 0; row < matrixToPrint.GetLength(0); row++) { for (int col = 0; col < matrixToPrint.GetLength(1); col++) { Console.Write(matrixToPrint[row, col] + " "); } Console.WriteLine(); } Console.WriteLine(); Console.WriteLine("Print 3D Cube :"); int[,,] cube3d = { { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }, { { 10, 11, 12 }, { 13, 14, 15 }, { 16, 17, 18 } }, { { 19, 20, 21 }, { 22, 23, 24 }, { 25, 26, 27 } } }; for (int row = 0; row < cube3d.GetLength(0); row++) { for (int col = 0; col < cube3d.GetLength(1); col++) { for (int elem = 0; elem < cube3d.GetLength(2); elem++) { Console.Write(cube3d[row, col, elem] + " "); } Console.Write(" "); } Console.WriteLine(); } Console.WriteLine(); Console.WriteLine("Jagged Arrays:"); int[][] jagged = new int[3][]; jagged[0] = new int[3]; jagged[1] = new int[2]; jagged[2] = new int[1]; Console.WriteLine(jagged[0][0] = 1); Console.WriteLine(jagged[0][1] = 2); Console.WriteLine(jagged[0][2] = 3); Console.WriteLine(jagged[1][0] = 4); Console.WriteLine(jagged[1][1] = 5); Console.WriteLine(jagged[2][0] = 6); Console.WriteLine(); int[][] jaggedArray = new int[3][]; for (int row = 0; row < 3; row++) { Console.WriteLine("Write some numbers separated by ',' to fill one of the rows of the Jagged array :"); jaggedArray[row] = Console.ReadLine().Split(',').Select(int.Parse).ToArray(); } Console.WriteLine(); Console.WriteLine("Print jagged array:"); for (int row = 0; row < jaggedArray.GetLength(0); row++) { for (int col = 0; col < jaggedArray[row].Length; col++) { Console.Write(jaggedArray[row][col] + " "); } Console.WriteLine(); } }
private void ValidateBrush() { bool updated = false; if (showBrush) { if (updateTaper) { taper = new float[brushWidth, brushWidth]; int radius = (brushWidth - 1) / 2; float taperStep = (100f - brushTaper) / 100f / radius; float currentTaper = 1f - taperStep; int evenOddMod = (brushWidth & 0x1) == 0 ? 1 : 0; taper[radius, radius] = 1.0f; if (evenOddMod == 1) { taper[radius, radius + 1] = 1f; taper[radius + 1, radius] = 1f; taper[radius + 1, radius + 1] = 1f; } // The evenOddMod has the effect of drawing a 1 index larger box // Examples: // // r = 3 r = 4 // // 3 x x x x // 2 x x x 2 x # # x // 1 x * x 1 x * # x // Z=0 x x x 0 x x x x // X=0 1 2 0 1 2 3 // // * = Center as defined by the radius // # = Padded center for even sized shapes (which evenOddMod is used for) // x = Values populated by loop below with currentTaper // Z/X = Axis labels for the array for (int r = 1; r <= radius; r++) { for (int i = radius - r; i <= radius + r + evenOddMod; i++) { taper[i, radius - r] = currentTaper; taper[i, radius + r + evenOddMod] = currentTaper; taper[radius - r, i] = currentTaper; taper[radius + r + evenOddMod, i] = currentTaper; } currentTaper -= taperStep; } updateTaper = false; updated = true; // DumpTaper(); } if (updateBrush) { switch (brushShape) { case BrushStyle.Square: brush = new float[brushWidth, brushWidth]; for (int x = 0; x < brushWidth; x++) { for (int z = 0; z < brushWidth; z++) { brush[x, z] = 1f; } } break; case BrushStyle.Diamond: if (brushWidth == 1) { brush = brushMask_1; } else { brush = new float[brushWidth, brushWidth]; int radius = brushWidth >> 1; int midSpans = (brushWidth - 3) >> 1; bool even = (brushWidth & 0x1) == 0; if (even) { radius--; } // top and bottom brush[radius, 0] = 0.25f; brush[radius, brushWidth - 1] = 0.25f; if (even) { brush[radius+1, 0] = 0.25f; brush[radius+1, brushWidth - 1] = 0.25f; } // middle brush[0, radius] = 0.25f; brush[brushWidth - 1, radius] = 0.25f; if (even) { brush[0, radius+1] = 0.25f; brush[brushWidth - 1, radius+1] = 0.25f; } for (int i = 1; i < brushWidth - 1; i++) { brush[i, radius] = 1f; if (even) { brush[i, radius+1] = 1f; } } // midspans (rows between top & middle and middle & bottom) for (int span = 0; span < midSpans; span++) { int fromX = radius - span; int toX = radius + span + (even ? 1 : 0); // ends of span (top and bottom) brush[fromX - 1, span + 1] = 0.5f; brush[toX + 1, span + 1] = 0.5f; brush[fromX - 1, brushWidth - span - 2] = 0.5f; brush[toX + 1, brushWidth - span - 2] = 0.5f; // middle of span (top and bottom) for (int x = fromX; x <= toX; x++) { brush[x, span + 1] = 1f; brush[x, brushWidth - span - 2] = 1f; } } } break; case BrushStyle.Circle: float[,] circleBrushMask = CreateCircleBrush(brushWidth); float[,] guassianBrush = CreateGaussianCircleBrush(brushWidth); brush = CombineBrushes(guassianBrush, circleBrushMask); break; case BrushStyle.Slash: if (brushWidth == 1) { brush = brushMask_1; } else { brush = new float[brushWidth, brushWidth]; // top brush[brushWidth - 1, 0] = 1f; brush[brushWidth - 2, 0] = 0.5f; // bottom brush[0, brushWidth - 1] = 1f; brush[1, brushWidth - 1] = 0.5f; for (int i = 1; i < brushWidth - 1; i++) { brush[brushWidth - 1 - i, i] = 1f; brush[brushWidth - 2 - i, i] = 0.5f; brush[brushWidth - i, i] = 0.5f; } } break; case BrushStyle.Backslash: if (brushWidth == 1) { brush = brushMask_1; } else { brush = new float[brushWidth, brushWidth]; // top brush[0, 0] = 1f; brush[1, 0] = 0.5f; // bottom brush[brushWidth - 1, brushWidth - 1] = 1f; brush[brushWidth - 2, brushWidth - 1] = 0.5f; for (int i = 1; i < brushWidth - 1; i++) { brush[i, i] = 1f; brush[i - 1, i] = 0.5f; brush[i + 1, i] = 0.5f; } } break; case BrushStyle.HBar: if (brushWidth == 1) { brush = brushMask_1; } else { brush = new float[brushWidth, brushWidth]; int radius = (brushWidth >> 1); for (int i = 0; i < brushWidth; i++) { brush[i, radius] = 1f; brush[i, radius - 1] = 0.5f; brush[i, radius + 1] = 0.5f; } } break; case BrushStyle.VBar: if (brushWidth == 1) { brush = brushMask_1; } else { brush = new float[brushWidth, brushWidth]; int radius = (brushWidth >> 1); for (int i = 0; i < brushWidth; i++) { brush[radius, i] = 1f; brush[radius - 1, i] = 0.5f; brush[radius + 1, i] = 0.5f; } } break; } DumpBrush(); updateBrush = false; updated = true; SetCursorLoc(cursorX, cursorZ); } } else { brush = new float[brushWidth, brushWidth]; taper = new float[brushWidth, brushWidth]; updated = true; } if (updated) { UpdateMaterialBrush(); } }
public void SetCoordinates(float[,] inCoords, int inSubtextureId) { }
public MapData(float[,] heightMap, Color[] colourMap) { this.heightMap = heightMap; this.colourMap = colourMap; }
/// <summary> /// An input color twist matrix with floating-point pixel values is applied /// within ROI. /// </summary> /// <param name="dest">Destination image</param> /// <param name="twistMatrix">The color twist matrix with floating-point pixel values [3,4].</param> public void ColorTwist(NPPImage_16fC3 dest, float[,] twistMatrix) { status = NPPNativeMethods.NPPi.ColorTwist.nppiColorTwist32f_16f_C3R(_devPtr, _pitch, dest.DevicePointer, dest.Pitch, _sizeRoi, twistMatrix); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiColorTwist32f_16f_C3R", status)); NPPException.CheckNppStatus(status, this); }
public HeightMapThreadInfo(Vector2 position, float[,] heightMap) { this.position = position; this.heightMap = heightMap; }
// Use this for initialization void Start() { t = GameObject.Find("Terrain").GetComponent <Terrain>(); originalHeights = t.terrainData.GetHeights(0, 0, t.terrainData.heightmapWidth, t.terrainData.heightmapHeight); }
/// <summary> /// in place color twist. /// /// An input color twist matrix with floating-point coefficient values is applied /// within ROI. /// </summary> /// <param name="aTwist">The color twist matrix with floating-point coefficient values. [3,4]</param> public void ColorTwist(float[,] aTwist) { status = NPPNativeMethods.NPPi.ColorTwist.nppiColorTwist32f_16f_C3IR(_devPtr, _pitch, _sizeRoi, aTwist); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiColorTwist32f_16f_C3IR", status)); NPPException.CheckNppStatus(status, this); }