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

WidgetManip.h

Go to the documentation of this file.
00001 //------------------------------------------------------------------------
00002 //
00003 //   Joe Kniss
00004 //     6-20-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 // WidgetManip.h
00019 
00020 #ifndef __WIDGET_MANIPULATION_DOT_H
00021 #define __WIDGET_MANIPULATION_DOT_H
00022 
00023 #include <mathGutz.h>
00024 #include <iostream>
00025 using namespace std;
00026 
00027 /// a bunch of utilities for manipulating widgets, defines things like
00028 ///  rotation etc, that all widgets can benefit from
00029 
00030 /// A "ball-plane" rotation. 
00031 inline
00032 gutz::mat3f ballPlaneRot(const gutz::vec3f &center, /// center of object being rotated 
00033                          const float rad,           /// radius (distance from center) 
00034                          const gutz::CameraSP cam,  /// camera for current event
00035                          const gutz::vec3f   &last, /// last mouse point    (world space)
00036                          const gutz::vec3f   &curr) /// current mouse point (world space)
00037 {
00038    const gutz::vec3f norm = cam->getViewDir();
00039    const gutz::vec3f cdir = (cam->getRayWorld(curr)).d;
00040    const gutz::vec3f ldir = (cam->getRayWorld(last)).d;
00041    float tc = std::numeric_limits<float>::max();
00042    float tl = std::numeric_limits<float>::max();
00043    /// ray plane intersect
00044    tc = gutz::intersectRayPlane(curr, cdir, center, norm);
00045    tc = gutz::g_min(tc, gutz::intersectRaySphere(curr,cdir,center,rad).x);
00046    tl = gutz::intersectRayPlane(last, ldir, center, norm);
00047    tl = gutz::g_min(tl, gutz::intersectRaySphere(last,ldir,center,rad).x);
00048    cerr << "tc = " << tc << "  tl = " << tl << endl;
00049    const gutz::vec3f cpt = curr + tc * cdir - center;
00050    cerr << " cur = " << cpt << endl;
00051    const gutz::vec3f lpt = last + tl * ldir - center;
00052    cerr << " las = " << lpt << endl;
00053    return gutz::axis2axis(lpt, cpt);
00054 }
00055 
00056 /// a convenience version of ballPlaneRot that takes the event and
00057 ///  the objects center & rad, calls ballPlaneRot and builds a 4x4 matrix
00058 ///  from the result.
00059 inline
00060 gutz::mat4f ballPlane(const gutz::MouseMoveEvent &mme,
00061                       const gutz::vec3f          &center,
00062                       const float                 rad)
00063 {
00064    return gutz::mat4f(ballPlaneRot(center,rad,
00065                                    mme.getCamera(),
00066                                    mme.getWorldLast(),
00067                                    mme.getWorldPos()),
00068                       gutz::vec3f_zero);
00069 }
00070 
00071 #endif
00072 

Send questions, comments, and bug reports to:
jmk