0% found this document useful (0 votes)
473 views57 pages

CG Lab Manual 2018-19-V1

This document provides an assignment to draw circles using the DDA and Bresenham circle drawing algorithms in C++. The objective is to understand object-oriented programming and circle drawing algorithms. Students are asked to write a C++ class that draws inscribed and circumscribed circles of a triangle by inheriting from a line class and using DDA for the inner circle and Bresenham's algorithm for the outer circle. The document outlines the problem, learning objectives, related concepts and mathematics, algorithm details, test cases, and conclusions.

Uploaded by

Harshada Koli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
473 views57 pages

CG Lab Manual 2018-19-V1

This document provides an assignment to draw circles using the DDA and Bresenham circle drawing algorithms in C++. The objective is to understand object-oriented programming and circle drawing algorithms. Students are asked to write a C++ class that draws inscribed and circumscribed circles of a triangle by inheriting from a line class and using DDA for the inner circle and Bresenham's algorithm for the outer circle. The document outlines the problem, learning objectives, related concepts and mathematics, algorithm details, test cases, and conclusions.

Uploaded by

Harshada Koli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 57

Computer Graphics

Laboratory
SE
Assignment No: - A1
Assignment No. 1 Revised On: 13/12/2018

TITLE Line drawing using DDA & Bresenham algorithm

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.

 To understand concept of DDA Algorithm.


OBJECTIVE  To understand concept of Bresenham’s Algorithm.
 To understand concept & features of object oriented
programming.
 To understand different manipulation facilities in QtCreator
using C++.

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

REFERENCES  J. Foley, V. Dam, S. Feiner, J. Hughes, “Computer Graphics


Principles and Practice”, 2nd Edition,Pearson Education, 2003, ISBN
81 – 7808 – 038 – 9.

 D. Hearn, M. Baker, “Computer Graphics – C Version”, 2nd Edition,


Pearson Education, 2002, ISBN,81 – 7808 – 794 – 4.

 D. Rogers, J. Adams, “Mathematical Elements for Computer


Graphics”, 2nd Edition, Tata McGraw-Hill Publicati00on, 2002,
ISBN 0 – 07 – 048677 – 8.
STEPS Refer to student activity flow chart

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.

 Concepts related Theory :-


I. DDA Algorithm:-
Digital Differential Analyzer (DDA) is used for linear interpolation of variables
over an interval between start and end point.
Digital differential analyzer(DDA)
Line Drawing 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

Select the largest of Δx or Δy as one raster unit.


Round the values rather than truncate.

X=x1+0.5
Y=y1+0.5

Begin main loop


i=1
while(i≤length)
setpixel(Integer(x),integer(y))
x=x+Δx
y=y+Δy
i=i + 1
endwhile
finish.

II. Bresenham’s Algorithm :-

Bresenham’s Algorithm:-
- Originally designed for digital plotters ,
Equally suited for use with CRT raster device

- Algorithm always increments by one unit in either


x or y depending on the slope of the line.

- The increment in other variable, either zero or


One is determined by examining the error term.

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

All variables are assumed integer.

// initialize variables//

X=x1
Y=y1
Δx=x2-x1
Δy=y2-y1

//Initilalize ē to compensate for a non zero intercept//

ē=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.

2. Enter a choice for drawing a Choice={DDA, Bresenham}


line using DDA and
Bresenham’s Algorithm.

3. Draw a line using DDA and O={Line}.


Bresenham’s Algorithm. If choice=”DDA”
then
Draw a line using DDA Algorithm
Else
Draw a line using Bresenham’s Algorithm
end

 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:

 Extra assignment list


o Write a program to draw house using DDA line Algorithm
o Write a program to draw different shapes like triangle, square, pentagon using
Bresenham’s line Algorithm
o Write a program to draw a Thick, Thin, Dotted lines using DDA line Algorithm?
o Write a program to draw a Thick, Thin, Dotted lines using Bresenham’s
Algorithm?

 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

TITLE Draw Circle using DDA & Bresenham algorithm

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

 To understand concept & features of object oriented


OBJECTIVE programming.
 To understand the concept of drawing circle using Bresenham’s
& DDA circle drawing algorithm.

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.

 D. Hearn, M. Baker, “Computer Graphics – C Version”, 2nd Edition,


Pearson Education, 2002, ISBN,81 – 7808 – 794 – 4.

 D. Rogers, J. Adams, “Mathematical Elements for Computer


Graphics”, 2nd Edition, Tata McGraw-Hill Publicati00on, 2002,
ISBN 0 – 07 – 048677 – 8.
STEPS Refer to student activity flow chart

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.

At x=0 and y=R for clockwise generation y is monotonically decreasing function of x.


At y=0, x=R for counterclockwise generation of the circle.
X is a monotonically decreasing function of y.

δ = | (xi + 1)2 + (yi)2 – R2 | - | (xi + 1)2 + (yi - 1)2 – R2 |


Difference between the squares of the distance from the actual circle to MH to MD.
δ ≤ o Choose MH at (xi + 1, yi )
δ ˃ o Choose MD at (xi + 1, yi - 1)
Case 1:-
(xi + 1)2 + (yi)2 – R2 ≥ 0
(xi + 1)2 + (yi - 1)2 – R2 ˂ 0
δ = (xi + 1)2 + (yi)2 – R2 + (xi + 1)2 + (yi - 1)2 – R2

Add and substitute -2yi +1

δ = 2 [(xi + 1)2 + (yi - 1)2 – R2 ] + 2yi -1


Use Δi difference

δ = 2(Δi + yi ) – 1.

Case 2:-

(xi + 1)2 + (yi)2 – R2 ˂ 0


(xi + 1)2 + (yi - 1)2 – R2 ˂ 0

Case 3:-
Consider MD and MV.

δ' = | (xi + 1)2 + (yi - 1)2 – R2 | - | (xi)2 + (yi - 1)2 – R2 |

δ’ ≤ o Choose MD at (xi + 1, yi -1 )
δ’ ˃ o Choose MV at (xi , yi - 1)

Conditions of General Bresenham’s Algorithm


Case 4:-

(xi + 1)2 + (yi - 1)2 – R2 ˃ 0


(xi)2 + (yi - 1)2 – R2 ˃ 0
δ’ ˃ o Correct Choice MV
Case 5:-

(xi + 1)2 + (yi - 1)2 – R2 ˃ 0


