コード例 #1
0
        public void RemoveObjsInRange(float posX, float posZ, float range)         //TODO: test, then replace CellNumsInRect. Or better replace with callback
        {
            Rect rect = new Rect(posX - range, posZ - range, range * 2, range * 2);

            rect = CoordinatesExtensions.Intersect(rect, this.rect);

            foreach (int c in CellNumsInRect(rect.min, rect.max))
            {
                for (int p = cells.array[c].count - 1; p >= 0; p--)
                {
                    float distSq = (cells.array[c].poses[p].x - posX) * (cells.array[c].poses[p].x - posX) + (cells.array[c].poses[p].z - posZ) * (cells.array[c].poses[p].z - posZ);
                    if (distSq < range * range)
                    {
                        Remove(c, p);
                    }
                }
            }
        }
コード例 #2
0
ファイル: Matrix.cs プロジェクト: Quintavius/Journeys
			public void WriteTextureInterpolated (Texture2D texture, CoordRect textureRect, WrapMode wrap=WrapMode.Once, float rangeMin=0, float rangeMax=1)
			{
				float pixelSizeX = 1f * textureRect.size.x / texture.width;
				float pixelSizeZ = 1f * textureRect.size.z / texture.height;

				Rect pixelTextureRect = new Rect(0, 0, texture.width, texture.height);
				Rect pixelMatrixRect = new Rect(
					(textureRect.offset.x - rect.offset.x) / pixelSizeX,
					(textureRect.offset.z - rect.offset.z) / pixelSizeZ,
					rect.size.x/pixelSizeX, 
					rect.size.z/pixelSizeZ);

				Rect pixelIntersection = CoordinatesExtensions.Intersect(pixelTextureRect, pixelMatrixRect);

				CoordRect intersect = new CoordRect(
					Mathf.CeilToInt(pixelIntersection.x),
					Mathf.CeilToInt(pixelIntersection.y),
					Mathf.FloorToInt(pixelIntersection.width),
					Mathf.FloorToInt(pixelIntersection.height) );

				Color[] colors = new Color[intersect.size.x*intersect.size.z];

				Coord min = intersect.Min; Coord max = intersect.Max;
				for (int x=min.x; x<max.x; x++)
					for (int z=min.z; z<max.z; z++)
				{
					float wx = x*pixelSizeX - textureRect.offset.x + rect.offset.x*2;
					float wz = z*pixelSizeZ - textureRect.offset.z + rect.offset.z*2;

					//float val = this[x,z]; //TODO: direct
					float val = GetInterpolated(wx, wz);
					val -= rangeMin;
					val /= rangeMax-rangeMin;

					//val = 1;

					colors[(z-min.z)*(max.x-min.x) + (x-min.x)] = new Color(val, val, val); //TODO: r should not be == r and ==b, there should be 1 byte diff
				}

				texture.SetPixels(intersect.offset.x, intersect.offset.z, intersect.size.x, intersect.size.z, colors);
				texture.Apply();
			}