arbeit
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

SurfaceWidget.cpp

Go to the documentation of this file.
00001 //------------------------------------------------------------------------
00002 //
00003 //   Joe Kniss
00004 //     9-9-03
00005 //                   ________    ____   ___ 
00006 //                  |        \  /    | /  /
00007 //                  +---+     \/     |/  /
00008 //                  +--+|  |\    /|     < 
00009 //                  |  ||  | \  / |  |\  \ 
00010 //                  |      |  \/  |  | \  \ 
00011 //                   \_____|      |__|  \__\
00012 //                       Copyright  2003 
00013 //                      Joe Michael Kniss
00014 //                   <<< jmk@cs.utah.edu >>>
00015 //               "All Your Base are Belong to Us"
00016 //-------------------------------------------------------------------------
00017 
00018 /// SurfaceWidget.cpp
00019 
00020 #include "SurfaceWidget.h"
00021 #include <iostream>
00022 #include <algorithm>
00023 
00024 using namespace gutz;
00025 using namespace std;
00026 
00027 ///////////////////////////////////////////////////////////////////////////
00028 // construct
00029 ///////////////////////////////////////////////////////////////////////////
00030 SurfaceWidget::SurfaceWidget(WidgetItem *parent, float border, bool drawBorder)
00031 : WidgetItem(parent), _lastPick(vec3f_zero)
00032 {
00033    addEvent(GUTZ_LEFT_MOUSE, PICK);
00034 }
00035 
00036 ///////////////////////////////////////////////////////////////////////////
00037 // intersect Plane
00038 ///////////////////////////////////////////////////////////////////////////
00039 gutz::vec3f SurfaceWidget::intersectPlane(const gutz::MouseEvent &me) const
00040 {
00041    planef p = getPlane();
00042    vec3f pos = me.getWorldPos();
00043    vec3f dir = _manip->getWorldEyeRayWorld( pos );
00044    
00045    float t = gutz::intersectRayPlane(pos,dir,p.p,p.n);
00046 
00047    return pos + dir * t;
00048 }
00049 
00050 ///////////////////////////////////////////////////////////////////////////
00051 // mouse def
00052 ///////////////////////////////////////////////////////////////////////////
00053 bool SurfaceWidget::mouseDef(const gutz::MouseEvent &me)
00054 {
00055    // should be a switch if we add more behaviors
00056    if( getEvent(me) == NO_EVENT ) return false;
00057 
00058    _lastPick = intersectPlane(me);
00059 
00060    cerr << " surface clicked @ " << _lastPick << endl;
00061 
00062    // emit the signal
00063    surfacePicked(_lastPick);
00064 
00065    return true;
00066 }
00067 
00068 ///////////////////////////////////////////////////////////////////////////
00069 // move def
00070 ///////////////////////////////////////////////////////////////////////////
00071 bool SurfaceWidget::moveDef(const gutz::MouseMoveEvent &mme)
00072 {
00073    if( getEvent(mme) == NO_EVENT ) return false;
00074 
00075    _lastPick = intersectPlane(mme);
00076 
00077    cerr << " surface click moved to " << _lastPick << endl;
00078 
00079    // emit the signal
00080    surfacePickMoved(_lastPick);
00081 
00082    return true;
00083 }
00084 
00085 

Send questions, comments, and bug reports to:
jmk