00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "bulletHeightfieldShape.h"
00016
00017 TypeHandle BulletHeightfieldShape::_type_handle;
00018
00019
00020
00021
00022
00023
00024 BulletHeightfieldShape::
00025 BulletHeightfieldShape(const PNMImage &image, PN_stdfloat max_height, BulletUpAxis up) {
00026
00027 _num_rows = image.get_x_size();
00028 _num_cols = image.get_y_size();
00029
00030 _data = new float[_num_rows * _num_cols];
00031
00032 for (int row=0; row < _num_rows; row++) {
00033 for (int column=0; column < _num_cols; column++) {
00034 _data[_num_cols * row + column] =
00035 max_height * image.get_bright(column, _num_cols - row - 1);
00036 }
00037 }
00038
00039 _shape = new btHeightfieldTerrainShape(_num_rows,
00040 _num_cols,
00041 _data,
00042 max_height,
00043 up,
00044 true, false);
00045 _shape->setUserPointer(this);
00046 }
00047
00048
00049
00050
00051
00052
00053 btCollisionShape *BulletHeightfieldShape::
00054 ptr() const {
00055
00056 return _shape;
00057 }
00058
00059
00060
00061
00062
00063
00064 void BulletHeightfieldShape::
00065 set_use_diamond_subdivision(bool flag) {
00066
00067 return _shape->setUseDiamondSubdivision(flag);
00068 }
00069