Billiard game

46 views
Skip to first unread message

อรรถวุฒิ บุตรดี

unread,
May 11, 2016, 2:16:31 PM5/11/16
to pi3d
Hi Paddy and everyone,

I've developed Virtual Realistic Billiard Game by using pi3d for two years. It's not finished yet but I would like to give you playing my game.
I rearrange my code and push my project to Git hub: RaspBilliard. please let me know if you have any problem. If you want to make it to pi3d demo, I will help you.

Thank you


Paddy

unread,
May 12, 2016, 1:05:01 PM5/12/16
to pi3d
Hi thanks for making this available. I will be away for a while so can't try it out till I get back looking forward to it.

Paddy

unread,
May 25, 2016, 5:55:25 PM5/25/16
to pi3d
Hi, back now. Just had a quick look at your game - it seems fantastically detailed. I tried running it on a linux laptop and found that the cython stuff wasn't compiled. When I looked at the code it seemed to be just used for finding roots of polynomials so I tried using numpy.roots() (and taking the first real root) did you try that first? Anyway I couldn't get any of the collisions to work (apart from on one occasion with another ball) so maybe I'll have to try and figure out what it's all doing!!

Also the menu.py didn't do anything once I made the final selection. Is it supposed to run main?

Paddy

unread,
May 26, 2016, 4:43:27 AM5/26/16
to pi3d
OK so after looking at QuadRootsRevG.cpp I see your cython functions return the smallest, positive real root else return -31.0

I think this does the same thing. For many things numpy will be FASTER than cython or even C. Also using this function should enable you to simplify the conditional calls (if x4:... elif x3 etc)

def solve_polynomial(p):
 
''' p is array of polynomial coefficients
  '''

  r
= np.roots(p)
  real_pos
= r[(r.imag == 0.0j) & (r.real >= 0.0)]
 
return real_pos.real.min() if len(real_pos) > 0 else -31.0 # no real positive roots, ho-hum


I'm not sure if I'm doing something wrong but when coloured balls go in a pocket they just stick there, when the cue balls goes in a pocket it drops to the floor. Subsequent strokes put the ball back on the table but the F line drawing stays on the floor and although the cue ball bounces off the cushions it doesn't hit other balls. I suppose you just have to make sure you don't pot the cue ball - like in the real game!

It might be nicer with 'tweening' for the camera movement. i.e. it moves towards the target camera position as if drawn by elastic rather than the rigid sudden movement.

Not sure about the rendering of the table and balls. I notice that you use mat_reflect but don't supply a reflection or bump (normal) map or specify bump repeat and shiny coeff. I will look at this and get back to you.

All in all it looks to be quite excellent (but undeniably very complicated!)

Paddy

Paddy

unread,
May 26, 2016, 12:23:08 PM5/26/16
to pi3d
I moved the light direction so it pointed down (-ve y component) and used set_normal_shine() on the table and balls but I couldn't get the balls to render properly. Eventually I got it working better when I got blender to generate UV mapping more along the lines of cylindrical projection. Still not really working properly but looks much nicer (actually might as well use mat_light for all the reflection that's going on). Also I made the ball creation function actually use the light if passed as an argument (which it is)

It might be nicer with shadow casting but it does create extra work each frame.

pool_pic.jpg

Paddy

unread,
May 26, 2016, 6:14:32 PM5/26/16
to pi3d
OK the mat_reflect issue was actually fixed by using is_uv
ball_obj.ball_model.set_normal_shine(Normtex, 0.0, Shinetex, 0.1, is_uv=False, bump_factor=0.0)
Rather than proper shadow casting it's much easier and quick to use an ImageSprite with rx=90. The y positions should be set so the first to be draw is lowest and subsequent ones marginally above it, otherwise there are problems with blending and depth z fighting (as visible below).

youtube video here

อรรถวุฒิ บุตรดี

unread,
Jun 7, 2016, 2:43:11 AM6/7/16
to pi3d
Hi Paddy,

Sorry for late reply, this topic didn't send me the email notification when you replied it.
You made it very really nice :).  I accept that I know nothing about graphic (I just try to use it).
I will collect your advice and update my code, and will make the 2 versions for Numpy and Cython version. Numpy version will be used when your machine cannot compile Cython. As I remember, I use Numpy on my windows7, it take about 1.2 seconds, but the Cython only use 0.32 seconds for the break shot.

อรรถวุฒิ บุตรดี

unread,
Jun 7, 2016, 11:00:11 AM6/7/16
to pi3d
Hi Paddy,

I have play your https://github.com/paddywwoof/RaspBilliard. It is very nice graphic :)

Known issues

  • when cue ball goes into pocket its trajectory moves to floor level so it no longer interacts with other balls and the trajectory line is drawn on the floor
  • Actually it's not issue. Because my game has not support for the rules yet. It's now just show about the physics. And I plan to code the rule of game (8 balls, 9 balls, snooker), multiplayer to play it with your friend, and AI to play with computer. So the plan is designed follow the menu.py


When I run on windows with my home computer. The time for calculation for break shot is as below. 
(Cue_Velo=40, Cue_Angle=0, no any spin, and then please press 'F' on your keyboard)
1. Cython -> Time for calculation=0.31 sec
2. Numpy > Time for calculation=1.45 sec (raspberry pi2 will use more than 10 seconds)

I've never test the Cython version on Raspberry Pi yet, but I will test it (if it can compile Cython code). and let you know the result.

Could you please develop the project with me? I already send you for collaborator (https://github.com/paddywwoof).
You make my project very nice and I need your help. Please make my repository for the nice graphic... please.

Reply all
Reply to author
Forward
0 new messages