0% found this document useful (0 votes)
26 views20 pages

Topic 3 - Basic Concepts of Graphics Programming

This document discusses basic concepts of graphics programming. It describes graphics libraries, which contain functions for rendering shapes and applying transformations. Popular graphics libraries include OpenGL, Direct3D, Vulkan, and Metal. OpenGL is widely used due to being open-source. The document also outlines different coordinate systems used in graphics, including Cartesian, polar, and spherical coordinates. Programmers must understand these concepts and coordinate systems to effectively program computer graphics.

Uploaded by

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

Topic 3 - Basic Concepts of Graphics Programming

This document discusses basic concepts of graphics programming. It describes graphics libraries, which contain functions for rendering shapes and applying transformations. Popular graphics libraries include OpenGL, Direct3D, Vulkan, and Metal. OpenGL is widely used due to being open-source. The document also outlines different coordinate systems used in graphics, including Cartesian, polar, and spherical coordinates. Programmers must understand these concepts and coordinate systems to effectively program computer graphics.

Uploaded by

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

Topic # 3 Basic concepts of graphics programming

IM-212 Computer-aided Engineering Design


Topic # 3
Basic concepts of graphics programming

Resource Persons
DEPARTMENT OF INDUSTRIAL AND MANUFACTURING ENGINEERING,
NED UNIVERSITY OF ENGINEERING AND TECHNOLOGY, KARACHI. Dr. Muhammad Wasif
Assistant Professor

OBJECTIVES
Following are the objectives of this topic;

 To aware about the fundamental graphics programming


 To disseminate the knowledge of graphics libraries available
 To enable participants to distinguish among the different coordinate
systems exist in CAD Systems

© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET) 2

© Dr. Muhammad Wasif (Assistant Professor - IMD, NED UET)


1
Topic # 3 Basic concepts of graphics programming

EXPECTATIONS
Following are the expectations from participants

 To view the complete presentation/video


 To replicate the Solidworks/CATIA demonstration shown in the lecture
 To read Chapter 2 of Books 1, Chapter 3 of Books 2 and Chapter 2 of
Book 3 (see Course profile for detail)
 To write down the extracts and notes
 To explore the extended knowledge of the topic from prescribed
chapter of the book and internet resources
© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET) 3

WHAT IS GRAPHICS LIBRARY?


 It is a library containing module and sub-routines to generate graphics on
a VDU.
 It contains functions to render different shapes, apply algorithm and
transformations.
 It is executed on CPU or GPU, commonly embedded in operating system.
 Executing these functions assemble an image to be output to a monitor or
VDU, such as a game view containing, sky, shadow, trees, water, boxes etc.
 This relieves the programmer of the task of creating and optimizing these
functions, and allows them to focus on building the graphics program.

© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET) 4

© Dr. Muhammad Wasif (Assistant Professor - IMD, NED UET)


2
Topic # 3 Basic concepts of graphics programming

© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET) 5

WHAT IS GRAPHICS LIBRARY?


 Buildings and constructions are made of basic elements, such as
blocks, spheres, pyramids etc?
 When sunlight falls on a building, how shadows are rendered?
 How waves of the seas are moving towards the shore?
 When light falls, how the surface shines?
 How skies are formatted?
 Common elements are defined in Graphics Libraries, programmer call
them and provide proper parameter values to it.
 Either it is intensity of light, size of block, shadow length etc.
© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET) 6

© Dr. Muhammad Wasif (Assistant Professor - IMD, NED UET)


3
Topic # 3 Basic concepts of graphics programming

HISTORY OF GRAPHICS LIBRARY


 CORE of ACM (Association for Computing
Machinery) and GKS (Graphic kernel system) of ISO
were written for 2D graphics in 1977. (Had
deficiencies)
 ISO invented Programmer's Hierarchical Interactive
Graphics System (PHIGS).
 Extended version of PHIGS for windows based OS is
called PEX.
© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET) 7

NAME OF FAMOUS GRAPHICS LIBRARIES


