WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 02-16-2010, 12:03 PM
just alex just alex is offline
Member
 
Join Date: Nov 2008
Posts: 18
Outputting modules

I have a sneaking suspicion that this is really easy, but I'm just not seeing how to do this. I've got a module that's supposed to take the data from my tracker and figure out what my subject is looking at. I'm trying to make this data get written into a data file when my subject collides with an object in the main program. I think the code should look something like
Code:
import viz
import math
import vizmat
import vizinfo
import vizact
from lookingat import LookingAt #the module
viz.go()

#adds the ppt
PORT_PPT = 1
ppt = viz.add('vizppt.dls')

ppt.command(3,"",1,1,5)

PORT_INTERSENSE = 2
isense = viz.add('intersense.dls') 
tracker = viz.add('intersense.dls')
viz.tracker()
tracker.reset()

# open a datafile for recording
subject = viz.input('Subject number:')
filename = 'subject' + str(subject) + '.txt'
datafile = open(filename,'a')

#testing collisions
viz.collision(viz.ON)
view = viz.get(viz.MAIN_VIEWPOINT)
view.rotate(0,1,0,90)

def mycollision(info):
   datafile.write('collision','a')
   datafile.write(str(Lookingat),'a')
   datafile.flush()
   
viz.callback(viz.COLLISION_EVENT, mycollision)
with the lookingat file like this
Code:
######################
## IMPORT LIBRARIES ##
######################

import viz
from math import cos, sin, radians
import vizmat	# library for vector math



####################
## RUNTIME MODULE ##
####################

class LookingAt:
	
	##
	# Constructs a new LookingAt object, which contains a pointer to
	# the client's viz.
	# @param vz: current Vizard instance (just pass in viz)
	#
	def __init__(self, vz):
		self.v = vz
	
	##
	# Calculates a projected point from given viewpoint at the given proximity.
	# @param pos: position of view
	# @param euler: euler coordinates of view orientation
	# @param proximity: distance of projected point from viewpoint
	# @return: Projected point
	#
	def projection(self, pos, euler, proximity):
		theta = radians(euler[0])
		phi = radians(euler[1] + 90)
		xProj = pos[0] + proximity*sin(theta)*sin(phi)
		yProj = pos[1] - proximity*cos(phi)
		zProj = pos[2] + proximity*cos(theta)*sin(phi)
		return [xProj, yProj, zProj]
	
	
	##
	# Finds the point ([X, Y, Z]) on the object the user is looking at.
	# @param v: viz pointer
	# @param proximity: max distance of viewed objects from viewpoint
	# @param objects: OPTIONAL list of objects to restrict intersection to
	# @return: Point on object, or None if not looking at any objects
	#
	def lookingPoint(self, proximity, objects=0):
		pos = self.v.get(viz.HEAD_POS)
		euler = self.v.get(viz.HEAD_EULER)
		proj = self.projection(pos, euler, proximity)
		intersection = self.v.intersect(pos, proj)
		if intersection.valid:
			if (objects == 0):
				return intersection.point
			for object in objects:
				if (intersection.object == object):
					return intersection.point
	
	
	##
	# Finds the closest object the viewer is directly looking at.
	# @param v: viz pointer
	# @param proximity: max distance of viewed objects from viewpoint
	# @return: Object looking at, or None if not looking at any objects
	#
	def lookingObject(self, proximity):
		pos = self.v.get(viz.HEAD_POS)
		euler = self.v.get(viz.HEAD_EULER)
		proj = self.projection(pos, euler, proximity)
		intersection = self.v.intersect(pos, proj)
		if intersection.valid:
			return intersection.object
however, i'm not getting this to work correctly. Am I missing a step in properly importing the lookingat data, or is there an error in the code I'm using to output the collision data?
Reply With Quote
 


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
importing modules from Psychopy starbug Vizard 0 02-08-2010 09:06 AM
Modules / Require / Include function Johannes Vizard 4 04-27-2005 12:12 PM


All times are GMT -7. The time now is 01:47 PM.


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