Friday, August 24, 2012

OpenGL :: 3D (Part 1/2) :: Material 4


OpenGL :: 3D (Part 1/2) :: Material 4


list of contents :
  • The real on the screen
  • Perspective
  • Place the camera

The real on the screen

When you describe your 3D scene in OpenGL (to blow glVertex ), you describe the world as it is in absolute terms, in its own mark.
To the real world on the screen, we must give some indications OpenGL:
  • defining which area of ​​the window will be used for rendering *;
  • define the projection mode (eg perspective);
  • place the camera in the real world.


* This step is automatically performed in the creation of the window. We will see in Part II how to change the split-screen (several screens rendered on the same window).

Based on this information, OpenGL can determine changes in subjecting the real world objects in three dimensions to draw 2 on the screen dimensions.

User Image


In the real world you work at vertices and on the screen in pixels. The drawing up of you may have noticed that I did not reveal any Z screen. It was just not to confuse you because the screen is 2 dimensional. Z but the screen is still to give a pixel depth information.

User Image



The mark X, Y, Z of the screen is not straightforward: if we apply the rule of the right hand.The Z axis should move the screen towards us. However, the agreement was made in image synthesis the Z axis goes into the screen.






What is the unit of distance in OpenGL?


Answer: the one you want ! Indeed, when we think what that something is big or small, really? Without reference it is difficult to visually determine the size of an object. We know it is small because there is another object by which we know the size. We knowcompare .
How do I know that something is away? Because when we move, its size does not vary much and because of the time we get close.example in OpenGL that "1" is 1 meter as 1 mm or as 1 km is the same as long as the proportions are maintained and that the speeds of movement are appropriate. Indeed, if we faced a cube of "1" in width and only support once the button "forward" moves us from 10000 will say: I will be very fast, or the object was (as we just lose it) very very small indeed. however it is sometimes useful to refer to known units. If one unit is 1 meter OpenGL, then it will be easier to use a physics engine that uses real units.



Perspective

The most important passage is in 3D projection . To move from a world in 3D describes a window with 2D pixel we must lose a dimension and therefore project. projection method that we use in 3D perspective. The prospect is defined by the pyramid below:



User Image
Pyramid clipping


This pyramid is called the pyramid clipping . That is to say, any object that is not within the blue zone will not be drawn. More shape to define how to project objects on the screen by drawing a parallel with the actual pyramid whose summit the eye of the user and cut his screen :

User Image
actual pyramid (here seen from above)


The ratio (given in the diagram above) is a ratio between the width and height. For a TV this ratio is 4/3 times of 16/9. Sizes for standard computer (1024x768, 800x600, 640x480), it is also 4/3. But your window is not obliged to use the whole screen and can have its own proportions and there are more screens with special ratios. It is therefore important not to take for granted in your applications and always defined in terms of the size of the window that you create (I will make a schedule SDL on how to detect the available modes for full screen). parameters near and far determine the minimum and maximum distances of objects.Outside this interval objects are not displayed. This problem may arise if the value is far too small, the user may see objects disappear when it goes away, or worse see the scene suddenly appear. We will see in Part II how to use the fog to deal with this problem. At the moment a large value (vis-à-vis the size of your scene) will be good enough. The only parameter that can escape here is the angle . This is the viewing angle between the planes up and down the pyramid (often denoted fovy for field of view on the y axis). Generally used a value around 70 °. When the output of Half-Life 2 there was a controversy over the angle misnomer (90 °) which made ​​some people uncomfortable. To see the influence of this angle, I have 3 is made ​​of the same scene with different angles:






User Image
User Image
User Image


We note that if you give a small angle , it gives an effect of zoom . And I will not deny that this is exactly what is used in games for zoom (binoculars or sniper).


OpenGL application



To set the perspective projection mode as simply calling the function

gluPerspective (fovy, ratio, near, far);


Eg for a 640x480 window:Code: C + +
Select
1
gluPerspective ( 70 , ( two ) 640 / 480 , 1 , 1000 );


This call changes the current matrix, even if it is not the projection matrix. We must therefore make sure to select the matrix GL_PROJECTION , initialize and then call gluPerspective .

Here is our new code to initialize our OpenGL application:Code: C + +

