开发者

XNA 3D Camera & Billboard Camera Facing Rotation

Please can you help me with the following questions?

  1. How do I rotate (about the Z axis) a camera position around a 开发者_开发知识库Vector3 as pivot?
  2. How do I rotate (about the Z axis) a quad object positioned in front of that camera and make sure that the quad always faces the camera around the same Vector3 pivot?

The picture to explain it is below:

XNA 3D Camera & Billboard Camera Facing Rotation

Please kindly answer, thank you


Note that XNA has a helper for this Matrix.CreateBillboard(...), although if you have access to the camera matrix it is probably simpler to do the following:

        var billboardWorld = Matrix.Invert(camera.ViewMatrix);
        billboardWorld.Translation = billboardPosition;


In addition to rotating the camera around that vector3 point, you can also use that as the target that the camera is looking at. Then you only need to transform the camera's position around that point. It appears that the up vector for making the camera will always stay the same. You mention the Z axis but XNA is a Y-up system so from your image you would perform rotations about the Y axis.

Vector3 pivotPoint = new Vector3(?, ?, ?);
cameraPosition = Vector3.Transform(cameraPosition - pivotPoint, Matrix.CreateRotationY(anglePerFrame)) + pivotPoint;
View = Matrix.CreatLookAt(cameraPosition, pivotPoint, Vector3.Up);

Matrix billboardWorld = Matrix.Identity;
billBoardWorld.Forward = Vector3.Normalize(cameraPosition - pivotPoint);
billboardWorld.Right = Vector3.Normalize(Vector3.Cross(billboardWorld.Forward, Vector3.Up));
billboardWorld.Translation = cameraPosition - (billboardWorld.Backwards * distFromCamera);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