You are on page 1of 17

1.

What is Affine Transformation

 It’s a transformation that combines linear transformation and translation class.

Properties
 Origin does not necessarily map to origin
 Lines map to lines which means lines remain parallel and
evenly spaced.
 Parallel lines remain parallel
 Ratios are preserved like this
 Affine transformation mostly implemented by including homogenous coordinates
for uniform representations of transformation classes since we use linear
transformations(rotation, scaling and other) with translation done by appending
1 to the input vector and translation vector.

2. Why do we use homogeneous coordinates in computer graphics?

 Homogeneous coordinates are ubiquitous in computer graphics because they


allow common vector operations(Uniform representation of all
transformation classes) such as translation, rotation, scaling and
perspective projection to be represented as a matrix by which the
vector is multiplied.

 Homogenous can used in all transformation class to fit the picture into proper
position.

 To treat all transformations in a consistent way.

 In HC ,2d changes into 3d and other


#3 G.Tessellation

 Tessellation is a technique that allows you to generate primitives (triangles,


lines, points and such) on the graphics-card.

 Specifically, it lets us repeatedly subdivide the current geometry into a finer


mesh.

 This allows you to load a relatively coarse mesh on your graphics card,
generate more vertices and triangles dynamically and then have a mesh on the
screen that looks much smoother

 Can be accurately described as tiling.


 Tessellations consist of a repeating pattern of one or more shapes.

 Tessellation is done in multiple stages, and it is done AFTER the vertex


shader and it differ based on general purpose software package we used

 In OpenGL, they are called the Tessellation Control Shader,


Tesselation Primitive Generation, and the Tessellation Evaluation
Shader.

 There are a few qualifications for a pattern to be a tessellation. These include:

 Shapes cannot overlap


 Shapes cannot have space between them.
 The patterns are created by rotating, translating, or reflecting the
shapes.
Fig1 :Stages of tessellation

How are Tessellations Made?

 When a geometric shape is repeated over and over again, covering


a plane of tiles without any gaps or overlaps, it results in a tessellation 
 Tessellations are made through a group of techniques called transformations
OpenGL Tessellation
 Tessellation is subdividing concave polygons or polygons with intersecting
edges into convex polygons.

 Since OpenGL accepts only convex polygons for rendering, these non-convex
polygons must be tessellated before rendering.

 OpenGl provides a collection of routines to process tessellation.

Types of Tessellations.

Regular Tessellations

 The regular tessellation only has one repeating polygon shape within its


image
 A regular polygon is a shape that has equal side lengths and angle
measurements.
 The shapes that are commonly used include squares, triangles, or hexagons.
 The pattern of a regular tessellation is identical at each of its vertices.
 Regular tessellations have interior angles that are divisors of 360 degrees.
 For example, a triangle’s three angles total 180 degrees; which is a divisor of
360. A hexagon contains six angles whose measurements total 720 degrees.
This also is a divisor of 180, because 180 fits evenly into 720.

REGULAR TESSELLATIONS:
 RULE #1: The tessellation must tile a floor (that goes on forever) with no overlapping or
gaps.
 RULE #2: The tiles must be regular polygons - and all the same.
 RULE #3: Each vertex must look the same.

Semi-Regular Tessellations

 When two or three types of polygons share a common vertex, a semi-regular


tessellation is forms.
 There are nine different types of semi-regular tessellations including
combining a hexagon and a square that both contain a 1-inch side.
 Example of a semi-regular tessellation is formed by combining two hexagons
with two equilateral triangles.
 Another example of a semi-regular tessellation is that with triangle–
triangle–square–triangle–square in cyclic order, at each vertex.
Demi-Regular Tessellations

 A demi-regular tessellation is a pattern of regular polygons in


which there are two or three different polygon arrangements.
 There are 20 different types of demi-regular tessellations; these
are tessellations that combine two or three polygon
arrangements.
 A demi-regular tessellation can be formed by placing a row of
squares, then a row of equilateral triangles that are alternated up
and down forming a line of squares when combined.
 Demi-regular tessellations always contain two vertices.
Tessellation Benefits

 Saves lots of memory and bandwidth, which allows an application to render higher
detailed surfaces from low-resolution models.
 Supports scalable-rendering techniques, such as continuous or view dependent
levels-of-detail which can be calculated on the fly.
 Improves performance by performing expensive computations at lower frequency
(doing calculations on a lower-detail model). This could include blending
calculations using blend shapes or morph targets for realistic animation or physics
calculations for collision detection or soft body dynamics.

#4 Parabola

 A parabola is a plot of a function.


 a plane curve generated by a point moving so that its distance from a fixed
point is equal to its distance from a fixed line.
 something bowl-shaped (such as an antenna or microphone reflector)
 More specifically, it is the plot of a second degree polynomial function with
