zoukankan      html  css  js  c++  java
  • 摄像机旋转

    三维场景中的旋转,是摄像机本身在世界坐标系中绕Y轴进行旋转,从而改变位置,而其他的姿态不变,也就是摄像机的Position向量绕着世界坐标系的Y轴进行旋转。

    三种方式:

    1,采用角度(不通用),此方法适合目标点是世界坐标系原点。

    private float angleFirst = 0;
    private void RotateYFirst(float paAngle)
    {
       //通过角度
       angleFirst += paAngle;
       if (angle > 6.28f)
       {
           angle -= 6.28f;
       }
       camPosition = new Vector3(4 * (float)Math.Cos(angleFirst), 0, 4 * (float)Math.Sin(angleFirst));
       Matrix view = Matrix.LookAtLH(camPosition, camTarget, camUp);
       device.SetTransform(TransformType.View, view);
    }

    2,采用Matrix.RotationY方法对Position向量进行旋转(较为通用)

    //通过世界矩阵的Transform
    private void RotateYSecond(float paAngle)
    {
       //摄像机绕世界坐标系的Y轴进行旋转,摄像机本身的姿态不进行任何改变
       Vector4 tempRotate = Vector3.Transform(
           camPosition, Matrix.RotationY(paAngle));
       camPosition = new Vector3(tempRotate.X, tempRotate.Y, tempRotate.Z);
     
       Matrix view = Matrix.LookAtLH(
           camPosition,
           camTarget,
           camUp);
       device.SetTransform(TransformType.View, view);
    }

    3,原理和2中一样,不过在旋转计算时,采用四元素数进行处理

    //通过四元素数进行旋转变换(同样绕着世界坐标系的Y轴)
    private void RotateYThree(float paAngle)
    {
       Vector4 tempRotate = Vector3.Transform(
           camPosition,
           Matrix.RotationQuaternion(Quaternion.RotationAxis(new Vector3(0, 1, 0), paAngle)));
       camPosition = new Vector3(tempRotate.X, tempRotate.Y, tempRotate.Z);
     
       Matrix view = Matrix.LookAtLH(camPosition, camTarget, camUp);
       device.SetTransform(TransformType.View, view);
    }
  • 相关阅读:
    Reinforcement Learning Qlearning 算法学习3 AI
    2012年末工作中遇到的问题总结及感悟
    对JMS的一些认识
    readme
    数据库表扩展字段设计思路
    对网络安全性和apache shiro的一些认识
    JDK版本的了解
    下拉框“数据字典”设计
    缓存学习总结
    apache commons包简介
  • 原文地址:https://www.cnblogs.com/sharpfeng/p/1999593.html
Copyright © 2011-2022 走看看