![]() |
VR-Forces 4.0.4 Class Documentation
|
00001 /******************************************************************************* 00002 ** Copyright (c) 2009 MAK Technologies, Inc. 00003 ** All rights reserved. 00004 *******************************************************************************/ 00005 /******************************************************************************* 00006 ** $RCSfile: DtSpeedTreeDrawable.h,v $ $Revision: 1.11 $ $State: Exp $ 00007 *******************************************************************************/ 00008 00012 00013 #pragma once 00014 #include <vrvSt/vrvSt.h> 00015 #include <vlutil/vlExceptions.h> 00016 #include <osg/Drawable> 00017 00018 namespace makVrv 00019 { 00020 00021 class DtDe; 00022 class DtSpeedTreeForest; 00023 class DtSpeedTreeProfile; 00024 00027 class DT_DLL_VRVST DtSpeedTreeDrawable : public osg::Drawable 00028 { 00029 public: 00030 00033 struct TreeInstanceRecord 00034 { 00035 TreeInstanceRecord() 00036 : mySptFilePath() 00037 , myScale(1.0f) 00038 , myRotation(0.0f) 00039 { 00040 myPositionArray[0] = myPositionArray[1] = myPositionArray[2] = 0.0f; 00041 } 00042 00043 ~TreeInstanceRecord() 00044 { 00045 } 00046 00049 std::string mySptFilePath; 00050 00052 float myPositionArray[3]; 00053 00055 float myScale; 00056 00058 float myRotation; 00059 }; 00060 00061 typedef std::vector<TreeInstanceRecord> TreeInstanceRecordVector; 00062 00063 friend class DtSpeedTreeProfile; 00064 00067 DtSpeedTreeDrawable(DtDe& de, DtSpeedTreeForest* forestModel, 00068 const std::string& speedTreeDataPathRoot, int randomSeed); 00069 00071 DtSpeedTreeDrawable(const DtSpeedTreeDrawable& orig, 00072 const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY ); 00073 00074 virtual osg::Object* cloneType() const { throw DtCorruptedState("Unable to clone"); } \ 00075 virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new DtSpeedTreeDrawable (*this,copyop); } \ 00076 virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const DtSpeedTreeDrawable *>(obj)!=NULL; } \ 00077 virtual const char* libraryName() const { return "vrvSt"; }\ 00078 virtual const char* className() const { return "DtSpeedTreeForestDrawable"; } 00079 00081 virtual ~DtSpeedTreeDrawable(); 00082 00084 virtual void setProfile(int profile); 00085 00087 virtual void drawImplementation(osg::RenderInfo&) const; 00088 00090 virtual void setTreesHaveChanged(bool bFlag); 00091 00093 virtual bool treesHaveChanged() const; 00094 00095 00099 virtual osg::BoundingBox computeBound() const; 00100 00103 virtual void setTreeClippingPlane(float fFar); 00104 00107 virtual void setTreeLodDistances(float fNear, float fFar); 00108 00110 virtual DtSpeedTreeForest* forest(); 00111 00115 virtual void releaseGLObjects(osg::State* state = 0) const; 00116 00117 protected: 00118 00121 void rebuildForest(DtSpeedTreeProfile* profile); 00122 00123 DtSpeedTreeProfile* getCurrentProfile(unsigned int contextId) const; 00124 void setCurrentProfile(unsigned int contextId, DtSpeedTreeProfile* profile); 00125 00126 void flushGLObjects(unsigned int contextID) const; 00127 00128 //Create a profile with context active 00129 void createProfile(unsigned int contextId); 00130 void populateForest( DtSpeedTreeProfile* profile, const TreeInstanceRecordVector& recordVector ); 00131 bool addTree(const TreeInstanceRecord& record ); 00132 00133 protected: 00134 00135 DtDe& myDe; 00136 bool myTreesHaveChanged; 00137 DtSpeedTreeForest* myForestModel; 00138 typedef std::map<unsigned int, DtSpeedTreeProfile*> ContextSpecificForestMap; 00139 mutable ContextSpecificForestMap myCurrentProfile; 00140 bool myProfileHasChanged; 00141 int myProfileId; 00142 00143 int myRandomSeed; 00144 00145 float myFarPlane; 00146 float myNearLod; 00147 float myFarLod; 00148 00149 }; 00150 }