做這樣的事情:
// first of all, include the x,y position (assuming 2D, since pool) in the Ball object:
class Ball
{
//...
private:
float xpos, ypos;
//...
};
然後,當你構建球的陣列,而不是僅僅做8個球,你會想在堆上分配內存,使其將持續貫穿整個遊戲。所以這樣做:
Ball *ball= new Ball*[8];
ball[0] = new Ball(x0,y0);
ball[1] = new Ball(x1,y1);
ball[2] = new Ball(x2,y2);
ball[3] = new Ball(x3,y3);
// ...
確保當你的遊戲結束後,你自己清理。
for (int i = 0; i < 8; i++)
delete ball[i];
delete [] ball;
然後在你的球::平局()做這樣的事情:
Ball::draw()
{
glColor3f(/*yellow*/); // Set the color to yellow
glTranslatef(-xpos, -ypos, 0); // Move to the position of the ball
// Draw the ball
glTranslatef(xpos, ypos, 0); // Move back to the default position
}
所有你需要做的就是拿出正確的(X0,Y0),(X1,Y1) ,(x2,y2)...形成一個三角形!這是否有意義/回答你的問題?
謝謝這是有益的:)我會給這個去看看它是如何變成! – DK10 2011-04-21 17:02:29
請Upvote +接受,如果這解決了你的問題。 – 2011-04-21 21:10:19