Advertisement

how to translate 2nd oject based on 1st object?

Started by December 11, 2003 08:21 PM
0 comments, last by coda_x 21 years, 2 months ago
i drew a rect and wish to add another rect on top of it (all in 3D) but it doesn''t seem to show in the expected way. this is my code and not sure where is wrong: void CMainDialog::RenderScene() { UpdateData(TRUE); // dimensions from dialog length =(m_length/m_resolution); breath =(m_breadth/m_resolution); x = length/2; y = breath/2; SetupRC();//settings glTranslatef(0.0f,-1.5f,-7.0f); glRotatef(rquad,1.0f,1.0f,1.0f); //drawing 1st rect if(m_length!=0 && m_breadth!=0){ glColor3ub(242,134,60); shape();} //drawing 2nd rect on top of 1st if(m_thick!=0){ glTranslatef(0.0f,y,0.0f); y=((m_thick/m_resolution)/2); glColor3ub(255,153,204); shape();} } void CMainDialog::shape() { //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[0]); glVertex3fv(&v[faces[0]][0]); glVertex3fv(&v[faces[1]][0]); glVertex3fv(&v[faces[2]][0]); glVertex3fv(&v[faces[3]][0]); glEnd();} } the 1st rect showed OK but the 2nd rect whenever i changed the m_thick, i would expect the 2nd to still rest nicely &#111;n top of 1st rect but when the m_thick is too larger/smaller than m_breadth, the 2nd rect seem to "eat into" 1st rect or either floating above 1st rect, how do i do proper translate? </i>
quote:


if(m_thick!=0)
{
glTranslatef(0.0f,y,0.0f);
y=((m_thick/m_resolution)/2);
...
}



try:

y=((m_thick/m_resolution)/2);
glTranslatef(0.0f,y,0.0f);

| - Project-X - | - adDeath - | - my windows XP theme - | - email me - |

This topic is closed to new replies.

Advertisement