Select
1
2
3
4
5
6
SDL_Init ( SDL_INIT_VIDEO ) 
SDL_WM_SetCaption ( "SDL GL 
   
  
 



As the definition of perspective does the matrix GL_PROJECTION we can simply initialize once and not for each image. Of course, if the ratio of the window should change dynamically should redefine risk perspective see all objects distorted.

Place the camera

Now that we know how to plan, it would be nice to place the view anywhere in the scene. For this we use a kind of camera with the virtual call:

gluLookAt (CAMx, Camy, Camz, Ciblex cibleY, target, VertX, verty, Vertz);


CAMx , Camy and Camz define the position of the camera; CIBLEX , cibleY and target define the position of the camera fixed point (the corresponding point will be at the center of the display) VertX , Verty and Vertz define the vector vertical. following three images taken with different settings of the camera so that you understand the value of each parameter:





User Image

gluLookAt (1.5, 1.5, 5, 0, 0, 0, 0, 1, 0)
The camera is (1.5,1.5,5) and looks (0,0,0). gluLookAt (1.5, 1.5, 5 , 1.5, 1.5, 0, 0, 1, 0) The camera is (1.5,1.5,5) and looks (1.5,1.5,0), that is to say, right before it (unlike the previous image). gluLookAt (1.5, 1.5, 5, 0, 0, 0, 1, 1, 0) and the same position as before, but his eyes vertical vector is (1,1,0), or the scene was thought with a vertical (0,1,0), the image is "leaning" on the side.

User Image




User Image




The importance of vertical



You saw the call to gluLookAt lets you define the vertical that you want for your scene. The whole thing is to be consistent and to design your scene accordingly.
Nevertheless, it is much more convenient to choose as a vector of vertical marker base X (1,0,0) , Y (0,1,0) or Z (0,0,1) .

Between Y and Z which is the best choice?


Good question. One or both are valid choices: we can imagine the transition to three e dimension as the addition of depth as well as the addition of height . In the world of computer graphics it is not uncommon to see one or the other . Going forward , I will try to respect the choice Z = vertical as it has been in many games and OpenGL seems to have helped (we shall see in the chapter on quadrics ...).



User Image
Editor FarCry , Z is the vertical


When the call?



Place the camera move back to everyone so it is centered on the camera and oriented along the axis of the eye. This logically affects the matrix GL_MODELVIEW and you will not be surprised therefore that the appeal of the camera is just after resettingGL_MODELVIEW .Code: C + +

Select
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
void  Draw () 
{ 
    glClear (  GL_COLOR_BUFFER_BIT  );

    glMatrixMode (  GL_MODELVIEW  ); 
    glLoadIdentity (  );

    gluLookAt ( 3 , 3 , 3 , 0 , 0 , 0 , 0 , 0 , 1 );  / / Example

    / * 3D drawing here * /

    glFlush (); 
    SDL_GL_SwapBuffers (); 
}
That now you know how it is possible to move from a 3D world to a 2D screen and the camera will know.
To summarize, our new program for drawing skeleton of 3D:Code: C + +

Select
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<SDL/SDL.h> # Include 
# include <GL/gl.h> 
<GL/glu.h> # include 
# include <cstdlib>

void  Draw ();

int  main ( int  argc ,  char  * argv []) 
{ 
    SDL_Event  event ;

    SDL_Init ( SDL_INIT_VIDEO ) 
    atexit ( SDL_Quit ) 
    SDL_WM_SetCaption ( "SDL GL Application" ,  NULL ); 
    SDL_SetVideoMode ( 640 ,  480 ,  32 ,  SDL_OPENGL );

    glMatrixMode (  GL_PROJECTION  ); 
    glLoadIdentity (); 
    gluPerspective ( 70 , ( two ) 640 / 480 , 1 , 1000 );

    Draw ();

    for  (; ;) 
    { 
        SDL_WaitEvent ( & event );

        switch ( event . kind ) 
        { 
            case  SDL_Quit: 
            exit ( 0 ); 
            break ; 
        } 
        Draw ();

    }

    return  0 ; 
}

void  Draw () 
{ 
    glClear (  GL_COLOR_BUFFER_BIT  );

    glMatrixMode (  GL_MODELVIEW  ); 
    glLoadIdentity (  );

    gluLookAt ( 3 , 3 , 3 , 0 , 0 , 0 , 0 , 0 , 1 );

    / * 3D design * /

    glFlush (); 
    SDL_GL_SwapBuffers (); 
}

No comments:

Post a Comment

Slider

Image Slider By engineerportal.blogspot.in The slide is a linking image  Welcome to Engineer Portal... #htmlcaption

Tamil Short Film Laptaap

Tamil Short Film Laptaap
Laptapp

Labels

About Blogging (1) Advance Data Structure (2) ADVANCED COMPUTER ARCHITECTURE (4) Advanced Database (4) ADVANCED DATABASE TECHNOLOGY (4) ADVANCED JAVA PROGRAMMING (1) ADVANCED OPERATING SYSTEMS (3) ADVANCED OPERATING SYSTEMS LAB (2) Agriculture and Technology (1) Analag and Digital Communication (1) Android (1) Applet (1) ARTIFICIAL INTELLIGENCE (3) aspiration 2020 (3) assignment cse (12) AT (1) AT - key (1) Attacker World (6) Basic Electrical Engineering (1) C (1) C Aptitude (20) C Program (87) C# AND .NET FRAMEWORK (11) C++ (1) Calculator (1) Chemistry (1) Cloud Computing Lab (1) Compiler Design (8) Computer Graphics Lab (31) COMPUTER GRAPHICS LABORATORY (1) COMPUTER GRAPHICS Theory (1) COMPUTER NETWORKS (3) computer organisation and architecture (1) Course Plan (2) Cricket (1) cryptography and network security (3) CS 810 (2) cse syllabus (29) Cyberoam (1) Data Mining Techniques (5) Data structures (3) DATA WAREHOUSING AND DATA MINING (4) DATABASE MANAGEMENT SYSTEMS (8) DBMS Lab (11) Design and Analysis Algorithm CS 41 (1) Design and Management of Computer Networks (2) Development in Transportation (1) Digital Principles and System Design (1) Digital Signal Processing (15) DISCRETE MATHEMATICS (1) dos box (1) Download (1) ebooks (11) electronic circuits and electron devices (1) Embedded Software Development (4) Embedded systems lab (4) Embedded systems theory (1) Engineer Portal (1) ENGINEERING ECONOMICS AND FINANCIAL ACCOUNTING (5) ENGINEERING PHYSICS (1) english lab (7) Entertainment (1) Facebook (2) fact (31) FUNDAMENTALS OF COMPUTING AND PROGRAMMING (3) Gate (3) General (3) gitlab (1) Global warming (1) GRAPH THEORY (1) Grid Computing (11) hacking (4) HIGH SPEED NETWORKS (1) Horizon (1) III year (1) INFORMATION SECURITY (1) Installation (1) INTELLECTUAL PROPERTY RIGHTS (IPR) (1) Internal Test (13) internet programming lab (20) IPL (1) Java (38) java lab (1) Java Programs (28) jdbc (1) jsp (1) KNOWLEDGE MANAGEMENT (1) lab syllabus (4) MATHEMATICS (3) Mechanical Engineering (1) Microprocessor and Microcontroller (1) Microprocessor and Microcontroller lab (11) migration (1) Mini Projects (1) MOBILE AND PERVASIVE COMPUTING (15) MOBILE COMPUTING (1) Multicore Architecute (1) MULTICORE PROGRAMMING (2) Multiprocessor Programming (2) NANOTECHNOLOGY (1) NATURAL LANGUAGE PROCESSING (1) NETWORK PROGRAMMING AND MANAGEMENT (1) NETWORKPROGNMGMNT (1) networks lab (16) News (14) Nova (1) NUMERICAL METHODS (2) Object Oriented Programming (1) ooad lab (6) ooad theory (9) OPEN SOURCE LAB (22) openGL (10) Openstack (1) Operating System CS45 (2) operating systems lab (20) other (4) parallel computing (1) parallel processing (1) PARALLEL PROGRAMMING (1) Parallel Programming Paradigms (4) Perl (1) Placement (3) Placement - Interview Questions (64) PRINCIPLES OF COMMUNICATION (1) PROBABILITY AND QUEUING THEORY (3) PROGRAMMING PARADIGMS (1) Python (3) Question Bank (1) question of the day (8) Question Paper (13) Question Paper and Answer Key (3) Railway Airport and Harbor (1) REAL TIME SYSTEMS (1) RESOURCE MANAGEMENT TECHNIQUES (1) results (3) semester 4 (5) semester 5 (1) Semester 6 (5) SERVICE ORIENTED ARCHITECTURE (1) Skill Test (1) software (1) Software Engineering (4) SOFTWARE TESTING (1) Structural Analysis (1) syllabus (34) SYSTEM SOFTWARE (1) system software lab (2) SYSTEMS MODELING AND SIMULATION (1) Tansat (2) Tansat 2011 (1) Tansat 2013 (1) TCP/IP DESIGN AND IMPLEMENTATION (1) TECHNICAL ENGLISH (7) Technology and National Security (1) Theory of Computation (3) Thought for the Day (1) Timetable (4) tips (4) Topic Notes (7) tot (1) TOTAL QUALITY MANAGEMENT (4) tutorial (8) Ubuntu LTS 12.04 (1) Unit Wise Notes (1) University Question Paper (1) UNIX INTERNALS (1) UNIX Lab (21) USER INTERFACE DESIGN (3) VIDEO TUTORIALS (1) Virtual Instrumentation Lab (1) Visual Programming (2) Web Technology (11) WIRELESS NETWORKS (1)

LinkWithin