⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oglviewer.cpp

📁 The purpose of this program is to enable building a config file to the radarFDTD package using a mo
💻 CPP
📖 第 1 页 / 共 2 页
字号:
   gluPerspective(45.0, ((GLfloat)w)/((GLfloat)h), 0.0, backClipingPlan);}void OGLViewer::paintGL () {  glClear (GL_COLOR_BUFFER_BIT);  draw_geometry();}	void OGLViewer::keyPressEvent(QKeyEvent * e) {  switch (e->key()) {    case 'z':      m_zooming = true;      m_rotating = false;      //cout << "Going to zoom...\n";      break;    case 'r':      m_rotating = true;      m_zooming = false;      break;    default:      e->ignore();      break;   }	}	void OGLViewer::mousePressEvent(QMouseEvent *e){  //cout << "Mouse press event !\n";  switch (e->button()) {  case Qt::LeftButton:    m_lastx = e->x();    m_lasty = e->y();    break;  case Qt::RightButton:		if (m_popup != NULL) {			delete m_popup;			m_popup = NULL;		}		m_popup = new QPopupMenu(this,"Message Operations");    m_popup->insertItem("&Move",this,SLOT(setMove()));		m_popup->insertItem("&Zoom", this, SLOT(setZoom()));		m_popup->insertItem("&Rotate", this, SLOT(setRotate()));		m_popup->insertItem("R&eset", this, SLOT(Reset()));    m_popup->exec(QCursor::pos());    break;  case Qt::MidButton:    break;  default:    break;  }}void OGLViewer::mouseMoveEvent(QMouseEvent *e){  //cout << "Mouse move event !\n";  if (m_moving) {    m_transx -= m_lastx - e->x();    m_transy += m_lasty - e->y();  } else if (m_zooming) {    m_transx -= m_lastx - e->x();    m_transz += m_lasty - e->y();  } else {    m_rotx += m_lastx - e->x();    m_roty -= m_lasty - e->y();  }  m_lastx = e->x();  m_lasty = e->y();  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  glMatrixMode(GL_MODELVIEW);  glLoadIdentity();  updateGL();}void OGLViewer::toggleBoxDraw(bool ){  m_drawBox = (m_drawBox) ? false : true;  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  glMatrixMode(GL_MODELVIEW);  glLoadIdentity();  draw_geometry();  updateGL();}void OGLViewer::toggleObjectsDraw(bool ){  m_drawObjects = (m_drawObjects) ? false : true;  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  glMatrixMode(GL_MODELVIEW);  glLoadIdentity();  draw_geometry();  updateGL();}void OGLViewer::toggleRCVsDraw(bool ){  m_drawRCVs = (m_drawRCVs) ? false : true;  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  glMatrixMode(GL_MODELVIEW);  glLoadIdentity();  draw_geometry();  updateGL();}void OGLViewer::toggleXMTsDraw(bool ){  m_drawXMTs = (m_drawXMTs) ? false : true;  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  glMatrixMode(GL_MODELVIEW);  glLoadIdentity();  draw_geometry();  updateGL();}void OGLViewer::setMove(){  m_moving = true;  m_zooming = false;  m_rotating = false;}void OGLViewer::setZoom(){  m_moving = false;  m_zooming = true;  m_rotating = false;}void OGLViewer::setRotate(){  m_moving = false;  m_zooming = false;  m_rotating = true;}void OGLViewer::Reset(){}void OGLViewer::axis(){  glDisable(GL_LIGHTING);  glBegin(GL_LINES);  glColor3f(1.0, 0.0, 0.0);  glVertex3f(0.0, 0.0, 0.0);  glVertex3f(10.0, 0.0, 0.0);    glColor3f(0.0, 1.0, 0.0);       glVertex3f(0.0, 0.0, 0.0);  glVertex3f(0.0, 10.0, 0.0);    glColor3f(0.0, 0.0, 1.0);       glVertex3f(0.0, 0.0, 0.0);  glVertex3f(0.0, 0.0, 10.0);  glEnd();}void OGLViewer::draw_scene(){  //printf("Trans: %g %g %g\n",m_transx,m_transy,m_transz);  glTranslatef(m_transx/3.0, m_transy/3.0, -10.0 + m_transz/3.0);  glRotatef(m_rotx, 0.0, 1.0, 0.0);  glRotatef(m_roty, 1.0, 0.0, 0.0);  glPushMatrix();  glTranslatef(-1,-1,-1);  axis();  glPopMatrix();  if (m_drawBox)    wireBox(m_Lx,m_Ly,m_Lz,1.0,1.0,0.0);}void OGLViewer::light_scene(){  //glLightfv(GL_LIGHT0, GL_POSITION, [40.0, 40, 100.00, 0.0])  //glLightfv(GL_LIGHT0, GL_DIFFUSE, [0.99, 0.99, 0.99, 1.0])  //glEnable(GL_LIGHT0)  static float v1[4] = {0, 0, 200.0, 1.0};  glLightfv(GL_LIGHT1, GL_POSITION,v1);  static float v2[4] = {1.0, 1.0, 1.0, 1.0};  glLightfv(GL_LIGHT1, GL_AMBIENT,v2);  static float v3[4] = {0.5, 0.5, 0.5, 1.0};  glLightfv(GL_LIGHT1, GL_DIFFUSE,v3);  glEnable(GL_LIGHT1);}void OGLViewer::draw_geometry(){  //cout << "Draw geometry...\n";  glMatrixMode(GL_MODELVIEW);  glLoadIdentity();  draw_scene();  glDisable(GL_LIGHTING);  if (m_drawObjects) {    glPushMatrix();    glTranslatef(0,0,0);    glCallList(1); // Objects    glPopMatrix();  }  if (m_drawXMTs) {    glPushMatrix();    glTranslatef(0,0,0);    glCallList(3); // transmitters    glPopMatrix();  }  if (m_drawRCVs) {    glPushMatrix();    glTranslatef(0,0,0);    glCallList(5); // receivers    glPopMatrix();  }  glEnable(GL_LIGHTING);  light_scene();}void OGLViewer::takeGeometry(QValueList<object_t>& geom,                             int Lx, int Ly, int Lz){  //cout << "takeGeometry ...\n";  m_Lx = (float)Lx;  m_Ly = (float)Ly;  m_Lz = (float)Lz;	double lx=0.0, ly=0.0, lz = 0.0;	// Delete old list	glDeleteLists(1,1);	glNewList(1, GL_COMPILE);	glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 1.0);	float v1[4] = {0.3, 0.3, 0.3, 1.0};	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE,v1);	float v2[4] = {1.0, 1.0, 1.0, 1.0};	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT,v2);  glTranslatef(0,0,0);	for (unsigned int i=0; i<geom.size(); i++) {		for (unsigned int j=0; j<geom[i].boxes.size(); j++) {      if (geom[i].boxes.size() == 1) { // For a  box        // The wireBox is not centered         double vx = geom[i].boxes[j].x0;        double vy = geom[i].boxes[j].y0;        double vz = geom[i].boxes[j].z0;        glTranslatef(vx-lx, vy-ly, vz-lz);        lx = vx;        ly = vy;        lz = vz;        QColor c = m_colMap[geom[i].boxes[j].material_indx];        wireBox(geom[i].boxes[j].x1-geom[i].boxes[j].x0,                geom[i].boxes[j].y1-geom[i].boxes[j].y0,                geom[i].boxes[j].z1-geom[i].boxes[j].z0,                c.red()/255.0,c.green()/255.0,c.blue()/255.0);      } else {        // Cube center        double vx = abs(geom[i].boxes[j].x0 + geom[i].boxes[j].x1)/2.0;        double vy = abs(geom[i].boxes[j].y0 + geom[i].boxes[j].y1)/2.0;        double vz = abs(geom[i].boxes[j].z0 + geom[i].boxes[j].z1)/2.0;        glTranslatef(vx-lx, vy-ly, vz-lz);        lx = vx;        ly = vy;        lz = vz;        QColor c = m_colMap[geom[i].boxes[j].material_indx];        //cout << "indx: " << geom[i].boxes[j].material_indx << " [" << c.red()        //   << " " << c.green() << " " << c.blue() << "]\n";        wireCube(1.0,c.red()/255.0,c.green()/255.0,c.blue()/255.0);      }		}	}	glEndList();  if (m_drawObjects)     glCallList(1);  //draw_geometry();	updateGL();}void OGLViewer::takeXMTs(QValueList<xmt_t>& xmts, int polarization){	double lx=0.0, ly=0.0, lz = 0.0;	glDeleteLists(3,1);	glNewList(3, GL_COMPILE);  //cout << "Taking XMTs ...\n";  glTranslatef(0,0,0);  for (unsigned int cnt=0; cnt<xmts.size(); cnt++) {    //cout << "Add " << cnt << endl;    for (int i=xmts[cnt].x0; i<=xmts[cnt].x1; i+=xmts[cnt].skip) {      for (int j=xmts[cnt].y0; j<=xmts[cnt].y1; j+=xmts[cnt].skip) {        for (int k=xmts[cnt].z0; k<=xmts[cnt].z1; k+=xmts[cnt].skip) {          double vx = (double)i;          double vy = (double)j;          double vz = (double)k;          glTranslatef(vx-lx, vy-ly, vz-lz);          lx = vx;          ly = vy;          lz = vz;          drawXMT(polarization);        }      }    }  }  glEndList();  if (m_drawXMTs)    glCallList(3);  //draw_geometry();	updateGL();}void OGLViewer::takeRCVs(QValueList<rcv_t>& rcvs){	double lx=0.0, ly=0.0, lz = 0.0;	glDeleteLists(5,1);	glNewList(5, GL_COMPILE);  //cout << "Taking RCVs ...\n";  glTranslatef(0,0,0);  for (unsigned int cnt=0; cnt<rcvs.size(); cnt++) {    //cout << "Add " << cnt << endl;    for (int i=rcvs[cnt].x0; i<=rcvs[cnt].x1; i+=rcvs[cnt].skip) {      for (int j=rcvs[cnt].y0; j<=rcvs[cnt].y1; j+=rcvs[cnt].skip) {        for (int k=rcvs[cnt].z0; k<=rcvs[cnt].z1; k+=rcvs[cnt].skip) {          double vx = (double)i;          double vy = (double)j;          double vz = (double)k;          glTranslatef(vx-lx, vy-ly, vz-lz);          lx = vx;          ly = vy;          lz = vz;          drawRCV(rcvs[cnt].component);        }      }    }  }  glEndList();  if (m_drawRCVs)    glCallList(5);  //draw_geometry();	updateGL();}void OGLViewer::refresh(){  updateGL();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -