Sign in to follow this  
lomateron

triangle always pointing at the camera

Recommended Posts

I can see the triangle in the center of the screen if I don't apply any World,View,Projection matrix

How do I modify the World matrix so that the triangle always points to the camera no matter its location in the world?

Share this post


Link to post
Share on other sites

the normal way of doing this will be creating rotation matrix using the position of the camera and the triangle in the world

but this is not necessary and it produces wrong results too if the camera is too close to the triangle and not looking directly at it.

I think I just have to mod the View matrix?

Share this post


Link to post
Share on other sites

Many people do it the wrong way, even the ones at nvidia doing FleX, when you get very close to a ball, it will kind of "let you pass".

 

solution:

 

if you are using D3DXMatrixLookAtLH in the HLSL code you just need the View matrix data, before applying the world,view,projection matrices do this...

mMatrx[2] = float3(View._13, View._23, View._33);
mMatrx[0] = normalize(cross(float3(0.0f,1.0f,0.0f), mMatrx[2]));
mMatrx[1] = cross(mMatrx[2], mMatrx[0]);

input.Pos.xyz = mul(input.Pos.xyz, mMatrx);
Edited by lomateron

Share this post


Link to post
Share on other sites


so that the triangle always points to the camera


rotation matrix using the position of the camera and the triangle ... it produces wrong results too if the camera is too close to the triangle ... I think I just have to mod the View matrix?

 

If you're using a perspective projection, any object (whatever its distance from the camera) will appear somewhat "distorted" the further away it is from screen center.

 

Can you describe what you mean by "wrong results," and what you want to see that would be "right results"?

 

It you change the view matrix, that will change the camera's position, the camera's view angle, or both. In addition, changing the view matrix instead of the object's world matrix won't make a difference as the object's vertices are multiplied by both matrices in any case.

Share this post


Link to post
Share on other sites
As cozzie said, look up billboarding.

One method is to extract the camera's rotation matrix, invert it, and apply it to the triangle before applying the camera matrix.

Share this post


Link to post
Share on other sites
When you do this most importantly with billboarding it is important to note there is a difference between facing the camera and on a plane parallel with the camera. A triangle facing the camera will look strange (at an angle) if it is over to the left or right of the view or above the camera etc. Using the plane normal usually gives better more expected results.

Have a quick look here too: http://stackoverflow.com/questions/5467007/inverting-rotation-in-3d-to-make-an-object-always-face-the-camera/5487981#5487981

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