for(i=0;i<3;i++)
e[i]=0;
for(i=0;i<3;i++) //向量在局部坐标系中的表示,坐
标变换P=PA
for(j=0;j<3;j++) //矩阵A的第4行表示平移,第4列表示投影
}
void ProcessMoving(Point3I curPoint) {
downPoint.x=m_downPoint.x; downPoint.y=m_downPoint.y;
double cosa; //旋转角余弦
Point3I downPoint; //鼠标相对于窗口左上角象素坐标
for(i=0;i<3;i++)
p[i]=e[i];
e[i]+=p[j]*a[j][i];
///////////////////////////////////////////////////////////
//把鼠标在屏幕上的移动看成是在(椭)球面上的移动
//开始转换坐标,将平面坐标系转换为原点在客户区中心的三维笛卡尔坐标 //计算球面上点的坐标
downPoint.x=(long)(downPoint.x-m_clientWidth/2); downPoint.y=(long)(m_clientHeight/2-downPoint.y);
/4;
4;
downPoint.z=(m_clientWidth*m_clientWidth+m_clientHeight*m_clientHeight)
downPoint.z=downPoint.z-
(downPoint.x*downPoint.x+downPoint.y*downPoint.y);
if(downPoint.z>0)
downPoint.z=(long)sqrt((double)downPoint.z);
else
downPoint.z=0;
curPoint.x=curPoint.x-m_clientWidth/2; curPoint.y=m_clientHeight/2-curPoint.y;
curPoint.z=(m_clientWidth*m_clientWidth+m_clientHeight*m_clientHeight)/
curPoint.z=curPoint.z-(curPoint.x*curPoint.x+curPoint.y*curPoint.y); if(curPoint.z>0)
curPoint.z=(long)sqrt((double)curPoint.z);
else
curPoint.z=0;
/////坐标转换完毕///////////////////////
if(m_transMode==TRANSLATE)//水平和垂直平移 {
m_rotation=0.0;
m_translate[0]=(curPoint.x-downPoint.x)/m_clientWidth; m_translate[1]=(curPoint.y-downPoint.y)/m_clientHeight;
}
m_translate[2]=0;
Localize(m_translate);//平移量转化为局部坐标系中的值
if(m_transMode==SCALE) //缩放 {
m_rotation=0.0; m_translate[0]=0.0; m_translate[1]=0.0; m_translate[2]=0.0;
m_ratio=(1-(curPoint.y-downPoint.y)/(double)m_clientHeight);
}
if(m_transMode==ROTATE ) //旋转 {
m_translate[0]=0.0; m_translate[1]=0.0; m_translate[2]=0.0; m_ratio=1;
cosa=downPoint.x*curPoint.x+ downPoint.y*curPoint.y+
downPoint.z*curPoint.z;
cosa=cosa/sqrt((double)downPoint.x*downPoint.x+ downPoint.y*downPoint.y+
downPoint.z*downPoint.z);
表示
}
cosa=cosa/sqrt((double)curPoint.x*curPoint.x+ curPoint.y*curPoint.y+
curPoint.z*curPoint.z);
if(cosa>1-0.00001)
m_rotation=0.0;
else if(cosa<-1+0.00001)
m_rotation=90.0;
else {
m_rotation=acos(cosa);
m_rotation=m_rotation*180/3.14159; }
m_axis[0]=downPoint.y*curPoint.z-downPoint.z*curPoint.y; m_axis[1]=downPoint.z*curPoint.x-downPoint.x*curPoint.z; m_axis[2]=downPoint.x*curPoint.y-downPoint.y*curPoint.x;
Localize(m_axis); //旋转轴转换为局部坐标系中的
}
void GeometryTransfer() {
if(m_transMode == ROTATE) {
}
}
glRotated(m_rotation,m_axis[0],m_axis[1],m_axis[2]);
m_rotation = 0;
else if(m_transMode==TRANSLATE) {
int i;
for(i = 0; i < 3; i++)
m_translate[i] *= m_clip;
}
glTranslated(m_translate[0],m_translate[1],m_translate[2]);
for(i = 0; i < 3; i++)
m_translate[i] = 0;
else //if(m_transMode==SCALE) { }
glScaled(m_ratio, m_ratio, m_ratio);
m_ratio=1;
void MakeParabolicSurface()