Panda3D
|
00001 // Filename: bulletHeightfieldShape.cxx 00002 // Created by: enn0x (05Feb10) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "bulletHeightfieldShape.h" 00016 00017 TypeHandle BulletHeightfieldShape::_type_handle; 00018 00019 //////////////////////////////////////////////////////////////////// 00020 // Function: BulletHeightfieldShape::Constructor 00021 // Access: Published 00022 // Description: 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 // Function: BulletHeightfieldShape::ptr 00050 // Access: Public 00051 // Description: 00052 //////////////////////////////////////////////////////////////////// 00053 btCollisionShape *BulletHeightfieldShape:: 00054 ptr() const { 00055 00056 return _shape; 00057 } 00058 00059 //////////////////////////////////////////////////////////////////// 00060 // Function: BulletHeightfieldShape::set_use_diamond_subdivision 00061 // Access: Published 00062 // Description: 00063 //////////////////////////////////////////////////////////////////// 00064 void BulletHeightfieldShape:: 00065 set_use_diamond_subdivision(bool flag) { 00066 00067 return _shape->setUseDiamondSubdivision(flag); 00068 } 00069