Fixed jumpy interpolation caused by multiple interpolations per frame.
This commit is contained in:
parent
d576600885
commit
c28261dcfa
@ -180,9 +180,9 @@ namespace SlatedGameToolkit.Framework.Graphics
|
||||
Logger.Log(string.Format("Camera initial dimensions: {0}x{1}, ratio of view: {2}", width, height, width / height), LogLevel.DEBUG);
|
||||
}
|
||||
|
||||
public void InterpolatePosition(float delta)
|
||||
public void InterpolatePosition(double delta)
|
||||
{
|
||||
this.Position += delta * (MoveTo - Position);
|
||||
this.Position += (float) delta * (MoveTo - Position);
|
||||
}
|
||||
}
|
||||
}
|
@ -5,9 +5,9 @@ namespace SlatedGameToolkit.Framework.Graphics.Render
|
||||
public interface IPositionInterpolable
|
||||
{
|
||||
/// <summary>
|
||||
/// Is called between each update to allow rendered meshes to be interpolated between positions and time steps.
|
||||
/// Allows this object to perform interpolation based on the position (delta) between the update frames.
|
||||
/// </summary>
|
||||
/// <param name="delta">A normalized value between [0, 1] representing the current position between the updates.</param>
|
||||
void InterpolatePosition(float delta);
|
||||
void InterpolatePosition(double delta);
|
||||
}
|
||||
}
|
@ -20,7 +20,6 @@ namespace SlatedGameToolkit.Framework.Graphics.Render
|
||||
public bool Debug { get; set; }
|
||||
private const int VERTEX_LENGTH = 9;
|
||||
private bool disposed;
|
||||
private float batchDelta;
|
||||
public GLContext GLContext {get; private set; }
|
||||
private int projULoc, viewULoc, modelULoc, texturedULoc, singleChanneledULoc, flippedULoc;
|
||||
private Camera camera;
|
||||
@ -123,12 +122,10 @@ namespace SlatedGameToolkit.Framework.Graphics.Render
|
||||
/// </summary>
|
||||
/// <param name="modelsMatrix">The models matrix.</param>
|
||||
/// <param name="delta">The time elapsed since the last update.</param>
|
||||
public virtual void Begin(Matrix4x4 modelsMatrix, double delta) {
|
||||
public virtual void Begin(Matrix4x4 modelsMatrix) {
|
||||
if (Batching) throw new InvalidOperationException("This batch is already started.");
|
||||
this.Batching = true;
|
||||
this.modelsMatrix = modelsMatrix;
|
||||
|
||||
this.batchDelta = (float)delta;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -137,10 +134,6 @@ namespace SlatedGameToolkit.Framework.Graphics.Render
|
||||
/// <param name="mesh">Draws the given mesh.</param>
|
||||
public virtual void Draw(IMesh mesh) {
|
||||
if (!Batching) throw new InvalidOperationException("This batch has not been begun.");
|
||||
IPositionInterpolable moveable = mesh as IPositionInterpolable;
|
||||
if (moveable != null) {
|
||||
moveable.InterpolatePosition(batchDelta);
|
||||
}
|
||||
if (mesh.Texture?.Handle != this.texture?.Handle) {
|
||||
Flush();
|
||||
this.texture = mesh.Texture;
|
||||
@ -200,8 +193,6 @@ namespace SlatedGameToolkit.Framework.Graphics.Render
|
||||
GLContext.BindTexture(TextureTarget.Texture2D, texture.Handle);
|
||||
}
|
||||
renderProgram.Use();
|
||||
camera.InterpolatePosition(batchDelta);
|
||||
|
||||
vertexBuffers.BufferVertices(data, true);
|
||||
vertexBuffers.BufferIndices(indices, true);
|
||||
GLContext.UniformMatrix4fv(modelULoc, 1, false, modelsMatrix.ToColumnMajorArray());
|
||||
|
@ -9,8 +9,8 @@ namespace SlatedGameToolkit.Framework.Graphics.Render
|
||||
{
|
||||
private Matrix4x4 matRot;
|
||||
private bool changed;
|
||||
private RectangleF rectangle;
|
||||
private Vector3 rotation;
|
||||
private Vector2 origin, dimensions;
|
||||
private RectangleF textureBounds;
|
||||
private ValueTuple<Vector3, Vector2>[] vertices;
|
||||
private uint[] indices;
|
||||
@ -26,26 +26,26 @@ namespace SlatedGameToolkit.Framework.Graphics.Render
|
||||
public float X {
|
||||
get
|
||||
{
|
||||
return origin.X;
|
||||
return rectangle.X;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
changed = true;
|
||||
origin.X = value;
|
||||
rectangle.X = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float Y {
|
||||
get
|
||||
{
|
||||
return origin.Y;
|
||||
return rectangle.Y;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
changed = true;
|
||||
origin.Y = value;
|
||||
rectangle.Y = value;
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,13 +53,13 @@ namespace SlatedGameToolkit.Framework.Graphics.Render
|
||||
{
|
||||
get
|
||||
{
|
||||
return dimensions.X;
|
||||
return rectangle.Width;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
changed = true;
|
||||
dimensions.X = value;
|
||||
rectangle.Width = value;
|
||||
}
|
||||
}
|
||||
|
||||
@ -67,14 +67,14 @@ namespace SlatedGameToolkit.Framework.Graphics.Render
|
||||
{
|
||||
get
|
||||
{
|
||||
return dimensions.Y;
|
||||
return rectangle.Height;
|
||||
}
|
||||
|
||||
|
||||
set
|
||||
{
|
||||
changed = true;
|
||||
dimensions.Y = value;
|
||||
rectangle.Height = value;
|
||||
}
|
||||
}
|
||||
|
||||
@ -140,8 +140,7 @@ namespace SlatedGameToolkit.Framework.Graphics.Render
|
||||
public RectangleMesh(RectangleF meshBounds, ITexture texture, Color color) {
|
||||
this.changed = true;
|
||||
this.rotation = Vector3.Zero;
|
||||
this.origin = Vector2.Zero;
|
||||
this.dimensions = Vector2.Zero;
|
||||
this.rectangle = RectangleF.Empty;
|
||||
this.Texture = texture;
|
||||
this.Color = color;
|
||||
this.indices = new uint[] {0, 1, 3, 1, 2, 3};
|
||||
@ -166,10 +165,10 @@ namespace SlatedGameToolkit.Framework.Graphics.Render
|
||||
private void CalculateVertices() {
|
||||
if (!changed) return;
|
||||
Vector3[] baseVerts = new Vector3[4];
|
||||
baseVerts[0] = new Vector3(this.origin, 0);
|
||||
baseVerts[1] = new Vector3(this.origin.X + this.dimensions.X, this.origin.Y, 0);
|
||||
baseVerts[2] = new Vector3(baseVerts[1].X, this.origin.Y + this.dimensions.Y, 0);
|
||||
baseVerts[3] = new Vector3(this.origin.X, baseVerts[2].Y, 0);
|
||||
baseVerts[0] = new Vector3(this.rectangle.X, this.rectangle.Y, 0);
|
||||
baseVerts[1] = new Vector3(this.rectangle.Right, this.rectangle.Y, 0);
|
||||
baseVerts[2] = new Vector3(baseVerts[1].X, this.rectangle.Bottom, 0);
|
||||
baseVerts[3] = new Vector3(this.rectangle.X, baseVerts[2].Y, 0);
|
||||
|
||||
for (int i = 0; i < vertices.Length; i++)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user