HI there,

i made this 3D pool game/simulator for a physics competition a month ago and thought i might share the results. I got second place btw

This version is the playable one, the other (even more physics) only works if you are ready to play at 10000x slow motion.

It takes everything (almost) conceivable in to account including:

friction,collisions,spin,collision imparted spin,wall bounce dampening,wall imparted spin, non linear friction,table imparted spin, etc...

the advanced physics allow for realistic (and unrealistic) side english shots, backspin, follow and other pool techniques. The UI is very unfriendly and the playability is not very good either. the GFX is non existen allthough ive made all the models my self

.

with this version, the break shot does not work ideally to avoid the simulation from exploding.

controlls:

WASD for camera

hold space to rotate camera

press enter to start shooting

press enter again when you have an aproximate aim to enter aiming mode

press leftmouse to shoot

if you get a freeball (whatever the whiteball gets in a hole or you hit the wrong ball) press enter to place, navigate using the minimap

and yeah very user-unfriendly.

press F1,F2,F3 to hide physics related grahps

thanks

the game is in the attached .rar

for the physics oriented, the yellow vectors on the balls are their spin (w) and the green one is velocity (v) the graph shows the cue balls w and v and their respective derivatives if i recall

t# = timeofimpact(b(i).p,b(j).p,b(i).v,b(j).v,radius#) ` time that has passed since the impact (seconds)
t#(cols) = t#
addvec2(b(i).tp,b(i).p,b(i).v,v3,t#) ` old position at the collision time
addvec2(b(j).tp,b(j).p,b(j).v,v3,t#) ` same for the other ball
subtract vector3 n,b(i).tp,b(j).tp ` vector that from centers of the balls to each other (normal)
scale vector3 r1,n,-0.5 : scale vector3 r2,n,0.5 ` vectors from ball centers to the point of collision
vectorproject(b(i).v,n,vnorm1) ` stores the vector projection of ball(i)s velocity on the normal in vector v2
vectorproject(b(j).v,n,vnorm2) ` same for ball(j) in vector v3
dvn# = length vector3(vnorm1)+length vector3(vnorm2) ` change in momentum
bt# = collisionmod#/(dvn#^(0.2)) ` collision duration
subtract vector3 vtan1,vnorm1,b(i).v : subtract vector3 vtan2,vnorm2,b(j).v ` tangential velocities
add vector3 b(i).tv,b(i).tv,vnorm2 : subtract vector3 b(i).tv,b(i).tv,vnorm1 ` adds v3 to ball(i)s velocity and subtracts v2 from it
add vector3 b(j).tv,b(j).tv,vnorm1 : subtract vector3 b(j).tv,b(j).tv,vnorm2 ` vice versa
addvec2(b(i).tp,b(i).tp,b(i).tv,v3,-t#) : addvec2(b(j).tp,b(j).tp,b(j).tv,v3,-t#) ` move the balls "back" to their "current" place so they wont loose time
cross product vector3 v4,r1,b(i).w ` perimeter velocities due to rotation
cross product vector3 v5,r2,b(j).w ` ...
subtract vector3 vpr,v4,v5 ` relative to the other ball
konst# = (mu_b#*mass#*dvn#)/bt# ` Fu = (-u*m*dvn)/dt (Vpr+Vt)/|Vpr+Vt|
add vector3 v4,vpr,vtan1 : subtract vector3 v5,vtan2,vpr ` ...
normalize vector3 v4,v4 : normalize vector3 v5,v5 ` ...
scale vector3 fu1,v4,konst# : scale vector3 fu2,v5,konst# ` ...
konst2# = bt#/I# ` dt/inertia
cross product vector3 v2,r1,fu1 : cross product vector3 v3,r2,fu2 ` momentarm (svenska)
multiply vector3 v2,konst2# : multiply vector3 v3,konst2#*impartedspin# `...
add vector3 b(i).tw,b(i).tw,v2 : add vector3 b(j).tw,b(j).tw,v3 ` apply the dW
bt#(cols) = bt#

the above is the playable analytical solver for the collisions

subtract vector3 n,b(i).p,b(j).p : nl# = length vector3(n)
vectorproject(b(i).v,n,v2) : subtract vector3 vtan1,b(i).v,v2
vectorproject(b(j).v,n,v2) : subtract vector3 vtan2,b(j).v,v2
vn# = (abs(dot product vector3(b(i).v,n))+abs(dot product vector3(b(j).v,n)))/nl#
normalize vector3 v3,n : multiply vector3 v3,radius# : multiply vector3 n,0.5 : subtract vector3 v3,v3,n
scale vector3 v4,v3,(dt#*k#)*(vn#^0.2)
add vector3 b(i).tv,b(i).tv,v4 : subtract vector3 b(j).tv,b(j).tv,v4
cross product vector3 v6,n,b(i).w : add vector3 v6,v6,vtan1
cross product vector3 v7,n,b(j).w : add vector3 v7,v7,vtan2
subtract vector3 v3,v6,v7 : normalize vector3 v3,v3
scale vector3 fu1,v3,(length vector3(v4)*mass#*mu_b#)/dt#
cross product vector3 fu2,n,fu1
scale vector3 v1,fu2,dt#/I#
add vector3 b(i).tw,b(i).tw,v1 : subtract vector3 b(j).tw,b(j).tw,v1

teh above is the real life solver, real physics is usually much simpler as is apparent

. it uses springs, the k value is 3.81...x10^8 if i recall and that is the reason it has to be calculated a couple of million times per second get good results in high velocity collisions

[1024x768 version a couple of posts down]