forked from rpereira-dev/CubeEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added camera destinations + pop ups on editor
- Loading branch information
rpereira
committed
Jan 23, 2018
1 parent
eba7af0
commit 97bb198
Showing
23 changed files
with
512 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
VoxelEngine/src/com/grillecube/client/renderer/camera/CameraDestination.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.grillecube.client.renderer.camera; | ||
|
||
public abstract class CameraDestination<T extends Camera> { | ||
|
||
private final float duration; | ||
private float accumulator; | ||
|
||
public CameraDestination(float duration) { | ||
this.duration = duration; | ||
} | ||
|
||
public final void init(T camera) { | ||
this.accumulator = 0; | ||
this.onInit(camera); | ||
} | ||
|
||
protected abstract void onInit(T camera); | ||
|
||
/** | ||
* | ||
* @param cameraView | ||
* @param dt | ||
* @return true if the destination is reached | ||
*/ | ||
public boolean update(T camera, float dt) { | ||
this.accumulator += dt; | ||
if (this.accumulator >= this.duration) { | ||
this.onReached(camera); | ||
return (true); | ||
} | ||
this.onUpdate(camera, this.accumulator / this.duration); | ||
return (false); | ||
} | ||
|
||
/** a callback on destination update (ratio is in [0, 1] */ | ||
protected abstract void onUpdate(T camera, float ratio); | ||
|
||
/** a callback whenever the destination is reached */ | ||
protected abstract void onReached(T camera); | ||
} |
49 changes: 49 additions & 0 deletions
49
VoxelEngine/src/com/grillecube/client/renderer/camera/CameraDestinationCenter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.grillecube.client.renderer.camera; | ||
|
||
public class CameraDestinationCenter extends CameraDestination<CameraPerspectiveWorldCentered> { | ||
|
||
public final float desiredDistance; | ||
public final float desiredPhi; | ||
public final float desiredTheta; | ||
|
||
public float camDistance; | ||
public float camPhi; | ||
public float camTheta; | ||
|
||
/** | ||
* | ||
* @param desiredPosition | ||
* : future position of the camera | ||
* @param desiredRotation | ||
* : future rotation of the camera | ||
* @param duration | ||
* : duration of the transition | ||
*/ | ||
public CameraDestinationCenter(float desiredDistance, float desiredPhi, float desiredTheta, float duration) { | ||
super(duration); | ||
this.desiredDistance = desiredDistance; | ||
this.desiredPhi = desiredPhi; | ||
this.desiredTheta = desiredTheta; | ||
} | ||
|
||
@Override | ||
protected final void onInit(CameraPerspectiveWorldCentered camera) { | ||
this.camDistance = camera.getR(); | ||
this.camPhi = camera.getPhi(); | ||
this.camTheta = camera.getTheta(); | ||
} | ||
|
||
@Override | ||
protected final void onUpdate(CameraPerspectiveWorldCentered camera, float ratio) { | ||
camera.setR(this.camDistance * (1.0f - ratio) + this.desiredDistance * ratio); | ||
camera.setPhi(this.camPhi * (1.0f - ratio) + this.desiredPhi * ratio); | ||
camera.setTheta(this.camTheta * (1.0f - ratio) + this.desiredTheta * ratio); | ||
} | ||
|
||
@Override | ||
protected final void onReached(CameraPerspectiveWorldCentered camera) { | ||
camera.setR(this.desiredDistance); | ||
camera.setPhi(this.desiredPhi); | ||
camera.setTheta(this.desiredTheta); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
VoxelEngine/src/com/grillecube/client/renderer/camera/CameraDestinationRaw.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.grillecube.client.renderer.camera; | ||
|
||
import com.grillecube.common.maths.Quaternion; | ||
import com.grillecube.common.maths.Vector3f; | ||
|
||
public class CameraDestinationRaw extends CameraDestination<CameraView> { | ||
|
||
public final Vector3f desiredPosition; | ||
public final Quaternion desiredRotation; | ||
|
||
private Vector3f camPos; | ||
private Quaternion camRot; | ||
|
||
/** | ||
* | ||
* @param desiredPosition | ||
* : future position of the camera | ||
* @param desiredRotation | ||
* this.accumulator = 0; | ||
* | ||
* : future rotation of the camera | ||
* @param duration | ||
* : duration of the transition | ||
*/ | ||
public CameraDestinationRaw(Vector3f desiredPosition, Quaternion desiredRotation, float duration) { | ||
super(duration); | ||
this.desiredPosition = desiredPosition; | ||
this.desiredRotation = desiredRotation; | ||
} | ||
|
||
@Override | ||
protected final void onInit(CameraView camera) { | ||
this.camRot = new Quaternion(); | ||
this.camPos = new Vector3f(); | ||
this.camPos.set(camera.getPosition()); | ||
this.camRot.set(Quaternion.toQuaternion(camera.getRot())); | ||
} | ||
|
||
@Override | ||
protected final void onUpdate(CameraView camera, float ratio) { | ||
camera.setPosition(Vector3f.interpolate(this.camPos, this.desiredPosition, ratio, null)); | ||
camera.setRot(Quaternion.toEulerAngle(Quaternion.interpolate(this.camRot, this.desiredRotation, ratio))); | ||
} | ||
|
||
@Override | ||
protected final void onReached(CameraView camera) { | ||
camera.setPosition(this.desiredPosition); | ||
camera.setRot(Quaternion.toEulerAngle(this.desiredRotation)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.