Build error of 0.15.1 and 0.15.2 with external libccd

Issue #40 resolved
Jeongseok Lee created an issue

It seems 0.15.1 and 0.15.2 cannot be built for a specific build option (--enable-libccd). When I build 0.15.1 and 0.15.2 (tested both on macOS sierra and ubuntu trusty), I got following errors:

$ ./configure --enable-libccd
$ make
# ...
Last 15 lines from /Users/jeongseoklee/Library/Logs/Homebrew/ode/03.make:
libtool: compile:  clang++ -DPACKAGE_NAME=\"ou\" -DPACKAGE_TARNAME=\"ou\" -DPACKAGE_VERSION=\"0\" "-DPACKAGE_STRING=\"ou 0\"" -DPACKAGE_BUGREPORT=\"oleh_derevenko@users.sourceforge.net\" -DPACKAGE_URL=\"\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -D__EXTENSIONS__=1 -D_ALL_SOURCE=1 -D_GNU_SOURCE=1 -D_POSIX_PTHREAD_SEMANTICS=1 -D_TANDEM_SOURCE=1 -DPACKAGE=\"ou\" -DVERSION=\"0\" -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -DHAVE_LIBC=1 -DHAVE_LIBPTHREAD=1 -D_REENTRANT=1 -DSTDC_HEADERS=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDDEF_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_STDBOOL_H=1 -DHAVE_PTRDIFF_T=1 -DHAVE_MEMSET=1 -DMAC_OS_X_VERSION=1050 -D_OU_TARGET_OS=_OU_TARGET_OS_MAC -I. -I../../include -D_OU_NAMESPACE=odeou -D_OU_FEATURE_SET=_OU_FEATURE_SET_ATOMICS -fno-exceptions -fno-rtti -g -O2 -MT threadlocalstorage.lo -MD -MP -MF .deps/threadlocalstorage.Tpo -c threadlocalstorage.cpp -o threadlocalstorage.o >/dev/null 2>&1
In file included from atomic.cpp:32:
../../include/ou/atomic.h:717:2: error: unknown type name '__ou_cmpxchg_value_t'
        __ou_cmpxchg_value_t aoOldValue = *paoDestination;
        ^
libtool: compile:  clang++ -DPACKAGE_NAME=\"ou\" -DPACKAGE_TARNAME=\"ou\" -DPACKAGE_VERSION=\"0\" "-DPACKAGE_STRING=\"ou 0\"" -DPACKAGE_BUGREPORT=\"oleh_derevenko@users.sourceforge.net\" -DPACKAGE_URL=\"\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -D__EXTENSIONS__=1 -D_ALL_SOURCE=1 -D_GNU_SOURCE=1 -D_POSIX_PTHREAD_SEMANTICS=1 -D_TANDEM_SOURCE=1 -DPACKAGE=\"ou\" -DVERSION=\"0\" -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -DHAVE_LIBC=1 -DHAVE_LIBPTHREAD=1 -D_REENTRANT=1 -DSTDC_HEADERS=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDDEF_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_STDBOOL_H=1 -DHAVE_PTRDIFF_T=1 -DHAVE_MEMSET=1 -DMAC_OS_X_VERSION=1050 -D_OU_TARGET_OS=_OU_TARGET_OS_MAC -I. -I../../include -D_OU_NAMESPACE=odeou -D_OU_FEATURE_SET=_OU_FEATURE_SET_ATOMICS -fno-exceptions -fno-rtti -g -O2 -MT customization.lo -MD -MP -MF .deps/customization.Tpo -c customization.cpp -o customization.o >/dev/null 2>&1
1 error generated.
make[2]: *** [atomic.lo] Error 1
make[2]: *** Waiting for unfinished jobs....
libtool: compile:  clang++ -DPACKAGE_NAME=\"ou\" -DPACKAGE_TARNAME=\"ou\" -DPACKAGE_VERSION=\"0\" "-DPACKAGE_STRING=\"ou 0\"" -DPACKAGE_BUGREPORT=\"oleh_derevenko@users.sourceforge.net\" -DPACKAGE_URL=\"\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -D__EXTENSIONS__=1 -D_ALL_SOURCE=1 -D_GNU_SOURCE=1 -D_POSIX_PTHREAD_SEMANTICS=1 -D_TANDEM_SOURCE=1 -DPACKAGE=\"ou\" -DVERSION=\"0\" -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -DHAVE_LIBC=1 -DHAVE_LIBPTHREAD=1 -D_REENTRANT=1 -DSTDC_HEADERS=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDDEF_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_STDBOOL_H=1 -DHAVE_PTRDIFF_T=1 -DHAVE_MEMSET=1 -DMAC_OS_X_VERSION=1050 -D_OU_TARGET_OS=_OU_TARGET_OS_MAC -I. -I../../include -D_OU_NAMESPACE=odeou -D_OU_FEATURE_SET=_OU_FEATURE_SET_ATOMICS -fno-exceptions -fno-rtti -g -O2 -MT malloc.lo -MD -MP -MF .deps/malloc.Tpo -c malloc.cpp -o malloc.o >/dev/null 2>&1
mv -f .deps/threadlocalstorage.Tpo .deps/threadlocalstorage.Plo
mv -f .deps/customization.Tpo .deps/customization.Plo
mv -f .deps/malloc.Tpo .deps/malloc.Plo
make[1]: *** [all-recursive] Error 1
make: *** [all-recursive] Error 1

