计算机图形学(移动相机视角和各种可视光下图形变化)

本文探讨了计算机图形学中移动相机视角对图形显示的影响,同时详细解析了不同光照条件下图形的视觉变化,展示了从不同角度和光照环境如何塑造虚拟世界的表现力。
摘要由CSDN通过智能技术生成

移动相机角度

#include <stdio.h>
#include <gl/glut.h>
#include <math.h>
#include "gmath.h"
#include "gmatrix3d.h"
#include "gvector3d.h"
#include "gcamera.h"

bool gIsButtonDown = false;
int gMouseX = 0;
int gMouseY = 0;

GCamera gCamera;

void drawPlan()
{
   
	glColor3f(0.6f,0.6f,0.6f);

	glBegin(GL_LINES);
	for(float u=-1.0f;u<1.01f;u+=0.2f)
	{
   
		glVertex3d(-1,0,u);
		glVertex3d(1,0,u);

		glVertex3d(u,0,-1);
		glVertex3d(u,0,1);
	}
	glEnd();
}

void onDisplay()
{
   
	glClearColor(0,0,0,1);
	//清除缓存
	glClear(GL_COLOR_BUFFER_BIT);
	
	glLoadIdentity();

	gCamera.lookAt();

	glLineWidth(2);

	drawPlan();

	glPushMatrix();
	glTranslatef(-0.3f,0,-0.3f);
	glColor3f(1,0,0);
	glutWireCube(0.4f);
	glPopMatrix();

	glPushMatrix();
	glTranslatef(0.3f,0,-0.3f);
	glColor3f(0,1,0);
	glutWireSphere(0.2f,16,16);
	glPopMatrix();

	glPushMatrix();
	glTranslatef(0,0,0.3f);
	glRotatef(-90,1,0,0);
	glColor3f(1,1,0);
	glutWireCone(0.2f,0.6f,16,8);
	glPopMatrix();
	//交换缓存
	glutSwapBuffers();
}

void onReshape(int w,int h)
{
   
	/*glViewport(0,0,w,h);
 	double aspect = (double)w/h;
 	glMatrixMode(GL_PROJECTION);          //对接下来要做什么进行声明   GL_PROJECTION 投影, GL_MODELVIEW 模型视图, GL_TEXTURE 纹理.
 	glLoadIdentity();                     //恢复初始坐标系

	gluPerspective(60,aspect,0.1,10);
	//glOrtho(-1,1,-1,1,-1,1);
	glMatrixMode(GL_MODELVIEW);*/
	gCamera.setScreenSize(w, h);
	gCamera.project();
	glutPostRedisplay();
}

GVector3d mousePt2SphereVec(int x, int y, int cw, int ch)
{
   
	double lx, ly, lz,r;
	lx = (2.0 * x - cw) / cw;
	ly = (ch - 2.0 * y) / ch;
	r = lx*lx + ly*ly;
	if (r > 1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值