On 9/8/06, Alan
Harris <[EMAIL PROTECTED]>
wrote:
Thanks - using the correct
node did the trick.
I am, however, completely baffled by the coordinates for the TexGen.
glTexGen (and hence osg::TexGen) takes you vertex data and multiplies
it be a tex gen matrix to produce texture coordinates. The TexGen
bascially specifies this matrix, by specifying the 4 Vec4 planes that
compose this matrix. There are also two forms of TexGen:
EYE_LINEAR one that premultilies the texgen matrix by the inverse
modelview matrix
OBJECT_LINEAR just uses the planes you specify directly.
For this type of work you'll want to use EYE_LINEAR TexGen, and because
its dependent on the view matrix that value of the view matrix
effectively positions it in space, and this modelview dependency also
means that the OSG has to treat it differently than normal OpenGL
state, and does so by having these TexGen state attributes attached to
a TexGenNode, and the OSG spots these special nodes during the cull
traversal and uses this to position them in right place (
i.e. with the modelview matrix that in accumulated down to the
TexGenNode.)
Ok. Perhaps this was a little more than you wanted to know, its happens
to be one of the more non intuitive parts of OpenGL and the by
consequence the OSG so don't be too worried if it doesn't automatically
make sense. Work at it though, eventually things should fall in place.
The following is a code
snippet. The terrain coords are the standard
-100 to 100 in both directions as used in the osgSpotlight example. In
order to get the region covered by the texture to go from -50 to +50,
the specification to ortho needs to be -150 to +50!!!
To get -100 to +100 it needs to be -300 to -100. The difference gives
the width and the mean gives the left/bottom edge.
this gives a texture from -50 to +50
double left = -150.0;
double right = 50.0;
double bottom = -150.0;
double top = 50.0;
double znear = -1.0;
double zfar = 1.0;
texgen->setPlanesFromMatrix(osg::Matrixd::lookAt(position,
position+direction, up)*
osg::Matrixd::ortho(left,right,bottom,top,znear,zfar));
I'm a little lost in a quick read through, so I'll add that what you
are doing here is to set the same matrix in the TexGen as was used to
capture the shadow, the idea being that you are effectively reversing
the process.
The only thing to note is that tex coords go from 0 to 1, while the eye
coordinates (what everything is projected in to) is in non dimensional
clip space which goes from -1 to 1, so you'll need an extra matrix
multiplation in the maths you pass to texgen. Have a look at the
osgshadowtexture example and you should spot this extra multiplication.
So I suppose the first question is:
am I using the correct method/matrices in order to get an exact
geometry as specified in plan view.
and secondly
am I using them correctly.
I expect not. The answers may well be in the OpenGL refs, but am I away
from my books at the moment. Thanks for any help.