the general form: y=ax2+bx+cy=ax2+bx+c

In C, this can be expressed as:

1. y = a*x*x + b*x + c 
 Where y and x are floating point variables and a, b and c are constants. Now,
how to transfer this to the screen? By doing a bit of clever discrete
mathematics.
 Let us assume we have a canvas to plot individual pixels on. Then the actual
plotting function would look like this:

1. void plotParabola(const double a, const double b, const double c) { 


2.  
3. int x, y; 
4.  
5. for (x=-50; x <= 50; x++) { 
6. y = (int)(a*x*x + b*x + c); 
7. canvasPlotPixel(x, y, COLOR_BLACK); 
8. } 
9. } 

#Ellipse

Ellipse Definition

 An ellipse is the locus of points in a plane, the sum of whose distances from
two fixed points is a constant value.

 The two fixed points are called the foci of the ellipse.
Ellipse Equation

Equation of ellipse id x^2/a^2+y^2/b^2=1

Mid-point Ellipse algorithm is used to draw an ellipse in computer


graphics.

Mid-Point Ellipse Algorithm: 


1. Take input radius along x axis and y axis and obtain center of ellipse.
2. Initially, we assume ellipse to be centered at origin and the first point as : (x, y 0)=
(0, ry).
3. Obtain the initial decision parameter for region 1 as: p1 0=ry2+1/4rx2-rx 2ry
4. For every xk position in region 1 : 
If p1k<0 then the next point along the is (x k+1 , yk) and p1k+1=p1k+2ry2xk+1+ry2
Else, the next point is (x k+1, yk-1 ) 
And p1k+1=p1k+2ry2xk+1 – 2rx2yk+1+ry2
5. Obtain the initial value in region 2 using the last point (x 0, y0) of region 1 as:
p20=ry2(x0+1/2)2+rx2 (y0-1)2-rx2ry2
6. At each yk in region 2 starting at k =0 perform the following task. 
If p2k>0 the next point is (x k, yk-1) and p2k+1=p2k-2rx2yk+1+rx2
7. Else, the next point is (x k+1, yk -1) and p2k+1=p2k+2ry2xk+1 -2rx2yk+1+rx2
8. Now obtain the symmetric points in the three quadrants and plot the coordinate
value as: x=x+xc, y=y+yc
9. Repeat the steps for region 1 until 2r y2x>=2rx2y

Standard Equation of an Ellipse

There are two standard equations of the ellipse. These equations are based on the
transverse axis and the conjugate axis of each of the ellipse. The standard equation of
the ellipse x2a2+y2b2=1x2a2+y2b2=1 has the transverse axis as the x-axis and the
conjugate axis as the y-axis. Further, another standard equation of the ellipse
is x2b2+y2a2=1x2b2+y2a2=1 and it has the transverse axis as the y-axis and its
conjugate axis as the x-axis. The below image shows the two standard forms of
equations of an ellipse.

#Animating flag

#incluude<windows.h>
#include<gl/glut.h>
#include<math.h>
#define PI 3.1416
typedef struct point
{
GLfloat x, y, z;
};
void bino(int n, int *C)
{
int k, j;
for(k=0;k<=n;k++)
{
C[k]=1;
for(j=n;j>=k+1; j--)
C[k]*=j;
for(j=n-k;j>=2;j--)
C[k]/=j;
}
}
void computeBezPt(float u, point *pt1, int cPt, point *pt2, int *C)
{
int k, n=cPt-1;
float bFcn;
pt1 ->x =pt1 ->y = pt1->z=0.0;
for(k=0; k< cPt; k++)
{
bFcn = C[k] * pow(u, k) * pow( 1-u, n-k);
pt1 ->x += pt2[k].x * bFcn;
pt1 ->y += pt2[k].y * bFcn;
pt1 ->z += pt2[k].z * bFcn;

}
}
void bezier(point *pt1, int cPt, int bPt)
{
point bcPt;
float u;
int *C, k;
C= new int[cPt];
bino(cPt-1, C);
glBegin(GL_LINE_STRIP);
for(k=0; k<=bPt; k++)
{
u=float(k)/float(bPt);
computeBezPt(u, &bcPt, cPt, pt1, C);
glVertex2f(bcPt.x, bcPt.y);
}
glEnd();
delete[]C;
}
float theta = 0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
int nCtrlPts = 4, nBCPts =20;
point ctrlPts[4] = {{100, 400, 0}, {150, 450, 0}, {250, 350, 0},
{300, 400, 0}};
ctrlPts[1].x +=50*sin(theta * PI/180.0);
ctrlPts[1].y +=25*sin(theta * PI/180.0);
ctrlPts[2].x -= 50*sin((theta+30) * PI/180.0);
ctrlPts[2].y -= 50*sin((theta+30) * PI/180.0);
ctrlPts[3].x -= 25*sin((theta) * PI/180.0);
ctrlPts[3].y += sin((theta-30) * PI/180.0);
theta+=0.2;
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glPointSize(5);
glPushMatrix();

