Render model with constant screen size

Started by
6 comments, last by MHGameWork 15 years, 5 months ago
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?
----------------Don't play games, create them!The Wizards
Advertisement
I'm trying to do the exact same thing, so hopefully someone knows :)
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?
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,
----------------Don't play games, create them!The Wizards
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.



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
----------------Don't play games, create them!The Wizards
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 ;)

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
----------------Don't play games, create them!The Wizards

This topic is closed to new replies.

Advertisement