How to do that ?

Hi

Hello everybody,

What I want to add is a two rows of balls (spheres) and when my bouncing ball hits one of that spheres… the sphere will disappeare … ??

Here is an illustration image :

Any idea …?

Thanks in advance …

Hi !

Not sure what you want to know, erasing the sphere is pretty simple, just don’t render it any more…

But for the rest, what do you need to figure out, collision detection or how to move the ball or what ?

Mikael

Hello mikael,

Each time ‘the bouncing game’ will hit different sphere … so each time I have to erease a different sphere selected randomly by the bouncing ball… how can I do that …

I already knew about collision detection , neither it nor moving the ball is my problem…

Maybe what I need is to create an array holding the spheres or their positions when the bouncing ball hit the sphere it state will turned to zero …But how to do that if its right … I don’t know ?

Thanks mikael…

you seem to not have an OpenGL problem but rahter a game engine problem… you are writing a bouncing ball game, and have to deal with typical stuff to manage the virual world your game takes place in. You have to invent a structure to manage the spheres and the bouncing ball, detect collisions and deleting spheres from the scene. OpenGL ist just used for rendering, but the complete game management you have to do yourself.

However, the bouncing ball scenario is quite simple, it should not be a big problem to write something like that. If you have rather large problems with this, maybe it’s a case of generally improving your programmings skills.

you need a class “Ball” or “Sphere” and each of the spheres and balls is one instance of this class. Each object has a position in space and a speed an a direction in which it moves, and you have to move the ones of them that ar moving (i.e. the ball), detect collisions and remove them from the scene if “hit”.

Jan

Here is where learning C/C++ come in handy.
My next thought to talk to you about was the use of structures.

Lets say we have your balls, each one has a location and state.

typedef struct My_balls
{
float x,y;
int state; // state = 0 then ball not drawn, state = 1 ball is drawn.
}

// Create space for eight balls and their location and inital states
My_balls balls_init[8] = {{4,5,1},…{3,2,1}};

// This is for when game in is play,we initalize this variable with balls_init at start of game.
My_balls balls_store[8];

// You would do this at the start of the game.
for(i=0;i<8;i++)
{
balls_store[i] = balls_init[i]; reset balls to inital state.
}

// in the display routine
// Process balls.

for(i=0;i<8;i++)
{
if( balls_store[i].state ) Draw_ball( balls_store[i].x,balls_store[i].y); // Draw ball only if state is one.
}

// add to collision routine, when a ball it hit.

balls_store[hit_ball].state = 0;

Also would add if a ball is in state = 0 then if the main ball hits it we just let if pass on through.

Hope this helps

[This message has been edited by nexusone (edited 12-16-2003).]

Hi Jan

Yeah … that’s what I mean …The idea is to generate two rows of balls, When a bouncing ball (hits) each of these balls ( the hitted ball will disapear) as an illustrated image shown …

the matter here is not opengl code because I already did that ( I mean the drawing of the two rows and coding the bouncing ball …) the matter here is programming … a pure programming … since I don’t know deeply about vc++ … I faced difficulties in programming the above…

Thank you …

Hi

Yeah … that’s what I mean … I really don’t know how to thank you … but I have some questions

What I 'm gotting so far is the following …

Question (1):

As declaration:

//typedef

struct My_balls
{
float x,y;
int state;
} ;

My_balls balls_init[26] = { {0,0,1},{0,0,1},{0,0,1},{0,0,1},{0,0,1},{0,0,1},{0,0,1},{0,0,1},{0,0,1},{0,0,1},{0,0,1},{0,0,1},{0,0,1},{0,0,1},{0,0,1},{0,0,1},{0,0,1},{0,0,1},{0,0,1},{0,0,1},{0,0,1},{0,0,1},{0,0 ,1} };

My_balls balls_store[26];

Why I am doing that ?
because I have 26 balls (13 in each row). I put {0,0,1) because I don’t know what you mean by that .Is it (x,y,state) so do I have to put all the actual Xs and Ys I mean statring like that for example (-45,66,1),(-55,66,1)… etc …??

Furthermore, you create space for 8 ball which means on row what about the other row?

…Is that what you mean or I’m going wrong here … ?

Question(2) :

Here is where I am drawing the balls

/***** Drawing Two rows of Balls ******/

void drawballs (void)
{
int row ;
for (row=0; row<13; row++)
{
glPushMatrix(); //save matrix
glTranslatef(-55.0f+10row,66.0f,0.0f);
glColor3f(1.0f, 1.0f, 0.0f);
glutSolidSphere(4.5,20,20);
glPopMatrix(); //restore matrix}
}
for (row=0; row<13; row++)
{
glPushMatrix(); //save matrix
glTranslatef(-55.0f+10
row,55.0f,0.0f);
glColor3f(1.0f, 1.0f, 0.0f);
glutSolidSphere( 4.5,20,20);
glPopMatrix(); //restore matrix}
}
}

// End of drawing …

As following your steps you said :

"// in the display routine
// Process balls.

for(i=0;i<8;i++)
{
if( balls_store[i].state ) Draw_ball( balls_store[i].x,balls_store[i].y); // Draw ball only if state is one.
}"

I can’t get what you mean by "Draw_ball( balls_store[i].x,balls_store[i].y); " … I suppose you mean the drawballs routine … but in my case here … drawballs routine will draw the whole number of balls … so Do I have to add/change something in my drawballs routine … ??

Thanks so much in advance nexusone

[This message has been edited by glcrazy (edited 12-18-2003).]

Hi nexusone again,
I do some modifcations … I hope this is correct …

My_balls balls_init[26] = { {-55,66,1},
{-45,66,1},{-35,66,1},{-25,66,1},{-25,66,1},
{-15,66,1},{-5,66,1} ,{5,66,1}, {15,66,1}, {25,66,1},{35,66,1}, {45,66,1}, {55,66,1}, {-55,55,1},{-45,55,1},{-35,55,1},{-25,55,1},{-25,55,1},{-15,55,1},{-5,55,1},{5,55,1}, {15,55,1}, {25,55,1}, {35,55,1}, {45,55,1},{55,55,1}};

Draw_ball routine:

void Draw_ball(float xx, float yy)
{
glPushMatrix(); //save matrix
glTranslatef(xx,yy,0.0f);
glColor3f(1.0f, 1.0f, 0.0f);
glutSolidSphere( 4.5,20,20);
glPopMatrix(); //restore matrix}
}

Eventhough it still not work with me !

Just remember I am pulling this from my head, to give you a example and idea of how to do it.

What is the problem, does not draw in the correct place or order?

Now on drawing two rows of ball’s, you can do the following in your display routine:

int i;

for(i = 0; i < 26; i++)
{
if (My_balls.[i].state) Draw_Ball(My_balls[i].x,My_balls[i].y); // only balls in state 1 are drawn.
}

Another thing, sometimes it is good to draw out your screen object on grid paper to get an idea of location.

[This message has been edited by nexusone (edited 12-18-2003).]

[This message has been edited by nexusone (edited 12-18-2003).]

[This message has been edited by nexusone (edited 12-18-2003).]

IT WORKS …

Thankyou all