Author Topic: Pool  (Read 49674 times)

0 Members and 1 Guest are viewing this topic.

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Pool
« Reply #40 on: February 17, 2007 »
damn thats a kick in the stones do you know how to install a flappy drive you would be able to slot the floppy drive in the other pc the only thing is that floppy cables can go in the wrong way around unlike all other cables in a modern pc it would take about five minutes tops if you get the cable the right way around first time and if its the wrong way it wont break your pc at all

Challenge Trophies Won:

Offline Clanky

  • Laser Guided Memories
  • Amiga 1200
  • ****
  • Posts: 340
  • Karma: 16
  • kiss that sound that pounds your senses
    • View Profile
Re: Pool
« Reply #41 on: February 17, 2007 »
Ok, finally got it working... had to use 'my' old cord instead of my brothers.

It just needs the collisions added and I'm sure it's all working properly with rules and stuff.
He tilts, and his eyes are focused on the ground far below.. Wind? Angels? Men..

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Pool
« Reply #42 on: February 17, 2007 »
I'll put in the collisions a.s.a.p  ;) I cant wait til this is a finished game  :D Its looking ace at the moment Clanky this is gonna be brill
« Last Edit: February 17, 2007 by rain_storm »

Challenge Trophies Won:

Offline Clanky

  • Laser Guided Memories
  • Amiga 1200
  • ****
  • Posts: 340
  • Karma: 16
  • kiss that sound that pounds your senses
    • View Profile
Re: Pool
« Reply #43 on: February 17, 2007 »
Just realised... there are some rules missing... and I also need to fix the spin stuff. So, when you finish and post it - I will edit it so it has the other missing rules and spin (hopefully I can code the spin).

Thanks for this Rain.
I'll give you karma!
He tilts, and his eyes are focused on the ground far below.. Wind? Angels? Men..

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Pool
« Reply #44 on: February 17, 2007 »
You deserve k+ too man like the pause and stuff hope to have the collisions up and runnin by tomarrow then we can tackle the finishing touches

Challenge Trophies Won:

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Pool
« Reply #45 on: February 17, 2007 »
Man this is proving to be a challenge for me I am not use to workin in someone elses code but I always loved a challenge :D I may have to rework some parts but where ever I make a change I will try to have my adjustments runnin alongside you own code and not effect things for your code. that will help me and make it so that things are not messed up elsewhere so if you see something being done twice but with different variables thats why

Challenge Trophies Won:

Offline Clanky

  • Laser Guided Memories
  • Amiga 1200
  • ****
  • Posts: 340
  • Karma: 16
  • kiss that sound that pounds your senses
    • View Profile
Re: Pool
« Reply #46 on: February 18, 2007 »
Haha, I see your point!
Good luck with this... glad you took over to finish it because it was just sitting on my computer without collisions...

Thanks again Rain.  :buddies:
He tilts, and his eyes are focused on the ground far below.. Wind? Angels? Men..

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: Pool
« Reply #47 on: February 18, 2007 »
I've been looking into these collisions again, not with the intentions of being used in this project but feel free to use anything if you want (although it's still not working).

For this I've made some assumptions so please tell me if anything at all here is wrong.

1. The velocities of the balls along the tangent to the collision normal do not change.

2. The speed and direction of the combined centre of mass of both balls is the same before and after the collision

3. The speed at which the balls travel away from each other after the collision is equal to the speed at which they travelled towards each other before the collision.

I'm pretty certain about 1 and 2 but not so sure about 3.

from that, I've come up with this test in blitz.

Code: [Select]
Graphics 800,600,32,2

x1#=300:y1#=300
vx1#=40:vy1#=20
x2#=310:y2#=295
vx2#=-20:vy2#=40

Repeat

;read start position of ball1 from mouse coords
vx1#=300.0-MouseX()
vy1#=300.0-MouseY()

;get the collision normal and tangent
nx#=x2-x1
ny#=y2-y1
l#=1.0/Sqr(nx*nx+ny*ny)
nx#=nx*l
ny#=ny*l
tx#=ny
ty#=-nx

;get the tangent component of each balls vector
vp1#=vx1*tx+vy1*ty
vp2#=vx2*tx+vy2*ty

;write the tangent component into variables for the result
rx1#=vp1*tx
ry1#=vp1*ty
rx2#=vp2*tx
ry2#=vp2*ty

;find the centre of gravity of both balls combined
;the direction and speed of the centre of gravity should be constant before and after the collision
cx#=((vx1)+(vx2))*.5
cy#=((vy1)+(vy2))*.5

;get the initial distance apart
;they should be travelling apart After the collision at the same rate they travelled towards each other before
rad#=Sqr(((vx1)-(vx2))^2.0+((vy1)-(vy2))^2.0)*.5

;calculate where on the circle edge (radius from centre of gravity) the line is for v1
dot#=tx*(rx1-cx)+ty*(ry1-cy)
dis#=-Sqr(rad*rad-dot*dot)-(nx*(rx1-cx)+ny*(ry1-cy))
rx1#=rx1+nx*dis
ry1#=ry1+ny*dis

;and same for v2
dot#=tx*(rx2-cx)+ty*(ry2-cy)
dis#=Sqr(rad*rad-dot*dot)-(nx*(rx2-cx)+ny*(ry2-cy))
rx2#=rx2+nx*dis
ry2#=ry2+ny*dis

