WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 01-27-2009, 09:42 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
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

Code:
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)
Reply With Quote
  #2  
Old 05-11-2010, 11:20 PM
Darkmax Darkmax is offline
Member
 
Join Date: Feb 2010
Posts: 108
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
Reply With Quote
  #3  
Old 05-13-2010, 12:32 PM
JimC JimC is offline
Member
 
Join Date: Jun 2009
Posts: 42
Have you tried passing all=True to viz.intersect()?
Reply With Quote
  #4  
Old 05-13-2010, 08:23 PM
Darkmax Darkmax is offline
Member
 
Join Date: Feb 2010
Posts: 108
Cool

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
Reply With Quote
  #5  
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
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange Wii Mote error... shivanangel Vizard 8 02-18-2009 12:32 PM
vizinfo + wiimote ? djdesmangles Vizard 6 10-22-2008 02:18 PM
Sending sound to Wiimote ? djdesmangles Vizard 1 07-31-2008 11:26 AM
wiimote and sensor bar masaki Vizard 1 03-06-2008 03:07 PM


All times are GMT -7. The time now is 03:36 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC