view Viewer/resources/keybord.js~ @ 6:ca8540cab316

viewer
author <e085737>
date Fri, 26 Nov 2010 15:45:27 +0900
parents
children
line wrap: on
line source


var currentlyPressedKeys = Object();

function HandleKeyDown(event){
    currentlyPressedKeys[event.keyCode] = true;
}

function HandleKeyUp(event){
    currentlyPressedKeys[event.keyCode] = false;
}

function HandleKeys() {
    lim_x = (width-my_cube.w)/2.0;
    lim_y = (height-my_cube.h)/2.0;
    move_speed   = 5.0;
    angle_modify = 2.0;
    left_push    = currentlyPressedKeys[37];
    down_push    = currentlyPressedKeys[40];
    right_push   = currentlyPressedKeys[39];
    up_push      = currentlyPressedKeys[38];
    vacuum_push  = currentlyPressedKeys[86];
    move_push    = currentlyPressedKeys[83];
    zoom_push    = currentlyPressedKeys[90];
    default_push = currentlyPressedKeys[68];


    if(move_push){
        Object_move()
    }else if(zoom_push){
	Object_zoom()
    }else{
	Object_rotate()
    }

    if(default_push){
	Object_default()
    }

    if(vacuum_push){
	my_cube.cube_collision();
	my_cube.vacuum();
    }

    /*if(start_push){
        title.collision();
    }*/
}

function Object_rotate(){

    if(right_push){
        my_cube.angle[0] += angle_modify;
    }else if(left_push){
	my_cube.angle[0] -= angle_modify;
    }

    if(up_push){
	my_cube.angle[1] -= angle_modify;
    }else if(down_push){
	my_cube.angle[1] += angle_modify;
    }
}

function Object_move(){

    if(right_push && my_cube.xyz[0] < lim_x){
        my_cube.xyz[0] += move_speed;
    }else if(left_push && my_cube.xyz[0] > -lim_x){
	my_cube.xyz[0] -= move_speed;
    }

    if(up_push && my_cube.xyz[1] < lim_y){
	my_cube.xyz[1] += move_speed;
    }else if(down_push && my_cube.xyz[1] > -lim_y){
	my_cube.xyz[1] -= move_speed;
    }
}

function Object_zoom(){
    zoom = 10.0;
    if(up_push){
        my_cube.xyz[2] -= zoom
    }else if(down_push){
	my_cube.xyz[2] += zoom
    }
}


function Object_default(){
    my_cube.xyz[0] = 0
    my_cube.xyz[1] = 0
    my_cube.xyz[2] = 0
    my_cube.angle[0] = 0
    my_cube.angle[1] = 0
    my_cube.angle[2] = 0
}