void myGlutMouse(int button, int state, int x, int y){ GLint viewport[4]; ::glGetIntegerv(GL_VIEWPORT,viewport); const int win_w = viewport[2]; const int win_h = viewport[3]; mov_begin_x = (2.0*x-win_w)/win_w; mov_begin_y = (win_h-2.0*y)/win_h; imodifier = ::glutGetModifiers(); if( state == GLUT_DOWN && imodifier == 0 ){ const unsigned int size_buffer = 2048; unsigned int selec_buffer[size_buffer]; Com::View::PickPre(size_buffer,selec_buffer, x,y,5,5, camera); drawer_ary.DrawSelection(); std::vector<Com::View::SSelectedObject> aSelecObj = Com::View::PickPost(selec_buffer, x,y, camera ); drawer_ary.ClearSelected(); if( aSelecObj.size() > 0 ){ drawer_ary.AddSelected( aSelecObj[0].name ); if( aSelecObj[0].name[1] == 3 ){ id_loop_selected = aSelecObj[0].name[2]; picked_pos = aSelecObj[0].picked_pos; } else{ id_loop_selected = 0; } mouse_pos = picked_pos; } } if( state == GLUT_UP && imodifier == 0 ){ if( imode == 1 ){ if( cad_3d.IsElemID(Cad::LOOP,id_loop_selected) ){ const Cad::CLoop3D& l = cad_3d.GetLoop(id_loop_selected); const Com::CVector2D v0 = l.Project(picked_pos); const Com::CVector2D v1 = l.Project(mouse_pos); cad_3d.AddRectLoop(id_loop_selected,v0,v1); id_loop_selected = 0; drawer_ary.Clear(); drawer_ary.PushBack( new Cad::View::CDrawer_Cad3D(cad_3d) ); } } } }
bool SetNewProblem() { const unsigned int nprob = 4; static unsigned int iprob = 0; std::cout << "SetNewProblem() " << iprob << std::endl; cad_3d.Clear(); if( iprob == 0 ){ unsigned int id_s0 = cad_3d.AddCuboid(1,1,1); drawer_ary.Clear(); drawer_ary.PushBack( new Cad::View::CDrawer_Cad3D(cad_3d) ); drawer_ary.InitTrans(camera); } if( iprob == 1 ){ unsigned int id_s0 = cad_3d.AddCuboid(1,1,0.7); unsigned int id_l1 = 0; { std::vector<Com::CVector3D> aVec; aVec.push_back( Com::CVector3D(0.5,0.2,0.7) ); aVec.push_back( Com::CVector3D(0.8,0.2,0.7) ); aVec.push_back( Com::CVector3D(0.8,0.8,0.7) ); aVec.push_back( Com::CVector3D(0.5,0.8,0.7) ); id_l1 = cad_3d.AddPolygon(aVec,6); } unsigned int id_l2 = 0; { std::vector<Com::CVector3D> aVec; aVec.push_back( Com::CVector3D(0.2,1.0,0.3) ); aVec.push_back( Com::CVector3D(0.2,1.0,0.5) ); aVec.push_back( Com::CVector3D(0.8,1.0,0.5) ); aVec.push_back( Com::CVector3D(0.8,1.0,0.3) ); id_l2 = cad_3d.AddPolygon(aVec,3); } cad_3d.LiftLoop(id_l1,cad_3d.GetLoop(id_l1).normal* 0.2); cad_3d.LiftLoop(id_l2,cad_3d.GetLoop(id_l2).normal*-0.2); { const unsigned int id_v1 = cad_3d.AddPoint( Cad::EDGE,1, Com::CVector3D(0,0.7,0 ) ); const unsigned int id_v2 = cad_3d.AddPoint( Cad::EDGE,9, Com::CVector3D(0,0.7,0.7) ); Cad::CBRepSurface::CResConnectVertex res = cad_3d.ConnectVertex(id_v1, id_v2); unsigned int id_l_lift = cad_3d.GetIdLoop_Edge(res.id_e_add,true); cad_3d.LiftLoop(id_l_lift,cad_3d.GetLoop(id_l_lift).normal*0.2); } { const unsigned int id_v1 = cad_3d.AddPoint( Cad::EDGE,9, Com::CVector3D(0,0.3,0.7 ) ); const unsigned int id_v2 = cad_3d.AddPoint( Cad::EDGE,5, Com::CVector3D(0,0.0,0.2 ) ); const unsigned int id_v3 = cad_3d.AddPoint( Cad::LOOP,17,Com::CVector3D(0,0.3,0.2 ) ); cad_3d.ConnectVertex(id_v1, id_v3); Cad::CBRepSurface::CResConnectVertex res = cad_3d.ConnectVertex(id_v2, id_v3); unsigned int id_l_lift = res.id_l_add; cad_3d.LiftLoop(id_l_lift,cad_3d.GetLoop(id_l_lift).normal*-0.2); } cad_3d.LiftLoop(6,Com::CVector3D(0,0,-0.1)); { const unsigned int id_v1 = cad_3d.AddPoint( Cad::EDGE,3, Com::CVector3D(1.0,0.2,0.0 ) ); const unsigned int id_v2 = cad_3d.AddPoint( Cad::LOOP,4, Com::CVector3D(1.0,0.2,0.2 ) ); const unsigned int id_v3 = cad_3d.AddPoint( Cad::LOOP,4, Com::CVector3D(1.0,0.6,0.2 ) ); const unsigned int id_v4 = cad_3d.AddPoint( Cad::EDGE,3, Com::CVector3D(1.0,0.6,0.0 ) ); cad_3d.ConnectVertex(id_v1, id_v2); cad_3d.ConnectVertex(id_v2, id_v3); Cad::CBRepSurface::CResConnectVertex res = cad_3d.ConnectVertex(id_v3, id_v4); unsigned int id_l_lift = res.id_l_add; cad_3d.LiftLoop(id_l_lift,cad_3d.GetLoop(id_l_lift).normal*-0.1); } drawer_ary.Clear(); drawer_ary.PushBack( new Cad::View::CDrawer_Cad3D(cad_3d) ); drawer_ary.InitTrans(camera); } if( iprob == 2 ){ unsigned int id_s0 = cad_3d.AddCuboid(1,1,1); cad_3d.AddRectLoop(1, Com::CVector2D(0.2,0.2), Com::CVector2D(0.8,1.2) ); cad_3d.LiftLoop(1,cad_3d.GetLoop(1).normal*0.1); // cad_3d.LiftLoop(7,cad_3d.GetLoop(7).normal*0.1); drawer_ary.Clear(); drawer_ary.PushBack( new Cad::View::CDrawer_Cad3D(cad_3d) ); drawer_ary.InitTrans(camera); } if( iprob == 3 ){ unsigned int id_s0 = cad_3d.AddCuboid(1,1,1); cad_3d.AddRectLoop(6, cad_3d.GetLoop(6).Project(Com::CVector3D(0.2,0.2,1)), cad_3d.GetLoop(6).Project(Com::CVector3D(0.8,0.8,1)) ); cad_3d.AddRectLoop(7, cad_3d.GetLoop(7).Project(Com::CVector3D(0.3,0.3,1)), cad_3d.GetLoop(7).Project(Com::CVector3D(0.7,0.7,1)) ); // cad_3d.AddRectLoop(7, Com::CVector2D(0.3,0.3), Com::CVector2D(0.7,0.7) ); cad_3d.LiftLoop(7,cad_3d.GetLoop(7).normal*0.1); drawer_ary.Clear(); drawer_ary.PushBack( new Cad::View::CDrawer_Cad3D(cad_3d) ); drawer_ary.InitTrans(camera); } ::glMatrixMode(GL_PROJECTION); ::glLoadIdentity(); Com::View::SetProjectionTransform(camera); iprob++; if( iprob == nprob ) iprob=0; return true; }