Making fun little programs that calculate stuff.
This is basic balls.
Printable View
Making fun little programs that calculate stuff.
This is basic balls.
Bouncey balls.
Bubbles.
perhaps you should post the source instead of the compiled exe
Not sure what I want to do with it yet.
Maybe I'll post the source later.
What was your method for making the balls bounce of each other? I want to know how to do that.
PS I'm not going to be using Visual Basic so if you could just explain like a general algorithm, i would be thankful.
The code is optimized for the structures.
Unless you were also using circles my code would probably be of little help to you.
I use the distance formula to find the distance between centers, then check to see if that's less than the radii of the circles combined. If so 'lengthly algo here'. Also, using a a^2+b^2=c^2 deviation, I calculate the points where the centers of the two collosioning objects should be. The hope is of course they don't overlap and using this method has given me decent results.
The bouncing is determained by the x,y (again a^2+b^2=c^2, find C from the movements). That is used to conserve momentum.
;)
There are also friction and gravity forces.
The method I use for determaining the resultant vector post collide isn't very accurate, but for all intents of this program, it suffices. The objects trade vectors. There is no glancing programming yet. I am, however; making advances towards such.
Here's a more functional version.
Left clicking on a ball with read it's info until deselected.
Right clicking on a ball will make it a magnet until deselected.
You Can tweak Gravity(higher is more) and...
Friction Free(1 = None, 0 = Pure Friction, > 1 = speeding up).
Why do the balls/bubbles sometimes do overlap?
Is it that you only check for a fixed number of collisions at a time?
The ballPhysics.zip contains an update routine for checking such things.Quote:
Originally posted by opus
Why do the balls/bubbles sometimes do overlap?
Is it that you only check for a fixed number of collisions at a time?
For each ball the same process is used.
Each point is looped, then for each point every other point is checked for collision.
For an example, if you resize the window until very tiny, then maximize, you'll see the balls literally popping out.
maybe I don't get your point, but I see bubbles that overlap each other (not only the shaded part, but also the solid blue part up to the white light-reflection).
ust look at a bubble in the middle of a big number of others.
I think at some times another bubble can overrun the investigated.
The engine is only as accurate was what's calculated. This isn't nature and things just happen! ;)
Yeah, things can overlap, if found the code will reposition them.
This depends on the version of course.<- !! All prior to the latest release don't have the enchancement.
...I'm thinking about making one in 3d.
And I didn't use any references for this. Just what I know. So that granted, I did pretty well.(i think)
That's a YES
Or in Navy-language BZ
Your balls and bouncing balls are perfect systems - they don't loose energy.
Maybe you could add an ambient property 'Temperature', so your balls can loose energy as heat.
Just a thought.
It's more about physical appearance, and it's speed of calculation.Quote:
Originally posted by Judd
Your balls and bouncing balls are perfect systems - they don't loose energy.
Maybe you could add an ambient property 'Temperature', so your balls can loose energy as heat.
Just a thought.
I just added the point info for technical fun.
BTW: those are earlier versions. Physics versions have such forces as friction and gravity.
Do one on inelastic oblique collisions.
I've developed two different collision routines.
The first is far better at conservation of momentum, while the second yields more precise resultant vectors. But the magnitude of such results are not at all accurate as the first's.
This first code:
VB Code:
If Points(Y).Size < 1 Then Points(Y).Size = 1 pd = (Points(X).Size / Points(Y).Size) / 2 P1mx = (Points(X).Move.X) P1my = (Points(X).Move.Y) If Points(X).Size < 1 Then Points(X).Size = 1 If Points(X).Size > Points(Y).Size Then pd = (Points(X).Size / Points(Y).Size) Points(X).Move.X = (Points(Y).Move.X / pd) * Fric Points(X).Move.Y = (Points(Y).Move.Y / pd) * Fric Points(Y).Move.X = (P1mx * pd) * Fric Points(Y).Move.Y = (P1my * pd) * Fric ' Else pd = (Points(Y).Size / (Points(X).Size)) Points(X).Move.X = (Points(Y).Move.X * pd) * Fric Points(X).Move.Y = (Points(Y).Move.Y * pd) * Fric Points(Y).Move.X = (P1mx / pd) * Fric Points(Y).Move.Y = (P1my / pd) * Fric End If
The second.
VB Code:
pxmx = Points(X).Move.X pxmy = Points(X).Move.Y pymx = Points(Y).Move.X pymy = Points(Y).Move.Y If Points(X).Size > Points(Y).Size Then Points(X).Move.X = (((xRadii + yRadii) * xd) / dist * Fric) Points(X).Move.Y = (((xRadii + yRadii) * yd) / dist * Fric) Points(Y).Move.X = -(((xRadii + yRadii) * xd) / dist * Fric) Points(Y).Move.Y = -(((xRadii + yRadii) * yd) / dist * Fric) Else Points(X).Move.X = (((xRadii + yRadii) * xd) / dist * Fric) Points(X).Move.Y = (((xRadii + yRadii) * yd) / dist * Fric) Points(Y).Move.X = -(((xRadii + yRadii) * xd) / dist * Fric) Points(Y).Move.X = -(((xRadii + yRadii) * yd) / dist * Fric) End If
Points is defined as:
VB Code:
Private Points() As pPoint 'pPoint is: Private Type pPoint Loc As sPoint Move As sPoint Size As Long Color As rgbCol LastColl As Long End Type 'which uses: Private Type sPoint X As Single Y As Single End Type Private Type rgbCol r As Long g As Long b As Long End Type
When colliding:
VB Code:
If dist > 1 Then Points(X).Loc.X = Points(Y).Loc.X + ((xRadii + yRadii) * xd) / dist Points(X).Loc.Y = Points(Y).Loc.Y + ((xRadii + yRadii) * yd) / dist Points(Y).Loc.X = Points(X).Loc.X - ((xRadii + yRadii) * xd) / dist Points(Y).Loc.Y = Points(X).Loc.Y - ((xRadii + yRadii) * yd) / dist End If
Sets each particle's location out of the other particle.
I've actually made minor modifications that will yield inelastic collisions.Quote:
Originally posted by plenderj
Do one on inelastic oblique collisions.
If you change the second code, to set the other particle's position as it's own, this requires you buffer the original spots. (as is done)
Poly particles will form, like molecules, and they 'can' break away though.
I have a lot of commented codes in my project.
Ok, here's the source code.
Two balls colliding at high speed, overlaps each other if the collision detection is performed after the balls have moved. This also results in incorrect distribution of momentum. I had to solve this problem once earlier:
http://www.vbforums.com/showthread.p...threadid=75004
I modify the code to check such things.Quote:
Originally posted by kedaman
Two balls colliding at high speed, overlaps each other if the collision detection is performed after the balls have moved. This also results in incorrect distribution of momentum. I had to solve this problem once earlier:
http://www.vbforums.com/showthread.p...threadid=75004
The problem is there really is no time varible.
I could however move both particles to their destinations then if the dist > radii then step back. The problem is the stepping back just adds further calculation.
Precision over accuracy.
You calculate the time at which the collision occurs relative to the time unit at which you move the balls one step in your loop, from the formula of distance per velocity t=x/v, in this case |X+Vt|=r1+r2, X and V are the position and velocity vectors of which one of the balls moves relative to the other.
There's the source code *looks up a few posts*.Quote:
Originally posted by kedaman
You calculate the time at which the collision occurs relative to the time unit at which you move the balls one step in your loop, from the formula of distance per velocity t=x/v, in this case |X+Vt|=r1+r2, X and V are the position and velocity vectors of which one of the balls moves relative to the other.
Feel free to add your additions then post an updated version.
can't be arsed with vb hehe :D
Arkanoid clone.
Going to add ball collisions eventually. As well as power-ups, etc.
Fackaball version .6
What's new?
-added 10 power ups. (from .2)
-minor bug fixes
Very sweet!
You should submit it to PSC(Planet-source-code.com). You'd get some sweet ratings
It needs some major optimizations.Quote:
Originally posted by VBD
Very sweet!
You should submit it to PSC(Planet-source-code.com). You'd get some sweet ratings
On lower-end systems the game is incredibly slow.
A good 10 minutes per level... if not more.
I plan to replace the shapes with GDI API. Or perhaps... bitblt... bitblt would be sexy....
Thanks for the 'sweet' comment though.
:D
Hi,
nice game, but
I'm using it on a Win2000 system, and whren clicking on FullScreen a second window for fullscreeen is created, but the original one remains there. The second (full screen) one has just the window title and a black background.
Is that correct?
'tis a lovely app.
Noticed a couple of things myself though.
The physics isn't quite right.
Even if the ball hits the corner of the block, it continues on upwards.
The speed of the balls seems to jump dramatically sometimes.
The paddle at the bottoms blinks quite a lot.
And if you go into Demo, you have some partial control over the paddle, and can also fire the guns...
To use the bitblt api, without all the code, load into the image list control. Then,
It is about just as fast but with much less code.Quote:
ImageList1.ListImages(0).Draw Me.Hdc, X, Y
Just a tip.
I didn't notice the slowness. I gues thats cause of my comp. It runs smooth....
A login converter...
WHat login is it for? Whats it do?:confused:
Converts say...Quote:
Originally posted by VBD
WHat login is it for? Whats it do?:confused:
http://user:[email protected]
to
http://site.com L:user P:pass
for site lists.
:p