While programming programmer must use one the following libraries;
Open GL Direct 3D Vulkan Metal

Require low Require low


Open Graphics Default MS-
resource, parallel resource, C++
Library Windows Library
processing based
Widely used due to Used in Windows Used in Android, Used in Apple
freeware based software Windows based systems

VR systems, Game Xbox One Nintendo PS-4, IOS

© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET) 8

© Dr. Muhammad Wasif (Assistant Professor - IMD, NED UET)


4
Topic # 3 Basic concepts of graphics programming

HOW OPENGL WORKS?

© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET) 9

© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET) 10

10

© Dr. Muhammad Wasif (Assistant Professor - IMD, NED UET)


5
Topic # 3 Basic concepts of graphics programming

z
P
TYPE OF COORDINATE SYSTEM Z

It is a reference system to determine location of a point x Y X y


with respect to it. We can use either; Cartesian Coordinate System

z
 Cartesian Coordinates: based on distances along the R P
three dimensions) - P(x, 𝑦, 𝑧) or θ Z
 Polar Coordinates: based on radial distance, angle on R
a plan and distance along z – P(R, 𝜃, 𝑧) or Polar Coordinate System

 Spherical Coordinates: based on radial distance and


two angles on planes - P(R, 𝜃, 𝜑) R P
φ
 Small letter ‘x’ represents axis, capital letter ‘X’ θ
represents distance. R
Spherical Coordinate System

© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET) 11

11

CARTESIAN COORDINATES
z

x y

© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET) 12

12

© Dr. Muhammad Wasif (Assistant Professor - IMD, NED UET)


6
Topic # 3 Basic concepts of graphics programming

POLAR COORDINATES
z

© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET) 13

13

POLAR COORDINATES

© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET) 14

14

© Dr. Muhammad Wasif (Assistant Professor - IMD, NED UET)


7
Topic # 3 Basic concepts of graphics programming

z
P
TYPE OF COORDINATE SYSTEM Z

It is a reference system to determine location of a point x Y X y


with respect to it. We can use either; Cartesian Coordinate System

z
 Cartesian Coordinates: based on distances along the R P
three dimensions) - P(x, 𝑦, 𝑧) or θ Z
 Polar Coordinates: based on radial distance, angle on R
a plan and distance along z – P(R, 𝜃, 𝑧) or Polar Coordinate System

 Spherical Coordinates: based on radial distance and


two angles on planes - P(R, 𝜃, 𝜑) R P
φ
 Small letter ‘x’ represents axis, capital letter ‘X’ θ
represents distance. R
Spherical Coordinate System

© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET) 15

15

z
P
TYPE OF COORDINATE SYSTEM Z

It is a reference system to determine location of a point x Y X y


with respect to it. We can use either; Cartesian Coordinate System

z
 Cartesian Coordinates: based on distances along the R P
three dimensions) - P(x, 𝑦, 𝑧) or θ Z
 Polar Coordinates: based on radial distance, angle on R
a plan and distance along z – P(R, 𝜃, 𝑧) or Polar Coordinate System

 Spherical Coordinates: based on radial distance and


two angles on planes - P(R, 𝜃, 𝜑) R P
φ
 Small letter ‘x’ represents axis, capital letter ‘X’ θ
represents distance. R
Spherical Coordinate System

© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET) 16

16

© Dr. Muhammad Wasif (Assistant Professor - IMD, NED UET)


8
Topic # 3 Basic concepts of graphics programming

IN-CLASS ACTIVITY-3.1
A point in space is represented by P(6,4,11) in millimeters. z
Determine the equivalent point in Polar and Spherical P
Coordinate Systems. 11
Important Note: Perform it on a separate paper and keep
in notes, this activity will be submitted in assignment file at x 4 6 y
the end of semester. Keep your copy for your record and Cartesian Coordinate System
examination preparation.
Polar Coordinate P(R, 𝜃, 𝑧) = P(7.211mm,33.7°,11mm)
Spherical Coordinate P(R, 𝜃, 𝜑) = P(7.211mm,33.7°,55.75°)

© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET) 17

17

IN-CLASS ACTIVITY-3.2
A point in space is represented by P(12mm,60°,30°).
Determine the equivalent point in Cartesian and Polar
R P
Coordinate Systems.
φ
Important Note: Perform it on a separate paper and keep θ
in notes, this activity will be submitted in assignment file at R
the end of semester. Keep your copy for your record and Spherical Coordinate System
examination preparation.
Cartesian Coordinate P(x, 𝑦, 𝑧) = P(5.192mm, 9, 6mm)
Polar Coordinate P(R, 𝜃, 𝑧) = P(12mm,60°,6mm)

© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET) 18

18

© Dr. Muhammad Wasif (Assistant Professor - IMD, NED UET)


9
Topic # 3 Basic concepts of graphics programming

MATLAB FUNCTION
function y1=trancs(n,x)
% Enter n=1 if input is in Carterian coordinte r=sqrt(y1(1)^2+y1(2)^2+x(3)^2);
% Enter n=2 if input is in Polar coordinte si=acosd(x(1)/r);
% Enter n=3 if input is in Spehrical coordinte fprintf('Polar in Carterian coorinate is :
% Use function cc=trancs(1,[2 3 4]) (%f,%f,%f)',y1(1),y1(2),x(3));
% where [2 3 4] represents coordinate, output is in same format fprintf('\nPolar in Spherical coorinate is:
if n==1 (%f,%f,%f)\n',x(1),x(2),si);
R=sqrt(x(1)^2+x(2)^2); elseif n==3
theta=asind(x(2)/R); y1(3)=x(1).*sind(x(3));
si=atand(x(3)/R); r=x(1).*cosd(x(3));
fprintf('Cartesian in Polar coorinate is : y1(1)=r.*cosd(x(2));
(%f,%f,%f)',R,theta,x(3)); y1(2)=r.*sind(x(2));
fprintf('\nCartesian in Spherical coorinate is: fprintf('Spherical in Carterian coorinate is :
(%f,%f,%f)\n',R,theta,si); (%f,%f,%f)',y1(1),y1(2),y1(3));
elseif n==2 fprintf('\nSpherical in Polar coorinate is :
y1(1)=x(1).*cosd(x(2)); (%f,%f,%f)\n',x(1),x(2),y1(3));
y1(2)=x(1).*sind(x(2)); end

© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET) 19

19

COORDINATE SYSTEMS IN CAD


Purpose of coordinate system is
 to define the location of the points of an object in space and
 to define the location of those points on screen.
There are five types of coordinate systems are used to display the image of a CAD object
on the graphics display, these are;
1. Device coordinate system
2. Virtual coordinate system
3. World coordinate system
4. Model coordinate system
5. Viewing coordinate system
All coordinate system are related to each other in graphics programming to view the object
on display unit.

© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET) 20

20

© Dr. Muhammad Wasif (Assistant Professor - IMD, NED UET)


10
Topic # 3 Basic concepts of graphics programming

DEVICE COORDINATE SYSTEM (DCS)


 It is a 2D coordinate system and located on an arbitrary position in VDU.
 (u,v) coordinate completely specify the location of a point.
 No need to specify perpendicular direction on u,v, since display
unit is a 2D display system.
 Different devices has different locations, directions u
and ranges of “u” and “v” depending on the v
v
number of pixel on each display.
v u
 In graphics programming, DCS has to be changed,
to show the same image on different display units. u

© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET) 21

21

VIRTUAL COORDINATE SYSTEM (VCS)


 VCS is a virtually set by the programmer on the lower left corner in VDU,
directing “u” towards horizontal and “v” toward vertical directions.
 Graphics program evaluate the location of DCS, and range of display
unit and transforms the DCS to the VCS location.
 The unit vector along the “u” and “v” directions of v
the DCS and VCS and used to transform, by DCS
knowing the orientation and location of the DCS. u
v
 Therefore, a point specified w.r.t. to the VCS will
VCS u
remain on same position for all display devices.

© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET) 22

