from visual import *

print """
Right button drag to rotate "camera" to view scene.
Middle button to drag up or down to zoom in or out.
  On a two-button mouse, middle is left + right.
  On a one-button mouse, middle is CTRL + mouse.
"""

# build the box
side = 4.0
thk = 0.3
s2 = 2*side - thk
s3 = 2*side + thk
wallR = box (pos=( side, 0, 0), length=thk, height=s2,  width=s3,  color = color.red)
wallL = box (pos=(-side, 0, 0), length=thk, height=s2,  width=s3,  color = color.red)
wallB = box (pos=(0, -side, 0), length=s3,  height=thk, width=s3,  color = color.blue)
wallT = box (pos=(0,  side, 0), length=s3,  height=thk, width=s3,  color = color.blue)
wallBK = box(pos=(0, 0, -side), length=s2,  height=s2,  width=thk, color = (0.7,0.7,0.7))

# create the ball
ball = sphere (color = color.green, radius = 0.4)
ball.mass = 1.0
ball.p = vector (-0.15, -0.23, +0.27)

# create the box
box = box (length=1, height=0.33, width=0.66, color = color.yellow)
box.mass = 2.0
box.p = vector (-0.16, -0.21, +0.25)

# create the ellipsoid
ellipsoid = ellipsoid (length=1, height=2, width=3, color=(1,0,1))
ellipsoid.mass = 1.0
ellipsoid.p = vector (-0.14, -0.22, +0.26)

# set up distances from the outer sides of the box that the objects should bounce from
side = side - thk*0.5 - ball.radius
side2 = side - thk*0.5 - box.x
side3 = side - thk*0.5 - ellipsoid.x


dt = 0.5
t=0.0
while 1: #loop inifinately
  rate(100) #ensure that the speed of the loop will be the same across all pc's
  t = t + dt
  #draw all objects in their new posion
  ball.pos = ball.pos + ball.p*(dt/ball.mass)
  box.pos = box.pos + box.p*(dt/box.mass)
  ellipsoid.pos = ellipsoid.pos + ellipsoid.p*(dt/ellipsoid.mass)
  #give the box and ellipsoid somne rotation
  box.rotate(angle=0.0628, axis=( -0.16, -0.21, +0.25))
  ellipsoid.rotate(angle=0.0314, axis=(-0.14, -0.22, +0.26))
  #check if objects are hitting any sides and if so change their direction otherwise continue to move them in thier given paths
  if not (side > ball.x > -side):
    ball.p.x = -ball.p.x
  if not (side > ball.y > -side):
    ball.p.y = -ball.p.y
  if not (side > ball.z > -side):
    ball.p.z = -ball.p.z   
  if not (side2 > box.x > -side2):
    box.p.x = -box.p.x
  if not (side2 > box.y > -side2):
    box.p.y = -box.p.y
  if not (side2 > box.z > -side2):
    box.p.z = -box.p.z
  if not (side3 > ellipsoid.x > -side3):
    ellipsoid.p.x = -ellipsoid.p.x
  if not (side3 > ellipsoid.y > -side3):
    ellipsoid.p.y = -ellipsoid.p.y
  if not (side3 > ellipsoid.z > -side3):
    ellipsoid.p.z = -ellipsoid.p.z



