gl3d_window.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:8k
- /*
- * ===========================================================================
- * PRODUCTION $Log: gl3d_window.cpp,v $
- * PRODUCTION Revision 1000.2 2004/06/01 20:52:29 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.7
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: gl3d_window.cpp,v 1000.2 2004/06/01 20:52:29 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:
- *
- */
- #include <ncbi_pch.hpp>
- #include "gl3d_window.hpp"
- #include <gui/opengl/gldlist.hpp>
- #include <gui/opengl/glutils.hpp>
- #include <gui/opengl/geometry.hpp>
- #include <FL/glut.H>
- BEGIN_NCBI_SCOPE
- CGl3dWindow::CGl3dWindow(int x, int y, int w, int h, const char* label)
- : CGlCanvas3d(x, y, w, h)
- , m_Arcball(CVect3<float>(0.0f, 0.0f, 0.0f), 2.0f)
- , m_State(eNormal)
- {
- m_Arcball.Resolution(w, h);
- }
- void CGl3dWindow::draw()
- {
- x_DrawBackground(0.2f, 0.2f, 0.4f);
- x_SetupView();
- // misc enables
- glEnable(GL_DEPTH_TEST);
- glEnable(GL_CULL_FACE);
- glEnable(GL_COLOR_MATERIAL);
- // lights
- static GLfloat light_pos[] = { 20.0f, 20.0f, 5.0f, 1.0f };
- static GLfloat white_light[] = { 1.0f, 1.0f, 1.0f, 1.0f };
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
- glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
- glLightfv(GL_LIGHT0, GL_POSITION, light_pos);
- glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light);
- glLightfv(GL_LIGHT0, GL_SPECULAR, white_light);
- // apply our arcball and view transforms
- glTranslatef(0.0f, 0.0f, -40.0f);
- m_Arcball.ApplyGL();
- //
- // draw something interesting
- //
- if (m_Dlist.IsValid()) {
- m_Dlist.Call();
- } else {
- CGlDisplayListCompile COMPILE(m_Dlist,
- CGlDisplayList::eCompileAndExecute);
- glPushMatrix();
- glColor3f(1.0f, 0.5f, 0.0f);
- glTranslatef(5.0f, 0.0f, 0.0f);
- CGlGeometry::DrawCylinder(CVect3<float>(0.0f, 0.0f, 0.0f),
- CVect3<float>(10.0f, 0.0f, 0.0f),
- 1.0f, 3, 10);
- //glutSolidTorus(2.0f, 7.0f, 30, 50);
- glPopMatrix();
- glPushMatrix();
- glColor3f(0.0f, 1.0f, 0.0f);
- glTranslatef(-5.0f, 0.0f, 0.0f);
- //glRotatef(90, 1.0f, 0.0f, 0.0f);
- CGlGeometry::DrawCylinder(CVect3<float>(0.0f, 0.0f, 0.0f),
- CVect3<float>(0.0f, 10.0f, 0.0f),
- 1.0f, 3, 10);
- //glutSolidTorus(2.0f, 7.0f, 30, 50);
- glPopMatrix();
- }
- CGlUtils::CheckGlError();
- }
- void CGl3dWindow::resize(int x, int y, int w, int h)
- {
- m_Arcball.Resolution(w, h);
- CGlCanvas3d::resize(x, y, w, h);
- }
- int CGl3dWindow::handle(int event)
- {
- switch (event) {
- case FL_PUSH:
- // always return 1 here - this insures that the FL_MOVE and FL_RELEASE
- // events are registered
- if (Fl::event_button() == 1) {
- return 1;
- }
- break;
- case FL_DRAG:
- if (Fl::event_button() == 1) {
- switch (m_State) {
- case eNormal:
- if (Fl::event_shift()) {
- // zoom
- m_State = eZoom;
- x_Zoom();
- } else if (Fl::event_ctrl()) {
- // pan
- m_State = ePan;
- x_Pan();
- } else {
- // rotate
- m_State = eRotate;
- x_Rotate();
- }
- break;
- case eRotate:
- //
- // rotate - activated on left click-drag
- //
- if ( !Fl::event_shift() && !Fl::event_ctrl()) {
- x_Rotate();
- } else {
- // end rotate
- m_Arcball.EndDrag();
- m_State = eNormal;
- }
- break;
- case ePan:
- //
- // pan - activated on ctrl-left-click-drag
- //
- if (Fl::event_ctrl()) {
- x_Pan();
- } else {
- // end pan
- m_State = eNormal;
- }
- break;
- case eZoom:
- //
- // zoom - activated on shift-left-click-drag
- //
- if (Fl::event_shift()) {
- x_Zoom();
- } else {
- // end pan
- m_State = eNormal;
- }
- break;
- }
- redraw();
- return 1;
- }
- break;
- case FL_RELEASE:
- if (Fl::event_button() == 1) {
- switch (m_State) {
- case eRotate:
- m_Arcball.Update(Fl::event_x(), Fl::event_y());
- m_Arcball.EndDrag();
- break;
- case eZoom:
- case ePan:
- case eNormal:
- break;
- }
- return 1;
- }
- break;
- }
- return CGlCanvas3d::handle(event);
- }
- void CGl3dWindow::x_Rotate()
- {
- redraw();
- m_Arcball.Update(Fl::event_x(), Fl::event_y());
- if ( !m_Arcball.IsDragging() ) {
- m_Arcball.BeginDrag();
- }
- }
- void CGl3dWindow::x_Pan()
- {
- }
- void CGl3dWindow::x_Zoom()
- {
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: gl3d_window.cpp,v $
- * Revision 1000.2 2004/06/01 20:52:29 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/01/27 18:32:51 dicuccio
- * Don't cull front faces
- *
- * Revision 1.5 2003/12/22 19:23:22 dicuccio
- * Inherit from CDialog. Added calls to interla geometry processing functions
- *
- * Revision 1.4 2003/09/29 15:44:41 dicuccio
- * Deprecated gui/scope.hpp. Merged gui/core/types.hpp into gui/types.hpp
- *
- * Revision 1.3 2003/06/10 19:03:09 dicuccio
- * Canonicalize the FL/ headers
- *
- * Revision 1.2 2003/06/09 19:24:19 dicuccio
- * Temporarily deisable code which requires glut
- *
- * Revision 1.1 2003/06/09 19:22:29 dicuccio
- * Initial revision
- *
- * Revision 1.1 2003/06/03 17:41:05 dicuccio
- * Initial revision
- *
- * ===========================================================================
- */