Added movement with angle with arrows

This commit is contained in:
Thomas FORGIONE 2015-05-05 16:49:00 +02:00
parent 4cc35587ef
commit 2389763c5f
2 changed files with 44 additions and 1 deletions

View File

@ -77,6 +77,21 @@ PointerCamera.prototype.update = function() {
this.anglesFromVectors(); this.anglesFromVectors();
} }
} else if (this.movingHermite) {
// Hermite polynom version
var eval = this.hermitePosition.eval(this.t);
this.position.x = eval.x;
this.position.y = eval.y;
this.position.z = eval.z;
this.target = Tools.sum(this.position, this.hermiteAngles.eval(this.t));
this.t += 0.005;
if (this.t > 1) {
this.movingHermite = false;
this.anglesFromVectors();
}
} else { } else {
// Update angles // Update angles
if (this.increasePhi) {this.phi += this.sensitivity; this.changed = true; } if (this.increasePhi) {this.phi += this.sensitivity; this.changed = true; }
@ -181,6 +196,34 @@ PointerCamera.prototype.move = function(otherCamera, toSave) {
} }
} }
PointerCamera.prototype.moveHermite = function(otherCamera, toSave) {
if (toSave === undefined)
toSave = true;
this.movingHermite = true;
this.t = 0;
this.hermitePosition = new Hermite.special.Polynom(
this.position.clone(),
otherCamera.position.clone(),
Tools.diff(otherCamera.target, otherCamera.position)
);
this.hermiteAngles = new Hermite.special.Polynom(
Tools.diff(this.target, this.position),
Tools.diff(otherCamera.target, otherCamera.position),
new THREE.Vector3()
);
if (toSave) {
if (this.changed) {
this.save();
this.changed = false;
}
this.history.addState({position: otherCamera.position.clone(), target: otherCamera.target.clone()});
}
}
PointerCamera.prototype.isColliding = function(direction) { PointerCamera.prototype.isColliding = function(direction) {
this.raycaster.set(this.position, direction.clone().normalize()); this.raycaster.set(this.position, direction.clone().normalize());
var intersects = this.raycaster.intersectObjects(this.collidableObjects, true); var intersects = this.raycaster.intersectObjects(this.collidableObjects, true);

View File

@ -505,7 +505,7 @@ function updateMouse(event) {
function click(event) { function click(event) {
var newCamera = pointedCamera(event); var newCamera = pointedCamera(event);
if (newCamera !== undefined) { if (newCamera !== undefined) {
cameras.mainCamera().move(newCamera); cameras.mainCamera().moveHermite(newCamera);
updateElements(); updateElements();
} }
} }