Panda3D
physxHeightFieldDesc.I
1 // Filename: physxHeightFieldDesc.I
2 // Created by: enn0x (15Oct09)
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 
16 
17 ////////////////////////////////////////////////////////////////////
18 // Function: PhysxHeightFieldDesc::Constructor
19 // Access: Published
20 // Description:
21 ////////////////////////////////////////////////////////////////////
22 INLINE PhysxHeightFieldDesc::
23 PhysxHeightFieldDesc() {
24 
25  _samples = NULL;
26  _desc.setToDefault();
27 }
28 
29 ////////////////////////////////////////////////////////////////////
30 // Function: PhysxHeightFieldDesc::Destructor
31 // Access: Published
32 // Description:
33 ////////////////////////////////////////////////////////////////////
34 INLINE PhysxHeightFieldDesc::
35 ~PhysxHeightFieldDesc() {
36 
37 }
38 
39 ////////////////////////////////////////////////////////////////////
40 // Function: PhysxHeightFieldDesc::set_to_default
41 // Access: Published
42 // Description: (re)sets the structure to the default.
43 ////////////////////////////////////////////////////////////////////
44 INLINE void PhysxHeightFieldDesc::
46 
47  _desc.setToDefault();
48 }
49 
50 ////////////////////////////////////////////////////////////////////
51 // Function: PhysxHeightFieldDesc::is_valid
52 // Access: Published
53 // Description: Returns true if the descriptor is valid.
54 ////////////////////////////////////////////////////////////////////
55 INLINE bool PhysxHeightFieldDesc::
56 is_valid() const {
57 
58  return _desc.isValid();
59 }
60 
61 ////////////////////////////////////////////////////////////////////
62 // Function: PhysxHeightFieldDesc::set_size
63 // Access: Private
64 // Description:
65 ////////////////////////////////////////////////////////////////////
66 INLINE void PhysxHeightFieldDesc::
67 set_size(unsigned int num_rows, unsigned int num_columns) {
68 
69  if (_samples) {
70  unset_size();
71  }
72 
73  _desc.format = NX_HF_S16_TM;
74  _desc.nbRows = (NxU32) num_rows;
75  _desc.nbColumns = (NxU32) num_columns;
76  _desc.sampleStride = sizeof(NxU32);
77 
78  _samples = new NxU32[_desc.nbColumns * _desc.nbRows];
79  _desc.samples = _samples;
80 
81 }
82 
83 ////////////////////////////////////////////////////////////////////
84 // Function: PhysxHeightFieldDesc::unset_size
85 // Access: Private
86 // Description: Releases the memory allocated for the height field
87 // samples.
88 ////////////////////////////////////////////////////////////////////
89 INLINE void PhysxHeightFieldDesc::
90 unset_size() {
91 
92  if (_samples) {
93  _desc.nbRows = (NxU32) 0;
94  _desc.nbColumns = (NxU32) 0;
95  _desc.samples = NULL;
96  delete[] _samples;
97  }
98 }
99 
void set_to_default()
(re)sets the structure to the default.
bool is_valid() const
Returns true if the descriptor is valid.