//--------------------------------------------------------------------------- void CFabAtHomeView::Pick(UINT nFlags, CPoint point) //--------------------------------------------------------------------------- {// find objects in selction zone if(!this->bShowModel) return; #define BUFSIZE 1000 GLuint selectBuf[BUFSIZE]; GLint hits=0, viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPickMatrix(point.x, viewport[3]-point.y, 5, 5, viewport); SetViewTransformation(); glMatrixMode(GL_MODELVIEW); glSelectBuffer(BUFSIZE, selectBuf); glRenderMode(GL_SELECT); glInitNames(); DrawScene(); hits = glRenderMode(GL_RENDER); glMatrixMode(GL_PROJECTION); glLoadIdentity(); SetViewTransformation(); glMatrixMode(GL_MODELVIEW); // deselect all if necessary CFabAtHomeDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if ((nFlags & MK_SHIFT) == 0) { pDoc->model.SelectAll(false); } // parse hit buffer and select items int idx=0,v; for (int hit = 0; hit<hits; hit++) { int names = selectBuf[idx]; if (names == 2) { switch (selectBuf[idx+3]) { case NAMESTACK_CHUNK: v = selectBuf[idx+4]; ASSERT(v >= 0 && v <= pDoc->model.chunk.GetSize()); pDoc->model.SelectOneChunk(v); pDoc->UpdateAllViews(0); return; break; } } idx += 3+names; } pDoc->UpdateAllViews(0); }
//--------------------------------------------------------------------------- void CFabAtHomeView::UpdatePerspective() //--------------------------------------------------------------------------- {// update perspective parameters wglMakeCurrent(m_pDC->GetSafeHdc(), hrc); glMatrixMode(GL_PROJECTION); glLoadIdentity(); SetViewTransformation(); glMatrixMode(GL_MODELVIEW); }
/********************************************************** * * SetViewVariables * * parameters IN : * MyMatrix & viewTransformation * *********************************************************/ void ViewPointRec::SetViewVariables (MyMatrix & viewTransformation) { sinTheta = sin ( Util::InRadians (theta) ); cosTheta = cos ( Util::InRadians (theta) ); sinPhi = sin ( Util::InRadians (phi) ); cosPhi = cos ( Util::InRadians (phi) ); xView = rho * cosTheta * sinPhi; yView = rho * sinTheta * sinPhi; zView = rho * cosPhi; SetViewTransformation (viewTransformation); }
void SetViewVariables(ViewPointRec *view_ref_point, Matrix * view_transformation){ view_ref_point->sin_theta = 0; view_ref_point->cos_theta = 0; view_ref_point->sin_phi = 0; view_ref_point->cos_phi = 0; view_ref_point->sin_theta = sin(InRadians(view_ref_point->theta)); view_ref_point->cos_theta = cos(InRadians(view_ref_point->theta)); view_ref_point->sin_phi = sin(InRadians(view_ref_point->phi)); if (view_ref_point->phi == 90){ view_ref_point->cos_phi = 0; } else view_ref_point->cos_phi = cos(InRadians(view_ref_point->phi)); view_ref_point->x_view = view_ref_point->rho * view_ref_point->cos_theta * view_ref_point->sin_phi; view_ref_point->y_view = view_ref_point->rho * view_ref_point->sin_theta * view_ref_point->sin_phi; view_ref_point->z_view = view_ref_point->rho * view_ref_point->cos_phi; SetViewTransformation(view_ref_point, *view_transformation); }
//--------------------------------------------------------------------------- void CFabAtHomeView::InitGL() //--------------------------------------------------------------------------- { PIXELFORMATDESCRIPTOR pfd; int n; GLfloat fMaxObjSize, fAspect; GLfloat fNearPlane, fFarPlane; m_pDC = new CClientDC(this); ASSERT(m_pDC != NULL); if (!bSetupPixelFormat()) return; n = ::GetPixelFormat(m_pDC->GetSafeHdc()); ::DescribePixelFormat(m_pDC->GetSafeHdc(), n, sizeof(pfd), &pfd); hrc = wglCreateContext(m_pDC->GetSafeHdc()); wglMakeCurrent(m_pDC->GetSafeHdc(), hrc); GetClientRect(&m_oldRect); glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); if (m_oldRect.bottom) fAspect = (GLfloat)m_oldRect.right/m_oldRect.bottom; else // don't divide by zero, not that we should ever run into that... fAspect = 1.0f; fNearPlane = 0.0f; fFarPlane = 100.0f; fMaxObjSize = 3.0f; m_fRadius = fNearPlane + fMaxObjSize / 2.0f; //initialize the panning/zooming cursor start point. startPoint = m_oldRect.CenterPoint(); // initialize rolling matrix with unity glPushMatrix(); glLoadIdentity(); glRotated(-90,0,0,1); glRotated(-60,0,1,0); glScaled(scale, scale, scale); glGetDoublev(GL_MODELVIEW_MATRIX, rotmat); glPopMatrix(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); SetViewTransformation(); glMatrixMode(GL_MODELVIEW); // Load character Set // BOOL CreateFont( int nHeight, int nWidth, int nEscapement, int nOrientation, // int nWeight, BYTE bItalic, BYTE bUnderline, BYTE cStrikeOut, BYTE nCharSet, // BYTE nOutPrecision, BYTE nClipPrecision, BYTE nQuality, // BYTE nPitchAndFamily, LPCTSTR lpszFacename ); CFont times; times.CreateFont(0,0,0,0, FW_NORMAL,FALSE,FALSE,0,DEFAULT_CHARSET, OUT_TT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY, DEFAULT_PITCH,"Times New Roman"); // m_pDC->SelectObject(GetStockObject(SYSTEM_FONT)); m_pDC->SelectObject(×); // create the bitmap display lists // we're making images of glyphs 0 thru 255 // the display list numbering starts at 1000, an arbitrary choice wglUseFontBitmaps(m_pDC->GetSafeHdc(), 0, 255, 1000); // display a string: // indicate start of glyph display lists glListBase(1000); // to draw the characters in a string, do, for example: // glCallLists(24, GL_UNSIGNED_BYTE, "Hello Win32 OpenGL World"); }