I was reading through the Vector2f code the other day and found a few things that could be improved:
in the setTheta method these lines of code are unused.
Code:
double oldTheta = getTheta();
if ((theta < -360) || (theta > 360)) {
oldTheta = oldTheta % 360;
}
if (theta < 0) {
oldTheta = 360 + oldTheta;
}
also in getTheta these lines are unnecessary as atan2 wont return a value outside +-PI.
Code:
if ((theta < -360) || (theta > 360)) {
theta = theta % 360;
}
While i was playing around i also noticed that slick uses a FastTrig lib for cos and sin. So i figured i might post this here:
http://http.developer.nvidia.com/Cg/atan2.htmlTranslated to java:
Code:
private float atan2(float y, float x)
{
float t0, t1, t3, t4;
float xAbs = Math.abs(x);
float yAbs = Math.abs(y);
t3 = xAbs;
t1 = yAbs;
t0 = Math.max(t3, t1);
t1 = Math.min(t3, t1);
t3 = 1f / t0;
t3 = t1 * t3;
t4 = t3 * t3;
t0 = - 0.013480470f;
t0 = t0 * t4 + 0.057477314f;
t0 = t0 * t4 - 0.121239071f;
t0 = t0 * t4 + 0.195635925f;
t0 = t0 * t4 - 0.332994597f;
t0 = t0 * t4 + 0.999995630f;
t3 = t0 * t3;
t3 = (yAbs > xAbs) ? 1.570796327f - t3 : t3;
t3 = (x < 0) ? 3.141592654f - t3 : t3;
t3 = (y < 0) ? -t3 : t3;
return t3;
}
In the particles code i found that slick doesn't use java generics and casts to ParticleEmitter and ParticlePool a whole lot.
A while back i rewrote the particle code myself and could get rid of all the casts, though i did not test if there was any performance gain.