;draw test
Color $ff,$ff,$ff
Line x1,y1,x1-vx1,y1-vy1
Line x2,y2,x2-vx2,y2-vy2
Text 50,50,"total v before:"+(Sqr(vx1^2+vy1^2)+Sqr(vx2^2+vy2^2))

Color 0,0,$ff
Line x1,y1,x1+rx1,y1+ry1
Line x2,y2,x2+rx2,y2+ry2
Text 50,70,"total v after:"+(Sqr(rx1^2+ry1^2)+Sqr(rx2^2+ry2^2))

Flip
Cls
Until KeyDown(1)
End

But the sum of the velocities before and after the collision vary quite a lot and I have no idea what else to try as this all fits with the assumptions I've made.

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Pool
« Reply #48 on: February 18, 2007 »
3 is true but its true of the speed at which they are traveling relative to each other not the table so if ball one moves at 1 meter per second and ball two is not moving both balls will end up traveling at 1/2 meter per second after collision. This will be useful thanks for including it here Stonemonkey. This is a really tough game to get right even though its just a game based on collisions.

Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: Pool
« Reply #49 on: February 18, 2007 »
For 3. I mean (ignoring any other forces) if they are 1m apart 1 second before the collision then they will be 1m apart 1 second after the collision.

EDIT:
My calculations even though not working properly have a very surprising result, if the balls are placed and given velocity vectors in such a way that separate them instead of colliding them, the collision calculations seem to be able to handle that and the calculated vectors are the same as the initial vectors.
« Last Edit: February 18, 2007 by Stonemonkey »

Offline Clanky

  • Laser Guided Memories
  • Amiga 1200
  • ****
  • Posts: 340
  • Karma: 16
  • kiss that sound that pounds your senses
    • View Profile
Re: Pool
« Reply #50 on: February 19, 2007 »
I thought there was friction applied to the balls through the table? This would make 3 not true for this game?
But, I don't know haha lol
He tilts, and his eyes are focused on the ground far below.. Wind? Angels? Men..

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: Pool
« Reply #51 on: February 19, 2007 »
Heh, there should be but I'm wanting to work out the collision calcs without worrying about any other forces like that for now.

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Pool
« Reply #52 on: February 19, 2007 »
Not necessary to include friction at the moment of impact because the force of the collisions is so great that it will overshadow all other forces acting on the balls at the moment of impact at least. friction can easily be applied after collisions in a separate process

Challenge Trophies Won:

Offline Clanky

  • Laser Guided Memories
  • Amiga 1200
  • ****
  • Posts: 340
  • Karma: 16
  • kiss that sound that pounds your senses
    • View Profile
Re: Pool
« Reply #53 on: February 19, 2007 »
Ok! Sounds like a plan!  :inspired:
Looks like your  :stirrer: something really good up Rain... all the best
He tilts, and his eyes are focused on the ground far below.. Wind? Angels? Men..

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Pool
« Reply #54 on: February 19, 2007 »
Hey guys I have come accross the perfect algorithm ( you have to register an account) that addresses all of the short comings that my own collisions fail to incorporate. But there is one thing that I cant figure out. I need to calculate the angle between two vectors by using the dot product and I am not familiar with the process involved. This is the best I can come up with ...

Code: [Select]
  dot_product = (cosine_a*cosine_b + sine_a*sine_b)

  angle = acos(dot_product)
  if (cos(angle > 0) then
    rem both balls are heading towards each other
  fi

is that right? I cant get the angle returned to tell me if the balls are heading towards each other. this algorithm is far superior in that balls can travel at any speed and this is the only part that I cant understand. all the rest makes perfect sense to me. also this algorithm will always strike the nearest ball at the correct place and time something my own collisions can only achieve through trial and error (and a lot of rewinding)

Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: Pool
« Reply #55 on: February 19, 2007 »
Looks ok but you don't need to change to the angle and back again and i think it should be < 0

dot_product = (cosine_a*cosine_b + sine_a*sine_b)
if (dot_product < 0) then
    rem both balls are heading towards each other
  fi

Offline rdc

  • Pentium
  • *****
  • Posts: 1495
  • Karma: 140
  • Yes, it is me.
    • View Profile
    • Clark Productions
Re: Pool
« Reply #56 on: February 19, 2007 »
Her is a good explanation of a dot product:

http://freespace.virgin.net/hugo.elias/routines/r_dot.htm


Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Pool
« Reply #57 on: February 19, 2007 »
Thanks rdc thats gettin bookmarked really clear and shows how to do it in 3D as well  :D

Challenge Trophies Won:

Offline Clanky

  • Laser Guided Memories
  • Amiga 1200
  • ****
  • Posts: 340
  • Karma: 16
  • kiss that sound that pounds your senses
    • View Profile
Re: Pool
« Reply #58 on: February 20, 2007 »
Sounds like this project just got a kick in the butt!
Hope all is going well Rain, I'm looking forward to seeing this project complete, your name has 30+ karma written on it haha
 :updance: :2funny:
He tilts, and his eyes are focused on the ground far below.. Wind? Angels? Men..

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Pool
« Reply #59 on: February 20, 2007 »
Hope it works out like it should and nothin goes against us, I have also been lookin into A.I. routine based on calculating distance and the angle between white ball, colour ball and pocket but I think that kind of thing may be too hard to get workin, but who knows at this stage. thank god there has been a lot of help with this game. Big thanks guys :cheers:

Challenge Trophies Won: