# triangle always pointing at the camera

This topic is 1269 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 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 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 on other sites
Not sure if I understand correct what you want, but you might look up "billboarding"

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

1. 1
2. 2
3. 3
4. 4
5. 5
Rutin
11

• 12
• 19
• 10
• 14
• 10
• ### Forum Statistics

• Total Topics
632665
• Total Posts
3007724
• ### Who's Online (See full list)

There are no registered users currently online

×