Gizmo3D

gzIntersector.h

Go to the documentation of this file.
00001 //*****************************************************************************
00002 // File         : gzIntersector.h
00003 // Module       : 
00004 // Description  : Class definition of the gzIntersector class
00005 // Author       : Anders Modén      
00006 // Product      : Gizmo3D 2.1.1
00007 //      
00008 // Copyright © 2003- Saab Training Systems AB, Sweden   
00009 //          
00010 // NOTE:    Gizmo3D is a high performance 3D Scene Graph and effect visualisation 
00011 //          C++ toolkit for Linux, Mac OS X, Windows (Win32) and IRIX® for  
00012 //          usage in Game or VisSim development.
00013 //
00014 //
00015 // Revision History...                          
00016 //                                  
00017 // Who  Date    Description                     
00018 //                                  
00019 // AMO  000828  Created file    
00020 //
00021 //******************************************************************************
00022 #ifndef __GZ_INTERSECTOR_H__
00023 #define __GZ_INTERSECTOR_H__
00024 
00030 #include "gzScene.h"
00031 #include "gzContext.h"
00032 
00033 enum gzIntersectQuery
00034 {   
00035     GZ_INTERSECTOR_NEAREST_POINT            =   (1<<0),
00036     GZ_INTERSECTOR_NORMAL                   =   (1<<1),
00037     GZ_INTERSECTOR_NODE                     =   (1<<2),
00038     GZ_INTERSECTOR_HISTORY                  =   (1<<3), 
00039     GZ_INTERSECTOR_ABC_TRI                  =   (1<<4),
00040     GZ_INTERSECTOR_ALL_HITS                 =   (1<<5),
00041 };
00042 
00043 GZ_USE_BIT_LOGIC(gzIntersectQuery);
00044 
00045 
00046 class gzIntersectorResult
00047 {
00048 public:
00049 
00050     gzVec3                  coordinate;
00051 
00052     gzVec3                  a,b,c;
00053 
00054     gzVec3                  normal;
00055 
00056     gzRefPointer<gzNode>    node;
00057 
00058     gzList<gzNode>          history;
00059 
00060     gzULong                 resultmask;
00061 };
00062 
00063 class gzIntersector;
00064 
00065 class gzIntersectorAction : public gzTraverseAction
00066 {
00067 public:
00068     GZ_DECLARE_TYPE_INTERFACE_EXPORT(GZ_GRAPH_EXPORT);  // typed interface
00069 
00070     GZ_GRAPH_EXPORT gzIntersectorAction(gzIntersector *intersector=NULL);
00071 
00072     GZ_GRAPH_EXPORT virtual ~gzIntersectorAction(){};
00073 
00074     GZ_GRAPH_EXPORT gzVoid action(gzNode *node , gzContext *context);
00075 
00076     GZ_GRAPH_EXPORT gzVoid setIntersector(gzIntersector *intersector);
00077 
00078     GZ_GRAPH_EXPORT gzIntersector *getIntersector()                 { return m_intersector; }
00079 
00080     GZ_GRAPH_EXPORT const gzVec3 & getStartPos()            const   { return m_transformedStartPos; } 
00081     GZ_GRAPH_EXPORT const gzVec3 & getDirection()           const   { return m_transformedDirection; }
00082 
00083     GZ_GRAPH_EXPORT const gzList<gzNode> & getHistory()     const   { return m_history; };
00084 
00085 protected:
00086 
00087     GZ_GRAPH_EXPORT virtual gzBool checkBoundary(gzContext *context, gzNode *node);
00088     GZ_GRAPH_EXPORT virtual gzVoid preTraverseAction( gzNode *node , gzContext *context);
00089     GZ_GRAPH_EXPORT virtual gzVoid postTraverseAction( gzNode *node , gzContext *context);
00090 
00091 private:
00092 
00093     gzIntersector *     m_intersector;
00094                         
00095     gzULong             m_currentTransformIndex;
00096                         
00097     gzVec3              m_transformedStartPos;
00098     gzVec3              m_transformedDirection;
00099 
00100     gzQueue<gzVec3>     m_transformedStartPosStorage;               
00101     gzQueue<gzVec3>     m_transformedDirectionStorage;
00102 
00103 
00104     gzList<gzNode>      m_history;
00105 };
00106 
00107 
00108 //******************************************************************************
00109 // Class    : gzIntersector
00110 //                                  
00111 // Purpose  : -
00112 //                                  
00113 // Notes    : - 
00114 //                                  
00115 // Revision History...                          
00116 //                                  
00117 // Who  Date    Description                     
00118 //                                  
00119 // AMO  000828  Created 
00120 //                                  
00121 //******************************************************************************
00122 class gzIntersector : public gzObject , public gzNameInterface , public gzIntersectMask
00123 {
00124 public:
00125 
00126     GZ_DECLARE_TYPE_INTERFACE_EXPORT(GZ_GRAPH_EXPORT);  // typed interface
00127 
00128     GZ_GRAPH_EXPORT gzIntersector(const gzString & name=GZ_EMPTY_STRING);
00129     GZ_GRAPH_EXPORT virtual ~gzIntersector(){};
00130 
00131     // ---------- Clone interface ---------------------------------------
00132     GZ_GRAPH_EXPORT virtual gzReference* clone() const;
00133 
00134     // ---------- intersector interface ---------------------------------
00135 
00136     GZ_GRAPH_EXPORT gzVoid setBaseTransform(const gzMatrix4 &baseTransform);
00137     GZ_GRAPH_EXPORT gzVoid setProjectionTransform(const gzMatrix4 &projectionTransform);
00138 
00139     GZ_GRAPH_EXPORT gzVoid setStartPosition(const gzVec3 &position);
00140     GZ_GRAPH_EXPORT gzVoid setDirection(const gzVec3 &direction);
00141 
00142     GZ_GRAPH_EXPORT gzVoid clearIntersector();
00143     
00144     GZ_GRAPH_EXPORT gzBool intersect(gzNode *node,gzIntersectQuery queryType=GZ_INTERSECTOR_NEAREST_POINT,gzFloat lodFactor=1.0);
00145 
00146     // ---------- intersector data --------------------------------------
00147 
00148     GZ_PROPERTY_GET_EXPORT( gzBool          ,   HasBaseTransform        , GZ_GRAPH_EXPORT);
00149     GZ_PROPERTY_GET_EXPORT( gzBool          ,   HasProjectionTransform  , GZ_GRAPH_EXPORT);
00150 
00151     GZ_PROPERTY_GET_EXPORT( gzMatrix4       ,   ProjectionTransform     , GZ_GRAPH_EXPORT);
00152     GZ_PROPERTY_GET_EXPORT( gzMatrix4       ,   InvProjectionTransform  , GZ_GRAPH_EXPORT);
00153     GZ_PROPERTY_GET_EXPORT( gzMatrix4       ,   BaseTransform           , GZ_GRAPH_EXPORT);
00154     GZ_PROPERTY_GET_EXPORT( gzMatrix4       ,   InvBaseTransform        , GZ_GRAPH_EXPORT);
00155 
00156     // ---------- query results -----------------------------------------
00157 
00158     GZ_GRAPH_EXPORT gzDynamicArray<gzIntersectorResult> getResult();
00159 
00160     GZ_GRAPH_EXPORT gzIntersectQuery getQueryType();
00161 
00162     GZ_GRAPH_EXPORT gzVoid addResult(const gzIntersectorResult &data);
00163 
00164 private:
00165 
00166     friend class gzIntersectorAction;
00167 
00168     gzVec3                              m_startPos;
00169     gzVec4                              m_direction;
00170 
00171     gzBool                              m_hasStartPosition;
00172     gzBool                              m_hasDirection;
00173 
00174     gzIntersectQuery                    m_queryType;
00175 
00176     gzDynamicArray<gzIntersectorResult> m_results;
00177 
00178     gzRefPointer<gzContext>             m_context;
00179 
00180     gzIntersectorAction                 m_action;
00181 
00182     static gzULong                      s_contextTID;
00183 
00184     static gzRefPointer<gzContext>      s_context;
00185 
00186 };
00187 
00188 // Utilities ----------------------
00189 
00190 GZ_GRAPH_EXPORT gzVoid gzGetMouseXYIntersector(gzVec3 &startPosition,gzVec3 &direction,const gzCamera *camera,const gzLong mouse_x,const gzLong mouse_y, const gzULongXY & winSize);
00191 
00192 
00193 #endif

Documentation for Gizmo3D generated at Wed Feb 20 11:54:06 2008 by   Saab Training Systems AB, ¸ (c) 2003-and beyond