Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 13, 2008, 11:45:51 PM (16 years ago)
Author:
rgrieder
Message:

Updated to Bullet 2.73 (first part).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h

    r2192 r2430  
    1919#include "btConcaveShape.h"
    2020
    21 ///The btHeightfieldTerrainShape simulates a 2D heightfield terrain collision shape. You can also use the more general btBvhTriangleMeshShape instead.
    22 ///An example implementation of btHeightfieldTerrainShape is provided in Demos/VehicleDemo/VehicleDemo.cpp
     21///btHeightfieldTerrainShape simulates a 2D heightfield terrain
     22/**
     23  The caller is responsible for maintaining the heightfield array; this
     24  class does not make a copy.
     25
     26  The heightfield can be dynamic so long as the min/max height values
     27  capture the extremes (heights must always be in that range).
     28
     29  The local origin of the heightfield is assumed to be the exact
     30  center (as determined by width and length and height, with each
     31  axis multiplied by the localScaling).
     32
     33  Most (but not all) rendering and heightfield libraries assume upAxis = 1
     34  (that is, the y-axis is "up").  This class allows any of the 3 coordinates
     35  to be "up".  Make sure your choice of axis is consistent with your rendering
     36  system.
     37
     38  The heightfield heights are determined from the data type used for the
     39  heightfieldData array. 
     40
     41   - PHY_UCHAR: height at a point is the uchar value at the
     42       grid point, multipled by heightScale.  uchar isn't recommended
     43       because of its inability to deal with negative values, and
     44       low resolution (8-bit).
     45
     46   - PHY_SHORT: height at a point is the short int value at that grid
     47       point, multipled by heightScale.
     48
     49   - PHY_FLOAT: height at a point is the float value at that grid
     50       point.  heightScale is ignored when using the float heightfield
     51       data type.
     52
     53  Whatever the caller specifies as minHeight and maxHeight will be honored.
     54  The class will not inspect the heightfield to discover the actual minimum
     55  or maximum heights.  These values are used to determine the heightfield's
     56  axis-aligned bounding box, multiplied by localScaling.
     57
     58  For usage and testing see the TerrainDemo.
     59 */
    2360class btHeightfieldTerrainShape : public btConcaveShape
    2461{
     
    2663        btVector3       m_localAabbMin;
    2764        btVector3       m_localAabbMax;
    28        
     65        btVector3       m_localOrigin;
     66
    2967        ///terrain data
    3068        int     m_heightStickWidth;
    3169        int m_heightStickLength;
     70        btScalar        m_minHeight;
    3271        btScalar        m_maxHeight;
    3372        btScalar m_width;
    3473        btScalar m_length;
     74        btScalar m_heightScale;
    3575        union
    3676        {
    3777                unsigned char*  m_heightfieldDataUnsignedChar;
     78                short*          m_heightfieldDataShort;
    3879                btScalar*                       m_heightfieldDataFloat;
    3980                void*                   m_heightfieldDataUnknown;
    4081        };
    41        
    42         bool    m_useFloatData;
     82
     83        PHY_ScalarType  m_heightDataType;       
    4384        bool    m_flipQuadEdges;
    4485  bool  m_useDiamondSubdivision;
     
    5293        void            getVertex(int x,int y,btVector3& vertex) const;
    5394
    54         inline bool testQuantizedAabbAgainstQuantizedAabb(int* aabbMin1, int* aabbMax1,const  int* aabbMin2,const  int* aabbMax2) const
    55         {
    56                 bool overlap = true;
    57                 overlap = (aabbMin1[0] > aabbMax2[0] || aabbMax1[0] < aabbMin2[0]) ? false : overlap;
    58                 overlap = (aabbMin1[2] > aabbMax2[2] || aabbMax1[2] < aabbMin2[2]) ? false : overlap;
    59                 overlap = (aabbMin1[1] > aabbMax2[1] || aabbMax1[1] < aabbMin2[1]) ? false : overlap;
    60                 return overlap;
    61         }
     95
     96
     97        /// protected initialization
     98        /**
     99          Handles the work of constructors so that public constructors can be
     100          backwards-compatible without a lot of copy/paste.
     101         */
     102        void initialize(int heightStickWidth, int heightStickLength,
     103                        void* heightfieldData, btScalar heightScale,
     104                        btScalar minHeight, btScalar maxHeight, int upAxis,
     105                        PHY_ScalarType heightDataType, bool flipQuadEdges);
    62106
    63107public:
    64         btHeightfieldTerrainShape(int heightStickWidth,int heightStickHeight,void* heightfieldData, btScalar maxHeight,int upAxis,bool useFloatData,bool flipQuadEdges);
     108        /// preferred constructor
     109        /**
     110          This constructor supports a range of heightfield
     111          data types, and allows for a non-zero minimum height value.
     112          heightScale is needed for any integer-based heightfield data types.
     113         */
     114        btHeightfieldTerrainShape(int heightStickWidth,int heightStickLength,
     115                                  void* heightfieldData, btScalar heightScale,
     116                                  btScalar minHeight, btScalar maxHeight,
     117                                  int upAxis, PHY_ScalarType heightDataType,
     118                                  bool flipQuadEdges);
     119
     120        /// legacy constructor
     121        /**
     122          The legacy constructor assumes the heightfield has a minimum height
     123          of zero.  Only unsigned char or floats are supported.  For legacy
     124          compatibility reasons, heightScale is calculated as maxHeight / 65535
     125          (and is only used when useFloatData = false).
     126         */
     127        btHeightfieldTerrainShape(int heightStickWidth,int heightStickLength,void* heightfieldData, btScalar maxHeight,int upAxis,bool useFloatData,bool flipQuadEdges);
    65128
    66129        virtual ~btHeightfieldTerrainShape();
Note: See TracChangeset for help on using the changeset viewer.