opengl自定义函数实现平移旋转缩放
没有直接调用OpenGL几何变换函数,运用齐次坐标,采用矩阵相乘的方式自己编程实现;
控制方式:鼠标左键拖着移动,鼠标右键旋转方向,滚轮缩放
我为了完成实验作业自己写的
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
..A..H. 65024 2018-05-27 12:18 opengl函数实现平移旋转缩放.vs3Dpickv15.suo
文件 37130240 2018-05-27 12:18 opengl函数实现平移旋转缩放.vs3Dpickv15Browse.VC.db
文件 3604480 2018-05-24 11:09 opengl函数实现平移旋转缩放.vs3Dpickv15ipch1b7c1f9d8ba0e544.ipch
文件 3604480 2018-05-24 17:03 opengl函数实现平移旋转缩放.vs3Dpickv15ipch1cd6e519e9c42d5.ipch
文件 3604480 2018-05-25 14:34 opengl函数实现平移旋转缩放.vs3Dpickv15ipch2e87b34bc5a06ea4.ipch
文件 3604480 2018-05-27 12:00 opengl函数实现平移旋转缩放.vs3Dpickv15ipch4594dd35148ef33e.ipch
文件 3604480 2018-05-22 22:09 opengl函数实现平移旋转缩放.vs3Dpickv15ipch6d9f927b4f3e75c5.ipch
文件 3604480 2018-05-23 17:17 opengl函数实现平移旋转缩放.vs3Dpickv15ipch834d186b7889040c.ipch
文件 9658 2018-05-24 12:40 opengl函数实现平移旋转缩放3Dpick3Dpick.vcxproj
文件 1584 2018-05-24 12:40 opengl函数实现平移旋转缩放3Dpick3Dpick.vcxproj.filters
文件 165 2018-05-20 11:12 opengl函数实现平移旋转缩放3Dpick3Dpick.vcxproj.user
文件 1020 2018-05-27 11:11 opengl函数实现平移旋转缩放3DpickDebug3Dpick.log
文件 2721 2018-05-23 17:31 opengl函数实现平移旋转缩放3DpickDebug3Dpick.obj
文件 2883584 2018-05-25 14:35 opengl函数实现平移旋转缩放3DpickDebug3Dpick.pch
文件 218 2018-05-27 11:11 opengl函数实现平移旋转缩放3DpickDebug3Dpick.tlog3Dpick.lastbuildstate
文件 23852 2018-05-27 11:11 opengl函数实现平移旋转缩放3DpickDebug3Dpick.tlogCL.command.1.tlog
文件 114398 2018-05-27 11:11 opengl函数实现平移旋转缩放3DpickDebug3Dpick.tlogCL.read.1.tlog
文件 5826 2018-05-27 11:11 opengl函数实现平移旋转缩放3DpickDebug3Dpick.tlogCL.write.1.tlog
文件 11830 2018-05-27 11:11 opengl函数实现平移旋转缩放3DpickDebug3Dpick.tloglink.command.1.tlog
文件 15628 2018-05-27 11:11 opengl函数实现平移旋转缩放3DpickDebug3Dpick.tloglink.read.1.tlog
文件 1530 2018-05-27 11:11 opengl函数实现平移旋转缩放3DpickDebug3Dpick.tloglink.write.1.tlog
文件 59959 2018-05-27 11:11 opengl函数实现平移旋转缩放3DpickDebugmain.obj
文件 65682 2018-05-23 19:47 opengl函数实现平移旋转缩放3DpickDebugmain.obj.enc
文件 74471 2018-05-25 14:35 opengl函数实现平移旋转缩放3DpickDebugmath3d.obj
文件 74021 2018-05-21 12:37 opengl函数实现平移旋转缩放3DpickDebugmath3d.obj.enc
文件 159389 2018-05-24 12:28 opengl函数实现平移旋转缩放3DpickDebugSelection.obj
文件 158982 2018-05-22 22:50 opengl函数实现平移旋转缩放3DpickDebugselection.obj.enc
文件 5988 2018-05-25 14:35 opengl函数实现平移旋转缩放3DpickDebugstdafx.obj
文件 535552 2018-05-27 11:11 opengl函数实现平移旋转缩放3DpickDebugvc141.idb
文件 577536 2018-05-27 11:11 opengl函数实现平移旋转缩放3DpickDebugvc141.pdb
............此处省略82个文件信息
#include “stdafx.h“
//#include “math3d.h“
#include
#include
#include
#include
using namespace std;
#define GLUT_WHEEL_UP 3
#define GLUT_WHEEL_DOWN 4
////////////////////////////////////////////////////////////
////math3d////
#define PI_DIV_180 (0.017453292519943296)// 1°= 2π/360 = 0.0174弧度
typedef float Vector2f[2]; // 3D points = 3D Vectors but we need a
typedef float Vector3f[3]; // Vector of three floats (x y z)
typedef float Vector4f[4]; // Lesser used... Do we really need these?
typedef float Matrix33f[9]; // A 3 x 3 matrix column major (floats) - OpenGL style
typedef float Matrix44f[16]; // A 4 X 4 matrix column major (floats) - OpenGL style
#define DegToRad(x) ((x)*PI_DIV_180)
inline void LoadVector3(Vector3f v const float x const float y const float z)
{
v[0] = x; v[1] = y; v[2] = z;
} // 4x4 float
inline void CopyVector3(Vector3f dst const Vector3f src) { memcpy(dst src sizeof(Vector3f)); }
inline void LoadVector4(Vector4f v const float x const float y const float z const float w)
{
v[0] = x; v[1] = y; v[2] = z; v[3] = w;
}
void LoadIdentity44(Matrix44f m)
{
// Don‘t be fooled this is still column major
static Matrix44f identity = { 1.0f 0.0f 0.0f 0.0f
0.0f 1.0f 0.0f 0.0f
0.0f 0.0f 1.0f 0.0f
0.0f 0.0f 0.0f 1.0f };
memcpy(m identity sizeof(Matrix44f));
}
////////////////////////////////////////////////////////////
//参数
static float rotatee = 0.001;
static float translate = 0.01;
static float PI = 3.14159;
void translate3D(GLfloat tx GLfloat ty GLfloat tz);
void scale3D();
void Vector4Mulitply(Vector4f vOut const Vector4f v const Matrix44f m);
void comChange(float angle float angle2 GLfloat tx GLfloat ty GLfloat tz);
/////////////////////////////////鼠标左键/////////////////////////////////////
//鼠标按下时的坐标
int x0 y00;
//鼠标停下时的坐标
int x1 y11;
//鼠标是否按下
bool LeftButtonIsDown = false;
/////////////////////////////////鼠标右键/////////////////////////////////////
//鼠标按下时的坐标
int x2 y2;
//鼠标停下时的坐标
int x3 y3;
//鼠标是否按下
bool RightButtonIsDown = false;
//位移增量
float tx = 0;
float ty = 0;
float tz = 0;
//旋转增量
float rx = 0;
float ry = 0;
float rz = 0;
//缩放增量
float zoom = 1.0;
// 将立方体的八个顶点保存到一个数组里面 原始数据
static float vertex_list[8][3] =
{
-20.0f -20.0f -20.0f
20.0f -20.0f -20.0f
-20.0f 20.0f -20.0f
20.0f20.0f -20.0f
-20.0f -20.0f20.0f
20.0f -20.0f 20.0f
-20.0f 20.0f 20.0f
20.0f20.0f 20.0f
};
//画图数据
static float vertex_draw[8][3] =
{
-20.0f -20.0f -20.0f
20.0f -20.0f -20.0f
-20.0f 20.0f -20.0f
20.0f20.0f -20.0f
-20.0f -20.0f20.0f
20.0f -20.0f 20.0f
-20.0f 20.0f 20.0f
20.0f20.0f 20.0f
};
// 将要使用的顶点的序号保存到一个数组里面
static const GLint index_list[][2] =
{
{ 0 1 }
{ 2 3 }
{ 4 5 }
{ 6 7 }
{ 0 2 }
{ 1 3 }
{ 4 6 }
{ 5 7 }
{ 0 4 }
{ 1 5 }
{ 7 3 }
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
..A..H. 65024 2018-05-27 12:18 opengl函数实现平移旋转缩放.vs3Dpickv15.suo
文件 37130240 2018-05-27 12:18 opengl函数实现平移旋转缩放.vs3Dpickv15Browse.VC.db
文件 3604480 2018-05-24 11:09 opengl函数实现平移旋转缩放.vs3Dpickv15ipch1b7c1f9d8ba0e544.ipch
文件 3604480 2018-05-24 17:03 opengl函数实现平移旋转缩放.vs3Dpickv15ipch1cd6e519e9c42d5.ipch
文件 3604480 2018-05-25 14:34 opengl函数实现平移旋转缩放.vs3Dpickv15ipch2e87b34bc5a06ea4.ipch
文件 3604480 2018-05-27 12:00 opengl函数实现平移旋转缩放.vs3Dpickv15ipch4594dd35148ef33e.ipch
文件 3604480 2018-05-22 22:09 opengl函数实现平移旋转缩放.vs3Dpickv15ipch6d9f927b4f3e75c5.ipch
文件 3604480 2018-05-23 17:17 opengl函数实现平移旋转缩放.vs3Dpickv15ipch834d186b7889040c.ipch
文件 9658 2018-05-24 12:40 opengl函数实现平移旋转缩放3Dpick3Dpick.vcxproj
文件 1584 2018-05-24 12:40 opengl函数实现平移旋转缩放3Dpick3Dpick.vcxproj.filters
文件 165 2018-05-20 11:12 opengl函数实现平移旋转缩放3Dpick3Dpick.vcxproj.user
文件 1020 2018-05-27 11:11 opengl函数实现平移旋转缩放3DpickDebug3Dpick.log
文件 2721 2018-05-23 17:31 opengl函数实现平移旋转缩放3DpickDebug3Dpick.obj
文件 2883584 2018-05-25 14:35 opengl函数实现平移旋转缩放3DpickDebug3Dpick.pch
文件 218 2018-05-27 11:11 opengl函数实现平移旋转缩放3DpickDebug3Dpick.tlog3Dpick.lastbuildstate
文件 23852 2018-05-27 11:11 opengl函数实现平移旋转缩放3DpickDebug3Dpick.tlogCL.command.1.tlog
文件 114398 2018-05-27 11:11 opengl函数实现平移旋转缩放3DpickDebug3Dpick.tlogCL.read.1.tlog
文件 5826 2018-05-27 11:11 opengl函数实现平移旋转缩放3DpickDebug3Dpick.tlogCL.write.1.tlog
文件 11830 2018-05-27 11:11 opengl函数实现平移旋转缩放3DpickDebug3Dpick.tlogli
文件 15628 2018-05-27 11:11 opengl函数实现平移旋转缩放3DpickDebug3Dpick.tlogli
文件 1530 2018-05-27 11:11 opengl函数实现平移旋转缩放3DpickDebug3Dpick.tlogli
文件 59959 2018-05-27 11:11 opengl函数实现平移旋转缩放3DpickDebugmain.obj
文件 65682 2018-05-23 19:47 opengl函数实现平移旋转缩放3DpickDebugmain.obj.enc
文件 74471 2018-05-25 14:35 opengl函数实现平移旋转缩放3DpickDebugmath3d.obj
文件 74021 2018-05-21 12:37 opengl函数实现平移旋转缩放3DpickDebugmath3d.obj.enc
文件 159389 2018-05-24 12:28 opengl函数实现平移旋转缩放3DpickDebugSelection.obj
文件 158982 2018-05-22 22:50 opengl函数实现平移旋转缩放3DpickDebugselection.obj.enc
文件 5988 2018-05-25 14:35 opengl函数实现平移旋转缩放3DpickDebugstdafx.obj
文件 535552 2018-05-27 11:11 opengl函数实现平移旋转缩放3DpickDebugvc141.idb
文件 577536 2018-05-27 11:11 opengl函数实现平移旋转缩放3DpickDebugvc141.pdb
............此处省略82个文件信息
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)