22

© Dr. Muhammad Wasif (Assistant Professor - IMD, NED UET)


11
Topic # 3 Basic concepts of graphics programming

RELATION BETWEEN DCS AND VCS


 Programme calls the location of DCS and v
P(u,v)
resolution, e.g. DCS 1
u
 For DCS 1 v
Resolution = 800x600, DCS@ center VCS 1
u
DCS=(400,300). P(x,y) in VCS 1 = (400+u, 300+v) v
DCS 2
 For DCS 2 P(u,v) u
Resolution = 1200x800, DCS@left up 90oCW
DCS=(1200,800). P(x,y) in VCS 1 = (1200-v, 800-u) v
VCS 2
u

© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET) 23

23

MODEL COORDINATE SYSTEM (MCS)


 Since it specify the location of a point of a CAD model in space.
Therefore, it is a 3D coordinate system. z
z
 The shape of an object is defined by the MCS
coordinates of all the points or some characteristic x y
x MCS
points on the object with respect to a coordinate z y z
system attached to the object. z
WC MCS
 This coordinate system is called the model xS y x
y
coordinate system. x MCS y

 MCS is rigidly attached with the CAD model.

© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET) 24

24

© Dr. Muhammad Wasif (Assistant Professor - IMD, NED UET)


12
Topic # 3 Basic concepts of graphics programming

WORLD COORDINATE SYSTEM (WCS)


 Since it specify the location of a point of a CAD model in space.
Therefore, it is a 3D coordinate system. z
z
 WCS is the reference system in which location MCS
and orientation of different components of a x y
x MCS
CAD object are related and stored with respect z y z
to each other. I.e. it defined the world of z
MCS
reference. WC
xS y x
y
 In an assembly, different parts are constraint x MCS y
w.r.t the assembly coordinate system, which is
the WCS for all parts.

© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET) 25

25

PERSPECTIVE AND PARALLEL PROJECTION


 3D entities are needed to be projected on the 2D display unit (retina of
eye or display screen).
 Two types of projections are used; perspective projection (realistic) and
parallel projection.

Perspective Projection Parallel Projection

© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET) 26

26

© Dr. Muhammad Wasif (Assistant Professor - IMD, NED UET)


13
Topic # 3 Basic concepts of graphics programming

PERSPECTIVE AND PARALLEL PROJECTION


 Viewpoint is the viewer’s eye, whereas, viewsite is the point of interest
on the viewing object. Vector emerging from viewpoint to viewsite
defines the viewing direction.

Perspective Projection Parallel Projection


Projected image is formed by the Projected image is formed by the
intersection b/w the screen and the lines intersection b/w the screen and the lines
from object points to the center of from object points parallel to the viewing
projection. direction.

© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET) 27

27

PERSPECTIVE AND PARALLEL PROJECTION

© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET) 28

28

© Dr. Muhammad Wasif (Assistant Professor - IMD, NED UET)


14
Topic # 3 Basic concepts of graphics programming

PROJECTIONS IN DESIGN
PROJECTIONS

PARALLEL
PERSPECTIVE
(parallel projectors)
(converging projectors)

One point
Orthographic Oblique
(projectors not perpendicular to (one principal
(projectors perpendicular vanishing point)
to view plane) view plane)

Two point
Axonometric General (Two principal
Multiview vanishing point)
(view plane (view plane not parallel
parallel to principal to principal planes) Cavalier
planes) Three point
(Three principal
Cabinet vanishing point)

Isometric Dimetric Trimetric Ref : Lecture notes of Sanu Philip


© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET) 29

29

ASSIGNMENT - 1

Assignment - 1

© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET) 30

30

© Dr. Muhammad Wasif (Assistant Professor - IMD, NED UET)


15
Topic # 3 Basic concepts of graphics programming

VIEWING COORDINATE SYSTEM (VCS)


 It facilitates the viewing projection.
 vCS is located at the viewsite, such that z-axis directs towards the view
