glmtransform.hpp
来自「ncbi源码」· HPP 代码 · 共 215 行
HPP
215 行
/* * =========================================================================== * PRODUCTION $Log: glmtransform.hpp,v $ * PRODUCTION Revision 1000.0 2004/04/12 19:32:56 gouriano * PRODUCTION PRODUCTION: IMPORTED [CATCHUP_003] Dev-tree R1.1 * PRODUCTION * =========================================================================== */#ifndef GUI_OPENGL___GLM_TRANSFORM___HPP#define GUI_OPENGL___GLM_TRANSFORM___HPP/* $Id: glmtransform.hpp,v 1000.0 2004/04/12 19:32:56 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, Vladimir Tereshkov * * File Description: * Arbitrary OpenGL Mouse transformations class based on CGlArcBall with addition of pan and zoom */#include <corelib/ncbistd.hpp>#include <gui/math/quat.hpp>#include <gui/math/vect3.hpp>#include <gui/math/matrix4.hpp>BEGIN_NCBI_SCOPEclass CGlMTransform{ public: typedef CVect3<float> TVect; typedef CQuat<float> TQuat; enum EMode { eRotate, ePan, eZoom, eTranslate, // pan+zoom eAll // translate+rotate }; // ctor CGlMTransform(void); // construct at a center and radius CGlMTransform(const TVect& center, float radius); // dtor ~CGlMTransform(void); // set the screen resolution void Resolution(int x, int y); // place the world at a center and radius void Place(const TVect& center, float radius); // place a world at a center, keeping the current radius void Place(const TVect& center); // update the arc ball for a given mouse position void Update(int x, int y); // begin a drag event void BeginDrag(void); // end a drag event void EndDrag(void); // determine if the arc ball is in a drag state bool IsDragging(void) const; // apply the arcball using OpenGL void ApplyGL(EMode mode = eAll) const; // mode switches void Switch2Mode(int mode); void Switch2Rotate(); void Switch2Pan(); void Switch2Zoom(); CGlMTransform& operator= (const CGlMTransform&); CGlMTransform(const CGlMTransform&); // access the current rotation matrix const CMatrix4<float>& GetMatrix() const { return m_MatNow; } // access the current translation vector const CVect3<float>& GetTranslation() const { return m_Translate; } private: // current mode EMode m_Mode; // boolean flag: are we dragging? bool m_IsDragging; // screen resolution int m_ScreenX; int m_ScreenY; // current mouse position(in scaled coordinates) float m_MouseX; float m_MouseY; // mouse position at the start of the drag cycle CVect4 < float> m_DragFrom; // center of the arcball world CVect4 < float> m_Center; // radius of the arcball world float m_Radius; // quaternions for rotation TQuat m_QuatNow; TQuat m_QuatDown; TQuat m_QuatDrag; // current rotation matrix CMatrix4<float> m_MatNow; // zoom and pan CVect3<float> m_Translate; CVect3<float> m_TranslateDown; // convert screen coordinates to sphere coordinates CVect4<float> x_ToSphere(float x, float y);};// // set the screen resolutioninlinevoid CGlMTransform::Resolution(int x, int y){ m_ScreenX = x; m_ScreenY = y;}//// determine if the arc ballis being dragged//inlinebool CGlMTransform::IsDragging(void) const{ return m_IsDragging;}// mode setup functions inlinevoid CGlMTransform::Switch2Mode(int mode){ m_Mode = static_cast<EMode>(mode);}inlinevoid CGlMTransform::Switch2Rotate(){ m_Mode = eRotate;}inlinevoid CGlMTransform::Switch2Pan(){ m_Mode = ePan;}inlinevoid CGlMTransform::Switch2Zoom(){ m_Mode = eZoom;} END_NCBI_SCOPE/* * =========================================================================== * $Log: glmtransform.hpp,v $ * Revision 1000.0 2004/04/12 19:32:56 gouriano * PRODUCTION: IMPORTED [CATCHUP_003] Dev-tree R1.1 * * Revision 1.1 2004/01/05 16:20:49 tereshko * Initial revision * * =========================================================================== */#endif // GUI_OPENGL___GLM_TRANSFORM___HPP
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?