From 95a1bd5848a3c0faadbf2753058b7f9ec7c01834 Mon Sep 17 00:00:00 2001 From: Tazpn <tazpn@users.sourceforge.net> Date: Sun, 17 Jun 2007 01:58:42 +0000 Subject: [PATCH] More Collision helper methods --- include/obj/bhkConvexVerticesShape.h | 24 ++++++++++++ include/obj/bhkSphereRepShape.h | 12 ++++++ src/obj/bhkConvexVerticesShape.cpp | 56 ++++++++++++++++++++++++++++ src/obj/bhkSphereRepShape.cpp | 9 +++++ 4 files changed, 101 insertions(+) diff --git a/include/obj/bhkConvexVerticesShape.h b/include/obj/bhkConvexVerticesShape.h index 00ab1e73..4d488c31 100644 --- a/include/obj/bhkConvexVerticesShape.h +++ b/include/obj/bhkConvexVerticesShape.h @@ -72,6 +72,30 @@ public: */ NIFLIB_API vector<Vector3> GetNormals() const; + /*! + * Used to retrieve the distance to center for vertices. The size of the vector will either be zero if no normals are used, or be the same as the vertex count retrieved with the IShapeData::GetVertexCount function. + * \return A vector containing the normals used by this mesh, if any. + */ + NIFLIB_API vector<float> GetDistToCenter() const; + + /*! + * Used to set the vertex data used by this mesh. Calling this function will clear all other data in this object. + * \param in A vector containing the vertices to replace those in the mesh with. Note that there is no way to set vertices one at a time, they must be sent in one batch. + */ + NIFLIB_API void SetVertices( const vector<Vector3> & in ); + + /*! + * Used to set the normal data used by this mesh. The size of the vector must either be zero, or the same as the vertex count retrieved with the IShapeData::GetVertexCount function or the function will throw an exception. + * \param in A vector containing the normals to replace those in the mesh with. Note that there is no way to set normals one at a time, they must be sent in one batch. Use an empty vector to signify that this mesh will not be using normals. + */ + NIFLIB_API void SetNormals( const vector<Vector3> & in ); + + /*! + * Used to sets the distance to center for vertices. The size of the vector must either be zero, or the same as the vertex count retrieved with the IShapeData::GetVertexCount function or the function will throw an exception. + * \param in A vector containing the normals to replace those in the mesh with. Note that there is no way to set normals one at a time, they must be sent in one batch. Use an empty vector to signify that this mesh will not be using normals. + */ + NIFLIB_API void SetDistToCenter( const vector<float> & in ); + //--END CUSTOM CODE--// protected: /*! Unknown. */ diff --git a/include/obj/bhkSphereRepShape.h b/include/obj/bhkSphereRepShape.h index 00ce1ab9..27cb1b44 100644 --- a/include/obj/bhkSphereRepShape.h +++ b/include/obj/bhkSphereRepShape.h @@ -69,6 +69,18 @@ public: */ NIFLIB_API void SetMaterial( HavokMaterial value ); + /*! + * Gets the capsule's radius. + * \return The radius of the capsule. + */ + NIFLIB_API float GetRadius() const; + + /*! + * Sets the capsule's radius. + * \param[in] value The new radius for the capsule. + */ + NIFLIB_API void SetRadius( float value ); + //--END CUSTOM CODE--// protected: /*! The shape's material. */ diff --git a/src/obj/bhkConvexVerticesShape.cpp b/src/obj/bhkConvexVerticesShape.cpp index d6454a38..7f82e41f 100644 --- a/src/obj/bhkConvexVerticesShape.cpp +++ b/src/obj/bhkConvexVerticesShape.cpp @@ -178,4 +178,60 @@ vector<Vector3> bhkConvexVerticesShape::GetVertices() const { } return good_vertices; } + +vector<float> bhkConvexVerticesShape::GetDistToCenter() const +{ + //Remove any bad triangles + vector<float> good_dist; + for ( unsigned i = 0; i < normals.size(); ++i ) { + good_dist.push_back(normals[i][3]); + } + return good_dist; +} + +void bhkConvexVerticesShape::SetVertices( const vector<Vector3> & in ) +{ + int size = in.size(); + vertices.resize(size); + for (int i=0; i<size; ++i) + { + Float4 &f = vertices[i]; + const Vector3 &v = in[i]; + f[0] = v.x; + f[1] = v.y; + f[2] = v.z; + f[3] = 0.0f; + } +} + +void bhkConvexVerticesShape::SetNormals( const vector<Vector3> & in ) +{ + int size = in.size(); + normals.resize(size); + for (int i=0; i<size; ++i) + { + Float4 &f = normals[i]; + const Vector3 &v = in[i]; + f[0] = v.x; + f[1] = v.y; + f[2] = v.z; + f[3] = 0.0f; + } +} + +void bhkConvexVerticesShape::SetDistToCenter( const vector<float> & in ) +{ + if ( in.size() != normals.size() ) { + throw runtime_error("Distance vector size does not match normal size."); + } + int size = in.size(); + normals.resize(size); + for (int i=0; i<size; ++i) + { + Float4 &f = normals[i]; + f[3] = in[i]; + } +} + + //--END CUSTOM CODE--// diff --git a/src/obj/bhkSphereRepShape.cpp b/src/obj/bhkSphereRepShape.cpp index 7337a5cc..0e7bc31e 100644 --- a/src/obj/bhkSphereRepShape.cpp +++ b/src/obj/bhkSphereRepShape.cpp @@ -102,4 +102,13 @@ void bhkSphereRepShape::SetMaterial( HavokMaterial value ) { material = value; } +float bhkSphereRepShape::GetRadius() const { + return radius; +} + +void bhkSphereRepShape::SetRadius( float value ) { + radius = value; +} + + //--END CUSTOM CODE--// -- GitLab