point and y-axis is parallel to the vertical direction to the scree.
 The vertical direction is to be provided by the CAD user, called the up
direction.

© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET) 31

31

PROJECTION POINTS (PERSPECTIVE) yv

xv
screen Ov

zv
From similar triangle
S
Xs   Xv
• Distances Xs and Ys are along the horizontal and vertical directions along the screen. L  Zv
• Equations states that the larger the value of Zv, will increase the size of image i.e. the S
lengths Xs and Ys. Ys   Yv
• Therefore the nearer object looks larger as compared to the same distant object. L  Zv

© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET)


32

32

© Dr. Muhammad Wasif (Assistant Professor - IMD, NED UET)


16
Topic # 3 Basic concepts of graphics programming

PROJECTION POINTS (PARALLEL) yv

xv
screen Ov

zv

Xs  Xv
Ys  Yv
• No effect on size of distant or nearer objects.
• When the viewing plane is perpendicular to the viewing direction, it is called orthographic view.
• When the viewing plane is not perpendicular to the viewing direction, it is called oblique view.

© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET)


33

33

HOMOGENOUS COORDINATES
 A 3D coordinate “P” can be represented by P(x,y,z) in a
3D 3 space.
 It can also be represented by P(wx,wy,wz,w), where
w≠0, in 4 space, specifying a finite space, this
representation is called homogenous coordinate of a
point.
 Diving all coordinates by “w”, point P(wx,wy,wz,w) can
also be specified as P(x,y,z,1).
© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET) 34

34

© Dr. Muhammad Wasif (Assistant Professor - IMD, NED UET)


17
Topic # 3 Basic concepts of graphics programming

PROJECTION CALCULATIONS z

Coordinate y
value in MCS World Viewing
y Model
Model Coordinate Coordinate
Coordinate
Transformation System System
System x
Coordinate OM
value in WCS
Viewing Ov Viewsite x
Transformation
Coordinate z y
value in vCS
v Device
Projection v OW x Coordinate
Transformation
Projection in Virtual System
Image
VCS Coordinate
OD u
Viewing System
Projection in z
DCS OV u Screen

Viewpoint
© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET) 35

35

PROJECTION CALCULATIONS
 The procedure of calculating projections points;
 The coordinate of points in MCS are transformed to WCS
using the model transformation.
 The coordinate of the points in WCS are transformed to
vCS using the viewing transformation.
 The coordinate of the points in vCS are transformed to VCS
using the viewing transformation (Xs and Ys).
 Finally, the point in VCS are transformed to the DCS using
the device driver routine.
© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET) 36

36

© Dr. Muhammad Wasif (Assistant Professor - IMD, NED UET)


18
Topic # 3 Basic concepts of graphics programming

WINDOW
 It defines the region in space that will be projected onto the display
monitor.
 The visible region, called viewing volume.
 To simplify the viewing volume, it is cut by near and far planes.

© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET) 37

37

VIEWPORTS
 It is an area to which the viewing volume
defined by the window is mapped.
 Mapping will involve a translation and a scaling
to take into account the deviation of the
viewport center from the center of the display
monitor and the size difference between the
window and the viewport.
 The Xs and Ys are to scaled to the projection in
the viewport.

© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET) 38

38

© Dr. Muhammad Wasif (Assistant Professor - IMD, NED UET)


19
Topic # 3 Basic concepts of graphics programming

REFERENCES
1. e-Design Computer-Aided Engineering Design by Kuang-Hua Chang,
Elsevier, 2015
2. Principals of CAD/CAM/CAE by Kunwoo Lee, Wesley Longman, Inc.
3. Mastering CAD/CAM by Ibrahim Zeid, McGraw-Hill
Science/Engineering/Math, 2008.

© DR. MUHAMMAD WASIF (ASSISTANT PROFESSOR - IMD, NED UET) 39

39

© Dr. Muhammad Wasif (Assistant Professor - IMD, NED UET)


20

You might also like