How undo/disable projection for the GUI only?

Started by
3 comments, last by darkelf2k5 14 years, 11 months ago
Hi, so I'm still using the beloved DirectX sprite interface and and am wondering if there is any standard way of drawing UI elements separate from any view and projection transformations? Notice that for some UI elements, it would be nice to have them located in world space aswell, but not rescaling with camera zoom. My approach was to multiply the inverse view*projection matrix with the worldmatrix of my desired sprite(s), but that produces positions like -50000, whereas it was before situated at ~150/150.

D3DXMATRIX backTransform = d3dManager.getView() * d3dManager.getProjection();
D3DXMatrixInverse(&backTransform,NULL,&backTransform);
guiElement->m_worldMatrix *= backTransform;

In my understanding, that should have cancelled out the view and projection transformations, and leave my sprite at the same world position, but untouched by zooming. Any input or suggestion is very welcome! I'm on the right track, am I not?
Advertisement
Why not set an identity view matrix and use D3DXMatrixOrthoLH for your projection matrix?
Good idea, unfortunately it doesn't work either. I reset the view matrix to identity and reset my projection matrix to Ortho with no zooming right before calling guisprite->Draw();, but then it didnt get rendered at all.
So I removed the view matrix reset and now it gets rendered, at the correct position, but moving or zooming the camera also moves the gui element away from its world position.
edit: actually, If I never zoomed, the whole thing would work right now. I don't quite understand it, just vaguely it makes sense since the view is responsible for the camera position and I need the gui element to be able to move out of sight.

[Edited by - Meai on May 2, 2009 9:49:48 AM]
I have little experience with sprites, and don't know what transforms they do internally, but I suspect it's not straightforward, since they have a center and position in the draw call which must be taken into account. Also, since the sprite interface has its own SetWorldView methods, there's a chance the view and projection you are using aren't the relevant ones.

Also, I'm always suspicious of using the same parameter for input and output, as you do in D3DXMatrixInverse. Might work, but it's a suspect I think is good to eliminate.

I'd suggest first of all that you debug the code and see that you're getting the expected inverse. Then play with a single sprite to see how the transforms affect it. Try to do the transform yourself in code, and see if what you get is similar to what you see.
Quote:Original post by Evil Steve
Why not set an identity view matrix and use D3DXMatrixOrthoLH for your projection matrix?


Depending on the z value of the sprites, you might need to pass a default view mat, say, looking at the origin from (0,0,-1). Identity view paired with all 0 z values will not show IIRC.
Every time you implement a singleton, God kills a kitten. Please, think of the kittens!

This topic is closed to new replies.

Advertisement