(xi)2 + (yi - 1)2 – R2 = 0
So δ ˃ o Choose (xi + 1, 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.

Min (MH , MD ,MV)

MH = |(xi + 1)2 + (yi)2 – R2 |


MD = |(xi + 1)2 + (yi - 1)2 – R2 |
MV = |(xi )2 + (yi - 1)2 – R2 |

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

Bresenham’s Incremental Circle Drawing Algorithm:-


For the first quadrant, all variables assumed as integer.
//initialize variables//
Xi =0
Yi = R
Δi = 2(1-R)
Limit = 0
While Yi ≥ limit
Call setpixel(Xi ,Yi)
Determine if case 1 or 2, 4, 5 or 3
If Δi ˂ 0 then
δ = 2 Δi + 2 Yi -1
Determine whether case 1 or 2
If δ ≤ 0 then
Call MH (xi , yi , Δi)
Else
Call MD (xi , yi , Δi)
End IF
ElseIf Δi ˃ 0 then
δ’ = 2 Δi - 2 Xi -1
Determine whether case 4 or 5
If δ’ ≤ 0 then
Call MD (xi , yi , Δi)
Else
Call MV (xi , yi , Δi)
End If
Else If Δi = 0 then
Call MD (xi , yi , Δi)
End IF
End While
FINISH
Move Horizontally
Subroutine MH (xi , yi , Δi)
xi = xi + 1
Δi = Δi +2 xi +1
End Sub
Subroutine MD (xi , yi , Δi)
xi = xi + 1
yi = yi - 1
Δi = Δi +2 xi - 2 yi + 2
End Sub

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.

 Extra assignment list


o Design clock?

 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.

 D. Hearn, M. Baker, “Computer Graphics – C Version”, 2nd Edition,


Pearson Education, 2002, ISBN,81 – 7808 – 794 – 4.

 D. Rogers, J. Adams, “Mathematical Elements for Computer


Graphics”, 2nd Edition, Tata McGraw-Hill Publicati00on, 2002,
ISBN 0 – 07 – 048677 – 8.

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.

 Concepts related Theory :-


 A scaling transformation:
A scaling transformation alters size of an object. In the scaling process, we either
compress or expand the dimension of the object.
Scaling operation can be achieved by multiplying each vertex coordinate (x, y) of the
polygon by scaling factor sx and sy to produce the transformed coordinates as (x’, y’).

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.

P=[X][Y] p' = [X′][Y′]T = [tx][ty]

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

TITLE To Draw polygons using mouse click event handling.

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

REFERENCES  J. Foley, V. Dam, S. Feiner, J. Hughes, “Computer Graphics


Principles and Practice”, 2nd Edition,Pearson Education, 2003, ISBN
81 – 7808 – 038 – 9.

 D. Hearn, M. Baker, “Computer Graphics – C Version”, 2nd Edition,


Pearson Education, 2002, ISBN,81 – 7808 – 794 – 4.

 D. Rogers, J. Adams, “Mathematical Elements for Computer


Graphics”, 2nd Edition, Tata McGraw-Hill Publicati00on, 2002,
ISBN 0 – 07 – 048677 – 8.

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.

Concave or non-convex polygons:-

A simple polygon that is not convex is called concave, non-convex or reentrant. A


concave polygon will always have an interior angle with a measure that is greater than
180 degrees. It is always possible to partition a concave polygon into a set of convex
polygons.
A concave polygon is defined as a polygon with one or more interior angles greater
than 180°. It looks sort of like a vertex has been 'pushed in' towards the inside of the
polygon. Note that a triangle (3-gon) can never be concave.

 Review Questions
 What is polygon?
 Explain convex and concave polygon?

 Extra assignment list


Write a C/C++ program to draw a house with polygon drawing function?

 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.

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.

 D. Hearn, M. Baker, “Computer Graphics – C Version”, 2nd Edition,


Pearson Education, 2002, ISBN,81 – 7808 – 794 – 4.

 D. Rogers, J. Adams, “Mathematical Elements for Computer


Graphics”, 2nd Edition, Tata McGraw-Hill Publicati00on, 2002,
ISBN 0 – 07 – 048677 – 8.

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:

Bresenham Line Algorithm:

Bresenham's line algorithm is an algorithm that determines the points of an n-


dimensional raster that should be selected in order to form a close approximation to a
straight line between two points. It is commonly used to draw line primitives in a bitmap
image (e.g. on a computer screen), as it uses only integer addition, subtraction and bit
shifting, all of which are very cheap operations in standard computer architectures. It is
an incremental error algorithm.
Illustration of the result of Bresenham's line algorithm. (0,0) is at the top left corner of the
grid, (1,1) is at the top left end of the line and (11, 5) is at the bottom right end of the line.

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

Seed fill Algorithm:


Flood fill, also called seed fill, is an algorithm that determines the area connected to a
given node in a multi-dimensional array. It is used in the "bucket" fill tool of paint
programs to fill connected.
The flood-fill algorithm takes three parameters: a start node, a target color, and a
replacement color. The algorithm looks for all nodes in the array that are connected to the
start node by a path of the target color and changes them to the replacement color. There
are many ways in which the flood-fill algorithm can be structured, but they all make use
of a queue or stack data structure, explicitly or implicitly.
Depending on whether we consider nodes touching at the corners connected or not, we
have two variations: eight-way and four-way respectively.

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.

Rotation 45˚ with the horizontal axis:


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’).
Note: Write rotation matrix
 Conclusion: After successfully completing this assignment, student should be able to
draw graphically chessboard rotated 45 degrees w.r.t. horizontal axis and fill it using
seed fill algorithm

Computer Graphics
Laboratory
SE
Assignment No: - B1
Assignment B1 Revised On: 13/12/2018

TITLE To draw line with different patterns.

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

REFERENCES  J. Foley, V. Dam, S. Feiner, J. Hughes, “Computer Graphics


Principles and Practice”, 2nd Edition,Pearson Education, 2003, ISBN
81 – 7808 – 038 – 9.

 D. Hearn, M. Baker, “Computer Graphics – C Version”, 2nd Edition,


Pearson Education, 2002, ISBN,81 – 7808 – 794 – 4.

 D. Rogers, J. Adams, “Mathematical Elements for Computer


Graphics”, 2nd Edition, Tata McGraw-Hill Publicati00on, 2002,
ISBN 0 – 07 – 048677 – 8.

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 }

 Concepts related Theory :-


Draws a dashed and dotted line using DDA Algorithm. Takes the line co-ordinates
from the user to plot the desired line. The program starts with one given end point and
then calculates each successive pixel that lies on the line using DDA Algorithm. To
make the line dashed and dotted,the program plots some pixels in order and then
skips some pixels to produce the dotted effect. Alternate pixels are plotted to produce
the dotted line effect. Applying these two simultaneously we the dashed-dotted line
effect.
 Review Questions
What is aliasing?
What is anti-aliasing?
Why aliasing occur in Raster scan display?

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

TITLE To Implement seed fill.

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

REFERENCES  J. Foley, V. Dam, S. Feiner, J. Hughes, “Computer Graphics


Principles and Practice”, 2nd Edition,Pearson Education, 2003, ISBN
81 – 7808 – 038 – 9.

 D. Hearn, M. Baker, “Computer Graphics – C Version”, 2nd Edition,


Pearson Education, 2002, ISBN,81 – 7808 – 794 – 4.

 D. Rogers, J. Adams, “Mathematical Elements for Computer


Graphics”, 2nd Edition, Tata McGraw-Hill Publicati00on, 2002,
ISBN 0 – 07 – 048677 – 8.

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:


• Polygon filling: process of coloring the area of a polygon
• Decide whether the point is inside or outside of the polygon.
• Inside  change to filled color
• Outside remain same as of background color
• Area/Region: collection of pixels

Seed fill algorithm:


• Boundary fill & flood fill algorithm together is called as seed-fill algorithm
• Principle: “start at a sample pixel called as a seed pixel from the area, fill the
color value & the boundary color value”.
• Areas can be defined at 2 levels
– 1. pixel level
– 2. geometric level
Simple seed fill algorithm using stack
• Push the seed pixel to stack.
• While stack is not empty
Pop a pixel from stack
Set pixel to req value
For each of 4-connected pixels adjacent to the current pixel
check if it is boundary pixel, or if it has already been set to the required value. In
either case, neglect it.
Otherwise, push it onto the stack.
Algorithm for 4- connected component
• Read SeedPixel(x,y), fill, boundary
• Pushpixel(x,y)
• While (stack<>empty)
• Poppixel(x,y)
• Setpixel(x,y,fill)
• If(getpixel(x+1,y))<>fill && getpixel(x+1,y)<>boundary
• Pushpixel(x+1,y)
• If(getpixel(x-1,y))<>fill && getpixel(x-1,y)<>boundary
• Pushpixel(x-1,y)
• If(getpixel(x,y+1))<>fill && getpixel(x,y+1)<>boundary
• Pushpixel(x,y+1)
• If(getpixel(x,y-1))<>fill && getpixel(x,y-1)<>boundary
• Pushpixel(x,y-1)
• End while

Output:
Computer Graphics
Laboratory
SE

Assignment No: - B3
Assignment B3 Revised On: 13/12/2018

TITLE To clip line using algorithm

PROBLEM STATEMENT Write C++/Java program to implement Cohen-Sutherland line


/DEFINITION clipping algorithm for given

window. Draw line using mouse interfacing to draw polygon


 To understand concept of different clipping algorithm
OBJECTIVE  To Implement Cohen-sutherland algorithm
 to draw lines by mouse interfacing
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

REFERENCES  J. Foley, V. Dam, S. Feiner, J. Hughes, “Computer Graphics


Principles and Practice”, 2nd Edition,Pearson Education, 2003, ISBN
81 – 7808 – 038 – 9.

 D. Hearn, M. Baker, “Computer Graphics – C Version”, 2nd Edition,


Pearson Education, 2002, ISBN,81 – 7808 – 794 – 4.

 D. Rogers, J. Adams, “Mathematical Elements for Computer


Graphics”, 2nd Edition, Tata McGraw-Hill Publicati00on, 2002,
ISBN 0 – 07 – 048677 – 8.

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

window. Draw line using mouse interfacing to draw polygon


Prerequisites:
Line Drawing Algorithm.
Mouse interfacing.
Clipping related algorithm
 Learning Objectives
To understand the concepts of mouse interfacing
To improve the coding skill of students
To learn the concept of Clipping
 Learning Outcome
After completion of this assignment student should able to clip line as per the
clipping window.
Related Mathematics:
Let S be the system for clipping line
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:-
mouse interfacing for input to the algorithm.
clipping function with respect to desire window.
Output:
Success: Successful clipping of line.
Failure: after clipping lines which are outside clipping boundary are also visible.
 Concepts related Theory :-
The algorithm includes, excludes or partially includes the line based on whether:
 Both endpoints are in the viewport region (bitwise OR of endpoints = 00): trivia
