gluUnProject is popping entity position

BlitzMax Forums/MiniB3D Module/gluUnProject is popping entity position

AdamRedwoods(Posted 2012) [#1]
I have no idea why gluUnProject is popping my entity (sphere2) when I get my position back and am moving the camera. It pops back when I am stationary.

I have tried my own routine and the glu library, both do the same popping. Any ideas?

Here's the full code


many thanks

Last edited 2012


AdamRedwoods(Posted 2012) [#2]
Solved: when using the camera's proj[] and mod[] matrixes, these are only updated during render (using glGetDouble), so I was getting the correct camera matrix too late.

So I used the internal camera matrix and inversed it to get the modelview matrix.

Local cam_mat:TMatrix = cam.mat.Copy().Inverse()

inv_mat= cam_mat.Inverse()
inv_mat.Multiply(proj_mat.Inverse())
''...etc...


..but this leads to another thought. When converting miniB3D to use openGL2.0, we need the projection matrix internal.
Has anyone done this yet?

Last edited 2012


AdamRedwoods(Posted 2012) [#3]
The above doesn't work. using the camera matrix gets closer, but something is still wrong.

Using this in the main routine shows what is off:
	Local x:Float = MouseX()
	Local y:Float = MouseY()
	
	Local vec:TVector = camUnProject(x,y,0.8, cam.mod_mat, cam.proj_mat, cam.viewport, cam)


	Local vx:Double, vy:Double, vz:Double
	y = TGlobal.height - y
	gluUnProject(x,y,0.8,cam.mod_mat,cam.proj_mat, cam.viewport, Varptr vx, Varptr vy, Varptr vz)


the zdepth input changes the location when drawn. it shouldn't do that, because eventually I need a ray from camera near to camera far planes.

I'm open for suggestions. One thought is I need a complete matrix.Inverse() method.

Last edited 2012


AdamRedwoods(Posted 2012) [#4]
GOT IT!!!!
whew, ugh my brain hurts....

The problem was two-fold:
1. needed the full TMatrix.Inverse() for 4x4 matrix
2. needed the full TMatrix.Translate() for 4x4 matrix
3. then the grid[3][3] can be normalized with the x,y,z result

Thanks to kfprimm for his Matrix.Inverse() through max3d.

Notes on UnProject:
This can be optimized. Not only can the full Inverse() be optimized, but by using the camera's matrix and caching the Projection Matrix inverse, UnProject can be sped up considerably.

final code


Add to TMatrix:


Last edited 2012