Thread: wiimote
View Single Post
  #6  
Old 05-13-2010, 08:40 PM
Darkmax Darkmax is offline
Member
 
Join Date: Feb 2010
Posts: 108
this is a example of the solution if some want to know, i make it without the wiimote because i didn't have my wiimote at the moment

Code:
import viz

viz.go()

#Disable Mouse
viz.mouse.setOverride(viz.ON)

#Add Box at position 0,2,4
box = viz.add("box.wrl")
box.setPosition(0,2,4)

#Add Sphere at position 0.7,2,5
sphere = viz.add("ball.wrl",scene=2)
sphere.setPosition(0.7,2,5)

#2D crosshair
pointer = viz.addTexQuad(viz.SCREEN,texture=viz.addTexture("crosshair.png"))
pointer2 = viz.addTexQuad(viz.SCREEN,texture=viz.addTexture("crosshair.png"),scene=2)

#Move the pointer
def mueveCursor(e):
	pointer.setPosition(e.x,e.y)
	pointer2.setPosition(e.x,e.y)
viz.callback(viz.MOUSE_MOVE_EVENT,mueveCursor)

#Make a line and check intersections
def FireLine():
	line = viz.screentoworld(pointer.getPosition())
	dir = viz.Vector(line.dir)
	dir.setLength(200)
	begin = line.begin
	end = line.begin + dir
	if viz.MainView.getScene() == viz.Scene1:
		info = viz.intersect(begin,end)
	else:
		info = viz.Scene2.intersect(begin,end)

	if info.valid and info.object == box:
		print "intersected with the box"
	elif info.valid and info.object == sphere:
		print "intersected with the sphere"
	else:
		print "not intersected"

vizact.onkeydown(" ",FireLine)

#Change between scenes
def switchScene(key):
	if key is "1":
		viz.scene(1)
	elif key is "2":
		viz.scene(2)
viz.callback(viz.KEYDOWN_EVENT,switchScene)
Reply With Quote