triangle always pointing at the camera

Started by
5 comments, last by Brain 9 years ago

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?

Advertisement

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?

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);


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.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Not sure if I understand correct what you want, but you might look up "billboarding"

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

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.
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

This topic is closed to new replies.

Advertisement