Game Development Reference
In-Depth Information
The handleKeys handler is pretty simple. If the keyboard keys are pressed along
with the Shift key, then the handler invokes the yaw , pitch , or roll function of
our camera object, rotating the corresponding vectors with a constant value ( this.
cam.roll(-Math.PI * 0.025) ). If the Shift key is not pressed, then the handler
gets the current position of the camera ( var pos = this.cam.getPosition() )
and then changes it by adding or subtracting the respective constant value of
the x , y , and z axes of the position property of the camera object ( this.cam.
setPosition([pos[0]+10, pos[1], pos[2]]) ; here, 10 indicates the changed x
value of the camera so as to move along positive x axis).
KeyBoardInteractor.prototype.handleKeys=function (event) {
if(event.shiftKey) {
switch(event.keyCode) {//determine the key pressed
case 65://a key
this.cam.roll(-Math.PI * 0.025);//tilt to the left
break;
case 37://left arrow
this.cam.yaw(Math.PI * 0.025);//rotate to the left
break;
case 68://d key
this.cam.roll(Math.PI * 0.025);//tilt to the right
break;
case 39://right arrow
this.cam.yaw(-Math.PI * 0.025);//rotate to the right
break;
case 83://s key
case 40://down arrow
this.cam.pitch(Math.PI * 0.025);//look down
break;
case 87://w key
case 38://up arrow
this.cam.pitch(-Math.PI * 0.025);//look up
break;
}
}
else {
var pos = this.cam.getPosition();
switch(event.keyCode) {//determine the key pressed
case 65://a key
case 37://left arrow
this.cam.setPosition([pos[0]-10, pos[1],
pos[2]]);//move - along the X axis
break;
case 68://d key
case 39://right arrow
 
Search WWH ::




Custom Search