3d XNA广告牌精灵至摄像机平面
我有一架照相机3d XNA广告牌精灵至摄像机平面,3d,xna,camera,rotation,sprite,3d,Xna,Camera,Rotation,Sprite,我有一架照相机 _aspectRatio = device.Viewport.AspectRatio; _projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(90.0f),_aspectRatio,0.1f,10000.0f); 视图矩阵随更新一起设置,_位置由旋转中定义的旋转设置 private void Update() { _viewMatrix =
_aspectRatio = device.Viewport.AspectRatio;
_projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(90.0f),_aspectRatio,0.1f,10000.0f);
视图矩阵随更新一起设置,_位置由旋转中定义的旋转设置
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();
}
要在字段中设置精灵,我使用以下代码:
_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);
它正在工作,精灵正看着相机与相机平面垂直。当摄影机位置向量发生变化时,会出现问题,精灵保持初始角度,我不知道在哪里可以计算精灵的Y旋转变化。解决方案是我在摄影机类中使用Y旋转。在那门课上,我有一个方法,可以看到y轴旋转
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();
}