我的lookAt和Perspective调用与VS gluPerspective和glLookat有什么不同(多维数据集拉伸) [英] What's different with my lookAt and perspective calls VS gluPerspective and glLookat (cube stretched)

查看:153
本文介绍了我的lookAt和Perspective调用与VS gluPerspective和glLookat有什么不同(多维数据集拉伸)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

旁注:大家好,如果您发现我的问题/答案有所帮助,请不要忘记投票.我有点需要...

所以我对矩阵[投影和模型]的实现似乎有所不同(除了我出于调试目的而注释掉的东西).以下是绘制多维数据集时看到的错误的屏幕截图. 请记住,我确实使视口和矩阵与窗口大小保持最新,并使用float和int来计算屏幕比例,所以不要打扰,我已经检查了通常的可疑对象.....

So there seems to be something different with my implementation of both matrix [projection and model] (other than the stuff I've commented out for debugging purposes). Below is a screenshot of the bug I see when drawing a cube. Keep in mind I do keep the viewport and matrix up to date with the window size and calculate screen ratio with float and not int, so don't bother asking, I've checked the usual suspects.....

屏幕截图

文件(Linux构建,请参见./build中的自述文件)
旁注:在调试时,我更改了立方体的距离.要重现屏幕截图,请在workspace.cpp的第76行上将mDistance设置为大约90,然后将窗口框架拉伸到窗口右下角标注的尺寸.

Files (linux build, see readme in ./build)
side note: while debugging, I've changed the cube's distance. To reproduce the screen shot, on line 76 of workspace.cpp set mDistance to about 90 and stretch the window frame to dimensions noted at lower right corner of the window.

请记住屏幕截图和调试文本输出是单独的事件,因为我一直在调试此问题并获取新的数字.

代码:

#define _AP_MAA 0
#define _AP_MAB 1
#define _AP_MAC 2
#define _AP_MAD 3
#define _AP_MBA 4
#define _AP_MBB 5
#define _AP_MBC 6
#define _AP_MBD 7
#define _AP_MCA 8
#define _AP_MCB 9
#define _AP_MCC 10
#define _AP_MCD 11
#define _AP_MDA 12
#define _AP_MDB 13
#define _AP_MDC 14
#define _AP_MDD 15

设置相机视角:

void APCamera::setPerspective(GMFloat_t fov, GMFloat_t aspect, GMFloat_t near, GMFloat_t far)
{
   GMFloat_t difZ = near - far;

   GMFloat_t *data;

   mProjection->clear(); //set to identity matrix
   data = mProjection->getData();

   GMFloat_t v = 1.0f / tan(fov / 2.0f);

   data[_AP_MAA] = v / aspect;
   data[_AP_MBB] = v;
   data[_AP_MCC] = (far + near) / (difZ);
   data[_AP_MCD] = -1.0f;
   data[_AP_MDD] = 0.0f;
   data[_AP_MDC] = (2.0f * far * near)/ (difZ);

   mRatio = aspect;

   mInvProjOutdated = true;
   mIsPerspective = true;
}

设置摄像头方向:

bool APCamera::lookTo(Coordinate &to, Coordinate &from, Coordinate &up)  
 {
      Coordinate f, unitUp, right;  
      GMFloat_t *data;

      CoordinateOp::diff(&to, &from, &f);
      VectorOp::toUnit(&f, &f);
      VectorOp::toUnit(&up, &unitUp);
      VectorOp::cross(&f, &unitUp, &right);

      if((fabs(right.x) < FLOAT_THRESHOLD) && (fabs(right.y) < FLOAT_THRESHOLD) && (fabs(right.z) < FLOAT_THRESHOLD))
     {
         return false;
     }

     mCamPt = from;

     VectorOp::toUnit(&right, &mRight);
     mForward = f;
     VectorOp::cross(&mRight, &mForward, &mUp);

     mModelView->clear();
     data = mModelView->getData();

     data[_AP_MAA] = mRight.x;
     data[_AP_MBA] = mRight.y;
     data[_AP_MCA] = mRight.z;

     data[_AP_MAB] = mUp.x;
     data[_AP_MBB] = mUp.y;
     data[_AP_MCB] = mUp.z;

     data[_AP_MAC] = -mForward.x;
     data[_AP_MBC] = -mForward.y;
     data[_AP_MCC] = -mForward.z;

     //translation part is commented out to narrow bugs down, "camera" is kept at the center (0,0,0)
     //data[_AP_MDA] = (data[_AP_MAA] * -mCamPt.x) + (data[_AP_MBA] * -mCamPt.y) + (data[_AP_MCA] * -mCamPt.z);
     //data[_AP_MDB] = (data[_AP_MAB] * -mCamPt.x) + (data[_AP_MBB] * -mCamPt.y) + (data[_AP_MCB] * -mCamPt.z);
     //data[_AP_MDC] = (data[_AP_MAC] * -mCamPt.x) + (data[_AP_MBC] * -mCamPt.y) + (data[_AP_MCC] * -mCamPt.z);

  mInvViewOutdated = true;
  return true;
}  

调试输出:

LookTo()发件人:< 0,0,0>收件人:< -1,0,0>:
0.000000 0.000000 -1.000000 0.000000
0.000000 1.000000 0.000000 0.000000
1.000000 -0.000000 -0.000000 0.000000
0.000000 0.000000 0.000000 1.000000

LookTo() From:<0,0,0> To:<-1,0,0>:
0.000000 0.000000 -1.000000 0.000000
0.000000 1.000000 0.000000 0.000000
1.000000 -0.000000 -0.000000 0.000000
0.000000 0.000000 0.000000 1.000000

setPerspective()fov:0.785398比率:1.185185近:0.500000远:100.000000:
2.036993 0.000000 0.000000 0.000000
0.000000 2.414213 0.000000 0.000000
0.000000 0.000000 -1.010050 -1.005025
0.000000 0.000000 -1.000000 0.000000

setPerspective() fov:0.785398 ratio:1.185185 near:0.500000 far:100.000000:
2.036993 0.000000 0.000000 0.000000
0.000000 2.414213 0.000000 0.000000
0.000000 0.000000 -1.010050 -1.005025
0.000000 0.000000 -1.000000 0.000000

推荐答案

最后,看起来制造麻烦的人只是FOV. 因此,快速的答案是:没有,我没有做任何与记录在案的观点并着眼于功能的事情.对于遇到类似问题的任何人,2.0f * atan(tan(DEFAULT_FOV_RAD/mRatio) * mRatio)都为我完成了工作.

In the end, it looks like the trouble maker was just the FOV. So the quick answer is NO I didn't do anything different from the documented perspective and look at function. For anyone having a similar problem 2.0f * atan(tan(DEFAULT_FOV_RAD/mRatio) * mRatio) did the job for me.

这篇关于我的lookAt和Perspective调用与VS gluPerspective和glLookat有什么不同(多维数据集拉伸)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