From 613b0016787b2b16e936ec8473f078fe6d95dc93 Mon Sep 17 00:00:00 2001 From: Branan Purvine-Riley Date: Sun, 16 Mar 2014 14:26:40 -0700 Subject: [PATCH] Clean up plDistributor max/pl point interop There were two terrible things here: * Some nasty pointer-based casting * Storing references to temporaries Unfortunately, storing addrs of temps was happening through a helper function, so VS won't warn here. I think I caught all the cases where those functions were being used wrongly, but I can't be sure until coverity runs on this commit. --- Sources/Tools/MaxConvert/plDistributor.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Sources/Tools/MaxConvert/plDistributor.cpp b/Sources/Tools/MaxConvert/plDistributor.cpp index 20cab330..517eeb3b 100644 --- a/Sources/Tools/MaxConvert/plDistributor.cpp +++ b/Sources/Tools/MaxConvert/plDistributor.cpp @@ -83,8 +83,11 @@ static const float kMaxHeight = 10.f; // overall rnd - overall probability that a candidate seed point (passing all other criteria) will be used // -static inline hsPoint3& hsP3(const Point3& p) { return *(hsPoint3*)&p; } -static inline hsVector3& hsV3(const Point3& p) { return *(hsVector3*)&p; } + +static inline const hsPoint3& hsP3(const Point3& p) { return reinterpret_cast(p); } +static inline const hsVector3& hsV3(const Point3& p) { return reinterpret_cast(p); } +static inline hsPoint3& hsP3(Point3& p) { return reinterpret_cast(p); } +static inline hsVector3& hsV3(Point3& p) { return reinterpret_cast(p); } static inline Matrix3 Transpose(const Matrix3& m) { return Matrix3(m.GetColumn3(0), m.GetColumn3(1), m.GetColumn3(2), Point3(0,0,0)); @@ -1010,9 +1013,9 @@ BOOL plDistributor::IProjectVertex(const Point3& pt, const Point3& dir, float ma for( i = 0; i < faces.Count(); i++ ) { int iFace = faces[i]; - const hsPoint3& p0 = hsP3(fSurfMesh->getVert(fSurfMesh->faces[iFace].getVert(0)) * fSurfToWorld); - const hsPoint3& p1 = hsP3(fSurfMesh->getVert(fSurfMesh->faces[iFace].getVert(1)) * fSurfToWorld); - const hsPoint3& p2 = hsP3(fSurfMesh->getVert(fSurfMesh->faces[iFace].getVert(2)) * fSurfToWorld); + hsPoint3 p0 = hsP3(fSurfMesh->getVert(fSurfMesh->faces[iFace].getVert(0)) * fSurfToWorld); + hsPoint3 p1 = hsP3(fSurfMesh->getVert(fSurfMesh->faces[iFace].getVert(1)) * fSurfToWorld); + hsPoint3 p2 = hsP3(fSurfMesh->getVert(fSurfMesh->faces[iFace].getVert(2)) * fSurfToWorld); Point3 plnPt = pt; if( triUtil.ProjectOntoPlaneAlongVector(p0, p1, p2, hsV3(dir), hsP3(plnPt)) )