public override void DrawLayerQuad(vf2d offset, vf2d scale, Pixel tint) { GL.BindBuffer(BufferTarget.ArrayBuffer, m_vbQuad); const int numVerts = 4; const float voffset = 1f; Bvert[] verts = new Bvert[numVerts] { new Bvert(new float[5] { -voffset, -voffset, 1.0f, 0.0f * scale.x + offset.x, 1.0f * scale.y + offset.y }, tint), new Bvert(new float[5] { +voffset, -voffset, 1.0f, 1.0f * scale.x + offset.x, 1.0f * scale.y + offset.y }, tint), new Bvert(new float[5] { -voffset, +voffset, 1.0f, 0.0f * scale.x + offset.x, 0.0f * scale.y + offset.y }, tint), new Bvert(new float[5] { +voffset, +voffset, 1.0f, 1.0f * scale.x + offset.x, 0.0f * scale.y + offset.y }, tint) }; GL.BufferData(BufferTarget.ArrayBuffer, sizeof(Bvert) * numVerts, verts, BufferUsageHint.StreamDraw); GL.DrawArrays(PrimitiveType.TriangleStrip, 0, 4); }
public override bool OnUserCreate() { _controller = new ImGuiController(ScreenWidth(), ScreenHeight(), this); velocity = new vf2d(0, 0); offset = new vf2d(0, 0); map = new Pixel[mapWidth, mapHeight]; intMap = new int[mapWidth, mapHeight]; Random rng = new Random(); for (int y = 0; y < mapHeight; y++) { for (int x = 0; x < mapWidth; x++) { map[x, y] = new Pixel(x / (float)mapWidth, y / (float)mapHeight, 1f - (y / (float)mapHeight), 1f); intMap[x, y] = rng.Next(20); } } spr = new Sprite(0, 0); spr.LoadFromFile("assets/spritesheet03.png"); decal = new Decal(spr); mGameLayer = CreateLayer(); EnableLayer(mGameLayer, true); SetLayerCustomRenderFunction(mGameLayer, DrawImGui); return(true); }
public GameObject(PixelGameEngine pge, vf2d pos) { this.Pos = pos; this.pge = pge; Vel = new vf2d(0.01f, 0.02f); Acc = new vf2d(0, 0); Ang = 0; }
public void Update() { if (sprite == null) { return; } vUVScale = new vf2d(1.0f / (float)sprite.width, 1.0f / (float)sprite.height); Const.renderer.ApplyTexture(id); Const.renderer.UpdateTexture(id, sprite); }
private float getTriangleDistance(vf2d a1, vf2d a2, vf2d a3) { var distance = getDistance(a1, a2); distance += getDistance(a2, a3); distance += getDistance(a3, a1); mindist = Math.Min(distance, mindist); maxdist = Math.Max(distance, maxdist); return(distance); }
public void DrawCell(int x, int y, int gridX, int gridY, vf2d offset, float scale, Pixel celldata, int mapData) { int nx = (int)(gridX + x * (size * scale) - ((size * scale) * offset.x)); int ny = (int)(gridY + y * (size * scale) - ((size * scale) * offset.y)); //FillRect(nx, ny, (int)(size*scale), (int)(size*scale), celldata); DrawSprite(nx, ny, mapData, scale); //DrawRect(nx, ny, (int)(size * scale), (int)(size * scale), celldata); //DrawString(nx+10,ny+10, (celldata.r).ToString(), Pixel.WHITE); }
public Bvert(float[] pos, vf2d text, Pixel col) { this.x = pos[0]; this.y = pos[1]; this.z = pos[2]; this.tx = text.x; this.ty = text.y; this.r = col.r; this.g = col.g; this.b = col.b; this.a = col.a; }
public Bvert(float[] pos, vf2d text, byte r, byte g, byte b, byte a = 255) { this.x = pos[0]; this.y = pos[1]; this.z = pos[2]; this.tx = text.x; this.ty = text.y; this.r = r; this.g = g; this.b = b; this.a = a; }
public override bool OnUserUpdate(float fElapsedTime) { vf2d v = new vf2d(1, 1); //VectorF2d f = v.norm int offsetx = (ScreenWidth() / 2) - ((fw / 2) * spacing_scale); int offsety = (ScreenHeight() / 2) - ((fh / 2) * spacing_scale); if (GetKey(Key.SPACE).bPressed) { flag = !flag; } if (GetKey(Key.T).bPressed) { showTriangle = !showTriangle; } if (GetKey(Key.P).bPressed) { showPixel = !showPixel; } if (GetKey(Key.LEFT).bPressed) { wavefunction++; wavefunction = wavefunction % 4; } if (GetKey(Key.RIGHT).bPressed) { wavefunction--; wavefunction = Math.Abs(wavefunction % 4); } Clear(Pixel.BLACK); int spacingX = spacing_scale; int spacingY = spacing_scale; vf2d[,] flagMap = new vf2d[fw, fh]; for (int y = 0; y < fh; y++) { for (int x = 0; x < fw; x++) { Pixel col = Pixel.MAGENTA; col = flagColors(x, y); int xo = offsetx + (x * spacingX); int yo = offsety + (y * spacingY); float index = i - (x / 1f) - (y / 1.25f); float cx = 0; float cy = 0; switch (wavefunction) { case 0: cx = (float)Math.Cos(index + x) * (y * 0.25f) * 1.5f + xo; cy = (float)Math.Sin(index + y) * (x * 0.25f) * 1.5f + yo; break; case 1: cx = (float)Math.Cos(index + y) * (y * 0.25f) * 1.5f + xo; cy = (float)Math.Sin(index + x) * (x * 0.25f) * 1.5f + yo; break; case 2: cx = (float)Math.Cos(index + y) * (x * 0.25f) * 1.5f + xo; cy = (float)Math.Cos(index + x) * (y * 0.25f) * 1.5f + yo; break; case 3: cx = (float)Math.Cos(index) * 1.5f + xo; cy = (float)Math.Sin(index) * 1.5f + yo; break; } flagMap[x, y] = new vf2d(cx, cy); } } for (int y = 0; y < fh - 1; y++) { for (int x = 0; x < fw - 1; x++) { if (showTriangle) { var distance = getTriangleDistance(flagMap[x, y], flagMap[x + 1, y], flagMap[x, y + 1]); FillTriangle(flagMap[x, y], flagMap[x + 1, y], flagMap[x, y + 1], getFancyColor(flagColors(x, y), distance)); distance = getTriangleDistance(flagMap[x, y + 1], flagMap[x + 1, y + 1], flagMap[x + 1, y]); FillTriangle(flagMap[x, y + 1], flagMap[x + 1, y + 1], flagMap[x + 1, y], getFancyColor(flagColors(x, y), distance)); } if (showPixel) { Draw(flagMap[x, y], flagColors(x, y)); } } } //i++; i += fElapsedTime * 10; return(true); }
private float getDistance(vf2d start, vf2d end) { var distance = (float)Math.Sqrt(Math.Pow((end.y - start.y), 2) + Math.Pow((end.x - start.x), 2)); return(distance); }
public abstract void DrawLayerQuad(vf2d offset, vf2d scale, Pixel tint);