XNA中的摄像机

 

XNA中摄像机是通过ViewProjection来体现的,其中View矩阵用于实现世界坐标到摄像机坐标的转换。Projection是投影矩阵,用于完成摄像机坐标系到屏幕坐标系的转换。根据面向对象的思想及程序重用性和可维护性的需要可以将有关摄像机的操作封装到一个摄像机类中,同时提供第一人称、第三人称摄像机。

1、   View的创建

                    public static Matrix CreateLookAt (
   
   
                                Vector3 cameraPosition,       /* The position of the camera */
   
   
                                Vector3 cameraTarget,         /* The direction that the camera is pointing */
   
   
                                Vector3 cameraUpVector
   
   
               )
               Vector3 cameraUpVector The direction that is "up" from the camera's point of view
  
  

         view = Matrix.CreateLookAt(cameraPosition, cameraLookat, cameraLookUp);

2、   Projection的创建

                    public static Matrix CreatePerspectiveFieldOfView (
   
   
                                         float fieldOfView,                              /*Field of view in radians*/
   
   
                                float aspectRatio,                             /*宽高比*/
   
   
                                float nearPlaneDistance,                /*Distance to the near view plane*/
   
   
                                float farPlaneDistance                                         /*Distance to the far view plane*/
   
   
                    )
   
   

float aspectRatioAspect ratio, defined as view space width divided by height

proj = Matrix.CreatePerspectiveFieldOfView(viewAngle, aspectRatio, nearClip, farClip);

在编程过程中我们需要改变摄像机的位置和摄像机所观察的指向来跟踪物体或者完成第一人称摄像机与第三人称摄像机的切换。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值