public void Render(KBuild build, KAnimBank bank, int frameNumber) { Matrix4 modelMat = Matrix4.Identity; Matrix4 pivotMat = Matrix4.Identity; Matrix4 transformMat = Matrix4.Identity; geoShader.Activate(); // Draw Origin geoShader.SetUniform("Model", ref modelMat); origin.Draw(); if (frameNumber < 0 || frameNumber >= bank.FrameCount) { frameNumber = 0; } KAnimFrame frame = bank.Frames[frameNumber]; Matrix4 frameMat = Matrix4.CreateTranslation(frame.X, frame.Y, 0); spriteShader.Activate(); texture.Bind(); for (int i = frame.ElementCount - 1; i >= 0; i--) { KAnimElement element = frame.Elements[i]; string symbol = build.GetSymbolName(element.SymbolHash); if (symbol == null) { continue; } KFrame sprite = build.GetFrame(symbol, element.FrameNumber); if (sprite == null) { continue; } pivotMat = Matrix4.CreateTranslation(sprite.PivotX, sprite.PivotY, 0); transformMat = new Matrix4( element.M00, -element.M10, 0, 0, element.M01, -element.M11, 0, 0, 0, 0, -1, 0, element.M02, -element.M12, 0, 1 ); modelMat = halfScaleMat * pivotMat * transformMat; spriteShader.SetUniform("Model", ref modelMat); MakeQuadVBO(sprite.PivotWidth, sprite.PivotHeight, element.Red, element.Green, element.Blue, element.Alpha, sprite.GetUVRectangle(), out Vertex[] vertices, out int[] elements); quad.SetData(OpenTK.Graphics.OpenGL.PrimitiveType.Triangles, vertices, elements); quad.Draw(); } }
private void listBoxBanks_SelectedIndexChanged(object sender, System.EventArgs e) { if (listBoxBanks.SelectedIndex < 0) { SelectedBank = null; } else { SelectedBank = listBoxBanks.SelectedItem as KAnimBank; } currentFrame = 0; textBoxFrameNumber.Text = currentFrame.ToString(); display.Invalidate(); }