测试发现,还是NEHE的鼠标旋转物体效果好啊,但NEHE是在基于Windows 的程序框架下编写的,不少代码融入到了windows编程中,感觉比较混乱,所以就想提取出来,在基于控制台的框架下实现出来,在此框架下代码结构比较简单,便于以后再使用这些代码,也就是便于代码复用。主程序代码如下
#include <stdlib.h>
#include <GL/glut.h>
#include <stdio.h>
#include "math.h"
#include "ArcBall.h"
// object
GLfloat vertices[] = {-1.0,-1.0,-1.0,1.0,-1.0,-1.0,
1.0,1.0,-1.0, -1.0,1.0,-1.0, -1.0,-1.0,1.0,
1.0,-1.0,1.0, 1.0,1.0,1.0, -1.0,1.0,1.0};
GLfloat colors[] = {0.0,0.0,0.0,1.0,0.0,0.0,
1.0,1.0,0.0, 0.0,1.0,0.0, 0.0,0.0,1.0,
1.0,0.0,1.0, 1.0,1.0,1.0, 0.0,1.0,1.0};
GLubyte cubeIndices[]={0,3,2,1,2,3,7,6,0,4,7,3,1,2,6,5,4,5,6,7,0,1,5,4};
// mouse control
Matrix4fT
0.0f,
0.0f,
0.0f,
Matrix3fT
0.0f,
0.0f,
Matrix3fT
0.0f,
0.0f,
ArcBallT
Instance
Point2fT
// NEW: Current Mouse Point
bool
// NEW: Clicking The Mouse?
bool
// NEW: Dragging The Mouse?
void display(void)
{
// NEW: Prepare Dynamic Transform
// NEW: Apply Dynamic Transform
}
void mouse(int btn, int state, int x, int y)
{
// Reset Rotation
// Reset Rotation
}
void mouseMotion(int x, int y)
{
// Not Dragging
// First Click
// Prepare For Dragging
// Set Last Static Rotation To Last Dynamic One