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">6>
Implement the back-face removal method to display the solid cube with the following vertices.
And the answer is given here
Comments
Post a Comment