Exemplo n.º 1
0
void myGlutMotion( int x, int y ){
	GLint viewport[4];
	::glGetIntegerv(GL_VIEWPORT,viewport);
	const int win_w = viewport[2];
	const int win_h = viewport[3];
	const double mov_end_x = (2.0*x-win_w)/win_w;
	const double mov_end_y = (win_h-2.0*y)/win_h;
	if(      imodifier == GLUT_ACTIVE_CTRL ){
		camera.MouseRotation(mov_begin_x,mov_begin_y,mov_end_x,mov_end_y); 
	}
	else if( imodifier == GLUT_ACTIVE_SHIFT ){
		camera.MousePan(mov_begin_x,mov_begin_y,mov_end_x,mov_end_y); 
	}
  else if( cad_3d.IsElemID(Cad::LOOP,id_loop_selected) ){    
    if( imode == 0 ){
      if( cad_3d.IsElemID(Cad::LOOP,id_loop_selected) ){
        Com::CVector3D nv = cad_3d.GetLoop(id_loop_selected).normal;
        double n[3] = { nv.x, nv.y, nv.z };
        double r[9];  camera.RotMatrix33(r);
        double nr[3] = { r[0]*n[0]+r[1]*n[1]+r[2]*n[2], r[3]*n[0]+r[4]*n[1]+r[5]*n[2], r[6]*n[0]+r[7]*n[1]+r[8]*n[2] };
        double del[2] = { mov_end_x-mov_begin_x, mov_end_y-mov_begin_y };
        nr[0] /= camera.GetHalfViewHeight()*camera.GetWindowAspect();
        nr[1] /= camera.GetHalfViewHeight();
        if( nr[0]*nr[0] + nr[1]*nr[1] > 1.0e-5 ){
          double r = (nr[0]*del[0]+nr[1]*del[1])/(nr[0]*nr[0]+nr[1]*nr[1]);
          cad_3d.LiftLoop(id_loop_selected,nv*r);
          drawer_ary.Clear();
          drawer_ary.PushBack( new Cad::View::CDrawer_Cad3D(cad_3d) );    
        }              
      }
    }
    if( imode == 1 ){      
      if( cad_3d.IsElemID(Cad::LOOP,id_loop_selected) ){
        const Cad::CLoop3D& l = cad_3d.GetLoop(id_loop_selected);
        const Com::CVector3D& o0 = l.org; 
        const Com::CVector3D& n0 = l.normal;
        Com::CMatrix3 r = camera.RotMatrix33();      
        Com::CVector3D d1 = r.MatVecTrans( Com::CVector3D(0,0,-1) );
        double hvh = camera.GetHalfViewHeight();
        double asp = camera.GetWindowAspect();
        Com::CVector3D cp = -camera.GetCenterPosition()+Com::CVector3D(hvh*asp*mov_end_x,hvh*mov_end_y,0);
        Com::CVector3D o1 = r.MatVecTrans( cp ) + camera.GetObjectCenter();
        double tmp0 = Dot(d1,n0);
        double tmp1 = Dot(o0-o1,n0);
        double tmp2 = tmp1/tmp0;
        mouse_pos = o1+d1*tmp2;
      }
    }
  }
	mov_begin_x = mov_end_x;
	mov_begin_y = mov_end_y;
	::glutPostRedisplay();
}
Exemplo n.º 2
0
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;
}