Skip to content
Snippets Groups Projects
Commit 0469a338 authored by Amanda Ghassaei's avatar Amanda Ghassaei
Browse files

rotation working again

parent 45b53205
No related branches found
No related tags found
No related merge requests found
...@@ -224,15 +224,13 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', ' ...@@ -224,15 +224,13 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', '
}; };
Assembler.prototype.pickUpStock = function(index, position, speed, settings, callback){ Assembler.prototype.pickUpStock = function(index, position, speed, settings, callback){
if (index.z%2 != 0) {//rotate on odd rows
this.components.frame.rotateTo(new THREE.Vector3(0, 0, Math.PI/2), speed, callback);
} else {
this.components.frame.rotateTo(new THREE.Vector3(0, 0, 0), speed, callback);
}
_.each(this.stock, function(stock){ _.each(this.stock, function(stock){
stock.show(); stock.show();
}); });
callback(); if (index.z%2 != 0) {//rotate on odd rows
this.components.frame.rotateTo(new THREE.Vector3(0, 0, Math.PI/2), speed, callback);
}
this.components.frame.rotateTo(new THREE.Vector3(0, 0, 0), speed, callback);
}; };
Assembler.prototype.releaseStock = function(index, position, settings){ Assembler.prototype.releaseStock = function(index, position, settings){
......
...@@ -74,7 +74,7 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){ ...@@ -74,7 +74,7 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){
}; };
Component.prototype.getRotation = function(){ Component.prototype.getRotation = function(){
return this.object3D.rotation.toVector3(); return this.object3D.rotation.toVector3().clone();
}; };
Component.prototype.getObject3D = function(){ Component.prototype.getObject3D = function(){
...@@ -88,41 +88,34 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){ ...@@ -88,41 +88,34 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){
} }
var currentPosition = this.getRotation(); var currentPosition = this.getRotation();
var increment = 0.15;//speed/1500.0*cam.get("simSpeed"); var increment = 0.15;//speed/1500.0*cam.get("simSpeed");
var incrVector = target.clone().sub(currentPosition); var axis = new THREE.Vector3().subVectors(target, currentPosition);
if (increment == 0 || incrVector.length() == 0) { if (increment == 0 || axis.length() == 0) {
if (callback) callback(); if (callback) callback();
return; return;
} }
increment = Math.max(increment, 0.00001);//need to put a min on the increment - otherwise this stalls out with floating pt tol increment = Math.max(increment, 0.00001);//need to put a min on the increment - otherwise this stalls out with floating pt tol
incrVector.normalize().multiplyScalar(increment); this._incrementalRotation(increment, target, axis, callback);
this._incrementalRotation(incrVector, target, callback);
}; };
Component.prototype._incrementalRotation = function(increment, target, callback){ Component.prototype._incrementalRotation = function(increment, target, axis, callback){
var self = this; var self = this;
setTimeout(function(){ setTimeout(function(){
var remainingDist = (target.clone().sub(self.getRotation())).length(); var remainingDist = (target.clone().sub(self.getRotation())).length();
var nextPos; if (remainingDist < 0.01) {
if (remainingDist == 0) {
if (callback) callback(); if (callback) callback();
return; return;
} else if (remainingDist < increment.length()){ } else if (remainingDist < Math.abs(increment)){
nextPos = target;//don't overshoot
self.object3D.rotation.x = target.x; self.object3D.rotation.x = target.x;
self.object3D.rotation.y = target.y; self.object3D.rotation.y = target.y;
self.object3D.rotation.z = target.z; self.object3D.rotation.z = target.z;
if (callback) callback(); if (callback) callback();
return; return;
} else {
nextPos = self.getRotation().add(increment);
} }
// console.log(target.clone().normalize()); self.object3D.rotateOnAxis(axis.clone().normalize(), increment);
console.log(increment); self._incrementalRotation(increment, target, axis, callback);
self.object3D.rotateOnAxis(target.clone().normalize(), nextPos.z);
self._incrementalRotation(increment, target, callback);
}, 10); }, 10);
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment