Sign in to follow this  
MHGameWork

Render model with constant screen size

Recommended Posts

I'm writing an world editor. At the moment i have my translation gizmo up and being rendered in my editor. Now i would like it to always appear the same size on the screen, no matter what the distance of the camera is. Of course it should rotate when the camera moves, but the onscreen size should remain thesame. I'm just trying to mimic the gizmo's behaviour like in 3dsmax or other modeling/game software. Can anyone help me out?

Share this post


Link to post
Share on other sites
Never done it before but the reason it changes size based on camera distance is because its drawn with perspective projection.
Can't you drawn the gizmo with orthographic projection and the rest of the scene with perspective as usual?

Share this post


Link to post
Share on other sites
Well, i thought about that, but i think that that only works when the gizmo is at the center of the screen. When the object is for example on the back left of the viewing frustum, isn't the gizmo being clipped out by an orthographic projection?

Anyway, i will give it a try, maybe ill get some clues from what happens.

Thanks anyway,

Share this post


Link to post
Share on other sites
I render my gizmo (or widget I call it) as a bunch of lines centered at the origin or a models origin. Then based on distance (take the distance from camera position to the widgets origin) I scale the widget.

so I have something like.

vector3 cameraPos, widgetPos;

float scale = distance(cameraPos - widgetPos) / 100;

then when drawing.

glScale(scale,scale,scale);

//render the widget now.

seems to work fine, it might not be 100% precise as in the widget may not be the same size at every distance, but its pretty good and works fine for my needs.



Share this post


Link to post
Share on other sites
Quote:
Original post by MHGameWork
now its working perfectly, thanks. Are you sure it is not 100% precise? because to me it seems like it is.

thanks for your help


excellent, well when i say not 100% I cant really tell if the model is precisely the same size when you are further away, it looks fine to the eye though but what I mean was if you zoom out really far it may be slightly smaller by a fractional amount that isn't noticeable. anyway it works fine like you say so we shouldn't worry about it ;)

Share this post


Link to post
Share on other sites
i agree :P. When i was working i made an algoritm to make 2 models on different locations look the same size. Then i simplified it and i got your line of code.

After drawing some viewfrustum i realized that it is the correct method. So it should be the exact same size.

But above all precision issues, it's just extremely simple, and perfect.

Thanks again for your help

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this