0% found this document useful (0 votes)
55 views36 pages

CG Reportnewraj22

c

Uploaded by

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

CG Reportnewraj22

c

Uploaded by

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

Computer Graphics Project

I.

2014

Synopsis

The main aim of computer graphics is to display and print realisticlooking images. This task is achieved by computing the outer surface of the
object or objects to be displayed, and rendering it by simulating the way it is
seen in real life. Most real objects are visible because they reflect light, so the
main task of rendering is to simulate light reflection. Rendering is therefore an
important part of computer graphics. In order to render a real object, such as a
teapot or a car, its surface has first to be calculated and stored in the computer
as a mathematical expression. The rendering algorithm then scans the surface
point by point, computes the normal vector to the surface at every point, and
uses the normal to compute the amount and color of light reflected from the
point.
Electric circuit using Bresenhams' Line Drawing Algorithm, here
bresenhams' line drawing algorithm is used to simulate an Electrical Circuit.
Bouncing of balloons using Curves, here Bezier curves are used to create
Balloons. Bezier curves are a very popular curve type. Bezier curves have
precisely n control points, where n + 1 is the degree of the Bezier polynomial.
A Bezier curve is a parametric curve frequently used in computer graphics
and related fields.
Line is the two points connected each other. Line is the fundamental
unit of the computer graphics used to generate different shapes of objects by
connecting different points in the plane. The lines can be animated with
differen color combinations to use in developments of repots. This project
deals with different line pattern like Thick and Thin line and Two lines
with background. The Bresenhams line drawing algorithm is one of the
computer graphics techneque to draw line effectivly by coonecting points.
Bouncing is a special affect in motion pictures and animations that
keep changing (or Translates) the image's position around the screen through a
seamless transition. Creating Balloons with Bezier Curves, Bezier curves
have n control points, where n+1 is the degree of the Bezier polynomial. The
idea behind Bezier curves is to create a smooth curve, one intuitive
Dept. Of MCA

Page 1

Computer Graphics Project

2014

mechanism is to first connect the four control points with lines. Then draw
new lines connecting the midpoints of those lines, until the resulting curve is
sufficiently smooth.

Dept. Of MCA

Page 2

Computer Graphics Project


II.

2014

Design Specification
Bresenhams Line-Drawing Algorithm:

Bresenham's line algorithm is an algorithm that determines which


points in an n-dimensional raster should be plotted in order to form a close
approximation to a straight line between two given points. It is commonly
used to draw lines 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 one of the earliest algorithms developed in the
field of computer graphics. A minor extension to the original algorithm also
deals with drawing circles.

The three main features of Bresenham's line drawing algorithm are:


It is incremental. The calculation of the next pixel's x,y coordinate
are based on the current pixel's x,y coordinate.
It uses only integer values.
The number of divides and multiplies is kept to a minimum.
We shall develop the algorithm for lines with a slope of between 0 and
1 (i.e. sloping upwards from left to right).

Illustration of the result of Bresenham's line algorithm. (0,0) is at the


Dept. Of MCA

Page 3

Computer Graphics Project

2014

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:
Step 1: Input the two endpoints and store the left endpoint in
(x0,y0).
Step 2: Set color for frame-buffer position (x0,y0); ie., plot the first
point.
Step 3: Calculatte the costants x,y,2y,2y-2x, and obtain the
starting value for decision parameter as
p0=2y-x
Step 4: At each xk along the line, starting at k=0, perform the
following test: If pk< 0, the next point to plot is (xk+1, yk)

and

pk+1=pk+2y
Otherwise, the next point to ploat is(xk+1,yk+1) and
pk+1=pk+2y-2x
Step 5: Repeat step 4 x-1 more times.

Develop a screen saver with curves with the given attributes


Bouncing Balloons using Curves
Bezier curves are a very popular curve type which were widely
publicized in 1962 by the French engineer Pierre Bzier, who used them to
design automobile bodies. The curves were first developed in 1959 by Paul de
Casteljau using de Casteljau's algorithm, a numerically stable method to
evaluate Bzier curves. Bezier curves are a form of "parametric" function
which are used to model smooth curves that can be scaled indefinitely.
"Paths," as they are commonly referred to in image manipulation programs,
are combinations of linked Bezier curves. Paths are not bound by the limits of
rasterized images and are intuitive to modify. Bezier curves are also used in
animation as a tool to control motion.
Dept. Of MCA

Page 4

Computer Graphics Project

2014

Bezier curves have precisely n control points, where n + 1 is the


