Transform object to exact pixel position on screen

Started by
1 comment, last by Evil Steve 13 years, 7 months ago
Hello,
how can i transform/pose an object pixel-exact on screen, for example for an UI-Interface?

I did that with "DeclarationUsage.PositionTransformed", so vertext-position is equal to screen-pixel-position. But the Problem with PositionTransformed is, i can't rotate the object.

Greetings
Advertisement

If you're familiar with picking (selecting 3D objects with your mouse) you could go with a technique akin to that. You unproject your desired screen space coordinates to get a coordinate in world space where you can put your object so it remains in a fixed spot on the screen. You'll have to do this each frame if the camera is moving, but this way you can apply your desired rotation to the object and then translate it to this worldspace coordinate you obtained by unprojecting. This is probably only worth the hassle for real 3D models though (for example previewing an upgrade in your UI); for the 2D UI stuff it might be more useful to turn to sprites.
Rim van Wersch [ MDXInfo ] [ XNAInfo ] [ YouTube ] - Do yourself a favor and bookmark this excellent free online D3D/shader book!
Personally, I'd use an orthographic projection matrix for 2D items. Then you can specify the position of them in any coordinate system you like (E.g. (0, 0) to (width, height)).

This topic is closed to new replies.

Advertisement