Welcome to FreeSpin3D Sign in | Join
in Search

Rotate 3D Objects through Directional Buttons

Last post 07-02-2008 12:14 PM by Hillenbrand. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 06-29-2008 7:48 PM

    Rotate 3D Objects through Directional Buttons

    I have made a 3D Object rotation working example through buttons. This Code is helpful for beginners....
    BASIC EXAMPLE----

    Here is the code below:

    Step 1 : Create 5 buttons namely - reset_button, rotate_x_up, rotate_x_down, rotate_y_left, rotate_y_right

    a) reset_button to reset the object to its actual position

    b) rotate_x_up, rotate_x_down buttons to rotate the object on X axis

    c) rotate_y_left, rotate_y_right buttons to rotate the object on Y axis

    Note :  write all piece of code on frame itself not on buttons

    Step 2 : Create 4 functions namely - reset_obj, rotate_X_UP, rotate_X_DOWN, rotate_Y_LEFT, rotate_Y_RIGHT

     Note :  The buttons will call the function on mouse click events

    Step3: Assign "object_3d" as reference name to your 3d object.

    Below is the code u can understand easily.

    /////////////////////////////////////////////////Code//////////////////////////////////////////////////////////////////


    ///Reset 3D object to its Actual Position
    function reset_obj(eventObject:MouseEvent) {
    object_3d.RviReset();
    }

    reset_button.addEventListener(MouseEvent.CLICK, reset_obj);

    ////////////////////////////////////////////////////////////

    ///Rotate 3D Object on X axis////////////////////////////////////
    function rotate_X_UP(eventObject:MouseEvent) {
    object_3d.RviAutoX=1;
    }

    function rotate_X_DOWN(eventObject:MouseEvent) {
    object_3d.RviAutoX=-1;
    }

    function rotate_X_Stop(eventObject:MouseEvent) {
    object_3d.RviAutoX=0;
    }


    rotate_x_up.addEventListener(MouseEvent.MOUSE_DOWN, rotate_X_UP );
    rotate_x_down.addEventListener(MouseEvent.MOUSE_DOWN, rotate_X_DOWN );
    rotate_x_up.addEventListener(MouseEvent.MOUSE_UP, rotate_X_Stop);
    rotate_x_up.addEventListener(MouseEvent.MOUSE_OUT, rotate_X_Stop);
    rotate_x_down.addEventListener(MouseEvent.MOUSE_UP, rotate_X_Stop);
    rotate_x_down.addEventListener(MouseEvent.MOUSE_OUT, rotate_X_Stop);


    ////////////////////////////////////////////////////////////////////

    ///Rotate 3D Object at Y axis////////////////////////////////////
    function rotate_Y_LEFT(eventObject:MouseEvent) {
    object_3d.RviAutoY=1;
    }

    function rotate_Y_RIGHT(eventObject:MouseEvent) {
    object_3d.RviAutoY=-1;
    }

    function rotate_Y_Stop(eventObject:MouseEvent) {
    object_3d.RviAutoY=0;
    }


    rotate_y_left.addEventListener(MouseEvent.MOUSE_DOWN, rotate_Y_LEFT );
    rotate_y_right.addEventListener(MouseEvent.MOUSE_DOWN, rotate_Y_RIGHT );
    rotate_y_left.addEventListener(MouseEvent.MOUSE_UP, rotate_Y_Stop);
    rotate_y_left.addEventListener(MouseEvent.MOUSE_OUT, rotate_Y_Stop);
    rotate_y_right.addEventListener(MouseEvent.MOUSE_UP, rotate_Y_Stop);
    rotate_y_right.addEventListener(MouseEvent.MOUSE_OUT, rotate_Y_Stop);


    ////////////////////////////////////////////////////////////////////

  • 07-02-2008 12:14 PM In reply to

    Re: Rotate 3D Objects through Directional Buttons

    Thanks for this....very useful. Interseting use of RviAutoX and RviAutoY

     

     Is it possible to zoom in and out from the model ???

     

    H.

     

     

     

    Save the cheerleader, save the world
Page 1 of 1 (2 items)
Revolver3d