Questions about hard cirlces collisions 2d

I’m pretty new to jogl, as well as opengl, and just have a couple of questions.

I’m trying to make a particle simulation with hard cirlces collisions. My question is, is it faster to use an image as the cirlces, or is it faster to draw the circles using the draw polygon. I want the ability to use a lot of particles.

If the image is faster, what do I map it onto and how do I make part of it transparent. I’m also new to this.

I apologize for these seemingly trivial questions, but I really do appreciate the help.

kirby

Hi,

I would say that a fast way to draw particles is to use GL_POINT_SPRITES, you put your particles center into a vertex array or a VBO, you enable the sprites and draw all in one call…
For the collision you’ll have to do the math, whatever your rendering method is… since you will have a nice MVC pattern to handle your particles. :stuck_out_tongue:

would it be better to use a displayList that defines the sprite, and then just use gltranslate. Would this be faster. The circles aren’t going to be animated, and so I thought that maybe this approach might work

You can perform a little bench mark but I’m quite sure it won’t be faster… You’ll make a lot of glTranslate calls, with point sprites only one big draw.

Thanks a lot for the responses, but now I have two questions.

  1. What do you mean by one draw. I still have to change the particle positions somehow right? And then redraw the new positions. Maybe I’m just missing something.

  2. This part is a little more tricky. I know how to calculate if two particles will collide after a certain amount of time in normal conditions, but what I’m trying to do is a bit different. I’m trying to simulate a lot of particles by having my coordinates and particles be periodic. I want to have infinitely many particles all “reflected” in these other coordinates. This means that if a particle is traveling left it will, reappear out the right side. But this also means that if there is a particle on the right side it should hit it and collide. Same goes from top to bottom.

Since this is a simulation I need to calculate the exact time of collision, so I can’t do tick-based. So what I am stuck on is how to calculate the next time of collision, without actually creating these infinite particles. Maybe it takes 5 wrap arounds before these particles hit, but I’m not sure how this can be done. Though I hear it’s done often in chemistry demos.

kirby

Yes you have to update your position, but what I mean by “one draw” is that you only need to perform one openGL operation. You modify the buffer where your particles positions are stored and you draw the buffer in a single shot, which is quite fast…

For the second question I’m not taking the chance of answering you… but it seems possible to try a time update and then a collision checking, it may not be the fastest way nevertheless.

It was a little unclear on your second question. When you say that they have to be reflected onto the other side of the screen, couldn’t you just wrap the actual coordinate around. Then collisions would still work fine.

EX:
if (posX<0)
posX=width of screen
else if (posX>width of screen)
posX=0

and then do the same for y.

Of course there also could be mathematical functions that would take an arbitrary coordinate and match it onto the window and give the screen coordinate. Then when you want collisions, you just pass the real coordinate through the function and use that point to do the math.
However, this last idea should be unnecessary since you draw in screen space, collide in screen space, so you might as well have the coordinates be measured in screen space and actually wrap the values like I said to do first.

Sorry for rambling, I’m a bit tired.

Thanks for the replies everyone ;D.

But I’m still a confused as to my second question. You are indeed right, I can just add the if statement and the particle position will be mirrored, no problem. The problem comes into play when I have to calculate if two particles collide and the exact time. Usually you can solve this using a parametric equation with the position and velocity vectors, but now my coordinates are periodic, and I’m stuck.

I know I could just update the positions, check the particles for collisions, and then update; but I want this to be very precise and therefore I need the calculation.

Anyone have any ideas?

Have a function that takes a position and can convert the position from screen space to normal space, and from screen space to normal space. When you collide, you take your normal positions and run them through collision detection (try a physics engine for this, like joode or odejava), then draw them to the screen, putting them through your function that matches them to the screen.

However, I really must ask why you’re trying to use periodic locations, when you’re drawing won’t match. It seems that it would be incredibly confusing to the user. Also, you said you’re worried about loss of precision, I don’t think setting the particle’s position explicitly when it gets mirrored will do that much to you. In the end it will be faster than creating a transform function (see above) and will make it easier for the user to understand exactly what’s happening.