Panda3D
physxSoftBodyMeshDesc.cxx
1 // Filename: physxSoftBodyMeshDesc.cxx
2 // Created by: enn0x (12Sep10)
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 "physxSoftBodyMeshDesc.h"
16 #include "physxManager.h"
17 
18 ////////////////////////////////////////////////////////////////////
19 // Function: PhysxSoftBodyMeshDesc::set_num_vertices
20 // Access: Published
21 // Description: Sets the number of vertices to be stored within
22 // this soft body mesh. The function allocates memory
23 // for the vertices, but it does not set any vertices.
24 //
25 // This method must be called before any calls to
26 // set_vertex are done!
27 ////////////////////////////////////////////////////////////////////
29 set_num_vertices(unsigned int numVertices) {
30 
31  // Vertices
32  if (_desc.vertices) {
33  delete [] _vertices;
34  }
35 
36  _vertices = new NxVec3[numVertices];
37 
38  _desc.numVertices = numVertices;
39  _desc.vertices = _vertices;
40 }
41 
42 ////////////////////////////////////////////////////////////////////
43 // Function: PhysxSoftBodyMeshDesc::set_vertex
44 // Access: Published
45 // Description: Sets a single vertex. You have to call the function
46 // set_num_vertices before you can call this function.
47 ////////////////////////////////////////////////////////////////////
49 set_vertex(unsigned int idx, const LPoint3f &vert) {
50 
51  nassertv(_desc.numVertices > idx);
52 
53  _vertices[idx] = PhysxManager::point3_to_nxVec3(vert);
54 }
55 
56 ////////////////////////////////////////////////////////////////////
57 // Function: PhysxSoftBodyMeshDesc::set_num_tetrahedra
58 // Access: Published
59 // Description: Sets the number of tetrahedra to be stored in this
60 // soft body mesh.
61 //
62 // This method must be called before any calls to
63 // set_tetrahedron are done!
64 ////////////////////////////////////////////////////////////////////
66 set_num_tetrahedra(unsigned int numTetrahedra) {
67 
68  if (_desc.tetrahedra) {
69  delete [] _tetrahedra;
70  }
71 
72  _tetrahedra = new NxU32[4 * numTetrahedra];
73 
74  _desc.numTetrahedra = numTetrahedra;
75  _desc.tetrahedra = _tetrahedra;
76 }
77 
78 ////////////////////////////////////////////////////////////////////
79 // Function: PhysxSoftBodyMeshDesc::set_tetrahedron
80 // Access: Published
81 // Description: Sets a single tetrahedron, by providing the three
82 // indices i1, i2, i3, i4.
83 ////////////////////////////////////////////////////////////////////
85 set_tetrahedron(unsigned int idx,
86  unsigned int i1, unsigned int i2, unsigned int i3, unsigned int i4) {
87 
88  nassertv(_desc.numTetrahedra > idx);
89 
90  idx = 4 * idx;
91  _tetrahedra[idx] = i1;
92  _tetrahedra[idx + 1] = i2;
93  _tetrahedra[idx + 2] = i3;
94  _tetrahedra[idx + 3] = i4;
95 }
96 
void set_num_tetrahedra(unsigned int n)
Sets the number of tetrahedra to be stored in this soft body mesh.
static NxVec3 point3_to_nxVec3(const LPoint3f &p)
Converts from LPoint3f to NxVec3.
Definition: physxManager.I:77
void set_num_vertices(unsigned int n)
Sets the number of vertices to be stored within this soft body mesh.
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
void set_vertex(unsigned int idx, const LPoint3f &vert)
Sets a single vertex.
void set_tetrahedron(unsigned int idx, unsigned int i1, unsigned int i2, unsigned int i3, unsigned int i4)
Sets a single tetrahedron, by providing the three indices i1, i2, i3, i4.