Comments (17)

  1. Oleh Derevenko Account Deactivated

    I have made a fix in the latest version. Please get the sources from the Mercurial repository and check if the problem is resolved. If that's the case I'll merge the fix into 0.15.x branch and publish a new release.

  2. Jeongseok Lee reporter

    Thanks for the quick reply!

    I tested the latest commit in the default branch (b9c7c5a) but still get the following errors:

    $ ./bootstrap
    $ ./configure --enable-libccd
    $ make
    # ...
    collision_libccd.cpp: In function 'void ccdGeomToCyl(dGeomID, ccd_cyl_t*)':
    collision_libccd.cpp:178:65: error: void value not ignored as it ought to be
         int cylAxisNormalizationResult = ccdVec3Normalize(&cyl->axis);
                                                                     ^
    collision_libccd.cpp: In function 'bool correctTriangleContactNormal(ccd_triangle_t*, dContactGeom*, IFaceAngleStorageView*, const int*, unsigned int)':
    collision_libccd.cpp:897:67: error: 'ccdVec3CopyScaled' was not declared in this scope
         ccdVec3CopyScaled(&cntScaledNormal, &cntNormal, contact->depth);
                                                                       ^
    collision_libccd.cpp:909:41: error: invalid operands of types 'void' and 'int' to binary 'operator!='
         if (ccdVec3Normalize(&triNormal) != 0) {
                                             ^
    collision_libccd.cpp:919:44: error: invalid operands of types 'void' and 'int' to binary 'operator!='
             if (ccdVec3Normalize(&edgeAxis) != 0) {
                                                ^
    collision_libccd.cpp:939:59: error: 'ccdVec3Add2' was not declared in this scope
                 ccdVec3Add2(&v, &vertexToPos, &cntScaledNormal);
                                                               ^
    collision_libccd.cpp:946:79: error: 'CCD_ATAN2' was not declared in this scope
                     ccd_real_t contactNormalToTriangleNormalAngle = CCD_ATAN2(y, x);
                                                                                   ^
    collision_libccd.cpp:981:62: error: 'ccdQuatRotVec2' was not declared in this scope
                         ccdQuatRotVec2(&cntNormal, &cntNormal, &q);
                                                                  ^
    make[4]: *** [collision_libccd.lo] Error 1
    make[4]: Leaving directory `/home/js/Downloads/odedevs-ode-b9c7c5a35c54/ode/src'
    make[3]: *** [all-recursive] Error 1
    make[3]: Leaving directory `/home/js/Downloads/odedevs-ode-b9c7c5a35c54/ode/src'
    make[2]: *** [all] Error 2
    make[2]: Leaving directory `/home/js/Downloads/odedevs-ode-b9c7c5a35c54/ode/src'
    make[1]: *** [all-recursive] Error 1
    make[1]: Leaving directory `/home/js/Downloads/odedevs-ode-b9c7c5a35c54/ode'
    make: *** [all-recursive] Error 1
    
  3. Oleh Derevenko Account Deactivated

    Probably you are building with system installed version of libccd. Please try configuring with "--with-libccd=internal"

  4. Oleh Derevenko Account Deactivated

    So far, I have rebuilt and re-uploaded the 0.15.2 archive with the patch to add the missing define. As for building with system installed libccd, I'll try to resolve it in the next few days. If you use internal libccd, it should probably compile for you.

  5. Jeongseok Lee reporter

    It worked with "--with-libccd=internal", Thanks!

    So if ode (>= 0.15.1) doesn't work with system installed version of libccd, how about making it to always use the internal libccd? Will wait for your fix then.

    I will update the homebrew formula accordingly.

  6. Oleh Derevenko Account Deactivated

    Somebody wanted this option to be able to use system versions of libccd as nobody updates it in our repository and the system library could be newer. However, the original libccd lacks some convenience functions and and does not check for errors properly. So, while doing changes recently I've lost compatibility with the original libccd. I'll try to modify the ODE code to both have the new changes I have added and be able to compile with the original libccd if that is desired.

  7. Oleh Derevenko Account Deactivated

    Ah, that was the first time I was publishing the release. It used to be another person before. So I first made it 0.13.2. Then I realized that 0.14 would suit better. Then I had found that I had missed a version number in one place in configure.ac and left it as "0.13.2" instead of "0.14". So I had to re-tag.

  8. Oleh Derevenko Account Deactivated

    Please try the following patch. Alas, I do not currently have a system to test compiling with external libccd.

    diff -r 0dd5e962fd6f build/premake4.lua
    --- a/build/premake4.lua    Thu May 18 01:19:28 2017 +0300
    +++ b/build/premake4.lua    Fri May 19 01:15:33 2017 +0300
    @@ -298,6 +298,7 @@
           "../ode/src/joints",
           "../OPCODE",
           "../GIMPACT/include",
    +      "../libccd/src/custom",
           "../libccd/src"
         }
    
    @@ -384,7 +385,7 @@
           }
    
         configuration { "with-libccd" }
    -      files   { "../libccd/src/ccd/*.h", "../libccd/src/*.c" }
    +      files   { "../libccd/src/custom/ccdcustom/*.h", "../libccd/src/ccd/*.h", "../libccd/src/*.c" }
           defines { "dLIBCCD_ENABLED", "dLIBCCD_INTERNAL", 
             "dLIBCCD_BOX_CYL", "dLIBCCD_CYL_CYL", "dLIBCCD_CAP_CYL", "dLIBCCD_CONVEX_BOX",
             "dLIBCCD_CONVEX_CAP", "dLIBCCD_CONVEX_CYL", "dLIBCCD_CONVEX_SPHERE", "dLIBCCD_CONVEX_CONVEX" }
    diff -r 0dd5e962fd6f libccd/src/Makefile.am
    --- a/libccd/src/Makefile.am    Thu May 18 01:19:28 2017 +0300
    +++ b/libccd/src/Makefile.am    Fri May 19 01:15:33 2017 +0300
    @@ -1,5 +1,6 @@
     SUBDIRS = testsuites
    
    +AM_CPPFLAGS = -I./custom
     AM_CFLAGS = -std=c99
    
     noinst_LTLIBRARIES = libccd.la
    @@ -10,10 +11,10 @@
            ccd.c ccd/ccd.h \
            ccd/list.h \
            polytope.c ccd/polytope.h \
    -       ccd/quat.h \
    +       ccd/quat.h custom/ccdcustom/quat.h \
            ccd/simplex.h \
            support.c ccd/support.h \
    -       vec3.c ccd/vec3.h \
    +       vec3.c ccd/vec3.h custom/ccdcustom/vec3.h \
             mpr.c
    
     nodist_libccd_la_SOURCES = ccd/precision.h
    diff -r 0dd5e962fd6f libccd/src/ccd.c
    --- a/libccd/src/ccd.c  Thu May 18 01:19:28 2017 +0300
    +++ b/libccd/src/ccd.c  Fri May 19 01:15:33 2017 +0300
    @@ -18,7 +18,7 @@
     #include <stdio.h>
     #include <float.h>
     #include <ccd/ccd.h>
    -#include <ccd/vec3.h>
    +#include <ccdcustom/vec3.h>
     #include <ccd/simplex.h>
     #include <ccd/polytope.h>
     #include <ccd/alloc.h>
    @@ -185,7 +185,7 @@
         if (ret == 0 && nearest){
             // store normalized direction vector
             ccdVec3Copy(dir, &nearest->witness);
    -        ret = ccdVec3Normalize(dir);
    +        ret = ccdVec3SafeNormalize(dir);
    
             if (ret == 0) {
                 // compute depth of penetration
    diff -r 0dd5e962fd6f libccd/src/ccd/quat.h
    --- a/libccd/src/ccd/quat.h Thu May 18 01:19:28 2017 +0300
    +++ b/libccd/src/ccd/quat.h Fri May 19 01:15:33 2017 +0300
    @@ -66,14 +66,9 @@
    
    
     /**
    - * Rotate vector s by quaternion q and put result into d.
    - */
    -_ccd_inline void ccdQuatRotVec2(ccd_vec3_t *d, const ccd_vec3_t *s, const ccd_quat_t *q);
    -
    -/**
      * Rotate vector v by quaternion q.
      */
    -_ccd_inline void ccdQuatRotVec(ccd_vec3_t *v, const ccd_quat_t *q) { ccdQuatRotVec2(v, v, q); }
    +_ccd_inline void ccdQuatRotVec(ccd_vec3_t *v, const ccd_quat_t *q);
    
    
     /**** INLINES ****/
    @@ -202,32 +197,32 @@
         return ccdQuatInvert(dest);
     }
    
    -_ccd_inline void ccdQuatRotVec2(ccd_vec3_t *d, const ccd_vec3_t *s, const ccd_quat_t *q)
    -{
    -    // original version: 31 mul + 21 add
    -    // optimized version: 18 mul + 12 add
    -    // formula: d = s + 2 * cross(q.xyz, cross(q.xyz, v) + q.w * s)
    -    ccd_real_t cross1_x, cross1_y, cross1_z, cross2_x, cross2_y, cross2_z;
    -    ccd_real_t x, y, z, w;
    -    ccd_real_t vx, vy, vz;
    -
    -    vx = ccdVec3X(s);
    -    vy = ccdVec3Y(s);
    -    vz = ccdVec3Z(s);
    -
    -    w = q->q[3];
    -    x = q->q[0];
    -    y = q->q[1];
    -    z = q->q[2];
    -
    -    cross1_x = y * vz - z * vy + w * vx;
    -    cross1_y = z * vx - x * vz + w * vy;
    -    cross1_z = x * vy - y * vx + w * vz;
    -    cross2_x = y * cross1_z - z * cross1_y;
    -    cross2_y = z * cross1_x - x * cross1_z;
    -    cross2_z = x * cross1_y - y * cross1_x;
    -    ccdVec3Set(d, vx + 2 * cross2_x, vy + 2 * cross2_y, vz + 2 * cross2_z);
    -}
    +_ccd_inline void ccdQuatRotVec(ccd_vec3_t *v, const ccd_quat_t *q)
    +{
    +    // original version: 31 mul + 21 add
    +    // optimized version: 18 mul + 12 add
    +    // formula: v = v + 2 * cross(q.xyz, cross(q.xyz, v) + q.w * v)
    +    ccd_real_t cross1_x, cross1_y, cross1_z, cross2_x, cross2_y, cross2_z;
    +    ccd_real_t x, y, z, w;
    +    ccd_real_t vx, vy, vz;
    +
    +    vx = ccdVec3X(v);
    +    vy = ccdVec3Y(v);
    +    vz = ccdVec3Z(v);
    +
    +    w = q->q[3];
    +    x = q->q[0];
    +    y = q->q[1];
    +    z = q->q[2];
    +
    +    cross1_x = y * vz - z * vy + w * vx;
    +    cross1_y = z * vx - x * vz + w * vy;
    +    cross1_z = x * vy - y * vx + w * vz;
    +    cross2_x = y * cross1_z - z * cross1_y;
    +    cross2_y = z * cross1_x - x * cross1_z;
    +    cross2_z = x * cross1_y - y * cross1_x;
    +    ccdVec3Set(v, vx + 2 * cross2_x, vy + 2 * cross2_y, vz + 2 * cross2_z);
    +}
    
     #ifdef __cplusplus
     } /* extern "C" */
    diff -r 0dd5e962fd6f libccd/src/ccd/vec3.h
    --- a/libccd/src/ccd/vec3.h Thu May 18 01:19:28 2017 +0300
    +++ b/libccd/src/ccd/vec3.h Fri May 19 01:15:33 2017 +0300
    @@ -65,7 +65,6 @@
     # define CCD_FABS(x) (fabsf(x)) /*!< absolute value */
     # define CCD_FMAX(x, y) (fmaxf((x), (y))) /*!< maximum of two floats */
     # define CCD_FMIN(x, y) (fminf((x), (y))) /*!< minimum of two floats */
    -# define CCD_ATAN2(x, y) (atan2f((x), (y))) /*!< atan2 of two floats */
     #endif /* CCD_SINGLE */
    
     #ifdef CCD_DOUBLE
    @@ -81,7 +80,6 @@
     # define CCD_FABS(x) (fabs(x)) /*!< absolute value */
     # define CCD_FMAX(x, y) (fmax((x), (y))) /*!< maximum of two floats */
     # define CCD_FMIN(x, y) (fmin((x), (y))) /*!< minimum of two floats */
    -# define CCD_ATAN2(x, y) (atan2((x), (y))) /*!< atan2 of two floats */
     #endif /* CCD_DOUBLE */
    
     #define CCD_ONE CCD_REAL(1.)
    @@ -161,30 +159,15 @@
     _ccd_inline void ccdVec3Sub2(ccd_vec3_t *d, const ccd_vec3_t *v, const ccd_vec3_t *w);
    
     /**
    - * d = v + w
    - */
    -_ccd_inline void ccdVec3Add2(ccd_vec3_t *d, const ccd_vec3_t *v, const ccd_vec3_t *w);
    -
    -/**
      * d = d * k;
      */
     _ccd_inline void ccdVec3Scale(ccd_vec3_t *d, ccd_real_t k);
    
    -/**
    - * d = s * k;
    - */
    -_ccd_inline void ccdVec3CopyScaled(ccd_vec3_t *d, const ccd_vec3_t *s, ccd_real_t k);
    -
    -/**
    - * d = v + s * k;
    - */
    -_ccd_inline void ccdVec3AddScaled(ccd_vec3_t *d, const ccd_vec3_t *v, const ccd_vec3_t *s, ccd_real_t k);
    -
    
     /**
      * Normalizes given vector to unit length.
      */
    -_ccd_inline int ccdVec3Normalize(ccd_vec3_t *d);
    +_ccd_inline void ccdVec3Normalize(ccd_vec3_t *d);
    
    
     /**
    @@ -306,13 +289,6 @@
         v->v[2] -= w->v[2];
     }
    
    -_ccd_inline void ccdVec3Add(ccd_vec3_t *v, const ccd_vec3_t *w)
    -{
    -    v->v[0] += w->v[0];
    -    v->v[1] += w->v[1];
    -    v->v[2] += w->v[2];
    -}
    -
     _ccd_inline void ccdVec3Sub2(ccd_vec3_t *d, const ccd_vec3_t *v, const ccd_vec3_t *w)
     {
         d->v[0] = v->v[0] - w->v[0];
    @@ -320,11 +296,11 @@
         d->v[2] = v->v[2] - w->v[2];
     }
    
    -_ccd_inline void ccdVec3Add2(ccd_vec3_t *d, const ccd_vec3_t *v, const ccd_vec3_t *w)
    +_ccd_inline void ccdVec3Add(ccd_vec3_t *v, const ccd_vec3_t *w)
     {
    -    d->v[0] = v->v[0] + w->v[0];
    -    d->v[1] = v->v[1] + w->v[1];
    -    d->v[2] = v->v[2] + w->v[2];
    +    v->v[0] += w->v[0];
    +    v->v[1] += w->v[1];
    +    v->v[2] += w->v[2];
     }
    
     _ccd_inline void ccdVec3Scale(ccd_vec3_t *d, ccd_real_t k)
    @@ -334,31 +310,10 @@
         d->v[2] *= k;
     }
    
    -_ccd_inline void ccdVec3CopyScaled(ccd_vec3_t *d, const ccd_vec3_t *s, ccd_real_t k)
    -{
    -    d->v[0] = s->v[0] * k;
    -    d->v[1] = s->v[1] * k;
    -    d->v[2] = s->v[2] * k;
    -}
    -
    -_ccd_inline void ccdVec3AddScaled(ccd_vec3_t *d, const ccd_vec3_t *v, const ccd_vec3_t *s, ccd_real_t k)
    +_ccd_inline void ccdVec3Normalize(ccd_vec3_t *d)
     {
    -    d->v[0] = v->v[0] + s->v[0] * k;
    -    d->v[1] = v->v[1] + s->v[1] * k;
    -    d->v[2] = v->v[2] + s->v[2] * k;
    -}
    -
    -_ccd_inline int ccdVec3Normalize(ccd_vec3_t *d)
    -{
    -    int result = -1;
    -
    -    ccd_real_t len = CCD_SQRT(ccdVec3Len2(d));
    -    if (len >= CCD_EPS) {
    -        ccdVec3Scale(d, CCD_ONE / len);
    -        result = 0;
    -    }
    -
    -    return result;
    +    ccd_real_t k = CCD_ONE / CCD_SQRT(ccdVec3Len2(d));
    +    ccdVec3Scale(d, k);
     }
    
     _ccd_inline ccd_real_t ccdVec3Dot(const ccd_vec3_t *a, const ccd_vec3_t *b)
    diff -r 0dd5e962fd6f libccd/src/custom/ccdcustom/quat.h
    --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
    +++ b/libccd/src/custom/ccdcustom/quat.h    Fri May 19 01:15:33 2017 +0300
    @@ -0,0 +1,69 @@
    +/***
    + * libccd
    + * ---------------------------------
    + * Copyright (c)2010 Daniel Fiser <danfis@danfis.cz>
    + *
    + *
    + *  This file is part of libccd.
    + *
    + *  Distributed under the OSI-approved BSD License (the "License");
    + *  see accompanying file BDS-LICENSE for details or see
    + *  <http://www.opensource.org/licenses/bsd-license.php>.
    + *
    + *  This software is distributed WITHOUT ANY WARRANTY; without even the
    + *  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    + *  See the License for more information.
    + */
    +
    +#ifndef __CCD_CUSTOM_QUAT_H__
    +#define __CCD_CUSTOM_QUAT_H__
    +
    +#include <ccd/quat.h>
    +
    +#ifdef __cplusplus
    +extern "C" {
    +#endif /* __cplusplus */
    +
    +/**
    + * Rotate vector s by quaternion q and put result into d.
    + */
    +_ccd_inline void ccdQuatRotVec2(ccd_vec3_t *d, const ccd_vec3_t *s, const ccd_quat_t *q);
    +
    +
    +_ccd_inline void ccdQuatRotVec2(ccd_vec3_t *d, const ccd_vec3_t *s, const ccd_quat_t *q)
    +{
    +#ifndef dLIBCCD_USE_SYSTEM
    +    // original version: 31 mul + 21 add
    +    // optimized version: 18 mul + 12 add
    +    // formula: d = s + 2 * cross(q.xyz, cross(q.xyz, v) + q.w * s)
    +    ccd_real_t cross1_x, cross1_y, cross1_z, cross2_x, cross2_y, cross2_z;
    +    ccd_real_t x, y, z, w;
    +    ccd_real_t vx, vy, vz;
    +
    +    vx = ccdVec3X(s);
    +    vy = ccdVec3Y(s);
    +    vz = ccdVec3Z(s);
    +
    +    w = q->q[3];
    +    x = q->q[0];
    +    y = q->q[1];
    +    z = q->q[2];
    +
    +    cross1_x = y * vz - z * vy + w * vx;
    +    cross1_y = z * vx - x * vz + w * vy;
    +    cross1_z = x * vy - y * vx + w * vz;
    +    cross2_x = y * cross1_z - z * cross1_y;
    +    cross2_y = z * cross1_x - x * cross1_z;
    +    cross2_z = x * cross1_y - y * cross1_x;
    +    ccdVec3Set(d, vx + 2 * cross2_x, vy + 2 * cross2_y, vz + 2 * cross2_z);
    +#else
    +    ccdVec3Copy(d, s);
    +    ccdQuatRotVec(d, q);
    +#endif
    +}
    +
    +#ifdef __cplusplus
    +} /* extern "C" */
    +#endif /* __cplusplus */
    +
    +#endif /* __CCD_QUAT_H__ */
    diff -r 0dd5e962fd6f libccd/src/custom/ccdcustom/vec3.h
    --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
    +++ b/libccd/src/custom/ccdcustom/vec3.h    Fri May 19 01:15:33 2017 +0300
    @@ -0,0 +1,114 @@
    +/***
    + * libccd
    + * ---------------------------------
    + * Copyright (c)2010,2011 Daniel Fiser <danfis@danfis.cz>
    + *
    + *
    + *  This file is part of libccd.
    + *
    + *  Distributed under the OSI-approved BSD License (the "License");
    + *  see accompanying file BDS-LICENSE for details or see
    + *  <http://www.opensource.org/licenses/bsd-license.php>.
    + *
    + *  This software is distributed WITHOUT ANY WARRANTY; without even the
    + *  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    + *  See the License for more information.
    + */
    +
    +#ifndef __CCD_CUSTOM_VEC3_H__
    +#define __CCD_CUSTOM_VEC3_H__
    +
    +#include <ccd/vec3.h>
    +
    +
    +#ifdef __cplusplus
    +extern "C" {
    +#endif /* __cplusplus */
    +
    +
    +#ifdef CCD_SINGLE
    +# define CCD_ATAN2(x, y) (atan2f((x), (y))) /*!< atan2 of two floats */
    +#endif /* CCD_SINGLE */
    +
    +#ifdef CCD_DOUBLE
    +# define CCD_ATAN2(x, y) (atan2((x), (y))) /*!< atan2 of two floats */
    +#endif /* CCD_DOUBLE */
    +
    +/**
    + * d = v + w
    + */
    +_ccd_inline void ccdVec3Add2(ccd_vec3_t *d, const ccd_vec3_t *v, const ccd_vec3_t *w);
    +
    +/**
    + * d = s * k;
    + */
    +_ccd_inline void ccdVec3CopyScaled(ccd_vec3_t *d, const ccd_vec3_t *s, ccd_real_t k);
    +
    +/**
    + * d = v + s * k;
    + */
    +_ccd_inline void ccdVec3AddScaled(ccd_vec3_t *d, const ccd_vec3_t *v, const ccd_vec3_t *s, ccd_real_t k);
    +
    +
    +/**
    + * Normalizes given vector to unit length.
    + */
    +_ccd_inline int ccdVec3SafeNormalize(ccd_vec3_t *d);
    +
    +
    +_ccd_inline void ccdVec3Add2(ccd_vec3_t *d, const ccd_vec3_t *v, const ccd_vec3_t *w)
    +{
    +#ifndef dLIBCCD_USE_SYSTEM
    +    d->v[0] = v->v[0] + w->v[0];
    +    d->v[1] = v->v[1] + w->v[1];
    +    d->v[2] = v->v[2] + w->v[2];
    +#else
    +    ccdVec3Copy(d, v);
    +    ccdVec3Add(d, w);
    +#endif
    +}
    +
    +_ccd_inline void ccdVec3CopyScaled(ccd_vec3_t *d, const ccd_vec3_t *s, ccd_real_t k)
    +{
    +#ifndef dLIBCCD_USE_SYSTEM
    +    d->v[0] = s->v[0] * k;
    +    d->v[1] = s->v[1] * k;
    +    d->v[2] = s->v[2] * k;
    +#else
    +    ccdVec3Copy(d, s);
    +    ccdVec3Scale(d, k);
    +#endif
    +}
    +
    +_ccd_inline void ccdVec3AddScaled(ccd_vec3_t *d, const ccd_vec3_t *v, const ccd_vec3_t *s, ccd_real_t k)
    +{
    +#ifndef dLIBCCD_USE_SYSTEM
    +    d->v[0] = v->v[0] + s->v[0] * k;
    +    d->v[1] = v->v[1] + s->v[1] * k;
    +    d->v[2] = v->v[2] + s->v[2] * k;
    +#else
    +    ccdVec3Copy(d, s);
    +    ccdVec3Scale(d, k);
    +    ccdVec3Add(d, v);
    +#endif
    +}
    +
    +_ccd_inline int ccdVec3SafeNormalize(ccd_vec3_t *d)
    +{
    +    int result = -1;
    +
    +    ccd_real_t len = CCD_SQRT(ccdVec3Len2(d));
    +    if (len >= CCD_EPS) {
    +        ccdVec3Scale(d, CCD_ONE / len);
    +        result = 0;
    +    }
    +
    +    return result;
    +}
    +
    +
    +#ifdef __cplusplus
    +} /* extern "C" */
    +#endif /* __cplusplus */
    +
    +#endif /* __CCD_CUSTOM_VEC3_H__ */
    diff -r 0dd5e962fd6f libccd/src/mpr.c
    --- a/libccd/src/mpr.c  Thu May 18 01:19:28 2017 +0300
    +++ b/libccd/src/mpr.c  Fri May 19 01:15:33 2017 +0300
    @@ -17,6 +17,7 @@
    
     #include <stdlib.h>
     #include <ccd/ccd.h>
    +#include <ccdcustom/vec3.h>
     #include <ccd/simplex.h>
     #include <ccd/dbg.h>
    
    @@ -189,7 +190,7 @@
         // vertex 1 = support in direction of origin
         ccdVec3Copy(&dir, &ccdSimplexPoint(portal, 0)->v);
         ccdVec3Scale(&dir, CCD_REAL(-1.));
    -    if (ccdVec3Normalize(&dir) != 0) {
    +    if (ccdVec3SafeNormalize(&dir) != 0) {
             return -1;
         }
         __ccdSupport(obj1, obj2, &dir, ccd, ccdSimplexPointW(portal, 1));
    @@ -214,7 +215,7 @@
             }
         }
    
    -    if (ccdVec3Normalize(&dir) != 0) {
    +    if (ccdVec3SafeNormalize(&dir) != 0) {
             return -1;
         }
         __ccdSupport(obj1, obj2, &dir, ccd, ccdSimplexPointW(portal, 2));
    @@ -231,7 +232,7 @@
         ccdVec3Sub2(&vb, &ccdSimplexPoint(portal, 2)->v,
                          &ccdSimplexPoint(portal, 0)->v);
         ccdVec3Cross(&dir, &va, &vb);
    -    if (ccdVec3Normalize(&dir) != 0) {
    +    if (ccdVec3SafeNormalize(&dir) != 0) {
             return -1;
         }
    
    @@ -279,7 +280,7 @@
                 ccdVec3Sub2(&vb, &ccdSimplexPoint(portal, 2)->v,
                                  &ccdSimplexPoint(portal, 0)->v);
                 ccdVec3Cross(&dir, &va, &vb);
    -            if (ccdVec3Normalize(&dir) != 0) {
    +            if (ccdVec3SafeNormalize(&dir) != 0) {
                     return -1;
                 }
             }else{
    @@ -352,7 +353,7 @@
                                               &ccdSimplexPoint(portal, 3)->v,
                                               pdir);
                 *depth = CCD_SQRT(*depth);
    -            if (ccdVec3Normalize(pdir) != 0) {
    +            if (ccdVec3SafeNormalize(pdir) != 0) {
                     return -1;
                 }
    
    @@ -412,7 +413,7 @@
    
         ccdVec3Copy(dir, &ccdSimplexPoint(portal, 1)->v);
         *depth = CCD_SQRT(ccdVec3Len2(dir));
    -    if (ccdVec3Normalize(dir) != 0) {
    +    if (ccdVec3SafeNormalize(dir) != 0) {
             return -1;
         }
         return 0;
    @@ -522,7 +523,7 @@
         ccdVec3Sub2(&v3v1, &ccdSimplexPoint(portal, 3)->v,
                            &ccdSimplexPoint(portal, 1)->v);
         ccdVec3Cross(dir, &v2v1, &v3v1);
    -    if (ccdVec3Normalize(dir) != 0) {
    +    if (ccdVec3SafeNormalize(dir) != 0) {
             return -1;
         }
         return 0;
    diff -r 0dd5e962fd6f ode/src/Makefile.am
    --- a/ode/src/Makefile.am   Thu May 18 01:19:28 2017 +0300
    +++ b/ode/src/Makefile.am   Fri May 19 01:15:33 2017 +0300
    @@ -154,13 +154,16 @@
     if LIBCCD
    
     AM_CPPFLAGS += -DdLIBCCD_ENABLED
    +AM_CPPFLAGS += -I$(top_srcdir)/libccd/src/custom -I$(top_builddir)/libccd/src/custom
    
     if LIBCCD_INTERNAL
     AM_CPPFLAGS += -I$(top_srcdir)/libccd/src -I$(top_builddir)/libccd/src 
     libode_la_LIBADD += $(top_builddir)/libccd/src/libccd.la
    +AM_CPPFLAGS += -DdLIBCCD_INTERNAL
     else
     AM_CPPFLAGS += $(CCD_CFLAGS)
     libode_la_LIBADD += $(CCD_LIBS)
    +AM_CPPFLAGS += -DdLIBCCD_SYSTEM
     endif
    
    
    diff -r 0dd5e962fd6f ode/src/collision_libccd.cpp
    --- a/ode/src/collision_libccd.cpp  Thu May 18 01:19:28 2017 +0300
    +++ b/ode/src/collision_libccd.cpp  Fri May 19 01:15:33 2017 +0300
    @@ -22,7 +22,8 @@
    
     #include <ode/collision.h>
     #include <ccd/ccd.h>
    -#include <ccd/quat.h>
    +#include "ccdcustom/vec3.h"
    +#include "ccdcustom/quat.h"
     #include "config.h"
     #include "odemath.h"
     #include "collision_libccd.h"
    @@ -175,7 +176,7 @@
         ccdQuatRotVec(&cyl->axis, &cyl->o.rot);
         ccdVec3Copy(&cyl->p1, &cyl->axis);
         ccdVec3Copy(&cyl->p2, &cyl->axis);
    -    int cylAxisNormalizationResult = ccdVec3Normalize(&cyl->axis);
    +    int cylAxisNormalizationResult = ccdVec3SafeNormalize(&cyl->axis);
         dUVERIFY(cylAxisNormalizationResult == 0, "Invalid cylinder has been passed");
         ccdVec3Scale(&cyl->p2, -1.0);
         ccdVec3Add(&cyl->p1, &cyl->o.pos);
    @@ -906,7 +907,7 @@
         // Triangle face normal
         ccd_vec3_t triNormal;
         ccdVec3Cross(&triNormal, &edges[dMTV_FIRST], &edges[dMTV_SECOND]);
    -    if (ccdVec3Normalize(&triNormal) != 0) {
    +    if (ccdVec3SafeNormalize(&triNormal) != 0) {
             anyFault = true;
         }
    
    @@ -916,7 +917,7 @@
             ccd_vec3_t &edgeAxis = edges[testEdgeIndex]; 
    
             // Edge axis
    -        if (ccdVec3Normalize(&edgeAxis) != 0) {
    +        if (ccdVec3SafeNormalize(&edgeAxis) != 0) {
                 // This should not happen normally as in the case on of edges is degenerated
                 // the triangle normal calculation would have to fail above. If for some
                 // reason the above calculation succeeds and this one would not, it is
    
  9. Jeongseok Lee reporter

    It works on my system (trusty + gcc 4.8.5), thanks! It would be nice to release 0.15.3 with this patch.

  10. Oleh Derevenko Account Deactivated

    Technically, it does not change anything with regards to 0.15.2. The internal libccd mode remains exatly the same (just a few inline functons were relocated into new headers). And the system libccd mode did not compile anyway. Therefore I assume it it acceptable to just repack 0.15.2 with the corrections.

  11. Oleh Derevenko Account Deactivated

    Technically, it does not change anything with regards to 0.15.2. The internal libccd mode remains exatly the same (just a few inline functons were relocated into new headers). And the system libccd mode did not compile anyway. Therefore I assume it it acceptable to just repack 0.15.2 with the corrections.

  12. Log in to comment