Panda3D
bulletHeightfieldShape.cxx
1 // Filename: bulletHeightfieldShape.cxx
2 // Created by: enn0x (05Feb10)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "bulletHeightfieldShape.h"
16 
17 TypeHandle BulletHeightfieldShape::_type_handle;
18 
19 ////////////////////////////////////////////////////////////////////
20 // Function: BulletHeightfieldShape::Constructor
21 // Access: Published
22 // Description:
23 ////////////////////////////////////////////////////////////////////
24 BulletHeightfieldShape::
25 BulletHeightfieldShape(const PNMImage &image, PN_stdfloat max_height, BulletUpAxis up) {
26 
27  _num_rows = image.get_x_size();
28  _num_cols = image.get_y_size();
29 
30  _data = new float[_num_rows * _num_cols];
31 
32  for (int row=0; row < _num_rows; row++) {
33  for (int column=0; column < _num_cols; column++) {
34  _data[_num_cols * row + column] =
35  max_height * image.get_bright(column, _num_cols - row - 1);
36  }
37  }
38 
39  _shape = new btHeightfieldTerrainShape(_num_rows,
40  _num_cols,
41  _data,
42  max_height,
43  up,
44  true, false);
45  _shape->setUserPointer(this);
46 }
47 
48 ////////////////////////////////////////////////////////////////////
49 // Function: BulletHeightfieldShape::ptr
50 // Access: Public
51 // Description:
52 ////////////////////////////////////////////////////////////////////
53 btCollisionShape *BulletHeightfieldShape::
54 ptr() const {
55 
56  return _shape;
57 }
58 
59 ////////////////////////////////////////////////////////////////////
60 // Function: BulletHeightfieldShape::set_use_diamond_subdivision
61 // Access: Published
62 // Description:
63 ////////////////////////////////////////////////////////////////////
64 void BulletHeightfieldShape::
65 set_use_diamond_subdivision(bool flag) {
66 
67  return _shape->setUseDiamondSubdivision(flag);
68 }
69 
The name of this class derives from the fact that we originally implemented it as a layer on top of t...
Definition: pnmImage.h:68
int get_y_size() const
Returns the number of pixels in the Y direction.
int get_x_size() const
Returns the number of pixels in the X direction.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
float get_bright(int x, int y) const
Returns the linear brightness of the given xel, as a linearized float in the range 0...
Definition: pnmImage.I:1020