/* * Copyright (c) 2005 Erwin Coumans http://www.erwincoumans.com * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, * provided that the above copyright notice appear in all copies. * Erwin Coumans makes no representations about the suitability * of this software for any purpose. * It is provided "as is" without express or implied warranty. */ #include "CombinedSimplexSolver.h" #include //switch off asserts //#define MY_ASSERT assert #define MY_ASSERT bool useVoronoi = true; CombinedSimplexSolver::CombinedSimplexSolver() :m_useVoronoiSolver(useVoronoi) { } void CombinedSimplexSolver::reset() { m_voronoiSolver.reset(); m_johnsonSolver.reset(); } void CombinedSimplexSolver::addVertex(const SimdVector3& w, const SimdPoint3& p, const SimdPoint3& q) { printf("addVertex (%f %f %f)\n",w[0],w[1],w[2]); m_voronoiSolver.addVertex(w,p,q); m_johnsonSolver.addVertex(w,p,q); int i; i=0; SimdPoint3 vp1,vp2; SimdPoint3 jp1,jp2; /* bool isClosest0 = m_voronoiSolver.closest(vp1); bool isClosest1 = m_johnsonSolver.closest(vp1); m_voronoiSolver.compute_points(vp1, vp2); m_johnsonSolver.compute_points(jp1,jp2); i=0; */ } bool CombinedSimplexSolver::closest(SimdVector3& v) { bool result0 = 0; bool result1 = 0; SimdVector3 v0,v1; result0 = m_voronoiSolver.closest(v0); result1 = m_johnsonSolver.closest(v1); if (result0 != result1) { result0 = m_voronoiSolver.closest(v0); result1 = m_johnsonSolver.closest(v1); int i; i=0; } if (m_useVoronoiSolver) { v = v0; return result0; } v = v1; return result1; } SimdScalar CombinedSimplexSolver::maxVertex() { SimdScalar maxv0 = m_voronoiSolver.maxVertex(); SimdScalar maxv1 = m_johnsonSolver.maxVertex(); MY_ASSERT(maxv0 = maxv1); if (m_useVoronoiSolver) return maxv0; return maxv1; } bool CombinedSimplexSolver::fullSimplex() const { bool fullSimplex0 = m_voronoiSolver.fullSimplex(); bool fullSimplex1 = m_johnsonSolver.fullSimplex(); MY_ASSERT(fullSimplex0 == fullSimplex1); if (m_useVoronoiSolver) return fullSimplex0; return fullSimplex1; } int CombinedSimplexSolver::getSimplex(SimdPoint3 *pBuf, SimdPoint3 *qBuf, SimdVector3 *yBuf) const { int simplex0 = m_voronoiSolver.getSimplex(pBuf, qBuf, yBuf); int simplex1 = m_johnsonSolver.getSimplex(pBuf, qBuf, yBuf); // MY_ASSERT(simplex0 == simplex1); if (m_useVoronoiSolver) { return m_voronoiSolver.getSimplex(pBuf, qBuf, yBuf); } return simplex1; } void CombinedSimplexSolver::debugPrint() { SimdPoint3 pBuf0[4]; SimdPoint3 qBuf0[4]; SimdPoint3 yBuf0[4]; SimdPoint3 pBuf1[4]; SimdPoint3 qBuf1[4]; SimdPoint3 yBuf1[4]; int verts0,verts1; verts0 = m_voronoiSolver.getSimplex(&pBuf0[0], &qBuf0[0], &yBuf0[0]); verts1 = m_johnsonSolver.getSimplex(&pBuf1[0], &qBuf1[0], &yBuf1[0]); printf("numverts0 = %d, numverts1 = %d\n",verts0,verts1); for (int i=0;i