void drawtriangle(float W,float L,float H)
{
//if(Line_Side==false)
//{
static float normal[3];
glBegin(GL_QUADS);
{
float v[4][3] ={{ W/2, L/2, -H/2},
{ -W/2, L/2, H/2},
{ -W/2,-L/2, H/2},
{ W/2,-L/2, -H/2}};
// Calculate the normal for the plane
calcNormal(v,normal);
glNormal3fv(normal);
glVertex3fv(v[0]);
glVertex3fv(v[1]);
glVertex3fv(v[2]);
glVertex3fv(v[3]);
}
{
float v[3][3] = {{ W/2, L/2, -H/2},
{ -W/2,L/2, -H/2},
{ -W/2,L/2,H/2}};
calcNormal(v,normal);
glNormal3fv(normal);
glVertex3fv(v[0]);
glVertex3fv(v[1]);
glVertex3fv(v[2]);
glVertex3fv(v[3]);
}
{
float v[4][3] = {{ -W/2, L/2, H/2},
{ -W/2, L/2,-H/2},
{ -W/2, -L/2,-H/2},
{ -W/2, -L/2, H/2}};
calcNormal(v,normal);
glNormal3fv(normal);
glVertex3fv(v[0]);
glVertex3fv(v[1]);
glVertex3fv(v[2]);
glVertex3fv(v[3]);
}
{
float v[3][3] = {{-W/2, -L/2, H/2},
{ -W/2, -L/2,-H/2},
{ W/2,-L/2,-H/2}};
calcNormal(v,normal);
glNormal3fv(normal);
glVertex3fv(v[0]);
glVertex3fv(v[1]);
glVertex3fv(v[2]);
glVertex3fv(v[3]);
}
{
float v[4][3] = {{ W/2, L/2, -H/2},
{ W/2, -L/2,-H/2},
{ -W/2, -L/2,-H/2},
{ -W/2, L/2, -H/2}};
calcNormal(v,normal);
glNormal3fv(normal);
glVertex3fv(v[0]);
glVertex3fv(v[1]);
glVertex3fv(v[2]);
glVertex3fv(v[3]);
}
glEnd();
/*}
else
{
// 邊緣線
int i;
glColor3ub(0, 0, 0);
glBegin(GL_LINE_STRIP);
{
float v[4][3] ={{ W/2, L/2, -H/2},
{ -W/2, L/2, H/2},
{ -W/2,-L/2, H/2},
{ W/2,-L/2, -H/2}};
for(i=0; i
2006-12-10 13:33:24 · 2 個解答 · 發問者 ? 1 in 電腦與網際網路 ➔ 程式設計
這題和您另一題雖然程式內容不同,但問題完全一樣。
請參那一題的解答。
學程式一定要自己解決過問題,才會進步。
加油!^_^
2006-12-17 17:51:19 · answer #1 · answered by ? 7 · 0⤊ 0⤋
你的程式不完全~~有些可能是我依常理推的
一開始glBegin(GL_QUADS)
GL_QUADS是產生矩形的函式
float v[4][3] ={{ W/2, L/2, -H/2},
{ -W/2, L/2, H/2},
{ -W/2,-L/2, H/2},
{ W/2,-L/2, -H/2}};
可能根據視窗大小~~W是寬~~H是高
calcNormal是你自訂的函式
接下來都是一樣~~
glBegin(GL_LINE_STRIP)
GL_LINE_STRIP這函式可以產生線段
for(i=0; i<5; i++)
glVertex3fv(v[i%4])
這裡經由glVertex3fv(v[i%4])產生出的值
會相連在一起~~直到FOR迴圈結束
接下來都一樣
2006-12-20 11:32:39 · answer #2 · answered by 王子麵 3 · 0⤊ 0⤋