--- amcviewer.py	Wed Feb  2 17:12:10 2005
+++ amcviewer_new.py	Wed Feb  2 23:49:58 2005
@@ -7,9 +7,9 @@
 ########################################################################################################
 
 def usage():
-  errorexit("Usage: ppython amcviewer.py file.amc")
+  errorexit("Usage: ppython amcviewer.py 0/1 file.amc")
 
-if (len(sys.argv) != 2): usage()
+if (len(sys.argv) != 3): usage()
 
 woman = mocapActor("woman42")
 woman.reparentTo(render)
@@ -37,7 +37,7 @@
 #base.camera.setPos(-8,-20,8)
 #base.camera.lookAt(0.0,0.0,3.0)
 
-allframes = readMocapFile(sys.argv[1])
+allframes = readMocapFile(sys.argv[2])
 
 # start at first frame
 woman.applyMocapFrame(allframes[0])
@@ -99,5 +99,51 @@
       taskMgr.remove("playLoop")
 
 kpress = keyboardPress()
+
+# (floor_x_amc,floor_z_amc) gives you the path in the coordinate system corresponding to the data in the amc files
+# floor_y_amc is not necessary
+
+class mousePress(DirectObject.DirectObject):
+  def __init__(self):
+    self.accept('mouse1',self.mouse_left)
+    self.accept('mouse1-up',self.mouse_left_up)
+
+  def mouse_left(self):
+    def playLoopMouse(task):
+      if base.mouseWatcherNode.hasMouse():
+	fov = base.camNode.getLens().getFov()
+	aspect = base.camNode.getLens().getAspectRatio()
+        screen_x = base.mouseWatcherNode.getMouseX() * aspect
+        screen_y = base.mouseWatcherNode.getMouseY()
+	screen_z = 1.0 / math.tan(fov.getY()*0.5*(math.pi/180.0))
+	cam_mat = base.camera.getMat()
+	vec_0 = cam_mat.getRow3(0)
+	vec_1 = cam_mat.getRow3(1)
+	vec_2 = cam_mat.getRow3(2)
+	ray = vec_0 * screen_x + vec_2 * screen_y + vec_1 * screen_z
+
+	# -0.3 is hardcoded above for the floor's position
+	# if you change that, you need to change it here too
+	k = (-0.3-base.camera.getZ()) / ray.getZ()
+	floor_x_panda = base.camera.getX() + ray.getX() * k
+	floor_y_panda = base.camera.getY() + ray.getY() * k
+	floor_z_panda = -0.3
+
+	sphere = loader.loadModelCopy("sphere")
+	sphere.reparentTo(render)
+	sphere.setScale(0.1)
+	sphere.setPos(floor_x_panda,floor_y_panda,floor_z_panda)
+
+        floor_x_amc = 5.0 * floor_x_panda
+        floor_z_amc = -5.0 * floor_y_panda
+#        print ("floor_x_amc "+str(floor_x_amc)+"   floor_z_amc "+str(floor_z_amc))
+      return Task.cont
+    taskMgr.add(playLoopMouse,"playLoopMouse")
+
+  def mouse_left_up(self):
+    taskMgr.remove("playLoopMouse")
+
+if (int(sys.argv[1]) == 1):
+  mpress = mousePress()
 
 run()
