mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
make camera accurate
This commit is contained in:
parent
b9b111bf85
commit
d79c7a90e9
2 changed files with 29 additions and 5 deletions
|
|
@ -63,6 +63,7 @@ class CameraController extends Object {
|
|||
public var phi:Float;
|
||||
public var theta:Float;
|
||||
|
||||
var lastTargetPos:Vector;
|
||||
var lastCamPos:Vector;
|
||||
var lastVertTranslation:Vector;
|
||||
|
||||
|
|
@ -220,10 +221,19 @@ class CameraController extends Object {
|
|||
}
|
||||
var orientationQuat = level.getOrientationQuat(currentTime);
|
||||
|
||||
var cameraDistance = CameraDistance;
|
||||
|
||||
if (this.finish) {
|
||||
// Make the camera spin around slowly
|
||||
CameraPitch = this.level.finishPitch;
|
||||
CameraYaw = this.level.finishYaw;
|
||||
var effectTime = 1.0;
|
||||
if (@:privateAccess this.marble.finishAnimTime >= 2.0)
|
||||
effectTime = 1.0;
|
||||
else
|
||||
effectTime = @:privateAccess this.marble.finishAnimTime * 0.5;
|
||||
effectTime *= 0.5 * CameraDistance;
|
||||
cameraDistance += effectTime;
|
||||
}
|
||||
|
||||
if (!this.level.isWatching) {
|
||||
|
|
@ -236,6 +246,18 @@ class CameraController extends Object {
|
|||
}
|
||||
|
||||
var marblePosition = level.marble.collider.transform.getPosition();
|
||||
|
||||
if (this.finish) {
|
||||
// Move the target to the centre of the finish
|
||||
var padMat = @:privateAccess this.level.endPad.getAbsPos();
|
||||
var offset = padMat.up();
|
||||
var padPos = padMat.getPosition();
|
||||
var focusPos = padPos.add(offset);
|
||||
focusPos.scale(0.025);
|
||||
focusPos = focusPos.add(lastTargetPos.multiply(0.975));
|
||||
marblePosition = focusPos;
|
||||
}
|
||||
|
||||
var up = new Vector(0, 0, 1);
|
||||
up.transform(orientationQuat.toMatrix());
|
||||
var directionVector = new Vector(1, 0, 0);
|
||||
|
|
@ -244,14 +266,14 @@ class CameraController extends Object {
|
|||
var q1 = new Quat();
|
||||
q1.initRotateAxis(0, 1, 0, CameraPitch);
|
||||
directionVector.transform(q1.toMatrix());
|
||||
cameraVerticalTranslation.transform(q1.toMatrix());
|
||||
// cameraVerticalTranslation.transform(q1.toMatrix());
|
||||
q1.initRotateAxis(0, 0, 1, CameraYaw);
|
||||
directionVector.transform(q1.toMatrix());
|
||||
cameraVerticalTranslation.transform(q1.toMatrix());
|
||||
// cameraVerticalTranslation.transform(q1.toMatrix());
|
||||
directionVector.transform(orientationQuat.toMatrix());
|
||||
cameraVerticalTranslation.transform(orientationQuat.toMatrix());
|
||||
camera.up = up;
|
||||
camera.pos = marblePosition.sub(directionVector.multiply(CameraDistance));
|
||||
camera.pos = marblePosition.sub(directionVector.multiply(cameraDistance)).add(cameraVerticalTranslation);
|
||||
camera.target = marblePosition.add(cameraVerticalTranslation);
|
||||
|
||||
var closeness = 0.1;
|
||||
|
|
@ -278,7 +300,7 @@ class CameraController extends Object {
|
|||
}
|
||||
|
||||
if (firstHit != null) {
|
||||
if (firstHitDistance < CameraDistance) {
|
||||
if (firstHitDistance < cameraDistance) {
|
||||
// camera.pos = marblePosition.sub(directionVector.multiply(firstHit.distance * 0.7));
|
||||
var plane = new Plane(firstHit.normal.x, firstHit.normal.y, firstHit.normal.z, firstHit.point.dot(firstHit.normal));
|
||||
var normal = firstHit.normal.multiply(-1);
|
||||
|
|
@ -312,6 +334,7 @@ class CameraController extends Object {
|
|||
if (!oob) {
|
||||
lastCamPos = camera.pos;
|
||||
lastVertTranslation = cameraVerticalTranslation;
|
||||
lastTargetPos = marblePosition.clone();
|
||||
}
|
||||
|
||||
this.setPosition(camera.pos.x, camera.pos.y, camera.pos.z);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package shaders;
|
||||
|
||||
import src.MarbleGame;
|
||||
import h3d.scene.fwd.Light;
|
||||
|
||||
class DirLight extends Light {
|
||||
|
|
@ -33,7 +34,7 @@ class DirLight extends Light {
|
|||
}
|
||||
|
||||
override function getShadowDirection():h3d.Vector {
|
||||
return new h3d.Vector(0, 0, -1);
|
||||
return MarbleGame.instance.world.currentUp.multiply(-1);
|
||||
}
|
||||
|
||||
override function emit(ctx) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue