I just though somebody might find this useful!
public class Rotation3D {
public static vec3 point(vec3 center, vec3 point, float xr, float yr, float zr) {
vec3 p = point.copy();
p = Rotation3D.rotateX(center, p, xr);
p = Rotation3D.rotateY(center, p, yr);
p = Rotation3D.rotateZ(center, p, zr);
return p;
}
public static vec3 rotateX(vec3 center, vec3 point, float xr) {
float xrot = (float) Math.toRadians(xr);
float px = point.x;
float py = point.y;
float pz = point.z;
float x = px;
float y = (float) (Math.cos(xrot) * py - Math.sin(xrot) * pz);
float z = (float) (Math.sin(xrot) * py + Math.cos(xrot) * pz);
return new vec3(x, y, z);
}
public static vec3 rotateY(vec3 center, vec3 point, float yr) {
float yrot = (float) Math.toRadians(yr);
float px = point.x;
float py = point.y;
float pz = point.z;
float x = (float) (Math.cos(yrot) * px + Math.sin(yrot) * pz);
float y = (float) py;
float z = (float) (-Math.sin(yrot) * px + Math.cos(yrot) * pz);
return new vec3(x, y, z);
}
public static vec3 rotateZ(vec3 center, vec3 point, float zr) {
float zrot = -(float) Math.toRadians(zr);
float px = point.x;
float py = point.y;
float pz = point.z;
float x = (float) (Math.cos(zrot) * px - Math.sin(zrot) * py);
float y = (float) (Math.sin(zrot) * px + Math.cos(zrot) * py);
float z = pz;
return new vec3(x, y, z);
}
}
I have done this using wikipedia on rotation matrices.
PS
vec3 is just a class which stores xyz floats