• Welcome to Dark Bit Factory & Gravity.
 

Pool

Started by Clanky, February 10, 2007

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

Clanky

Wow.. I just needa finish Green Boxcopter - then I have finished a game...
I will do this later, because'a I'm'a tryin' ta mak'a pool game'a.

Basic information:
  There are 15 balls (one black, 7 red, 7 yellow) with one white ball;
  I have the visuals of the table;
  I have set up a check system to see what each balls status is (current position, direction, etc.);
  Hopefully I can be taught how to make circlular collisions with defractions of the balls to the angle where the white ball has hit them.

I have the visuals - like normal I code the easy stuff. I just need to make it so the balls collide and rebound of of each other and stuff like that.
I won't be able to put the code up for awhile because I have it on the other - non internet connected computer.
When I get it on this computer, I will post it. But in the mean time, hopefully someone can give me a low down on making balls collide and rebound and stuff. And to make it so the balls go off on angles porportional to where they have been hit? Dig it??? (Hope so!)
Also, I am having real trouble with the white ball collisions... when I hit it (I have coded a little bit on breaking, with the power of the hit decreasing as it rolls, and decreasing more if it hits a wall), it is hitting the top of the table and turning right? Not suppose to happen as it hasn't hit a side wall yet?
Also, if someone would be kind enough to teach me how to make it so that you can more you 'cue' (I think that's the stick?) around in a circle, and to hit the ball of on an angle?

I will try and get the code up here as soon as I can... most probably tomorrow (hopefully)

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

Jim

Fryer put quite a bit of work into this problem a few years ago.  I don't think we were particularly satisfied with the results.  It's not too bad colliding one ball against another, but when you have a pack of balls it can be very difficult.

Post it up and we can all have a look.

Jim
Challenge Trophies Won:

Shockwave

If you can solve the problems of a game like this Clanky, I will personally give you a +50 Karma boost! Whatever happens, you'll learn a lot from it!! If you manage to impliment top and backspin and sidespin properly I'll boost your Karma by 100.

A great project. I can forsee problems of balls geting stuck inside each other etc... *shudders*
Shockwave ^ Codigos
Challenge Trophies Won:

rdc


rain_storm

#4
I would be delighted to help you on this one, in fact if you dont mind it being a team effort I would be happy to take on half the burden. I have already attempted a pool game not as far as putting backspin on the cue but got all the balls bouncing around correctly things went to pot for me when I thought it would be nice to make it 3D. Anyway I will type my old one out on the PC (its on my memory card atm) if you want a look at the code. I will post it here if you do.

Edit: Pool game attached at last. Graphics are a little modified from Clankys, It was the swept collision between the balls and the walls that held the whole show up, Sorry for the long wait. Thanks to everyone who had helped to make this happen.

Better late than never ;D

Challenge Trophies Won:

Jim

Nice link rdc - in snooker it can be simplified a bit because all the balls are the same size and you can just set both ball masses to 1 and ignore them.

Jim
Challenge Trophies Won:

Clanky

Ok, heres the visual side of the game... I had to make the power and shot code just for this demo - it only goes straight ahead. but, it isn't really calculated at all... it's only the visuals.

Thanx for everything guys.
And I agree, this will be heaps hard... and I did think about having spin and stuff - I will see if i can make it so you have a ball with the position of where the cue will hit the ball on a side panel.

Hopefully this can be a DBF Team Game.
He tilts, and his eyes are focused on the ground far below.. Wind? Angels? Men..

Clanky

Thanx rcd... that page has really inspired me to make this game!
I did year 12 physics, so the momentum aspects of the collisions were a flash back *cries in happyness*... good Mr. Newton with his fundemental law for momentum - "after collision: both balls will have equal magnitude with opposite direction..." or something (and hopefully Mr. Newton's law)
I actually had two books complete on physics - with loads of information about collisions and momenta... but, there gone - bummer!!!
I guess this will be hard...
He tilts, and his eyes are focused on the ground far below.. Wind? Angels? Men..

Stonemonkey

This was as far as I got with this, exe and source for b3d but it doesn't use b3d collisions or anything like that. I never quite worked out the right way of calculating the results of the sphere-sphere collisions but it works fairly well.

http://www.stonemonkie.pwp.blueyonder.co.uk/pool3d_3.zip

Shockwave

Holy shit Fryer! That's mentally good! Check your Karma.
Shockwave ^ Codigos
Challenge Trophies Won:

Paul

#10
I did a simple ball bounce code for a fire demo(haven't posted it because i haven't got any music to go with it). but it doesn't work to well, probably not well enough at all.  :(

the .exe is really nice and works perfectly but the sourcecode freezes







I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won:

Stonemonkey

Sorry about that Paul. atm I don't have b3d installed so i'd probably been messing around with something at the time of working on it. I'll look out something that works.

Stonemonkey

#12
installed b3d but can't work out why it's freezing atm but here's an earlier source, it doesn't have the pockets.

rain_storm

pool3d3 is amazing but I couldnt get pool3d2 to run its says error texture not found or something to that effect but the routines should prove invaluable looks like this little project has generated quite a bit of interest

Challenge Trophies Won:

Stonemonkey

Sorry again, I've added the texture to the above attachment.

rain_storm

its workin perfect now I love the shadows

Challenge Trophies Won:

Clanky

Very nice pool program Stonemonkey! Beautiful... just you can't sink the balls  :( lol


I've got a cue in my program now - copied Jim Shaw's rotation bit out of his Physics Sample. It rotates, but I need some help with creating an angle so the ball moves in the direction the cue is pointing.

Then, some help with making collisions... I tried using the information from the site rdc gave, but it seems YaBASIC doesn't allow normalise() or dotpoint() **or something**

I added really nice shadow effects to the balls today. This was really a nice addition because it gave it a 3D feel to the balls. I also added a spin factor... g2g - lightning comming!! eeee
He tilts, and his eyes are focused on the ground far below.. Wind? Angels? Men..

Jim

Moving a ball in the direction of an arrow:
If a ball is going in direction 'angle' then if you say

xpos = xpos + cos(angle) * speed
ypos = ypos + sin(angle) * speed

that will move it the right way.  In yabasic, angles are in radians.

radians = degrees/180*3.14159

and

degrees = radians*3.14159/180


Normalising a vector:
If you want to make a vector have length 1 (that is, if you apply Pythagoras' Theorem to the x,y,z of the vector it comes out as 1) then you need to say

length = sqr(x*x + y*y + z*z) : rem Pythagoras
x = x / length
y = y / length
z = z / length


Vector dot product:
This calculates the amount of one vector that lies in the direction of another vector.  It's also useful for finding out the angle between two vectors.  If you have two vectors x1,y1,z1 and x2,y2,z2 then

dot = x1 * x2 + y1 * y2 + z1 * z2


If you're working in 2d (like in this pool game) just remove all the z terms from the last 2 equations, ie

length = sqr(x*x + y*y) : rem Pythagoras
x = x / length
y = y / length


dot = x1 * x2 + y1 * y2


Jim
Challenge Trophies Won:

rdc

Useful stuff, Jim.

Paul

the code is working for me now, wonder why it freezed instead of MAV'ing
I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won: