CG Lab Manual 2018-19-V1
CG Lab Manual 2018-19-V1
Laboratory
SE
Assignment No: - A1
Assignment No. 1 Revised On: 13/12/2018
PROBLEM STATEMENT Write C++ program to draw the following pattern using Line drawing
/DEFINITION algorithms. Use Bresenham’s line drawing algorithms for square and
DDA line drawing algorithm for diamond.
Operating Systems
S/W PACKAGES AND 1. Open source Linux or its derivative
HARDWARE
APPARATUS USED 2. Open Source C++ Programming tool like G++/GCC
1. Date
INSTRUCTIONS FOR 2. Assignment no.
WRITING JOURNAL 3. Problem definition
4. Learning objective
5. Learning Outcome
6. Concepts related Theory
7. Related Mathematics
8. Algorithm.
9. Dry Run Example
10. Test Cases
11. Conclusion and applications
Assignment A1
Aim
Write a C++ class for a Line drawing method using overloading DDA and Bresenham’s
Algorithms, inheriting the pixel or point.
Prerequisites
Concept of drawing a pixel or point.
Concept of drawing a line.
Object oriented programming features.
Learning Objectives
To understand concept of DDA Algorithm.
To understand concept of Bresenham’s Algorithms.
To understand concept & features of object oriented programming.
To understand different manipulation facilities in c++ .
Learning Outcome
After successfully completing this assignment, you should be able to
Draw a line using DDA Algorithm.
Draw a line using Bresenham’s Algorithm.
Begin.
If abs(x2-x1) ≥ abs (y2-y1) then
Length=abs(x2-x1)
Else
Length=abs(y2-y1)
End if.
Δx=(x2-x1)/length
Δy=(y2-y1)/length
X=x1+0.5
Y=y1+0.5
Bresenham’s Algorithm:-
- Originally designed for digital plotters ,
Equally suited for use with CRT raster device
For,
e=e+m
ē/2Δx = ē/2Δx+Δy/Δx
ē=ē+2Δy
Bresenham’s integer Algorithm for line :-
For the first octant the line end points are (x1,y1) and (x2,y2)
assumed not equal
// initialize variables//
X=x1
Y=y1
Δx=x2-x1
Δy=y2-y1
ē=2*Δy-Δx
begin the main loop
for i=1 to Δx
setpixel(x,y)
while(ē>0)
y=y+1
ē=ē-2*Δx
endwhile
x=x+1
ē=ē+2*Δy
next i
finish.
Sr. No Steps
1. Enter the coordinates of I= { x1,y1,x2,y2,choice}
line.
Review Questions
What is DDA Algorithm?
What is Bresenham’s Algorithm?
Compare DDA Algorithm and Bresenham’s Algorithm?
What are advantages of Bresenham’s Algorithm over DDA Algorithm?
What are basic functions used for line drawing?
Test cases:
Conclusion :
After successfully completing this assignment, student should be able to
understand and implement line drawing using DDA algorithm and Bresenham’s Algorithm
in C/ C++.
Computer Graphics
Laboratory
SE
Assignment No: - A2
Asignment No. A2 Revised On: 13/12/2018
PROBLEM STATEMENT Write C++ program to draw inscribed and Circumscribed circles in the
/DEFINITION triangle as shown in an example below. Use Bresenham’s Circle
drawing algorithm for outer circle and DDA circle for inner circle.
Use any Line drawing algorithm for drawing triangle
Operating Systems
S/W PACKAGES AND 1. Open source Linux or its derivative
HARDWARE 2. Open Source C++ Programming tool like G++/GCC
APPARATUS USED
REFERENCES J. Foley, V. Dam, S. Feiner, J. Hughes, “Computer Graphics
Principles and Practice”, 2nd Edition,Pearson Education, 2003, ISBN
81 – 7808 – 038 – 9.
1.Date
INSTRUCTIONS FOR 2. Assignment no.
WRITING JOURNAL 3.Problem definition
4.Learning objective
5.Learning Outcome
6.Concepts related Theory
7.Related Mathematics
8. Algorithm.
9.Dry Run Example
10.Test Cases
11.Conclusion and applications
Assignment A2
Aim
Write a C++ class for a circle drawing inheriting line class .
Prerequisites
Concept of drawing a pixel or point.
Concept of drawing a line.
Object oriented programming features.
Learning Objectives
To understand concept of inheritance.
To understand concept & features of object oriented programming.
To understand different manipulation facilities in c++.
Learning Outcome
After successfully completing this assignment, you should be able to
Draw a circle by inheriting the members of line class.
Related Mathematics
Let S be the system for drawing a circle by inheriting line class, such that
S = {s, e, DD , NDD I, O, Fme , Ffriend | ᶲ};
Where,
s is a start state of the class S.
e is a end state of the class S.
DD = Deterministic data; here x interval dx, y interval dy along a line and slope of
given line.
NDD = Non deterministic data; here tendency of line increment in horizon might be
uncertain initially.
Input Analysis:-
I be the input to the system S. The system S takes x and y coordinates of center
C of circle.
Ii = {C, r | C is the centre and r is the radius of circle.}
C = {(x, y) | x, y are x and y coordinates of centre C}
r = r is a finite positive integer.
Functions:-
Ffriend is a friend class of class Fme having input parameter
Ffriend = {C, r, f1,f2}
C is the Centre of circle.
R is radius of circle.
f1 = acceptinput(); -function for accepting input from user.
f2 = drawCircle(x, y, r); - function for drawing a line.
Output:-
O= {locus of points around centre as per the specified radius.}
Concepts related Theory
Bresenham’s Circle Generation Algorihtm:-
Only one octant of the circle need be generated. The other parts are obtained by
successive reflection.
δ = 2(Δi + yi ) – 1.
Case 2:-
Case 3:-
Consider MD and MV.
δ’ ≤ o Choose MD at (xi + 1, yi -1 )
δ’ ˃ o Choose MV at (xi , yi - 1)
Δi = 0 (xi + 1, yi -1 ) MD
Δi ˂ 0
δ≤0 (xi + 1, yi ) MH
δ˃0 (xi + 1, yi -1 ) MD
Δi ˃ 0
δ' ≤ 0 (xi + 1, yi -1 ) MD
δ’ ˃ 0 (xi , yi -1 ) Mv
For any given point on the circle there are only three possible selection of the next pixel
which best represents the circle, horizontally to the right, diagonally downward to the
right and vertically downward.
If Δi ˂ 0
Then Point inside the circle.
If Δi ˃ 0
Then Point outside the circle.
Where
Δi = ( xi + 1)2 + (yi - 1)2 – R2
Move Vertically
Subroutine MV (xi , yi , Δi)
yi = yi - 1
Δi = Δi - 2 yi + 1
End Sub
Review Questions
Explain Bresenham’s circle drawing algorithm?
Explain Δ,δ,δ’ in Bresenham’s circle drawing algorithm with relate mathematics.
Conclusion :
After successfully completing this assignment, student should be able to
draw a circle by inheriting line class in C/ C++
Computer Graphics
Laboratory
SE
Assignment No: - A3
Assignment A3 Revised On: 13/12/2018
TITLE To Implement 2D transformations.
PROBLEM STATEMENT Write C++/Java program to draw 2-D object and perform following
/DEFINITION basic transformations,
a) Scaling
b) Translation
c) Rotation
Use operator overloading.
To understand mathematical concepts behind implementation
OBJECTIVE of 2D transformations
To Implement 2D transformations using matrix multiplication
in C++/Java
S/W PACKAGES AND 1. Open source Linux or its derivative
HARDWARE
APPARATUS USED 2. Open Source C++ Programming tool like G++/GCC
REFERENCES J. Foley, V. Dam, S. Feiner, J. Hughes, “Computer Graphics
Principles and Practice”, 2nd Edition,Pearson Education, 2003, ISBN
81 – 7808 – 038 – 9.
1.Date
INSTRUCTIONS FOR 2. Assignment no.
WRITING JOURNAL 3.Problem definition
4.Learning objective
5.Learning Outcome
6.Concepts related Theory
7.Related Mathematics
8. Algorithm.
9.Dry Run Example
10.Test Cases
11.Conclusion and applications
Assignment A3
Aim
Write C++/Java program to draw 2-D object and perform following basic transformations.
Prerequisites
Concept of drawing a line.
Object oriented programming features.
Learning Objectives
To understand concept & features of object oriented programming.
To understand the basic graphic functions in C/C++.
Learning Outcome
After successfully completing this assignment, you should be able to draw
different transformations like scaling, translation and rotation.
So, x’ = x * sx and
y’ = y * sy.
The scaling factor sx, sy scales the object in X and Y direction respectively. So, the above
equation can be represented in matrix form:
Or P’ = S . P
Scaling process:
If the scaling factor S is less than 1, then we reduce the size of the object. If the scaling
factor S is greater than 1, then we increase size of the object.
Algorithm:
1. Make a 2x2 scaling matrix S as:
Sx 0
0 Sy
2. For each point of the polygon.
(i) Make a 2x1 matrix P, where P[0][0] equals to x coordinate of the point and P[1][0]
equals to y coordinate of the point.
(ii) Multiply scaling matrix S with point matrix P to get the new coordinate.
3. Draw the polygon using new coordinates.
Translation:
A translation moves an object to a different position on the screen. You can translate a
point in 2D by adding translation coordinate (tx, ty) to the original coordinate (X, Y) to
get the new coordinate (X’, Y’).
X’ = X + tx
Y’ = Y + ty
The pair (tx, ty) is called the translation vector or shift vector. The above equations can
also be represented using the column vectors.
We can write it as −
P’ = P + T
Rotation:
In rotation, we rotate the object at particular angle θ (theta) from its origin. From the
following figure, we can see that the point P(X, Y) is located at angle φ from the
horizontal X coordinate with distance r from the origin.
Let us suppose you want to rotate it at the angle θ. After rotating it to a new location, you
will get a new point P’ (X’, Y’).
Using standard trigonometric the original coordinate of point P(X, Y) can be represented
as −
X=rcosϕ......(1)
Y=rsinϕ......(2)
Same way we can represent the point P’ (X’, Y’) as −
x′=rcos(ϕ+θ)=rcosϕcosθ−rsinϕsinθ.......(3)
y′=rsin(ϕ+θ)=rcosϕsinθ+rsinϕcosθ.......(4)
Substituting equation (1) & (2) in (3) & (4) respectively, we will get
x′=xcosθ−ysinθ
y′=xsinθ+ycosθ
Representing the above equation in matrix form,
[X′Y′]=[XY][cosθ sinθ
-sinθ cosθ] OR
P’ = P . R
Where R is the rotation matrix
R=[cosθ sinθ
-sinθ cosθ]
Conclusion:
After successfully completing this assignment, student should be able to perform basic
transformations like translation, scaling and rotation in C/ C++.
Computer Graphics
Laboratory
SE
Assignment No: - A4
Assignment A4 Revised On: 13/12/2018
PROBLEM STATEMENT Write C++ program to draw the polygons by using the mouse. Choose
/DEFINITION colors by clicking on the designed color pane. Use window port to
draw. Use DDA algorithm for line drawing.
To understand concept of polygon drawing
OBJECTIVE To understand the basic graphic functions in C++ for mouse
click event handling.
Operating Systems
S/W PACKAGES AND 1. Open source Linux or its derivative
HARDWARE
APPARATUS USED 2. Open Source C++ Programming tool like G++/GCC
1.Date
INSTRUCTIONS FOR 2. Assignment no.
WRITING JOURNAL 3.Problem definition
4.Learning objective
5.Learning Outcome
6.Concepts related Theory
7.Related Mathematics
8. Algorithm.
9.Dry Run Example
10.Test Cases
11.Conclusion and applications
Assignment A4
Aim
Write a C/C++ program to draw a polygon with programmable edges.
Prerequisites
Concept of drawing a line.
Object oriented programming features.
Learning Objectives
To understand concept & features of object oriented programming.
To understand the basic graphic functions in C/C++.
Learning Outcome
After successfully completing this assignment, you should be able to draw a
convex polygon with programmable edges.
Related Mathematics
Let S be the system for drawing a Convex polygon with programmable edges,
such that
S = {s, e, I, O, DD, NDD, Fme , Ffriend | ᶲ};
Where,
s is a start state of the class S.
x and y coordinates of vertices of edge are initialized to zero.
e is a end state of the class S.
DD = Deterministic data; here x interval dx, y interval dy along a line and slope of
given line.
NDD = Non deterministic data; here tendency of line increment in horizon might be
uncertain initially.
Input Analysis:-
I be the input to the system S. The system S takes x and y coordinates of vertices
V of polygon.
Ii = { V1, V2, …Vn.| Vi are vertices of polygon.}
Vi = {(xi, yi) | xi, yi are x and y coordinates of vertices of polygon.}
Functions:-
Ffriend is a friend class of class Fme having input parameter
Ffriend = { Vi , f1, f2 }
f1 = acceptinput(); -function for accepting input from user.
f2 = drawpolygon(V1, V2, …Vn.); - function for drawing a line using DDA
algorithm.
Output:-
O= {Polygon displayed on the screen.}
Concepts related Theory :-
Convex polygon:-
A convex polygon is a simple polygon whose interior is a convex set. The following
properties of a simple polygon are both equivalent to convexity:
• Every internal angle is less than or equal to 180 degrees.
• Every line segment between two vertices remains inside or on the boundary of the
polygon.
A simple polygon is strictly convex if every internal angle is strictly less than 180
degrees. Equivalently, a polygon is strictly convex if every line segment between two
nonadjacent vertices of the polygon is strictly interior to the polygon except at its
endpoints. A convex polygon is defined as a polygon with all its interior angles less than
180°. This means that all the vertices of the polygon will point outwards, away from the
interior of the shape. Think of it as a 'bulging' polygon. Note that a triangle (3-gon) is
always convex.
Review Questions
What is polygon?
Explain convex and concave polygon?
Conclusion :
After successfully completing this assignment, student should be able to
understand and draw a convex polygon with programmable edges C/ C++.
Computer Graphics
Laboratory
SE
Assignment No: - A5
Assignment A5 Revised On: 13/12/2018
TITLE
PROBLEM STATEMENT Write C++/Java program to draw a 4X4 chessboard rotated 45˚ with
/DEFINITION the horizontal axis. Use Bresenham algorithm to draw all the lines.
Use seed fill algorithm to fill black squares of the rotated chessboard.
To understand mathematical concept behind rotation,
OBJECTIVE Bresenham’s line algorithm and seed fill.
To plot and fill 4X4 chessboard rotated 45˚ with the horizontal
axis.
1.Date
INSTRUCTIONS FOR 2. Assignment no.
WRITING JOURNAL 3.Problem definition
4.Learning objective
5.Learning Outcome
6.Concepts related Theory
7.Related Mathematics
8. Algorithm.
9.Dry Run Example
10.Test Cases
11.Conclusion and applications
Concept related Theory:
Algorithm:
1. Calculate dx=abs(x2-x1) and dy=abs(y2-y1)
2. if dx>=dy
3. Initialize decision parameter p=2*(dy)-dx and i=0
4. while(i<dx)
1) putpixel(x,y,colour)
2) if p<0
3) p=p+2*dy
4) else
5) p=p+2*(dy-dx)
6) increment y
7) end else
8) increment x and i
5. end while
6. if dy>dx
7. Initialize decision parameter p=2*(dy)-dx and i=0
8. while(i<dy)
1) putpixel(x,y,colour)
2) if p<0
3) p=p+2*dx
4) else
5) p=p+2*(dx-dy)
6) increment x
7) end else
8) increment y and i
9. end while
Algorithm:
Flood-fill (node, target-color, replacement-color):
1. If target-color is equal to replacement-color, return.
2. If the color of node is not equal to target-color, return.
3. Set the color of node to replacement-color.
4. Perform Flood-fill (one step to the south of node, target-color, replacement-color).
Perform Flood-fill (one step to the north of node, target-color, replacement-color).
Perform Flood-fill (one step to the west of node, target-color, replacement-color).
Perform Flood-fill (one step to the east of node, target-color, replacement-color).
5. Return.
Computer Graphics
Laboratory
SE
Assignment No: - B1
Assignment B1 Revised On: 13/12/2018
PROBLEM STATEMENT Write C++/Java program for line drawing using DDA or Bresenham’s
/DEFINITION algorithm with patterns such as solid, dotted, dashed, dash dot and
thick.
To understand concept of different line styales, e.g. thick,thin
OBJECTIVE dotted etc.
To Implement DDA/Bresenham for drawing lines.
Operating Systems
S/W PACKAGES AND 1. Open source Linux or its derivative
HARDWARE
APPARATUS USED 2. Open Source C++ Programming tool like G++/GCC
1.Date
INSTRUCTIONS FOR 2. Assignment no.
WRITING JOURNAL 3.Problem definition
4.Learning objective
5.Learning Outcome
6.Concepts related Theory
7.Related Mathematics
8. Algorithm.
9.Dry Run Example
10.Test Cases
11.Conclusion and applications
Aim:
Write C++/Java program for line drawing using DDA or Bresenham’s algorithm with patterns
such as solid, dotted, dashed, dash dot and thick.
Prerequisites:
Line Drawing Algorithm
Different types of line.
Learning Objectives
To understand the concepts of patterns of line.
To improve the coding skill of students
To learn the concept of anti-aliasing.
Learning Outcome
After completion of this assignment student should able to draw different line
patterns.
Related Mathematics:
Let S be the system for drawing a line using DDA algorithm and
Bresenham’s Algorithm, such that
S = {s, e, I, O, DD, NDD, Fme , Ffriend | ᶲ};
Where,
s is a start state of the class S.
x and y coordinates of start point and end point of line are initialized to zero.
e is a end state of the class S.
DD = Deterministic data; here x interval dx, y interval dy along a line and slope of
given line.
NDD = Non deterministic data; here tendency of line increment in horizon might be
uncertain initially.
Input Analysis:-
I be the input to the system S. The system S takes x and y coordinates of point
p1, p2.
Ii = {(p1, p2) | p1, p2 are end points of line segment}
Pi = {(xi, yi) | xi, yi are x and y coordinates of point pi}
Functions:-
Ffriend is a friend class of class Fme having input parameter
Ffriend = { p1, p2, f1, f2 ,f3}
f1 = acceptinput(); -function for accepting input from user.
f2 = ddaLine(p1, p2); - function for drawing a line using DDA algorithm.
f3 = bresenhamLine(p1, p2); - function for drawing a line using Bresenham’s
algorithm.
Output:-
O= {p1, p2, ….pn | where Pi Ɛ L ˄ L satisfies y = mx + C }
Conclusion:
After completion of this assignment student should able to draw different line patterns.
Computer Graphics
Laboratory
SE
Assignment No: - B2
Assignment B2 Revised On: 13/12/2018
PROBLEM STATEMENT Write C++/Java program to draw a convex polygon and fill it with
/DEFINITION desired color using Seed fill algorithm. Use mouse interfacing to draw
polygon.
To understand concept of seed fill.
OBJECTIVE To fill polygon using seed fill algorithm.
Operating Systems
S/W PACKAGES AND 1. Open source Linux or its derivative
HARDWARE
APPARATUS USED 2. Open Source C++ Programming tool like G++/GCC
1.Date
INSTRUCTIONS FOR 2. Assignment no.
WRITING JOURNAL 3.Problem definition
4.Learning objective
5.Learning Outcome
6.Concepts related Theory
7.Related Mathematics
8. Algorithm.
9.Dry Run Example
10.Test Cases
11.Conclusion and applications
Output:
Computer Graphics
Laboratory
SE
Assignment No: - B3
Assignment B3 Revised On: 13/12/2018
1.Date
INSTRUCTIONS FOR 2. Assignment no.
WRITING JOURNAL 3.Problem definition
4.Learning objective
5.Learning Outcome
6.Concepts related Theory
7.Related Mathematics
8. Algorithm.
9.Dry Run Example
10.Test Cases
11.Conclusion and applications
Aim:
Write C++/Java program to implement Cohen-Sutherland line clipping algorithm for given
Conclusion:
After completion of this assignment student should able clip line with respect to
desire window.
Computer Graphics
Laboratory
SE
Assignment No: - B4
Assignment No. B4 Revised On: 13/12/2018
TITLE Reflection of 2-D object about X axis, Y axis and about X=Y axis.
1.Date
INSTRUCTIONS FOR 2. Assignment no.
WRITING JOURNAL 3.Problem definition
4.Learning objective
5.Learning Outcome
6.Concepts related Theory
7.Related Mathematics
8. Algorithm.
9.Dry Run Example
10.Test Cases
11.Conclusion and applications
Aim
Write C++/Java program to implement reflection of 2-D object about X axis, Y axis
and about X=Y axis. Also rotate object about arbitrary point given by user.
Prerequisites
Concept of linear algebra with vectors, matrices, and transforms.
Object oriented programming features operator overloading in classes.
Learning Objectives
It introduces the basics of linear algebra with vectors, matrices, and
transforms.
It shows you how linear algebra relates to simple computer graphics.
It gives you practice with operator overloading in classes.
Learning Outcome
After successfully completing this assignment, you should be able to
Reflection of 2-D object about X axis, Y axis and about X=Y axis.
Related Mathematics
Let S be the system for drawing a 2-D object (for e.g. Triangle)
S = {s, e, I, O, DD, NDD, F, θ (theta)};
Where,
s is a start state of the class S.
x and y coordinates of start point and end point of line are initialized to zero.
e is a end state of the class S.
DD = Deterministic data.
NDD = Non deterministic data; here tendency of line increment in horizon might be
uncertain initially.
Input Analysis:-
I be the input to the system S. The system S takes x and y coordinates of point
p1, p2.
Ii = {(p1, p2) | p1, p2 are end points of line segment}
Pi = {(xi, yi) | xi, yi are x and y coordinates of point pi}
Functions:-
F is a class having input parameter
F = { f1, f2, f3, f4}
f1 = drawObject (); -function for accepting input from user to draw object.
f2 = reflectXaxis(); - function for reflecting 2D object about X axis.
f3 = reflectYaxis(); - function for reflecting 2D object about X axis.
f4 = reflectXYaxis(); - function for reflecting 2D object about X=Y axis.
Output:-
O= {Display 2-D object according to reflection choice on screen}
2D transformations:
Reflection is nothing but producing mirror image of an object. Reflection can be done
just by rotating the object about given axis of reflection with an angle of 180 degrees.
Conclusion :
After successfully completing this assignment, student should be able to
perform basic 2D reflection about X axis, Y axis and about X=Y axis.
Computer Graphics
Laboratory
SE
Assignment No: - B5
Assignment No. B5 Revised On: 13/12/2018
TITLE Hilbert curve using concept of fractals.
PROBLEM STATEMENT Write C++/Java program to generate Hilbert curve using concept of
/DEFINITION fractals.
1.Date
INSTRUCTIONS FOR 2. Assignment no.
WRITING JOURNAL 3.Problem definition
4.Learning objective
5.Learning Outcome
6.Concepts related Theory
7.Related Mathematics
8. Algorithm.
9.Dry Run Example
10.Test Cases
11.Conclusion and applications
Aim
Write C++/Java program to generate Hilbert curve using concept of fractals.
Prerequisites
Concept of linear algebra with vectors, matrices, and transforms.
Object oriented programming features operator overloading in classes.
Learning Objectives
It introduces the basics of linear algebra with vectors, matrices, and
transforms.
It shows you how linear algebra relates to simple computer graphics.
Learning Outcome
After successfully completing this assignment, you should be able to
Generate Hilbert curve using concept of fractals.
Related Mathematics
Let S be the system for drawing a 2-D object
S = {s, e, I, O, DD, NDD, F};
Where,
s is a start state of the class S.
x and y coordinates of start point and end point of line are initialized to zero.
e is a end state of the class S.
DD = Deterministic data.
NDD = Non deterministic data; here tendency of line increment in horizon might be
uncertain initially.
Input Analysis:-
I be the input to the system S.
Functions:-
F is a class having input parameter
F = { f1}
f1 = hilbert(); -function to generate Hilbert curve using concept of fractals..
Output:-
O= {Hilbert curve}
Hilbert curve:
Space filling curve.
Drawn by connecting centers of 4 sub‐squares, make up larger square.
Iteration 0: 3 segments connect 4 centers in upside‐down U.
Reflection is nothing but producing mirror image of an object. Reflection can be done
just by rotating the object about given axis of reflection with an angle of 180 degrees.
Conclusion :
After successfully completing this assignment, student should be able to
generate Hilbert curve using concept of fractals.
Programming Laboratory
SE
Assignment No: - C1
Assignment C1 Revised On: 13/12/2018
TITLE To implement 3D transformations.
PROBLEM STATEMENT Write C++/Java program to draw 3-D cube and perform following
/DEFINITION transformations on it using OpenGL. A) Scaling b) Translation c)
Rotation about one axis.
To understand concept & features of OpenGL.
OBJECTIVE To understand the basic graphic functions in OpenGL
To understand & Implement 3D transformations using OpenGL
library functions.
Operating Systems
S/W PACKAGES AND 1. Open source Linux or its derivative
HARDWARE
APPARATUS USED 2. Open Source C++ Programming tool like G++/GCC
Aim
Use OpenGL graphics library functions to implement 3D transformations.
Prerequisites
Concept of 3D transformations and features of OpenGL library functions.
Learning Outcome
After successfully completing this assignment, you should be able to implement
different types of transformations & animations using OpenGL.
Related Mathematics
Let S be the system for drawing a bouncing ball animation, such that
S = {s, e, I, O, DD, NDD, Fme , Ffriend | ᶲ};
Where,
s is a start state of the class S.
x and y coordinates of vertices of edge are initialized to zero.
e is a end state of the class S.
DD = Deterministic data; here x interval dx, y interval dy along a line and slope of
given line.
NDD = Non deterministic data; here tendency of line increment in horizon might be
uncertain initially.
Input Analysis:-
I be the input to the system S. The system S takes x and y coordinates of vertices
V of polygon.
Ii = { f1, f2, …fn.| fi are the set of frames including bouncing ball animation.}
Functions:-
Ffriend is a friend class of class Fme having input parameter
Ffriend = { fi , a }
fi = set of frames including bouncing ball animation.
a = animation (fi); - function for animating a bouncing ball.
Output:-
2 . Rotation
3 . Scaling
4 . Reflection
OpenGL:-
(Open Graphics Library) is a specification defining a cross-language cross-platform
API for writing applications that produce 3D computer graphics (and 2D computer
graphics as well). The interface consists of over 250 different function calls which
can be used to draw complex three-dimensional scenes from simple primitives. It is
very popular in the video games industry where it competes with Direct3D on
Microsoft Windows platforms. OpenGL is widely used in CAD, virtual reality,
scientific visualization, information visualization, and video game development.
glClear( GL_COLOR_BUFFER_BIT );
We now set the modelview matrix, which controls the position of the camera relative to
the primitives we render. We move it backwards 3 units along the Z axis, which leaves it
pointing towards the origin:
The projection matrix governs the perspective effect applied to primitives, and is
controlled in a similar way to the modelview matrix:
glMatrixMode( GL_PROJECTION ); /* Subsequent matrix commands will
affect the projection matrix */
glLoadIdentity(); /* Initialise the projection matrix
to identity */
glFrustum( -1, 1, -1, 1, 1, 1000 ); /* Apply a perspective-projection
matrix */
Direct3D:-
Direct3D is part of Microsoft's DirectX application programming interface (API).
Direct3D is available for Microsoft Windows operating systems (Windows 95 and
above), and for other platforms through the open source software Wine. It is the base
for the graphics API on the Xbox and Xbox 360 console systems. Direct3D is used to
render three dimensional graphics in applications where performance is important,
such as games. Direct3D also allows applications to run fullscreen instead of
embedded in a window, though they can still run in a window if programmed for that
feature.
Direct3D uses hardware acceleration if it is available on the graphics card,
allowing for hardware acceleration of the entire 3D rendering pipeline or even only
partial acceleration. Direct3D exposes the advanced graphics capabilities of 3D
graphics hardware, including z-buffering, spatial anti-aliasing, alpha blending,
mipmapping, atmospheric effects, and perspective-correct texture mapping.
Integration with other DirectX technologies enables Direct3D to deliver such features
as video mapping, hardware 3D rendering in 2D overlay planes, and even sprites,
providing the use of 2D and 3D graphics in interactive media ties.
Direct3D is a 3D API. That is, it contains many commands for 3D rendering;
however, since version 8, Direct3D has superseded the old DirectDraw framework
and also taken responsibility for the rendering of 2D graphics.[1] Microsoft strives to
continually update Direct3D to support the latest technology available on 3D graphics
cards. Direct3D offers full vertex software emulation but no pixel software emulation
for features not available in hardware. For example, if software programmed using
Direct3D requires pixel shaders and the video card on the user's computer does not
support that feature, Direct3D will not emulate it, although it will compute and render
the polygons and textures of the 3D models, albeit at a usually degraded quality and
performance compared to the hardware equivalent.
Maya software:-
Maya animation software offers a comprehensive creative feature set for 3D
computer animation, modelling, simulation, rendering and compositing on a highly
extensible production platform. Maya now has next-generation display technology,
accelerated modelling workflows and new tools for handling complex data.
Autodesk Maya, commonly shortened to Maya, is 3D computer graphics software
that runs on Windows, Mac OS and Linux, originally developed by Alias Systems
Corporation (formerly Alias|Wavefront) and currently owned and developed by
Autodesk, Inc. It is used to create interactive 3D applications, including video
games, animated film, TV series, or visual effects.
Maya is an application used to generate 3D assets for use in film, television, game
development and architecture. The software was initially released for the IRIX
operating system. However, this support was discontinued in August 2006 after the
release of version 6.5. Maya was available in both "Complete" and "Unlimited"
editions until August 2008, when it was turned into a single suite. Users define a
virtual workspace (scene) to implement and edit media of a particular project. Scenes
can be saved in a variety of formats, the default being .mb (Maya Binary). Maya
exposes a node graph architecture. Scene elements are node-based, each node having
its own attributes and customization. As a result, the visual representation of a scene
is based entirely on a network of interconnecting nodes, depending on each other's
information. For the convenience of viewing these networks, there is a dependency
and a directed acyclic graph. Users who are students, teachers (or veterans or
unemployed in USA markets) can download a full educational version from the
Autodesk Education community. The versions available at the community are only
licensed for non commercial use (once activated with the product license) and some
products create watermarks on output renders.
Blender Software:-
Blender is a free and open-source 3D computer graphics software product used
for creating animated films, visual effects, art, 3D printed models, interactive 3D
applications and video games. Blender's features include 3D modeling, UV
unwrapping, texturing, rigging and skinning, fluid and smoke simulation, particle
simulation, soft body simulation, sculpting, animating, match moving, camera
tracking, rendering, video editing and compositing. It also features a built-in game
engine. This software contains features that are characteristic of high-end 3D
software. Among its capabilities are:
1. Support for a variety of geometric primitives, including polygon meshes, fast
subdivision surface modeling, Bezier curves, NURBS surfaces, metaballs, multi-
res digital sculpting (including dynamic topology, maps baking, remeshing,
resymetrize, decimation..), outline font, and a new n-gon modeling system called
B-mesh.
2. Internal render engine with scanline ray tracing, indirect lighting, and ambient
occlusion that can export in a wide variety of formats.
3. A pathtracer render engine called Cycles, which can take advantage of the GPU
for rendering. Cycles supports the Open Shading Language since blender 2.65.
4. Integration with a number of external render engines through plugins.
5. Keyframed animation tools including inverse kinematics, armature (skeletal),
hook, curve and lattice-based deformations, shape keys (morphing), non-linear
animation, constraints, and vertex weighting.
6. Simulation tools for Soft body dynamics including mesh collision detection,
LBM fluid dynamics, smoke simulation, Bullet rigid body dynamics, ocean
generator with waves.
7. A particle system that includes support for particle-based hair.
8. Modifiers to apply non-destructive effects.
9. Python scripting for tool creation and prototyping, game logic, importing and/or
exporting from other formats, task automation and custom tools.
10. A fully integrated node-based compositor within the rendering pipeline
accelerated with OpenCL.
Screenshots for adding a sphere to the frame:-
Review Questions
1. What is animation?
2. Explain different types of animation?
3. Explain importance and applications of animation?
Extra assignment list
Write a C/C++ program for car animation by using Direct3D/Maya
software/OpenGL?
Conclusion :
After successfully completing this assignment, student should be able to
understand and create animation by using OpenGL.