游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2590|回复: 7

关于利用四元素进行观察变换的问题

[复制链接]

20

主题

84

帖子

84

积分

注册会员

Rank: 2

积分
84
发表于 2009-11-2 23:14:00 | 显示全部楼层 |阅读模式
谁能够提供些详细点并且容易读懂的关于坐标变换相关的资料?

很多说的不是很详细 要么就是不容易懂。
        //************************************************************
        // camera stuff
        //************************************************************
        fRoll = fPitch = fYaw = 0.0f;
    D3DXVECTOR3 vPos(0.0f, 0.0f, 0.0f);
    static D3DXMATRIX matView  = D3DXMATRIX(1.0f, 0.0f, 0.0f, 0.0f,
                                0.0f, 1.0f, 0.0f, 0.0f,  
                                0.0f, 0.0f, 1.0f, 0.0f,  
                                0.0f, 0.0f,-5.0f, 1.0f);
        // Process keyboard input
        if (m_bKey[VK_UP])                        fPitch += fOneStep; // Pitch Up
    if (m_bKey[VK_DOWN])                fPitch -= fOneStep; // Pitch Down
    if (m_bKey[VK_LEFT])            fYaw += fOneStep; // Turn Left
    if (m_bKey[VK_RIGHT])            fYaw -= fOneStep; // Turn Right
    if (m_bKey['C'])                    fRoll += fOneStep; // Rotate Left
    if (m_bKey['X'])                    fRoll -= fOneStep; // Rotate Right
    if (m_bKey[VK_HOME])                vPos.z += fOneStep; // Move Forward
    if (m_bKey[VK_END])                        vPos.z -= fOneStep; // Move Backward
    if (m_bKey[VK_NUMPAD4])                vPos.x -= fOneStep; // Slide Left
    if (m_bKey[VK_NUMPAD6])                vPos.x += fOneStep; // Slide Right
    if (m_bKey[VK_NUMPAD8])     vPos.y += fOneStep; // Slide Down
    if (m_bKey[VK_NUMPAD2])     vPos.y -= fOneStep; // Slide Up

    // Update position and view matricies
    D3DXMATRIX matR, matTemp;
        D3DXQuaternionRotationYawPitchRoll (&qR, fYaw, fPitch, fRoll);       
        D3DXMatrixRotationQuaternion (&matR, &qR);                                               
        D3DXMatrixMultiply (&matView, &matR, &matView);
        D3DXMatrixTranslation (&matTemp, vPos.x, vPos.y, vPos.z);
        D3DXMatrixMultiply (&matView, &matTemp, &matView);
             D3DXMatrixInverse (&matTemp, NULL, &matView);

          m_pd3dDevice->SetTransform(D3DTS_VIEW, &matTemp );
谁能够再说说为什么这里要D3DXMatrixInverse (&matTemp, NULL, &matView)?

而且matView=matTemp*matR*matView这样的变换顺序是乱的,因为matView是静态的,保存了之前的平移的信息,如果在此基础上在旋转再平移,这样不是很乱吗?是不是书错了?

2

主题

429

帖子

435

积分

中级会员

Rank: 3Rank: 3

积分
435
发表于 2009-11-3 19:55:00 | 显示全部楼层

Re:关于利用四元素进行观察变换的问题

第一个问题,你看我回你的上个贴。

第二个,这是逻辑需求的问题,因为你要实现的效果就是,按了键之后相机移动,或旋转,下次再按键后的运动是在这次的基础上。绕x旋转20度,也可以等价为做两次绕x旋转10度,矩阵的变换是可以叠加的。

20

主题

84

帖子

84

积分

注册会员

Rank: 2

积分
84
 楼主| 发表于 2009-11-4 09:58:00 | 显示全部楼层

Re: Re:关于利用四元素进行观察变换的问题

Enigmaya: Re:关于利用四元素进行观察变换的问题

第一个问题,你看我回你的上个贴。

第二个,这是逻辑需求的问题,因为你要实现的效果就是,按了键之后相...

谢谢你的回答,的确旋转20度可以看成两次10度,这个我也可以想象得通,但是有了
D3DXMatrixMultiply (&matView, &matTemp, &matView);
matView中就不纯粹是旋转的信息了呀,也包含的平移的量了。

