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         void renderSurfaceBounds();
00124         
00125         BOOL containsPosition(const LLVector3 &position);
00126 
00127         void moveZ(const S32 x, const S32 y, const F32 delta);  
00128 
00129         LLViewerRegion *getRegion() const                               { return mRegionp; }
00130 
00131         F32 getMinZ() const                                                             { return mMinZ; }
00132         F32 getMaxZ() const                                                             { return mMaxZ; }
00133 
00134         void setWaterHeight(F32 height);
00135         F32 getWaterHeight() const;
00136 
00137         LLViewerImage *getSTexture();
00138         LLViewerImage *getWaterTexture();
00139         BOOL hasZData() const                                                   { return mHasZData; }
00140 
00141         void dirtyAllPatches(); // Use this to dirty all patches when changing terrain parameters
00142 
00143         void dirtySurfacePatch(LLSurfacePatch *patchp);
00144         LLVOWater *getWaterObj()                                                { return mWaterObjp; }
00145 
00146         static void setTextureSize(const S32 texture_size);
00147 
00148         friend class LLSurfacePatch;
00149         friend std::ostream& operator<<(std::ostream &s, const LLSurface &S);
00150 public:
00151         // Number of grid points on one side of a region, including +1 buffer for
00152         // north and east edge.
00153         S32 mGridsPerEdge;
00154 
00155         F32 mOOGridsPerEdge;                    // Inverse of grids per edge
00156 
00157         S32 mPatchesPerEdge;                    // Number of patches on one side of a region
00158         S32 mNumberOfPatches;                   // Total number of patches
00159 
00160 
00161         // Each surface points at 8 neighbors (or NULL)
00162         // +---+---+---+
00163         // |NW | N | NE|
00164         // +---+---+---+
00165         // | W | 0 | E |
00166         // +---+---+---+
00167         // |SW | S | SE|
00168         // +---+---+---+
00169         LLSurface *mNeighbors[8]; // Adjacent patches
00170 
00171         U32 mType;                              // Useful for identifying derived classes
00172         
00173         F32 mDetailTextureScale;        //  Number of times to repeat detail texture across this surface 
00174 
00175         static F32 sTextureUpdateTime;
00176         static S32 sTexelsUpdated;
00177         static LLStat sTexelsUpdatedPerSecStat;
00178 
00179 protected:
00180         void createSTexture();
00181         void createWaterTexture();
00182         void initTextures();
00183         void initWater();
00184 
00185 
00186         void createPatchData();         // Allocates memory for patches.
00187         void destroyPatchData();    // Deallocates memory for patches.
00188 
00189         BOOL generateWaterTexture(const F32 x, const F32 y,
00190                                                 const F32 width, const F32 height);             // Generate texture from composition values.
00191 
00192         //F32 updateTexture(LLSurfacePatch *ppatch);
00193         
00194         LLSurfacePatch *getPatch(const S32 x, const S32 y) const;
00195 
00196 protected:
00197         LLVector3d      mOriginGlobal;          // In absolute frame
00198         LLSurfacePatch *mPatchList;             // Array of all patches
00199 
00200         // Array of grid data, mGridsPerEdge * mGridsPerEdge
00201         F32 *mSurfaceZ;
00202 
00203         // Array of grid normals, mGridsPerEdge * mGridsPerEdge
00204         LLVector3 *mNorm;
00205 
00206         std::set<LLSurfacePatch *> mDirtyPatchList;
00207 
00208 
00209         // The textures should never be directly initialized - use the setter methods!
00210         LLPointer<LLViewerImage> mSTexturep;            // Texture for surface
00211         LLPointer<LLViewerImage> mWaterTexturep;        // Water texture
00212 
00213         LLPointer<LLVOWater>    mWaterObjp;
00214 
00215         // When we want multiple cameras we'll need one of each these for each camera
00216         S32 mVisiblePatchCount;
00217 
00218         U32                     mGridsPerPatchEdge;                     // Number of grid points on a side of a patch
00219         F32                     mMetersPerGrid;                         // Converts (i,j) indecies to distance
00220         F32                     mMetersPerEdge;                         // = mMetersPerGrid * (mGridsPerEdge-1)
00221 
00222         F32                     mSurfaceTexScale;                       // Scale factors for automatic tex coord generation
00223         F32                     mDetailTexScale;
00224 
00225         LLPatchVertexArray mPVArray;
00226 
00227         BOOL            mHasZData;                              // We've received any patch data for this surface.
00228         F32                     mMinZ;                                  // min z for this region (during the session)
00229         F32                     mMaxZ;                                  // max z for this region (during the session)
00230 
00231         S32                     mSurfacePatchUpdateCount;                                       // Number of frames since last update.
00232 
00233 private:
00234         LLViewerRegion *mRegionp; // Patch whose coordinate system this surface is using.
00235         static S32      sTextureSize;                           // Size of the surface texture
00236 };
00237 
00238 
00239 
00240 //        .   __.
00241 //     Z /|\   /| Y                                 North
00242 //        |   / 
00243 //        |  /             |<----------------- mGridsPerSurfaceEdge --------------->|
00244 //        | /              __________________________________________________________
00245 //        |/______\ X     /_______________________________________________________  /
00246 //                /      /      /      /      /      /      /      /M*M-2 /M*M-1 / /  
00247 //                      /______/______/______/______/______/______/______/______/ /  
00248 //                     /      /      /      /      /      /      /      /      / /  
00249 //                    /______/______/______/______/______/______/______/______/ /  
00250 //                   /      /      /      /      /      /      /      /      / /  
00251 //                  /______/______/______/______/______/______/______/______/ /  
00252 //      West       /      /      /      /      /      /      /      /      / /  
00253 //                /______/______/______/______/______/______/______/______/ /     East
00254 //               /...   /      /      /      /      /      /      /      / /  
00255 //              /______/______/______/______/______/______/______/______/ /  
00256 //       _.    / 2M   /      /      /      /      /      /      /      / /  
00257 //       /|   /______/______/______/______/______/______/______/______/ /  
00258 //      /    / M    / M+1  / M+2  / ...  /      /      /      / 2M-1 / /   
00259 //     j    /______/______/______/______/______/______/______/______/ /   
00260 //         / 0    / 1    / 2    / ...  /      /      /      / M-1  / /   
00261 //        /______/______/______/______/______/______/______/______/_/   
00262 //                                South             |<-L->|
00263 //             i -->
00264 //
00265 // where M = mSurfPatchWidth
00266 // and L = mPatchGridWidth
00267 // 
00268 // Notice that mGridsPerSurfaceEdge = a power of two + 1
00269 // This provides a buffer on the east and north edges that will allow us to 
00270 // fill the cracks between adjacent surfaces when rendering.
00271 #endif

Generated on Thu Jul 1 06:09:14 2010 for Second Life Viewer by  doxygen 1.4.7