Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / 3D Theory & Graphics / How to maintain billboard size when camera rotate or zoom ? Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
chmok2

May 20, 2005, 12:12 PM

Hi Everybody,

I met problem.
I have one 3d model (plane) to display on screen. It like GUI have fixed size pixels (e.g. 320 pixels).
Problem: When i rotate/zoom camera, the plane will not maintain fixed size. I use perspective projection on directx and this case cannot use rhw.

How to maintain the plane size ? scaling or other method?

Thanks

Terence

 
Erik Faye-Lund

May 20, 2005, 12:35 PM

how about just calculating the screen space position and drawing the billboard there? then you'll have full control...

 
etienne2005

May 20, 2005, 05:40 PM

---------------------
I met problem.
I have one 3d model (plane) to display on screen. It like GUI have fixed size pixels (e.g. 320 pixels).
Problem: When i rotate/zoom camera, the plane will not maintain fixed size. I use perspective projection on directx and this case cannot use rhw.

How to maintain the plane size ? scaling or other method?
----------------------

You speak of a billboard and then a 3D model...which is it ?
a billboard is 2D and a model is 3D...

When you draw in perspective projection what is far away will
apear smaller and what is near will appear bigger...
So if you ''Zoom'' you get closer and the plane 3d will deform
the nearest side will look bigger then the back
If you rotate the near point look big, the far side look smaller
Perspective projection is in the eye of the person who look...the camera

You may want to use Orthogonal Projection where no matter how ''far''
or ''near'' the object is it will not care about the distance and
the far side of the object will have the same height on screen as
the near parts close to your point of view

You use orthogonal projection
to draw in 2D in front of the 3D perspective world






 
chmok2

May 20, 2005, 07:47 PM

I used 3D Plane model to make billboard. It always face to camera and work fine.
I hope that this billboard can keep constant width size (e.g. 300 pixels) when i rotate/zoom camera.

It like HUD/form control to keep constant size when rotate/zoom camera.
In my case, Game Engine must use perspective projection. I cannot modify it, else render other objects will fail.

I have '3D Plane Model width' and 'expect plane width' (e.g. 300 pixels).
I tried find get two vertex (leftmost vertex, rightmost vertex) from bounding box, and transform them to 2d coordinate/and pixel width. Then I use 'expect plane width' divide 'pixel width' to get scale. But scale is not correct.

pseduocode:
float fscale;
float expectwidth = 300;
D3DXVECTOR leftvertex, rightvertex;
leftvertex = Get_BoundBox(left,top);
rightvertex = Get_BoundBox(right, top);
leftvertex = transform3dto2d(leftvertex);
rightvertex = transform3dto2d(rightvertex);
fscale = expectwidth / distance(leftvertex,rightvertex);
HOWEVER fscale is wrong....

How to solve this problem?
I have view matrix and projection matrix, camera position


Thanks a lot.

Terence

 
Rui Martins

May 23, 2005, 05:02 AM

Maybe I understood you wrong, but if what you want is just a 3D HUD over your scenery, just reset you matrix after drawing your scene, and then draw your HUD with the Identity Matrix.
Or you can scale it according to your viewport dimensions, so that one unit is one pixel or something like that.

 
Erik Faye-Lund

May 23, 2005, 05:59 AM

you are aware that you can use perspective projections for SOME parts of your scene, and not for all, are you?

 
Wernaeh

May 23, 2005, 09:00 AM

Note that you need to be careful with mixing different projections if you want your game to look good even on stereoscopic devices (shutter glasses, etc) =)

Cheers,
- Wernaeh

 
Rui Martins

May 23, 2005, 10:06 AM

Wernaeh wrote: Note that you need to be careful with mixing different projections if you want your game to look good even on stereoscopic devices (shutter glasses, etc) =)


That is only a problem, if your HUD is actually 3D.
If it is a regular 2D HUD, then it works as expected, because it basically is a plane in front of the display, with transparent areas 8).
However if the HUD somehow tries to show depth, it will not work with a orthogonal projection, because stereoscopy requires a Perspective Projection.

 
chmok2

May 23, 2005, 10:26 AM

Thanks all. I solved problem.

I got two vertex (leftmost vertex, rightmost vertex) from bounding box, and transform them to 2d coordinate/and pixel width. Then I use 'expect plane width' divide 'pixel width' to get scale. It work but it has minor problem (not exactly expect size, it will project more few pixels). It is not affect my project.

pseduocode:
float fscale;
float expectwidth = 300;
D3DXVECTOR leftvertex, rightvertex;
D3DMATRIX matBB; //billboard ..face to screen
D3DMATRIX matscale,matworld,mattran;

leftvertex = Get_BoundBox(left,top);
rightvertex = Get_BoundBox(right, top);
leftvertex = (leftvertex+objpos) * matBB;
rightvertex = (rightvertex+objpos) * matBB;
leftvertex = transform3dto2d(leftvertex);
rightvertex = transform3dto2d(rightvertex);
fscale = expectwidth / distance(leftvertex,rightvertex);
//make scale matrix
matscale.identity();
matscale._11=fscale; matscale._22=fscale;matscale._33=fscale;
matworld = matscale * matBB * mattran;
transform(WORLD,matworld)
done!!!..hehe.. Thank a lot.

 
This thread contains 9 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.