Skip to content

Instantly share code, notes, and snippets.

@shivshank
Created November 8, 2015 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shivshank/79ef6d2d7780cb69676a to your computer and use it in GitHub Desktop.
Save shivshank/79ef6d2d7780cb69676a to your computer and use it in GitHub Desktop.
A simple 2D Java Renderer (incomplete example implemenation)
/* An example implemenation of data structures to support a 2D Renderer in (semi) Java... */
class abstract Body {
public Vector2f posNext;
public Vector2f posPrev;
/**
* The actual position of the object at time t = t0 + dt * alpha.
*/
protected Vector2f pos = new Vector2f(0f, 0f);
protected void interpolatePos(float alpha) {
// Maybe everything should be converted to double and then back to float?
// Not sure if that will help precision.. I don't even think the precision really matters here, though.
pos.x = posPrev.x + alpha * (posNext.x - posPrev.x);
pos.y = posPrev.y + alpha * (posNext.y - posPrev.y);
}
public abstract void draw(double alpha);
}
/**
* A Particle is a simple colored polygon.
*/
class Particle {
}
class Sprite {
}
class Mesh {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment