XNA Billboard sprite to camera plane
I got a camera set up with
_aspectRatio = device.Viewport.Aspe开发者_StackOverflow中文版ctRatio;
_projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(90.0f),_aspectRatio,0.1f,10000.0f);
The view matrix get set with the Update, and the _position is set by a rotation defined in rotation.
private void Update()
{
_viewMatrix = Matrix.CreateLookAt(_position, _lookAt, Vector3.Up);
}
public void Rotate(float angle)
{
rotation += angle;
_position = Vector3.Transform(_position, Matrix.CreateRotationY(angle));
Update();
}
To set the sprite in the field, i use this code:
_effect.Parameters["xWorld"].SetValue(Matrix.CreateRotationY(camera.rotation) * PositionMatrix);
_effect.Parameters["xView"].SetValue(camera.ViewMatrix);
_effect.Parameters["xProjection"].SetValue(camera.ProjectionMatrix);
_effect.Parameters["xTexture"].SetValue(_texture);
It is working, the sprite is looking at the camera perpendiculair with the camera plane. Problems are coming when the camera position vector is changed, the sprite is keeping the initial angle and I don't know where I can calculate the changed Y rotation for the sprite.
The solution was that I took the y rotation in the camera class. In that class I had a method where I could see the y rotation.
精彩评论