Smoother camera hermite move

This commit is contained in:
Thomas FORGIONE 2015-05-11 10:20:19 +02:00
parent 06976bd845
commit b1cf8afaaf
1 changed files with 86 additions and 77 deletions

View File

@ -64,7 +64,15 @@ PointerCamera.prototype.constructor = PointerCamera;
// Update function // Update function
PointerCamera.prototype.update = function() { PointerCamera.prototype.update = function() {
if (this.moving) { if (this.moving) {
// Linear motion this.linearMotion();
} else if (this.movingHermite) {
this.hermiteMotion();
} else {
this.normalMotion();
}
}
PointerCamera.prototype.linearMotion = function() {
var position_direction = Tools.diff(this.new_position, this.position); var position_direction = Tools.diff(this.new_position, this.position);
var target_direction = Tools.diff(this.new_target, this.target); var target_direction = Tools.diff(this.new_target, this.target);
@ -76,9 +84,9 @@ PointerCamera.prototype.update = function() {
this.moving = false; this.moving = false;
this.anglesFromVectors(); this.anglesFromVectors();
} }
}
} else if (this.movingHermite) { PointerCamera.prototype.hermiteMotion = function() {
// Hermite polynom version
var eval = this.hermitePosition.eval(this.t); var eval = this.hermitePosition.eval(this.t);
this.position.x = eval.x; this.position.x = eval.x;
this.position.y = eval.y; this.position.y = eval.y;
@ -92,7 +100,9 @@ PointerCamera.prototype.update = function() {
this.movingHermite = false; this.movingHermite = false;
this.anglesFromVectors(); this.anglesFromVectors();
} }
} else { }
PointerCamera.prototype.normalMotion = function() {
// Update angles // Update angles
if (this.increasePhi) {this.phi += this.sensitivity; this.changed = true; } if (this.increasePhi) {this.phi += this.sensitivity; this.changed = true; }
if (this.decreasePhi) {this.phi -= this.sensitivity; this.changed = true; } if (this.decreasePhi) {this.phi -= this.sensitivity; this.changed = true; }
@ -143,7 +153,6 @@ PointerCamera.prototype.update = function() {
this.target = this.position.clone(); this.target = this.position.clone();
this.target.add(forward); this.target.add(forward);
} }
}
PointerCamera.prototype.reset = function() { PointerCamera.prototype.reset = function() {
this.position.copy(new THREE.Vector3(-8.849933489419644, 9.050627639459208, 0.6192960680432451)); this.position.copy(new THREE.Vector3(-8.849933489419644, 9.050627639459208, 0.6192960680432451));
@ -206,7 +215,7 @@ PointerCamera.prototype.moveHermite = function(otherCamera, toSave) {
this.hermitePosition = new Hermite.special.Polynom( this.hermitePosition = new Hermite.special.Polynom(
this.position.clone(), this.position.clone(),
otherCamera.position.clone(), otherCamera.position.clone(),
Tools.diff(otherCamera.target, otherCamera.position) Tools.mul(Tools.diff(otherCamera.target, otherCamera.position).normalize(),4)
); );
this.hermiteAngles = new Hermite.special.Polynom( this.hermiteAngles = new Hermite.special.Polynom(