glcanvas3d.cpp

来自「ncbi源码」· C++ 代码 · 共 170 行

CPP
170
字号
/* * =========================================================================== * PRODUCTION $Log: glcanvas3d.cpp,v $ * PRODUCTION Revision 1000.2  2004/06/01 20:50:35  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.7 * PRODUCTION * =========================================================================== *//*  $Id: glcanvas3d.cpp,v 1000.2 2004/06/01 20:50:35 gouriano Exp $ * =========================================================================== * *                            PUBLIC DOMAIN NOTICE *               National Center for Biotechnology Information * *  This software/database is a "United States Government Work" under the *  terms of the United States Copyright Act.  It was written as part of *  the author's official duties as a United States Government employee and *  thus cannot be copyrighted.  This software/database is freely available *  to the public for use. The National Library of Medicine and the U.S. *  Government have not placed any restriction on its use or reproduction. * *  Although all reasonable efforts have been taken to ensure the accuracy *  and reliability of the software and data, the NLM and the U.S. *  Government do not and cannot warrant the performance or results that *  may be obtained by using this software or data. The NLM and the U.S. *  Government disclaim all warranties, express or implied, including *  warranties of performance, merchantability or fitness for any particular *  purpose. * *  Please cite the author in any work or product based on this material. * * =========================================================================== * * Authors:  Mike DiCuccio * * File Description: *    CGlCanvas3d -- provide standardized OpenGL view setup for FLTK */#include <ncbi_pch.hpp>#include <gui/opengl/glcanvas3d.hpp>BEGIN_NCBI_SCOPECGlCanvas3d::CGlCanvas3d(int x, int y, int width, int height, const char* label)    : CGlCanvas(x, y, width, height, label){    m_Camera.SetLayout(CGlCamera::ePerspective);    m_Camera.SetNearPlane  (0.1f);    m_Camera.SetFarPlane   (1000.0f);    m_Camera.SetFieldOfView(45.0f);    m_Camera.SetAspectRatio(float(w()) / float(h()));}CGlCanvas3d::~CGlCanvas3d(void){}void CGlCanvas3d::resize(int x, int y, int w, int h){    CGlCanvas::resize(x, y, w, h);    m_Camera.SetAspectRatio(float(w) / float(h));}//// CGlCanvas3d::setupView(void)// this function is responsible for establishing the standard view// setup parameters, including viewport and viewing matrices//void CGlCanvas3d::x_SetupView(void){    // set up a standard viewport    glViewport(0, 0, w(), h());    // set our viewing matrices.  we don't save the old matrices, so there is    // no need to call ReleaseCurrent().    // we also make sure that our aspect ratio is up-to-date    m_Camera.MakeCurrent();    // always leave in modelview matrix    glMatrixMode(GL_MODELVIEW);    glLoadIdentity();}void CGlCanvas3d::Project(float& x, float& y,float& z) const{    GLint viewport[4];    GLdouble proj_matrix[16];    GLdouble model_matrix[16];    glGetDoublev(GL_PROJECTION_MATRIX, proj_matrix);    glGetDoublev(GL_MODELVIEW_MATRIX,  model_matrix);    glGetIntegerv(GL_VIEWPORT, viewport);    GLdouble px = 0.0;    GLdouble py = 0.0;    GLdouble pz = 0.0;    gluProject(x, y, z, model_matrix, proj_matrix, viewport,               &px, &py, &pz);    x = (float)px;    y = (float)py;    z = (float)pz;}void CGlCanvas3d::Unproject(float& x, float& y,float& z) const{    GLint viewport[4];    GLdouble proj_matrix[16];    GLdouble model_matrix[16];    glGetDoublev(GL_PROJECTION_MATRIX, proj_matrix);    glGetDoublev(GL_MODELVIEW_MATRIX,  model_matrix);    glGetIntegerv(GL_VIEWPORT, viewport);    GLdouble px = 0.0;    GLdouble py = 0.0;    GLdouble pz = 0.0;    gluUnProject(x, y, z, model_matrix, proj_matrix, viewport,               &px, &py, &pz);    x = (float)px;    y = (float)py;    z = (float)pz;}END_NCBI_SCOPE/* * =========================================================================== * $Log: glcanvas3d.cpp,v $ * Revision 1000.2  2004/06/01 20:50:35  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.7 * * Revision 1.7  2004/05/21 22:27:45  gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.6  2004/03/12 15:24:21  rsmith * change native types to GLxxx types for better portability. * * Revision 1.5  2004/03/11 17:37:42  dicuccio * Added resize(), Project(), Unproject() * * Revision 1.4  2003/09/29 15:44:40  dicuccio * Deprecated gui/scope.hpp.  Merged gui/core/types.hpp into gui/types.hpp * * Revision 1.3  2003/07/21 19:31:34  dicuccio * Added NULL callback for CGlCanvas - works around interenting problem with * Fl_Gl_Window's default callback.  Removed unused ctor. * * Revision 1.2  2003/06/03 17:42:06  dicuccio * Added texture support.  Added classes to handle OpenGL camera setup and * viewport specification. * * Revision 1.1  2003/05/06 16:00:33  dicuccio * Initial revision * * =========================================================================== */

⌨️ 快捷键说明

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