如果第一次变换绕vR旋转a度,平移一个v量,保存在matview中。
第二次旋转式绕vR'旋转b度(这样的四元素得到的矩阵为matR),如果再平移一个v'的量(得到平移矩阵matTemp)。
matView=matTemp*matR*matView
matView现在已经表示为先平移v'量,然后绕vR'旋转,再平移一个v量和绕vR旋转a度。
这样的变换顺序是乱的。
先平移再旋转与先旋转再平移的变换结果是不同的。每次旋转都是在之前的平移后的基础上旋转,这样感觉不对呀。

3

主题

17

帖子

17

积分

新手上路

Rank: 1

积分
17
发表于 2009-11-4 13:14:00 | 显示全部楼层

Re: 关于利用四元素进行观察变换的问题

  • Linux ebook free download
  • Hardening Linux ebook free download
  • Linux Cookbook ebook free download
  • Linux on the Mainframe ebook free download
  • Linux Unwired  ebook free download
  • Linux: Phrasebook  ebook free download
  • Inside Linux ebook free download
  • Practical Linux ebook free download
  • Suse Linux ebook free download
  • Fedora Linux ebook free download
  • Linux Clustering: Building and Maintaining Linux Clusters ebook free download
  • Linux Kernel in a Nutshell ebook free download
  • Linux Server Hacks ebook free download
  • Linux Power Tools ebook free download
  • Understanding the Linux Kernel ebook free download
  • Linux Security Cookbook ebook free download
  • Advanced Linux Networking ebook free download
  • Advanced Linux Programming ebook free download
  • User Mode Linux ebook free download
  • Linux For Programmers And Users ebook free download
  • Linux Enterprise Cluster ebook free download
  • Professional Linux Programming ebook free download
  • Managing RAID on Linux ebook free download
  • Linux System Programming ebook free download
  • Linux System Administration ebook free download
  • Integrating Linux and Windows ebook free download
  • Troubleshooting Linux Firewalls ebook free download
  • Linux Network Servers ebook free download
  • Linux Programming Bible ebook free download
  • Java Programming on Linux ebook free download
  • Linux Programming Unleashed ebook free download
  • Linux Socket Programming ebook free download
  • Moving from Windows to Linux ebook free download
  • Linux Desktop Hacks ebook free download
  • Hardening Linux (2005) ebook free download
  • Linux+ Certification Bible ebook free download
  • Hacker Linux Uncovered ebook free download
  • Linux Troubleshooting Bible ebook free download
  • Linux Desktop Garage ebook free download
  • 2

    主题

    429

    帖子

    435

    积分

    中级会员

    Rank: 3Rank: 3

    积分
    435
    发表于 2009-11-4 20:16:00 | 显示全部楼层

    Re:关于利用四元素进行观察变换的问题

    “在已经表示为先平移v'量,然后绕vR'旋转,再平移一个v量和绕vR旋转a度。
    这样的变换顺序是乱的。”

    后面的相机运动是基于前一次的运动的,当然前一次的平移,旋转要保留了。后一次旋转的轴和第一次已经不一样了。
    后面的平移也是基于前面的结果的,这和旋转叠加同理。
    虽然 mR * mT != mT * mR,但是这里不涉及这个问题。
    多次变换的叠加,没有规定必须先平移再旋转。如,向前走两步,然后向后转,然后往“当前方向”走两步,你就回到了原来的位置。这里面旋转和位移,完全都是按照实际需要的顺序依次来的。不会有什么顺序乱的问题。


    20

    主题

    84

    帖子

    84

    积分

    注册会员

    Rank: 2

    积分
    84
     楼主| 发表于 2009-11-5 15:45:00 | 显示全部楼层

    Re:关于利用四元素进行观察变换的问题

    如果平移后再旋转就不是绕自身旋转了
    matView它包含的平移旋转等是全部杂到一起的,所以感觉不对

    2

    主题

    429

    帖子

    435

    积分

    中级会员

    Rank: 3Rank: 3

    积分
    435
    发表于 2009-11-5 19:22:00 | 显示全部楼层

    Re:关于利用四元素进行观察变换的问题

    相机旋转一般有两种,一种是,绕自身旋转,另一种是绕目标点旋转(orbit)。你这里是第二种吧?

    20

    主题

    84

    帖子

    84

    积分

    注册会员

    Rank: 2

    积分
    84
     楼主| 发表于 2009-11-6 09:06:00 | 显示全部楼层

    Re:关于利用四元素进行观察变换的问题

    这个是书上的例题,我也不知道具体属于哪个。。。很谢谢你耐心的回答
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

    GMT+8, 2025-6-18 09:20

    Powered by Discuz! X3.4

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表