当前位置: 首页>>代码示例>>C++>>正文


C++ Matrix4d::GetPtr方法代码示例

本文整理汇总了C++中Matrix4d::GetPtr方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrix4d::GetPtr方法的具体用法?C++ Matrix4d::GetPtr怎么用?C++ Matrix4d::GetPtr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Matrix4d的用法示例。


在下文中一共展示了Matrix4d::GetPtr方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: MouseEventHandler

void GraphicCamera::MouseEventHandler(int button, int state, int x, int y){ 
  double realy, wx, wy, wz;
  // if ALT key used
//  int mode = glutGetModifiers();  
  
  if (state == GLUT_UP && CameraMode != kINACTIVE) {
    current_elev += dt_elev;
    current_azim += dt_azim;
    //reset change in elevation and roll of the camera;
    dt_elev = dt_azim = 0.0;
    CameraMode = kINACTIVE;
  } else if (state == GLUT_DOWN) { 
    MouseStartX = MousePrevX = x;
    MouseStartY = MousePrevY = y;
    switch(button) {
      case GLUT_LEFT_BUTTON:
        //rotating 
        CameraMode = kROTATE;
        break;
      case GLUT_MIDDLE_BUTTON:
        // translating
        CameraMode = kTRANSLATE;
        glGetIntegerv(GL_VIEWPORT, ViewPort);
        glGetDoublev(GL_MODELVIEW_MATRIX, MvMat.GetPtr());
        glGetDoublev(GL_PROJECTION_MATRIX, ProjMat.GetPtr());
        // height of window in pixels
        realy = ViewPort[3] - y - 1;
        gluProject(aim_.x(), aim_.y(), aim_.z(), MvMat.GetPtr(), 
                   ProjMat.GetPtr(), ViewPort, &wx, &wy, &wz);
        gluUnProject((GLdouble) x, (GLdouble) realy, wz, MvMat.GetPtr(),
                     ProjMat.GetPtr(), ViewPort, &PrevMousePos.x(), 
                     &PrevMousePos.y(), &PrevMousePos.z()); 
        break;
      case GLUT_RIGHT_BUTTON:
        CameraMode = kZOOM;
        break;
    }
  }
}
开发者ID:cecilulysess,项目名称:GraphicLibrary,代码行数:39,代码来源:GraphicCamera.cpp

示例2: MouseMotionEventHandler

void GraphicCamera::MouseMotionEventHandler(int x, int y) {
  int mouse_dx, mouse_dy, d;
  double z;
  Vec3d mouse_pos, dir;
  Vec3d WndX, WndY, WndZ;
  float realy;
  double wx, wy, wz;

  if (CameraMode != kINACTIVE) {
    mouse_dx = x - MousePrevX;
    mouse_dy = y - MousePrevY;

    if (abs(mouse_dx) > abs(mouse_dy)) {
      d = mouse_dx;
    } else {
      d = mouse_dy;
    }

    switch(CameraMode) {

      case kZOOM:
        z = (double) d / 100.0;
        dir = aim_ - pos_;
        if (dir.Norm() < 0.1 && z > 0) {
          z *= 10.0;
          aim_ = aim_ + z * dir;
        }
        pos_ = pos_ + z * dir;
        break;
      case kROTATE:
        dt_azim = ((double) (x - MouseStartX)) / 5.0;
        dt_elev = ((double) (y - MouseStartY)) / 5.0;
        
        loc_dt_azim = ((double) mouse_dx) / 5.0;
        loc_dt_elev = ((double) mouse_dy) / 5.0;

        WndX = {1.0, 0.0, 0.0};
        WndY = {0.0, 1.0, 0.0};

        RotateX(WndX, current_elev + dt_elev);
        RotateY(WndX, current_azim + dt_azim);
        WndX.z() *= -1;
        
        RotateX(WndY, current_elev + dt_elev);
        RotateY(WndY, current_azim + dt_azim);
        WndY.z() *= -1;

        WndZ = (WndX % WndY).Normalization();

        ArbitraryRotate(WndX, WndY, WndZ, loc_dt_elev, 0, pos_, aim_);
        ArbitraryRotate(Vec3d(1, 0, 0), Vec3d(0, 1, 0), Vec3d(0, 0, 1), 0,
                        -loc_dt_azim, pos_, aim_);
        up_ = WndY.Normalization();

        break;
      case kTRANSLATE:

        realy = ViewPort[3] - y - 1;
        gluProject(aim_.x(), aim_.y(), aim_.z(), MvMat.GetPtr(),
                   ProjMat.GetPtr(), ViewPort,
                   &wx, &wy, &wz);

        gluUnProject((GLdouble) x, (GLdouble) realy, wz, MvMat.GetPtr(),
                     ProjMat.GetPtr(),
                     ViewPort, &mouse_pos.x(), &mouse_pos.y(), 
                     &mouse_pos.z());
        
        // move both the camera position and its aim coordinate
        dir = mouse_pos - PrevMousePos;
        pos_ = pos_ - dir;
        aim_ = aim_ - dir;

        PrevMousePos = mouse_pos;
        break;
    }
    MousePrevX = x;
    MousePrevY = y;
  }
}
开发者ID:cecilulysess,项目名称:GraphicLibrary,代码行数:79,代码来源:GraphicCamera.cpp


注:本文中的Matrix4d::GetPtr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。