PDA

View Full Version : wiimote


AlyssaK
01-27-2009, 12:24 AM
Hi all,

I'm looking at integrating the wiimote into an environment created in vizard.

I've looked at the documentation in help, still relatively new to python and vizard apologies

I have a few questions, I was previously using viz.pick to find out which object the mouse is pointing towards. I'm now using a pointer as demonstrated in the documentation:

pointer = viz.addTextQuad(viz.SCREEN, texture=viz.add('arrow.tif'))

etc..

I need to select an object how would i achieve this without using viz.pick?

I have thought about using the arrow keys to navigate similar to the below code using the arrow keys of the keyboard
vizact.whilekeydown(viz.KEY_LEFT, viz.rotate, viz.BODY_ORI, -ROTATION_INC, 0, 0)

I have got this far :) thinking of creating a seperate method for each button

vizact.onsensordown(wiimote,wii.BUTTON_LEFT,func,a rgs)

I'm not sure where to go from here.

I look forward to hearing your opinions on how to approach this.

Thanks

Jeff
01-27-2009, 09:42 PM
try using the viz.screentoworld function to get a line that you can use to call viz.intersect. This code should let you know if the pointer is in line with an object

def FireLine():

line = viz.screentoworld(pointer.getPosition())
dir = viz.Vector(line.dir)
dir.setLength(200)
begin = line.begin
end = line.begin + dir
info = viz.intersect(begin,end)
if info.valid:
print "intersected"

vizact.onsensordown(wiimote,wii.BUTTON_B,FireLine)

Darkmax
05-11-2010, 11:20 PM
Hi,
I found this code to implement my cursor with wii in my vr and it works great, but just with the first scene cause, i have 4 world each in a scene and i'm trying to implement this on the four scenes but just its working with the first.

i searched on the documentation and forums, and i cant find how to tell vizard to generate a line on the second world? for example to check if something colliding between the line but on the scene 2 not in the first one

JimC
05-13-2010, 12:32 PM
Have you tried passing all=True to viz.intersect()?

Darkmax
05-13-2010, 08:23 PM
Thanks for your help JimC, but this throws me all the intersections with the line but just in scene 1.

Something that i don't know how to use it because if i print this, is a list with this:
[<viz.Intersect object at 0x02646390>, <viz.Intersect object at 0x026463D0>]

I don't know why to elements if just intersect with one element(maybe cause it was cube,and intersect with to faces of the cube the line), but how i use this information in hexadecimal?

But returning with my original question i found the solution, something that i didn't check before because i was searching the solution on viz.screentoworld but is with <scene>.intersect this check if something intersect on the scene that you specify :D

Darkmax
05-13-2010, 08:40 PM
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


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)