degree of the Bezier polynomial. To create a longer curve, it is necessary to
connect multiple Bezier curves. This is usually done by making the last
control point of one curve the same as the first control point of the next curve.
Bezier curves pass through the first and last control points of each curve
segment, however, which makes them quite easy to work with and popular for
use in interactive design programs. Bezier curves always lie within the convex
hull of the control points, and always have the sum of the basis functions add
to 1. [4]
The idea behind Bezier curves is quite simple. To create a smooth
curve, one intuitive mechanism is to first connect the four control points with
lines. Then draw new lines connecting the midpoints of those lines, and more
new lines to connect the midpoints of the new lines, and so forth until the
resulting curve is sufficiently smooth.
Formula for Bezier Curves - [5]
A n-dimensional Bezier curve is a curve of degree n. It is composed of
Bernstein basis polynomials of degree n:

with the Bernstein basis polynomials of degree n defined as:

Pi is called control point for the Bezier curve. By connecting all control points
with lines, we receive a polygon - starting in P0 and finishing in Pn - that is
called Bzier polygon. The Bezier curve is completely contained in the hull
built from the Bzier polygon.

Bezier Curve of degree 4.


Dept. Of MCA

Page 5

Computer Graphics Project

2014

The Bernstein polynomials are the weighting functions for Bezier curves. The
following image shows the Berstein polynomial functions of a Bezier curve of
degree We can see how much influence has each polynomial on the curve

progression. For
example at t=0 only b0 is nonzero. Therefore all other polynomials don't have
a bearing on the curve progression in the point S(t=0).

III.
Dept. Of MCA

Graphical Features
Page 6

Computer Graphics Project

2014

An Electrical Circuit is a fictorial representation of how the Electricity


flows in an electrical connectivity. Electrical Circuits are very usefull in
knowing the current(or electricity) flow. Electricians use the circuits to design
the entire connectivity of Electricity of a Building.
A Balloon is a air blown object which moves around in air when not
tied to any thing. A spline curve is defined, modified & manipulated with
operations on the control points. By interactively selecting spatial positions for
the control points, a designer can set up an initial shape. After the polynomial
fit is displayed for a given set of control points, the designer can then
reposition some of or all the control points to restructure the shape of the
curve. In general, a Bezier Curve can be fitted to any number of control
points. The degree of the Bezier polynomial is determined by the number of
control points to be approximated & their relative position. [6]
Coloring Effects
The color effects of Electrical Circuit are:

Black

White

The color of the background for Bouncing Balloons using Curves is:

Black

Color of the 1st Balloon are:

Red

Green

Blue

Yellow

Color s of the rest 2 Balloons are:

Light Blue

White

Dept. Of MCA

Page 7

Computer Graphics Project

2014

Green

List of OpenGL functions incorporated in this project is as follows

glClear(GL_COLOR_BUFFER_BIT)

gluOrtho2D()

glColor3f()

glMatrixMode(GL_PROJECTION)

glClearColor()

glBegin(GL_POINTS)

glBegin(GL_LINES)

glEnd()

glFlush()

Dept. Of MCA

Page 8

Computer Graphics Project


IV.

2014

OUTPUT Screen

1. Electrical Circut using Bresenhams' Line Drawing Algorithm:


Fig 1
The above figure shows the design of the Electrical circuit.
2. Develop a screen saver using curves Bouncing Balloons using Curves.

Fig 2
Figure 2 shows the Balloons Created Using Bezeir Curves.
Dept. Of MCA

Page 9

Computer Graphics Project

2014

Fig 3
Figure 3 shows the Balloons Created Using Bezeir Curves.

Fig 4
Figure 4 shows the Balloons Created Using Bezeir Curves.
Dept. Of MCA

Page 10

Computer Graphics Project

2014

Fig 5
Figure 5 shows the Balloons Created Using Bezeir Curves.

Dept. Of MCA

Page 11

Computer Graphics Project

2014

Conclusion
Bouncing of Balloons using curves is a computer animated screen
saver. The use of bouncing technique helps in translation of the object with
animation. When the balloon hits the XMAX or YMAX of the screen, it
bounces back, this phenomenon is continued endlessly.
Another project is about designing a pattern of an Electrical Circuit.
Where Bresenhams' Line Drawing Algorithm is used to draw different line
styles.
The future enhancement of the bouncing technique can be done with
use of user input of co-ordinates system and use of keyboard/Mouse events for
the car travelling direction.

Dept. Of MCA

Page 12

