Skip to main content

Hidden Surface Removal

Look at the scratch code "RotatingSolidCube.cpp" and study 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] =100; v[7][1] = 300; v[7][2] = 100;

}

Point2D Project_ortho(float x, float y, float z){
 Point2D p0;
 p0.x = x ;
 p0.y = y ;
 return p0;
}

void update_normals(){      //updating the normal vectors 
 for (int f=0; f<6 -="" -dx="" ......="" 0.0f="" 0="" 1.0f="" 180.0="" 3.14="" 600="" 6="" 800="" 8="" amp="" ang="" angle="" argc="" argv="" break="" case="" char="" complete="" cos="" default:="" deg_x="" deg_y="" drawbox="" dx="" dy="" dz="" exit="" f="" faces="" float="" font="" for="" gl_projection="" glbegin="" glclear="" glclearcolor="" glcolor3f="" glend="" glflush="" glloadidentity="" glmatrixmode="" gluortho2d="" glut_key_down:="" glut_key_left:="" glut_key_right:="" glut_key_up:="" glutcreatewindow="" glutdisplayfunc="" glutinit="" glutinitwindowposition="" glutinitwindowsize="" glutkeyboardfunc="" glutmainloop="" glutpostredisplay="" glutspecialfunc="" glvertex2f="" glviewport="" i="" if="" in="" init="" int="" key="" keyboard="" main="" mydisplay="" n="" p0.x="" p0.y="" p0="Project_ortho(v[" p1.x="" p1.y="" p1="Project_ortho(v[" p2.x="" p2.y="" p2="Project_ortho(v[" p3.x="" p3.y="" p3="Project_ortho(v[" point2d="" portion="" prisms="" q="" radians="" return="" rotatebox_x="" rotatebox_y="" rotatex="" rotatey="" sin="" special="" switch="" this="" translate="" tx="*x," ty="*y," tz="" unsigned="" v="" void="" x="" y="" z="-tx">

Implement the back-face removal method to display the solid cube with the following vertices.
And the answer is given here

Comments

Popular posts from this blog

Some Basic Questions and answers on Operating System Concepts

1.        What are the three main purposes of an operating system? To provide an environment for a computer user to execute programs on computer hardware in a convenient and efficient manner. To allocate the separate resources of the computer as needed to solve the problem given. The allocation process should be as fair and efficient as possible. As a control program it serves two major functions: (1)    supervision of the execution of user programs to prevent errors and improper use of the computer, and (2)    Management of the operation and control of I/O devices. 2.       Keeping in mind the various definitions of operating system, consider whether the operating system should include applications such as web browsers and mail programs. Argue both that it should and that it should not, and support your answers. Point: Applications such as web browsers and email tools are performing an...

Image Processing

Okay, Now let's start doing Image Processing exercises on MATLAB. Before diving in let's start knowing what are the terms "Histograms", "Cumulative Histograms" and "Histogram Equalization" of an image. Let's see what are those, Histogram An image histogram is a type of histogram that acts as a graphical representation of the tonal distribution in a digital image. It plots the number of pixels for each tonal value. By looking at the histogram for a specific image a viewer will be able to judge the entire tonal distribution at a glance. Cumulative Histogram A cumulative histogram is a mapping that counts the cumulative number of observations in all of the bins up to the specified bin. That is, the cumulative histogram M i of a histogram m j is defined as:  Histogram Equalization Histogram equalization is a method in image processing of contrast adjustment using the image's histogram. for more definitions visit wik...