PDA

View Full Version : Create image directly in front of head


Notch
01-10-2014, 02:43 AM
I'd like to create a vision-occluding polygon that hangs directly in front of the virtual user's head. I need to be able to manipulate the position of this polygon, so that it covers different parts of the view depending on where I move it. By default, it will cover exactly half of the view.

I've managed to generate a polygon that is head-attached, but it seems to hang directly through the centre of the "eyes", such that the player can see through the plane. In other words, the plane does not occlude the view, but can be seen if you look around.

How can I code this plane to sit slightly further forwards, so that it obscures the view of the world? Here's what I'm using at the moment ('scotoma.png' is simply a 128x128 coloured square):

scotoma = viz.addTexture('scotoma.png')
quad = viz.addTexQuad(parent=viz.HEAD, texture=scotoma,size=50)

I've tried using the following to manipulate the position of the polygon:

quad.setPosition(quad.getPosition() + [0, 10, 0])

... But it doesn't seem to shift the polygon at all.

Any ideas? It's important that the polygon is head-relative, as I need to shift it around a little bit from time to time.

Any help would be greatly appreciated.

Erikvdb
01-10-2014, 01:09 PM
I've tried using the following to manipulate the position of the polygon:

quad.setPosition(quad.getPosition() + [0, 10, 0])
In python, [x,y,z] + [a,b,c] actually gives you [x,y,z,a,b,c], so no wonder that doesn't work. The solution is actually much simpler. Since the quad is parented to the head, setPosition defaults to relative translation. In other words, you can simply say:

quad = viz.addTexQuad(parent=viz.HEAD, size=1)
quad.color(1,0,0)
quad.setPosition([0,0,10])
This places a red quad of 1x1 meter 10 meters in front of your view. Change size and position (and color/texture) as you see fit.

Notch
01-14-2014, 07:17 AM
Many thanks - works perfectly :)