llsurface.h

Go to the documentation of this file.
00001 
00032 #ifndef LL_LLSURFACE_H
00033 #define LL_LLSURFACE_H
00034 
00035 //#include "vmath.h"
00036 #include "v3math.h"
00037 #include "v3dmath.h"
00038 #include "v4math.h"
00039 #include "m3math.h"
00040 #include "m4math.h"
00041 #include "llquaternion.h"
00042 
00043 #include "v4coloru.h"
00044 #include "v4color.h"
00045 
00046 #include "llvowater.h"
00047 #include "llpatchvertexarray.h"
00048 #include "llviewerimage.h"
00049 
00050 class LLTimer;
00051 class LLUUID;
00052 class LLAgent;
00053 class LLStat;
00054 
00055 static const U8 NO_EDGE    = 0x00;
00056 static const U8 EAST_EDGE  = 0x01;
00057 static const U8 NORTH_EDGE = 0x02;
00058 static const U8 WEST_EDGE  = 0x04;
00059 static const U8 SOUTH_EDGE = 0x08;
00060 
00061 static const S32 ONE_MORE_THAN_NEIGHBOR = 1;
00062 static const S32 EQUAL_TO_NEIGHBOR              = 0;
00063 static const S32 ONE_LESS_THAN_NEIGHBOR = -1;
00064 
00065 const S32 ABOVE_WATERLINE_ALPHA = 32;  // The alpha of water when the land elevation is above the waterline.
00066 
00067 class LLViewerRegion;
00068 class LLSurfacePatch;
00069 class LLBitPack;
00070 class LLGroupHeader;
00071 
00072 class LLSurface 
00073 {
00074 public:
00075         LLSurface(U32 type, LLViewerRegion *regionp = NULL);
00076         virtual ~LLSurface();
00077 
00078         static void initClasses(); // Do class initialization for LLSurface and its child classes.
00079 
00080         void create(const S32 surface_grid_width,
00081                                 const S32 surface_patch_width,
00082                                 const LLVector3d &origin_global,
00083                                 const F32 width);       // Allocates and initializes surface
00084 
00085         void setRegion(LLViewerRegion *regionp);
00086 
00087         void setOriginGlobal(const LLVector3d &origin_global);
00088 
00089         void connectNeighbor(LLSurface *neighborp, U32 direction);
00090         void disconnectNeighbor(LLSurface *neighborp);
00091         void disconnectAllNeighbors();
00092 
00093         virtual void decompressDCTPatch(LLBitPack &bitpack, LLGroupHeader *gopp, BOOL b_large_patch);
00094         virtual void updatePatchVisibilities(LLAgent &agent);
00095 
00096         inline F32 getZ(const U32 k) const                              { return mSurfaceZ[k]; }
00097         inline F32 getZ(const S32 i, const S32 j) const { return mSurfaceZ[i + j*mGridsPerEdge]; }
00098 
00099         LLVector3 getOriginAgent() const;
00100         const LLVector3d &getOriginGlobal() const;
00101         F32 getMetersPerGrid() const;
00102         S32 getGridsPerEdge() const; 
00103         S32 getPatchesPerEdge() const;
00104         S32 getGridsPerPatchEdge() const;
00105         U32 getRenderStride(const U32 render_level) const;
00106         U32 getRenderLevel(const U32 render_stride) const;
00107 
00108         // Returns the height of the surface immediately above (or below) location,
00109         // or if location is not above surface returns zero.
00110         F32 resolveHeightRegion(const F32 x, const F32 y) const;
00111         F32 resolveHeightRegion(const LLVector3 &location) const
00112                         { return resolveHeightRegion( location.mV[VX], location.mV[VY] ); }
00113         F32 resolveHeightGlobal(const LLVector3d &position_global) const;
00114         LLVector3 resolveNormalGlobal(const LLVector3d& v) const;                               //  Returns normal to surface
00115 
00116         LLSurfacePatch *resolvePatchRegion(const F32 x, const F32 y) const;
00117         LLSurfacePatch *resolvePatchRegion(const LLVector3 &position_region) const;
00118         LLSurfacePatch *resolvePatchGlobal(const LLVector3d &position_global) const;
00119 
00120         // Update methods (called during idle, normally)
00121         BOOL idleUpdate(F32 max_update_time);
00122 
00123         BOOL containsPosition(const LLVector3 &position);
00124 
00125         void moveZ(const S32 x, const S32 y, const F32 delta);  
00126 
00127         LLViewerRegion *getRegion() const                               { return mRegionp; }
00128 
00129         F32 getMinZ() const                                                             { return mMinZ; }
00130         F32 getMaxZ() const                                                             { return mMaxZ; }
00131 
00132         void setWaterHeight(F32 height);
00133         F32 getWaterHeight() const;
00134 
00135         LLViewerImage *getSTexture();
00136         LLViewerImage *getWaterTexture();
00137         BOOL hasZData() const                                                   { return mHasZData; }
00138 
00139         void dirtyAllPatches(); // Use this to dirty all patches when changing terrain parameters
00140 
00141         void dirtySurfacePatch(LLSurfacePatch *patchp);
00142         LLVOWater *getWaterObj()                                                { return mWaterObjp; }
00143 
00144         static void setTextureSize(const S32 texture_size);
00145 
00146         friend class LLSurfacePatch;
00147         friend std::ostream& operator<<(std::ostream &s, const LLSurface &S);
00148 public:
00149         // Number of grid points on one side of a region, including +1 buffer for
00150         // north and east edge.
00151         S32 mGridsPerEdge;
00152 
00153         F32 mOOGridsPerEdge;                    // Inverse of grids per edge
00154 
00155         S32 mPatchesPerEdge;                    // Number of patches on one side of a region
00156         S32 mNumberOfPatches;                   // Total number of patches
00157 
00158 
00159         // Each surface points at 8 neighbors (or NULL)
00160         // +---+---+---+
00161         // |NW | N | NE|
00162         // +---+---+---+
00163         // | W | 0 | E |
00164         // +---+---+---+
00165         // |SW | S | SE|
00166         // +---+---+---+
00167         LLSurface *mNeighbors[8]; // Adjacent patches
00168 
00169         U32 mType;                              // Useful for identifying derived classes
00170         
00171         F32 mDetailTextureScale;        //  Number of times to repeat detail texture across this surface 
00172 
00173         static F32 sTextureUpdateTime;
00174         static S32 sTexelsUpdated;
00175         static LLStat sTexelsUpdatedPerSecStat;
00176 
00177 protected:
00178         void createSTexture();
00179         void createWaterTexture();
00180         void initTextures();
00181         void initWater();
00182 
00183 
00184         void createPatchData();         // Allocates memory for patches.
00185         void destroyPatchData();    // Deallocates memory for patches.
00186 
00187         BOOL generateWaterTexture(const F32 x, const F32 y,
00188                                                 const F32 width, const F32 height);             // Generate texture from composition values.
00189 
00190         //F32 updateTexture(LLSurfacePatch *ppatch);
00191         
00192         LLSurfacePatch *getPatch(const S32 x, const S32 y) const;
00193 
00194 protected:
00195         LLVector3d      mOriginGlobal;          // In absolute frame
00196         LLSurfacePatch *mPatchList;             // Array of all patches
00197 
00198         // Array of grid data, mGridsPerEdge * mGridsPerEdge
00199         F32 *mSurfaceZ;
00200 
00201         // Array of grid normals, mGridsPerEdge * mGridsPerEdge
00202         LLVector3 *mNorm;
00203 
00204         std::set<LLSurfacePatch *> mDirtyPatchList;
00205 
00206 
00207         // The textures should never be directly initialized - use the setter methods!
00208         LLPointer<LLViewerImage> mSTexturep;            // Texture for surface
00209         LLPointer<LLViewerImage> mWaterTexturep;        // Water texture
00210 
00211         LLPointer<LLVOWater>    mWaterObjp;
00212 
00213         // When we want multiple cameras we'll need one of each these for each camera
00214         S32 mVisiblePatchCount;
00215 
00216         U32                     mGridsPerPatchEdge;                     // Number of grid points on a side of a patch
00217         F32                     mMetersPerGrid;                         // Converts (i,j) indecies to distance
00218         F32                     mMetersPerEdge;                         // = mMetersPerGrid * (mGridsPerEdge-1)
00219 
00220         F32                     mSurfaceTexScale;                       // Scale factors for automatic tex coord generation
00221         F32                     mDetailTexScale;
00222 
00223         LLPatchVertexArray mPVArray;
00224 
00225         BOOL            mHasZData;                              // We've received any patch data for this surface.
00226         F32                     mMinZ;                                  // min z for this region (during the session)
00227         F32                     mMaxZ;                                  // max z for this region (during the session)
00228 
00229         S32                     mSurfacePatchUpdateCount;                                       // Number of frames since last update.
00230 
00231 private:
00232         LLViewerRegion *mRegionp; // Patch whose coordinate system this surface is using.
00233         static S32      sTextureSize;                           // Size of the surface texture
00234 };
00235 
00236 
00237 
00238 //        .   __.
00239 //     Z /|\   /| Y                                 North
00240 //        |   / 
00241 //        |  /             |<----------------- mGridsPerSurfaceEdge --------------->|
00242 //        | /              __________________________________________________________
00243 //        |/______\ X     /_______________________________________________________  /
00244 //                /      /      /      /      /      /      /      /M*M-2 /M*M-1 / /  
00245 //                      /______/______/______/______/______/______/______/______/ /  
00246 //                     /      /      /      /      /      /      /      /      / /  
00247 //                    /______/______/______/______/______/______/______/______/ /  
00248 //                   /      /      /      /      /      /      /      /      / /  
00249 //                  /______/______/______/______/______/______/______/______/ /  
00250 //      West       /      /      /      /      /      /      /      /      / /  
00251 //                /______/______/______/______/______/______/______/______/ /     East
00252 //               /...   /      /      /      /      /      /      /      / /  
00253 //              /______/______/______/______/______/______/______/______/ /  
00254 //       _.    / 2M   /      /      /      /      /      /      /      / /  
00255 //       /|   /______/______/______/______/______/______/______/______/ /  
00256 //      /    / M    / M+1  / M+2  / ...  /      /      /      / 2M-1 / /   
00257 //     j    /______/______/______/______/______/______/______/______/ /   
00258 //         / 0    / 1    / 2    / ...  /      /      /      / M-1  / /   
00259 //        /______/______/______/______/______/______/______/______/_/   
00260 //                                South             |<-L->|
00261 //             i -->
00262 //
00263 // where M = mSurfPatchWidth
00264 // and L = mPatchGridWidth
00265 // 
00266 // Notice that mGridsPerSurfaceEdge = a power of two + 1
00267 // This provides a buffer on the east and north edges that will allow us to 
00268 // fill the cracks between adjacent surfaces when rendering.
00269 #endif

Generated on Fri May 16 08:34:02 2008 for SecondLife by  doxygen 1.5.5