Computer Graphics Project

2014

References
1. Steven M. Seitz, And Charles R. Dyer, "View Morphing" Proc.
SIGGRAPH 96. In Computer Graphics 2012 pp. 21-30.
2. William Armstrong, Mark Green, and R. Lake. Near-real-time control
of human gure models, 2013 IEEE Computer Graphics and
Applications, 7(6):52 61.
3. Donald Hearn; M. Pauline Baker. Computer graphics. Prentice-Hall.
ISBN 978-0-13-161530-4.
4. Cartography for Swiss Higher Education,
www.cartouche.com/1.6.1.BezierCurve.html
5. Weisstein, Eric W. "Bzier Curve." From MathWorld--A Wolfram
Web Resource. http://mathworld.wolfram.com/BezierCurve.html
6. Donald Hearn, M. Pauline Baker, Warren Carithers, Computer
graphics with OpenGL Fourth Edition, Pages 410-422, ISBN 978-93325-1871-1.

Dept. Of MCA

Page 13

Computer Graphics Project

2014

Source Code
/* Electrical Circuit using Bresenhams' Line Drawing Algorithm */
#include<stdio.h>
#include<GL/gl.h>
#include<GL/glu.h>
#include<GL/glut.h>
#include<math.h>
void myinit();
void putpixel();
void display();
int x1;
int x2,y2,y3;
int flag1=0, flag=0;
void putpixel(int x,int y)
{
glBegin(GL_POINTS);
glVertex2i(x,y);
glEnd();
glFlush();
}

void putpixel1(int x,int y)


{
if(flag%5==0)
{

Dept. Of MCA

Page 14

Computer Graphics Project

2014

if(flag1%2==1)
{
glBegin(GL_POINTS);
glVertex2i(x,y);
glEnd();
}
}
flag++;
flag1++;
glFlush();
}

void brline(int x1, int y1, int x2, int y2)


{
int dx,dy,i,e;
int incx, incy, inc1, inc2, x,y;
dx=x2-x1;
dy=y2-y1;
if(dx<0) {
dx=-dx;
}
if(dy<0) {
dy=-dy;
}
incx=1;

Dept. Of MCA

Page 15

Computer Graphics Project

2014

if(x2<x1) {
incx=-1; }
incy=1;
if(y2<y1) {
incy=-1; }
x=x1;
y=y1;

if(dx>dy)
{
putpixel(x,y);
e=2*dy-dx;
inc1=2*(dy-dx);
inc2=2*dy;

for(i=0;i<dx;i++)
{
if(e>=0)
{
y=y+incy;
e=e+inc1;
}
else
e=e+inc2;

Dept. Of MCA

Page 16

Computer Graphics Project

2014

x=x+incx;
putpixel(x,y);
}
}
else
{
putpixel(x,y);
e=2*dx-dy;
inc1=2*(dx-dy);
inc2=2*dx;

for(i=0;i<dy;i++)
{
if(e>=0)
{
x=x+incx;
e=e+inc1;
}
else
e=e+inc2;
y=y+incy;
putpixel(x,y);
}
}
}

Dept. Of MCA

Page 17

Computer Graphics Project

2014

void brlin(int x1, int y1, int x2, int y2)


{
int dx,dy,i,e;
int incx, incy, inc1, inc2, x,y;
dx=x2-x1;
dy=y2-y1;
if(dx<0) {
dx=-dx;
}
if(dy<0) {
dy=-dy;
}
incx=1;
if(x2<x1) {
incx=-1; }
incy=1;
if(y2<y1) {
incy=-1; }
x=x1;
y=y1;

if(dx>dy)
{
putpixel1(x,y);

Dept. Of MCA

Page 18

Computer Graphics Project

2014

e=2*dy-dx;
inc1=2*(dy-dx);
inc2=2*dy;

for(i=0;i<dx;i+=2)
{
if(e>=0)
{
y=y+incy;
e=e+inc1;
}
else
e=e+inc2;

x=x+incx;
putpixel1(x,y);
}
}
else
{
putpixel1(x,y);
e=2*dx-dy;
inc1=2*(dx-dy);
inc2=2*dx;

Dept. Of MCA

Page 19

Computer Graphics Project

2014

for(i=0;i<dy;i+=2)
{
if(e>=0)
{
x=x+incx;
e=e+inc1;
}
else
e=e+inc2;
y=y+incy;
putpixel1(x,y);
}
}
}

