6.5编程实例-立方体透视投影
来源:互联网 发布:第章启航网络 编辑:程序博客网 时间:2024/06/05 04:26
#include <GL/glut.h>
GLint winWidth = 600, winHeight = 600; //设置初始化窗口大小
/* 观察坐标系参数设置*/
GLfloat x0 = 0.0, y0= 0.0, z0 =5.0; // 设置观察坐标系原点
GLfloat xref = 0.0, yref =0.0, zref = 0.0; //设置观察坐标系参考点(视点)
GLfloat Vx = 0.0, Vy = 1.0, Vz = 0.0; // 设置观察坐标系向上向量(y轴)
/*观察体(视见体)参数设置 */
GLfloat xwMin = -1.0, ywMin = -1.0, xwMax = 1.0, ywMax = 1.0;//设置裁剪窗口坐标范围
GLfloat dnear = 1.5, dfar = 20.0;//设置远、近裁剪面深度范围
void init (void)
{
glClearColor(1.0,1.0,1.0,0.0);
//glShadeModel (GL_FLAT);//xz
/*①观察变换*/
/*视点变换*/
gluLookAt (x0, y0, z0, xref, yref, zref, Vx, Vy, Vz); //指定三维观察参数
/*模型变换*/
glMatrixMode (GL_MODELVIEW);
glScalef (2.0, 2.0, 2.0); //比例放缩变换
glRotatef(45.0, 0.0, 1.0, 1.0);//旋转变换
/*②投影变换*/
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glFrustum (xwMin, xwMax, ywMin, ywMax, dnear, dfar);//透视投影,设置透视视景体
}
void displayFcn (void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (0.0, 1.0, 0.0); // 设置前景色为绿色
glutSolidCube (1.0);//绘制单位立方体实体
glColor3f (0.0, 0.0, 0.0); // 设置前景色为黑色
glLineWidth (2.0); //设置线宽
glutWireCube (1.0);//绘制单位立方体线框
glFlush ();
}
void reshapeFcn (GLint newWidth, GLint newHeight)
{
/*③视口变换 */
glViewport (0, 0, newWidth, newHeight);//定义视口大小
winWidth = newWidth;
winHeight = newHeight;
}
void main (int argc, char** argv)
{
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition (100, 100);
glutInitWindowSize (winWidth, winHeight);
glutCreateWindow ("单位立方体的透视投影");
init ();
glutDisplayFunc (displayFcn);
glutReshapeFunc (reshapeFcn);
glutMainLoop ();
}
- 6.5编程实例-立方体透视投影
- OpenCV3_C++_Perspective()透视形式投影 实例
- 透视投影
- 透视投影
- 透视投影
- 透视投影
- 透视投影
- 透视投影
- 透视投影
- 透视投影详解(Dx 透视投影推导)
- OpenGL 正交投影、透视除法、透视投影
- 透视投影与正交投影
- OpenGL透视投影gluPerspective
- [转]透视投影
- OpenGL透视投影gluPerspective
- 透视投影的推导
- 透视投影详解
- 透视投影详解
- 4.4.1 二维复合矩阵编程实例
- STM32CubeMX:UART(DMA空闲方式)
- 4.4.2 OpenGL几何变换编程实例
- oracle 环境配置以及基本操作
- ViewPager 详解(二)---详解四大函数
- 6.5编程实例-立方体透视投影
- 20. Valid Parentheses
- 7.5.5编程实例-Bezier曲线曲面绘制
- 8.6.4编程实例-纹理映射
- 9.3.3编程实例-图形拾取
- C++中深拷贝与浅拷贝区别
- 10.4.3 编程实例-太阳系动画
- 关于百度定位申请应用AK的一些问题
- 已知网络地址查询MAC地址