world object location to screen space transform?

All about the core api and animation, input, sound, effect, collision and physics engines.
You can also post here your feature requests.

Moderator: Brume Dev Team

world object location to screen space transform?

Postby jeskeca on Wed Apr 09, 2008 11:26 pm

How do I get the screen X/Y location for an object position?

I would like to put up HUD "target indicators" that are drawn in HUD_PROJECTION but are placed on the screen to fit over an object position. I don't simply want them billboarded, as I want them to be constant size in the view.

My current strategy was to compute the screen X/Y projection of an object position, and use this to set the X/Y position of a HUD_PROJECTION element. However, I have only limited understanding of how the rendering/camera transform works. I tried to mirror what I see in BrumeMesh ComputeScreenQuad/ComputePoint to compute a screen-space X/Y, but either that's the wrong thing to do, or I'm doing something wrong.

I considered using billboarding and figuring out how to set the size of the billboard based on the object position so the billboard would stay constant-size in screen-space. I would also like to know how to do this, as it will allow me to make target indicators that are constant size but properly occluded by world-objects.
jeskeca
Brume Rookie
 
Posts: 17
Joined: Wed Apr 02, 2008 4:52 pm

Re: world object location to screen space transform?

Postby jeskeca on Thu Apr 10, 2008 12:53 am

Exciting, I was able to answer my first question by inverting the transform in the mouse ray-casting code.

This code seems to transform obj's position into screen/HUD coordinates...

Code: Select all
// compute camera coordinate for model
BrumeMatrix camLocal = brume.ActiveCamera.ViewMatrix *
             brume.ActiveCamera.ComputeProjection(BrumeRenderParams.PERSPECTIVE_DEFAULT);
BrumeVector newPos = BrumeVector.Transform(obj.Pos, camLocal);

// newPos is in -1 < x < 1 viewport space, convert to HUD coordinates,
// casting to an int removes the sub-pixel precision which we don't want for HUD textures
this.Pos.X = (float)  (int)(newPos.X * brume.BrumeWidth/2);
this.Pos.Y = (float) (int)(newPos.Y * brume.BrumeHeight/2)


Now I've been thinking about the "screen-sized" billboards, and it seems like it would be better to do that by handling it in the rendering code size transform than by calculating the necessary size to make the distant object translate to a fixed screen-size. Am i right in thinking this?
jeskeca
Brume Rookie
 
Posts: 17
Joined: Wed Apr 02, 2008 4:52 pm

Re: world object location to screen space transform?

Postby Silmaryls on Mon May 19, 2008 8:17 pm

Well I think it would be nice to have that feature into rendering code for ease of use.
But as the feature will not be available soon you can start with computing the size for the moment.
User avatar
Silmaryls
Brume Team Member
 
Posts: 340
Joined: Tue Feb 21, 2006 10:09 pm
Location: Paris - France


Return to Technical discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron