WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 03-30-2006, 01:19 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Yes, this is how most people implement crosshairs for stereo viewing. Here is a sample script that will place a crosshair 0.1 meters in front of the user.
Code:
import viz
viz.go(viz.STEREO)

viz.add('tut_ground.wrl')
viz.clearcolor(viz.GRAY)

crosshair = viz.add(viz.TEXQUAD)
crosshair.texture(viz.add('crosshair.png'))
crosshair.scale(0.01,0.01,0.01)

viz.mouse(viz.OFF)

def ontimer(num):
	line = viz.screentoworld(viz.mousepos())
	v = viz.Vector(viz.get(viz.HEAD_POS))
	dir = viz.Vector(line[3:]) - viz.Vector(line[:3])
	dir.normalize()
	dir *= 0.1 #Place crosshair 1/10th meter in front of user
	v += dir
	crosshair.translate(v.get())
	crosshair.rotatequat(viz.get(viz.VIEW_QUAT))
	
viz.callback(viz.TIMER_EVENT,ontimer)
viz.starttimer(0,0,viz.FOREVER)
Reply With Quote
  #2  
Old 04-04-2006, 09:40 AM
betancourtb82 betancourtb82 is offline
Member
 
Join Date: Jan 2006
Posts: 103
Ok, I implemented the crosshair as you said, however I'm still getting an offset between the bullet and the crosshair. Is there anyway to correct this now that I am using the "3d" version of the crosshair? I've attached a copy of the code.
Attached Files
File Type: zip Test2WithEyeAdjustment.zip (3.3 KB, 4141 views)
Reply With Quote
  #3  
Old 04-04-2006, 10:14 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
I tried your script but I didn't see any bullet. I've modified my previous code so that it shoots a bullet from the center of the viewpoint towards the direction of the crosshair. There will always be an apparent offset between the crosshair and the bullet due to binocular vision.
Code:
import viz
viz.go(viz.STEREO)

viz.add('tut_ground.wrl')
viz.clearcolor(viz.GRAY)

crosshair = viz.add(viz.TEXQUAD)
crosshair.texture(viz.add('crosshair.png'))
crosshair.scale(0.01,0.01,0.01)

viz.mouse(viz.OFF)

def ontimer(num):
	line = viz.screentoworld(viz.mousepos())
	v = viz.Vector(viz.get(viz.HEAD_POS))
	dir = viz.Vector(line[3:]) - viz.Vector(line[:3])
	dir.normalize()
	dir *= 0.1 #Place crosshair 1/10th meter in front of user
	v += dir
	crosshair.translate(v.get())
	crosshair.rotatequat(viz.get(viz.VIEW_QUAT))
	
viz.callback(viz.TIMER_EVENT,ontimer)
viz.starttimer(0,0,viz.FOREVER)

bullet = viz.add('white_ball.wrl')

def shoot():
	pos = viz.Vector(viz.get(viz.HEAD_POS))
	dir = viz.Vector(crosshair.get(viz.POSITION)) - pos
	dir.normalize()
	dir *= 10
	bullet.translate(pos.get())
	bullet.goto((pos+dir).get(),3)
vizact.onmousedown(viz.MOUSEBUTTON_LEFT,shoot)
Reply With Quote
  #4  
Old 04-04-2006, 10:46 AM
betancourtb82 betancourtb82 is offline
Member
 
Join Date: Jan 2006
Posts: 103
I apologize. I think I sent you something I was working on earlier but I corrected it. I still get the same behavior. Would you mind taking a look at this one and let me know if there is something wrong? Thanks
Attached Files
File Type: zip (Archived) Test2WithEyeAdjustment.zip (3.4 KB, 3979 views)
Reply With Quote
  #5  
Old 04-04-2006, 11:31 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
In both calls to viz.screentoworld you are adding an offset to the x position. You don't need to do this when using a 3D cursor. Also, after adding the cursor you should disable collisions on it so the bullet does not hit it.
Code:
crosshair.disable(viz.COLLISION)
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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


All times are GMT -7. The time now is 05:59 AM.


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