public Layer(Short2 size, LayerController layerUi) { this.size = size; this.layerUi = layerUi; RenderLayer(); }
public void DrawCircle(Short2 center, int radius, Color color) { int x0 = center.x, y0 = center.y; int x = radius, y = 0; int decisionOver2 = 1 - x; // Decision criterion divided by 2 evaluated at x=r, y=0 while (y <= x) { SetColor(x + x0, y + y0, color); // Octant 1 SetColor(y + x0, x + y0, color); // Octant 2 SetColor(-x + x0, y + y0, color); // Octant 4 SetColor(-y + x0, x + y0, color); // Octant 3 SetColor(-x + x0, -y + y0, color); // Octant 5 SetColor(-y + x0, -x + y0, color); // Octant 6 SetColor(x + x0, -y + y0, color); // Octant 7 SetColor(y + x0, -x + y0, color); // Octant 8 y++; if (decisionOver2 <= 0) { decisionOver2 += 2 * y + 1; // Change in decision criterion for y -> y+1 } else { x--; decisionOver2 += 2 * (y - x) + 1; // Change for y -> y+1, x -> x-1 } } }
public Short4(Short2 xy, short z, short w) { this.X = xy.X; this.Y = xy.Y; this.Z = z; this.W = w; }
public Short4(short x, short y, Short2 zw) { this.X = x; this.Y = y; this.Z = zw.X; this.W = zw.Y; }
public Short4(short x, Short2 yz, short w) { this.X = x; this.Y = yz.X; this.Z = yz.Y; this.W = w; }
public Short4(Short2 xy, Short2 zw) { this.X = xy.X; this.Y = xy.Y; this.Z = zw.X; this.W = zw.Y; }
public void SetTextureInfo(UnifiedTextureInfo textureInfo) { texcoords[0] = textureInfo.u0; // left top u texcoords[1] = textureInfo.v0; // left top v texcoords[2] = textureInfo.u0; // left bottom u texcoords[3] = textureInfo.v1; // left bottom v texcoords[4] = textureInfo.u1; // right top u texcoords[5] = textureInfo.v0; // right top v texcoords[6] = textureInfo.u1; // right bottom u texcoords[7] = textureInfo.v1; // right bottom v #if true _uv[0] = new Short2((short)(textureInfo.u0 * 32767), (short)(textureInfo.v0 * 32767)); //(0,0) _uv[1] = new Short2((short)(textureInfo.u0 * 32767), (short)(textureInfo.v1 * 32767)); //(1,0) _uv[2] = new Short2((short)(textureInfo.u1 * 32767), (short)(textureInfo.v0 * 32767)); //(0,1) _uv[3] = new Short2((short)(textureInfo.u1 * 32767), (short)(textureInfo.v1 * 32767)); //(1,1) #else _uv[0] = new Short2((short)(textureInfo.u0 * 32767), (short)(textureInfo.v0 * 32767)); _uv[1] = new Short2((short)(textureInfo.u1 * 32767), (short)(textureInfo.v0 * 32767)); //(1,0) _uv[2] = new Short2((short)(textureInfo.u0 * 32767), (short)(textureInfo.v1 * 32767)); //(0,1) _uv[3] = new Short2((short)(textureInfo.u1 * 32767), (short)(textureInfo.v1 * 32767)); //(1,1) #endif this.width = textureInfo.w; this.height = textureInfo.h; }
/// <summary> /// sdf 处理,整个挡格扩大一圈 /// </summary> /// <param name="lbock"></param> /// <param name="range">扩大的范围</param> private void SdfProcess(ref List <Short2> lbock, int range) { List <Short2> listNew = new List <Short2>(); foreach (Short2 pos in lbock) { if (CheckInMap(pos) == false) { continue; } for (int y = pos.y - range; y <= pos.y + range; y++) { for (int x = pos.x - range; x <= pos.x + range; x++) { Short2 p = new Short2(x, y); if (CheckInMap(p) == false) { continue; } listNew.Add(p); } } } lbock = listNew; }
/// <summary> /// 在轮廓中查找keyPoint /// </summary> /// <returns></returns> public bool FindKeyPoint(RLEGridMap grid, ref Float2 keyPoint) { if (grid == null) { return(false); } Polygon2D poly = new Polygon2D(pts.ToArray()); Double2 lb = poly.leftBottom; Double2 ru = poly.rightUp; Short2 slb = grid.GetIndex(lb) + Short2.one; Short2 sru = grid.GetIndex(ru) - Short2.one; for (int x = slb.x; x < sru.x; x++) { double xpos = x * (double)grid.TileSize; Double2 yminPos1 = Double2.zero; Double2 ymaxPos2 = Double2.zero; if (poly.GetPointsInAreabyXaixs(xpos, 1.0f, ref yminPos1, ref ymaxPos2) == true) { int ymin = (int)(yminPos1.y / grid.TileSize); int ymax = (int)(ymaxPos2.y / grid.TileSize); if (grid.CheckXDirHaveBlock(x, ymin, ymax) == true) { keyPoint = new Float2(x * grid.TileSize, ymax * grid.TileSize); return(true); } } } return(false); }
public void ApplyTransform(Selection selection) { var rotation = Quaternion.Euler(0, 0, -selection.Rotation); int i = 0; for (int y = 0; y < size.y; y++) { for (int x = 0; x < size.y; x++) { var coordinate = new Vector3(x, y); coordinate -= selection.Position; coordinate = rotation * coordinate; coordinate /= selection.Scale; coordinate += selection.Pivotal; var originalCoordinate = new Short2(coordinate.x + 0.5f, coordinate.y + 0.5f); if (selection.Content.ContainsKey(originalCoordinate) && selection.Content[originalCoordinate].a != 0) { SetColor(new Short2(x, y), selection.Content[originalCoordinate]); } i++; } } selection.ResetSelection(); }
public ParticleVertex(Short2 c, Vector3 pos, Vector3 v, Color r, float t) { Corner = c; Position = pos; Velocity = v; Random = r; Time = t; }
public void ClearColor(Short2 point) { if (selectedLayer == null) { return; } dirtyFlag |= selectedLayer.ClearColor(point); }
public void SubFromSelection(Short2 c) { if (selectedLayer == null) { return; } selectedLayer.SubFromSelection(c, selection); }
public void FillColor(Short2 point, Color color) { if (selectedLayer == null) { return; } dirtyFlag |= selectedLayer.FillColor(point, color); }
public Drawing(Short2 size, CanvasController canvasUi, Selection selection) { this.file = new DrawingFile(); this.size = size; this.canvasUi = canvasUi; this.selection = selection; RenderDrawing(); }
public void AddToSelection(Short2 c) { if (selectedLayer == null) { return; } selectedLayer.AddToSelection(c, selection); }
public Color GetColor(Short2 c) { if (IsIllegal(c)) { return(Color.clear); } return(HasColor(c) ? content[c] : Color.clear); }
public void ResizeLayer(Short2 c) { if (c == size) { return; } size = c; RenderLayer(); }
public void Short2() { // Test the limits. Assert.Equal((uint)0x0, new Short2(Vector2.Zero).PackedValue); Assert.Equal((uint)0x7FFF7FFF, new Short2(Vector2.One * 0x7FFF).PackedValue); Assert.Equal(0x80008000, new Short2(Vector2.One * -0x8000).PackedValue); // Test ToVector2. Assert.True(Equal(Vector2.One * 0x7FFF, new Short2(Vector2.One * 0x7FFF).ToVector2())); Assert.True(Equal(Vector2.Zero, new Short2(Vector2.Zero).ToVector2())); Assert.True(Equal(Vector2.One * -0x8000, new Short2(Vector2.One * -0x8000).ToVector2())); Assert.True(Equal(Vector2.UnitX * 0x7FFF, new Short2(Vector2.UnitX * 0x7FFF).ToVector2())); Assert.True(Equal(Vector2.UnitY * 0x7FFF, new Short2(Vector2.UnitY * 0x7FFF).ToVector2())); // Test clamping. Assert.True(Equal(Vector2.One * 0x7FFF, new Short2(Vector2.One * 1234567.0f).ToVector2())); Assert.True(Equal(Vector2.One * -0x8000, new Short2(Vector2.One * -1234567.0f).ToVector2())); // Test ToVector4. Assert.True(Equal(new Vector4(0x7FFF, 0x7FFF, 0, 1), (new Short2(Vector2.One * 0x7FFF)).ToVector4())); Assert.True(Equal(new Vector4(0, 0, 0, 1), (new Short2(Vector2.Zero)).ToVector4())); Assert.True(Equal(new Vector4(-0x8000, -0x8000, 0, 1), (new Short2(Vector2.One * -0x8000)).ToVector4())); // Test ordering float x = 0x2db1; float y = 0x361d; Assert.Equal((uint)0x361d2db1, new Short2(x, y).PackedValue); x = 127.5f; y = -5.3f; Assert.Equal(4294639744, new Short2(x, y).PackedValue); byte[] rgb = new byte[3]; byte[] rgba = new byte[4]; byte[] bgr = new byte[3]; byte[] bgra = new byte[4]; new Short2(x, y).ToXyzBytes(rgb, 0); Assert.Equal(rgb, new byte[] { 128, 127, 0 }); new Short2(x, y).ToXyzwBytes(rgba, 0); Assert.Equal(rgba, new byte[] { 128, 127, 0, 255 }); new Short2(x, y).ToZyxBytes(bgr, 0); Assert.Equal(bgr, new byte[] { 0, 127, 128 }); new Short2(x, y).ToZyxwBytes(bgra, 0); Assert.Equal(bgra, new byte[] { 0, 127, 128, 255 }); Short2 r = new Short2(); r.PackFromBytes(20, 38, 0, 255); r.ToXyzwBytes(rgba, 0); Assert.Equal(rgba, new byte[] { 20, 38, 0, 255 }); }
public void Short2() { // Test the limits. Assert.Equal((uint)0x0, new Short2(Vector2.Zero).PackedValue); Assert.Equal((uint)0x7FFF7FFF, new Short2(Vector2.One * 0x7FFF).PackedValue); Assert.Equal(0x80008000, new Short2(Vector2.One * -0x8000).PackedValue); // Test ToVector2. Assert.True(Equal(Vector2.One * 0x7FFF, new Short2(Vector2.One * 0x7FFF).ToVector2())); Assert.True(Equal(Vector2.Zero, new Short2(Vector2.Zero).ToVector2())); Assert.True(Equal(Vector2.One * -0x8000, new Short2(Vector2.One * -0x8000).ToVector2())); Assert.True(Equal(Vector2.UnitX * 0x7FFF, new Short2(Vector2.UnitX * 0x7FFF).ToVector2())); Assert.True(Equal(Vector2.UnitY * 0x7FFF, new Short2(Vector2.UnitY * 0x7FFF).ToVector2())); // Test clamping. Assert.True(Equal(Vector2.One * 0x7FFF, new Short2(Vector2.One * 1234567.0f).ToVector2())); Assert.True(Equal(Vector2.One * -0x8000, new Short2(Vector2.One * -1234567.0f).ToVector2())); // Test ToVector4. Assert.True(Equal(new Vector4(0x7FFF, 0x7FFF, 0, 1), (new Short2(Vector2.One * 0x7FFF)).ToVector4())); Assert.True(Equal(new Vector4(0, 0, 0, 1), (new Short2(Vector2.Zero)).ToVector4())); Assert.True(Equal(new Vector4(-0x8000, -0x8000, 0, 1), (new Short2(Vector2.One * -0x8000)).ToVector4())); // Test ordering float x = 0x2db1; float y = 0x361d; Assert.Equal((uint)0x361d2db1, new Short2(x, y).PackedValue); x = 127.5f; y = -5.3f; Assert.Equal(4294639744, new Short2(x, y).PackedValue); var rgb = default(Rgb24); var rgba = default(Rgba32); var bgr = default(Bgr24); var bgra = default(Bgra32); new Short2(x, y).ToRgb24(ref rgb); Assert.Equal(rgb, new Rgb24(128, 127, 0)); new Short2(x, y).ToRgba32(ref rgba); Assert.Equal(rgba, new Rgba32(128, 127, 0, 255)); new Short2(x, y).ToBgr24(ref bgr); Assert.Equal(bgr, new Bgr24(128, 127, 0)); new Short2(x, y).ToBgra32(ref bgra); Assert.Equal(bgra, new Bgra32(128, 127, 0, 255)); var r = new Short2(); r.PackFromRgba32(new Rgba32(20, 38, 0, 255)); r.ToRgba32(ref rgba); Assert.Equal(rgba, new Rgba32(20, 38, 0, 255)); }
/// <summary> /// 边缘点 /// </summary> /// <param name="pos"></param> /// <param name="nextPos"></param> /// <returns></returns> public bool CheckNearBlockPoint(Short2 pos, Short2 nextPos) { if (this.listblock.Contains(pos) == false && this.listblock.Contains(nextPos) == true) { return(true); } else { return(false); } }
/// <summary> /// 设置为非挡格 /// </summary> /// <param name="pos"></param> public void SetUnBlock(Short2 pos) { if (_blockArray == null) { return; } if (CheckInMap(pos) == true) { _blockArray[pos.y][pos.x] = 0; } }
/// <summary> /// /// </summary> /// <param name="pos"></param> /// <returns></returns> public bool CheckInMap(Short2 pos) { if (pos >= Short2.zero && pos < this._mapSize) { return(true); } else { return(false); } }
public void SubFromSelection(Short2 c, Selection selection) { if (IsIllegal(c)) { return; } FloodSetSelection(c, GetColor(c), false, selection); selection.CalcPivotal(); }
public void AddToSelection(Short2 c, Selection selection) { if (IsIllegal(c)) { return; } FloodSetSelection(c, GetColor(c), true, selection); selection.CalcPivotal(); }
public void Short2_ToRgba32() { // arrange var short2 = new Short2(127.5f, -5.3f); var actual = default(Rgba32); var expected = new Rgba32(128, 127, 0, 255); // act short2.ToRgba32(ref actual); // assert Assert.Equal(expected, actual); }
public void Short2_ToBgr24() { // arrange var short2 = new Short2(127.5f, -5.3f); var actual = default(Bgr24); var expected = new Bgr24(128, 127, 0); // act short2.ToBgr24(ref actual); // assert Assert.Equal(expected, actual); }
void FloodSetSelection(Short2 c, Color src, bool value, Selection selection) { if (IsIllegal(c) || GetColor(c) != src || selection.GetSelection(c) == value) { return; } selection.SetSelection(c, value); FloodSetSelection(new Short2(c.x, c.y + 1), src, value, selection); FloodSetSelection(new Short2(c.x, c.y - 1), src, value, selection); FloodSetSelection(new Short2(c.x - 1, c.y), src, value, selection); FloodSetSelection(new Short2(c.x + 1, c.y), src, value, selection); }
void FloodFill(Short2 c, Color src, Color dst) { if (IsIllegal(c) || GetColor(c) != src || GetColor(c) == dst) { return; } SetColor(c, dst); FloodFill(new Short2(c.x, c.y + 1), src, dst); FloodFill(new Short2(c.x, c.y - 1), src, dst); FloodFill(new Short2(c.x - 1, c.y), src, dst); FloodFill(new Short2(c.x + 1, c.y), src, dst); }
public void SetSelection(Short2 c, bool value = true) { if (value) { Area[c] = true; } else if (Area.ContainsKey(c)) { Area.Remove(c); } GridDirtyFlag = true; }
public void TestMemberFn_GetHashCode_i () { HashSet<Int32> hs = new HashSet<Int32>(); var rand = new System.Random(); var buff = new Byte[4]; UInt32 collisions = 0; for(Int32 i = 0; i < Settings.NumTests; ++i) { rand.NextBytes(buff); UInt32 packed = BitConverter.ToUInt32(buff, 0); var packedObj = new Short2(); packedObj.PackedValue = packed; Int32 hc = packedObj.GetHashCode (); if(hs.Contains(hc)) ++collisions; hs.Add(hc); } Assert.That(collisions, Is.LessThan(10)); }
public void TestMemberFn_ToString_i() { var testCase = new Short2(); testCase.PackFrom(0.656f, 0.125f); String s = testCase.ToString (); Assert.That(s, Is.EqualTo("00000001")); }
public void TestRandomValues_i() { var rand = new System.Random(); var buff = new Byte[4]; for(Int32 i = 0; i < Settings.NumTests; ++i) { rand.NextBytes(buff); UInt32 packed = BitConverter.ToUInt32(buff, 0); var packedObj = new Short2(); packedObj.PackedValue = packed; Single realX, realY = 0f; packedObj.UnpackTo(out realX, out realY); var newPackedObj = new Short2(realX, realY); Assert.That(newPackedObj.PackedValue, Is.EqualTo(packed)); } }
/// <summary> /// Allows the game component to perform any initialization it needs to before starting /// to run. This is where it can query for any required services and load content. /// </summary> public override void Initialize() { base.Initialize(); // Die vier Ecken eines quadratischen Partikels corners[0] = new Short2(-1, -1); corners[1] = new Short2(1, -1); corners[2] = new Short2(1, 1); corners[3] = new Short2(-1, 1); // Erstellen des Vertex Buffers vertexBuffer = new VertexBuffer(GraphicsDevice, ParticleVertex.VertexDeclaration, maxParticles * 4, BufferUsage.WriteOnly); // Erstellen der Indizes ushort[] indices = new ushort[maxParticles * 6]; for (int i = 0; i < maxParticles; i++) { indices[i * 6 + 0] = (ushort)(i * 4 + 0); indices[i * 6 + 1] = (ushort)(i * 4 + 1); indices[i * 6 + 2] = (ushort)(i * 4 + 2); indices[i * 6 + 3] = (ushort)(i * 4 + 0); indices[i * 6 + 4] = (ushort)(i * 4 + 2); indices[i * 6 + 5] = (ushort)(i * 4 + 3); } // Einlesen der Indizes in den Index Buffer indexBuffer = new IndexBuffer(GraphicsDevice, typeof(ushort), indices.Length, BufferUsage.WriteOnly); indexBuffer.SetData(indices); }
public void SetTextureInfo(UnifiedTextureInfo textureInfo) { texcoords[0] = textureInfo.u0; // left top u texcoords[1] = textureInfo.v0; // left top v texcoords[2] = textureInfo.u0; // left bottom u texcoords[3] = textureInfo.v1; // left bottom v texcoords[4] = textureInfo.u1; // right top u texcoords[5] = textureInfo.v0; // right top v texcoords[6] = textureInfo.u1; // right bottom u texcoords[7] = textureInfo.v1; // right bottom v #if true _uv[0] = new Short2((short)(textureInfo.u0*32767),(short)(textureInfo.v0*32767));//(0,0) _uv[1] = new Short2((short)(textureInfo.u0*32767),(short)(textureInfo.v1*32767));//(1,0) _uv[2] = new Short2((short)(textureInfo.u1*32767),(short)(textureInfo.v0*32767));//(0,1) _uv[3] = new Short2((short)(textureInfo.u1*32767),(short)(textureInfo.v1*32767));//(1,1) #else _uv[0] = new Short2((short)(textureInfo.u0*32767),(short)(textureInfo.v0*32767)); _uv[1] = new Short2((short)(textureInfo.u1*32767),(short)(textureInfo.v0*32767));//(1,0) _uv[2] = new Short2((short)(textureInfo.u0*32767),(short)(textureInfo.v1*32767));//(0,1) _uv[3] = new Short2((short)(textureInfo.u1*32767),(short)(textureInfo.v1*32767));//(1,1) #endif this.width = textureInfo.w; this.height = textureInfo.h; }