Sie sind auf Seite 1von 8

Name:- Mandar M.

Mayekar Roll no:-31

Aim:- To study co ordinate sys and various functions of graphics.h library of c++

Description:-
A coordinate system is a way of assigning numbers to points. In two dimensions, you need a pair of
numbers to specify a point. The coordinates are often referred to as x and y, although of course, the
names are arbitrary. More than that, the assignment of pairs of numbers to points is itself arbitrary to a
large extent. Points and objects are real things, but coordinates are just numbers that we assign to them
so that we can refer to them easily and work with them mathematically. We have seen the power of this
when we discussed transforms, which are defined mathematically in terms of coordinates but which
have real, useful physical meanings.

In three dimensions, you need three numbers to specify a point. (That's essentially what it means to be
three dimensional.) The third coordinate is often called z. The z-axis is perpendicular to both the x-axis
and the y-axis.

This conventional arrangement of the axes produces a right-handed coordinate system. This means that
if you point the thumb of your right hand in the direction of the positive z-axis, then when you curl the
fingers of that hand, they will curl in the direction from the positive x-axis towards the positive y-axis. If
you are looking at the tip of your thumb, the curl will be in the counterclockwise direction. Another way
to think about it is that if you curl the figures of your right hand from the positive x to the positive y-axis,
then your thumb will point in the direction of the positive z-axis. The default OpenGL coordinate system
(which, again, is hardly ever used) is a left-handed system. You should spend some time trying to
visualize right- and left-handed coordinates systems.

This conventional arrangement of the axes produces a right-handed coordinate system. This means that
if you point the thumb of your right hand in the direction of the positive z-axis, then when you curl the
fingers of that hand, they will curl in the direction from the positive x-axis towards the positive y-axis. If
you are looking at the tip of your thumb, the curl will be in the counterclockwise direction. Another way
to think about it is that if you curl the figures of your right hand from the positive x to the positive y-axis,
then your thumb will point in the direction of the positive z-axis. The default OpenGL coordinate system
(which, again, is hardly ever used) is a left-handed system. You should spend some time trying to
visualize right- and left-handed coordinates systems.

All of that describes the natural coordinate system from the viewer's point of view, the so-called "eye"
or "viewing" coordinate system. However, these eye coordinates are not necessarily the natural
coordinates on the world. The coordinate system on the world—the coordinate system in which the
scene is assembled—is referred to as world coordinates. Multiple Coordinate Systems in a Graphics
Program

In a typical graphics program, we may need to deal with a number of different coordinate systems, and
a good part of the work ( and the cause of many headaches ) is the conversion of coordinates from one
system to another.

Page | 1
Name:- Mandar M. Mayekar Roll no:-31

Multiple Coordinate Systems in a Graphics Program:-

We'll learn about the conversion process a little later, but in the meantime, here is a list of some of the
coordinate systems you may encounter:

World Coordinate System - Also known as the "universe" or sometimes "model" coordinate system.
This is the base reference system for the overall model, ( generally in 3D ), to which all other model
coordinates relate.

Object Coordinate System - When each object is created in a modelling program, the modeller must
pick some point to be the origin of that particular object, and the orientation of the object to a set of
model axes. For example when modelling a desk, the modeller might choose a point in the center of the
desk top for the origin, or the point in the center of the desk at floor level, or the bottom of one of the
legs of the desk. When this object is moved to a point in the world coordinate system, it is really the
origin of the object ( in object coordinate system ) that is moved to the new world coordinates, and all
other points in the model are moved by an equal amount. Note that while the origin of the object model
is usually somewhere on the model itself, it does not have to be. For example, the origin of a doughnut
or a tire might be in the vacant space in the middle.

Hierarchical Coordinate Systems - Sometimes objects in a scene are arranged in a hierarchy, so that the
"position" of one object in the hierarchy is relative to its parent in the hierarchy scheme, rather than to
the world coordinate system. For example, a hand may be positioned relative to an arm, and the arm
relative to the torso. When the arm moves, the hand moves with it, and when the torso moves, all three
objects move together.

Viewpoint Coordinate System - Also known as the "camera" coordinate system. This coordinate system
is based upon the viewpoint of the observer, and changes as they change their view. Moving an object
"forward" in this coordinate system moves it along the direction that the viewer happens to be looking
at the time.

Model Window Coordinate System - Not to be confused with desktop windowing systems ( MS
Windows or X Windows ), this coordinate system refers to the subset of the overall model world that is
to be displayed on the screen. Depending on the viewing parameters selected, the model window may
be rectalinear or a distorted viewing frustrum of some kind.

