|
|

楼主 |
发表于 2005-10-26 14:47:00
|
显示全部楼层
Re:请问OpenGL的投影平面--
To hovers:我只是猜测在zNear处,但并不确定,你可有什么根据?
To huawenguang:在计算机图形学中,讲到透视投影的时候,涉及一点透视的定义,可以理解为:投影平面与一个坐标轴正交,与另外两个坐标轴平行.想必投影平面和投影中心对于透视投影是存在的;在数学上,除了用一个点和一个平面来定义透视投影,也许还是其它方式.
至于我的离谱的那一点想法,是在<<OpenGL编程指南>>(传说中的红宝书)的第三章第5节--变换的诊断中看到的,或许是我表达有误.这里请容许我作一下解释:
我在使用gluPerspctive()函数时,首先计算fovy的值,用tan(fovy/2) = (h/2)/distance;
(已知的只有物体的大小及其各顶点的世界坐标),aspect在我未定义Viewport的时候为了避免显示失真,用aspect = w/h计算.
To dfq19:我最终想得到空间物体投影到屏幕上的较为精确的坐标区域,这在三维数据场的体绘制中有很大作用.
To forcewall:谢谢.
To zhuyi8319:谢谢.
其实我用另外一种方式表示,大家可能更加明白:
有DitkCamera类如下:
#ifndef DITK_CAMERA_H
#define DITK_CAMERA_H
#include "DitkMatrix.h"
class DitkCamera
{
public:
DitkCamera();
//得到Camera中某点坐标在世界坐标中的坐标值
//关于ViewMatrix矩阵:
//它能够将世界坐标系中的点变换到Camera中
void GetPosition(float& x, float& y, float& z)
{
x = this->m_InverseViewMatrix->ele[12];
y = this->m_InverseViewMatrix->ele[13];
z = this->m_InverseViewMatrix->ele[14];
}
void GetPosition(float x[3])
{
this->GetPosition(x[0],x[1],x[2]);
}
//获取Camera中焦点坐标
void GetFocalPoint(float& x, float& y, float& z)
{
x = this->m_FocalPoint[0];
y = this->m_FocalPoint[1];
z = this->m_FocalPoint[2];
}
void GetFocalPoint(float f[3])
{
this->GetFocalPoint(f[0],f[1],f[2]);
}
//得到Camera的厚度,可以认为是其远近平面间的距离
float GetThickness()
{
return this->m_Thickness;
}
int IsParallelProjection()
{
return this->m_ParallelProjection;
}
//设置等效于OpenGL的一些与Camera相关的函数
void LookAt(float eyex,float eyey,float eyez,float centerx,float centery,float centerz,float upx,float upy,float upz);
void Ortho(float left,float right,float bottom,float top,float zNear,float zFar);
void Frustum(float left,float right,float bottom,float top,float zNear,float zFar);
void Perspective(float fovy,float aspect,float zNear,float zFar);
void GetViewMatrix(DitkMatrix* m);
void GetViewMatrix(float m[16]);
void GetProjectionMatrix(DitkMatrix* m);
void GetProjectionMatrix(float m[16]);
void GetInverseOfViewMatrix(DitkMatrix* m);
void GetInverseOfViewMatrix(float m[16]);
void GetInverseOfProjectionMatrix(DitkMatrix* m);
void GetInverseOfProjectionMatrix(float m[16]);
//点在各种坐标系中的变换
void WorldToCamera(const float worldPoint[4], float cameraPoint[4]);
void WorldToView(const float worldPoint[4],float viewPoint[4]);
void CameraToView(const float cameraPoint[4],float viewPoint[4]);
void CameraToWorld(const float cameraPoint[4],float worldPoint[4]);
void ViewToWorld(const float viewPoint[4], float worldPoint[4]);
void ViewToCamera(const float viewPoint[4],float cameraPoint[4]);
protected:
int m_ParallelProjection;
float m_FocalPoint[3];
float m_Thickness;
//相关矩阵
DitkMatrix *m_ViewMatrix; //世界坐标到观察坐标
DitkMatrix *m_ProjectionMatrix; //观察坐标到投影坐标
DitkMatrix *m_InverseProjectionMatrix; //投影坐标到观察坐标
DitkMatrix *m_InverseViewMatrix; //观察坐标到世界坐标
virtual ~DitkCamera();
private:
DitkCamera(const DitkCamera&);
DitkCamera& operator=(const DitkCamera& src);
};
我若调用gluPerspective()则会怎么样影响m_ViewMatrix和m_ProjectionMatrix?
再次感谢大家的热心--- |
|