void display()
{
glClear(GL_COLOR_BUFFER_BIT);

//glFlush();
//glVertex2i(400,0);
//glVertex2i(-400,0);
//glVertex2i(0,400);
//glVertex2i(0,-400);
glColor3f(0.0,0.0,0.0);

Dept. Of MCA

Page 20

Computer Graphics Project

2014

brline(100,100,300,100);
//glutSolidSphere(3.0,100.0,100.0);
brline(500,100,800,100);
brline(1000,100,1300,100);
brline(1300,100,1300,500);
brline(1300,550,1300,1050);
brline(1300,1050,1000,1050);
brline(800,1050,500,1050);
brline(300,1050,100,1050);
brline(100,1050,100,550);
brline(100,500,100,100);
brlin(650,1050,650,50);
brlin(650,500,650,-300);

brline(300,1050,333,1000);
brline(333,1000,366,1100);
brline(366,1100,400,1000);
brline(400,1000,433,1100);
brline(433,1100,466,1000);
brline(466,1000,500,1050);

brline(800,1050,833,1000);
brline(833,1000,866,1100);
brline(866,1100,900,1000);

Dept. Of MCA

Page 21

Computer Graphics Project

2014

brline(900,1000,933,1100);
brline(933,1100,966,1000);
brline(966,1000,1000,1050);

brline(300,100,333,50);
brline(333,50,366,150);
brline(366,150,400,50);
brline(400,50,433,150);
brline(433,150,466,50);
brline(466,50,500,100);

brline(800,100,833,50);
brline(833,50,866,150);
brline(866,150,900,50);
brline(900,50,933,150);
brline(933,150,966,50);
brline(966,50,1000,100);

brline(75,500,125,500);
brline(50,550,150,550);
brline(600,500,700,500);
brline(625,550,675,550);
brline(1250,550,1350,550);
brline(1275,500,1325,500);

Dept. Of MCA

Page 22

Computer Graphics Project

2014

brline(0,600,0,550);
brline(-20,575,20,575);
brline(-20,475,20,475);

brline(530,575,570,575);
brline(550,500,550,450);
brline(530,475,570,475);

brline(1200,600,1200,550);
brline(1180,575,1220,575);
brline(1180,475,1220,475);

glEnd();
glBegin(GL_POINT);
glPointSize(6);
glVertex2i(100,100);
glVertex2i(650,100);
glVertex2i(1300,100);
glVertex2i(1300,1050);
glVertex2i(650,1050);
glVertex2i(100,1050);
glEnd();
glFlush();
}

Dept. Of MCA

Page 23

Computer Graphics Project

2014

void myinit()
{
glColor3f(1.0,1.0,1.0);
glClearColor(1,1,1,0);
glPointSize(2);
gluOrtho2D(-100,1400,-100,1300);
}

int main(int argc, char **argv)


{
glutInit(&argc,argv);

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(1500,1500);
glutInitWindowPosition(00,00);
glutCreateWindow("bresanhams");
glutDisplayFunc(display);
myinit();
glutMainLoop();
}

Dept. Of MCA

Page 24

Computer Graphics Project

2014

/* Develop a screen saver using curves Bouncing of balloons Created


using Curves */
# include <GL/glut.h>
#include<math.h>
#include<iostream>
/**************GLOBALS***************************************
************/
double spin = 0.0, scale = 1.0, scaleOffset = -0.005;
int tx = 60, ty = 67, dy = 2, dx =3, DIRspin = 1, HEXsize = 1;
int hex[13][2] ={{ 0,0 },{ 0,27 },{ 26,12},{26,-12},{ 0,-27},{-26,-12},{-26,12
},{-54,0 },{-24,51},{24,51 },{ 54,0 },{ 24,-51},{-24,-51} };
int Green[18] = {

0,1,9 , 0,2,10 , 0,3,11 , 0,4,12 , 0,5,7 , 0,6,8 };

int Purple[18] = {

0,2,9 , 0,3,10 , 0,4,11 , 0,5,12 , 0,6,7 , 0,1,8 };

void delay()
{

for(int i=0; i<=200000000;i++);

Dept. Of MCA

}
Page 25

Computer Graphics Project

2014

void draw_pixel(int x[], int y[], int z[],int limit)


{
glBegin(GL_LINE_STRIP);
for(int k=1; k<=limit-1;k++)
glVertex3i(x[k],y[k],z[k]);
glEnd();
}

