Panda3D
physxSoftBodyMeshDesc.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file physxSoftBodyMeshDesc.cxx
10  * @author enn0x
11  * @date 2010-09-12
12  */
13 
14 #include "physxSoftBodyMeshDesc.h"
15 #include "physxManager.h"
16 
17 /**
18  * Sets the number of vertices to be stored within this soft body mesh. The
19  * function allocates memory for the vertices, but it does not set any
20  * vertices.
21  *
22  * This method must be called before any calls to set_vertex are done!
23  */
25 set_num_vertices(unsigned int numVertices) {
26 
27  // Vertices
28  if (_desc.vertices) {
29  delete [] _vertices;
30  }
31 
32  _vertices = new NxVec3[numVertices];
33 
34  _desc.numVertices = numVertices;
35  _desc.vertices = _vertices;
36 }
37 
38 /**
39  * Sets a single vertex. You have to call the function set_num_vertices
40  * before you can call this function.
41  */
43 set_vertex(unsigned int idx, const LPoint3f &vert) {
44 
45  nassertv(_desc.numVertices > idx);
46 
47  _vertices[idx] = PhysxManager::point3_to_nxVec3(vert);
48 }
49 
50 /**
51  * Sets the number of tetrahedra to be stored in this soft body mesh.
52  *
53  * This method must be called before any calls to set_tetrahedron are done!
54  */
56 set_num_tetrahedra(unsigned int numTetrahedra) {
57 
58  if (_desc.tetrahedra) {
59  delete [] _tetrahedra;
60  }
61 
62  _tetrahedra = new NxU32[4 * numTetrahedra];
63 
64  _desc.numTetrahedra = numTetrahedra;
65  _desc.tetrahedra = _tetrahedra;
66 }
67 
68 /**
69  * Sets a single tetrahedron, by providing the three indices i1, i2, i3, i4.
70  */
72 set_tetrahedron(unsigned int idx,
73  unsigned int i1, unsigned int i2, unsigned int i3, unsigned int i4) {
74 
75  nassertv(_desc.numTetrahedra > idx);
76 
77  idx = 4 * idx;
78  _tetrahedra[idx] = i1;
79  _tetrahedra[idx + 1] = i2;
80  _tetrahedra[idx + 2] = i3;
81  _tetrahedra[idx + 3] = i4;
82 }
static NxVec3 point3_to_nxVec3(const LPoint3f &p)
Converts from LPoint3f to NxVec3.
Definition: physxManager.I:63
void set_num_vertices(unsigned int n)
Sets the number of vertices to be stored within this soft body mesh.
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.
void set_num_tetrahedra(unsigned int n)
Sets the number of tetrahedra to be stored in this soft body mesh.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.