资源简介
该实例目的是在VC下利用OpenGL接口实现=三维实体旋转、平移和缩放功能,鼠标操作很流畅,对需要这些功能的开发人员具有重要参考价值!
代码片段和文件信息
/************************************************
* Project Information:
*
* Filename:mathlib.cpp
* Version :1.0
* Last Update: May 2003
*
* Author: Bruce Christopher Barrera
* E-mail: bruce@opengl.com.br
* Date : around May 2003 :-)
*
* Comment: This is the math library
*
***********************************************/
#include “mathlib.h“
// This calculates a vector between 2 points and returns the result
CVector3 Vector(CVector3 vPoint1 CVector3 vPoint2)
{
CVector3 vVector; // The variable to hold the resultant vector
vVector.x = vPoint1.x - vPoint2.x; // Subtract point1 and point2 x‘s
vVector.y = vPoint1.y - vPoint2.y; // Subtract point1 and point2 y‘s
vVector.z = vPoint1.z - vPoint2.z; // Subtract point1 and point2 z‘s
return vVector; // Return the resultant vector
}
// This adds 2 vectors together and returns the result
CVector3 AddVector(CVector3 vVector1 CVector3 vVector2)
{
CVector3 vResult; // The variable to hold the resultant vector
vResult.x = vVector2.x + vVector1.x; // Add Vector1 and Vector2 x‘s
vResult.y = vVector2.y + vVector1.y; // Add Vector1 and Vector2 y‘s
vResult.z = vVector2.z + vVector1.z; // Add Vector1 and Vector2 z‘s
return vResult; // Return the resultant vector
}
// This divides a vector by a single number (scalar) and returns the result
CVector3 DivideVectorByScaler(CVector3 vVector1 float Scaler)
{
CVector3 vResult; // The variable to hold the resultant vector
vResult.x = vVector1.x / Scaler; // Divide Vector1‘s x value by the scaler
vResult.y = vVector1.y / Scaler; // Divide Vector1‘s y value by the scaler
vResult.z = vVector1.z / Scaler; // Divide Vector1‘s z value by the scaler
return vResult; // Return the resultant vector
}
// This returns the cross product between 2 vectors
CVector3 Cross(CVector3 vVector1 CVector3 vVector2)
{
CVector3 vCross; // The vector to hold the cross product
// Get the X value
vCross.x = ((vVector1.y * vVector2.z) - (vVector1.z * vVector2.y));
// Get the Y value
vCross.y = ((vVector1.z * vVector2.x) - (vVector1.x * vVector2.z));
// Get the Z value
vCross.z = ((vVector1.x * vVector2.y) - (vVector1.y * vVector2.x));
return vCross; // Return the cross product
}
// This returns the normal of a vector
CVector3 Normalize(CVector3 vNormal)
{
double Magnitude; // This holds the magitude
Magnitude = Mag(vNormal); // Get the magnitude
vNormal.x /= (float)Magnitude; // Divide the vector‘s X by the magnitude
vNormal.y /= (float)Magnitude; // Divide the vector‘s Y by the magnitude
vNormal.z /= (float)Magnitude; // Divide the vector‘s Z by the magnitude
return vNormal; // Return the normal
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1183 2003-10-17 19:01 NeheGL_Glut\devcpp\Makefile.win
文件 1326 2003-10-17 19:01 NeheGL_Glut\devcpp\nehegl_glut.dev
文件 73 2003-10-17 12:45 NeheGL_Glut\devcpp\nehegl_glut.layout
文件 127 2003-10-17 19:02 NeheGL_Glut\devcpp\NEHEGL~1.layout
文件 98348 2003-10-17 18:32 NeheGL_Glut\exe\logo.tga
文件 26123 2003-10-17 19:14 NeheGL_Glut\exe\nehegl_glut
文件 117807 2003-10-17 19:02 NeheGL_Glut\exe\nehegl_glut.exe
文件 15724 2003-10-17 19:13 NeheGL_Glut\exe\nehegl_glut.o
文件 8384 2003-10-17 19:13 NeheGL_Glut\exe\tga.o
文件 267 2003-10-17 18:32 NeheGL_Glut\linux\Makefile
文件 9972 2003-10-17 19:14 NeheGL_Glut\linux\nehegl_glut.o
文件 3280 2003-10-17 19:14 NeheGL_Glut\linux\tga.o
文件 4566 2003-10-17 18:57 NeheGL_Glut\msvc++\nehegl_glut.dsp
文件 545 2003-10-17 11:49 NeheGL_Glut\msvc++\nehegl_glut.dsw
文件 33792 2003-10-17 19:01 NeheGL_Glut\msvc++\nehegl_glut.ncb
文件 48640 2003-10-17 19:01 NeheGL_Glut\msvc++\nehegl_glut.opt
文件 1326 2003-10-17 19:01 NeheGL_Glut\msvc++\nehegl_glut.plg
文件 1436 2003-10-17 19:05 NeheGL_Glut\readme
文件 1520 2003-10-17 12:41 NeheGL_Glut\src\fr
文件 2851 2003-10-17 11:49 NeheGL_Glut\src\mathlib.cpp
文件 1716 2003-10-17 11:49 NeheGL_Glut\src\mathlib.h
文件 15253 2003-10-17 19:01 NeheGL_Glut\src\nehegl_glut.cpp
文件 1478 2003-10-17 19:14 NeheGL_Glut\src\nehegl_glut.msp
文件 9941 2003-10-17 19:01 NeheGL_Glut\src\nehegl_glut.o
文件 11735 2003-10-17 18:32 NeheGL_Glut\src\tga.cpp
文件 774 2003-10-17 18:32 NeheGL_Glut\src\tga.h
文件 2963 2003-10-17 19:01 NeheGL_Glut\src\tga.o
目录 0 2003-10-17 18:32 NeheGL_Glut\devcpp
目录 0 2003-10-17 19:14 NeheGL_Glut\exe
目录 0 2003-10-17 19:14 NeheGL_Glut\linux
............此处省略6个文件信息
- 上一篇:verilog数字钟报告含代码
- 下一篇:swift-豆瓣电台源代码、以及图片资源
评论
共有 条评论