coda

12-09-2003, 03:21 PM

I wish to draw several layers of rect one on top of each other based on dimensions (thickness) input by user for each layer. I can draw the 1st layer directly when user input the length, breadth but not sure how to proceed for drawing the subsequent layers by shifting the position and changing the thickness using the code for the inital layer.Below is what i used to draw the rect:

float x = m_length;

float y = m_breadth;

//normals for 6 surfaces of cube

GLfloat n[6][3]={{-1.0, 0.0, 0.0},

{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0},

{0.0, -1.0, 0.0}, {0.0, 0.0, 1.0},

{0.0, 0.0, -1.0}};

//vertex indices for 6 faces of cube

GLint faces[6][4]={{0, 1, 2, 3},

{3, 2, 6, 7}, {7, 6, 5, 4},{4, 5, 1, 0}, {5, 6, 2, 1}, {7, 4, 0, 3} };

//coordinates of vertices

v[0][0] = v[1][0] = v[2][0] = v[3][0] = x;

v[4][0] = v[5][0] = v[6][0] = v[7][0] = -x;

v[0][1] = v[1][1] = v[4][1] = v[5][1] = -y;

v[2][1] = v[3][1] = v[6][1] = v[7][1] = y;

v[0][2] = v[3][2] = v[4][2] = v[7][2] = 1;

v[1][2] = v[2][2] = v[5][2] = v[6][2] = -1;

int i=0;

for (i = 0; i < 6; i++) {

glBegin(GL_QUADS);

glNormal3fv(&n[i][0]);

glColor3ub(242,134,60);

glVertex3fv(&v[faces[i][0]][0]);

glVertex3fv(&v[faces[i][1]][0]);

glVertex3fv(&v[faces[i][2]][0]);

glVertex3fv(&v[faces[i][3]][0]);

glEnd();}

float x = m_length;

float y = m_breadth;

//normals for 6 surfaces of cube

GLfloat n[6][3]={{-1.0, 0.0, 0.0},

{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0},

{0.0, -1.0, 0.0}, {0.0, 0.0, 1.0},

{0.0, 0.0, -1.0}};

//vertex indices for 6 faces of cube

GLint faces[6][4]={{0, 1, 2, 3},

{3, 2, 6, 7}, {7, 6, 5, 4},{4, 5, 1, 0}, {5, 6, 2, 1}, {7, 4, 0, 3} };

//coordinates of vertices

v[0][0] = v[1][0] = v[2][0] = v[3][0] = x;

v[4][0] = v[5][0] = v[6][0] = v[7][0] = -x;

v[0][1] = v[1][1] = v[4][1] = v[5][1] = -y;

v[2][1] = v[3][1] = v[6][1] = v[7][1] = y;

v[0][2] = v[3][2] = v[4][2] = v[7][2] = 1;

v[1][2] = v[2][2] = v[5][2] = v[6][2] = -1;

int i=0;

for (i = 0; i < 6; i++) {

glBegin(GL_QUADS);

glNormal3fv(&n[i][0]);

glColor3ub(242,134,60);

glVertex3fv(&v[faces[i][0]][0]);

glVertex3fv(&v[faces[i][1]][0]);

glVertex3fv(&v[faces[i][2]][0]);

glVertex3fv(&v[faces[i][3]][0]);

glEnd();}