41 lines
1.5 KiB
Java
41 lines
1.5 KiB
Java
package electrosphere.renderer;
|
|
|
|
import org.joml.Matrix4f;
|
|
import org.joml.Quaternionf;
|
|
import org.joml.Vector3f;
|
|
|
|
/**
|
|
*
|
|
* @author satellite
|
|
*/
|
|
@Deprecated
|
|
public class Camera {
|
|
public Vector3f pos_Center = new Vector3f(0,0,0);
|
|
// public Vector3f pos_Front = new Vector3f(0,0,0);
|
|
// public Vector3f pos_Top = new Vector3f(0,0,0);
|
|
public Quaternionf rotation = new Quaternionf();
|
|
public Camera(){
|
|
|
|
}
|
|
|
|
public void apply_camera(Camera c){
|
|
pos_Center = new Vector3f(c.pos_Center);
|
|
rotation = new Quaternionf(c.rotation);
|
|
}
|
|
|
|
public Matrix4f get_view_matrix(){
|
|
Matrix4f rVal = new Matrix4f();
|
|
// rVal.setLookAt(pos_Center, pos_Front, pos_Top);
|
|
Vector3f up = new Vector3f(pos_Center);
|
|
//new Vector3f(pos_Center).add(new Quaternionf(rotation)..transform(new Vector3f(1,0,0)))
|
|
Vector3f up_modifier = new Vector3f(1,0,0);
|
|
Quaternionf up_transformation = new Quaternionf(rotation);
|
|
up_transformation.rotateAxis((float)Math.PI/2.0f, new Vector3f(up).cross(new Vector3f(0,1,0))); // the hard part is getting the axis in this logic to correspond to the vertical
|
|
up = up.add(up_transformation.transform(up_modifier));
|
|
rVal.setLookAt(pos_Center, //where our camera is
|
|
new Vector3f(pos_Center).add(rotation.transform(new Vector3f(1,0,0))), //where our camera wants to look
|
|
up); //where "up" is relative to our camera
|
|
return rVal;
|
|
}
|
|
}
|