How do online pool/billard games have 3D balls?

I know they must have like 50 different angles of the ball for its position but does anybody know EXACTLY how they do it ? im looking to do something similar.

Here is an example of what i mean.

Its only a 2D game but when the balls are hit they dont just move flat they roll asif they would in real life/3D

Thanks!

Moved to Newless Cluebies and duplicate topic deleted.

Please only put a post once.

The effects in that link you provided appear to just be smart use of a sprite sheet. All you’d need would be about 32 different shots of the ball from different rotations, then calculate the actual rotation to apply to the sprite. I admit it would take a lot of tweaking to get it working as nice as they had it working in that video, but the actual process of doing so is not complicated.

I would personally just use 3D balls - that would make life a lot easier.

Sorry about double post, i thought both categorys fitted.

What do you mean just use 3D balls? can they be used in 2D pool games because thats what were looking to make but with rolling balls obviously

Cheers.

Just draw a sphere on top of your pool table. There are plenty of games that have 3D objects on top of 2D sprites. You’ll need to use Java3D or OpenGL or something like that, though.

Even with a sphere your balls might not look quite right unless you implement spin on the ball, if only for aesthetics.

Thanks for the replies. Basically im trying to create something like this http://www.funkypool.com/ If you just click play it loads up. Its a 2D pool game with rotating balls i doubt them use sprite sheet because they are perfect.

Would Java3D be the best way to achieve this if this is the way? Getting 3D balls is not the problem its just the method behind it because ive never seen anything like it before.

Thanks!

I was investigating how to do this recently too, as am writing my own java pool game. What makes you think you can’t use spritesheets as Demonpants suggested? I was going to use this method too for my game. Basically for each ball generate a sprite sheet with all the different angles (the rotations/spin you can do in code).

A few ways to do this… GIMP (loads of tutorials on the net how to create 3D Pool Balls, however will take f’in ages getting all the angles for each ball colour etc)… Generate sprite sheet using code, either Java2D or Java3D. Generating SpriteSheets in Java2D is really easy, however for 3D balls with lighting/numbers etc… may be tricky (didnt manage to find good tutorial, although still probably doable)… So personally will probably try and generate then with Java3D… Should be doable juding by the Java3D tutorials I have seen!. (eg. http://www.java2s.com/Code/Java/3D/AredsphereusingtheSphereutilityclass.htm)

Given that steveyO has actually tried implementing this in code and I’m only speculating, he’d definitely be a better person to listen to. :slight_smile:

Yea thats my only problem its impossible to get EVERY angle of a pool ball using a sprite sheet and probably wouldnt be worth it. Funkypool must use something which allows them to import their 3D balls from photoshop or other 3D problems. Its just a case of finding out what.

FunkyPool supports angular velocity since their GUI lets you give the ball “english” (hitting off center). They are definitely rendering 3D balls. There is no special tools they are using, just textured spheres.

Using sprite sheets you’d be faking it. You’d have one animation of a ball rolling for each numbered ball. You’d rotate the animation based on the direction the ball was traveling. You don’t need every possible angle of the ball.

Again, unless you are simulating the ball’s rotation, you’ll be faking the ball rolling even if you are using 3D.

Yeah, as Nate said, you’re faking it either way. With a sprite sheet, you only need to fake enough rotations to where it gets to the point that it’s not noticeable for the player anymore - probably like 32 or 64 frames per ball.

You’ll need to use Java3D or OpenGL or something like that, though.

jPCT would be a good choice.

Ok thanks for the replies ill look into all methods does anybody have an example of a pool ball sprite sheet with all the diff angles of a ball on ?

Thanks

Hey guys, weve chosen to go the openGL, java way.

Im stuck for choice with these two, has anybody used either of them ? or know about them?

www.lwjgl.org

www.jpct.net

http://kenai.com/projects/jogl/pages/Home

I would personally try to do this in Java2D, OpenGL support is a pain. I would go for a sort of ray-tracing approach. This was done totally in 2D, using an elliptic lens distorted texture.

You could regenerated the image for every rotated ball every frame using a intelligently chosen texture and the right transform.

I am also looking to this. One way suggested was BufferedImage and editing it this way. But it seems a lot of work.

This it the best sprite sheet I could find to illustrate what they are talking about above.

I would imagine you would create a sprite sheet similar to this for each ball with a 3d modeler program by running the models threw a script.

[quote]I would personally try to do this in Java2D, OpenGL support is a pain. I would go for a sort of ray-tracing approach. This was done totally in 2D, using an elliptic lens distorted texture.
[/quote]
Actually, I was looking at the code on your website a couple of weeks ago when I was investigating how to do this myself… Unfortunately, was a bit too complex for my simple mind, but if the lighting could be done in Java2D then obviously would be fantastic and loads easier than Java3D…

This is something I put together tonight in Java2D to give you an idea. (36K at the moment, a proper sprite should should be less than 100K would guess).
http://www.bullsquared.com/pool/spriteSheet.png
All the balls are just drawn with g.drawOval(…)… (Of course anti-aliasing turned on). I am creating a texture with the numbers and circles (TexturePaint tp, and g.setPaint(tp) etc…)… I reckon I could fudge the number ovals and number text to make it look like they are spherical… Of course I have missed all the vertical rotations for the striped balls too (I think that covers every angle??).

If anyone has any easy to understand links on how to make these 3D Looking (using Java2D) then let me know and will fix and post the code. The ball shadows can easily be created using a seperate image… Wont really be spending any more time on this till March, other game to finish before I do my pool game.

As I said Java2D (source included):

http://angryoctopus.co.nz/java4k/pool.png

Source uses Quaternions for rotation, let me know if you have any questions.

Note: Nerd Sniping not appreciated, on the plus side, new 4K idea!

That’s beauteous. Very well done. :slight_smile: