We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 14
CG Caro qa)
_-AMarks
wey «Paratha aii auth 1h
tearing te —disvipbin Ga steed hier
ta hp be prayed Jolt. ons hy La
eign A apd
__—paccollel _frojution ——____
Vata
2 Define “Ponape chive _pusiecton with figs
Sed. enth 2d
ene it gtd ik tev je glare 2 lee :
ng fe in Called of tnsperbiise 7
F pojection c — = Jane =
- — Ee eenpaens
IZ
a Def vaniskiag — point
38 Wad ich_a_cet of Projetted eaveliel
Lint Lines_oppfuans to eo verge ix calles!ae Give use appticdbrons ‘| * Doftt, Cuddiny :
9 Desth Cuein a“ afflict by choosing A wea rinee
and a mln Intawul, value anal a tang of
s . é
dlalances vie usted Us infenuity nto vee
9) Austher appoliation ff cbf ting How sling
Net the alee fave mm Lhe preesived
intensity 4 objerts ‘
5d Define Orthognal pxgjecttorr view Volume
> She limits whteh ane unecl do form th top»
bofon ond =o gids 4 a chipper Asgtor called
G
the orthegonal pbrajection view Seba
ck dist andl olfine vigible gurfare drboetion
—) Objest-9pace milhods 2) Sage - pa @ mathods
tp dist tie lower 44 Dogical Sinful devices
7) STRING — uy) CHoIce
___ 2)_ LOCATOR . 5) VALDATORS
a). Pick 6) gTROKELtt Define measure aul “Tht
Toft Sieh a of prot, in
> MEASURE Bg a dwia i. whal the ly
Le
tothe. _applications pres ham. . ee
emi: “Owen i a ele 7
Phot ppuovicles Ho Asc valu 9 f Tefal
—~)_Locator “al Joints dasa pani 0-foston
Bin canted Lentini ae pity
tally ted
taney track a
Plc? A pick ke device _xoboxas the ident eng
Object on the — display do the user
ted udith the Saree
s_ Gs isonl __tenplemertte y we Le “
Physical Avice as te lotator buti — Separate — Sof care interfau. ty He liasir Pr x
4) Chores A choice device alloves the uss
select otte a_diccrate -rrumber g bio
ay gees Aarious widlaets bu
the ufado A widget is a 3
Saecatlive tombanent puovicled fp Pea went,
éyster cr a tool kit - —
5) VALUATORS 3 Spey beovide aoraleg inbed The se
——} oes pablical_ay ste aie -
Lond o> al olials ee
to brcvicl value.
—6) Stroxe? of Stroke devi Me Mian tay Bh pst
——Eranbls pushing deion a mowse been =
lean data mb ¢ eka ad
teleaning button ends Hess soln Cc]Q3) What is double buffering? How openGL
implements double buffering?
DOUBLE BUFFERING:
» Double|buffering!is n must in such animations where the primitives,
attributes and viewing conditions are changing continuously.
> Double buffer consists of two buffers: front buffers and back buffers.
Doubles buffering, — mode can be initialized:
glutinitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
> Further in the display function, we have to include: glutSwapBuffers)
to exchange the contents of front and the back buffer,
y
Using this approach, the problems associated with flicker can be
eliminated.
USING TIMER:
+ To understand the usage of timer, consider cube rotation program and
its execution is done by using fast GPU (modern GPUs can render tens of
millions of primitives per second) then cube will be rendered thousands
of time per second and we will see the blur on the display.
> Therefore, GLUT provides the following timer function:
glutTimerFuncfint delay, vold{*timer_func {int}, int value)
Execution of this function starts timer in the event loop that delays for
delay milliseconds. When timer has counted down, timer func is executed
the value parameter allow user to Pass variable into the timer call back.Q2)With diagram, Explain the steps for generating
three dimensional viewing effects?
Generating Three-Dimensional Viewing Effects
Y By varying the viewing parameters, we can obtain different views of objects in a scene.
Y we could change the direction of N to display objects at positions around the viewing-
coordinate origin.
Y We could also vary N to create a composite display consisting of multiple views from a
fixed camera position.
Y In interactive applications, the normal vectorNis the viewing parameter that is most often
changed. Of course,when we change the direction for N,we also have to change the other
axis vectors to maintain a right-handed viewing-coordinate system.
¥ If we want to simulate an animat
ion panning effect, as when a camera moves through a
scene or follows an object that is moving through a scene, we can keep the direction for
N fixed as we move the view point,
ve
b
Y Altematively, different views of an object or group of objects can be generated using
geometric transformations without changing the viewing parametersQ4)How popup menu's are created using GLUT,
illustrate with an example.
5.1.7 MENUS
> Menus are an important feature of any application program. OpenGL
provides a feature called “Pop-up-menus” using which sophisticated
interactive applications can be created.
Menu creation involves the following steps:
Define the actions corresponding to each entry in the menu.
Link the menu to a corresponding mouse button.
Register a callback function for each entry in the menu,
pe
glutcreatetens(deo2ec) :
thaamenutatry (“quit 1);
uthaamenutatry ("decrease gus
elutAveacthens (CUT RIGHT
‘The glutCreateMenu() registers the callback function demo_menu. The
function glutAddMenuEntry() adds the entry in the menu whose name is
¥
pased in first argument and the second argument is the identifier passed
to the callback when the entry is selected.
‘yold deae_neaaCint 18)
<
sviten(tad
4
case 15 ext (0)5
reat
> GLUT also supports the creation of hierarchical menus which is given
below:Q5) Explain symmetric perspective projection
frustum in detail with neat diagram.
& Perspective:
Y The line from the projection reference point through the center of the clipping window
and on through the view volume isthe centerline fora perspectiveprajection frustum.
It this centerline is perpendicular to the
respect to its centerline)
sw plane, we have a symmetric frastum (with
Frosum Centetine
Fac Cliping
Pane
View lane
Cee Yer tee)
¥ Because the frustum centerline intersects the view plane at the coordinate location (typ,
Yor» Zaph We can express the comer positions for the clipping window in terms of the
window
n= Yor
Yn = Yep +t
Y Another way to specify a symmetric perspective projection is to use parameters that
approximate the properties of « camera Tens
YA photograph
film plane.
Reflected light rays from the objects in a scene are collected on the film plane from
produced with a symmetric perspective projection of a scene onto the
within the “cone of vision” of the camera.
¥ This cone of vision can be referenced with a field-of-
the size ofthe camera lens.
jew angle, which is a measure of
A large field-of-view angle, for example, corresponds to a wide-angle lens.¥ In computer graphics, the cone of vision
approximated with a symmetric frustum, and
angle (o specify an angular size forthe frustum,
we can use a feld-o:
Serpe re
Vinee
Prjecon
Relerence
Rant
¥ Fora given projection reference point and view-plane position, the feld-of view angle
determines the height of the clipping window from the right triangles in the diagram of
Figure below, we see that
Gipping Window
sa that the clipping-window height can be calculated as,
ons)
‘Therefore the diagonal elements with the value :jp~y could be replaced by either of
height =
the following two expressions
Fry —ty = EM ca( 2)10 marks
Q1)What is meant bye measure and trigger of
a device?Explain with neat diagram various
input modes.
1, Measure of a device is what the device returns to the application
program,
2. Trigger of a device is a physical input on the device with which the user
can send signal to the computer
Example 1: The measure of a keyboard is a single character or array of
characters where as the trigger is the enter key.
Example 2: The measure of a mouse is the position of the cursor whereas the
trigger is when the mouse button is pressed.
The application program can obtain the measure and trigger in three distinct
modes.
1. REQUEST MODE: In this mode, measure of the device is not returned to
the program until the device is triggered.
« For example, consider a typical C program which reads a character input
using scanf). When the program needs the input, it halts when it
encounters the scanf{) statement and waits while user type characters at
the terminal. The data is placed in a keyboard buffer (measure) whose
contents are returned to the program only after enter key (trigger) is
pressed.
* Another example, consider a logical device such as locator, we can move
out pointing device to the desired location and then trigger the device
with its button, the trigger will cause the location to be returned to the
application program.
Request
Trigger Measure Program
process Trigger [Process
Measure
Figure: Request Mode2 SAMPLE MODE: In this mode, input is immediate. As soon as the
function call in the user program is executed, the measure is returned. Hence
Sample
Measure
process
Measure
Figure: Sample Mode
no trigger is needed.
Both request and sample modes are useful for the situation if and only if there
is a single input device from which the input is to be taken. However, in case of
flight simulators or computer games variety of input devices are used and these
mode cannot be used. Thus, event mode is used.
3. EVENT MODE: This mode can handle the multiple interactions.
* Suppose that we are in an environment with multiple input devices, each
with its own trigger and each running a measure process.
* Whenever a device is triggered, an event is generated.The device measure
including the identifier for the device is placed in an event queue.
* If the queue is empty, then the application program will wait until an
event occurs. If there is an event in a queue, the program can look at the
first event type and then decide what to do.
‘Await
Trigger ‘Measure Event Ce Program
Process Trigger proeeae Measure queue
Event
Figure: Event-mode model
Another approach is to associate a function when an event occurs, which is
called as “call back,”Q3)Explain how an event driven input can be
programmed for mouse device.
5.1.6 PROGRAMMING EVENT DRIVEN INPUT
> The various events can be recognized by the window system and call
back function can be called for each of these events.
USING POINTING DEVICES
> Pointing devices like mouse, trackball, data tablet allow programmer to
indicate a position on the display.
> There are two types of event associated with pointing device, which is
conventionally assumed to be mouse but could be trackball or data
tablet also.
1, MOVE EveENT - is generated when the mouse is move with one of the
button being pressed. If the mouse is moved without a button being
pressed, this event is called as “passive move event”.
2. MOUSE EvENT - is generated when one of the mouse buttons is either
pressed or released.
> The information returned to the application program includes button
that generated the event, state of the button after event (up or down),
position (x,y) of the cursor. Programming a mouse event involves two
steps:
The mouse callback function must be defined in the form: void
myMousefint button, int state, int x, int y) is written by the
programmer.
For example,
void myMouse(int button, int state, int x, int y)
{
if(button==GLUT_LEFT_BUTTON && state == GLUT_DOWN)
exit(0);Module 5 **4SAI RAM*** Input and Interaction
The above code ensures whenever the left mouse button is pressed down,
execution of the program gets terminated.
2. Register the defined mouse callback function in the main function, by
means of GLUT function:
glutMouseFunc{myMouse);
Write an OpenGL program to display square when a left button is
pressed and to exit the program if right button is pressed.
#include
#include
#include
int wh=500, ww=500;
float siz=3;
void myinit()
{
glClearColor(1.0,1.0,1.0,1.0);
glViewPort(0,0,w,h)
glMatrixMode(GL_PROJECTION);
glLoadidentity);
gluOrtho2D(0,{GLdouble) ww, 0, (GLdouble) wh);
glMatrixMode(GL_MODELVIEW);
glColor3f(1,0,0);
void drawsq (int x, int y)
{
y=wh-y;
glBegin(GL_POLYGON);
glVertex2f(x+siz, y+siz);
Mr. Sukruth Gowda MA, Dept., of CSE, SVIT 7Module 5 PASSAT RAM*A* Input and Interaction
glVertex2i{x-siz, y+siz);
glVertex2f{x-siz, y-siz);
glVertex2f{x+siz, y-siz);
glEnd();
glFlush();
}
void display()
{
giClear(GL_COLOR_BUFFER BIT);
void myMouse(int button, int state, int x, int y)
{
if(outton=-GLUT_LEFT_BUTTON && state == GLUT_DOWN)
drawsq(x,y);
if(outton=-GLUT_RIGHT_BUTTON && state == GLUT_DOWN)
exit(0);
J
void main(int arge, char **argy)
(
glutinit(&arge, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutinitWindowSize(wh, ww);
glutCreateWindow(“square”);
glutDisplayFunc(display);
glutMouseFune{myMouse);
myinit();
glutMainLoop();
‘Mr, Sukruth Gowda MA, Dept, of CSE, SVIT Is