fixed lookWithTouch.js to not reset

This commit is contained in:
ZappoMan 2014-03-25 12:55:50 -07:00
parent db05523bc3
commit a256473ac5

View file

@ -9,6 +9,7 @@
// //
// //
var startedTouching = false;
var lastX = 0; var lastX = 0;
var lastY = 0; var lastY = 0;
var yawFromMouse = 0; var yawFromMouse = 0;
@ -21,12 +22,14 @@ function touchBeginEvent(event) {
} }
lastX = event.x; lastX = event.x;
lastY = event.y; lastY = event.y;
startedTouching = true;
} }
function touchEndEvent(event) { function touchEndEvent(event) {
if (wantDebugging) { if (wantDebugging) {
print("touchEndEvent event.x,y=" + event.x + ", " + event.y); print("touchEndEvent event.x,y=" + event.x + ", " + event.y);
} }
startedTouching = false;
} }
function touchUpdateEvent(event) { function touchUpdateEvent(event) {
@ -44,24 +47,26 @@ function touchUpdateEvent(event) {
} }
function update(deltaTime) { function update(deltaTime) {
// rotate body yaw for yaw received from mouse if (startedTouching) {
var newOrientation = Quat.multiply(MyAvatar.orientation, Quat.fromPitchYawRollRadians(0, yawFromMouse, 0)); // rotate body yaw for yaw received from mouse
if (wantDebugging) { var newOrientation = Quat.multiply(MyAvatar.orientation, Quat.fromPitchYawRollRadians(0, yawFromMouse, 0));
print("changing orientation" if (wantDebugging) {
+ " [old]MyAvatar.orientation="+MyAvatar.orientation.x + "," + MyAvatar.orientation.y + "," print("changing orientation"
+ MyAvatar.orientation.z + "," + MyAvatar.orientation.w + " [old]MyAvatar.orientation="+MyAvatar.orientation.x + "," + MyAvatar.orientation.y + ","
+ " newOrientation="+newOrientation.x + "," + newOrientation.y + "," + newOrientation.z + "," + newOrientation.w); + MyAvatar.orientation.z + "," + MyAvatar.orientation.w
} + " newOrientation="+newOrientation.x + "," + newOrientation.y + "," + newOrientation.z + "," + newOrientation.w);
MyAvatar.orientation = newOrientation; }
yawFromMouse = 0; MyAvatar.orientation = newOrientation;
yawFromMouse = 0;
// apply pitch from mouse // apply pitch from mouse
var newPitch = MyAvatar.headPitch + pitchFromMouse; var newPitch = MyAvatar.headPitch + pitchFromMouse;
if (wantDebugging) { if (wantDebugging) {
print("changing pitch [old]MyAvatar.headPitch="+MyAvatar.headPitch+ " newPitch="+newPitch); print("changing pitch [old]MyAvatar.headPitch="+MyAvatar.headPitch+ " newPitch="+newPitch);
}
MyAvatar.headPitch = newPitch;
pitchFromMouse = 0;
} }
MyAvatar.headPitch = newPitch;
pitchFromMouse = 0;
} }
// Map the mouse events to our functions // Map the mouse events to our functions
@ -77,10 +82,6 @@ function scriptEnding() {
Controller.releaseTouchEvents(); Controller.releaseTouchEvents();
} }
MyAvatar.bodyYaw = 0;
MyAvatar.bodyPitch = 0;
MyAvatar.bodyRoll = 0;
// would be nice to change to update // would be nice to change to update
Script.update.connect(update); Script.update.connect(update);
Script.scriptEnding.connect(scriptEnding); Script.scriptEnding.connect(scriptEnding);