void Curve_draw(GLint x0, GLint y0, GLint z0, GLint x1, GLint y1, GLint
z1, GLint x2, GLint y2, GLint z2, GLint x3, GLint y3, GLint z3 )
{
int ax, ay,az, bx, by, bz,cx, cy, cz,dx, dy,dz, x[100], y[100],z[100];
double numsteps, i, t;
int k;
float stepsize;
ax = -x0 + 3*x1 + (-3*x2) + x3;
ay = -y0 + 3*y1 + (-3*y2) + y3;
az = -z0 + 3*z1 + (-3*z2) + z3;
bx = 3*x0 + (-6*x1) + (3*x2);
by = 3*y0 + (-6*y1) + (3*y2);
bz = 3*z0 + (-6*z1) + (3*z2);
cx = -3*x0 + 3*x1;
cy = -3*y0 + 3*y1;
cz = -3*z0 + 3*z1;
Dept. Of MCA

Page 26

Computer Graphics Project

2014

dx = x0;
dy = y0;
dz = z0;
numsteps = 100.0;
stepsize = 1.0/ (double) numsteps;
for(i=1,k=1; i<numsteps;i++,k++)
{
t = (double)stepsize*(double) i;

x[k] = ax * (t*t*t) + bx * (t*t) + cx*t + dx;


y[k] = ay * (t*t*t) + by * (t*t) + cy*t + dy;
z[k] = az * (t*t*t) + bz * (t*t) + cz*t + dz;
}
draw_pixel(x, y,z,k);
}

void display(void) {
glClear (GL_COLOR_BUFFER_BIT);
glPushMatrix();
glTranslatef(tx,ty,0);
glRotatef(spin, 0.0, 0.0, 1.0);
glScalef(scale, scale, 0.0);
/*
for(int i=-40;i<=-20;i++)
{

Dept. Of MCA

Page 27

Computer Graphics Project

2014

glColor3d(1,0,1);
Curve_draw(0,200,100,60,190,100,i+80,120,100,0,0,100);
}
for(int i=-20;i<=0;i++)
{
glColor3d(1,1,0);
Curve_draw(0,200,100,60,190,100,i+80,120,100,0,0,100);
}
for(int k=0;k<=20;k++)
{
glColor3d(1,1,1);
Curve_draw(0,200,100,100,190,100,k+80,120,100,0,0,100);
}
for(int k=20;k<=40;k++)
{
glColor3d(1,0,1);
Curve_draw(0,200,100,100,190,100,k+80,120,100,0,0,100);
}
for(int j=-20;j<=0;j++)
{
glColor3d(0,0,1);
Curve_draw(0,200,100,80,190,100,80,120,100,0,0,100);
}
for(int l=0;l<=20;l++)
{

Dept. Of MCA

Page 28

Computer Graphics Project

2014

glColor3d(1,1,1);
Curve_draw(0,200,100,80,190,100,80,120,100,0,0,100);
}
*/
for(int i=-40;i<=-20;i++)
{
glColor3d(0,1,0);
Curve_draw(40,190,100,(i+40),190,100,(i+100),120,100,0,0,100);
}
for(int i=-20;i<=0;i++)
{
glColor3d(1,1,1);
Curve_draw(40,190,100,(i+40),190,100,(i+100),120,100,0,0,100);
}
for(int k=0;k<=20;k++)
{
glColor3d(0,1,0);
Curve_draw(40,190,100,(k+80),190,100,(k+100),120,100,0,0,100);
}
for(int k=20;k<=40;k++)
{
glColor3d(0,1,0.6);
Curve_draw(40,190,100,(k+80),190,100,(k+100),120,100,0,0,100);
}
for(int j=-20;j<=0;j++)

Dept. Of MCA

Page 29

Computer Graphics Project

2014

{
glColor3d(0,1,0.4);
Curve_draw(40,190,100,(j+60),190,100,100,120,100,0,0,100);
}
for(int l=0;l<=20;l++)
{
glColor3d(0,1,1);
Curve_draw(40,190,100,(l+60),190,100,100,120,100,0,0,100);
}

for(int i=-40;i<=-20;i++)
{
glColor3d(0,1,0);
Curve_draw(-40,190,100,-(i+40),190,100,-(i+100),120,100,0,0,100);
}
for(int i=-20;i<=0;i++)
{
glColor3d(1,1,1);
Curve_draw(-40,190,100,-(i+40),190,100,-(i+100),120,100,0,0,100);
}
for(int k=0;k<=20;k++)
{
glColor3d(0,1,0);
Curve_draw(-40,190,100,-(k+80),190,100,-(k+100),120,100,0,0,100);

Dept. Of MCA

Page 30

Computer Graphics Project

2014

}
for(int k=20;k<=40;k++)
{
glColor3d(0,1,0.6);
Curve_draw(-40,190,100,-(k+80),190,100,-(k+100),120,100,0,0,100);
}
for(int j=-20;j<=0;j++)
{
glColor3d(0,1,0.4);
Curve_draw(-40,190,100,-(j+60),190,100,-100,120,100,0,0,100);
}
for(int l=0;l<=20;l++)
{
glColor3d(0,1,1);
Curve_draw(-40,190,100,-(l+60),190,100,-100,120,100,0,0,100);
}

for(int i=-50;i<=-20;i++)
{
glColor3d(1,0,0);
Curve_draw(0,220,100,i-20,210,100,i,140,100,0,0,100);
}
for(int i=-20;i<=0;i++)

Dept. Of MCA

Page 31

Computer Graphics Project

2014

{
glColor3d(0,1,0);
Curve_draw(0,220,100,i-20,210,100,i,140,100,0,0,100);
}
for(int k=0;k<=20;k++)
{
glColor3d(0,0,1);
Curve_draw(0,220,100,k+20,210,100,k,140,100,0,0,100);
}
for(int k=20;k<=40;k++)
{
glColor3d(1,1,0);
Curve_draw(0,220,100,k+20,210,100,k,140,100,0,0,100);
}
for(int j=-20;j<=0;j++)
{
glColor3d(0,1,0);
Curve_draw(0,220,100,j,210,100,0,140,100,0,0,100);
}
for(int l=0;l<=20;l++)
{
glColor3d(0,0,1);
Curve_draw(0,220,100,l,210,100,0,140,100,0,0,100);
}

Dept. Of MCA

Page 32

Computer Graphics Project

2014

glColor3d(1,1,1);
glutSolidSphere(5.0,100.0,100.0);
Curve_draw(0,0,100,30,30,100,30,-30,100,0,0,100);
Curve_draw(0,0,100,-30,30,100,-30,-30,100,0,0,100);
Curve_draw(0,0,100,-30,-30,100,30,-60,100,0,-90,100);
Curve_draw(0,0,100,-15,-10,100,-20,-25,100,-40,-30,100);
Curve_draw(0,0,100,15,-10,100,20,-25,100,40,-30,100);
glPopMatrix();
glutSwapBuffers();
}
void BounceDisplay(void) {

int Radius = 54;


if(HEXsize < 100){
scale += scaleOffset;
HEXsize++;
}
else {
HEXsize = 0;
scaleOffset *= -1;
}
Radius *= scale;
if(DIRspin < 0){
spin = spin - 2.0;
}

Dept. Of MCA

Page 33

Computer Graphics Project

2014

else{
spin = spin + 2.0;
}
if(spin > 360.0){
spin = spin - 360.0;
}
if(spin < -360.0){
spin = spin + 360.0;
}
tx += dx;
ty += dy;
if((tx + Radius) > 700){
DIRspin *= -1;
dx*= -1;
tx -= (tx + Radius) - 700;
}
if((tx - Radius) < 0 ){
DIRspin *= -1;
dx*= -1;
tx += -1 * (tx - Radius);
}
if((ty + Radius) > 600){
DIRspin *= -1;
dy *= -1;
ty -= (ty + Radius) - 600;

Dept. Of MCA

Page 34

Computer Graphics Project

2014

}
if ((ty - Radius) < 0 ){
DIRspin *= -1;
dy *= -1;
ty += -1 * (ty - Radius);
}
glutPostRedisplay();
}
void init (void) {
glClearColor (0.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
glPointSize(5.0);
glLoadIdentity();
glOrtho(0, 700, 0, 600, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
}
void mouse(int button, int state, int Mx, int My) {
switch(button){
case GLUT_LEFT_BUTTON:
if (state == GLUT_DOWN){
tx = Mx;
ty = 400 - My;
break;
}
case GLUT_RIGHT_BUTTON:

Dept. Of MCA

Page 35

Computer Graphics Project

2014

if(state == GLUT_DOWN){
DIRspin *= -1;

break;
}
default:
break;
}
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize (700, 600);
glutInitWindowPosition (100, 100);
glutCreateWindow ("GLBounce! (point, click right,left)");
init();
glutDisplayFunc(display);
glutIdleFunc(BounceDisplay);
glutMouseFunc(mouse);
glutMainLoop();
return 0;
}

Dept. Of MCA

Page 36

You might also like