Screen Coordinate System - This 2D coordinate system refers to the physical coordinates of the pixels
on the computer screen, based on current screen resolution. ( E.g. 1024x768 )

Viewport Coordinate System - This coordinate system refers to a subset of the screen space where the
model window is to be displayed. Typically the viewport will occupy the entire screen window, or even
the entire screen, but it is also possible to set up multiple smaller viewports within a single screen
window.

Page | 2
Name:- Mandar M. Mayekar Roll no:-31

Various functions of graphics.h library:-


1)void initGraphics();
void initGraphics(int width, int height);
Creates the graphics window on the screen. The first form creates a window with a default size of
500x300; the second allows the client to specify the size of the window. The call to initGraphics must
precede any console output or calls to other functions in this interface.
Usage:-
initGraphics();
initGraphics(width, height);

2)void drawArc(GRectangle bounds, double start, double sweep);


void drawArc(double x, double y, double width, double height,double start, double sweep);

Draws an elliptical arc inscribed in a rectangle. The parameters x, y, width, and height (or, equivalently,
the GRectangle bounds) specify the coordinates and dimensions of the bounding rectangle.
The start parameter indicates the angle at which the arc begins and is measured in degrees
counterclockwise from the +x axis. Thus, a start angle of 0 indicates an arc that begins along the line
running eastward from the center, a start angle of 135 begins along the line running northwest, and
a start angle of -90 begins along the line running south. The sweep parameter indicates the extent of
the arc and is also measured in degrees counterclockwise. A sweep angle of 90 defines a quarter circle
extending counterclockwise from the start angle, and a sweep angle of -180 defines a semicircle
extending clockwise.
Usage:-
drawArc(bounds, start, sweep);
drawArc(x, y, width, height, start, sweep);

3)void fillArc(GRectangle bounds, double start, double sweep);


void fillArc(double x, double y, double width, double height,double start, double sweep);

Fills a wedge-shaped area of an elliptical arc. The parameters are interpreted in the same way as those
for drawArc.
Usage:-
fillArc(bounds, start, sweep);
fillArc(x, y, width, height, start, sweep);

4)void drawImage(string filename, GPoint pt);


void drawImage(string filename, double x, double y);
void drawImage(string filename, GRectangle bounds);
void drawImage(string filename, double x, double y,double width, double height);

Draws the image from the specified file with its upper left corner at the specified point. The forms of the
call that include the bounds scale the image so that it fits inside the specified rectangle.
Usage:-
drawImage(filename, pt);
drawImage(filename, x, y);
drawImage(filename, bounds);
drawImage(filename, x, y, width, height);

Page | 3
Name:- Mandar M. Mayekar Roll no:-31

5)GRectangle getImageBounds(string filename);

Returns the bounds of the image contained in the specified file. Only the width and height components
of the rectangle are of interest; the x and y components are always 0.
Usage:-
GRectangle bounds = getImageBounds(filename);

6)void drawLine(GPoint p0, GPoint p1);


void drawLine(double x0, double y0, double x1, double y1);

Draws a line connecting the specified points.


Usage:-
drawLine(p0, p1);
drawLine(x0, y0, x1, y1);

7)GPoint drawPolarLine(GPoint p0, double r, double theta);


GPoint drawPolarLine(double x0, double y0, double r, double theta);

Draws a line of length r in the direction theta from the initial point. The angle theta is measured in
degrees counterclockwise from the +x axis. The function returns the end point of the line.
Usage:-
GPoint p1 = drawPolarLine(p0, r, theta);
GPoint p1 = drawPolarLine(x0, y0, r, theta);

8)void drawOval(GRectangle bounds);


void drawOval(double x, double y, double width, double height);

Draws the frame of a oval with the specified bounds.


Usage:-
drawOval(bounds);
drawOval(x, y, width, height);

9)void fillOval(GRectangle bounds);


void fillOval(double x, double y, double width, double height);

Fills the frame of a oval with the specified bounds.


Usage:-
fillOval(bounds);
fillOval(x, y, width, height);

10)void drawRect(GRectangle bounds);


void drawRect(double x, double y, double width, double height);

Draws the frame of a rectangle with the specified bounds.


Usage:-
drawRect(bounds);
drawRect(x, y, width, height);

Page | 4
Name:- Mandar M. Mayekar Roll no:-31

11)void fillRect(GRectangle bounds);


void fillRect(double x, double y, double width, double height);

