Skip to main content

Posts

Showing posts with the label Computer Graphics

Hidden Surface Removal

Look at the scratch code " RotatingSolidCube.cpp " and s tudy it carefully #include #include #include #include typedef struct{float x;float y;}Point2D; float dx = 200, dy = 200, dz = 200; GLfloat n[6][3]; /* Normals for the 6 faces of a cube. */ /* Vertex indices for the 6 faces of a cube. */ GLint faces[6][4] = { //traversed in counterclockwise direction as seen from outside {0, 1, 2, 3}, {3, 2, 6, 7}, {7, 6, 5, 4}, {4, 5, 1, 0}, {5, 6, 2, 1}, {7, 4, 0, 3} }; GLfloat v[8][3]; /* Will be filled in with X,Y,Z vertexes. */ void init(void) { /* Setup cube vertex data. */         v[0][0] =100; v[0][1] = 100; v[0][2] = 300;           v[1][0] =300; v[1][1] = 100; v[1][2] = 300;         v[2][0] =300; v[2][1] = 300; v[2][2] = 300;         v[3][0] =100; v[3][1] = 300; v[3][2] = 300;         v[4][0] =100; v[4][1] = 100; v[4][2] = 100;         v[5][0] =300; v[5][1] = 100; v[5][2] = 100;         v[6][0] =300; v[6][1] = 300; v[6][2] = 100;         v[7][0] =10

3D transformation & Projection

Clearly understand the given scratch code for the standard perspective projection. scratch code :  Pres_Proj.cpp Complete the code to  project the cube on the XY plane with the COP is at (0,0,-200) Use 2D translation to shift the projected cube so that the origin (0,0) moves to the centre of the screen [i.e., move the system to (WinWidth/2, WinHeight/2)] Use 3D translation to project the cube with COP is at (100,100,-200) The following file contain the answer for the above questions. While the file runs you can see the answer for 1. If you press your left-mouse button you will see the answer for 2. And by pressing right-mouse button you can view the answer for 3. PerspectiveProjection.cpp Enjoy.. #TRASHCODERS

Window to Viewport Mapping

1.  Try to execute the " ViewPortMap.cpp " with various values o f  bottomX,  bottomY,  width, and  height. 2.  Modify this code to get the display  a) such as this one b) and such as this And the answers are   Question 2)a)    Question 2)b) Enjoy!! #TrashCoders

Transformation and Translation

The solution will be posted soon... Try it out..

Rotating a Line w.r.t Origin and an Endpoint

Assignment 10 Rotating a given point in a anticlockwise direction about the origin in 2D. (You can specify a point by the left mouse button, and click the right mouse button to rotate it). Write a program to rotate any  line  through an angle (say 30 o ) with respect to  the origin [ Answer ]  one of its end points [ Answer ]

2D Transformation (Scale and Translate)

Write a program to accomplish the following tasks: draw a rectangle with vertices (0,0), (0,100), (200,100), (200,0). translates the rectangle to the mouse clicked location. Zoom-in the shape by pressing the "+" key, and  Zoom-out by pressing the "-" key. (Hint: Use the equations x = x 0 *S x , and y = y 0 *S y , where S x  and S y  are constants)    The file for the above will be available [-here-]  

Scan Conversion(Circle) - Midpoint Algorithm

Assignment 05. Use the mid-point circle technique to derive the necessary equations to scan convert the following circular sector (i.e., points from  27 0 o  to 315 o ) .  Implement your method and u se the circle's symmetric property to draw complete circles.   The file is available here ( ScanConvertCirclemidpoint.cpp ) Play with it. You will understand..

Scan Conversion(Circle) - Basic

Assignment 03. 1. Write a program to  generate points from 90 o  to 45 o  of a circle  centred at the origin, using  the standard x 2 +y 2 =r 2  circle equation,   using the trigonometric functions x = r cos θ, y = r sin θ  2. Use the circle's symmetric property to draw complete circles. The file is available here  Source.cpp Thanks to a friend NNI  

Scan Conversion(Line) - Bresenham's Algorithm

As the second Assignment we implemented Bresenham's Algorithm. For details visit  here . Assignment 02. 1.   Use the  Bresenham’s method to derive an algorithm to scan convert lines  with slope between 0 o  and -45 o (NOT  0 o  and +45 o ). 2.   Implement your algorithm to rasterize   lines that go from left to right, with slope between 0 o  and -45 o . 3.    Modify your program to scan convert lines with any slope. The file is available here (ScanConvertLine.cpp)

OpenGL

As we started learning OpenGL, We are going to do some practicals using Visual Studio and OpenGL. For that we need to follow some prerequisites. Thanks to Vishwanath This is GLUT installation instruction. Not free glut First download this 118 KB GLUT package from Here Extract the downloaded ZIP file and make sure you find the following glut.h glut32.lib glut32.dll If you have a 32 bits operating system, place glut32.dll to C:\Windows\System32\ , if your operating system is 64 bits, place it to 'C:\Windows\SysWOW64\' (to your system directory) Place glut.h C:\Program Files\Microsoft Visual Studio 12\VC\include\GL\ (NOTE: 12 here refers to your VS version it may be 8 or 10) If you do not find VC and following directories.. go on create it. Place glut32.lib to C:\Program Files\Microsoft Visual Studio 12\VC\lib\ Now, open visual Studio and Under Visual C++, select Empty Project(or your already existing p