空间一条直线绕任意轴旋转Word文档格式.docx
- 文档编号:15692087
- 上传时间:2022-11-15
- 格式:DOCX
- 页数:15
- 大小:21.58KB
空间一条直线绕任意轴旋转Word文档格式.docx
《空间一条直线绕任意轴旋转Word文档格式.docx》由会员分享,可在线阅读,更多相关《空间一条直线绕任意轴旋转Word文档格式.docx(15页珍藏版)》请在冰豆网上搜索。
gl\glaux.h>
//HeaderFileForTheGlauxLibrary
iostream.h>
math.h>
#definePi3.3
floattempory[4][4],Rab[4][4];
floatTa[4][4],Rx[4][4],Ry[4][4],Rz[4][4],Ry_1[4][4],Rx_1[4][4],Ta_1[4][4];
HDChDC=NULL;
//PrivateGDIDeviceContext
HGLRChRC=NULL;
//PermanentRenderingContext
HWNDhWnd=NULL;
//HoldsOurWindowHandle
HINSTANCEhInstance;
//HoldsTheInstanceOfTheApplication
boolkeys[256];
//ArrayUsedForTheKeyboardRoutine
boolactive=TRUE;
//WindowActiveFlagSetToTRUEByDefault
boolfullscreen=TRUE;
//FullscreenFlagSetToFullscreenModeByDefault
LRESULTCALLBACKWndProc(HWND,UINT,WPARAM,LPARAM);
//DeclarationForWndProc
GLvoidReSizeGLScene(GLsizeiwidth,GLsizeiheight)//ResizeAndInitializeTheGLWindow
{
if(height==0)//PreventADivideByZeroBy
{
height=1;
//MakingHeightEqualOne
}
glViewport(0,0,width,height);
//ResetTheCurrentViewport
glMatrixMode(GL_PROJECTION);
//SelectTheProjectionMatrix
glLoadIdentity();
//ResetTheProjectionMatrix
//CalculateTheAspectRatioOfTheWindow
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,10000.0f);
glMatrixMode(GL_MODELVIEW);
//SelectTheModelviewMatrix
//ResetTheModelviewMatrix
}
intInitGL(GLvoid)//AllSetupForOpenGLGoesHere
glShadeModel(GL_SMOOTH);
//EnableSmoothShading
glClearColor(0.0f,0.0f,0.0f,0.5f);
//BlackBackground
glClearDepth(1.0f);
//DepthBufferSetup
glEnable(GL_DEPTH_TEST);
//EnablesDepthTesting
glDepthFunc(GL_LEQUAL);
//TheTypeOfDepthTestingToDo
glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
//ReallyNicePerspectiveCalculations
returnTRUE;
//InitializationWentOK
voidMatrixMultiple(floato[4][4],floatt[4][4])
floattotal;
for(inti=0;
i<
4;
i++)
{
for(intj=0;
j<
j++)
{
total=0;
for(intk=0;
k<
k++)
{
total+=o[i][k]*t[k][j];
}
tempory[i][j]=total;
}
for(intk=0;
for(intl=0;
l<
l++)
Rab[k][l]=tempory[k][l];
voidsetTransformMatrixs(floatx0,floaty0,floatz0,floatx1,floaty1,floatz1,floatangle)
angle=angle*Pi/180;
floatd=sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0)+(z1-z0)*(z1-z0));
floata=(x1-x0)/d,b=(y1-y0)/d,c=(z1-z0)/d;
floatv=sqrt(b*b+c*c);
Ta[0][0]=Ta[1][1]=Ta[2][2]=Ta[3][3]=1;
Ta[3][0]=-x0;
Ta[3][1]=-y0;
Ta[3][2]=-z0;
Ry_1[1][1]=Ry_1[3][3]=1;
Ry_1[0][0]=Ry_1[2][2]=v;
Ry_1[2][0]=a;
Ry_1[0][2]=-a;
Rx_1[0][0]=Rx_1[3][3]=1;
Rx_1[1][1]=Rx_1[2][2]=c/v;
Rx_1[2][1]=b/v;
Rx_1[1][2]=-b/v;
Ta_1[0][0]=Ta_1[1][1]=Ta_1[2][2]=Ta_1[3][3]=1;
Ta_1[3][0]=x0;
Ta_1[3][1]=y0;
Ta_1[3][2]=z0;
Rx[0][0]=Rx[3][3]=1;
Rx[1][1]=Rx[2][2]=c/v;
Rx[2][1]=-b/v;
Rx[1][2]=b/v;
Ry[0][0]=Ry[2][2]=v;
Ry[1][1]=Ry[3][3]=1;
Ry[2][0]=-a;
Ry[0][2]=a;
Rz[0][0]=Rz[1][1]=cos(angle);
Rz[2][2]=Rz[3][3]=1;
Rz[1][0]=-sin(angle);
Rz[0][1]=sin(angle);
MatrixMultiple(Ta,Rx);
MatrixMultiple(Rab,Ry);
MatrixMultiple(Rab,Rz);
MatrixMultiple(Rab,Ry_1);
MatrixMultiple(Rab,Rx_1);
MatrixMultiple(Rab,Ta_1);
GLvoidrotating(floatx0,floaty0,floatz0,floatx1,floaty1,floatz1,floata0,floatb0,floatc0,floata1,floatb1,floatc1,floatangle)
setTransformMatrixs(a0,b0,c0,a1,b1,c1,angle);
glColor3f(1.0f,1.0f,1.0f);
glPointSize(1.0);
floatxt=x0*Rab[0][0]+y0*Rab[1][0]+z0*Rab[2][0]+Rab[3][0];
floatyt=x0*Rab[0][1]+y0*Rab[1][1]+z0*Rab[2][1]+Rab[3][1];
floatxt_1=x1*Rab[0][0]+y1*Rab[1][0]+z1*Rab[2][0]+Rab[3][0];
floatyt_1=x1*Rab[0][1]+y1*Rab[1][1]+z1*Rab[2][1]+Rab[3][1];
glBegin(GL_LINES);
glVertex3f(xt,yt,0);
glVertex3f(xt_1,yt_1,0);
glEnd();
intDrawGLScene(GLvoid)//Here'
sWhereWeDoAllTheDrawing
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
//ClearScreenAndDepthBuffer
//ResetTheCurrentModelviewMatrix
glTranslatef(0.0f,0.0f,-600.0f);
//MoveLeft1.5UnitsAndIntoTheScreen6.0
glPointSize(1.0f);
glColor3f(1.0,1.0,1.0);
//glEnable(GL_POINT_SMOOTH);
rotating(100,0,0,
0,0,0,
0,0,0,
-150,150,0,
120);
0,0,100,
90);
0,15
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 空间 一条 直线 任意 旋转