void CRenWin3D::DrawAxis() { glDisable(GL_LIGHTING); glClear(GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(-2.0f, 2.0f, -1.5f, 1.5f, 0.1f, 100.0f); glm::mat4 rotMx = glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), m_front, m_up); glm::vec4 vecX(0.1f, 0.0f, 0.0f, 1.0f); glm::vec4 vecY(0.0f, 0.1f, 0.0f, 1.0f); glm::vec4 vecZ(0.0f, 0.0f, 0.1f, 1.0f); vecX = rotMx * vecX; vecY = rotMx * vecY; vecZ = rotMx * vecZ; glTranslatef(-1.9f, -1.4f, -20.0f); glColor3f(1.0f, 0.0f, 0.0f); glBegin(GL_LINES); glVertex3f(0.0f, 0.0f, 0.0f); glVertex3f(vecX.x, vecX.y, vecX.z); glEnd(); glColor3f(0.0f, 1.0f, 0.0f); glBegin(GL_LINES); glVertex3f(0.0f, 0.0f, 0.0f); glVertex3f(vecY.x, vecY.y, vecY.z); glEnd(); glColor3f(0.0f, 0.0f, 1.0f); glBegin(GL_LINES); glVertex3f(0.0f, 0.0f, 0.0f); glVertex3f(vecZ.x, vecZ.y, vecZ.z); glEnd(); glPopMatrix(); glMatrixMode(GL_MODELVIEW); if(m_lighting) { glEnable(GL_LIGHTING); } glColor3f(1.0f, 1.0f, 1.0f); }
//------------------------------------------------------------------------------------------- // // 功能: 第二条直线的起点移动到第一条直线的中点位置, // 并通过构造旋转矩阵使得第二条直线和第一条直线垂直 // // 作者:Qin H.X. // // 日期:200709 // // 历史:无 // //---------------------------------------------------------------------------------------------- // - CGDCH06.TransformLine command (do not rename) static void CGDCH06TransformLine(void) { ads_name ename1,ename2; ads_point pickpt; if (acedEntSel(_T("\n选择直线1: "), ename1, pickpt) != RTNORM) { acutPrintf(_T("\n选择直线1失败")); return ; } if (acedEntSel(_T("\n选择直线2: "), ename2, pickpt) != RTNORM) { acutPrintf(_T("\n选择直线2失败")); return ; } AcDbObjectId IdLine1,IdLine2; acdbGetObjectId(IdLine1, ename1); acdbGetObjectId(IdLine2, ename2); //直线对象 AcDbLine *pLine1 = NULL; AcDbLine *pLine2 = NULL; //以读方式打开实体 if(Acad::eOk == acdbOpenObject(pLine1, IdLine1, AcDb::kForRead)) { if(Acad::eOk == acdbOpenObject(pLine2, IdLine2, AcDb::kForRead)) { // 计算第一条直线的中点 AcGePoint3d ptMid; ptMid.x = 0.5*(pLine1->endPoint ().x + pLine1->startPoint ().x); ptMid.y= 0.5*(pLine1->endPoint ().y + pLine1->startPoint ().y); ptMid.z = 0.5*(pLine1->endPoint ().z + pLine1->startPoint ().z); // 第二条直线起点到第一条直线的向量 AcGeVector3d vecMove = ptMid - pLine2->startPoint (); // 构造平移矩阵 AcGeMatrix3d mat,mat1; mat = mat.translation (vecMove); // 修改第二条直线 pLine2->upgradeOpen (); pLine2->transformBy (mat); //计算两条直线的夹角 AcGeVector3d vec1 = pLine1->endPoint ()- pLine1->startPoint (); AcGeVector3d vec2 = pLine2->endPoint ()- pLine2->startPoint (); double dAng; dAng = vec1.angleTo(vec2); AcGeVector3d vecZ(0.0,0.0,1.0); //计算旋转角度 double dRot; if(dAng<0.5*PI) { dRot = 0.5*PI - dAng; } else { dRot =dAng - 0.5*PI ; } // 构造旋转矩阵 mat1 = mat1.rotation (dRot,vecZ,pLine2->startPoint ()); //对直线进行旋转变换 pLine2->transformBy (mat1); pLine2->setColorIndex (1); //关闭实体 pLine2->close(); acutPrintf(_T("\n 操作完成 。")); } //关闭实体 pLine1->close(); } // Add your code for command CGDCH06.TransformLine here }