Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8321 in orxonox.OLD


Ignore:
Timestamp:
Jun 11, 2006, 9:02:58 PM (18 years ago)
Author:
ponder
Message:

Added a getAltitude() method to the Terrain class to retrieve the height at a given point on
the terrain. I hope the method works. It needs some testing

Location:
branches/terrain/src/lib/graphics/importer/terrain
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/terrain/src/lib/graphics/importer/terrain/terrain.cc

    r8319 r8321  
    156156}
    157157
     158
     159
    158160void Terrain::getAltitude( Triple& _alt, Triple& _normal )
    159161{
    160        
     162        float xScaled = _alt.x / scale.x, zScaled = _alt.z / scale.z;
     163        //The offset on the map
     164        int xOff =  (int)xScaled, zOff = (int)zScaled;
     165        //The interpolation values.
     166        float u = xScaled-xOff, v = zScaled-zOff;
     167       
     168        float dX = scale.x / ( pageSize-1 );
     169        float dZ = scale.z / ( pageSize-1 );
     170       
     171        //If u is bigger than v, we are on the lower triangle...
     172        if ( u > v ) {
     173               
     174                float alt[] = {
     175                        getAltitude( xOff+0, zOff+0 )*scale.y,
     176                        getAltitude( xOff+1, zOff+0 )*scale.y,
     177                        getAltitude( xOff+1, zOff+1 )*scale.y };
     178                _alt.y = (1.0f-u)*(1.0-v)*alt[0]+u*(1.0f-v)*alt[1]+u*v*alt[2];
     179               
     180                //Since we know about the directions of some x and z-coordinates,
     181                //not the whole cross products needs to be calculated. Grab yourself
     182                //pen and paper :)
     183                _normal.x = -dZ*( alt[0] - alt[1] );                           
     184                _normal.y = -dZ*dX;
     185                _normal.z =  dX*( alt[2] - alt[1] );
     186        }
     187        else {
     188                float alt[] = {
     189                        getAltitude( xOff+0, zOff+0 )*scale.y,
     190                        getAltitude( xOff+0, zOff+1 )*scale.y,
     191                        getAltitude( xOff+1, zOff+1 )*scale.y };                       
     192                _alt.y = (1.0f-u)*(1.0-v)*alt[0]+(1.0f-u)*v*alt[1]+u*v*alt[2];
     193                //Since we know about the directions of some x and z-coordinates,
     194                //not the whole cross products needs to be calculated. Grab yourself
     195                //pen and paper :)
     196                _normal.x =  dZ*( alt[2] - alt[1] );                           
     197                _normal.y = -dZ*dX;
     198                _normal.z = -dX*( alt[0] - alt[1] );
     199        }
    161200}
    162201
  • branches/terrain/src/lib/graphics/importer/terrain/terrain_page.cc

    r8319 r8321  
    6565                wantedLOD = TerrainPage::MAX_LODS-1;
    6666        }       
    67        
     67        // Calculate the tween factor. This is differently if the LOD is 0.
     68        if ( wantedLOD > 0 ) {
     69               
     70        }
     71        else {
     72               
     73        }
    6874        return wantedLOD;
    6975}
  • branches/terrain/src/lib/graphics/importer/terrain/terrain_page.h

    r8320 r8321  
    4444                 */
    4545                TerrainPage( Terrain *_owner, int _xOffset, int _zOffset );
     46               
    4647                /**
    4748                 * This is used only internally for communication between the TerrainPage and
     
    5859               
    5960                /**
    60                  * Makes the terrain look as if it were created with the given level of
     61                 * @brief Makes the terrain look as if it were created with the given level of
    6162                 * detail.
    6263                 */
     
    6465               
    6566                /**
    66                  * Draws a box around the TerrainPage. For debugging purposes.
     67                 * @brief Draws a box around the TerrainPage. For debugging purposes.
    6768                 */
    6869                void drawBox();
    6970               
    7071                /**
    71                  * Calculates the smallest fitting axis aligned bounding box for this TerrainPage.
     72                 * @brief Calculates the smallest fitting axis aligned bounding box for this TerrainPage.
    7273                 */
    7374                virtual void calculateBounds();         
     
    7576               
    7677                /**
    77                  * Sets the visibility to _flag. If the visibility changed, the vertex and index
     78                 * @brief Sets the visibility to _flag. If the visibility changed, the vertex and index
    7879                 * arrays are allocated or freed, respectively.
    7980                 */
     
    8182
    8283                /**
    83                  * Prepares the page for rendering.
     84                 * @brief Prepares the page for rendering.
    8485                 */
    8586                void show( );
    8687               
    8788                /**
     89                 * @brief Frees most of the memory for economomical reasons.
     90                 */
     91                void hide( );
     92               
     93                /**
     94                 * @brief Updates the tesselation if necessary.
     95                 */
     96                void updateTesselation( );
     97               
     98                /**
     99                 * @return The current tesselation level.
     100                 */
     101                int getLOD() { return currentLOD; }
     102               
     103                /**
     104                 * @return The curren tween factor. This is a floating point value  between 0.0f and 1.0f
     105                 */
     106                float getTween() { return 0.0f; }
     107               
     108                /**
     109                 * @brief Determines the new LOD which should be used by this terrain page based on
     110                 * the distance from the camera.
    88111                 *
    89                  */
    90                 void hide( );
    91                
    92                 /**
    93                  * Updates the tesselation if necessary.
    94                  */
    95                 void updateTesselation( );
    96                
    97                 /**
    98                  * Returns the current tesselation level.
    99                  */
    100                 int getLOD() { return currentLOD; }
    101                
    102                 /**
    103                  * Returns the curren tween factor. This is a floating point value  between 0.0f and 1.0f
    104                  */
    105                 float getTween() { return 0.0f; }
    106                
    107                 /**
    108                  * Determines the new LOD which should be used by this terrain page based on
    109                  * the distance from the camera.
    110                  * Note: No geometry is updated in this method. You need to call
     112                 * No geometry is updated in this method. You need to call
    111113                 * updateTesselation() in order to see a change in geometry. This method is
    112114                 * just a recommandation.
     
    118120                 * current frame, this function returns true, else you'll get false as the
    119121                 * return value.
     122                 * @return True if the page needs an update and false if not.
    120123                 */
    121124                bool isDirty() { return forceTesselation; }
    122125               
    123126                /**
    124                  * Calculates the maximal errors for every LOD.
     127                 * @brief Calculates the maximal errors for every LOD.
    125128                 */
    126129                void calculateErrors();
    127130               
    128131                /**
    129                  * Calculates the error for the given LOD. We just need to know the "worst"
     132                 * @brief Calculates the error for the given LOD. We just need to know the "worst"
    130133                 * vertex for choosing an appropriate LOD.
    131134                 */
     
    164167               
    165168                /**
    166                  * Returns the next active page
     169                 * @return the next active page
    167170                 */
    168171                inline pTerrainPage getNext() { return next; }
     
    174177               
    175178                /**
    176                  * Returns the wanted LOD. Make sure you call this method after a call to
     179                 * @return Returns the wanted LOD. Make sure you call this method after a call to
    177180                 * chooseLOD() or you will get screwed values.
    178181                 */
     
    180183               
    181184                /**
    182                  * Removes the page from the active page list.
     185                 * @brief Removes the page from the active page list.
    183186                 */
    184187                void deactivate();
    185188               
    186189                /**
    187                  * Inserts the page into the active page list.
     190                 * @brief Inserts the page into the active page list.
    188191                 */
    189192                void activate();               
     193               
    190194                protected:
    191195                       
     
    216220                        int                                                     currentLOD,
    217221                                                                                wantedLOD;
     222                        float                                           tween;
    218223                        pTerrainPage                            left,
    219224                                                                                right,
Note: See TracChangeset for help on using the changeset viewer.