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...

Play Fair Cipher (Version 2-with some corrections)

In my last post, I attached a file ( PlayFairCipher.java ) as my Play Fair Cipher Crypto System. But, I found out that it has an error when converting single row or column-wise words (E.g. WORD, PICO). Hence, I re-edited the file and my second version of it. Now it was working as expected. File : PlayFairCipherv2.java Comments are welcome.

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 ]