glLineWidth(5);
glColor3f(1, 0.4, 0.2); //Indian flag: Orange color code for(int i=0;i<50;i++)
for(int i=0;i<50;i++)
{
glTranslatef(0, -0.8, 0);
bezier(ctrlPts, nCtrlPts, nBCPts);
}
glColor3f(1, 1, 1); //Indian flag: white color code for(int i=0;i<50;i++)
for(int i=0;i<50;i++)
{
glTranslatef(0, -0.8, 0);
bezier(ctrlPts, nCtrlPts, nBCPts);
}
glColor3f(0, 1, 0); //Indian flag: green color code for(int i=0;i<50;i++)
for(int i=0;i<50;i++)
{
glTranslatef(0, -0.8, 0);
bezier(ctrlPts, nCtrlPts, nBCPts);
}
glPopMatrix();
glColor3f(0.7, 0.5,0.3);
glLineWidth(5);
glBegin(GL_LINES);
glVertex2f(100,400);
glVertex2f(100,40);
glEnd();
glutPostRedisplay();
glutSwapBuffers();
}
void init()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,500,0,500);
}
int main(int argc, char **argv)
{

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowPosition(0, 0);
glutInitWindowSize(500,500);
glutCreateWindow("Bezier Curve");
init();
glutDisplayFunc(display);
glutMainLoop();

#Rotating Cube

#include<gl/freeglut.h>
 
double rot = 0;
float matCol[] = {1,0,0,0};
 
void display(){
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(30,1,1,0);
glRotatef(rot,0,1,1);
glMaterialfv(GL_FRONT,GL_DIFFUSE,matCol);
glutWireCube(1);
glPopMatrix();
glFlush();
}
 
 
void onIdle(){
rot += 0.1;
glutPostRedisplay();
}
 
void reshape(int w,int h){
float ar = (float) w / (float) h ;
 
glViewport(0,0,(GLsizei)w,(GLsizei)h);
glTranslatef(0,0,-10);
glMatrixMode(GL_PROJECTION);
gluPerspective(70,(GLfloat)w/(GLfloat)h,1,12);
glLoadIdentity();
glFrustum ( -1.0, 1.0, -1.0, 1.0, 10.0, 100.0 ) ;
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
 
void init(){
float pos[] = {1,1,1,0};
float white[] = {1,1,1,0};
float shini[] = {70};
 
glClearColor(.5,.5,.5,0);
glShadeModel(GL_SMOOTH);
glLightfv(GL_LIGHT0,GL_AMBIENT,white);
glLightfv(GL_LIGHT0,GL_DIFFUSE,white);
glMaterialfv(GL_FRONT,GL_SHININESS,shini);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
}
 
int main(int argC, char* argV[])
{
glutInit(&argC,argV);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(600,500);
glutCreateWindow("Rossetta's Rotating Cube");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(onIdle);
glutMainLoop();
return 0;
}

#Simple car
#ifdef
__APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include <stdlib.h>
#include <math.h>
GLint b=300;
float counter=600.0;
void initOpenGl()
{
glClearColor(0.5,0.5,0.5,1); //Background Color
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,700,0,500);
glMatrixMode(GL_MODELVIEW);
}
void wheel(int x,int y)
{
float th;
glBegin(GL_POLYGON);
glColor3f(0,0,0);
for(int i=0;i<360;i++)
{
th=i*(3.1416/180);
glVertex2f(x+20*cos(th),y+20*sin(th));
}
glEnd();
}
void car()
{
//Bottom Part
glLoadIdentity();
counter=counter-0.03;
glTranslated(counter,100,0.0);
//glScaled(0.1,0.1,0.0);
glBegin(GL_POLYGON);
glVertex2f(100,100);
glVertex2f(100,160);
glVertex2f(450,160);
glVertex2f(450,100);
//Top Part
glBegin(GL_POLYGON);
glVertex2f(150,160);
glVertex2f(200,200);
glVertex2f(400,200);
glVertex2f(450,160);
glEnd();
wheel(200,100);
wheel(380,100);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
//Push and pop matrix for separating circle object from Background
glColor3f(0.0,1.0,0.0);
car();
glutSwapBuffers();
glFlush();
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|
GLUT_DEPTH);
glutInitWindowSize(700,500);
glutInitWindowPosition(0,0);
glutCreateWindow("Car Moving");
initOpenGl();
glutDisplayFunc(display);
glutIdleFunc(display);
glutMainLoop();
return 0;
}

You might also like