Fills the frame of a rectangle with the specified bounds.


Usage:-
fillRect(bounds);
fillRect(x, y, width, height);

12)void drawPolygon(Vector<GPoint> polygon);


void drawPolygon(Vector<GPoint> polygon, GPoint pt);
void drawPolygon(Vector<GPoint> polygon, double x, double y);

Draws the outline of the specified polygon. The optional pt or x and y parameters shift the origin of the
polygon to the specified point.
Usage:-
drawPolygon(polygon);
drawPolygon(polygon, pt);
drawPolygon(polygon, x, y);

13)void fillPolygon(Vector<GPoint> polygon);


void fillPolygon(Vector<GPoint> polygon, GPoint pt);
void fillPolygon(Vector<GPoint> polygon, double x, double y);

Fills the frame of the specified polygon. The optional pt or x and y parameters shift the origin of the
polygon to the specified point.
Usage:-
fillPolygon(polygon);
fillPolygon(polygon, pt);
fillPolygon(polygon, x, y);

14)void drawString(string str, GPoint pt);


void drawString(string str, double x, double y);

Draws the string str so that its baseline origin appears at the specified point. The text appears in the
current font and color.
Usage:-
drawString(str, pt);
drawString(str, x, y);

15)double getStringWidth(string str);

Returns the width of the string str when displayed in the current font.
Usage:-
double width = getStringWidth(str);

Page | 5
Name:- Mandar M. Mayekar Roll no:-31

16)void setFont(string font);

Sets a new font. The font parameter is a string in the form family-style-size. In this string, family is the
name of the font family; style is either missing (indicating a plain font) or one of the strings Bold, Italic,
or BoldItalic; and size is an integer indicating the point size. If any of these components is specified as an
asterisk, the existing value is retained. The font parameter can also be a sequence of such specifications
separated by semicolons, in which the first available font on the system is used.
Usage:-
setFont(font);

17)string getFont();

Returns the current font.


Usage:-
string font = getFont();

18)void setColor(string color);

Sets the color used for drawing. The color parameter is usually one of the predefined color names from
Java: BLACK, BLUE, CYAN, DARK_GRAY, GRAY, GREEN, LIGHT_GRAY, MAGENTA, ORANGE, PINK,RED, W
HITE, or YELLOW.

The case of the individual letters in the color name is ignored, as are spaces and underscores, so that the
Java color DARK_GRAY could be written as "Dark Gray".

The color can also be specified as a string in the form "#rrggbb" where rr, gg, and bb are pairs of
hexadecimal digits indicating the red, green, and blue components of the color.

Usage:-
setColor(color);

19)string getColor();

Returns the current color as a string in the form "#rrggbb". In this string, the values rr, gg, and bb are
two-digit hexadecimal values representing the red, green, and blue components of the color,
respectively.
Usage:-
string color = getColor();

20)void saveGraphicsState();

Saves the state of the graphics context. This function is used in conjunction
with restoreGraphicsState() to avoid changing the state set up by the client.
Usage:-
saveGraphicsState();

Page | 6
Name:- Mandar M. Mayekar Roll no:-31

21)void restoreGraphicsState();

Restores the graphics state from the most recent call to saveGraphicsState().
Usage:-
restoreGraphicsState();

22)double getWindowWidth();

Returns the width of the graphics window in pixels.


Usage:-
double width = getWindowWidth();

23)double getWindowHeight();

Returns the height of the graphics window in pixels.


Usage:-
double height = getWindowHeight();

24)void repaint();

Issues a request to update the graphics window. This function is called automatically when the program
pauses, waits for an event, waits for user input on the console, or terminates. As a result, most clients
will never need to call repaint explicitly.
Usage:-
repaint();

25)void pause(double milliseconds);

Pauses for the indicated number of milliseconds. This function is useful for animation where the motion
would otherwise be too fast.
Usage:-
pause(milliseconds);

26)void waitForClick();

Waits for a mouse click to occur anywhere in the window.


Usage:-
waitForClick();

27)void setWindowTitle(string title);

Sets the title of the primary graphics window.


Usage:-
setWindowTitle(title);

Page | 7
Name:- Mandar M. Mayekar Roll no:-31

28)string getWindowTitle();

Returns the title of the primary graphics window.


Usage:-
string title = getWindowTitle();

29)void exitGraphics();

Closes the graphics window and exits from the application without waiting for any additional user
interaction.
Usage:-
exitGraphics();

Conclusion:-

Page | 8

Das könnte Ihnen auch gefallen