spline_window.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:8k
- /*
- * ===========================================================================
- * PRODUCTION $Log: spline_window.cpp,v $
- * PRODUCTION Revision 1000.1 2004/06/01 20:52:43 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.3
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: spline_window.cpp,v 1000.1 2004/06/01 20:52:43 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 "spline_window.hpp"
- #include <gui/opengl/gldlist.hpp>
- #include <gui/opengl/glutils.hpp>
- #include <gui/opengl/geometry.hpp>
- #include <FL/glut.H>
- BEGIN_NCBI_SCOPE
- CSplineWindow::CSplineWindow(int x, int y, int w, int h, const char* label)
- : CGlCanvas3d(x, y, w, h)
- , m_State(eNormal)
- , m_Flags(fRenderLines | fRenderControlPoints)
- , m_Arcball(CVect3<float>(0.0f, 0.0f, 0.0f), 2.0f)
- , m_TargetDistance(10.0f)
- , m_LastMouseX(0)
- , m_LastMouseY(0)
- {
- m_Arcball.Resolution(w, h);
- m_Curve.SetPoint(0, CVect3<float>(0.0f, 0.0f, 0.0f));
- m_Curve.SetPoint(1, CVect3<float>(1.0f, 0.0f, 0.0f));
- m_Curve.SetPoint(2, CVect3<float>(1.0f, 1.0f, 0.0f));
- m_Curve.SetPoint(3, CVect3<float>(2.0f, 1.0f, 0.0f));
- m_Curve.Recalc();
- }
- void CSplineWindow::draw()
- {
- x_DrawBackground(0.2f, 0.2f, 0.4f);
- x_SetupView();
- // apply our arcball and view transforms
- glTranslatef(0.0f, 0.0f, -m_TargetDistance);
- m_Arcball.ApplyGL();
- //
- // draw something interesting
- //
- glColor3f(1.0f, 1.0f, 1.0f);
- if (m_Flags & fRenderLines) {
- m_Curve.Draw(CGlCurve<CCurveBezier>::eRender_Lines);
- }
- if (m_Flags & fRenderPoints) {
- m_Curve.Draw(CGlCurve<CCurveBezier>::eRender_Points);
- }
- if (m_Flags & fRenderControlPoints) {
- glColor3f(1.0f, 0.0f, 0.0f);
- glBegin(GL_LINE_STRIP);
- glVertex3fv(m_Curve.GetPoint(0).GetData());
- glVertex3fv(m_Curve.GetPoint(1).GetData());
- glVertex3fv(m_Curve.GetPoint(2).GetData());
- glVertex3fv(m_Curve.GetPoint(3).GetData());
- glEnd();
- glColor3f(0.3f, 0.3f, 1.0f);
- glPointSize(3.0f);
- glBegin(GL_POINTS);
- glVertex3fv(m_Curve.GetPoint(0).GetData());
- glVertex3fv(m_Curve.GetPoint(1).GetData());
- glVertex3fv(m_Curve.GetPoint(2).GetData());
- glVertex3fv(m_Curve.GetPoint(3).GetData());
- glEnd();
- }
- //
- // draw an axis set
- //
- glBegin(GL_LINES);
- glColor3f (1.0f, 0.0f, 0.0f);
- glVertex3f(0.0f, 0.0f, 0.0f);
- glVertex3f(1.0f, 0.0f, 0.0f);
- glColor3f (0.0f, 1.0f, 0.0f);
- glVertex3f(0.0f, 0.0f, 0.0f);
- glVertex3f(0.0f, 1.0f, 0.0f);
- glColor3f (0.0f, 0.0f, 1.0f);
- glVertex3f(0.0f, 0.0f, 0.0f);
- glVertex3f(0.0f, 0.0f, 1.0f);
- glEnd();
- CGlUtils::DumpState();
- CGlUtils::CheckGlError();
- }
- void CSplineWindow::resize(int x, int y, int w, int h)
- {
- m_Arcball.Resolution(w, h);
- CGlCanvas3d::resize(x, y, w, h);
- }
- int CSplineWindow::handle(int event)
- {
- int curr_x = Fl::event_x();
- int curr_y = Fl::event_y();
- int dx = curr_x - m_LastMouseX;
- int dy = curr_y - m_LastMouseY;
- m_LastMouseX = curr_x;
- m_LastMouseY = curr_y;
- 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(dy);
- } else if (Fl::event_ctrl()) {
- // pan
- m_State = ePan;
- x_Pan(dx, dy);
- } 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(dx, dy);
- } else {
- // end pan
- m_State = eNormal;
- }
- break;
- case eZoom:
- //
- // zoom - activated on shift-left-click-drag
- //
- if (Fl::event_shift()) {
- x_Zoom(dy);
- } else {
- // end pan
- m_State = eNormal;
- }
- break;
- default:
- 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;
- default:
- break;
- }
- return 1;
- }
- break;
- }
- return CGlCanvas3d::handle(event);
- }
- void CSplineWindow::TogglePoints()
- {
- m_Flags ^= fRenderPoints;
- }
- void CSplineWindow::ToggleLines()
- {
- m_Flags ^= fRenderLines;
- }
- void CSplineWindow::ToggleControlPoints()
- {
- m_Flags ^= fRenderControlPoints;
- }
- void CSplineWindow::x_Rotate()
- {
- redraw();
- m_Arcball.Update(Fl::event_x(), Fl::event_y());
- if ( !m_Arcball.IsDragging() ) {
- m_Arcball.BeginDrag();
- }
- }
- void CSplineWindow::x_Pan(int dx, int dy)
- {
- }
- void CSplineWindow::x_Zoom(int dy)
- {
- m_TargetDistance += m_TargetDistance * (float(dy) / float(y()));
- redraw();
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: spline_window.cpp,v $
- * Revision 1000.1 2004/06/01 20:52:43 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.3
- *
- * Revision 1.3 2004/05/21 22:27:45 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.2 2004/03/11 20:58:11 ucko
- * Fix calls to Draw.
- *
- * Revision 1.1 2004/03/11 17:39:24 dicuccio
- * Added spline demo project
- *
- * ===========================================================================
- */