accept.
 Both endpoints share at least one non-visible region, which implies that the line
does not cross the visible region. (bitwise AND of endpoints ≠ 0): trivial reject.
 Both endpoints are in different regions: in case of this nontrivial situation the
algorithm finds one of the two points that is outside the viewport region (there
will be at least one point outside). The intersection of the outpoint and extended
viewport border is then calculated (i.e. with the parametric equation for the line),
and this new point replaces the outpoint. The algorithm repeats until a trivial
accept or reject occurs.
 Review Questions
What is clipping?
What are the different algorithm related to clipping?
Explain Cohen-Sutherland algorithm in detail?
Why bit code play important role in Cohen-Sutherland algorithm?

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.

PROBLEM STATEMENT Write C++/Java program to implement reflection of 2-D object


/DEFINITION about X axis, Y axis and about X=Y axis. Also rotate object about
arbitrary point given by user.
 To understand mathematical concepts behind implementation
OBJECTIVE of 2D transformations
 To Implement 2D reflection 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.

 D. Hearn, M. Baker, “Computer Graphics – C Version”, 2nd


Edition, Pearson Education, 2002, ISBN, 81 – 7808 – 794 – 4.

 D. Rogers, J. Adams, “Mathematical Elements for Computer


Graphics”, 2nd Edition, Tata McGraw-Hill Publication, 2002,
ISBN 0 – 07 – 048677 – 8.

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}

 Concepts related Theory :-

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.

 To understand mathematical concepts Hilbert curve using


OBJECTIVE concept of fractals.

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.

 D. Hearn, M. Baker, “Computer Graphics – C Version”, 2nd


Edition, Pearson Education, 2002, ISBN, 81 – 7808 – 794 – 4.

 D. Rogers, J. Adams, “Mathematical Elements for Computer


Graphics”, 2nd Edition, Tata McGraw-Hill Publication, 2002,
ISBN 0 – 07 – 048677 – 8.

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}

 Concepts related Theory :-

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.

Hilbert Curve: Iteration 1


Each of 4 squares divided into 4 more squares.
U shape shrunk to half its original size, copied into 4 sectors.
In top left, simply copied, top right: it's flipped vertically.
In the bottom left, rotated 90 degrees clockwise.
Bottom right, rotated 90 degrees counter‐clockwise.
4 pieces connected with 3 segments, each of which is same size as the shrunken pieces of
the U shape (in red).
Hilbert Curve: Iteration 2
Each of the 16 squares from iteration 1 divided into 4 squares.
Shape from iteration 1 shrunk and copied.
3 connecting segments (shown in red) are added to complete the curve.

 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

REFERENCES  J. Foley, V. Dam, S. Feiner, J. Hughes, “Computer Graphics


Principles and Practice”, 2nd Edition,Pearson Education, 2003, ISBN
81 – 7808 – 038 – 9.

 D. Hearn, M. Baker, “Computer Graphics – C Version”, 2nd Edition,


Pearson Education, 2002, ISBN,81 – 7808 – 794 – 4.

 D. Rogers, J. Adams, “Mathematical Elements for Computer


Graphics”, 2nd Edition, Tata McGraw-Hill Publication, 2002,
ISBN 0 – 07 – 048677 – 8.
 http://graphics.wikia.com/wiki/OpenGL
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 C1

 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:-

O= {3D object transformations on the screen.}

 Concepts related Theory :- 3D Transformations


1 . Translation

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.

In order to start with a blank canvas:

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:

glMatrixMode( GL_MODELVIEW ); /* Subsequent matrix commands will


affect the modelview matrix */
glLoadIdentity(); /* Initialise the modelview to
identity */
glTranslatef( 0, 0, -3 ); /* Translate the modelview 3 units
along the Z axis */

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 */

Finally, we issue a polygon - a green square oriented in the XY plane:

glBegin( GL_POLYGON ); /* Begin issuing a polygon */


glColor3f( 0, 1, 0 ); /* Set the current color to green */
glVertex3f( -1, -1, 0 ); /* Issue a vertex */
glVertex3f( -1, 1, 0 ); /* Issue a vertex */
glVertex3f( 1, 1, 0 ); /* Issue a vertex */
glVertex3f( 1, -1, 0 ); /* Issue a vertex */
glEnd(); /* Finish issuing the polygon */

 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.

You might also like