国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

OpenGL學(xué)習(xí)筆記4_2(透視相關(guān))

2019-11-10 19:30:54
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

藍(lán)寶書(shū) 第四章

正交投影

在ChangeSize函數(shù)中使用glOrtho函數(shù)調(diào)整

glOrtho參考:點(diǎn)擊打開(kāi)鏈接

正交投影ChangeSize代碼參考

void ChangeSize(GLsizei w, GLsizei h){	GLfloat nRange = 100.0f;	// PRevent a divide by zero  	if (h == 0)		h = 1;	// Set Viewport to window dimensions  	glViewport(0, 0, w, h);	// Reset projection matrix stack  	glMatrixMode(GL_PROJECTION);	glLoadIdentity();	// Establish clipping volume (left, right, bottom, top, near, far)  	if (w <= h)		glOrtho(-nRange, nRange, -nRange*h / w, nRange*h / w, -nRange, nRange);	else		glOrtho(-nRange*w / h, nRange*w / h, -nRange, nRange, -nRange, nRange);	// Reset Model view matrix stack  	glMatrixMode(GL_MODELVIEW);	glLoadIdentity();}

透視投影

在ChangeSize函數(shù)中使用gluPerspective函數(shù)調(diào)整

gluPerspective參考:點(diǎn)擊打開(kāi)鏈接

透視投影ChangeSize代碼參考

void ChangeSize(GLsizei w, GLsizei h){	GLfloat faspect;	// Prevent a divide by zero	if (h == 0)		h = 1;	// Set viewport to window dimensions	glViewport(0, 0, w, h);	fAspect = (GLfloat)w / (GLfloat)h;	// Reset coordinate system	glMatrixMode(GL_PROJECTION);	glLoadIdentity();	// Produce the perspective projection	gluPerspective(60.0f, fAspect, 1.0, 400.0);	glMatrixMode(GL_MODELVIEW);	glLoadIdentity();}glOrtho函數(shù)和gluPerspective的作用是在整個(gè)世界中勾出一個(gè)視線(xiàn)可以達(dá)到的范圍

例4.3 太陽(yáng)地球月亮模型

光源參考:點(diǎn)擊打開(kāi)鏈接

#include <windows.h>  #include <math.h>  #include <GL/GL.h>  #include <GL/GLU.h>  #include <GL/glut.h>   void RenderScene(void){	static float fMoonRot = 0.0f;	static float fEarthRot = 0.0f;		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	glMatrixMode(GL_MODELVIEW);	glPushMatrix();	glTranslatef(0.0f, 0.0f, -300.0f);	//sun	glColor3ub(255, 255, 0);	glDisable(GL_LIGHTING);	glutSolidSphere(15.0f, 15, 15);	glEnable(GL_LIGHTING);	GLfloat lightPos[] = { 0.0f, 0.0f, 0.0f, 1.0f};	glLightfv(GL_LIGHT0, GL_POSITION, lightPos);	glRotatef(fEarthRot, 0.0f, 1.0f, 0.0f);	glColor3ub(0, 0, 255);	glTranslatef(105.0f, 0.0f, 0.0f);	glutSolidSphere(15.0f, 15, 15);	glColor3ub(200, 200, 200);	glRotatef(fMoonRot, 0.0f, 1.0f, 0.0f);	glTranslatef(30.0f, 0.0f, 0.0f);	fMoonRot += 15.0f;	if (fMoonRot > 360.0f)		fMoonRot = 0.0f;	glutSolidSphere(6.0f, 15, 15);	glPopMatrix(); // Modelview matrix	fEarthRot += 5.0f;	if (fEarthRot > 360.0f)		fEarthRot = 0.0f;	// Show the image	glutSwapBuffers();}void SetupRC(){	glEnable(GL_DEPTH_TEST);	glFrontFace(GL_CCW);	glEnable(GL_CULL_FACE);	glEnable(GL_LIGHTING);	glEnable(GL_LIGHT0);	glEnable(GL_COLOR_MATERIAL);	// Black background	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);}void timerProc(int id){	RenderScene();	glutTimerFunc(100, timerProc, 1);}void ChangeSize(GLsizei w, GLsizei h){	GLfloat fAspect;	// Prevent a divide by zero	if (h == 0)		h = 1;	// Set viewport to window dimensions	glViewport(0, 0, w, h);	fAspect = (GLfloat)w / (GLfloat)h;	// Reset coordinate system	glMatrixMode(GL_PROJECTION);	glLoadIdentity();	// Produce the perspective projection	gluPerspective(45.0f, fAspect, 1.0, 425.0);	glMatrixMode(GL_MODELVIEW);	glLoadIdentity();}int main(int argc, char* argv[]){	glutInit(&argc, argv);	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);	glutInitWindowSize(800, 600);	glutCreateWindow("Earth & Moon & Sun System");	glutDisplayFunc(RenderScene);//顯示回調(diào)函數(shù)  	glutReshapeFunc(ChangeSize);//窗口大小變形回調(diào)函數(shù)  	glutTimerFunc(100, timerProc, 1);	SetupRC();	glutMainLoop();	return 0;}


上一篇:126. Word Ladder II

下一篇:注解 Annotation

發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 城步| 民县| 建德市| 凉城县| 班玛县| 竹山县| 深泽县| 镇坪县| 镇雄县| 平塘县| 开鲁县| 平遥县| 佳木斯市| 郓城县| 汪清县| 邢台市| 本溪| 南涧| 吉隆县| 新建县| 宁武县| 会宁县| 增城市| 伊金霍洛旗| 沙田区| 三门峡市| 天镇县| 长乐市| 广安市| 堆龙德庆县| 南昌市| 大姚县| 琼结县| 无棣县| 东城区| 洪湖市| 潞西市| 普安县| 乌拉特前旗| 新宁县| 洛宁县|