Doc pour Engine + Introduction Tracking Tore
This commit is contained in:
37
src/engine/camera/Camera.java
Normal file
37
src/engine/camera/Camera.java
Normal file
@ -0,0 +1,37 @@
|
||||
package engine.camera;
|
||||
|
||||
import engine.Engine;
|
||||
import engine.math.Matrix4f;
|
||||
import engine.math.Vector3f;
|
||||
import engine.object.ObjectGl;
|
||||
|
||||
public class Camera {
|
||||
|
||||
private float dimension;
|
||||
private final Vector3f aspectRatio;
|
||||
private final Engine engine;
|
||||
|
||||
|
||||
public Camera(float dimension, Vector3f aspectRatio, Engine engine){
|
||||
this.dimension = dimension;
|
||||
this.aspectRatio = aspectRatio;
|
||||
this.engine = engine;
|
||||
float ar = aspectRatio.y / aspectRatio.x;
|
||||
ObjectGl.projection = Matrix4f.orthographic(-dimension, dimension, -dimension * ar, dimension * ar, 0.1f, 100.0f);
|
||||
}
|
||||
|
||||
public void zoom(float zoomFactor){
|
||||
engine.setUIElementZoomFactor(zoomFactor);
|
||||
this.dimension *= zoomFactor;
|
||||
float ar = aspectRatio.y / aspectRatio.x;
|
||||
ObjectGl.projection = Matrix4f.orthographic(-dimension, dimension, -dimension * ar, dimension * ar, 0.1f, 100.0f);
|
||||
}
|
||||
|
||||
public float getDimension(){
|
||||
return this.dimension;
|
||||
}
|
||||
|
||||
public Vector3f getAspectRatio(){
|
||||
return this.aspectRatio;
|
||||
}
|
||||
}
|
9
src/engine/camera/TrackingDummy.java
Normal file
9
src/engine/camera/TrackingDummy.java
Normal file
@ -0,0 +1,9 @@
|
||||
package engine.camera;
|
||||
|
||||
import engine.math.Vector3f;
|
||||
|
||||
public interface TrackingDummy {
|
||||
|
||||
public Vector3f getViewVector();
|
||||
|
||||
}
|
52
src/engine/camera/TrackingTore.java
Normal file
52
src/engine/camera/TrackingTore.java
Normal file
@ -0,0 +1,52 @@
|
||||
package engine.camera;
|
||||
|
||||
import engine.Engine;
|
||||
import engine.math.Vector3f;
|
||||
import engine.object.ObjectGl;
|
||||
|
||||
public class TrackingTore implements TrackingDummy {
|
||||
|
||||
private float rayonExt;
|
||||
private final float offset;
|
||||
private final ObjectGl obj1;
|
||||
private final ObjectGl obj2;
|
||||
private final Engine engine;
|
||||
|
||||
public TrackingTore(float offset, ObjectGl obj1, ObjectGl obj2, Engine engine){
|
||||
this.rayonExt = offset;
|
||||
this.offset = offset;
|
||||
this.obj1 = obj1;
|
||||
this.obj2 = obj2;
|
||||
this.engine = engine;
|
||||
}
|
||||
|
||||
public Vector3f getViewVector(){
|
||||
Vector3f vec = new Vector3f(0.0f,0.0f,0.0f);
|
||||
|
||||
//which object is to the left
|
||||
ObjectGl left = obj1.getXPos() >= obj2.getXPos() ? obj2 : obj1;
|
||||
ObjectGl right = obj1.getXPos() < obj2.getXPos() ? obj2 : obj1;
|
||||
|
||||
//Track his current position and other useful data
|
||||
float xPos = this.engine.getViewXPos();
|
||||
float dimension = this.engine.getCamera().getDimension();
|
||||
float distance = Math.abs(left.getXPos() - right.getXPos()) + right.getWidth() * right.getScalingFactor();
|
||||
float middle_point = (left.getXPos() + right.getXPos() + right.getWidth() * right.getScalingFactor()) / 2;
|
||||
|
||||
if (left.getXPos() < xPos - rayonExt){
|
||||
// Il faut décaler à gauche + dezoom
|
||||
vec.x = - middle_point - xPos;
|
||||
this.rayonExt = Math.abs(left.getXPos() - xPos);
|
||||
//mtn on dezoom il faut calculer le rapport necessaire pour avoir les deux objets dans le champs
|
||||
this.engine.getCamera().zoom(distance/dimension);
|
||||
} else if(left.getXPos() > xPos - rayonExt + offset){
|
||||
// this.engine.getCamera().zoom(dimension/distance);
|
||||
// Il faut décaler à droite + zoom
|
||||
} else if(right.getXPos() > xPos + rayonExt){
|
||||
// Il faut décaler à droite + dezoom
|
||||
} else if(right.getXPos() < xPos + rayonExt - offset){
|
||||
// Il faut décaler à gauche + zoom
|
||||
}
|
||||
return vec;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user