#include <stdio.h>
#include <gl/glut.h>
#include <math.h>
#include "gmath.h"
#include "gmatrix3d.h"
#include "gvector3d.h"
#include "gcamera.h"
GMatrix3d gRotMatrix;
double gRotx = 0.0;
double gRotY = 0.0;
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(1,1,1,1);
//清除缓存
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
gCamera.lookAt();
//glTranslated(0,0,-1.5);
glMultMatrixd(gRotMatrix);
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
OpenGL鼠标追踪球
最新推荐文章于 2022-08-09 17:26:34 发布
本文详细介绍了如何在OpenGL中实现鼠标追踪功能,通过捕捉鼠标移动事件来控制球体的旋转,提供了一种交互式的3D场景操作方式。
摘要由CSDN通过智能技术生成