Results 1 to 9 of 9

Thread: How to roll a cube??

  1. #1
    Guest

    How to roll a cube??

    I trying to roll a cube from left screen to right screen.Here are the coding.I hope somebody can help me as I am unable to call the rollCube function.
    Thanks.

    void MyMouse(int button,int state,int x,int y){
    if(button==GLUT_LEFT_BUTTON && state==GLUT_DOWN){

    glTranslated(100,0,0);
    glRotatef(-90.0,0.0,1.0,0.0);
    glTranslated(-100,0,0);
    }

    else if(button==GLUT_RIGHT_BUTTON && state==GLUT_DOWN)
    glutIdleFunc(NULL);
    glFlush();
    }

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: How to roll a cube??

    I personaly like to keep all the gltranslate/rotate stuff in my display() routine.

    example my mouse routine, only problem is that you only get movement once per click.

    void mouse(int button, int state, int x, int y)
    {

    if ((button == GLUT_RIGHT_BUTTON) && (state == GLUT_DOWN)) Worldz++;

    if ((button == GLUT_LEFT_BUTTON) && (state == GLUT_DOWN)) Worldz--;

    }

    To have it move until button is released do this:
    Note: edit and added rolling function.

    void mouse(int button, int state, int x, int y)
    {

    if ((button == GLUT_RIGHT_BUTTON) && (state == GLUT_DOWN)) cube_x = 1; 1 = roll right.

    if ((button == GLUT_RIGHT_BUTTON) && (state == GLUT_UP)) cube_x = 0; 0 = no motion
    // repeat above for left button excecpt cube_x = -1; where -1 = roll left.

    }

    display()
    {

    now add rotate and translate and drawing commands
    // note I have update a little

    glTranslate(cube_position_x, y, z); move right or left.
    glRotatef(cube_rotation, 1, 0, 0); Roll cube

    Draw cube

    }


    my_idle_func()
    {

    cube_position = cube_position + cube_x; // move cube right or left based on cube_x value.
    if (cube_position > 10) cube_position = 10; // max movement to the right. Adjust number to match your screen units
    if (cube_position < -10) cube_position = -10; // max movement to the left.

    // make cube roll
    cube_rotation = cube_rotation + cube_x; // rotate roll cube clockwise or counter based on direction of travel.
    if (cube_rotation > 360) cube_rotation = 0; // 360 is max of angle.
    if (cube_rotation < 0) cube_rotation = 360;

    glutRepostDisplay();// last call in idle func.
    }

    Let me know if there is anything you don't understand about this code


    Note if you reg. you will get an e-mail when someone post a reply to your message.

    Originally posted by Claudee:
    I trying to roll a cube from left screen to right screen.Here are the coding.I hope somebody can help me as I am unable to call the rollCube function.
    Thanks.

    void MyMouse(int button,int state,int x,int y){
    if(button==GLUT_LEFT_BUTTON && state==GLUT_DOWN){

    glTranslated(100,0,0);
    glRotatef(-90.0,0.0,1.0,0.0);
    glTranslated(-100,0,0);
    }

    else if(button==GLUT_RIGHT_BUTTON && state==GLUT_DOWN)
    glutIdleFunc(NULL);
    glFlush();
    }
    [This message has been edited by nexusone (edited 07-31-2002).]

    [This message has been edited by nexusone (edited 07-31-2002).]

  3. #3
    Senior Member Regular Contributor
    Join Date
    May 2002
    Posts
    189

    Re: How to roll a cube??

    just an idea from a newbie, why not try having the cube stay in the same spot and just spin the camera around it like crazy? You could probably figure out some easy formula with sine that would do the job nicely.

  4. #4
    Member Contributor
    Join Date
    Jul 2002
    Location
    Southampton, PA, USA
    Posts
    61

    Re: How to roll a cube??

    That's not a good habit to get into...

  5. #5
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: How to roll a cube??

    Yea, I thought that also when I first read the topic, but wanted to be helpful not a smart a$$.



    Originally posted by Jared@ETC:
    That's not a good habit to get into...

  6. #6
    Senior Member Regular Contributor
    Join Date
    May 2002
    Posts
    189

    Re: How to roll a cube??

    I didn't mean to give off the idea that my nose is up in the air, thats why I said, AN IDEA FROM A NEWBIE

    I don't know much about gl it was just an idea. If you can't take it that way then don't bother...

  7. #7
    Member Contributor
    Join Date
    May 2001
    Posts
    54

    Re: How to roll a cube??

    Why not use a sphere,

    they seem to roll really nicely!!!!!

    J

  8. #8
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: How to roll a cube??

    The comments where not aimed at you, but about the subject. it was a little joke about the subject.... think about it and maybe you will get it....




    Originally posted by 31337:
    I didn't mean to give off the idea that my nose is up in the air, thats why I said, AN IDEA FROM A NEWBIE

    I don't know much about gl it was just an idea. If you can't take it that way then don't bother...

  9. #9
    Guest

    Re: How to roll a cube??

    Thanks for everybody that already give a comment for me.

    Originally posted by Claudee:
    I trying to roll a cube from left screen to right screen.Here are the coding.I hope somebody can help me as I am unable to call the rollCube function.
    Thanks.

    void MyMouse(int button,int state,int x,int y){
    if(button==GLUT_LEFT_BUTTON && state==GLUT_DOWN){

    glTranslated(100,0,0);
    glRotatef(-90.0,0.0,1.0,0.0);
    glTranslated(-100,0,0);
    }

    else if(button==GLUT_RIGHT_BUTTON && state==GLUT_DOWN)
    glutIdleFunc(NULL);
    glFlush();
    }

Similar Threads

  1. Yaw, Pitch & Roll
    By OGL_PGR in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 10-08-2005, 07:26 AM
  2. about Yaw-Pitch-Roll
    By tigeryhong in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 03-22-2003, 12:07 PM
  3. Roll, Pitch, and Yaw
    By BigRD in forum OpenGL: Basic Coding
    Replies: 9
    Last Post: 10-18-2001, 07:19 AM
  4. roll a sphere?
    By newmannium in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 03-04-2001, 07:00 PM
  5. yaw, pitch, roll besides x, y, z
    By Bob Plugge in forum OpenGL: General
    Replies: 5
    Last Post: 11-01-2000, 02:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean