A 3d Bouncing Sphere

download A 3d Bouncing Sphere

of 29

Transcript of A 3d Bouncing Sphere

  • 8/4/2019 A 3d Bouncing Sphere

    1/29

    Providing all possible views and Interaction for the viewer to change the bouncingspeed of the (sphere)ball.

  • 8/4/2019 A 3d Bouncing Sphere

    2/29

    OpenGL was developed bySilicon Graphics Inc (SGI) on 1992 and is popular in thegaming industry where it competes with the Direct3D in the Microsoft Windows platform.

    OpenGL is broadly used in CAD (Computer Aided Design), virtual reality, scientific

    visualization, information visualization, flight simulation and video games development.

    OpenGL is a standard specification that defines an API that is multi-language and

    multi-platform and that enables the codification of applications that output

    computerized graphics in 2D and 3D.

    The interface consists in more than 250 different functions, which can be used to

    draw complex tridimensional scenes with simple primitives. It consist of manyfunctions that help to create an real world object and an particular existence for an

    object can be given.

  • 8/4/2019 A 3d Bouncing Sphere

    3/29

    In this project we are showing the necessary steps and routines to theproper codification and simulation of a bouncing sphere in 3D, which isthe most used in the animation field.

    With a simulation (virtual) model, we can have a closer vision of the

    object of study in contrast with reality, what make us capable of

    foreseeing how a determined object will look like and how it will behaveafter its proper construction in the physical world

    This program contains different types of viewing effects which the user

    can specify easily specify by using keyboard and mouse interfaces

    There is an immense amount of user interface provided both through the

    mouse and keyboard interface which helps the user to select the speed of the

    bouncing sphere , view angle along with the idle position of the object and

    other activities.

  • 8/4/2019 A 3d Bouncing Sphere

    4/29

    In this project we are showing the necessary steps and routines to the

    proper codification and simulation of a 3D Bouncing Sphere.

    A 3-Dimensional ball(sphere) bounces on a rectangular plane

    with an adjacent semi circle plane.

    There is user interface provided both through the keyboard and

    mouse

  • 8/4/2019 A 3d Bouncing Sphere

    5/29

    A pop up menu is provided by a right click of mouse that

    consists of sub menus for performing various actions.

    The ball keeps bouncing and the camera spins around it

    continuosly.

    Human intervention.

    Then the selected option will generate an event.

    This will place the device measure with its identifier is placed in an

    event queue.

  • 8/4/2019 A 3d Bouncing Sphere

    6/29

    After that,a particular service routine gives service to that

    particular event.

    Uses glut to manage windows, callbacks, and online menu.

    Uses glPolygonfill( ) to maintain colors in wireframe and solidmode.

    Various key strokes available to control independently the

    mech's many joints.and to view mech and environment fromdifferent angles, to alter positioning of the single light

    source.

  • 8/4/2019 A 3d Bouncing Sphere

    7/29

    Our objective is to create aBouncing 3D sphere theball will be bouncing and the camera(Users view)

    should slowly rotate about the center of the scene .The

    program should respond to keyboard events includingarrow keys along with themouse interface in a texturedbackground. So that it can adjust to the environment

    very easily.The model will be created through OpenGL

    programming.

  • 8/4/2019 A 3d Bouncing Sphere

    8/29

    Initially the user is given the privilege of giving interaction

    with the input devices.

    The user can select any option that listed in menu list.

    Then the selected option will generate an event.

    This project is implemented using C++ and OpenGL

    built in functions.

    Initially the bouncing ball appears on the screen.

  • 8/4/2019 A 3d Bouncing Sphere

    9/29

    A menu is created when the user right clicks on the mouse.

    The menu object shape mode contains nine submenus toggle

    camera spin ,toggle ball bounce ,screen mode ,ball size

    ,bouncing speed, view mode ,camera spin speed ,reset ,quit.

    When we click on toggle camera spin or toggle ball bounce the

    camera stops spinning or the ball stops bouncing.

    The size of the ball can be set as small.big or medium by

    clicking the ball size on pop up menu.

  • 8/4/2019 A 3d Bouncing Sphere

    10/29

    The screen mode can be either set to full or window size ,through

    screen mode option.

    The bouncing speed of the bal or the camera spin speed can be

    varied by selecting the respective options in the menu.

    The objects can be either viewed in polygonal form or mesh form

    according to the choice of the user by specifying it through therespective menu option.

  • 8/4/2019 A 3d Bouncing Sphere

    11/29

    The role of the user in our project can be specified as follows

    The bouncing of the ball and the spin of the camea can be stopped.

    The size of the ball can be varied.

    The ball can be viewed in polygonal or mesh form.

    The ball can be viewed in a full screen ode or window mode.

  • 8/4/2019 A 3d Bouncing Sphere

    12/29

    By using the keys specified in the keyboard the movement of the ball

    can be controlled.

    A description of various keys used in our project is as follows:

    A- moves the ball to left of the screen. D- moves the ball to right of the screen.

    W- moves the ball backwards ,away from screen.

    S- moves the ball forward , towards the screen.

    M,N- increases and decreases the length of ball bounce. K,I- increases and decreases the ball size.

    O,T- enables and disables the culling effect .

    L,P- shows the ball in line or poygonal form.

  • 8/4/2019 A 3d Bouncing Sphere

    13/29

    Both keyboard and mouse interface is provided.

    Allows the user to move the camera suitably to experiment with the

    perspective viewing.

    Movement of the ball in all possible directions.

    Variation can be done in shape and size of the ball.

    The size of the ball shrinks when it comes in contact with other object.

    This can be used in designing various games.

  • 8/4/2019 A 3d Bouncing Sphere

    14/29

    The above project can be analyzed as follows:

    This project is implemented usingCandOpenGLbuilt in functions.

    In the beginning the sphere will be bouncing and the camera will be spinning.

    When the user right clicks on the mouse menus will appear.The main pop-up contains nine menus toggle camera spin, toggle ball bounce, screen

    mode, ball size, bouncing speed, view mode, camera speed, reset, Quit.

    The menu screen mode contains two submenus - Full Screen mode and

    window Screen mode.

    The menu ball size contains three sub menus - small, medium, big.The menu bouncing speed contains three sub menus - slow, medium, fast.

    The menu view mode contains two sub menus - polygon mode, wired mode.

    The menu camera speed contains three sub menusslow, medium, fast.

    The menu contains reset option and quit.

    The quit menu, quits the window and come back to the main program.

  • 8/4/2019 A 3d Bouncing Sphere

    15/29

    3D Bouncing Sphere

  • 8/4/2019 A 3d Bouncing Sphere

    16/29

    Varying the speed of the ball bouncing.

  • 8/4/2019 A 3d Bouncing Sphere

    17/29

    Bouncing ball viewed in wired form.

  • 8/4/2019 A 3d Bouncing Sphere

    18/29

    Figure showing various size of the ball.

  • 8/4/2019 A 3d Bouncing Sphere

    19/29

    Figure to show the top-view.

  • 8/4/2019 A 3d Bouncing Sphere

    20/29

    Some of the important function definitions used in our code are:

    void Display(void)

    {glClear(GL_COLOR_BUFFER_BIT |

    GL_DEPTH_BUFFER_BIT);

    glPushMatrix();

    MakeCamera(FALSE,0,0);

    MakeGeometry();glPopMatrix();

    glutSwapBuffers();

    }

  • 8/4/2019 A 3d Bouncing Sphere

    21/29

    void MakeCamera(int pickmode,int x,int y)

    {

    static double theta = 0;

    glMatrixMode(GL_PROJECTION);

    glLoadIdentity();

    gluPerspective(70.0,1.0, 0.10,1000.0); /* near and far */glMatrixMode(GL_MODELVIEW);

    glLoadIdentity();

    gluLookAt(5*cos(theta*PI/180)*sin(updownrotate*PI/180),

    5*cos(updownrotate*PI/180),5*sin(theta*PI/180)*sin(updownrotate*PI/180),0.0,0.0,0.0,

    0.0,1.0,0.0);

    if (spincamera)

    theta += (cameradirection * 0.3);

    }

  • 8/4/2019 A 3d Bouncing Sphere

    22/29

    void HandleMainMenu(int whichone){

    switch (whichone)

    {

    case 1: spincamera = !spincamera; break;case 2: ballbounce = !ballbounce; break;

    case 3:glutFullScreen();break;

    case 4:glutReshapeWindow(400,400);break;

    case 100: exit(0); break;

    }

    }

  • 8/4/2019 A 3d Bouncing Sphere

    23/29

    void HandleSpeedMenu(int whichone)

    {

    switch (whichone)

    {case 1: ballspeed = 0.5; break;

    case 2: ballspeed = 2; break;

    case 3: ballspeed = 10; break;

    }

    }

  • 8/4/2019 A 3d Bouncing Sphere

    24/29

    void HandleCamaraMenu(int whichone)

    { switch (whichone)

    {

    case 1:cameradirection = 1; break;case 2: cameradirection = 2; break;

    case 3: cameradirection = 6; break;

    }

    }

  • 8/4/2019 A 3d Bouncing Sphere

    25/29

    void HandleClarityMenu(int ccc)

    {

    switch (ccc)

    {

    case 1: drawquality = DRAFT; break;

    case 2: drawquality = MEDIUM; break;

    case 3: drawquality = BEST; break;

    }

    }

  • 8/4/2019 A 3d Bouncing Sphere

    26/29

    void HandleVisibility(int visible)

    {

    if (visible == GLUT_VISIBLE)

    glutIdleFunc(HandleIdle);else

    glutIdleFunc(NULL);

    }

  • 8/4/2019 A 3d Bouncing Sphere

    27/29

    void DrawTextXY(double x,double y,double z,double scale,char *s){

    int i;

    glPushMatrix();

    glColor3f(1.0,0.0,1.0);glTranslatef(x,y,z);

    glScalef(scale,scale,scale);

    for (i=0;i< strlen(s);i++)

    glutStrokeCharacter(GLUT_STROKE_ROMAN,s[i]);

    glPopMatrix();}

  • 8/4/2019 A 3d Bouncing Sphere

    28/29

    An attempt has been made to develop an OpenGL graphics package

    which meets all the necessary requirements that were set out. It is

    user friendly and provides an easy interaction for the user.

    The user can very easily use this tool to draw or manipulate a

    drawing. The interfaces are mouse driven and the user can select a

    function by clicking on an option representing that function

    The sphere can be moved in all directions and shrinkswhenever it touches other objects. There is an immense amount

    of user interface provided both through the keyboard and

    mouse

  • 8/4/2019 A 3d Bouncing Sphere

    29/29

    FUTURE ENHANCEMENTThis project has been designed using OpenGL. The project

    can be designed using better languages and better graphical

    interfaces making use of inputs from light pens. New options like

    shear effect, shadows, lightning etc can be implemented. Higherlanguages like JAVA can be used to provide a new look to the

    project.

    In future we can enhance this project by including the various

    other interactive options to the mouse and the keyboard (can also usejoysticks) like increasing the number of balls (bouncing balls).We can

    develop this project as a game also by providing control over the

    movement of the ball and making the ball to reach the specified

    target in the environment.