Panda3D
 All Classes Functions Variables Enumerations
physxSoftBodyMeshDesc.cxx
00001 // Filename: physxSoftBodyMeshDesc.cxx
00002 // Created by:  enn0x (12Sep10)
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 "physxSoftBodyMeshDesc.h"
00016 #include "physxManager.h"
00017 
00018 ////////////////////////////////////////////////////////////////////
00019 //     Function: PhysxSoftBodyMeshDesc::set_num_vertices
00020 //       Access: Published
00021 //  Description: Sets the number of vertices to be stored within
00022 //               this soft body mesh. The function allocates memory
00023 //               for the vertices, but it does not set any vertices.
00024 //
00025 //               This method must be called before any calls to
00026 //               set_vertex are done!
00027 ////////////////////////////////////////////////////////////////////
00028 void PhysxSoftBodyMeshDesc::
00029 set_num_vertices(unsigned int numVertices) {
00030 
00031   // Vertices
00032   if (_desc.vertices) {
00033     delete [] _vertices;
00034   }
00035 
00036   _vertices = new NxVec3[numVertices];
00037 
00038   _desc.numVertices = numVertices;
00039   _desc.vertices = _vertices;
00040 }
00041 
00042 ////////////////////////////////////////////////////////////////////
00043 //     Function: PhysxSoftBodyMeshDesc::set_vertex
00044 //       Access: Published
00045 //  Description: Sets a single vertex. You have to call the function
00046 //               set_num_vertices before you can call this function.
00047 ////////////////////////////////////////////////////////////////////
00048 void PhysxSoftBodyMeshDesc::
00049 set_vertex(unsigned int idx, const LPoint3f &vert) {
00050 
00051   nassertv(_desc.numVertices > idx);
00052 
00053   _vertices[idx] = PhysxManager::point3_to_nxVec3(vert);
00054 }
00055 
00056 ////////////////////////////////////////////////////////////////////
00057 //     Function: PhysxSoftBodyMeshDesc::set_num_tetrahedra
00058 //       Access: Published
00059 //  Description: Sets the number of tetrahedra to be stored in this
00060 //               soft body mesh.
00061 //
00062 //               This method must be called before any calls to
00063 //               set_tetrahedron are done!
00064 ////////////////////////////////////////////////////////////////////
00065 void PhysxSoftBodyMeshDesc::
00066 set_num_tetrahedra(unsigned int numTetrahedra) {
00067 
00068   if (_desc.tetrahedra) {
00069     delete [] _tetrahedra;
00070   }
00071 
00072   _tetrahedra = new NxU32[4 * numTetrahedra];
00073 
00074   _desc.numTetrahedra = numTetrahedra;
00075   _desc.tetrahedra = _tetrahedra;
00076 }
00077 
00078 ////////////////////////////////////////////////////////////////////
00079 //     Function: PhysxSoftBodyMeshDesc::set_tetrahedron
00080 //       Access: Published
00081 //  Description: Sets a single tetrahedron, by providing the three
00082 //               indices i1, i2, i3, i4.
00083 ////////////////////////////////////////////////////////////////////
00084 void PhysxSoftBodyMeshDesc::
00085 set_tetrahedron(unsigned int idx,
00086                 unsigned int i1, unsigned int i2, unsigned int i3, unsigned int i4) {
00087 
00088   nassertv(_desc.numTetrahedra > idx);
00089 
00090   idx = 4 * idx;
00091   _tetrahedra[idx]     = i1;
00092   _tetrahedra[idx + 1] = i2;
00093   _tetrahedra[idx + 2] = i3;
00094   _tetrahedra[idx + 3] = i4;
00095 }
00096 
 All Classes Functions Variables Enumerations