WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   need some help with projection (maybe via module projector.py) (https://forum.worldviz.com/showthread.php?t=1746)

michaelrepucci 12-09-2008 12:33 PM

need some help with projection (maybe via module projector.py)
 
Hi Vizards, there doesn't seem to be much help on the projector.py module, just a few examples. This would be enough if I were trying something typical, but, as usual, I'm not. I'm not even sure that I can use projector.py to do this, but here goes.

What I have is an on-the-fly object which is essentially a 2D checkerboard. I would like to position it at some arbitrary angle and point in space, and then project its image onto an invisible surface at some other arbitrary angle and point in space.

For instance, if the checkerboard were slanted by 45 degrees, then projected onto an invisible wall placed between it and the viewer, the viewer would see the same image (it would look like a slanted checkerboard), but the image on the wall would actually be an unslanted, foreshortened checkerboard.

Can I use projector.py to do this, and, if so, how? Or is there some other Vizard tool I can use to do this arbitrary projection? Or will I have to calculate the projection matrix myself and manually adjust all the vertices in the OTF object?

farshizzo 12-17-2008 11:31 AM

The projector module can only project texture objects onto nodes. If you converted the 2D checkerboard object into an image then the projector module should do what you want, unless I'm misunderstanding you.

michaelrepucci 12-17-2008 11:55 AM

I suspected that. Unfortunately there isn't just one checkerboard, there are hundreds of versions, depending on which squares are visible, so that won't be so convenient. (FYI, we're recreating a perceptual stimulus for vision research - see http://www.nature.com/nature/journal.../409085a0.html).

What I've done most recently is to do all the math by hand, finding the intersection of the line between the camera and each point in the checkerboard, and the plane onto which I want the points projected. This seems to "mostly work", aside from some small error that I haven't been able to track down. Gets a little messy since I'm dealing with head-tracking and a PowerWall.

farshizzo 12-17-2008 12:25 PM

Are you dynamically generating the 2D checkerboard nodes? If so, then it shouldn't be that much more difficult to generate them as 2D textures instead. Is there some other requirement that is forcing you to generate the patterns as nodes instead of textures?

michaelrepucci 12-17-2008 12:31 PM

Are you saying I can make on-the-fly textures? That might work. Currently, I generate one 2D checkerboard as a collection of on-the-fly squares, then turn on or off the visibility of the appropriate squares. The only requirement that I can think of is that one a checkerboard is projected onto some plane, it's image must then not change if I move or rotate this plane. It's as if I'm burning the image onto this invisible sheet, which then I use as my new (distorted) checkerboard.

farshizzo 12-17-2008 01:03 PM

Yes, here is an example of how to create a texture on-the-fly and modify the data at runtime.
Code:

import viz
viz.go()

WIDTH = 16
HEIGHT = 16

#Create blank texture
tex = viz.addBlankTexture([WIDTH,HEIGHT])

#Create quad to display texture
quad = viz.addTexQuad(pos=(0,1.8,2),texture=tex)

def SetTextureColors(begin,end):
       
        #Get raw image data buffer
        data = tex.getImageData()

        #Modify image data so it blends from begin to end color
        def getColor(c):
                return [ chr(int(v*255)) for v in c ]

        for y in xrange(HEIGHT):
                for x in xrange(WIDTH):
                        index = y*WIDTH*3 + x*3
                        r,g,b = getColor(vizmat.Interpolate(begin,end,float(x)/WIDTH))
                        data[index] = r
                        data[index+1] = g
                        data[index+2] = b

        #Notify Vizard that texture data has been modified
        tex.hint(viz.TEXTURE_MODIFIED_HINT)

SetTextureColors(viz.WHITE,viz.RED)

#Toggle texture color when space key is pressed
vizact.onkeydown(' ',SetTextureColors,viz.WHITE,vizact.choice([viz.GREEN,viz.BLUE,viz.RED]))

From what you described I don't see why you can't use textures instead of nodes.

michaelrepucci 12-17-2008 01:34 PM

Interesting. I'll play with that and let you know if I have any problems. Thank you!


All times are GMT -7. The time now is 11:20 AM.

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