WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Outputting modules (https://forum.worldviz.com/showthread.php?t=2522)

just alex 02-16-2010 11:03 AM

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?


All times are GMT -7. The time now is 07:38 AM.

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