Showing preview only (354K chars total). Download the full file or copy to clipboard to get everything.
Repository: danfis/libccd
Branch: master
Commit: 7931e764a19e
Files: 103
Total size: 329.3 KB
Directory structure:
gitextract_m4hhryw2/
├── .gitignore
├── .travis.yml
├── BSD-LICENSE
├── CMakeLists.txt
├── Makefile.am
├── README.md
├── bootstrap
├── ccd-config.cmake.in
├── ccd.pc.in
├── configure.ac
├── doc/
│ ├── CMakeLists.txt
│ ├── Makefile
│ ├── _build/
│ │ └── .dir
│ ├── _static/
│ │ └── .dir
│ ├── _templates/
│ │ └── .dir
│ ├── compile-and-install.rst
│ ├── conf.py
│ ├── examples.rst
│ ├── index.rst
│ └── reference.rst
├── make-release.sh
└── src/
├── .gitignore
├── CMakeLists.txt
├── Makefile
├── Makefile.am
├── Makefile.include
├── alloc.h
├── ccd/
│ ├── ccd.h
│ ├── ccd_export.h
│ ├── compiler.h
│ ├── config.h.cmake.in
│ ├── config.h.m4
│ ├── quat.h
│ └── vec3.h
├── ccd.c
├── dbg.h
├── list.h
├── mpr.c
├── polytope.c
├── polytope.h
├── simplex.h
├── support.c
├── support.h
├── testsuites/
│ ├── .gitignore
│ ├── CMakeLists.txt
│ ├── Makefile
│ ├── Makefile.am
│ ├── bench.c
│ ├── bench2.c
│ ├── boxbox.c
│ ├── boxbox.h
│ ├── boxcyl.c
│ ├── boxcyl.h
│ ├── common.c
│ ├── common.h
│ ├── cu/
│ │ ├── .dir
│ │ ├── .gitignore
│ │ ├── CMakeLists.txt
│ │ ├── COPYING
│ │ ├── COPYING.LESSER
│ │ ├── Makefile
│ │ ├── Makefile.am
│ │ ├── check-regressions
│ │ ├── cu.c
│ │ ├── cu.h
│ │ └── latest.sh
│ ├── cylcyl.c
│ ├── cylcyl.h
│ ├── main.c
│ ├── mpr_boxbox.c
│ ├── mpr_boxbox.h
│ ├── mpr_boxcyl.c
│ ├── mpr_boxcyl.h
│ ├── mpr_cylcyl.c
│ ├── mpr_cylcyl.h
│ ├── polytope.c
│ ├── polytope.h
│ ├── regressions/
│ │ ├── .dir
│ │ ├── TSBoxBox.err
│ │ ├── TSBoxBox.out
│ │ ├── TSBoxCyl.err
│ │ ├── TSBoxCyl.out
│ │ ├── TSCylCyl.err
│ │ ├── TSCylCyl.out
│ │ ├── TSMPRBoxBox.err
│ │ ├── TSMPRBoxBox.out
│ │ ├── TSMPRBoxCyl.err
│ │ ├── TSMPRBoxCyl.out
│ │ ├── TSMPRCylCyl.err
│ │ ├── TSMPRCylCyl.out
│ │ ├── TSPt.err
│ │ ├── TSPt.out
│ │ ├── TSSphereSphere.err
│ │ ├── TSSphereSphere.out
│ │ ├── TSVec3.err
│ │ └── TSVec3.out
│ ├── spheresphere.c
│ ├── spheresphere.h
│ ├── support.c
│ ├── support.h
│ ├── vec3.c
│ └── vec3.h
└── vec3.c
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
Makefile.in
autom4te.cache/*
aclocal.m4
config.guess
config.sub
configure
depcomp
install-sh
ltmain.sh
missing
*~
src/gjk/config.h.in
build/*
ccd.pc
================================================
FILE: .travis.yml
================================================
dist: trusty
sudo: required
language: c
compiler:
- gcc
- clang
env:
global:
- PREFIX="$TRAVIS_BUILD_DIR/build/install"
matrix:
- USE_AUTOTOOLS=yes
- USE_CMAKE=yes
- USE_MAKEFILE=yes USE_DOUBLE=yes
- USE_MAKEFILE=yes USE_SINGLE=yes
script:
- mkdir -p "$PREFIX"
- if [[ "$USE_AUTOTOOLS" == "yes" ]]; then ./bootstrap && cd build && ../configure --prefix "$PREFIX"; fi
- if [[ "$USE_CMAKE" == "yes" ]]; then cd build && cmake "-DCMAKE_INSTALL_PREFIX=$PREFIX" ..; fi
- if [[ "$USE_MAKEFILE" == "yes" ]]; then cd src; fi
- make && make install
================================================
FILE: BSD-LICENSE
================================================
libccd
-------
Copyright (c)2010-2012 Daniel Fiser <danfis@danfis.cz>,
Intelligent and Mobile Robotics Group, Department of Cybernetics,
Faculty of Electrical Engineering, Czech Technical University in Prague.
All rights reserved.
This work was supported by SYMBRION and REPLICATOR projects.
The SYMBRION project is funded by European Commission within the work
"Future and Emergent Technologies Proactive" under grant agreement no.
216342.
The REPLICATOR project is funded within the work programme "Cognitive
Systems, Interaction, Robotics" under grant agreement no. 216240.
http://www.symbrion.eu/
http://www.replicators.eu/
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of the University nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
================================================
FILE: CMakeLists.txt
================================================
cmake_minimum_required(VERSION 2.8.11)
if(POLICY CMP0042)
cmake_policy(SET CMP0042 NEW)
endif()
# Can not explicitly declared the software as C in project command due to bug:
# https://gitlab.kitware.com/cmake/cmake/issues/16967
project(libccd)
set(CCD_VERSION_MAJOR 2)
set(CCD_VERSION_MINOR 0)
set(CCD_VERSION ${CCD_VERSION_MAJOR}.${CCD_VERSION_MINOR})
set(CCD_SOVERSION 2)
# Include GNUInstallDirs to get canonical paths
include(GNUInstallDirs)
include(CTest)
option(BUILD_DOCUMENTATION "Build the documentation" OFF)
option(BUILD_SHARED_LIBS "Build libccd as a shared library" ON)
option(ENABLE_DOUBLE_PRECISION
"Enable double precision computations instead of single precision" OFF)
# Option for some bundle-like build system in order not to expose
# any FCL binary symbols in their public ABI
option(CCD_HIDE_ALL_SYMBOLS "Hide all binary symbols" OFF)
if (CCD_HIDE_ALL_SYMBOLS)
add_definitions("-DCCD_STATIC_DEFINE")
endif()
# set the default build type
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build; options are Debug Release RelWithDebInfo MinSizeRel"
FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY
STRINGS
Debug
Release
RelWithDebInfo
MinSizeRel)
endif()
add_subdirectory(src)
if(BUILD_DOCUMENTATION)
add_subdirectory(doc)
endif()
include(CMakePackageConfigHelpers)
configure_package_config_file(ccd-config.cmake.in ccd-config.cmake
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/ccd"
PATH_VARS CMAKE_INSTALL_INCLUDEDIR CMAKE_INSTALL_LIBDIR
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
write_basic_package_version_file(ccd-config-version.cmake
VERSION ${CCD_VERSION} COMPATIBILITY AnyNewerVersion)
install(FILES
"${CMAKE_BINARY_DIR}/ccd-config.cmake"
"${CMAKE_BINARY_DIR}/ccd-config-version.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/ccd")
set(CCD_PKGCONFIG_DESCRIPTION
"Library for collision detection between convex shapes")
configure_file(ccd.pc.in ccd.pc @ONLY)
install(FILES "${CMAKE_BINARY_DIR}/ccd.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
install(FILES BSD-LICENSE DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/doc/ccd")
================================================
FILE: Makefile.am
================================================
SUBDIRS = src
EXTRA_DIST = doc \
BSD-LICENSE \
README.md \
make-release.sh
================================================
FILE: README.md
================================================
# libccd [](https://travis-ci.org/danfis/libccd)
***libccd*** is library for a collision detection between two convex shapes.
libccd implements variation on Gilbert–Johnson–Keerthi algorithm plus Expand
Polytope Algorithm (EPA) and also implements algorithm Minkowski Portal
Refinement (MPR, a.k.a. XenoCollide) as described in Game Programming Gems 7.
libccd is the only available open source library of my knowledge that include
MPR algorithm working in 3-D space. However, there is a library called
[mpr2d](http://code.google.com/p/mpr2d/), implemented in D programming
language, that works in 2-D space.
libccd is currently part of:
1. [ODE](http://www.ode.org/) library (see ODE's *./configure --help* how to enable it),
2. [FCL](http://www.ros.org/wiki/fcl) library from [Willow Garage](http://www.willowgarage.com/),
3. [Bullet3](http://bulletphysics.org/) library (https://github.com/bulletphysics/bullet3).
For implementation details on GJK algorithm, see
http://www.win.tue.nl/~gino/solid/jgt98convex.pdf.
## Dependencies
This library is currently based only on standard libraries.
The only exception are testsuites that are built on top of CU
(https://github.com/danfis/cu) library licensed under LGPL, however only
testing depends on it and libccd library itself can be distributed without it.
## License
libccd is licensed under OSI-approved 3-clause BSD License, text of license
is distributed along with source code in BSD-LICENSE file.
Each file should include license notice, the rest should be considered as
licensed under 3-clause BSD License.
## Compile And Install
libccd contains several mechanisms for compiling and installing. Using a simple Makefile, using autotools, and using CMake.
### 1. Using Makefile
Directory src/ contains Makefile that should contain everything needed for compilation and installation:
```sh
$ cd src/
$ make
$ make install
```
Library libccd is by default compiled in double precision of floating point numbers - you can change this by options *USE_SINGLE/USE_DOUBLE*, i.e.:
```sh
$ make USE_SINGLE=yes
```
will compile library in single precision.
Installation directory can be changed by options PREFIX, INCLUDEDIR and LIBDIR.
For more info type 'make help'.
### 2. Using Autotools
libccd also contains support for autotools:
Generate configure script etc.:
```sh
$ ./bootstrap
```
Create new build/ directory:
```sh
$ mkdir build && cd build
```
Run configure script:
```sh
$ ../configure
```
Run make and make install:
```sh
$ make && make install
```
configure script can change the way libccd is compiled and installed, most significant option is *--enable-double-precision* which enables double precision (single is default in this case).
### 3. Using CMake
To build using `make`:
```sh
$ mkdir build && cd build
$ cmake -G "Unix Makefiles" ..
$ make && make install
```
To build using `ninja`:
```sh
$ mkdir build && cd build
$ cmake -G Ninja ..
$ ninja && ninja install
```
Other build tools may be using by specifying a different generator. For example:
```sh
$ cmake -G Xcode ..
```
```bat
> cmake -G "Visual Studio 14 2015" ..
```
To compile using double precision, set the `ENABLE_DOUBLE_PRECISION` option:
```sh
$ mkdir build && cd build
$ cmake -G "Unix Makefiles" -DENABLE_DOUBLE_PRECISION=ON ..
$ make && make install
```
To build libccd as a shared library, set the `BUILD_SHARED_LIBS` option:
```sh
$ mkdir build && cd build
$ cmake -G "Unix Makefiles" -DBUILD_SHARED_LIBS=ON ..
$ make && make install
```
To build the test suite, set the `BUILD_TESTING` option:
```sh
$ mkdir build && cd build
$ cmake -G "Unix Makefiles" -DBUILD_TESTING=ON ..
$ make && make test
```
The installation directory may be changed using the `CMAKE_INSTALL_PREFIX` variable:
```sh
$ mkdir build && cd build
$ cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/path/to/install ..
$ make && make install
```
## GJK - Intersection Test
This section describes how to use libccd for testing if two convex objects intersects (i.e., 'yes/no' test) using Gilbert-Johnson-Keerthi (GJK) algorithm.
Procedure is very simple (and is similar for usages of library):
1. Include *<ccd/ccd.h>* file.
2. Implement support function for specific shapes. Support function is function that returns furthest point from object (shape) in specified direction.
3. Set up *ccd_t* structure.
4. Run ccdGJKIntersect() function on desired objects.
Here is skeleton of simple program:
```cpp
#include <ccd/ccd.h>
#include <ccd/quat.h> // for work with quaternions
/** Support function for box */
void support(const void *obj, const ccd_vec3_t *dir, ccd_vec3_t *vec)
{
// assume that obj_t is user-defined structure that holds info about
// object (in this case box: x, y, z, pos, quat - dimensions of box,
// position and rotation)
obj_t *obj = (obj_t *)_obj;
ccd_vec3_t dir;
ccd_quat_t qinv;
// apply rotation on direction vector
ccdVec3Copy(&dir, _dir);
ccdQuatInvert2(&qinv, &obj->quat);
ccdQuatRotVec(&dir, &qinv);
// compute support point in specified direction
ccdVec3Set(v, ccdSign(ccdVec3X(&dir)) * box->x * CCD_REAL(0.5),
ccdSign(ccdVec3Y(&dir)) * box->y * CCD_REAL(0.5),
ccdSign(ccdVec3Z(&dir)) * box->z * CCD_REAL(0.5));
// transform support point according to position and rotation of object
ccdQuatRotVec(v, &obj->quat);
ccdVec3Add(v, &obj->pos);
}
int main(int argc, char *argv[])
{
...
ccd_t ccd;
CCD_INIT(&ccd); // initialize ccd_t struct
// set up ccd_t struct
ccd.support1 = support; // support function for first object
ccd.support2 = support; // support function for second object
ccd.max_iterations = 100; // maximal number of iterations
int intersect = ccdGJKIntersect(obj1, obj2, &ccd);
// now intersect holds true if obj1 and obj2 intersect, false otherwise
}
```
## GJK + EPA - Penetration Of Two Objects
If you want to obtain also penetration info about two intersection objects ccdGJKPenetration() function can be used.
Procedure is almost same as for previous case:
```cpp
#include <ccd/ccd.h>
#include <ccd/quat.h> // for work with quaternions
/** Support function is same as in previous case */
int main(int argc, char *argv[])
{
...
ccd_t ccd;
CCD_INIT(&ccd); // initialize ccd_t struct
// set up ccd_t struct
ccd.support1 = support; // support function for first object
ccd.support2 = support; // support function for second object
ccd.max_iterations = 100; // maximal number of iterations
ccd.epa_tolerance = 0.0001; // maximal tolerance fro EPA part
ccd_real_t depth;
ccd_vec3_t dir, pos;
int intersect = ccdGJKPenetration(obj1, obj2, &ccd, &depth, &dir, &pos);
// now intersect holds 0 if obj1 and obj2 intersect, -1 otherwise
// in depth, dir and pos is stored penetration depth, direction of
// separation vector and position in global coordinate system
}
```
## MPR - Intersection Test
libccd also provides MPR - Minkowski Portal Refinement algorithm that can be used for testing if two objects intersects.
Procedure is similar to the one used for GJK algorithm. Support function is same but also function that returns center (or any point near center) of given object must be implemented:
```cpp
#include <ccd/ccd.h>
#include <ccd/quat.h> // for work with quaternions
/** Support function is same as in previous case */
/** Center function - returns center of object */
void center(const void *_obj, ccd_vec3_t *center)
{
obj_t *obj = (obj_t *)_obj;
ccdVec3Copy(center, &obj->pos);
}
int main(int argc, char *argv[])
{
...
ccd_t ccd;
CCD_INIT(&ccd); // initialize ccd_t struct
// set up ccd_t struct
ccd.support1 = support; // support function for first object
ccd.support2 = support; // support function for second object
ccd.center1 = center; // center function for first object
ccd.center2 = center; // center function for second object
ccd.mpr_tolerance = 0.0001; // maximal tolerance
int intersect = ccdMPRIntersect(obj1, obj2, &ccd);
// now intersect holds true if obj1 and obj2 intersect, false otherwise
}
```
## MPR - Penetration Of Two Objects
Using MPR algorithm for obtaining penetration info about two intersection objects is equally easy as in previous case instead ccdMPRPenetration() function is used:
```cpp
#include <ccd/ccd.h>
#include <ccd/quat.h> // for work with quaternions
/** Support function is same as in previous case */
/** Center function is same as in prevous case */
int main(int argc, char *argv[])
{
...
ccd_t ccd;
CCD_INIT(&ccd); // initialize ccd_t struct
// set up ccd_t struct
ccd.support1 = support; // support function for first object
ccd.support2 = support; // support function for second object
ccd.center1 = center; // center function for first object
ccd.center2 = center; // center function for second object
ccd.mpr_tolerance = 0.0001; // maximal tolerance
ccd_real_t depth;
ccd_vec3_t dir, pos;
int intersect = ccdMPRPenetration(obj1, obj2, &ccd, &depth, &dir, &pos);
// now intersect holds 0 if obj1 and obj2 intersect, -1 otherwise
// in depth, dir and pos is stored penetration depth, direction of
// separation vector and position in global coordinate system
}
```
================================================
FILE: bootstrap
================================================
#!/bin/sh
libtoolize -f -c
aclocal
autoheader -f
autoconf
automake -a --foreign -f -c
================================================
FILE: ccd-config.cmake.in
================================================
@PACKAGE_INIT@
set(CCD_VERSION_MAJOR @CCD_VERSION_MAJOR@)
set(CCD_VERSION_MINOR @CCD_VERSION_MINOR@)
set(CCD_VERSION @CCD_VERSION@)
set(CCD_SOVERSION @CCD_SOVERSION@)
set(CCD_FOUND ON)
set_and_check(CCD_INCLUDE_DIRS "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@")
set_and_check(CCD_LIBRARY_DIRS "@PACKAGE_CMAKE_INSTALL_LIBDIR@")
set(CCD_LIBRARIES ccd)
include("${CMAKE_CURRENT_LIST_DIR}/ccd-targets.cmake")
================================================
FILE: ccd.pc.in
================================================
# Generated by CMake @CMAKE_VERSION@ for ccd
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
Name: @PROJECT_NAME@
Description: @CCD_PKGCONFIG_DESCRIPTION@
Version: @CCD_VERSION@
Requires: @CCD_PKGCONFIG_REQUIRES@
Libs: -L${libdir} -lccd @CCD_PKGCONFIG_EXTRA_LIBS@
Cflags: -I${includedir}
================================================
FILE: configure.ac
================================================
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
#AC_PREREQ([2.65])
AC_INIT([libccd], [2.0], [danfis@danfis.cz])
AC_CONFIG_SRCDIR([src/ccd.c])
AC_CONFIG_HEADERS([src/ccd/config.h])
AM_INIT_AUTOMAKE
# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
AC_PROG_INSTALL
AC_DISABLE_SHARED
LT_INIT
# Checks for libraries.
AC_CHECK_LIB([m], [main])
# FIXME: Replace `main' with a function in `-lrt':
AC_CHECK_LIB([rt], [main])
# Checks for header files.
AC_CHECK_HEADERS([float.h stdlib.h string.h unistd.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_SIZE_T
# Checks for library functions.
AC_FUNC_FORK
AC_FUNC_REALLOC
AC_CHECK_FUNCS([clock_gettime])
use_double=no
AC_ARG_ENABLE(double-precision,
AS_HELP_STRING([--enable-double-precision],
[enable double precision computations instead of single precision]),
[use_double=yes])
if test $use_double = no
then
AC_DEFINE([CCD_SINGLE], [], [use single precision])
else
AC_DEFINE([CCD_DOUBLE], [], [use double precision])
fi
AC_CONFIG_FILES([Makefile
src/Makefile
src/testsuites/Makefile
src/testsuites/cu/Makefile])
AC_OUTPUT
================================================
FILE: doc/CMakeLists.txt
================================================
find_program(SPHINX_EXECUTABLE NAMES sphinx-build sphinx-build2)
if(NOT SPHINX_EXECUTABLE)
message(FATAL_ERROR "Could NOT find required executable sphinx-build")
endif()
add_custom_target(doc ALL)
set(CCD_DOCTREE_DIR "${CMAKE_CURRENT_BINARY_DIR}/.doctrees")
set(CCD_HTML_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/html")
add_custom_target(html COMMAND
"${SPHINX_EXECUTABLE}" -b html -d "${CCD_DOCTREE_DIR}" -q
"${CMAKE_CURRENT_SOURCE_DIR}" "${CCD_HTML_OUTPUT_DIR}")
add_dependencies(doc html)
install(DIRECTORY "${CCD_HTML_OUTPUT_DIR}"
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/doc/ccd")
set(CCD_DOC_ADDITIONAL_MAKE_CLEAN_FILES
"${CCD_DOCTREE_DIR}"
"${CCD_HTML_OUTPUT_DIR}")
if(NOT WIN32)
set(CCD_MAN_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/man")
add_custom_target(man COMMAND
"${SPHINX_EXECUTABLE}" -b man -d "${CCD_DOCTREE_DIR}" -q
"${CMAKE_CURRENT_SOURCE_DIR}" "${CCD_MAN_OUTPUT_DIR}")
add_dependencies(doc man)
install(DIRECTORY "${CCD_MAN_OUTPUT_DIR}/"
DESTINATION "${CMAKE_INSTALL_MANDIR}/man1")
list(APPEND CCD_DOC_ADDITIONAL_MAKE_CLEAN_FILES "${CCD_MAN_OUTPUT_DIR}")
endif()
set_directory_properties(PROPERTIES
ADDITIONAL_MAKE_CLEAN_FILES ${CCD_DOC_ADDITIONAL_MAKE_CLEAN_FILES})
================================================
FILE: doc/Makefile
================================================
# Makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
PAPER =
BUILDDIR = _build
# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
PAPEROPT_letter = -D latex_paper_size=letter
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
# the i18n builder cannot share the environment and doctrees with the others
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
.PHONY: help
help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " html to make standalone HTML files"
@echo " dirhtml to make HTML files named index.html in directories"
@echo " singlehtml to make a single large HTML file"
@echo " pickle to make pickle files"
@echo " json to make JSON files"
@echo " htmlhelp to make HTML files and a HTML help project"
@echo " qthelp to make HTML files and a qthelp project"
@echo " applehelp to make an Apple Help Book"
@echo " devhelp to make HTML files and a Devhelp project"
@echo " epub to make an epub"
@echo " epub3 to make an epub3"
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
@echo " latexpdf to make LaTeX files and run them through pdflatex"
@echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx"
@echo " text to make text files"
@echo " man to make manual pages"
@echo " texinfo to make Texinfo files"
@echo " info to make Texinfo files and run them through makeinfo"
@echo " gettext to make PO message catalogs"
@echo " changes to make an overview of all changed/added/deprecated items"
@echo " xml to make Docutils-native XML files"
@echo " pseudoxml to make pseudoxml-XML files for display purposes"
@echo " linkcheck to check all external links for integrity"
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
@echo " coverage to run coverage check of the documentation (if enabled)"
@echo " dummy to check syntax errors of document sources"
.PHONY: clean
clean:
rm -rf $(BUILDDIR)/*
.PHONY: html
html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
.PHONY: dirhtml
dirhtml:
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
.PHONY: singlehtml
singlehtml:
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
@echo
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
.PHONY: pickle
pickle:
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
@echo
@echo "Build finished; now you can process the pickle files."
.PHONY: json
json:
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
@echo
@echo "Build finished; now you can process the JSON files."
.PHONY: htmlhelp
htmlhelp:
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
@echo
@echo "Build finished; now you can run HTML Help Workshop with the" \
".hhp project file in $(BUILDDIR)/htmlhelp."
.PHONY: qthelp
qthelp:
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
@echo
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/libccd.qhcp"
@echo "To view the help file:"
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/libccd.qhc"
.PHONY: applehelp
applehelp:
$(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp
@echo
@echo "Build finished. The help book is in $(BUILDDIR)/applehelp."
@echo "N.B. You won't be able to view it unless you put it in" \
"~/Library/Documentation/Help or install it in your application" \
"bundle."
.PHONY: devhelp
devhelp:
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
@echo
@echo "Build finished."
@echo "To view the help file:"
@echo "# mkdir -p $$HOME/.local/share/devhelp/libccd"
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/libccd"
@echo "# devhelp"
.PHONY: epub
epub:
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
@echo
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
.PHONY: epub3
epub3:
$(SPHINXBUILD) -b epub3 $(ALLSPHINXOPTS) $(BUILDDIR)/epub3
@echo
@echo "Build finished. The epub3 file is in $(BUILDDIR)/epub3."
.PHONY: latex
latex:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
@echo "Run \`make' in that directory to run these through (pdf)latex" \
"(use \`make latexpdf' here to do that automatically)."
.PHONY: latexpdf
latexpdf:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through pdflatex..."
$(MAKE) -C $(BUILDDIR)/latex all-pdf
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
.PHONY: latexpdfja
latexpdfja:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through platex and dvipdfmx..."
$(MAKE) -C $(BUILDDIR)/latex all-pdf-ja
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
.PHONY: text
text:
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
@echo
@echo "Build finished. The text files are in $(BUILDDIR)/text."
.PHONY: man
man:
$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
@echo
@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
.PHONY: texinfo
texinfo:
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo
@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
@echo "Run \`make' in that directory to run these through makeinfo" \
"(use \`make info' here to do that automatically)."
.PHONY: info
info:
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo "Running Texinfo files through makeinfo..."
make -C $(BUILDDIR)/texinfo info
@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
.PHONY: gettext
gettext:
$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
@echo
@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
.PHONY: changes
changes:
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
@echo
@echo "The overview file is in $(BUILDDIR)/changes."
.PHONY: linkcheck
linkcheck:
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
@echo
@echo "Link check complete; look for any errors in the above output " \
"or in $(BUILDDIR)/linkcheck/output.txt."
.PHONY: doctest
doctest:
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
@echo "Testing of doctests in the sources finished, look at the " \
"results in $(BUILDDIR)/doctest/output.txt."
.PHONY: coverage
coverage:
$(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage
@echo "Testing of coverage in the sources finished, look at the " \
"results in $(BUILDDIR)/coverage/python.txt."
.PHONY: xml
xml:
$(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml
@echo
@echo "Build finished. The XML files are in $(BUILDDIR)/xml."
.PHONY: pseudoxml
pseudoxml:
$(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml
@echo
@echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml."
.PHONY: dummy
dummy:
$(SPHINXBUILD) -b dummy $(ALLSPHINXOPTS) $(BUILDDIR)/dummy
@echo
@echo "Build finished. Dummy builder generates no files."
================================================
FILE: doc/_build/.dir
================================================
================================================
FILE: doc/_static/.dir
================================================
================================================
FILE: doc/_templates/.dir
================================================
================================================
FILE: doc/compile-and-install.rst
================================================
Compile And Install
====================
libccd contains several mechanisms for compiling and installing.
Using a simple Makefile, using autotools, and using CMake.
1. Using Makefile
------------------
Directory ``src/`` contains Makefile that should contain everything needed for compilation and installation:
.. code-block:: bash
$ cd src/
$ make
$ make install
Library libccd is by default compiled in double precision of floating point
numbers - you can change this by options ``USE_SINGLE``/``USE_DOUBLE``, i.e.:
.. code-block:: bash
$ make USE_SINGLE=yes
will compile library in single precision.
Installation directory can be changed by options ``PREFIX``, ``INCLUDEDIR``
and ``LIBDIR``.
For more info type '``make help``'.
2. Using Autotools
-------------------
libccd also contains support for autotools:
Generate configure script etc.:
.. code-block:: bash
$ ./bootstrap
Create new ``build/`` directory:
.. code-block:: bash
$ mkdir build && cd build
Run configure script:
.. code-block:: bash
$ ../configure
Run make and make install:
.. code-block:: bash
$ make && make install
configure script can change the way libccd is compiled and installed, most
significant option is ``--enable-double-precision`` which enables double
precision (single is default in this case).
3. Using CMake
---------------
To build using ``make``:
.. code-block:: bash
$ mkdir build && cd build
$ cmake -G "Unix Makefiles" ..
$ make && make install
To build using ``ninja``:
.. code-block:: bash
$ mkdir build && cd build
$ cmake -G Ninja ..
$ ninja && ninja install
Other build tools may be using by specifying a different generator. For example:
.. code-block:: bash
$ cmake -G Xcode ..
.. code-block:: batch
> cmake -G "Visual Studio 14 2015" ..
To compile using double precision, set the ``ENABLE_DOUBLE_PRECISION`` option:
.. code-block:: bash
$ mkdir build && cd build
$ cmake -G "Unix Makefiles" -DENABLE_DOUBLE_PRECISION=ON ..
$ make && make install
To build libccd as a shared library, set the ``BUILD_SHARED_LIBS`` option:
.. code-block:: bash
$ mkdir build && cd build
$ cmake -G "Unix Makefiles" -DBUILD_SHARED_LIBS=ON ..
$ make && make install
To build the test suite, set the ``BUILD_TESTING`` option:
.. code-block:: bash
$ mkdir build && cd build
$ cmake -G "Unix Makefiles" -DBUILD_TESTING=ON ..
$ make && make test
The installation directory may be changed by specifying the ``CMAKE_INSTALL_PREFIX`` variable:
.. code-block:: bash
$ mkdir build && cd build
$ cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/path/to/install ..
$ make && make install
================================================
FILE: doc/conf.py
================================================
# -*- coding: utf-8 -*-
#
# libccd documentation build configuration file, created by
# sphinx-quickstart on Fri Sep 9 14:53:37 2016.
#
# This file is execfile()d with the current directory set to its
# containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
# -- General configuration ------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.mathjax']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
# The encoding of source files.
#
# source_encoding = 'utf-8-sig'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = u'libccd'
copyright = u'2013, Daniel Fiser <danfis@danfis.cz>'
author = u'Daniel Fiser'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = u'2.0'
# The full version, including alpha/beta/rc tags.
release = u'2.0'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#
# today = ''
#
# Else, today_fmt is used as the format for a strftime call.
#
# today_fmt = '%B %d, %Y'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
# The reST default role (used for this markup: `text`) to use for all
# documents.
#
# default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
#
# add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#
# add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#
# show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
# modindex_common_prefix = []
# If true, keep warnings as "system message" paragraphs in the built documents.
# keep_warnings = False
# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False
# -- Options for HTML output ----------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'default'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
# html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
# html_theme_path = []
# The name for this set of Sphinx documents.
# "<project> v<release> documentation" by default.
#
# html_title = u'libccd Documentation'
# A shorter title for the navigation bar. Default is the same as html_title.
#
# html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#
# html_logo = None
# The name of an image file (relative to this directory) to use as a favicon of
# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#
# html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied
# directly to the root of the documentation.
#
# html_extra_path = []
# If not None, a 'Last updated on:' timestamp is inserted at every page
# bottom, using the given strftime format.
# The empty string is equivalent to '%b %d, %Y'.
#
# html_last_updated_fmt = None
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#
# html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
#
# html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#
# html_additional_pages = {}
# If false, no module index is generated.
#
# html_domain_indices = True
# If false, no index is generated.
#
# html_use_index = True
# If true, the index is split into individual pages for each letter.
#
# html_split_index = False
# If true, links to the reST sources are added to the pages.
#
# html_show_sourcelink = True
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
#
# html_show_sphinx = True
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
#
# html_show_copyright = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#
# html_use_opensearch = ''
# This is the file name suffix for HTML files (e.g. ".xhtml").
# html_file_suffix = None
# Language to be used for generating the HTML full-text search index.
# Sphinx supports the following languages:
# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja'
# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr', 'zh'
#
# html_search_language = 'en'
# A dictionary with options for the search language support, empty by default.
# 'ja' uses this config value.
# 'zh' user can custom change `jieba` dictionary path.
#
# html_search_options = {'type': 'default'}
# The name of a javascript file (relative to the configuration directory) that
# implements a search results scorer. If empty, the default will be used.
#
# html_search_scorer = 'scorer.js'
# Output file base name for HTML help builder.
htmlhelp_basename = 'libccddoc'
# -- Options for LaTeX output ---------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',
# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'libccd.tex', u'libccd Documentation',
author, 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
#
# latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#
# latex_use_parts = False
# If true, show page references after internal links.
#
# latex_show_pagerefs = False
# If true, show URL addresses after external links.
#
# latex_show_urls = False
# Documents to append as an appendix to all manuals.
#
# latex_appendices = []
# It false, will not define \strong, \code, itleref, \crossref ... but only
# \sphinxstrong, ..., \sphinxtitleref, ... To help avoid clash with user added
# packages.
#
# latex_keep_old_macro_names = True
# If false, no module index is generated.
#
# latex_domain_indices = True
# -- Options for manual page output ---------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'libccd', u'libccd Documentation',
[author], 1)
]
# If true, show URL addresses after external links.
#
# man_show_urls = False
# -- Options for Texinfo output -------------------------------------------
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'libccd', u'libccd Documentation',
author, 'libccd', 'One line description of project.',
'Miscellaneous'),
]
# Documents to append as an appendix to all manuals.
#
# texinfo_appendices = []
# If false, no module index is generated.
#
# texinfo_domain_indices = True
# How to display URL addresses: 'footnote', 'no', or 'inline'.
#
# texinfo_show_urls = 'footnote'
# If true, do not generate a @detailmenu in the "Top" node's menu.
#
# texinfo_no_detailmenu = False
================================================
FILE: doc/examples.rst
================================================
Example of Usage
=================
1. GJK - Intersection Test
---------------------------
This section describes how to use **libccd** for testing if two convex objects intersects (i.e., 'yes/no' test) using Gilbert-Johnson-Keerthi (GJK) algorithm.
Procedure is very simple (and similar to the usage of the rest of the
library):
#. Include ``<ccd/ccd.h>`` file.
#. Implement support function for specific shapes. Support function is
function that returns furthest point from object (shape) in specified
direction.
#. Set up ``ccd_t`` structure.
#. Run ``ccdGJKIntersect()`` function on desired objects.
Here is a skeleton of simple program:
.. code-block:: c
#include <ccd/ccd.h>
#include <ccd/quat.h> // for work with quaternions
/** Support function for box */
void support(const void *obj, const ccd_vec3_t *dir,
ccd_vec3_t *vec)
{
// assume that obj_t is user-defined structure that holds info about
// object (in this case box: x, y, z, pos, quat - dimensions of box,
// position and rotation)
obj_t *obj = (obj_t *)_obj;
ccd_vec3_t dir;
ccd_quat_t qinv;
// apply rotation on direction vector
ccdVec3Copy(&dir, _dir);
ccdQuatInvert2(&qinv, &obj->quat);
ccdQuatRotVec(&dir, &qinv);
// compute support point in specified direction
ccdVec3Set(v, ccdSign(ccdVec3X(&dir)) * box->x * CCD_REAL(0.5),
ccdSign(ccdVec3Y(&dir)) * box->y * CCD_REAL(0.5),
ccdSign(ccdVec3Z(&dir)) * box->z * CCD_REAL(0.5));
// transform support point according to position and rotation of object
ccdQuatRotVec(v, &obj->quat);
ccdVec3Add(v, &obj->pos);
}
int main(int argc, char *argv[])
{
...
ccd_t ccd;
CCD_INIT(&ccd); // initialize ccd_t struct
// set up ccd_t struct
ccd.support1 = support; // support function for first object
ccd.support2 = support; // support function for second object
ccd.max_iterations = 100; // maximal number of iterations
int intersect = ccdGJKIntersect(obj1, obj2, &ccd);
// now intersect holds true if obj1 and obj2 intersect, false otherwise
}
2. GJK + EPA - Penetration Of Two Objects
------------------------------------------
If you want to obtain also penetration info about two intersection objects
``ccdGJKPenetration()`` function can be used.
Procedure is almost the same as for the previous case:
.. code-block:: c
#include <ccd/ccd.h>
#include <ccd/quat.h> // for work with quaternions
/** Support function is same as in previous case */
int main(int argc, char *argv[])
{
...
ccd_t ccd;
CCD_INIT(&ccd); // initialize ccd_t struct
// set up ccd_t struct
ccd.support1 = support; // support function for first object
ccd.support2 = support; // support function for second object
ccd.max_iterations = 100; // maximal number of iterations
ccd.epa_tolerance = 0.0001; // maximal tolerance fro EPA part
ccd_real_t depth;
ccd_vec3_t dir, pos;
int intersect = ccdGJKPenetration(obj1, obj2, &ccd, &depth, &dir, &pos);
// now intersect holds true if obj1 and obj2 intersect, false otherwise
// in depth, dir and pos is stored penetration depth, direction of
// separation vector and position in global coordinate system
}
3. MPR - Intersection Test
---------------------------
**libccd** also provides *MPR* - Minkowski Portal Refinement algorithm that
can be used for testing if two objects intersects.
Procedure is similar to the one used for GJK algorithm. Support function is
the same but also function that returns a center (or any point near center)
of a given object must be implemented:
.. code-block:: c
#include <ccd/ccd.h>
#include <ccd/quat.h> // for work with quaternions
/** Support function is same as in previous case */
/** Center function - returns center of object */
void center(const void *_obj, ccd_vec3_t *center)
{
obj_t *obj = (obj_t *)_obj;
ccdVec3Copy(center, &obj->pos);
}
int main(int argc, char *argv[])
{
...
ccd_t ccd;
CCD_INIT(&ccd); // initialize ccd_t struct
// set up ccd_t struct
ccd.support1 = support; // support function for first object
ccd.support2 = support; // support function for second object
ccd.center1 = center; // center function for first object
ccd.center2 = center; // center function for second object
ccd.mpr_tolerance = 0.0001; // maximal tolerance
int intersect = ccdMPRIntersect(obj1, obj2, &ccd);
// now intersect holds true if obj1 and obj2 intersect, false otherwise
}
4. MPR - Penetration Of Two Objects
------------------------------------
Using MPR algorithm for obtaining penetration info about two intersection
objects is equally easy as in the previous case instead but
``ccdMPRPenetration()`` function is used:
.. code-block:: c
#include <ccd/ccd.h>
#include <ccd/quat.h> // for work with quaternions
/** Support function is same as in previous case */
/** Center function is same as in prevous case */
int main(int argc, char *argv[])
{
...
ccd_t ccd;
CCD_INIT(&ccd); // initialize ccd_t struct
// set up ccd_t struct
ccd.support1 = support; // support function for first object
ccd.support2 = support; // support function for second object
ccd.center1 = center; // center function for first object
ccd.center2 = center; // center function for second object
ccd.mpr_tolerance = 0.0001; // maximal tolerance
ccd_real_t depth;
ccd_vec3_t dir, pos;
int intersect = ccdMPRPenetration(obj1, obj2, &ccd, &depth, &dir, &pos);
// now intersect holds true if obj1 and obj2 intersect, false otherwise
// in depth, dir and pos is stored penetration depth, direction of
// separation vector and position in global coordinate system
}
================================================
FILE: doc/index.rst
================================================
.. libccd documentation master file, created by
sphinx-quickstart2 on Thu May 23 13:49:12 2013.
libccd's documentation
=======================
See homepage: http://libccd.danfis.cz
Contents:
.. toctree::
:maxdepth: 2
compile-and-install.rst
examples.rst
reference.rst
.. Indices and tables
.. ==================
.. * :ref:`genindex`
.. * :ref:`modindex`
.. * :ref:`search`
================================================
FILE: doc/reference.rst
================================================
Reference
==========
.. literalinclude:: ../src/ccd/ccd.h
:language: c
:linenos:
================================================
FILE: make-release.sh
================================================
#!/bin/bash
# Creates .tar.gz package of specified version.
# Takes one argument - identification of commit
NAME=libccd
COMMIT=""
CMD="git archive"
# read arguments
COMMIT="$1"
if [ "$COMMIT" = "" ]; then
echo "Usage: $0 commit [--notest] [--nodoc]"
echo "Error: you must specify commit which should be packed"
exit -1;
fi;
PREFIX=${NAME}-$COMMIT/
FN=${NAME}-$COMMIT.tar.gz
if echo "$COMMIT" | grep '^v[0-9]\.[0-9]\+' >/dev/null 2>&1; then
tmp=$(echo "$COMMIT" | sed 's/^v//')
PREFIX=${NAME}-$tmp/
FN=${NAME}-$tmp.tar.gz
fi
$CMD --prefix="$PREFIX" --format=tar $COMMIT | gzip >"$FN"
echo "Package: $FN"
================================================
FILE: src/.gitignore
================================================
*.o
*.a
ccd/config.h
ccd/config.h.in
================================================
FILE: src/CMakeLists.txt
================================================
if(DEFINED CCD_SINGLE OR DEFINED CCD_DOUBLE)
# make sure only DOUBLE or SINGLE is set; default to SINGLE
if(CCD_SINGLE)
set(CCD_DOUBLE OFF)
else()
set(CCD_SINGLE ON)
endif()
if(CCD_DOUBLE)
set(CCD_SINGLE OFF)
endif()
elseif(ENABLE_DOUBLE_PRECISION)
set(CCD_DOUBLE ON)
set(CCD_SINGLE OFF)
else()
set(CCD_DOUBLE OFF)
set(CCD_SINGLE ON)
endif()
configure_file(ccd/config.h.cmake.in ccd/config.h)
set(CCD_INCLUDES
ccd/ccd.h
ccd/compiler.h
ccd/ccd_export.h
ccd/quat.h
ccd/vec3.h
"${CMAKE_CURRENT_BINARY_DIR}/ccd/config.h")
set(CCD_SOURCES
alloc.h
ccd.c
dbg.h
list.h
mpr.c
polytope.c
polytope.h
simplex.h
support.c
support.h
vec3.c)
add_library(ccd ${CCD_INCLUDES} ${CCD_SOURCES})
set_target_properties(ccd PROPERTIES
PUBLIC_HEADER "${CCD_INCLUDES}"
SOVERSION ${CCD_SOVERSION}
VERSION ${CCD_VERSION})
target_include_directories(ccd PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)
if(NOT WIN32)
find_library(LIBM_LIBRARY NAMES m)
if(NOT LIBM_LIBRARY)
message(FATAL_ERROR "Could NOT find required library LibM")
endif()
target_link_libraries(ccd "${LIBM_LIBRARY}")
if(BUILD_SHARED_LIBS)
set(CCD_PKGCONFIG_EXTRA_LIBS -lm PARENT_SCOPE)
endif()
endif()
export(TARGETS ccd FILE "${CMAKE_BINARY_DIR}/ccd-targets.cmake")
install(TARGETS ccd
EXPORT ccd-targets
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/ccd"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
install(EXPORT ccd-targets DESTINATION "${CMAKE_INSTALL_LIBDIR}/ccd")
macro (check_compiler_visibility)
include (CheckCXXCompilerFlag)
check_cxx_compiler_flag(-fvisibility=hidden COMPILER_SUPPORTS_VISIBILITY)
endmacro()
if(UNIX)
check_compiler_visibility()
if (COMPILER_SUPPORTS_VISIBILITY)
set_target_properties(ccd
PROPERTIES COMPILE_FLAGS "-fvisibility=hidden")
endif()
endif()
if(NOT WIN32 AND BUILD_TESTING AND NOT CCD_HIDE_ALL_SYMBOLS)
add_subdirectory(testsuites)
endif()
================================================
FILE: src/Makefile
================================================
###
# 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.
##
-include Makefile.include
CFLAGS += -I. -fvisibility=hidden
TARGETS = libccd.a
OBJS = ccd.o mpr.o support.o vec3.o polytope.o
all: $(TARGETS)
libccd.a: $(OBJS)
ar cr $@ $(OBJS)
ranlib $@
ccd/config.h: ccd/config.h.m4
$(M4) $(CONFIG_FLAGS) $< >$@
%.o: %.c %.h ccd/config.h
$(CC) $(CFLAGS) $(DEFS) -c -o $@ $<
%.o: %.c ccd/config.h
$(CC) $(CFLAGS) $(DEFS) -c -o $@ $<
%.h: ccd/config.h
%.c: ccd/config.h
install:
mkdir -p $(PREFIX)/$(INCLUDEDIR)/ccd
mkdir -p $(PREFIX)/$(LIBDIR)
cp ccd/*.h $(PREFIX)/$(INCLUDEDIR)/ccd/
cp libccd.a $(PREFIX)/$(LIBDIR)
clean:
rm -f $(OBJS)
rm -f $(TARGETS)
rm -f ccd/config.h
if [ -d testsuites ]; then $(MAKE) -C testsuites clean; fi;
check:
$(MAKE) -C testsuites check
check-valgrind:
$(MAKE) -C testsuites check-valgrind
help:
@echo "Targets:"
@echo " all - Build library"
@echo " install - Install library into system"
@echo ""
@echo "Options:"
@echo " CC - Path to C compiler"
@echo " M4 - Path to m4 macro processor"
@echo ""
@echo " DEBUG 'yes'/'no' - Turn on/off debugging (default: 'no')"
@echo " PROFIL 'yes'/'no' - Compiles profiling info (default: 'no')"
@echo " NOWALL 'yes'/'no' - Turns off -Wall gcc option (default: 'no')"
@echo " NOPEDANTIC 'yes'/'no' - Turns off -pedantic gcc option (default: 'no')"
@echo ""
@echo " USE_SINGLE 'yes' - Use single precision (default: 'no')"
@echo " USE_DOUBLE 'yes' - Use double precision (default: 'yes')"
@echo ""
@echo " PREFIX - Prefix where library will be installed (default: /usr/local)"
@echo " INCLUDEDIR - Directory where header files will be installed (PREFIX/INCLUDEDIR) (default: include)"
@echo " LIBDIR - Directory where library will be installed (PREFIX/LIBDIR) (default: lib)"
@echo ""
.PHONY: all clean check check-valgrind help
================================================
FILE: src/Makefile.am
================================================
SUBDIRS = . testsuites
lib_LTLIBRARIES = libccd.la
libccd_la_SOURCES = alloc.h \
ccd/compiler.h \
dbg.h \
ccd.c ccd/ccd.h \
ccd/ccd_export.h \
list.h \
polytope.c polytope.h \
ccd/quat.h \
simplex.h \
support.c support.h \
vec3.c ccd/vec3.h \
mpr.c
libccd_la_CFLAGS = -fvisibility=hidden
================================================
FILE: src/Makefile.include
================================================
###
# 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.
##
CC ?= gcc
M4 ?= m4
PYTHON ?= python
SYSTEM = $(shell uname)
SYSTEM_CXXFLAGS =
SYSTEM_LDFLAGS =
ifeq '$(SYSTEM)' 'FreeBSD'
SYSTEM_CXXFLAGS = -Wno-long-long
else
endif
NOWALL ?= no
NOPEDANTIC ?= no
DEBUG ?= no
PROFIL ?= no
ifeq '$(PROFIL)' 'yes'
DEBUG = yes
endif
ifeq '$(DEBUG)' 'yes'
CFLAGS = -g
endif
ifeq '$(PROFIL)' 'yes'
CFLAGS += -pg
endif
ifneq '$(NOWALL)' 'yes'
CFLAGS += -Wall
endif
ifneq '$(NOPEDANTIC)' 'yes'
CFLAGS += -pedantic
endif
CONFIG_FLAGS =
USE_DOUBLE ?= yes
USE_SINGLE ?= no
ifeq '$(USE_SINGLE)' 'yes'
CONFIG_FLAGS += -DUSE_SINGLE
USE_DOUBLE = no
endif
ifeq '$(USE_DOUBLE)' 'yes'
CONFIG_FLAGS += -DUSE_DOUBLE
endif
CFLAGS += --std=gnu99
LDFLAGS += $(SYSTEM_LDFLAGS)
CHECKTARGETS =
check-dep: $(CHECKTARGETS)
PREFIX ?= /usr/local
INCLUDEDIR ?= include
LIBDIR ?= lib
showvars:
@echo "SYSTEM = "$(SYSTEM)
@echo ""
@echo "CC = $(CC)"
@echo "M4 = $(M4)"
@echo ""
@echo "DEBUG = $(DEBUG)"
@echo "PROFIL = $(PROFIL)"
@echo "NOWALL = $(NOWALL)"
@echo "NOPEDANTIC = $(NOPEDANTIC)"
@echo "USE_SINGLE = $(USE_SINGLE)"
@echo "USE_DOUBLE = $(USE_DOUBLE)"
@echo ""
@echo "CFLAGS = $(CFLAGS)"
@echo "LDFLAGS = $(LDFLAGS)"
@echo "CONFIG_FLAGS = $(CONFIG_FLAGS)"
@echo ""
@echo "PREFIX = $(PREFIX)"
@echo "INCLUDEDIR = $(INCLUDEDIR)"
@echo "LIBDIR = $(LIBDIR)"
@echo ""
.DEFAULT_GOAL := all
.PHONY: showvars
================================================
FILE: src/alloc.h
================================================
/***
* 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_ALLOC_H__
#define __CCD_ALLOC_H__
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/**
* Functions and macros required for memory allocation.
*/
/* Memory allocation: */
#define __CCD_ALLOC_MEMORY(type, ptr_old, size) \
(type *)realloc((void *)ptr_old, (size))
/** Allocate memory for one element of type. */
#define CCD_ALLOC(type) \
__CCD_ALLOC_MEMORY(type, NULL, sizeof(type))
/** Allocate memory for array of elements of type type. */
#define CCD_ALLOC_ARR(type, num_elements) \
__CCD_ALLOC_MEMORY(type, NULL, sizeof(type) * (num_elements))
#define CCD_REALLOC_ARR(ptr, type, num_elements) \
__CCD_ALLOC_MEMORY(type, ptr, sizeof(type) * (num_elements))
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
#endif /* __CCD_ALLOC_H__ */
================================================
FILE: src/ccd/ccd.h
================================================
/***
* 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_H__
#define __CCD_H__
#include <ccd/vec3.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/**
* Type of *support* function that takes pointer to 3D object and direction
* and returns (via vec argument) furthest point from object in specified
* direction.
*/
typedef void (*ccd_support_fn)(const void *obj, const ccd_vec3_t *dir,
ccd_vec3_t *vec);
/**
* Returns (via dir argument) first direction vector that will be used in
* initialization of algorithm.
*/
typedef void (*ccd_first_dir_fn)(const void *obj1, const void *obj2,
ccd_vec3_t *dir);
/**
* Returns (via center argument) geometric center (some point near center)
* of given object.
*/
typedef void (*ccd_center_fn)(const void *obj1, ccd_vec3_t *center);
/**
* Main structure of CCD algorithm.
*/
struct _ccd_t {
ccd_first_dir_fn first_dir; //!< Returns initial direction where first
//!< support point will be searched
ccd_support_fn support1; //!< Function that returns support point of
//!< first object
ccd_support_fn support2; //!< Function that returns support point of
//!< second object
ccd_center_fn center1; //!< Function that returns geometric center of
//!< first object
ccd_center_fn center2; //!< Function that returns geometric center of
//!< second object
unsigned long max_iterations; //!< Maximal number of iterations
ccd_real_t epa_tolerance;
ccd_real_t mpr_tolerance; //!< Boundary tolerance for MPR algorithm
ccd_real_t dist_tolerance;
};
typedef struct _ccd_t ccd_t;
/**
* Default first direction.
*/
CCD_EXPORT void ccdFirstDirDefault(const void *o1, const void *o2,
ccd_vec3_t *dir);
#define CCD_INIT(ccd) \
do { \
(ccd)->first_dir = ccdFirstDirDefault; \
(ccd)->support1 = NULL; \
(ccd)->support2 = NULL; \
(ccd)->center1 = NULL; \
(ccd)->center2 = NULL; \
\
(ccd)->max_iterations = (unsigned long)-1; \
(ccd)->epa_tolerance = CCD_REAL(0.0001); \
(ccd)->mpr_tolerance = CCD_REAL(0.0001); \
(ccd)->dist_tolerance = CCD_REAL(1E-6); \
} while(0)
/**
* Returns true if two given objects interest.
*/
CCD_EXPORT int ccdGJKIntersect(const void *obj1, const void *obj2,
const ccd_t *ccd);
/**
* This function computes separation vector of two objects. Separation
* vector is minimal translation of obj2 to get obj1 and obj2 speparated
* (without intersection).
* Returns 0 if obj1 and obj2 intersect and sep is filled with translation
* vector. If obj1 and obj2 don't intersect -1 is returned.
* If memory allocation fails -2 is returned.
*/
CCD_EXPORT int ccdGJKSeparate(const void *obj1, const void *obj2,
const ccd_t *ccd, ccd_vec3_t *sep);
/**
* Computes penetration of obj2 into obj1.
* Depth of penetration, direction and position is returned. It means that
* if obj2 is translated by distance depth in direction dir objects will
* have touching contact, pos should be position in global coordinates
* where force should take a place.
*
* CCD+EPA algorithm is used.
*
* Returns 0 if obj1 and obj2 intersect and depth, dir and pos are filled
* if given non-NULL pointers.
* If obj1 and obj2 don't intersect -1 is returned.
* If memory allocation fails -2 is returned.
*/
CCD_EXPORT int ccdGJKPenetration(const void *obj1, const void *obj2,
const ccd_t *ccd, ccd_real_t *depth,
ccd_vec3_t *dir, ccd_vec3_t *pos);
/**
* Returns true if two given objects intersect - MPR algorithm is used.
*/
CCD_EXPORT int ccdMPRIntersect(const void *obj1, const void *obj2,
const ccd_t *ccd);
/**
* Computes penetration of obj2 into obj1.
* Depth of penetration, direction and position is returned, i.e. if obj2
* is translated by computed depth in resulting direction obj1 and obj2
* would have touching contact. Position is point in global coordinates
* where force should take a place.
*
* Minkowski Portal Refinement algorithm is used (MPR, a.k.a. XenoCollide,
* see Game Programming Gem 7).
*
* Returns 0 if obj1 and obj2 intersect, otherwise -1 is returned.
*/
CCD_EXPORT int ccdMPRPenetration(const void *obj1, const void *obj2,
const ccd_t *ccd, ccd_real_t *depth,
ccd_vec3_t *dir, ccd_vec3_t *pos);
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
#endif /* __CCD_H__ */
================================================
FILE: src/ccd/ccd_export.h
================================================
#ifndef CCD_EXPORT_H
#define CCD_EXPORT_H
#ifdef CCD_STATIC_DEFINE
# define CCD_EXPORT
#else
# ifdef _MSC_VER
# ifdef ccd_EXPORTS
# define CCD_EXPORT __declspec(dllexport)
# else /* ccd_EXPORTS */
# define CCD_EXPORT __declspec(dllimport)
# endif /* ccd_EXPORTS */
# else
# ifndef CCD_EXPORT
# ifdef ccd_EXPORTS
/* We are building this library */
# define CCD_EXPORT __attribute__((visibility("default")))
# else
/* We are using this library */
# define CCD_EXPORT __attribute__((visibility("default")))
# endif
# endif
# endif
#endif
#endif
================================================
FILE: src/ccd/compiler.h
================================================
/***
* 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_COMPILER_H__
#define __CCD_COMPILER_H__
#include <stddef.h>
#define ccd_offsetof(TYPE, MEMBER) offsetof(TYPE, MEMBER)
#define ccd_container_of(ptr, type, member) \
(type *)( (char *)ptr - ccd_offsetof(type, member))
/**
* Marks inline function.
*/
#ifdef __GNUC__
# define _ccd_inline static inline __attribute__((always_inline))
#else /* __GNUC__ */
# define _ccd_inline static __inline
#endif /* __GNUC__ */
/**
* __prefetch(x) - prefetches the cacheline at "x" for read
* __prefetchw(x) - prefetches the cacheline at "x" for write
*/
#ifdef __GNUC__
# define _ccd_prefetch(x) __builtin_prefetch(x)
# define _ccd_prefetchw(x) __builtin_prefetch(x,1)
#else /* __GNUC__ */
# define _ccd_prefetch(x) ((void)0)
# define _ccd_prefetchw(x) ((void)0)
#endif /* __GNUC__ */
#ifdef __ICC
// disable unused parameter warning
# pragma warning(disable:869)
// disable annoying "operands are evaluated in unspecified order" warning
# pragma warning(disable:981)
#endif /* __ICC */
#ifdef _MSC_VER
// disable unsafe function warning
# define _CRT_SECURE_NO_WARNINGS
#endif /* _MSC_VER */
#endif /* __CCD_COMPILER_H__ */
================================================
FILE: src/ccd/config.h.cmake.in
================================================
#ifndef __CCD_CONFIG_H__
#define __CCD_CONFIG_H__
#cmakedefine CCD_SINGLE
#cmakedefine CCD_DOUBLE
#endif /* __CCD_CONFIG_H__ */
================================================
FILE: src/ccd/config.h.m4
================================================
#ifndef __CCD_CONFIG_H__
#define __CCD_CONFIG_H__
ifdef(`USE_SINGLE', `#define CCD_SINGLE')
ifdef(`USE_DOUBLE', `#define CCD_DOUBLE')
#endif /* __CCD_CONFIG_H__ */
================================================
FILE: src/ccd/quat.h
================================================
/***
* 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_QUAT_H__
#define __CCD_QUAT_H__
#include <ccd/compiler.h>
#include <ccd/vec3.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
struct _ccd_quat_t {
ccd_real_t q[4]; //!< x, y, z, w
};
typedef struct _ccd_quat_t ccd_quat_t;
#define CCD_QUAT(name, x, y, z, w) \
ccd_quat_t name = { {x, y, z, w} }
_ccd_inline ccd_real_t ccdQuatLen2(const ccd_quat_t *q);
_ccd_inline ccd_real_t ccdQuatLen(const ccd_quat_t *q);
_ccd_inline void ccdQuatSet(ccd_quat_t *q, ccd_real_t x, ccd_real_t y, ccd_real_t z, ccd_real_t w);
_ccd_inline void ccdQuatCopy(ccd_quat_t *dest, const ccd_quat_t *src);
_ccd_inline int ccdQuatNormalize(ccd_quat_t *q);
_ccd_inline void ccdQuatSetAngleAxis(ccd_quat_t *q,
ccd_real_t angle, const ccd_vec3_t *axis);
_ccd_inline void ccdQuatScale(ccd_quat_t *q, ccd_real_t k);
/**
* q = q * q2
*/
_ccd_inline void ccdQuatMul(ccd_quat_t *q, const ccd_quat_t *q2);
/**
* q = a * b
*/
_ccd_inline void ccdQuatMul2(ccd_quat_t *q,
const ccd_quat_t *a, const ccd_quat_t *b);
/**
* Inverts quaternion.
* Returns 0 on success.
*/
_ccd_inline int ccdQuatInvert(ccd_quat_t *q);
_ccd_inline int ccdQuatInvert2(ccd_quat_t *dest, const ccd_quat_t *src);
/**
* Rotate vector v by quaternion q.
*/
_ccd_inline void ccdQuatRotVec(ccd_vec3_t *v, const ccd_quat_t *q);
/**** INLINES ****/
_ccd_inline ccd_real_t ccdQuatLen2(const ccd_quat_t *q)
{
ccd_real_t len;
len = q->q[0] * q->q[0];
len += q->q[1] * q->q[1];
len += q->q[2] * q->q[2];
len += q->q[3] * q->q[3];
return len;
}
_ccd_inline ccd_real_t ccdQuatLen(const ccd_quat_t *q)
{
return CCD_SQRT(ccdQuatLen2(q));
}
_ccd_inline void ccdQuatSet(ccd_quat_t *q, ccd_real_t x, ccd_real_t y, ccd_real_t z, ccd_real_t w)
{
q->q[0] = x;
q->q[1] = y;
q->q[2] = z;
q->q[3] = w;
}
_ccd_inline void ccdQuatCopy(ccd_quat_t *dest, const ccd_quat_t *src)
{
*dest = *src;
}
_ccd_inline int ccdQuatNormalize(ccd_quat_t *q)
{
ccd_real_t len = ccdQuatLen(q);
if (len < CCD_EPS)
return 0;
ccdQuatScale(q, CCD_ONE / len);
return 1;
}
_ccd_inline void ccdQuatSetAngleAxis(ccd_quat_t *q,
ccd_real_t angle, const ccd_vec3_t *axis)
{
ccd_real_t a, x, y, z, n, s;
a = angle/2;
x = ccdVec3X(axis);
y = ccdVec3Y(axis);
z = ccdVec3Z(axis);
n = CCD_SQRT(x*x + y*y + z*z);
// axis==0? (treat this the same as angle==0 with an arbitrary axis)
if (n < CCD_EPS){
q->q[0] = q->q[1] = q->q[2] = CCD_ZERO;
q->q[3] = CCD_ONE;
}else{
s = sin(a)/n;
q->q[3] = cos(a);
q->q[0] = x*s;
q->q[1] = y*s;
q->q[2] = z*s;
ccdQuatNormalize(q);
}
}
_ccd_inline void ccdQuatScale(ccd_quat_t *q, ccd_real_t k)
{
size_t i;
for (i = 0; i < 4; i++)
q->q[i] *= k;
}
_ccd_inline void ccdQuatMul(ccd_quat_t *q, const ccd_quat_t *q2)
{
ccd_quat_t a;
ccdQuatCopy(&a, q);
ccdQuatMul2(q, &a, q2);
}
_ccd_inline void ccdQuatMul2(ccd_quat_t *q,
const ccd_quat_t *a, const ccd_quat_t *b)
{
q->q[0] = a->q[3] * b->q[0]
+ a->q[0] * b->q[3]
+ a->q[1] * b->q[2]
- a->q[2] * b->q[1];
q->q[1] = a->q[3] * b->q[1]
+ a->q[1] * b->q[3]
- a->q[0] * b->q[2]
+ a->q[2] * b->q[0];
q->q[2] = a->q[3] * b->q[2]
+ a->q[2] * b->q[3]
+ a->q[0] * b->q[1]
- a->q[1] * b->q[0];
q->q[3] = a->q[3] * b->q[3]
- a->q[0] * b->q[0]
- a->q[1] * b->q[1]
- a->q[2] * b->q[2];
}
_ccd_inline int ccdQuatInvert(ccd_quat_t *q)
{
ccd_real_t len2 = ccdQuatLen2(q);
if (len2 < CCD_EPS)
return -1;
len2 = CCD_ONE / len2;
q->q[0] = -q->q[0] * len2;
q->q[1] = -q->q[1] * len2;
q->q[2] = -q->q[2] * len2;
q->q[3] = q->q[3] * len2;
return 0;
}
_ccd_inline int ccdQuatInvert2(ccd_quat_t *dest, const ccd_quat_t *src)
{
ccdQuatCopy(dest, src);
return ccdQuatInvert(dest);
}
_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" */
#endif /* __cplusplus */
#endif /* __CCD_QUAT_H__ */
================================================
FILE: src/ccd/vec3.h
================================================
/***
* libccd
* ---------------------------------
* Copyright (c)2010-2013 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_VEC3_H__
#define __CCD_VEC3_H__
#include <math.h>
#include <float.h>
#include <stdlib.h>
#include <ccd/compiler.h>
#include <ccd/config.h>
#include <ccd/ccd_export.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#ifndef CCD_SINGLE
# ifndef CCD_DOUBLE
# error You must define CCD_SINGLE or CCD_DOUBLE
# endif /* CCD_DOUBLE */
#endif /* CCD_SINGLE */
#ifdef WIN32
# define CCD_FMIN(x, y) ((x) < (y) ? (x) : (y))
#endif /* WIN32 */
#ifdef CCD_SINGLE
# ifdef CCD_DOUBLE
# error You can define either CCD_SINGLE or CCD_DOUBLE, not both!
# endif /* CCD_DOUBLE */
typedef float ccd_real_t;
//# define CCD_EPS 1E-6
# define CCD_EPS FLT_EPSILON
# define CCD_REAL_MAX FLT_MAX
# define CCD_REAL(x) (x ## f) /*!< form a constant */
# define CCD_SQRT(x) (sqrtf(x)) /*!< square root */
# define CCD_FABS(x) (fabsf(x)) /*!< absolute value */
# define CCD_FMAX(x, y) (fmaxf((x), (y))) /*!< maximum of two floats */
# ifndef CCD_FMIN
# define CCD_FMIN(x, y) (fminf((x), (y))) /*!< minimum of two floats */
# endif /* CCD_FMIN */
#endif /* CCD_SINGLE */
#ifdef CCD_DOUBLE
typedef double ccd_real_t;
//# define CCD_EPS 1E-10
# define CCD_EPS DBL_EPSILON
# define CCD_REAL_MAX DBL_MAX
# define CCD_REAL(x) (x) /*!< form a constant */
# define CCD_SQRT(x) (sqrt(x)) /*!< square root */
# define CCD_FABS(x) (fabs(x)) /*!< absolute value */
# define CCD_FMAX(x, y) (fmax((x), (y))) /*!< maximum of two floats */
# ifndef CCD_FMIN
# define CCD_FMIN(x, y) (fmin((x), (y))) /*!< minimum of two floats */
# endif /* CCD_FMIN */
#endif /* CCD_DOUBLE */
#define CCD_ONE CCD_REAL(1.)
#define CCD_ZERO CCD_REAL(0.)
struct _ccd_vec3_t {
ccd_real_t v[3];
};
typedef struct _ccd_vec3_t ccd_vec3_t;
/**
* Holds origin (0,0,0) - this variable is meant to be read-only!
*/
CCD_EXPORT extern ccd_vec3_t *ccd_vec3_origin;
/**
* Array of points uniformly distributed on unit sphere.
*/
CCD_EXPORT extern ccd_vec3_t *ccd_points_on_sphere;
CCD_EXPORT extern size_t ccd_points_on_sphere_len;
/** Returns sign of value. */
_ccd_inline int ccdSign(ccd_real_t val);
/** Returns true if val is zero. **/
_ccd_inline int ccdIsZero(ccd_real_t val);
/** Returns true if a and b equal. **/
_ccd_inline int ccdEq(ccd_real_t a, ccd_real_t b);
#define CCD_VEC3_STATIC(x, y, z) \
{ { (x), (y), (z) } }
#define CCD_VEC3(name, x, y, z) \
ccd_vec3_t name = CCD_VEC3_STATIC((x), (y), (z))
_ccd_inline ccd_real_t ccdVec3X(const ccd_vec3_t *v);
_ccd_inline ccd_real_t ccdVec3Y(const ccd_vec3_t *v);
_ccd_inline ccd_real_t ccdVec3Z(const ccd_vec3_t *v);
/**
* Returns true if a and b equal.
*/
_ccd_inline int ccdVec3Eq(const ccd_vec3_t *a, const ccd_vec3_t *b);
/**
* Returns squared length of vector.
*/
_ccd_inline ccd_real_t ccdVec3Len2(const ccd_vec3_t *v);
/**
* Returns distance between a and b.
*/
_ccd_inline ccd_real_t ccdVec3Dist2(const ccd_vec3_t *a, const ccd_vec3_t *b);
_ccd_inline void ccdVec3Set(ccd_vec3_t *v, ccd_real_t x, ccd_real_t y, ccd_real_t z);
/**
* v = w
*/
_ccd_inline void ccdVec3Copy(ccd_vec3_t *v, const ccd_vec3_t *w);
/**
* Substracts coordinates of vector w from vector v. v = v - w
*/
_ccd_inline void ccdVec3Sub(ccd_vec3_t *v, const ccd_vec3_t *w);
/**
* Adds coordinates of vector w to vector v. v = v + w
*/
_ccd_inline void ccdVec3Add(ccd_vec3_t *v, const ccd_vec3_t *w);
/**
* d = v - w
*/
_ccd_inline void ccdVec3Sub2(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);
/**
* Normalizes given vector to unit length.
*/
_ccd_inline void ccdVec3Normalize(ccd_vec3_t *d);
/**
* Dot product of two vectors.
*/
_ccd_inline ccd_real_t ccdVec3Dot(const ccd_vec3_t *a, const ccd_vec3_t *b);
/**
* Cross product: d = a x b.
*/
_ccd_inline void ccdVec3Cross(ccd_vec3_t *d, const ccd_vec3_t *a, const ccd_vec3_t *b);
/**
* Returns distance^2 of point P to segment ab.
* If witness is non-NULL it is filled with coordinates of point from which
* was computed distance to point P.
*/
CCD_EXPORT ccd_real_t ccdVec3PointSegmentDist2(const ccd_vec3_t *P,
const ccd_vec3_t *a,
const ccd_vec3_t *b,
ccd_vec3_t *witness);
/**
* Returns distance^2 of point P from triangle formed by triplet a, b, c.
* If witness vector is provided it is filled with coordinates of point
* from which was computed distance to point P.
*/
CCD_EXPORT ccd_real_t ccdVec3PointTriDist2(const ccd_vec3_t *P,
const ccd_vec3_t *a,
const ccd_vec3_t *b,
const ccd_vec3_t *c,
ccd_vec3_t *witness);
/**** INLINES ****/
_ccd_inline int ccdSign(ccd_real_t val)
{
if (ccdIsZero(val)){
return 0;
}else if (val < CCD_ZERO){
return -1;
}
return 1;
}
_ccd_inline int ccdIsZero(ccd_real_t val)
{
return CCD_FABS(val) < CCD_EPS;
}
_ccd_inline int ccdEq(ccd_real_t _a, ccd_real_t _b)
{
ccd_real_t ab;
ccd_real_t a, b;
ab = CCD_FABS(_a - _b);
if (CCD_FABS(ab) < CCD_EPS)
return 1;
a = CCD_FABS(_a);
b = CCD_FABS(_b);
if (b > a){
return ab < CCD_EPS * b;
}else{
return ab < CCD_EPS * a;
}
}
_ccd_inline ccd_real_t ccdVec3X(const ccd_vec3_t *v)
{
return v->v[0];
}
_ccd_inline ccd_real_t ccdVec3Y(const ccd_vec3_t *v)
{
return v->v[1];
}
_ccd_inline ccd_real_t ccdVec3Z(const ccd_vec3_t *v)
{
return v->v[2];
}
_ccd_inline int ccdVec3Eq(const ccd_vec3_t *a, const ccd_vec3_t *b)
{
return ccdEq(ccdVec3X(a), ccdVec3X(b))
&& ccdEq(ccdVec3Y(a), ccdVec3Y(b))
&& ccdEq(ccdVec3Z(a), ccdVec3Z(b));
}
_ccd_inline ccd_real_t ccdVec3Len2(const ccd_vec3_t *v)
{
return ccdVec3Dot(v, v);
}
_ccd_inline ccd_real_t ccdVec3Dist2(const ccd_vec3_t *a, const ccd_vec3_t *b)
{
ccd_vec3_t ab;
ccdVec3Sub2(&ab, a, b);
return ccdVec3Len2(&ab);
}
_ccd_inline void ccdVec3Set(ccd_vec3_t *v, ccd_real_t x, ccd_real_t y, ccd_real_t z)
{
v->v[0] = x;
v->v[1] = y;
v->v[2] = z;
}
_ccd_inline void ccdVec3Copy(ccd_vec3_t *v, const ccd_vec3_t *w)
{
*v = *w;
}
_ccd_inline void ccdVec3Sub(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];
d->v[1] = v->v[1] - w->v[1];
d->v[2] = 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 ccdVec3Scale(ccd_vec3_t *d, ccd_real_t k)
{
d->v[0] *= k;
d->v[1] *= k;
d->v[2] *= k;
}
_ccd_inline void ccdVec3Normalize(ccd_vec3_t *d)
{
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)
{
ccd_real_t dot;
dot = a->v[0] * b->v[0];
dot += a->v[1] * b->v[1];
dot += a->v[2] * b->v[2];
return dot;
}
_ccd_inline void ccdVec3Cross(ccd_vec3_t *d, const ccd_vec3_t *a, const ccd_vec3_t *b)
{
d->v[0] = (a->v[1] * b->v[2]) - (a->v[2] * b->v[1]);
d->v[1] = (a->v[2] * b->v[0]) - (a->v[0] * b->v[2]);
d->v[2] = (a->v[0] * b->v[1]) - (a->v[1] * b->v[0]);
}
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
#endif /* __CCD_VEC3_H__ */
================================================
FILE: src/ccd.c
================================================
/***
* libccd
* ---------------------------------
* Copyright (c)2012 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.
*/
#include <stdio.h>
#include <float.h>
#include <ccd/ccd.h>
#include <ccd/vec3.h>
#include "simplex.h"
#include "polytope.h"
#include "alloc.h"
#include "dbg.h"
/** Performs GJK algorithm. Returns 0 if intersection was found and simplex
* is filled with resulting polytope. */
static int __ccdGJK(const void *obj1, const void *obj2,
const ccd_t *ccd, ccd_simplex_t *simplex);
/** Performs GJK+EPA algorithm. Returns 0 if intersection was found and
* pt is filled with resulting polytope and nearest with pointer to
* nearest element (vertex, edge, face) of polytope to origin. */
static int __ccdGJKEPA(const void *obj1, const void *obj2,
const ccd_t *ccd,
ccd_pt_t *pt, ccd_pt_el_t **nearest);
/** Returns true if simplex contains origin.
* This function also alteres simplex and dir according to further
* processing of GJK algorithm. */
static int doSimplex(ccd_simplex_t *simplex, ccd_vec3_t *dir);
static int doSimplex2(ccd_simplex_t *simplex, ccd_vec3_t *dir);
static int doSimplex3(ccd_simplex_t *simplex, ccd_vec3_t *dir);
static int doSimplex4(ccd_simplex_t *simplex, ccd_vec3_t *dir);
/** d = a x b x c */
_ccd_inline void tripleCross(const ccd_vec3_t *a, const ccd_vec3_t *b,
const ccd_vec3_t *c, ccd_vec3_t *d);
/** Transforms simplex to polytope. It is assumed that simplex has 4
* vertices. */
static int simplexToPolytope4(const void *obj1, const void *obj2,
const ccd_t *ccd,
ccd_simplex_t *simplex,
ccd_pt_t *pt, ccd_pt_el_t **nearest);
/** Transforms simplex to polytope, three vertices required */
static int simplexToPolytope3(const void *obj1, const void *obj2,
const ccd_t *ccd,
const ccd_simplex_t *simplex,
ccd_pt_t *pt, ccd_pt_el_t **nearest);
/** Transforms simplex to polytope, two vertices required */
static int simplexToPolytope2(const void *obj1, const void *obj2,
const ccd_t *ccd,
const ccd_simplex_t *simplex,
ccd_pt_t *pt, ccd_pt_el_t **nearest);
/** Expands polytope using new vertex v.
* Return 0 on success, -2 on memory allocation failure.*/
static int expandPolytope(ccd_pt_t *pt, ccd_pt_el_t *el,
const ccd_support_t *newv);
/** Finds next support point (at stores it in out argument).
* Returns 0 on success, -1 otherwise */
static int nextSupport(const void *obj1, const void *obj2, const ccd_t *ccd,
const ccd_pt_el_t *el,
ccd_support_t *out);
void ccdFirstDirDefault(const void *o1, const void *o2, ccd_vec3_t *dir)
{
ccdVec3Set(dir, CCD_ONE, CCD_ZERO, CCD_ZERO);
}
int ccdGJKIntersect(const void *obj1, const void *obj2, const ccd_t *ccd)
{
ccd_simplex_t simplex;
return __ccdGJK(obj1, obj2, ccd, &simplex) == 0;
}
int ccdGJKSeparate(const void *obj1, const void *obj2, const ccd_t *ccd,
ccd_vec3_t *sep)
{
ccd_pt_t polytope;
ccd_pt_el_t *nearest;
int ret;
ccdPtInit(&polytope);
ret = __ccdGJKEPA(obj1, obj2, ccd, &polytope, &nearest);
// set separation vector
if (nearest)
ccdVec3Copy(sep, &nearest->witness);
ccdPtDestroy(&polytope);
return ret;
}
static int penEPAPosCmp(const void *a, const void *b)
{
ccd_pt_vertex_t *v1, *v2;
v1 = *(ccd_pt_vertex_t **)a;
v2 = *(ccd_pt_vertex_t **)b;
if (ccdEq(v1->dist, v2->dist)){
return 0;
}else if (v1->dist < v2->dist){
return -1;
}else{
return 1;
}
}
static int penEPAPos(const ccd_pt_t *pt, const ccd_pt_el_t *nearest,
ccd_vec3_t *pos)
{
ccd_pt_vertex_t *v;
ccd_pt_vertex_t **vs;
size_t i, len;
ccd_real_t scale;
// compute median
len = 0;
ccdListForEachEntry(&pt->vertices, v, ccd_pt_vertex_t, list){
len++;
}
vs = CCD_ALLOC_ARR(ccd_pt_vertex_t *, len);
if (vs == NULL)
return -1;
i = 0;
ccdListForEachEntry(&pt->vertices, v, ccd_pt_vertex_t, list){
vs[i++] = v;
}
qsort(vs, len, sizeof(ccd_pt_vertex_t *), penEPAPosCmp);
ccdVec3Set(pos, CCD_ZERO, CCD_ZERO, CCD_ZERO);
scale = CCD_ZERO;
if (len % 2 == 1)
len++;
for (i = 0; i < len / 2; i++){
ccdVec3Add(pos, &vs[i]->v.v1);
ccdVec3Add(pos, &vs[i]->v.v2);
scale += CCD_REAL(2.);
}
ccdVec3Scale(pos, CCD_ONE / scale);
free(vs);
return 0;
}
int ccdGJKPenetration(const void *obj1, const void *obj2, const ccd_t *ccd,
ccd_real_t *depth, ccd_vec3_t *dir, ccd_vec3_t *pos)
{
ccd_pt_t polytope;
ccd_pt_el_t *nearest;
int ret;
ccdPtInit(&polytope);
ret = __ccdGJKEPA(obj1, obj2, ccd, &polytope, &nearest);
// set separation vector
if (ret == 0 && nearest){
// compute depth of penetration
*depth = CCD_SQRT(nearest->dist);
// store normalized direction vector
ccdVec3Copy(dir, &nearest->witness);
ccdVec3Normalize(dir);
// compute position
if (penEPAPos(&polytope, nearest, pos) != 0){
ccdPtDestroy(&polytope);
return -2;
}
}
ccdPtDestroy(&polytope);
return ret;
}
static int __ccdGJK(const void *obj1, const void *obj2,
const ccd_t *ccd, ccd_simplex_t *simplex)
{
unsigned long iterations;
ccd_vec3_t dir; // direction vector
ccd_support_t last; // last support point
int do_simplex_res;
// initialize simplex struct
ccdSimplexInit(simplex);
// get first direction
ccd->first_dir(obj1, obj2, &dir);
// get first support point
__ccdSupport(obj1, obj2, &dir, ccd, &last);
// and add this point to simplex as last one
ccdSimplexAdd(simplex, &last);
// set up direction vector to as (O - last) which is exactly -last
ccdVec3Copy(&dir, &last.v);
ccdVec3Scale(&dir, -CCD_ONE);
// start iterations
for (iterations = 0UL; iterations < ccd->max_iterations; ++iterations) {
// obtain support point
__ccdSupport(obj1, obj2, &dir, ccd, &last);
// check if farthest point in Minkowski difference in direction dir
// isn't somewhere before origin (the test on negative dot product)
// - because if it is, objects are not intersecting at all.
if (ccdVec3Dot(&last.v, &dir) < CCD_ZERO){
return -1; // intersection not found
}
// add last support vector to simplex
ccdSimplexAdd(simplex, &last);
// if doSimplex returns 1 if objects intersect, -1 if objects don't
// intersect and 0 if algorithm should continue
do_simplex_res = doSimplex(simplex, &dir);
if (do_simplex_res == 1){
return 0; // intersection found
}else if (do_simplex_res == -1){
return -1; // intersection not found
}
if (ccdIsZero(ccdVec3Len2(&dir))){
return -1; // intersection not found
}
}
// intersection wasn't found
return -1;
}
static int __ccdGJKEPA(const void *obj1, const void *obj2,
const ccd_t *ccd,
ccd_pt_t *polytope, ccd_pt_el_t **nearest)
{
ccd_simplex_t simplex;
ccd_support_t supp; // support point
int ret, size;
*nearest = NULL;
// run GJK and obtain terminal simplex
ret = __ccdGJK(obj1, obj2, ccd, &simplex);
if (ret != 0)
return -1;
// transform simplex to polytope - simplex won't be used anymore
size = ccdSimplexSize(&simplex);
if (size == 4){
ret = simplexToPolytope4(obj1, obj2, ccd, &simplex, polytope, nearest);
}else if (size == 3){
ret = simplexToPolytope3(obj1, obj2, ccd, &simplex, polytope, nearest);
}else{ // size == 2
ret = simplexToPolytope2(obj1, obj2, ccd, &simplex, polytope, nearest);
}
if (ret == -1){
// touching contact
return 0;
}else if (ret == -2){
// failed memory allocation
return -2;
}
while (1){
// get triangle nearest to origin
*nearest = ccdPtNearest(polytope);
// get next support point
if (nextSupport(obj1, obj2, ccd, *nearest, &supp) != 0)
break;
// expand nearest triangle using new point - supp
if (expandPolytope(polytope, *nearest, &supp) != 0)
return -2;
}
return 0;
}
static int doSimplex2(ccd_simplex_t *simplex, ccd_vec3_t *dir)
{
const ccd_support_t *A, *B;
ccd_vec3_t AB, AO, tmp;
ccd_real_t dot;
// get last added as A
A = ccdSimplexLast(simplex);
// get the other point
B = ccdSimplexPoint(simplex, 0);
// compute AB oriented segment
ccdVec3Sub2(&AB, &B->v, &A->v);
// compute AO vector
ccdVec3Copy(&AO, &A->v);
ccdVec3Scale(&AO, -CCD_ONE);
// dot product AB . AO
dot = ccdVec3Dot(&AB, &AO);
// check if origin doesn't lie on AB segment
ccdVec3Cross(&tmp, &AB, &AO);
if (ccdIsZero(ccdVec3Len2(&tmp)) && dot > CCD_ZERO){
return 1;
}
// check if origin is in area where AB segment is
if (ccdIsZero(dot) || dot < CCD_ZERO){
// origin is in outside are of A
ccdSimplexSet(simplex, 0, A);
ccdSimplexSetSize(simplex, 1);
ccdVec3Copy(dir, &AO);
}else{
// origin is in area where AB segment is
// keep simplex untouched and set direction to
// AB x AO x AB
tripleCross(&AB, &AO, &AB, dir);
}
return 0;
}
static int doSimplex3(ccd_simplex_t *simplex, ccd_vec3_t *dir)
{
const ccd_support_t *A, *B, *C;
ccd_vec3_t AO, AB, AC, ABC, tmp;
ccd_real_t dot, dist;
// get last added as A
A = ccdSimplexLast(simplex);
// get the other points
B = ccdSimplexPoint(simplex, 1);
C = ccdSimplexPoint(simplex, 0);
// check touching contact
dist = ccdVec3PointTriDist2(ccd_vec3_origin, &A->v, &B->v, &C->v, NULL);
if (ccdIsZero(dist)){
return 1;
}
// check if triangle is really triangle (has area > 0)
// if not simplex can't be expanded and thus no itersection is found
if (ccdVec3Eq(&A->v, &B->v) || ccdVec3Eq(&A->v, &C->v)){
return -1;
}
// compute AO vector
ccdVec3Copy(&AO, &A->v);
ccdVec3Scale(&AO, -CCD_ONE);
// compute AB and AC segments and ABC vector (perpendircular to triangle)
ccdVec3Sub2(&AB, &B->v, &A->v);
ccdVec3Sub2(&AC, &C->v, &A->v);
ccdVec3Cross(&ABC, &AB, &AC);
ccdVec3Cross(&tmp, &ABC, &AC);
dot = ccdVec3Dot(&tmp, &AO);
if (ccdIsZero(dot) || dot > CCD_ZERO){
dot = ccdVec3Dot(&AC, &AO);
if (ccdIsZero(dot) || dot > CCD_ZERO){
// C is already in place
ccdSimplexSet(simplex, 1, A);
ccdSimplexSetSize(simplex, 2);
tripleCross(&AC, &AO, &AC, dir);
}else{
ccd_do_simplex3_45:
dot = ccdVec3Dot(&AB, &AO);
if (ccdIsZero(dot) || dot > CCD_ZERO){
ccdSimplexSet(simplex, 0, B);
ccdSimplexSet(simplex, 1, A);
ccdSimplexSetSize(simplex, 2);
tripleCross(&AB, &AO, &AB, dir);
}else{
ccdSimplexSet(simplex, 0, A);
ccdSimplexSetSize(simplex, 1);
ccdVec3Copy(dir, &AO);
}
}
}else{
ccdVec3Cross(&tmp, &AB, &ABC);
dot = ccdVec3Dot(&tmp, &AO);
if (ccdIsZero(dot) || dot > CCD_ZERO){
goto ccd_do_simplex3_45;
}else{
dot = ccdVec3Dot(&ABC, &AO);
if (ccdIsZero(dot) || dot > CCD_ZERO){
ccdVec3Copy(dir, &ABC);
}else{
ccd_support_t Ctmp;
ccdSupportCopy(&Ctmp, C);
ccdSimplexSet(simplex, 0, B);
ccdSimplexSet(simplex, 1, &Ctmp);
ccdVec3Copy(dir, &ABC);
ccdVec3Scale(dir, -CCD_ONE);
}
}
}
return 0;
}
static int doSimplex4(ccd_simplex_t *simplex, ccd_vec3_t *dir)
{
const ccd_support_t *A, *B, *C, *D;
ccd_vec3_t AO, AB, AC, AD, ABC, ACD, ADB;
int B_on_ACD, C_on_ADB, D_on_ABC;
int AB_O, AC_O, AD_O;
ccd_real_t dist;
// get last added as A
A = ccdSimplexLast(simplex);
// get the other points
B = ccdSimplexPoint(simplex, 2);
C = ccdSimplexPoint(simplex, 1);
D = ccdSimplexPoint(simplex, 0);
// check if tetrahedron is really tetrahedron (has volume > 0)
// if it is not simplex can't be expanded and thus no intersection is
// found
dist = ccdVec3PointTriDist2(&A->v, &B->v, &C->v, &D->v, NULL);
if (ccdIsZero(dist)){
return -1;
}
// check if origin lies on some of tetrahedron's face - if so objects
// intersect
dist = ccdVec3PointTriDist2(ccd_vec3_origin, &A->v, &B->v, &C->v, NULL);
if (ccdIsZero(dist))
return 1;
dist = ccdVec3PointTriDist2(ccd_vec3_origin, &A->v, &C->v, &D->v, NULL);
if (ccdIsZero(dist))
return 1;
dist = ccdVec3PointTriDist2(ccd_vec3_origin, &A->v, &B->v, &D->v, NULL);
if (ccdIsZero(dist))
return 1;
dist = ccdVec3PointTriDist2(ccd_vec3_origin, &B->v, &C->v, &D->v, NULL);
if (ccdIsZero(dist))
return 1;
// compute AO, AB, AC, AD segments and ABC, ACD, ADB normal vectors
ccdVec3Copy(&AO, &A->v);
ccdVec3Scale(&AO, -CCD_ONE);
ccdVec3Sub2(&AB, &B->v, &A->v);
ccdVec3Sub2(&AC, &C->v, &A->v);
ccdVec3Sub2(&AD, &D->v, &A->v);
ccdVec3Cross(&ABC, &AB, &AC);
ccdVec3Cross(&ACD, &AC, &AD);
ccdVec3Cross(&ADB, &AD, &AB);
// side (positive or negative) of B, C, D relative to planes ACD, ADB
// and ABC respectively
B_on_ACD = ccdSign(ccdVec3Dot(&ACD, &AB));
C_on_ADB = ccdSign(ccdVec3Dot(&ADB, &AC));
D_on_ABC = ccdSign(ccdVec3Dot(&ABC, &AD));
// whether origin is on same side of ACD, ADB, ABC as B, C, D
// respectively
AB_O = ccdSign(ccdVec3Dot(&ACD, &AO)) == B_on_ACD;
AC_O = ccdSign(ccdVec3Dot(&ADB, &AO)) == C_on_ADB;
AD_O = ccdSign(ccdVec3Dot(&ABC, &AO)) == D_on_ABC;
if (AB_O && AC_O && AD_O){
// origin is in tetrahedron
return 1;
// rearrange simplex to triangle and call doSimplex3()
}else if (!AB_O){
// B is farthest from the origin among all of the tetrahedron's
// points, so remove it from the list and go on with the triangle
// case
// D and C are in place
ccdSimplexSet(simplex, 2, A);
ccdSimplexSetSize(simplex, 3);
}else if (!AC_O){
// C is farthest
ccdSimplexSet(simplex, 1, D);
ccdSimplexSet(simplex, 0, B);
ccdSimplexSet(simplex, 2, A);
ccdSimplexSetSize(simplex, 3);
}else{ // (!AD_O)
ccdSimplexSet(simplex, 0, C);
ccdSimplexSet(simplex, 1, B);
ccdSimplexSet(simplex, 2, A);
ccdSimplexSetSize(simplex, 3);
}
return doSimplex3(simplex, dir);
}
static int doSimplex(ccd_simplex_t *simplex, ccd_vec3_t *dir)
{
if (ccdSimplexSize(simplex) == 2){
// simplex contains segment only one segment
return doSimplex2(simplex, dir);
}else if (ccdSimplexSize(simplex) == 3){
// simplex contains triangle
return doSimplex3(simplex, dir);
}else{ // ccdSimplexSize(simplex) == 4
// tetrahedron - this is the only shape which can encapsule origin
// so doSimplex4() also contains test on it
return doSimplex4(simplex, dir);
}
}
_ccd_inline void tripleCross(const ccd_vec3_t *a, const ccd_vec3_t *b,
const ccd_vec3_t *c, ccd_vec3_t *d)
{
ccd_vec3_t e;
ccdVec3Cross(&e, a, b);
ccdVec3Cross(d, &e, c);
}
/** Transforms simplex to polytope. It is assumed that simplex has 4
* vertices! */
static int simplexToPolytope4(const void *obj1, const void *obj2,
const ccd_t *ccd,
ccd_simplex_t *simplex,
ccd_pt_t *pt, ccd_pt_el_t **nearest)
{
const ccd_support_t *a, *b, *c, *d;
int use_polytope3;
ccd_real_t dist;
ccd_pt_vertex_t *v[4];
ccd_pt_edge_t *e[6];
size_t i;
a = ccdSimplexPoint(simplex, 0);
b = ccdSimplexPoint(simplex, 1);
c = ccdSimplexPoint(simplex, 2);
d = ccdSimplexPoint(simplex, 3);
// check if origin lies on some of tetrahedron's face - if so use
// simplexToPolytope3()
use_polytope3 = 0;
dist = ccdVec3PointTriDist2(ccd_vec3_origin, &a->v, &b->v, &c->v, NULL);
if (ccdIsZero(dist)){
use_polytope3 = 1;
}
dist = ccdVec3PointTriDist2(ccd_vec3_origin, &a->v, &c->v, &d->v, NULL);
if (ccdIsZero(dist)){
use_polytope3 = 1;
ccdSimplexSet(simplex, 1, c);
ccdSimplexSet(simplex, 2, d);
}
dist = ccdVec3PointTriDist2(ccd_vec3_origin, &a->v, &b->v, &d->v, NULL);
if (ccdIsZero(dist)){
use_polytope3 = 1;
ccdSimplexSet(simplex, 2, d);
}
dist = ccdVec3PointTriDist2(ccd_vec3_origin, &b->v, &c->v, &d->v, NULL);
if (ccdIsZero(dist)){
use_polytope3 = 1;
ccdSimplexSet(simplex, 0, b);
ccdSimplexSet(simplex, 1, c);
ccdSimplexSet(simplex, 2, d);
}
if (use_polytope3){
ccdSimplexSetSize(simplex, 3);
return simplexToPolytope3(obj1, obj2, ccd, simplex, pt, nearest);
}
// no touching contact - simply create tetrahedron
for (i = 0; i < 4; i++){
v[i] = ccdPtAddVertex(pt, ccdSimplexPoint(simplex, i));
}
e[0] = ccdPtAddEdge(pt, v[0], v[1]);
e[1] = ccdPtAddEdge(pt, v[1], v[2]);
e[2] = ccdPtAddEdge(pt, v[2], v[0]);
e[3] = ccdPtAddEdge(pt, v[3], v[0]);
e[4] = ccdPtAddEdge(pt, v[3], v[1]);
e[5] = ccdPtAddEdge(pt, v[3], v[2]);
// ccdPtAdd*() functions return NULL either if the memory allocation
// failed of if any of the input pointers are NULL, so the bad
// allocation can be checked by the last calls of ccdPtAddFace()
// because the rest of the bad allocations eventually "bubble up" here
if (ccdPtAddFace(pt, e[0], e[1], e[2]) == NULL
|| ccdPtAddFace(pt, e[3], e[4], e[0]) == NULL
|| ccdPtAddFace(pt, e[4], e[5], e[1]) == NULL
|| ccdPtAddFace(pt, e[5], e[3], e[2]) == NULL){
return -2;
}
return 0;
}
/** Transforms simplex to polytope, three vertices required */
static int simplexToPolytope3(const void *obj1, const void *obj2,
const ccd_t *ccd,
const ccd_simplex_t *simplex,
ccd_pt_t *pt, ccd_pt_el_t **nearest)
{
const ccd_support_t *a, *b, *c;
ccd_support_t d, d2;
ccd_vec3_t ab, ac, dir;
ccd_pt_vertex_t *v[5];
ccd_pt_edge_t *e[9];
ccd_real_t dist, dist2;
*nearest = NULL;
a = ccdSimplexPoint(simplex, 0);
b = ccdSimplexPoint(simplex, 1);
c = ccdSimplexPoint(simplex, 2);
// If only one triangle left from previous GJK run origin lies on this
// triangle. So it is necessary to expand triangle into two
// tetrahedrons connected with base (which is exactly abc triangle).
// get next support point in direction of normal of triangle
ccdVec3Sub2(&ab, &b->v, &a->v);
ccdVec3Sub2(&ac, &c->v, &a->v);
ccdVec3Cross(&dir, &ab, &ac);
__ccdSupport(obj1, obj2, &dir, ccd, &d);
dist = ccdVec3PointTriDist2(&d.v, &a->v, &b->v, &c->v, NULL);
// and second one take in opposite direction
ccdVec3Scale(&dir, -CCD_ONE);
__ccdSupport(obj1, obj2, &dir, ccd, &d2);
dist2 = ccdVec3PointTriDist2(&d2.v, &a->v, &b->v, &c->v, NULL);
// check if face isn't already on edge of minkowski sum and thus we
// have touching contact
if (ccdIsZero(dist) || ccdIsZero(dist2)){
v[0] = ccdPtAddVertex(pt, a);
v[1] = ccdPtAddVertex(pt, b);
v[2] = ccdPtAddVertex(pt, c);
e[0] = ccdPtAddEdge(pt, v[0], v[1]);
e[1] = ccdPtAddEdge(pt, v[1], v[2]);
e[2] = ccdPtAddEdge(pt, v[2], v[0]);
*nearest = (ccd_pt_el_t *)ccdPtAddFace(pt, e[0], e[1], e[2]);
if (*nearest == NULL)
return -2;
return -1;
}
// form polyhedron
v[0] = ccdPtAddVertex(pt, a);
v[1] = ccdPtAddVertex(pt, b);
v[2] = ccdPtAddVertex(pt, c);
v[3] = ccdPtAddVertex(pt, &d);
v[4] = ccdPtAddVertex(pt, &d2);
e[0] = ccdPtAddEdge(pt, v[0], v[1]);
e[1] = ccdPtAddEdge(pt, v[1], v[2]);
e[2] = ccdPtAddEdge(pt, v[2], v[0]);
e[3] = ccdPtAddEdge(pt, v[3], v[0]);
e[4] = ccdPtAddEdge(pt, v[3], v[1]);
e[5] = ccdPtAddEdge(pt, v[3], v[2]);
e[6] = ccdPtAddEdge(pt, v[4], v[0]);
e[7] = ccdPtAddEdge(pt, v[4], v[1]);
e[8] = ccdPtAddEdge(pt, v[4], v[2]);
if (ccdPtAddFace(pt, e[3], e[4], e[0]) == NULL
|| ccdPtAddFace(pt, e[4], e[5], e[1]) == NULL
|| ccdPtAddFace(pt, e[5], e[3], e[2]) == NULL
|| ccdPtAddFace(pt, e[6], e[7], e[0]) == NULL
|| ccdPtAddFace(pt, e[7], e[8], e[1]) == NULL
|| ccdPtAddFace(pt, e[8], e[6], e[2]) == NULL){
return -2;
}
return 0;
}
/** Transforms simplex to polytope, two vertices required */
static int simplexToPolytope2(const void *obj1, const void *obj2,
const ccd_t *ccd,
const ccd_simplex_t *simplex,
ccd_pt_t *pt, ccd_pt_el_t **nearest)
{
const ccd_support_t *a, *b;
ccd_vec3_t ab, ac, dir;
ccd_support_t supp[4];
ccd_pt_vertex_t *v[6];
ccd_pt_edge_t *e[12];
size_t i;
int found;
a = ccdSimplexPoint(simplex, 0);
b = ccdSimplexPoint(simplex, 1);
// This situation is a bit tricky. If only one segment comes from
// previous run of GJK - it means that either this segment is on
// minkowski edge (and thus we have touch contact) or it it isn't and
// therefore segment is somewhere *inside* minkowski sum and it *must*
// be possible to fully enclose this segment with polyhedron formed by
// at least 8 triangle faces.
// get first support point (any)
found = 0;
for (i = 0; i < ccd_points_on_sphere_len; i++){
__ccdSupport(obj1, obj2, &ccd_points_on_sphere[i], ccd, &supp[0]);
if (!ccdVec3Eq(&a->v, &supp[0].v) && !ccdVec3Eq(&b->v, &supp[0].v)){
found = 1;
break;
}
}
if (!found)
goto simplexToPolytope2_touching_contact;
// get second support point in opposite direction than supp[0]
ccdVec3Copy(&dir, &supp[0].v);
ccdVec3Scale(&dir, -CCD_ONE);
__ccdSupport(obj1, obj2, &dir, ccd, &supp[1]);
if (ccdVec3Eq(&a->v, &supp[1].v) || ccdVec3Eq(&b->v, &supp[1].v))
goto simplexToPolytope2_touching_contact;
// next will be in direction of normal of triangle a,supp[0],supp[1]
ccdVec3Sub2(&ab, &supp[0].v, &a->v);
ccdVec3Sub2(&ac, &supp[1].v, &a->v);
ccdVec3Cross(&dir, &ab, &ac);
__ccdSupport(obj1, obj2, &dir, ccd, &supp[2]);
if (ccdVec3Eq(&a->v, &supp[2].v) || ccdVec3Eq(&b->v, &supp[2].v))
goto simplexToPolytope2_touching_contact;
// and last one will be in opposite direction
ccdVec3Scale(&dir, -CCD_ONE);
__ccdSupport(obj1, obj2, &dir, ccd, &supp[3]);
if (ccdVec3Eq(&a->v, &supp[3].v) || ccdVec3Eq(&b->v, &supp[3].v))
goto simplexToPolytope2_touching_contact;
goto simplexToPolytope2_not_touching_contact;
simplexToPolytope2_touching_contact:
v[0] = ccdPtAddVertex(pt, a);
v[1] = ccdPtAddVertex(pt, b);
*nearest = (ccd_pt_el_t *)ccdPtAddEdge(pt, v[0], v[1]);
if (*nearest == NULL)
return -2;
return -1;
simplexToPolytope2_not_touching_contact:
// form polyhedron
v[0] = ccdPtAddVertex(pt, a);
v[1] = ccdPtAddVertex(pt, &supp[0]);
v[2] = ccdPtAddVertex(pt, b);
v[3] = ccdPtAddVertex(pt, &supp[1]);
v[4] = ccdPtAddVertex(pt, &supp[2]);
v[5] = ccdPtAddVertex(pt, &supp[3]);
e[0] = ccdPtAddEdge(pt, v[0], v[1]);
e[1] = ccdPtAddEdge(pt, v[1], v[2]);
e[2] = ccdPtAddEdge(pt, v[2], v[3]);
e[3] = ccdPtAddEdge(pt, v[3], v[0]);
e[4] = ccdPtAddEdge(pt, v[4], v[0]);
e[5] = ccdPtAddEdge(pt, v[4], v[1]);
e[6] = ccdPtAddEdge(pt, v[4], v[2]);
e[7] = ccdPtAddEdge(pt, v[4], v[3]);
e[8] = ccdPtAddEdge(pt, v[5], v[0]);
e[9] = ccdPtAddEdge(pt, v[5], v[1]);
e[10] = ccdPtAddEdge(pt, v[5], v[2]);
e[11] = ccdPtAddEdge(pt, v[5], v[3]);
if (ccdPtAddFace(pt, e[4], e[5], e[0]) == NULL
|| ccdPtAddFace(pt, e[5], e[6], e[1]) == NULL
|| ccdPtAddFace(pt, e[6], e[7], e[2]) == NULL
|| ccdPtAddFace(pt, e[7], e[4], e[3]) == NULL
|| ccdPtAddFace(pt, e[8], e[9], e[0]) == NULL
|| ccdPtAddFace(pt, e[9], e[10], e[1]) == NULL
|| ccdPtAddFace(pt, e[10], e[11], e[2]) == NULL
|| ccdPtAddFace(pt, e[11], e[8], e[3]) == NULL){
return -2;
}
return 0;
}
/** Expands polytope's tri by new vertex v. Triangle tri is replaced by
* three triangles each with one vertex in v. */
static int expandPolytope(ccd_pt_t *pt, ccd_pt_el_t *el,
const ccd_support_t *newv)
{
ccd_pt_vertex_t *v[5];
ccd_pt_edge_t *e[8];
ccd_pt_face_t *f[2];
// element can be either segment or triangle
if (el->type == CCD_PT_EDGE){
// In this case, segment should be replaced by new point.
// Simpliest case is when segment stands alone and in this case
// this segment is replaced by two other segments both connected to
// newv.
// Segment can be also connected to max two faces and in that case
// each face must be replaced by two other faces. To do this
// correctly it is necessary to have correctly ordered edges and
// vertices which is exactly what is done in following code.
//
ccdPtEdgeVertices((const ccd_pt_edge_t *)el, &v[0], &v[2]);
ccdPtEdgeFaces((ccd_pt_edge_t *)el, &f[0], &f[1]);
if (f[0]){
ccdPtFaceEdges(f[0], &e[0], &e[1], &e[2]);
if (e[0] == (ccd_pt_edge_t *)el){
e[0] = e[2];
}else if (e[1] == (ccd_pt_edge_t *)el){
e[1] = e[2];
}
ccdPtEdgeVertices(e[0], &v[1], &v[3]);
if (v[1] != v[0] && v[3] != v[0]){
e[2] = e[0];
e[0] = e[1];
e[1] = e[2];
if (v[1] == v[2])
v[1] = v[3];
}else{
if (v[1] == v[0])
v[1] = v[3];
}
if (f[1]){
ccdPtFaceEdges(f[1], &e[2], &e[3], &e[4]);
if (e[2] == (ccd_pt_edge_t *)el){
e[2] = e[4];
}else if (e[3] == (ccd_pt_edge_t *)el){
e[3] = e[4];
}
ccdPtEdgeVertices(e[2], &v[3], &v[4]);
if (v[3] != v[2] && v[4] != v[2]){
e[4] = e[2];
e[2] = e[3];
e[3] = e[4];
if (v[3] == v[0])
v[3] = v[4];
}else{
if (v[3] == v[2])
v[3] = v[4];
}
}
v[4] = ccdPtAddVertex(pt, newv);
ccdPtDelFace(pt, f[0]);
if (f[1]){
ccdPtDelFace(pt, f[1]);
ccdPtDelEdge(pt, (ccd_pt_edge_t *)el);
}
e[4] = ccdPtAddEdge(pt, v[4], v[2]);
e[5] = ccdPtAddEdge(pt, v[4], v[0]);
e[6] = ccdPtAddEdge(pt, v[4], v[1]);
if (f[1])
e[7] = ccdPtAddEdge(pt, v[4], v[3]);
if (ccdPtAddFace(pt, e[1], e[4], e[6]) == NULL
|| ccdPtAddFace(pt, e[0], e[6], e[5]) == NULL){
return -2;
}
if (f[1]){
if (ccdPtAddFace(pt, e[3], e[5], e[7]) == NULL
|| ccdPtAddFace(pt, e[4], e[7], e[2]) == NULL){
return -2;
}
}else{
if (ccdPtAddFace(pt, e[4], e[5], (ccd_pt_edge_t *)el) == NULL)
return -2;
}
}
}else{ // el->type == CCD_PT_FACE
// replace triangle by tetrahedron without base (base would be the
// triangle that will be removed)
// get triplet of surrounding edges and vertices of triangle face
ccdPtFaceEdges((const ccd_pt_face_t *)el, &e[0], &e[1], &e[2]);
ccdPtEdgeVertices(e[0], &v[0], &v[1]);
ccdPtEdgeVertices(e[1], &v[2], &v[3]);
// following code sorts edges to have e[0] between vertices 0-1,
// e[1] between 1-2 and e[2] between 2-0
if (v[2] != v[1] && v[3] != v[1]){
// swap e[1] and e[2]
e[3] = e[1];
e[1] = e[2];
e[2] = e[3];
}
if (v[3] != v[0] && v[3] != v[1])
v[2] = v[3];
// remove triangle face
ccdPtDelFace(pt, (ccd_pt_face_t *)el);
// expand triangle to tetrahedron
v[3] = ccdPtAddVertex(pt, newv);
e[3] = ccdPtAddEdge(pt, v[3], v[0]);
e[4] = ccdPtAddEdge(pt, v[3], v[1]);
e[5] = ccdPtAddEdge(pt, v[3], v[2]);
if (ccdPtAddFace(pt, e[3], e[4], e[0]) == NULL
|| ccdPtAddFace(pt, e[4], e[5], e[1]) == NULL
|| ccdPtAddFace(pt, e[5], e[3], e[2]) == NULL){
return -2;
}
}
return 0;
}
/** Finds next support point (and stores it in out argument).
* Returns 0 on success, -1 otherwise */
static int nextSupport(const void *obj1, const void *obj2, const ccd_t *ccd,
const ccd_pt_el_t *el,
ccd_support_t *out)
{
ccd_vec3_t *a, *b, *c;
ccd_real_t dist;
if (el->type == CCD_PT_VERTEX)
return -1;
// touch contact
if (ccdIsZero(el->dist))
return -1;
__ccdSupport(obj1, obj2, &el->witness, ccd, out);
// Compute dist of support point along element witness point direction
// so we can determine whether we expanded a polytope surrounding the
// origin a bit.
dist = ccdVec3Dot(&out->v, &el->witness);
if (dist - el->dist < ccd->epa_tolerance)
return -1;
if (el->type == CCD_PT_EDGE){
// fetch end points of edge
ccdPtEdgeVec3((ccd_pt_edge_t *)el, &a, &b);
// get distance from segment
dist = ccdVec3PointSegmentDist2(&out->v, a, b, NULL);
}else{ // el->type == CCD_PT_FACE
// fetch vertices of triangle face
ccdPtFaceVec3((ccd_pt_face_t *)el, &a, &b, &c);
// check if new point can significantly expand polytope
dist = ccdVec3PointTriDist2(&out->v, a, b, c, NULL);
}
if (dist < ccd->epa_tolerance)
return -1;
return 0;
}
================================================
FILE: src/dbg.h
================================================
/***
* 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_DBG_H__
#define __CCD_DBG_H__
/**
* Some macros which can be used for printing debug info to stderr if macro
* NDEBUG not defined.
*
* DBG_PROLOGUE can be specified as string and this string will be
* prepended to output text
*/
#ifndef NDEBUG
#include <stdio.h>
#ifndef DBG_PROLOGUE
# define DBG_PROLOGUE
#endif
# define DBG(format, ...) do { \
fprintf(stderr, DBG_PROLOGUE "%s :: " format "\n", __func__, ## __VA_ARGS__); \
fflush(stderr); \
} while (0)
# define DBG2(str) do { \
fprintf(stderr, DBG_PROLOGUE "%s :: " str "\n", __func__); \
fflush(stderr); \
} while (0)
# define DBG_VEC3(vec, prefix) do {\
fprintf(stderr, DBG_PROLOGUE "%s :: %s[%lf %lf %lf]\n", \
__func__, prefix, ccdVec3X(vec), ccdVec3Y(vec), ccdVec3Z(vec)); \
fflush(stderr); \
} while (0)
/*
# define DBG_VEC3(vec, prefix) do {\
fprintf(stderr, DBG_PROLOGUE "%s :: %s[%.20lf %.20lf %.20lf]\n", \
__func__, prefix, ccdVec3X(vec), ccdVec3Y(vec), ccdVec3Z(vec)); \
fflush(stderr); \
} while (0)
*/
#else
# define DBG(format, ...)
# define DBG2(str)
# define DBG_VEC3(v, prefix)
#endif
#endif /* __CCD_DBG_H__ */
================================================
FILE: src/list.h
================================================
/***
* 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_LIST_H__
#define __CCD_LIST_H__
#include <string.h>
#include <ccd/compiler.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
struct _ccd_list_t {
struct _ccd_list_t *next, *prev;
};
typedef struct _ccd_list_t ccd_list_t;
/**
* Get the struct for this entry.
* @ptr: the &ccd_list_t pointer.
* @type: the type of the struct this is embedded in.
* @member: the name of the list_struct within the struct.
*/
#define ccdListEntry(ptr, type, member) \
ccd_container_of(ptr, type, member)
/**
* Iterates over list.
*/
#define ccdListForEach(list, item) \
for (item = (list)->next; \
_ccd_prefetch((item)->next), item != (list); \
item = (item)->next)
/**
* Iterates over list safe against remove of list entry
*/
#define ccdListForEachSafe(list, item, tmp) \
for (item = (list)->next, tmp = (item)->next; \
item != (list); \
item = tmp, tmp = (item)->next)
/**
* Iterates over list of given type.
* @pos: the type * to use as a loop cursor.
* @head: the head for your list.
* @member: the name of the list_struct within the struct.
*/
#define ccdListForEachEntry(head, pos, postype, member) \
for (pos = ccdListEntry((head)->next, postype, member); \
_ccd_prefetch(pos->member.next), &pos->member != (head); \
pos = ccdListEntry(pos->member.next, postype, member))
/**
* Iterates over list of given type safe against removal of list entry
* @pos: the type * to use as a loop cursor.
* @n: another type * to use as temporary storage
* @head: the head for your list.
* @member: the name of the list_struct within the struct.
*/
#define ccdListForEachEntrySafe(head, pos, postype, n, ntype, member) \
for (pos = ccdListEntry((head)->next, postype, member), \
n = ccdListEntry(pos->member.next, postype, member); \
&pos->member != (head); \
pos = n, n = ccdListEntry(n->member.next, ntype, member))
/**
* Initialize list.
*/
_ccd_inline void ccdListInit(ccd_list_t *l);
_ccd_inline ccd_list_t *ccdListNext(ccd_list_t *l);
_ccd_inline ccd_list_t *ccdListPrev(ccd_list_t *l);
/**
* Returns true if list is empty.
*/
_ccd_inline int ccdListEmpty(const ccd_list_t *head);
/**
* Appends item to end of the list l.
*/
_ccd_inline void ccdListAppend(ccd_list_t *l, ccd_list_t *item);
/**
* Removes item from list.
*/
_ccd_inline void ccdListDel(ccd_list_t *item);
///
/// INLINES:
///
_ccd_inline void ccdListInit(ccd_list_t *l)
{
l->next = l;
l->prev = l;
}
_ccd_inline ccd_list_t *ccdListNext(ccd_list_t *l)
{
return l->next;
}
_ccd_inline ccd_list_t *ccdListPrev(ccd_list_t *l)
{
return l->prev;
}
_ccd_inline int ccdListEmpty(const ccd_list_t *head)
{
return head->next == head;
}
_ccd_inline void ccdListAppend(ccd_list_t *l, ccd_list_t *new)
{
new->prev = l->prev;
new->next = l;
l->prev->next = new;
l->prev = new;
}
_ccd_inline void ccdListDel(ccd_list_t *item)
{
item->next->prev = item->prev;
item->prev->next = item->next;
item->next = item;
item->prev = item;
}
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
#endif /* __CCD_LIST_H__ */
================================================
FILE: src/mpr.c
================================================
/***
* 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.
*/
#include <stdlib.h>
#include <ccd/ccd.h>
#include "simplex.h"
#include "dbg.h"
/** Finds origin (center) of Minkowski difference (actually it can be any
* interior point of Minkowski difference. */
_ccd_inline void findOrigin(const void *obj1, const void *obj2, const ccd_t *ccd,
ccd_support_t *center);
/** Discovers initial portal - that is tetrahedron that intersects with
* origin ray (ray from center of Minkowski diff to (0,0,0).
*
* Returns -1 if already recognized that origin is outside Minkowski
* portal.
* Returns 1 if origin lies on v1 of simplex (only v0 and v1 are present
* in simplex).
* Returns 2 if origin lies on v0-v1 segment.
* Returns 0 if portal was built.
*/
static int discoverPortal(const void *obj1, const void *obj2,
const ccd_t *ccd, ccd_simplex_t *portal);
/** Expands portal towards origin and determine if objects intersect.
* Already established portal must be given as argument.
* If intersection is found 0 is returned, -1 otherwise */
static int refinePortal(const void *obj1, const void *obj2,
const ccd_t *ccd, ccd_simplex_t *portal);
/** Finds penetration info by expanding provided portal. */
static void findPenetr(const void *obj1, const void *obj2, const ccd_t *ccd,
ccd_simplex_t *portal,
ccd_real_t *depth, ccd_vec3_t *dir, ccd_vec3_t *pos);
/** Finds penetration info if origin lies on portal's v1 */
static void findPenetrTouch(const void *obj1, const void *obj2, const ccd_t *ccd,
ccd_simplex_t *portal,
ccd_real_t *depth, ccd_vec3_t *dir, ccd_vec3_t *pos);
/** Find penetration info if origin lies on portal's segment v0-v1 */
static void findPenetrSegment(const void *obj1, const void *obj2, const ccd_t *ccd,
ccd_simplex_t *portal,
ccd_real_t *depth, ccd_vec3_t *dir, ccd_vec3_t *pos);
/** Finds position vector from fully established portal */
static void findPos(const void *obj1, const void *obj2, const ccd_t *ccd,
const ccd_simplex_t *portal, ccd_vec3_t *pos);
/** Extends portal with new support point.
* Portal must have face v1-v2-v3 arranged to face outside portal. */
_ccd_inline void expandPortal(ccd_simplex_t *portal,
const ccd_support_t *v4);
/** Fill dir with direction outside portal. Portal's v1-v2-v3 face must be
* arranged in correct order! */
_ccd_inline void portalDir(const ccd_simplex_t *portal, ccd_vec3_t *dir);
/** Returns true if portal encapsules origin (0,0,0), dir is direction of
* v1-v2-v3 face. */
_ccd_inline int portalEncapsulesOrigin(const ccd_simplex_t *portal,
const ccd_vec3_t *dir);
/** Returns true if portal with new point v4 would reach specified
* tolerance (i.e. returns true if portal can _not_ significantly expand
* within Minkowski difference).
*
* v4 is candidate for new point in portal, dir is direction in which v4
* was obtained. */
_ccd_inline int portalReachTolerance(const ccd_simplex_t *portal,
const ccd_support_t *v4,
const ccd_vec3_t *dir,
const ccd_t *ccd);
/** Returns true if portal expanded by new point v4 could possibly contain
* origin, dir is direction in which v4 was obtained. */
_ccd_inline int portalCanEncapsuleOrigin(const ccd_simplex_t *portal,
const ccd_support_t *v4,
const ccd_vec3_t *dir);
int ccdMPRIntersect(const void *obj1, const void *obj2, const ccd_t *ccd)
{
ccd_simplex_t portal;
int res;
// Phase 1: Portal discovery - find portal that intersects with origin
// ray (ray from center of Minkowski diff to origin of coordinates)
res = discoverPortal(obj1, obj2, ccd, &portal);
if (res < 0)
return 0;
if (res > 0)
return 1;
// Phase 2: Portal refinement
res = refinePortal(obj1, obj2, ccd, &portal);
return (res == 0 ? 1 : 0);
}
int ccdMPRPenetration(const void *obj1, const void *obj2, const ccd_t *ccd,
ccd_real_t *depth, ccd_vec3_t *dir, ccd_vec3_t *pos)
{
ccd_simplex_t portal;
int res;
// Phase 1: Portal discovery
res = discoverPortal(obj1, obj2, ccd, &portal);
if (res < 0){
// Origin isn't inside portal - no collision.
return -1;
}else if (res == 1){
// Touching contact on portal's v1.
findPenetrTouch(obj1, obj2, ccd, &portal, depth, dir, pos);
}else if (res == 2){
// Origin lies on v0-v1 segment.
findPenetrSegment(obj1, obj2, ccd, &portal, depth, dir, pos);
}else if (res == 0){
// Phase 2: Portal refinement
res = refinePortal(obj1, obj2, ccd, &portal);
if (res < 0)
return -1;
// Phase 3. Penetration info
findPenetr(obj1, obj2, ccd, &portal, depth, dir, pos);
}
return 0;
}
_ccd_inline void findOrigin(const void *obj1, const void *obj2, const ccd_t *ccd,
ccd_support_t *center)
{
ccd->center1(obj1, ¢er->v1);
ccd->center2(obj2, ¢er->v2);
ccdVec3Sub2(¢er->v, ¢er->v1, ¢er->v2);
}
static int discoverPortal(const void *obj1, const void *obj2,
const ccd_t *ccd, ccd_simplex_t *portal)
{
ccd_vec3_t dir, va, vb;
ccd_real_t dot;
int cont;
// vertex 0 is center of portal
findOrigin(obj1, obj2, ccd, ccdSimplexPointW(portal, 0));
ccdSimplexSetSize(portal, 1);
if (ccdVec3Eq(&ccdSimplexPoint(portal, 0)->v, ccd_vec3_origin)){
// Portal's center lies on origin (0,0,0) => we know that objects
// intersect but we would need to know penetration info.
// So move center little bit...
ccdVec3Set(&va, CCD_EPS * CCD_REAL(10.), CCD_ZERO, CCD_ZERO);
ccdVec3Add(&ccdSimplexPointW(portal, 0)->v, &va);
}
// vertex 1 = support in direction of origin
ccdVec3Copy(&dir, &ccdSimplexPoint(portal, 0)->v);
ccdVec3Scale(&dir, CCD_REAL(-1.));
ccdVec3Normalize(&dir);
__ccdSupport(obj1, obj2, &dir, ccd, ccdSimplexPointW(portal, 1));
ccdSimplexSetSize(portal, 2);
// test if origin isn't outside of v1
dot = ccdVec3Dot(&ccdSimplexPoint(portal, 1)->v, &dir);
if (ccdIsZero(dot) || dot < CCD_ZERO)
return -1;
// vertex 2
ccdVec3Cross(&dir, &ccdSimplexPoint(portal, 0)->v,
&ccdSimplexPoint(portal, 1)->v);
if (ccdIsZero(ccdVec3Len2(&dir))){
if (ccdVec3Eq(&ccdSimplexPoint(portal, 1)->v, ccd_vec3_origin)){
// origin lies on v1
return 1;
}else{
// origin lies on v0-v1 segment
return 2;
}
}
ccdVec3Normalize(&dir);
__ccdSupport(obj1, obj2, &dir, ccd, ccdSimplexPointW(portal, 2));
dot = ccdVec3Dot(&ccdSimplexPoint(portal, 2)->v, &dir);
if (ccdIsZero(dot) || dot < CCD_ZERO)
return -1;
ccdSimplexSetSize(portal, 3);
// vertex 3 direction
ccdVec3Sub2(&va, &ccdSimplexPoint(portal, 1)->v,
&ccdSimplexPoint(portal, 0)->v);
ccdVec3Sub2(&vb, &ccdSimplexPoint(portal, 2)->v,
&ccdSimplexPoint(portal, 0)->v);
ccdVec3Cross(&dir, &va, &vb);
ccdVec3Normalize(&dir);
// it is better to form portal faces to be oriented "outside" origin
dot = ccdVec3Dot(&dir, &ccdSimplexPoint(portal, 0)->v);
if (dot > CCD_ZERO){
ccdSimplexSwap(portal, 1, 2);
ccdVec3Scale(&dir, CCD_REAL(-1.));
}
while (ccdSimplexSize(portal) < 4){
__ccdSupport(obj1, obj2, &dir, ccd, ccdSimplexPointW(portal, 3));
dot = ccdVec3Dot(&ccdSimplexPoint(portal, 3)->v, &dir);
if (ccdIsZero(dot) || dot < CCD_ZERO)
return -1;
cont = 0;
// test if origin is outside (v1, v0, v3) - set v2 as v3 and
// continue
ccdVec3Cross(&va, &ccdSimplexPoint(portal, 1)->v,
&ccdSimplexPoint(portal, 3)->v);
dot = ccdVec3Dot(&va, &ccdSimplexPoint(portal, 0)->v);
if (dot < CCD_ZERO && !ccdIsZero(dot)){
ccdSimplexSet(portal, 2, ccdSimplexPoint(portal, 3));
cont = 1;
}
if (!cont){
// test if origin is outside (v3, v0, v2) - set v1 as v3 and
// continue
ccdVec3Cross(&va, &ccdSimplexPoint(portal, 3)->v,
&ccdSimplexPoint(portal, 2)->v);
dot = ccdVec3Dot(&va, &ccdSimplexPoint(portal, 0)->v);
if (dot < CCD_ZERO && !ccdIsZero(dot)){
ccdSimplexSet(portal, 1, ccdSimplexPoint(portal, 3));
cont = 1;
}
}
if (cont){
ccdVec3Sub2(&va, &ccdSimplexPoint(portal, 1)->v,
&ccdSimplexPoint(portal, 0)->v);
ccdVec3Sub2(&vb, &ccdSimplexPoint(portal, 2)->v,
&ccdSimplexPoint(portal, 0)->v);
ccdVec3Cross(&dir, &va, &vb);
ccdVec3Normalize(&dir);
}else{
ccdSimplexSetSize(portal, 4);
}
}
return 0;
}
static int refinePortal(const void *obj1, const void *obj2,
const ccd_t *ccd, ccd_simplex_t *portal)
{
ccd_vec3_t dir;
ccd_support_t v4;
while (1){
// compute direction outside the portal (from v0 throught v1,v2,v3
// face)
portalDir(portal, &dir);
// test if origin is inside the portal
if (portalEncapsulesOrigin(portal, &dir))
return 0;
// get next support point
__ccdSupport(obj1, obj2, &dir, ccd, &v4);
// test if v4 can expand portal to contain origin and if portal
// expanding doesn't reach given tolerance
if (!portalCanEncapsuleOrigin(portal, &v4, &dir)
|| portalReachTolerance(portal, &v4, &dir, ccd)){
return -1;
}
// v1-v2-v3 triangle must be rearranged to face outside Minkowski
// difference (direction from v0).
expandPortal(portal, &v4);
}
return -1;
}
static void findPenetr(const void *obj1, const void *obj2, const ccd_t *ccd,
ccd_simplex_t *portal,
ccd_real_t *depth, ccd_vec3_t *pdir, ccd_vec3_t *pos)
{
ccd_vec3_t dir;
ccd_support_t v4;
unsigned long iterations;
iterations = 0UL;
while (1){
// compute portal direction and obtain next support point
portalDir(portal, &dir);
__ccdSupport(obj1, obj2, &dir, ccd, &v4);
// reached tolerance -> find penetration info
if (portalReachTolerance(portal, &v4, &dir, ccd)
|| iterations > ccd->max_iterations){
*depth = ccdVec3PointTriDist2(ccd_vec3_origin,
&ccdSimplexPoint(portal, 1)->v,
&ccdSimplexPoint(portal, 2)->v,
&ccdSimplexPoint(portal, 3)->v,
pdir);
*depth = CCD_SQRT(*depth);
if (ccdIsZero(*depth)){
// If depth is zero, then we have a touching contact.
// So following findPenetrTouch(), we assign zero to
// the direction vector (it can actually be anything
// according to the decription of ccdMPRPenetration
// function).
ccdVec3Copy(pdir, ccd_vec3_origin);
}else{
ccdVec3Normalize(pdir);
}
// barycentric coordinates:
findPos(obj1, obj2, ccd, portal, pos);
return;
}
expandPortal(portal, &v4);
iterations++;
}
}
static void findPenetrTouch(const void *obj1, const void *obj2, const ccd_t *ccd,
ccd_simplex_t *portal,
ccd_real_t *depth, ccd_vec3_t *dir, ccd_vec3_t *pos)
{
// Touching contact on portal's v1 - so depth is zero and direction
// is unimportant and pos can be guessed
*depth = CCD_REAL(0.);
ccdVec3Copy(dir, ccd_vec3_origin);
ccdVec3Copy(pos, &ccdSimplexPoint(portal, 1)->v1);
ccdVec3Add(pos, &ccdSimplexPoint(portal, 1)->v2);
ccdVec3Scale(pos, 0.5);
}
static void findPenetrSegment(const void *obj1, const void *obj2, const ccd_t *ccd,
ccd_simplex_t *portal,
ccd_real_t *depth, ccd_vec3_t *dir, ccd_vec3_t *pos)
{
/*
ccd_vec3_t vec;
ccd_real_t k;
*/
// Origin lies on v0-v1 segment.
// Depth is distance to v1, direction also and position must be
// computed
ccdVec3Copy(pos, &ccdSimplexPoint(portal, 1)->v1);
ccdVec3Add(pos, &ccdSimplexPoint(portal, 1)->v2);
ccdVec3Scale(pos, CCD_REAL(0.5));
/*
ccdVec3Sub2(&vec, &ccdSimplexPoint(portal, 1)->v,
&ccdSimplexPoint(portal, 0)->v);
k = CCD_SQRT(ccdVec3Len2(&ccdSimplexPoint(portal, 0)->v));
k /= CCD_SQRT(ccdVec3Len2(&vec));
ccdVec3Scale(&vec, -k);
ccdVec3Add(pos, &vec);
*/
ccdVec3Copy(dir, &ccdSimplexPoint(portal, 1)->v);
*depth = CCD_SQRT(ccdVec3Len2(dir));
ccdVec3Normalize(dir);
}
static void findPos(const void *obj1, const void *obj2, const ccd_t *ccd,
const ccd_simplex_t *portal, ccd_vec3_t *pos)
{
ccd_vec3_t dir;
size_t i;
ccd_real_t b[4], sum, inv;
ccd_vec3_t vec, p1, p2;
portalDir(portal, &dir);
// use barycentric coordinates of tetrahedron to find origin
ccdVec3Cross(&vec, &ccdSimplexPoint(portal, 1)->v,
&ccdSimplexPoint(portal, 2)->v);
b[0] = ccdVec3Dot(&vec, &ccdSimplexPoint(portal, 3)->v);
ccdVec3Cross(&vec, &ccdSimplexPoint(portal, 3)->v,
&ccdSimplexPoint(portal, 2)->v);
b[1] = ccdVec3Dot(&vec, &ccdSimplexPoint(portal, 0)->v);
ccdVec3Cross(&vec, &ccdSimplexPoint(portal, 0)->v,
&ccdSimplexPoint(portal, 1)->v);
b[2] = ccdVec3Dot(&vec, &ccdSimplexPoint(portal, 3)->v);
ccdVec3Cross(&vec, &ccdSimplexPoint(portal, 2)->v,
&ccdSimplexPoint(portal, 1)->v);
b[3] = ccdVec3Dot(&vec, &ccdSimplexPoint(portal, 0)->v);
sum = b[0] + b[1] + b[2] + b[3];
if (ccdIsZero(sum) || sum < CCD_ZERO){
b[0] = CCD_REAL(0.);
ccdVec3Cross(&vec, &ccdSimplexPoint(portal, 2)->v,
&ccdSimplexPoint(portal, 3)->v);
b[1] = ccdVec3Dot(&vec, &dir);
ccdVec3Cross(&vec, &ccdSimplexPoint(portal, 3)->v,
&ccdSimplexPoint(portal, 1)->v);
b[2] = ccdVec3Dot(&vec, &dir);
ccdVec3Cross(&vec, &ccdSimplexPoint(portal, 1)->v,
&ccdSimplexPoint(portal, 2)->v);
b[3] = ccdVec3Dot(&vec, &dir);
sum = b[1] + b[2] + b[3];
}
inv = CCD_REAL(1.) / sum;
ccdVec3Copy(&p1, ccd_vec3_origin);
ccdVec3Copy(&p2, ccd_vec3_origin);
for (i = 0; i < 4; i++){
ccdVec3Copy(&vec, &ccdSimplexPoint(portal, i)->v1);
ccdVec3Scale(&vec, b[i]);
ccdVec3Add(&p1, &vec);
ccdVec3Copy(&vec, &ccdSimplexPoint(portal, i)->v2);
ccdVec3Scale(&vec, b[i]);
ccdVec3Add(&p2, &vec);
}
ccdVec3Scale(&p1, inv);
ccdVec3Scale(&p2, inv);
ccdVec3Copy(pos, &p1);
ccdVec3Add(pos, &p2);
ccdVec3Scale(pos, 0.5);
}
_ccd_inline void expandPortal(ccd_simplex_t *portal,
const ccd_support_t *v4)
{
ccd_real_t dot;
ccd_vec3_t v4v0;
ccdVec3Cross(&v4v0, &v4->v, &ccdSimplexPoint(portal, 0)->v);
dot = ccdVec3Dot(&ccdSimplexPoint(portal, 1)->v, &v4v0);
if (dot > CCD_ZERO){
dot = ccdVec3Dot(&ccdSimplexPoint(portal, 2)->v, &v4v0);
if (dot > CCD_ZERO){
ccdSimplexSet(portal, 1, v4);
}else{
ccdSimplexSet(portal, 3, v4);
}
}else{
dot = ccdVec3Dot(&ccdSimplexPoint(portal, 3)->v, &v4v0);
if (dot > CCD_ZERO){
ccdSimplexSet(portal, 2, v4);
}else{
ccdSimplexSet(portal, 1, v4);
}
}
}
_ccd_inline void portalDir(const ccd_simplex_t *portal, ccd_vec3_t *dir)
{
ccd_vec3_t v2v1, v3v1;
ccdVec3Sub2(&v2v1, &ccdSimplexPoint(portal, 2)->v,
&ccdSimplexPoint(portal, 1)->v);
ccdVec3Sub2(&v3v1, &ccdSimplexPoint(portal, 3)->v,
&ccdSimplexPoint(portal, 1)->v);
ccdVec3Cross(dir, &v2v1, &v3v1);
ccdVec3Normalize(dir);
}
_ccd_inline int portalEncapsulesOrigin(const ccd_simplex_t *portal,
const ccd_vec3_t *dir)
{
ccd_real_t dot;
dot = ccdVec3Dot(dir, &ccdSimplexPoint(portal, 1)->v);
return ccdIsZero(dot) || dot > CCD_ZERO;
}
_ccd_inline int portalReachTolerance(const ccd_simplex_t *portal,
const ccd_support_t *v4,
const ccd_vec3_t *dir,
const ccd_t *ccd)
{
ccd_real_t dv1, dv2, dv3, dv4;
ccd_real_t dot1, dot2, dot3;
// find the smallest dot product of dir and {v1-v4, v2-v4, v3-v4}
dv1 = ccdVec3Dot(&ccdSimplexPoint(portal, 1)->v, dir);
dv2 = ccdVec3Dot(&ccdSimplexPoint(portal, 2)->v, dir);
dv3 = ccdVec3Dot(&ccdSimplexPoint(portal, 3)->v, dir);
dv4 = ccdVec3Dot(&v4->v, dir);
dot1 = dv4 - dv1;
dot2 = dv4 - dv2;
dot3 = dv4 - dv3;
dot1 = CCD_FMIN(dot1, dot2);
dot1 = CCD_FMIN(dot1, dot3);
return ccdEq(dot1, ccd->mpr_tolerance) || dot1 < ccd->mpr_tolerance;
}
_ccd_inline int portalCanEncapsuleOrigin(const ccd_simplex_t *portal,
const ccd_support_t *v4,
const ccd_vec3_t *dir)
{
ccd_real_t dot;
dot = ccdVec3Dot(&v4->v, dir);
return ccdIsZero(dot) || dot > CCD_ZERO;
}
================================================
FILE: src/polytope.c
================================================
/***
* 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.
*/
#include <stdio.h>
#include <float.h>
#include "polytope.h"
#include "alloc.h"
_ccd_inline void _ccdPtNearestUpdate(ccd_pt_t *pt, ccd_pt_el_t *el)
{
if (ccdEq(pt->nearest_dist, el->dist)){
if (el->type < pt->nearest_type){
pt->nearest = el;
pt->nearest_dist = el->dist;
pt->nearest_type = el->type;
}
}else if (el->dist < pt->nearest_dist){
pt->nearest = el;
pt->nearest_dist = el->dist;
pt->nearest_type = el->type;
}
}
static void _ccdPtNearestRenew(ccd_pt_t *pt)
{
ccd_pt_vertex_t *v;
ccd_pt_edge_t *e;
ccd_pt_face_t *f;
pt->nearest_dist = CCD_REAL_MAX;
pt->nearest_type = 3;
pt->nearest = NULL;
ccdListForEachEntry(&pt->vertices, v, ccd_pt_vertex_t, list){
_ccdPtNearestUpdate(pt, (ccd_pt_el_t *)v);
}
ccdListForEachEntry(&pt->edges, e, ccd_pt_edge_t, list){
_ccdPtNearestUpdate(pt, (ccd_pt_el_t *)e);
}
ccdListForEachEntry(&pt->faces, f, ccd_pt_face_t, list){
_ccdPtNearestUpdate(pt, (ccd_pt_el_t *)f);
}
}
void ccdPtInit(ccd_pt_t *pt)
{
ccdListInit(&pt->vertices);
ccdListInit(&pt->edges);
ccdListInit(&pt->faces);
pt->nearest = NULL;
pt->nearest_dist = CCD_REAL_MAX;
pt->nearest_type = 3;
}
void ccdPtDestroy(ccd_pt_t *pt)
{
ccd_pt_face_t *f, *f2;
ccd_pt_edge_t *e, *e2;
ccd_pt_vertex_t *v, *v2;
// first delete all faces
ccdListForEachEntrySafe(&pt->faces, f, ccd_pt_face_t, f2, ccd_pt_face_t, list){
ccdPtDelFace(pt, f);
}
// delete all edges
ccdListForEachEntrySafe(&pt->edges, e, ccd_pt_edge_t, e2, ccd_pt_edge_t, list){
ccdPtDelEdge(pt, e);
}
// delete all vertices
ccdListForEachEntrySafe(&pt->vertices, v, ccd_pt_vertex_t, v2, ccd_pt_vertex_t, list){
ccdPtDelVertex(pt, v);
}
}
ccd_pt_vertex_t *ccdPtAddVertex(ccd_pt_t *pt, const ccd_support_t *v)
{
ccd_pt_vertex_t *vert;
vert = CCD_ALLOC(ccd_pt_vertex_t);
if (vert == NULL)
return NULL;
vert->type = CCD_PT_VERTEX;
ccdSupportCopy(&vert->v, v);
vert->dist = ccdVec3Len2(&vert->v.v);
ccdVec3Copy(&vert->witness, &vert->v.v);
ccdListInit(&vert->edges);
// add vertex to list
ccdListAppend(&pt->vertices, &vert->list);
// update position in .nearest array
_ccdPtNearestUpdate(pt, (ccd_pt_el_t *)vert);
return vert;
}
ccd_pt_edge_t *ccdPtAddEdge(ccd_pt_t *pt, ccd_pt_vertex_t *v1,
ccd_pt_vertex_t *v2)
{
const ccd_vec3_t *a, *b;
ccd_pt_edge_t *edge;
if (v1 == NULL || v2 == NULL)
return NULL;
edge = CCD_ALLOC(ccd_pt_edge_t);
if (edge == NULL)
return NULL;
edge->type = CCD_PT_EDGE;
edge->vertex[0] = v1;
edge->vertex[1] = v2;
edge->faces[0] = edge->faces[1] = NULL;
a = &edge->vertex[0]->v.v;
b = &edge->vertex[1]->v.v;
edge->dist = ccdVec3PointSegmentDist2(ccd_vec3_origin, a, b, &edge->witness);
ccdListAppend(&edge->vertex[0]->edges, &edge->vertex_list[0]);
ccdListAppend(&edge->vertex[1]->edges, &edge->vertex_list[1]);
ccdListAppend(&pt->edges, &edge->list);
// update position in .nearest array
_ccdPtNearestUpdate(pt, (ccd_pt_el_t *)edge);
return edge;
}
ccd_pt_face_t *ccdPtAddFace(ccd_pt_t *pt, ccd_pt_edge_t *e1,
ccd_pt_edge_t *e2,
ccd_pt_edge_t *e3)
{
const ccd_vec3_t *a, *b, *c;
ccd_pt_face_t *face;
ccd_pt_edge_t *e;
size_t i;
if (e1 == NULL || e2 == NULL || e3 == NULL)
return NULL;
face = CCD_ALLOC(ccd_pt_face_t);
if (face == NULL)
return NULL;
face->type = CCD_PT_FACE;
face->edge[0] = e1;
face->edge[1] = e2;
face->edge[2] = e3;
// obtain triplet of vertices
a = &face->edge[0]->vertex[0]->v.v;
b = &face->edge[0]->vertex[1]->v.v;
e = face->edge[1];
if (e->vertex[0] != face->edge[0]->vertex[0]
&& e->vertex[0] != face->edge[0]->vertex[1]){
c = &e->vertex[0]->v.v;
}else{
c = &e->vertex[1]->v.v;
}
face->dist = ccdVec3PointTriDist2(ccd_vec3_origin, a, b, c, &face->witness);
for (i = 0; i < 3; i++){
if (face->edge[i]->faces[0] == NULL){
face->edge[i]->faces[0] = face;
}else{
face->edge[i]->faces[1] = face;
}
}
ccdListAppend(&pt->faces, &face->list);
// update position in .nearest array
_ccdPtNearestUpdate(pt, (ccd_pt_el_t *)face);
return face;
}
void ccdPtRecomputeDistances(ccd_pt_t *pt)
{
ccd_pt_vertex_t *v;
ccd_pt_edge_t *e;
ccd_pt_face_t *f;
const ccd_vec3_t *a, *b, *c;
ccd_real_t dist;
ccdListForEachEntry(&pt->vertices, v, ccd_pt_vertex_t, list){
dist = ccdVec3Len2(&v->v.v);
v->dist = dist;
ccdVec3Copy(&v->witness, &v->v.v);
}
ccdListForEachEntry(&pt->edges, e, ccd_pt_edge_t, list){
a = &e->vertex[0]->v.v;
b = &e->vertex[1]->v.v;
dist = ccdVec3PointSegmentDist2(ccd_vec3_origin, a, b, &e->witness);
e->dist = dist;
}
ccdListForEachEntry(&pt->faces, f, ccd_pt_face_t, list){
// obtain triplet of vertices
a = &f->edge[0]->vertex[0]->v.v;
b = &f->edge[0]->vertex[1]->v.v;
e = f->edge[1];
if (e->vertex[0] != f->edge[0]->vertex[0]
&& e->vertex[0] != f->edge[0]->vertex[1]){
c = &e->vertex[0]->v.v;
}else{
c = &e->vertex[1]->v.v;
}
dist = ccdVec3PointTriDist2(ccd_vec3_origin, a, b, c, &f->witness);
f->dist = dist;
}
}
ccd_pt_el_t *ccdPtNearest(ccd_pt_t *pt)
{
if (!pt->nearest){
_ccdPtNearestRenew(pt);
}
return pt->nearest;
}
void ccdPtDumpSVT(ccd_pt_t *pt, const char *fn)
{
FILE *fout;
fout = fopen(fn, "a");
if (fout == NULL)
return;
ccdPtDumpSVT2(pt, fout);
fclose(fout);
}
void ccdPtDumpSVT2(ccd_pt_t *pt, FILE *fout)
{
ccd_pt_vertex_t *v, *a, *b, *c;
ccd_pt_edge_t *e;
ccd_pt_face_t *f;
size_t i;
fprintf(fout, "-----\n");
fprintf(fout, "Points:\n");
i = 0;
ccdListForEachEntry(&pt->vertices, v, ccd_pt_vertex_t, list){
v->id = i++;
fprintf(fout, "%lf %lf %lf\n",
ccdVec3X(&v->v.v), ccdVec3Y(&v->v.v), ccdVec3Z(&v->v.v));
}
fprintf(fout, "Edges:\n");
ccdListForEachEntry(&pt->edges, e, ccd_pt_edge_t, list){
fprintf(fout, "%d %d\n", e->vertex[0]->id, e->vertex[1]->id);
}
fprintf(fout, "Faces:\n");
ccdListForEachEntry(&pt->faces, f, ccd_pt_face_t, list){
a = f->edge[0]->vertex[0];
b = f->edge[0]->vertex[1];
c = f->edge[1]->vertex[0];
if (c == a || c == b){
c = f->edge[1]->vertex[1];
}
fprintf(fout, "%d %d %d\n", a->id, b->id, c->id);
}
}
================================================
FILE: src/polytope.h
================================================
/***
* 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_POLYTOPE_H__
#define __CCD_POLYTOPE_H__
#include <stdlib.h>
#include <stdio.h>
#include "support.h"
#include "list.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#define CCD_PT_VERTEX 1
#define CCD_PT_EDGE 2
#define CCD_PT_FACE 3
#define __CCD_PT_EL \
int type; /*! type of element */ \
ccd_real_t dist; /*! distance from origin */ \
ccd_vec3_t witness; /*! witness point of projection of origin */ \
ccd_list_t list; /*! list of elements of same type */
/**
* General polytope element.
* Could be vertex, edge or triangle.
*/
struct _ccd_pt_el_t {
__CCD_PT_EL
};
typedef struct _ccd_pt_el_t ccd_pt_el_t;
struct _ccd_pt_edge_t;
struct _ccd_pt_face_t;
/**
* Polytope's vertex.
*/
struct _ccd_pt_vertex_t {
__CCD_PT_EL
int id;
ccd_support_t v;
ccd_list_t edges; //!< List of edges
};
typedef struct _ccd_pt_vertex_t ccd_pt_vertex_t;
/**
* Polytope's edge.
*/
struct _ccd_pt_edge_t {
__CCD_PT_EL
ccd_pt_vertex_t *vertex[2]; //!< Reference to vertices
struct _ccd_pt_face_t *faces[2]; //!< Reference to faces
ccd_list_t vertex_list[2]; //!< List items in vertices' lists
};
typedef struct _ccd_pt_edge_t ccd_pt_edge_t;
/**
* Polytope's triangle faces.
*/
struct _ccd_pt_face_t {
__CCD_PT_EL
ccd_pt_edge_t *edge[3]; //!< Reference to surrounding edges
};
typedef struct _ccd_pt_face_t ccd_pt_face_t;
/**
* Struct containing polytope.
*/
struct _ccd_pt_t {
ccd_list_t vertices; //!< List of vertices
ccd_list_t edges; //!< List of edges
ccd_list_t faces; //!< List of faces
ccd_pt_el_t *nearest;
ccd_real_t nearest_dist;
int nearest_type;
};
typedef struct _ccd_pt_t ccd_pt_t;
CCD_EXPORT void ccdPtInit(ccd_pt_t *pt);
CCD_EXPORT void ccdPtDestroy(ccd_pt_t *pt);
/**
* Returns vertices surrounding given triangle face.
*/
_ccd_inline void ccdPtFaceVec3(const ccd_pt_face_t *face,
ccd_vec3_t **a,
ccd_vec3_t **b,
ccd_vec3_t **c);
_ccd_inline void ccdPtFaceVertices(const ccd_pt_face_t *face,
ccd_pt_vertex_t **a,
ccd_pt_vertex_t **b,
ccd_pt_vertex_t **c);
_ccd_inline void ccdPtFaceEdges(const ccd_pt_face_t *f,
ccd_pt_edge_t **a,
ccd_pt_edge_t **b,
ccd_pt_edge_t **c);
_ccd_inline void ccdPtEdgeVec3(const ccd_pt_edge_t *e,
ccd_vec3_t **a,
ccd_vec3_t **b);
_ccd_inline void ccdPtEdgeVertices(const ccd_pt_edge_t *e,
ccd_pt_vertex_t **a,
ccd_pt_vertex_t **b);
_ccd_inline void ccdPtEdgeFaces(const ccd_pt_edge_t *e,
ccd_pt_face_t **f1,
ccd_pt_face_t **f2);
/**
* Adds vertex to polytope and returns pointer to newly created vertex.
*/
CCD_EXPORT ccd_pt_vertex_t *ccdPtAddVertex(ccd_pt_t *pt, const ccd_support_t *v);
_ccd_inline ccd_pt_vertex_t *ccdPtAddVertexCoords(ccd_pt_t *pt,
ccd_real_t x, ccd_real_t y, ccd_real_t z);
/**
* Adds edge to polytope.
*/
CCD_EXPORT ccd_pt_edge_t *ccdPtAddEdge(ccd_pt_t *pt, ccd_pt_vertex_t *v1,
ccd_pt_vertex_t *v2);
/**
* Adds face to polytope.
*/
CCD_EXPORT ccd_pt_face_t *ccdPtAddFace(ccd_pt_t *pt, ccd_pt_edge_t *e1,
ccd_pt_edge_t *e2,
ccd_pt_edge_t *e3);
/**
* Deletes vertex from polytope.
* Returns 0 on success, -1 otherwise.
*/
_ccd_inline int ccdPtDelVertex(ccd_pt_t *pt, ccd_pt_vertex_t *);
_ccd_inline int ccdPtDelEdge(ccd_pt_t *pt, ccd_pt_edge_t *);
_ccd_inline int ccdPtDelFace(ccd_pt_t *pt, ccd_pt_face_t *);
/**
* Recompute distances from origin for all elements in pt.
*/
CCD_EXPORT void ccdPtRecomputeDistances(ccd_pt_t *pt);
/**
* Returns nearest element to origin.
*/
CCD_EXPORT ccd_pt_el_t *ccdPtNearest(ccd_pt_t *pt);
CCD_EXPORT void ccdPtDumpSVT(ccd_pt_t *pt, const char *fn);
CCD_EXPORT void ccdPtDumpSVT2(ccd_pt_t *pt, FILE *);
/**** INLINES ****/
_ccd_inline ccd_pt_vertex_t *ccdPtAddVertexCoords(ccd_pt_t *pt,
ccd_real_t x, ccd_real_t y, ccd_real_t z)
{
ccd_support_t s;
ccdVec3Set(&s.v, x, y, z);
return ccdPtAddVertex(pt, &s);
}
_ccd_inline int ccdPtDelVertex(ccd_pt_t *pt, ccd_pt_vertex_t *v)
{
// test if any edge is connected to this vertex
if (!ccdListEmpty(&v->edges))
return -1;
// delete vertex from main list
ccdListDel(&v->list);
if ((void *)pt->nearest == (void *)v){
pt->nearest = NULL;
}
free(v);
return 0;
}
_ccd_inline int ccdPtDelEdge(ccd_pt_t *pt, ccd_pt_edge_t *e)
{
// text if any face is connected to this edge (faces[] is always
// aligned to lower indices)
if (e->faces[0] != NULL)
return -1;
// disconnect edge from lists of edges in vertex struct
ccdListDel(&e->vertex_list[0]);
ccdListDel(&e->vertex_list[1]);
// disconnect edge from main list
ccdListDel(&e->list);
if ((void *)pt->nearest == (void *)e){
pt->nearest = NULL;
}
free(e);
return 0;
}
_ccd_inline int ccdPtDelFace(ccd_pt_t *pt, ccd_pt_face_t *f)
{
ccd_pt_edge_t *e;
size_t i;
// remove face from edges' recerence lists
for (i = 0; i < 3; i++){
e = f->edge[i];
if (e->faces[0] == f){
e->faces[0] = e->faces[1];
}
e->faces[1] = NULL;
}
// remove face from list of all faces
ccdListDel(&f->list);
if ((void *)pt->nearest == (void *)f){
pt->nearest = NULL;
}
free(f);
return 0;
}
_ccd_inline void ccdPtFaceVec3(const ccd_pt_face_t *face,
ccd_vec3_t **a,
ccd_vec3_t **b,
ccd_vec3_t **c)
{
*a = &face->edge[0]->vertex[0]->v.v;
*b = &face->edge[0]->vertex[1]->v.v;
if (face->edge[1]->vertex[0] != face->edge[0]->vertex[0]
&& face->edge[1]->vertex[0] != face->edge[0]->vertex[1]){
*c = &face->edge[1]->vertex[0]->v.v;
}else{
*c = &face->edge[1]->vertex[1]->v.v;
}
}
_ccd_inline void ccdPtFaceVertices(const ccd_pt_face_t *face,
ccd_pt_vertex_t **a,
ccd_pt_vertex_t **b,
ccd_pt_vertex_t **c)
{
*a = face->edge[0]->vertex[0];
*b = face->edge[0]->vertex[1];
if (face->edge[1]->vertex[0] != face->edge[0]->vertex[0]
&& face->edge[1]->vertex[0] != face->edge[0]->vertex[1]){
*c = face->edge[1]->vertex[0];
}else{
*c = face->edge[1]->vertex[1];
}
}
_ccd_inline void ccdPtFaceEdges(const ccd_pt_face_t *f,
ccd_pt_edge_t **a,
ccd_pt_edge_t **b,
ccd_pt_edge_t **c)
{
*a = f->edge[0];
*b = f->edge[1];
*c = f->edge[2];
}
_ccd_inline void ccdPtEdgeVec3(const ccd_pt_edge_t *e,
ccd_vec3_t **a,
ccd_vec3_t **b)
{
*a = &e->vertex[0]->v.v;
*b = &e->vertex[1]->v.v;
}
_ccd_inline void ccdPtEdgeVertices(const ccd_pt_edge_t *e,
ccd_pt_vertex_t **a,
ccd_pt_vertex_t **b)
{
*a = e->vertex[0];
*b = e->vertex[1];
}
_ccd_inline void ccdPtEdgeFaces(const ccd_pt_edge_t *e,
ccd_pt_face_t **f1,
ccd_pt_face_t **f2)
{
*f1 = e->faces[0];
*f2 = e->faces[1];
}
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
#endif /* __CCD_POLYTOPE_H__ */
================================================
FILE: src/simplex.h
================================================
/***
* 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_SIMPLEX_H__
#define __CCD_SIMPLEX_H__
#include <ccd/compiler.h>
#include "support.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
struct _ccd_simplex_t {
ccd_support_t ps[4];
int last; //!< index of last added point
};
typedef struct _ccd_simplex_t ccd_simplex_t;
_ccd_inline void ccdSimplexInit(ccd_simplex_t *s);
_ccd_inline int ccdSimplexSize(const ccd_simplex_t *s);
_ccd_inline const ccd_support_t *ccdSimplexLast(const ccd_simplex_t *s);
_ccd_inline const ccd_support_t *ccdSimplexPoint(const ccd_simplex_t *s, int idx);
_ccd_inline ccd_support_t *ccdSimplexPointW(ccd_simplex_t *s, int idx);
_ccd_inline void ccdSimplexAdd(ccd_simplex_t *s, const ccd_support_t *v);
_ccd_inline void ccdSimplexSet(ccd_simplex_t *s, size_t pos, const ccd_support_t *a);
_ccd_inline void ccdSimplexSetSize(ccd_simplex_t *s, int size);
_ccd_inline void ccdSimplexSwap(ccd_simplex_t *s, size_t pos1, size_t pos2);
/**** INLINES ****/
_ccd_inline void ccdSimplexInit(ccd_simplex_t *s)
{
s->last = -1;
}
_ccd_inline int ccdSimplexSize(const ccd_simplex_t *s)
{
return s->last + 1;
}
_ccd_inline const ccd_support_t *ccdSimplexLast(const ccd_simplex_t *s)
{
return ccdSimplexPoint(s, s->last);
}
_ccd_inline const ccd_support_t *ccdSimplexPoint(const ccd_simplex_t *s, int idx)
{
// here is no check on boundaries
return &s->ps[idx];
}
_ccd_inline ccd_support_t *ccdSimplexPointW(ccd_simplex_t *s, int idx)
{
return &s->ps[idx];
}
_ccd_inline void ccdSimplexAdd(ccd_simplex_t *s, const ccd_support_t *v)
{
// here is no check on boundaries in sake of speed
++s->last;
ccdSupportCopy(s->ps + s->last, v);
}
_ccd_inline void ccdSimplexSet(ccd_simplex_t *s, size_t pos, const ccd_support_t *a)
{
ccdSupportCopy(s->ps + pos, a);
}
_ccd_inline void ccdSimplexSetSize(ccd_simplex_t *s, int size)
{
s->last = size - 1;
}
_ccd_inline void ccdSimplexSwap(ccd_simplex_t *s, size_t pos1, size_t pos2)
{
ccd_support_t supp;
ccdSupportCopy(&supp, &s->ps[pos1]);
ccdSupportCopy(&s->ps[pos1], &s->ps[pos2]);
ccdSupportCopy(&s->ps[pos2], &supp);
}
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
#endif /* __CCD_SIMPLEX_H__ */
================================================
FILE: src/support.c
================================================
/***
* 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.
*/
#include "support.h"
void __ccdSupport(const void *obj1, const void *obj2,
const ccd_vec3_t *_dir, const ccd_t *ccd,
ccd_support_t *supp)
{
ccd_vec3_t dir;
ccdVec3Copy(&dir, _dir);
ccd->support1(obj1, &dir, &supp->v1);
ccdVec3Scale(&dir, -CCD_ONE);
ccd->support2(obj2, &dir, &supp->v2);
ccdVec3Sub2(&supp->v, &supp->v1, &supp->v2);
}
================================================
FILE: src/support.h
================================================
/***
* 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_SUPPORT_H__
#define __CCD_SUPPORT_H__
#include <ccd/ccd.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
struct _ccd_support_t {
ccd_vec3_t v; //!< Support point in minkowski sum
ccd_vec3_t v1; //!< Support point in obj1
ccd_vec3_t v2; //!< Support point in obj2
};
typedef struct _ccd_support_t ccd_support_t;
_ccd_inline void ccdSupportCopy(ccd_support_t *, const ccd_support_t *s);
/**
* Computes support point of obj1 and obj2 in direction dir.
* Support point is returned via supp.
*/
CCD_EXPORT void __ccdSupport(const void *obj1, const void *obj2,
const ccd_vec3_t *dir, const ccd_t *ccd,
ccd_support_t *supp);
/**** INLINES ****/
_ccd_inline void ccdSupportCopy(ccd_support_t *d, const ccd_support_t *s)
{
*d = *s;
}
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
#endif /* __CCD_SUPPORT_H__ */
================================================
FILE: src/testsuites/.gitignore
================================================
regressions/tmp.*
bench-out/*
*.o
test
bench
bench2
================================================
FILE: src/testsuites/CMakeLists.txt
================================================
add_subdirectory(cu)
set(MAIN_SOURCES
main.c
common.c
common.h
support.c
support.h
vec3.c
vec3.h
polytope.c
polytope.h
boxbox.c
boxbox.h
spheresphere.c
spheresphere.h
cylcyl.c
cylcyl.h
boxcyl.c
boxcyl.h
mpr_boxbox.c
mpr_boxbox.h
mpr_cylcyl.c
mpr_cylcyl.h
mpr_boxcyl.c
mpr_boxcyl.h
support.c
support.h)
add_executable(main ${MAIN_SOURCES})
target_link_libraries(main ccd cu)
add_test(NAME main COMMAND main)
if(NOT APPLE)
set(BENCH_SOURCES
bench.c
support.c
support.h)
add_executable(bench ${BENCH_SOURCES})
target_link_libraries(bench ccd cu)
add_test(NAME bench COMMAND bench)
set(BENCH2_SOURCES
bench2.c
support.c
support.h)
add_executable(bench2 ${BENCH2_SOURCES})
target_link_libraries(bench2 ccd cu)
add_test(NAME bench2 COMMAND bench2)
endif()
================================================
FILE: src/testsuites/Makefile
================================================
# force some options
DEBUG = yes
-include ../Makefile.include
CFLAGS += -I./ -I../ -Icu/
LDFLAGS += -L./ -Lcu/ -lcu -lrt -lm -L../ -lccd
CHECK_REG=cu/check-regressions
CHECK_TS ?=
OBJS = common.o support.o vec3.o polytope.o boxbox.o spheresphere.o \
cylcyl.o boxcyl.o mpr_boxbox.o mpr_cylcyl.o mpr_boxcyl.o
BENCH_OBJS = bench-boxbox.o
all: test bench bench2
test: cu $(OBJS) main.c
$(CC) $(CFLAGS) -o $@ main.c $(OBJS) $(LDFLAGS)
bench: cu bench.c support.o
$(CC) $(CFLAGS) -o $@ bench.c support.o $(LDFLAGS)
bench2: cu bench2.c support.o
$(CC) $(CFLAGS) -o $@ bench2.c support.o $(LDFLAGS)
%.o: %.c %.h
$(CC) $(CFLAGS) -c -o $@ $<
%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<
check: all
@echo ""
@echo "----------------------------------------";
./test $(CHECK_TS)
@echo "----------------------------------------";
@echo "Checking regressions:";
$(PYTHON) $(CHECK_REG) regressions
@echo ""
check-valgrind: all
valgrind -q --leak-check=full --show-reachable=yes --trace-children=yes \
--error-limit=no \
./test $(CHECK_TS)
check-valgrind-gen-suppressions: all
valgrind -q --leak-check=full --show-reachable=yes --trace-children=yes \
--gen-suppressions=all --log-file=out --error-limit=no \
./test $(CHECK_TS)
cu:
$(MAKE) ENABLE_TIMER=yes -C cu/
clean:
rm -f *.o
rm -f objs/*.o
rm -f test bench bench2
rm -f tmp.*
rm -f regressions/tmp.*
.PHONY: all clean check check-valgrind cu
================================================
FILE: src/testsuites/Makefile.am
================================================
SUBDIRS = cu
AM_CPPFLAGS = -I $(srcdir)/.. -I $(builddir)/.. -I $(srcdir)/cu
LDADD = $(builddir)/cu/libcu.la $(builddir)/../libccd.la
check_PROGRAMS = test bench bench2
test_SOURCES = main.c \
common.c common.h \
support.c support.h \
vec3.c vec3.h \
polytope.c polytope.h \
boxbox.c boxbox.h \
spheresphere.c spheresphere.h \
cylcyl.c cylcyl.h \
boxcyl.c boxcyl.h \
mpr_boxbox.c mpr_boxbox.h \
mpr_cylcyl.c mpr_cylcyl.h \
mpr_boxcyl.c mpr_boxcyl.h
bench_SOURCES = bench.c \
support.c support.h
bench2_SOURCES = bench2.c \
support.c support.h
================================================
FILE: src/testsuites/bench.c
================================================
#define CU_ENABLE_TIMER
#include <cu/cu.h>
#include <stdio.h>
#include <stdlib.h>
#include <ccd/ccd.h>
#include "support.h"
TEST_SUITES {
TEST_SUITES_CLOSURE
};
static int bench_num = 1;
static size_t cycles = 10000;
static void runBench(const void *o1, const void *o2, const ccd_t *ccd)
{
ccd_real_t depth;
ccd_vec3_t dir, pos;
size_t i;
const struct timespec *timer;
cuTimerStart();
for (i = 0; i < cycles; i++){
ccdGJKPenetration(o1, o2, ccd, &depth, &dir, &pos);
}
timer = cuTimerStop();
fprintf(stdout, "%02d: %ld %ld\n", bench_num,
(long)timer->tv_sec, (long)timer->tv_nsec);
fflush(stdout);
bench_num++;
}
static void boxbox(void)
{
fprintf(stdout, "%s:\n", __func__);
ccd_t ccd;
CCD_BOX(box1);
CCD_BOX(box2);
ccd_vec3_t axis;
ccd_quat_t rot;
box1.x = box1.y = box1.z = 1.;
box2.x = 0.5;
box2.y = 1.;
box2.z = 1.5;
bench_num = 1;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
runBench(&box1, &box2, &ccd);
runBench(&box2, &box1, &ccd);
ccdVec3Set(&box1.pos, -0.3, 0.5, 1.);
runBench(&box1, &box2, &ccd);
runBench(&box2, &box1, &ccd);
box1.x = box1.y = box1.z = 1.;
box2.x = box2.y = box2.z = 1.;
ccdVec3Set(&axis, 0., 0., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&box1.pos, 0., 0., 0.);
runBench(&box1, &box2, &ccd);
runBench(&box2, &box1, &ccd);
box1.x = box1.y = box1.z = 1.;
box2.x = box2.y = box2.z = 1.;
ccdVec3Set(&axis, 0., 0., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&box1.pos, -0.5, 0., 0.);
runBench(&box1, &box2, &ccd);
runBench(&box2, &box1, &ccd);
box1.x = box1.y = box1.z = 1.;
box2.x = box2.y = box2.z = 1.;
ccdVec3Set(&axis, 0., 0., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&box1.pos, -0.5, 0.5, 0.);
runBench(&box1, &box2, &ccd);
runBench(&box2, &box1, &ccd);
box1.x = box1.y = box1.z = 1.;
ccdVec3Set(&axis, 0., 1., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&box1.pos, -0.5, 0.1, 0.4);
runBench(&box1, &box2, &ccd);
runBench(&box2, &box1, &ccd);
box1.x = box1.y = box1.z = 1.;
ccdVec3Set(&axis, 0., 1., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&axis, 1., 1., 1.);
ccdQuatSetAngleAxis(&rot, M_PI / 4., &axis);
ccdQuatMul(&box1.quat, &rot);
ccdVec3Set(&box1.pos, -0.5, 0.1, 0.4);
runBench(&box1, &box2, &ccd);
runBench(&box2, &box1, &ccd);
box1.x = box1.y = box1.z = 1.;
box2.x = 0.2; box2.y = 0.5; box2.z = 1.;
box2.x = box2.y = box2.z = 1.;
ccdVec3Set(&axis, 0., 0., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&axis, 1., 0., 0.);
ccdQuatSetAngleAxis(&rot, M_PI / 4., &axis);
ccdQuatMul(&box1.quat, &rot);
ccdVec3Set(&box1.pos, -1.3, 0., 0.);
ccdVec3Set(&box2.pos, 0., 0., 0.);
runBench(&box1, &box2, &ccd);
runBench(&box2, &box1, &ccd);
fprintf(stdout, "\n----\n\n");
}
void cylcyl(void)
{
fprintf(stdout, "%s:\n", __func__);
ccd_t ccd;
CCD_CYL(cyl1);
CCD_CYL(cyl2);
ccd_vec3_t axis;
cyl1.radius = 0.35;
cyl1.height = 0.5;
cyl2.radius = 0.5;
cyl2.height = 1.;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
runBench(&cyl1, &cyl2, &ccd);
runBench(&cyl2, &cyl1, &ccd);
ccdVec3Set(&cyl1.pos, 0.3, 0.1, 0.1);
runBench(&cyl1, &cyl2, &ccd);
runBench(&cyl2, &cyl1, &ccd);
ccdVec3Set(&axis, 0., 1., 1.);
ccdQuatSetAngleAxis(&cyl2.quat, M_PI / 4., &axis);
ccdVec3Set(&cyl2.pos, 0., 0., 0.);
runBench(&cyl1, &cyl2, &ccd);
runBench(&cyl2, &cyl1, &ccd);
ccdVec3Set(&axis, 0., 1., 1.);
ccdQuatSetAngleAxis(&cyl2.quat, M_PI / 4., &axis);
ccdVec3Set(&cyl2.pos, -0.2, 0.7, 0.2);
runBench(&cyl1, &cyl2, &ccd);
runBench(&cyl2, &cyl1, &ccd);
ccdVec3Set(&axis, 0.567, 1.2, 1.);
ccdQuatSetAngleAxis(&cyl2.quat, M_PI / 4., &axis);
ccdVec3Set(&cyl2.pos, 0.6, -0.7, 0.2);
runBench(&cyl1, &cyl2, &ccd);
runBench(&cyl2, &cyl1, &ccd);
ccdVec3Set(&axis, -4.567, 1.2, 0.);
ccdQuatSetAngleAxis(&cyl2.quat, M_PI / 3., &axis);
ccdVec3Set(&cyl2.pos, 0.6, -0.7, 0.2);
runBench(&cyl1, &cyl2, &ccd);
runBench(&cyl2, &cyl1, &ccd);
fprintf(stdout, "\n----\n\n");
}
void boxcyl(void)
{
fprintf(stdout, "%s:\n", __func__);
ccd_t ccd;
CCD_BOX(box);
CCD_CYL(cyl);
ccd_vec3_t axis;
box.x = 0.5;
box.y = 1.;
box.z = 1.5;
cyl.radius = 0.4;
cyl.height = 0.7;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
runBench(&box, &cyl, &ccd);
runBench(&cyl, &box, &ccd);
ccdVec3Set(&cyl.pos, .6, 0., 0.);
runBench(&box, &cyl, &ccd);
runBench(&cyl, &box, &ccd);
ccdVec3Set(&cyl.pos, .6, 0.6, 0.);
runBench(&box, &cyl, &ccd);
runBench(&cyl, &box, &ccd);
ccdVec3Set(&cyl.pos, .6, 0.6, 0.5);
runBench(&box, &cyl, &ccd);
runBench(&cyl, &box, &ccd);
ccdVec3Set(&axis, 0., 1., 0.);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 3., &axis);
ccdVec3Set(&cyl.pos, .6, 0.6, 0.5);
runBench(&box, &cyl, &ccd);
runBench(&cyl, &box, &ccd);
ccdVec3Set(&axis, 0.67, 1.1, 0.12);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 4., &axis);
ccdVec3Set(&cyl.pos, .6, 0., 0.5);
runBench(&box, &cyl, &ccd);
runBench(&cyl, &box, &ccd);
ccdVec3Set(&axis, -0.1, 2.2, -1.);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 5., &axis);
ccdVec3Set(&cyl.pos, .6, 0., 0.5);
ccdVec3Set(&axis, 1., 1., 0.);
ccdQuatSetAngleAxis(&box.quat, -M_PI / 4., &axis);
ccdVec3Set(&box.pos, .6, 0., 0.5);
runBench(&box, &cyl, &ccd);
runBench(&cyl, &box, &ccd);
ccdVec3Set(&axis, -0.1, 2.2, -1.);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 5., &axis);
ccdVec3Set(&cyl.pos, .6, 0., 0.5);
ccdVec3Set(&axis, 1., 1., 0.);
ccdQuatSetAngleAxis(&box.quat, -M_PI / 4., &axis);
ccdVec3Set(&box.pos, .9, 0.8, 0.5);
runBench(&box, &cyl, &ccd);
runBench(&cyl, &box, &ccd);
fprintf(stdout, "\n----\n\n");
}
int main(int argc, char *argv[])
{
if (argc > 1){
cycles = atol(argv[1]);
}
fprintf(stdout, "Cycles: %u\n", (unsigned int)cycles);
fprintf(stdout, "\n");
boxbox();
cylcyl();
boxcyl();
return 0;
}
================================================
FILE: src/testsuites/bench2.c
================================================
#define CU_ENABLE_TIMER
#include <cu/cu.h>
#include <stdio.h>
#include <stdlib.h>
#include <ccd/ccd.h>
#include "support.h"
TEST_SUITES {
TEST_SUITES_CLOSURE
};
static int bench_num = 1;
static size_t cycles = 10000;
static void runBench(const void *o1, const void *o2, const ccd_t *ccd)
{
ccd_real_t depth;
ccd_vec3_t dir, pos;
size_t i;
const struct timespec *timer;
cuTimerStart();
for (i = 0; i < cycles; i++){
ccdMPRPenetration(o1, o2, ccd, &depth, &dir, &pos);
}
timer = cuTimerStop();
fprintf(stdout, "%02d: %ld %ld\n", bench_num,
(long)timer->tv_sec, (long)timer->tv_nsec);
fflush(stdout);
bench_num++;
}
static void boxbox(void)
{
fprintf(stdout, "%s:\n", __func__);
ccd_t ccd;
CCD_BOX(box1);
CCD_BOX(box2);
ccd_vec3_t axis;
ccd_quat_t rot;
box1.x = box1.y = box1.z = 1.;
box2.x = 0.5;
box2.y = 1.;
box2.z = 1.5;
bench_num = 1;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
ccd.center1 = ccdObjCenter;
ccd.center2 = ccdObjCenter;
runBench(&box1, &box2, &ccd);
runBench(&box2, &box1, &ccd);
ccdVec3Set(&box1.pos, -0.3, 0.5, 1.);
runBench(&box1, &box2, &ccd);
runBench(&box2, &box1, &ccd);
box1.x = box1.y = box1.z = 1.;
box2.x = box2.y = box2.z = 1.;
ccdVec3Set(&axis, 0., 0., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&box1.pos, 0., 0., 0.);
runBench(&box1, &box2, &ccd);
runBench(&box2, &box1, &ccd);
box1.x = box1.y = box1.z = 1.;
box2.x = box2.y = box2.z = 1.;
ccdVec3Set(&axis, 0., 0., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&box1.pos, -0.5, 0., 0.);
runBench(&box1, &box2, &ccd);
runBench(&box2, &box1, &ccd);
box1.x = box1.y = box1.z = 1.;
box2.x = box2.y = box2.z = 1.;
ccdVec3Set(&axis, 0., 0., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&box1.pos, -0.5, 0.5, 0.);
runBench(&box1, &box2, &ccd);
runBench(&box2, &box1, &ccd);
box1.x = box1.y = box1.z = 1.;
ccdVec3Set(&axis, 0., 1., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&box1.pos, -0.5, 0.1, 0.4);
runBench(&box1, &box2, &ccd);
runBench(&box2, &box1, &ccd);
box1.x = box1.y = box1.z = 1.;
ccdVec3Set(&axis, 0., 1., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&axis, 1., 1., 1.);
ccdQuatSetAngleAxis(&rot, M_PI / 4., &axis);
ccdQuatMul(&box1.quat, &rot);
ccdVec3Set(&box1.pos, -0.5, 0.1, 0.4);
runBench(&box1, &box2, &ccd);
runBench(&box2, &box1, &ccd);
box1.x = box1.y = box1.z = 1.;
box2.x = 0.2; box2.y = 0.5; box2.z = 1.;
box2.x = box2.y = box2.z = 1.;
ccdVec3Set(&axis, 0., 0., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&axis, 1., 0., 0.);
ccdQuatSetAngleAxis(&rot, M_PI / 4., &axis);
ccdQuatMul(&box1.quat, &rot);
ccdVec3Set(&box1.pos, -1.3, 0., 0.);
ccdVec3Set(&box2.pos, 0., 0., 0.);
runBench(&box1, &box2, &ccd);
runBench(&box2, &box1, &ccd);
fprintf(stdout, "\n----\n\n");
}
void cylcyl(void)
{
fprintf(stdout, "%s:\n", __func__);
ccd_t ccd;
CCD_CYL(cyl1);
CCD_CYL(cyl2);
ccd_vec3_t axis;
cyl1.radius = 0.35;
cyl1.height = 0.5;
cyl2.radius = 0.5;
cyl2.height = 1.;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
ccd.center1 = ccdObjCenter;
ccd.center2 = ccdObjCenter;
runBench(&cyl1, &cyl2, &ccd);
runBench(&cyl2, &cyl1, &ccd);
ccdVec3Set(&cyl1.pos, 0.3, 0.1, 0.1);
runBench(&cyl1, &cyl2, &ccd);
runBench(&cyl2, &cyl1, &ccd);
ccdVec3Set(&axis, 0., 1., 1.);
ccdQuatSetAngleAxis(&cyl2.quat, M_PI / 4., &axis);
ccdVec3Set(&cyl2.pos, 0., 0., 0.);
runBench(&cyl1, &cyl2, &ccd);
runBench(&cyl2, &cyl1, &ccd);
ccdVec3Set(&axis, 0., 1., 1.);
ccdQuatSetAngleAxis(&cyl2.quat, M_PI / 4., &axis);
ccdVec3Set(&cyl2.pos, -0.2, 0.7, 0.2);
runBench(&cyl1, &cyl2, &ccd);
runBench(&cyl2, &cyl1, &ccd);
ccdVec3Set(&axis, 0.567, 1.2, 1.);
ccdQuatSetAngleAxis(&cyl2.quat, M_PI / 4., &axis);
ccdVec3Set(&cyl2.pos, 0.6, -0.7, 0.2);
runBench(&cyl1, &cyl2, &ccd);
runBench(&cyl2, &cyl1, &ccd);
ccdVec3Set(&axis, -4.567, 1.2, 0.);
ccdQuatSetAngleAxis(&cyl2.quat, M_PI / 3., &axis);
ccdVec3Set(&cyl2.pos, 0.6, -0.7, 0.2);
runBench(&cyl1, &cyl2, &ccd);
runBench(&cyl2, &cyl1, &ccd);
fprintf(stdout, "\n----\n\n");
}
void boxcyl(void)
{
fprintf(stdout, "%s:\n", __func__);
ccd_t ccd;
CCD_BOX(box);
CCD_CYL(cyl);
ccd_vec3_t axis;
box.x = 0.5;
box.y = 1.;
box.z = 1.5;
cyl.radius = 0.4;
cyl.height = 0.7;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
ccd.center1 = ccdObjCenter;
ccd.center2 = ccdObjCenter;
runBench(&box, &cyl, &ccd);
runBench(&cyl, &box, &ccd);
ccdVec3Set(&cyl.pos, .6, 0., 0.);
runBench(&box, &cyl, &ccd);
runBench(&cyl, &box, &ccd);
ccdVec3Set(&cyl.pos, .6, 0.6, 0.);
runBench(&box, &cyl, &ccd);
runBench(&cyl, &box, &ccd);
ccdVec3Set(&cyl.pos, .6, 0.6, 0.5);
runBench(&box, &cyl, &ccd);
runBench(&cyl, &box, &ccd);
ccdVec3Set(&axis, 0., 1., 0.);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 3., &axis);
ccdVec3Set(&cyl.pos, .6, 0.6, 0.5);
runBench(&box, &cyl, &ccd);
runBench(&cyl, &box, &ccd);
ccdVec3Set(&axis, 0.67, 1.1, 0.12);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 4., &axis);
ccdVec3Set(&cyl.pos, .6, 0., 0.5);
runBench(&box, &cyl, &ccd);
runBench(&cyl, &box, &ccd);
ccdVec3Set(&axis, -0.1, 2.2, -1.);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 5., &axis);
ccdVec3Set(&cyl.pos, .6, 0., 0.5);
ccdVec3Set(&axis, 1., 1., 0.);
ccdQuatSetAngleAxis(&box.quat, -M_PI / 4., &axis);
ccdVec3Set(&box.pos, .6, 0., 0.5);
runBench(&box, &cyl, &ccd);
runBench(&cyl, &box, &ccd);
ccdVec3Set(&axis, -0.1, 2.2, -1.);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 5., &axis);
ccdVec3Set(&cyl.pos, .6, 0., 0.5);
ccdVec3Set(&axis, 1., 1., 0.);
ccdQuatSetAngleAxis(&box.quat, -M_PI / 4., &axis);
ccdVec3Set(&box.pos, .9, 0.8, 0.5);
runBench(&box, &cyl, &ccd);
runBench(&cyl, &box, &ccd);
fprintf(stdout, "\n----\n\n");
}
int main(int argc, char *argv[])
{
if (argc > 1){
cycles = atol(argv[1]);
}
fprintf(stdout, "Cycles: %u\n", (unsigned int)cycles);
fprintf(stdout, "\n");
boxbox();
cylcyl();
boxcyl();
return 0;
}
================================================
FILE: src/testsuites/boxbox.c
================================================
#include <stdio.h>
#include <cu/cu.h>
#include <ccd/ccd.h>
#include "support.h"
#include "../dbg.h"
#include "common.h"
TEST(boxboxSetUp)
{
}
TEST(boxboxTearDown)
{
}
TEST(boxboxAlignedX)
{
size_t i;
ccd_t ccd;
CCD_BOX(box1);
CCD_BOX(box2);
int res;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
//ccd.max_iterations = 20;
box1.x = 1;
box1.y = 2;
box1.z = 1;
box2.x = 2;
box2.y = 1;
box2.z = 2;
ccdVec3Set(&box1.pos, -5., 0., 0.);
ccdVec3Set(&box2.pos, 0., 0., 0.);
ccdQuatSet(&box1.quat, 0., 0., 0., 1.);
ccdQuatSet(&box2.quat, 0., 0., 0., 1.);
for (i = 0; i < 100; i++){
res = ccdGJKIntersect(&box1, &box2, &ccd);
if (i < 35 || i > 65){
assertFalse(res);
}else if (i != 35 && i != 65){
assertTrue(res);
}
box1.pos.v[0] += 0.1;
}
box1.x = 0.1;
box1.y = 0.2;
box1.z = 0.1;
box2.x = 0.2;
box2.y = 0.1;
box2.z = 0.2;
ccdVec3Set(&box1.pos, -0.5, 0., 0.);
ccdVec3Set(&box2.pos, 0., 0., 0.);
ccdQuatSet(&box1.quat, 0., 0., 0., 1.);
ccdQuatSet(&box2.quat, 0., 0., 0., 1.);
for (i = 0; i < 100; i++){
res = ccdGJKIntersect(&box1, &box2, &ccd);
if (i < 35 || i > 65){
assertFalse(res);
}else if (i != 35 && i != 65){
assertTrue(res);
}
box1.pos.v[0] += 0.01;
}
box1.x = 1;
box1.y = 2;
box1.z = 1;
box2.x = 2;
box2.y = 1;
box2.z = 2;
ccdVec3Set(&box1.pos, -5., -0.1, 0.);
ccdVec3Set(&box2.pos, 0., 0., 0.);
ccdQuatSet(&box1.quat, 0., 0., 0., 1.);
ccdQuatSet(&box2.quat, 0., 0., 0., 1.);
for (i = 0; i < 100; i++){
res = ccdGJKIntersect(&box1, &box2, &ccd);
if (i < 35 || i > 65){
assertFalse(res);
}else if (i != 35 && i != 65){
assertTrue(res);
}
box1.pos.v[0] += 0.1;
}
}
TEST(boxboxAlignedY)
{
size_t i;
ccd_t ccd;
CCD_BOX(box1);
CCD_BOX(box2);
int res;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
box1.x = 1;
box1.y = 2;
box1.z = 1;
box2.x = 2;
box2.y = 1;
box2.z = 2;
ccdVec3Set(&box1.pos, 0., -5., 0.);
ccdVec3Set(&box2.pos, 0., 0., 0.);
ccdQuatSet(&box1.quat, 0., 0., 0., 1.);
ccdQuatSet(&box2.quat, 0., 0., 0., 1.);
for (i = 0; i < 100; i++){
res = ccdGJKIntersect(&box1, &box2, &ccd);
if (i < 35 || i > 65){
assertFalse(res);
}else if (i != 35 && i != 65){
assertTrue(res);
}
box1.pos.v[1] += 0.1;
}
}
TEST(boxboxAlignedZ)
{
size_t i;
ccd_t ccd;
CCD_BOX(box1);
CCD_BOX(box2);
int res;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
box1.x = 1;
box1.y = 2;
box1.z = 1;
box2.x = 2;
box2.y = 1;
box2.z = 2;
ccdVec3Set(&box1.pos, 0., 0., -5.);
ccdVec3Set(&box2.pos, 0., 0., 0.);
ccdQuatSet(&box1.quat, 0., 0., 0., 1.);
ccdQuatSet(&box2.quat, 0., 0., 0., 1.);
for (i = 0; i < 100; i++){
res = ccdGJKIntersect(&box1, &box2, &ccd);
if (i < 35 || i > 65){
assertFalse(res);
}else if (i != 35 && i != 65){
assertTrue(res);
}
box1.pos.v[2] += 0.1;
}
}
TEST(boxboxRot)
{
size_t i;
ccd_t ccd;
CCD_BOX(box1);
CCD_BOX(box2);
int res;
ccd_vec3_t axis;
ccd_real_t angle;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
box1.x = 1;
box1.y = 2;
box1.z = 1;
box2.x = 2;
box2.y = 1;
box2.z = 2;
ccdVec3Set(&box1.pos, -5., 0.5, 0.);
ccdVec3Set(&box2.pos, 0., 0., 0.);
ccdQuatSet(&box2.quat, 0., 0., 0., 1.);
ccdVec3Set(&axis, 0., 1., 0.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
for (i = 0; i < 100; i++){
res = ccdGJKIntersect(&box1, &box2, &ccd);
if (i < 33 || i > 67){
assertFalse(res);
}else if (i != 33 && i != 67){
assertTrue(res);
}
box1.pos.v[0] += 0.1;
}
box1.x = 1;
box1.y = 1;
box1.z = 1;
box2.x = 1;
box2.y = 1;
box2.z = 1;
ccdVec3Set(&box1.pos, -1.01, 0., 0.);
ccdVec3Set(&box2.pos, 0., 0., 0.);
ccdQuatSet(&box1.quat, 0., 0., 0., 1.);
ccdQuatSet(&box2.quat, 0., 0., 0., 1.);
ccdVec3Set(&axis, 0., 1., 0.);
angle = 0.;
for (i = 0; i < 30; i++){
res = ccdGJKIntersect(&box1, &box2, &ccd);
if (i != 0 && i != 10 && i != 20){
assertTrue(res);
}else{
assertFalse(res);
}
angle += M_PI / 20.;
ccdQuatSetAngleAxis(&box1.quat, angle, &axis);
}
}
static void pConf(ccd_box_t *box1, ccd_box_t *box2, const ccd_vec3_t *v)
{
fprintf(stdout, "# box1.pos: [%lf %lf %lf]\n",
ccdVec3X(&box1->pos), ccdVec3Y(&box1->pos), ccdVec3Z(&box1->pos));
fprintf(stdout, "# box1->quat: [%lf %lf %lf %lf]\n",
box1->quat.q[0], box1->quat.q[1], box1->quat.q[2], box1->quat.q[3]);
fprintf(stdout, "# box2->pos: [%lf %lf %lf]\n",
ccdVec3X(&box2->pos), ccdVec3Y(&box2->pos), ccdVec3Z(&box2->pos));
fprintf(stdout, "# box2->quat: [%lf %lf %lf %lf]\n",
box2->quat.q[0], box2->quat.q[1], box2->quat.q[2], box2->quat.q[3]);
fprintf(stdout, "# sep: [%lf %lf %lf]\n",
ccdVec3X(v), ccdVec3Y(v), ccdVec3Z(v));
fprintf(stdout, "#\n");
}
TEST(boxboxSeparate)
{
ccd_t ccd;
CCD_BOX(box1);
CCD_BOX(box2);
int res;
ccd_vec3_t sep, expsep, expsep2, axis;
fprintf(stderr, "\n\n\n---- boxboxSeparate ----\n\n\n");
box1.x = box1.y = box1.z = 1.;
box2.x = 0.5;
box2.y = 1.;
box2.z = 1.5;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
ccdVec3Set(&box1.pos, -0.5, 0.5, 0.2);
res = ccdGJKIntersect(&box1, &box2, &ccd);
assertTrue(res);
res = ccdGJKSeparate(&box1, &box2, &ccd, &sep);
assertTrue(res == 0);
ccdVec3Set(&expsep, 0.25, 0., 0.);
assertTrue(ccdVec3Eq(&sep, &expsep));
ccdVec3Scale(&sep, -1.);
ccdVec3Add(&box1.pos, &sep);
res = ccdGJKSeparate(&box1, &box2, &ccd, &sep);
assertTrue(res == 0);
ccdVec3Set(&expsep, 0., 0., 0.);
assertTrue(ccdVec3Eq(&sep, &expsep));
ccdVec3Set(&box1.pos, -0.3, 0.5, 1.);
res = ccdGJKSeparate(&box1, &box2, &ccd, &sep);
assertTrue(res == 0);
ccdVec3Set(&expsep, 0., 0., -0.25);
assertTrue(ccdVec3Eq(&sep, &expsep));
box1.x = box1.y = box1.z = 1.;
box2.x = box2.y = box2.z = 1.;
ccdVec3Set(&axis, 0., 0., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&box1.pos, 0., 0., 0.);
res = ccdGJKSeparate(&box1, &box2, &ccd, &sep);
assertTrue(res == 0);
ccdVec3Set(&expsep, 0., 0., 1.);
ccdVec3Set(&expsep2, 0., 0., -1.);
assertTrue(ccdVec3Eq(&sep, &expsep) || ccdVec3Eq(&sep, &expsep2));
box1.x = box1.y = box1.z = 1.;
ccdVec3Set(&axis, 0., 0., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&box1.pos, -0.5, 0., 0.);
res = ccdGJKSeparate(&box1, &box2, &ccd, &sep);
assertTrue(res == 0);
pConf(&box1, &box2, &sep);
box1.x = box1.y = box1.z = 1.;
ccdVec3Set(&axis, 0., 1., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&box1.pos, -0.5, 0.1, 0.4);
res = ccdGJKSeparate(&box1, &box2, &ccd, &sep);
assertTrue(res == 0);
pConf(&box1, &box2, &sep);
}
#define TOSVT() \
svtObjPen(&box1, &box2, stdout, "Pen 1", depth, &dir, &pos); \
ccdVec3Scale(&dir, depth); \
ccdVec3Add(&box2.pos, &dir); \
svtObjPen(&box1, &box2, stdout, "Pen 1", depth, &dir, &pos)
TEST(boxboxPenetration)
{
ccd_t ccd;
CCD_BOX(box1);
CCD_BOX(box2);
int res;
ccd_vec3_t axis;
ccd_quat_t rot;
ccd_real_t depth;
ccd_vec3_t dir, pos;
fprintf(stderr, "\n\n\n---- boxboxPenetration ----\n\n\n");
box1.x = box1.y = box1.z = 1.;
box2.x = 0.5;
box2.y = 1.;
box2.z = 1.5;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
ccdVec3Set(&box2.pos, 0.1, 0., 0.);
res = ccdGJKPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 1");
//TOSVT();
ccdVec3Set(&box1.pos, -0.3, 0.5, 1.);
res = ccdGJKPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 2");
//TOSVT(); <<<
box1.x = box1.y = box1.z = 1.;
box2.x = box2.y = box2.z = 1.;
ccdVec3Set(&axis, 0., 0., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&box1.pos, 0.1, 0., 0.1);
res = ccdGJKPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 3");
//TOSVT();
box1.x = box1.y = box1.z = 1.;
box2.x = box2.y = box2.z = 1.;
ccdVec3Set(&axis, 0., 0., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&box1.pos, -0.5, 0., 0.);
res = ccdGJKPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 4");
//TOSVT();
box1.x = box1.y = box1.z = 1.;
box2.x = box2.y = box2.z = 1.;
ccdVec3Set(&axis, 0., 0., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&box1.pos, -0.5, 0.5, 0.);
res = ccdGJKPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 5");
//TOSVT();
box1.x = box1.y = box1.z = 1.;
box2.x = box2.y = box2.z = 1.;
ccdVec3Set(&box2.pos, 0.1, 0., 0.);
box1.x = box1.y = box1.z = 1.;
ccdVec3Set(&axis, 0., 1., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&box1.pos, -0.5, 0.1, 0.4);
res = ccdGJKPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 6");
//TOSVT();
box1.x = box1.y = box1.z = 1.;
ccdVec3Set(&axis, 0., 1., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&axis, 1., 1., 1.);
ccdQuatSetAngleAxis(&rot, M_PI / 4., &axis);
ccdQuatMul(&box1.quat, &rot);
ccdVec3Set(&box1.pos, -0.5, 0.1, 0.4);
res = ccdGJKPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 7");
//TOSVT(); <<<
box1.x = box1.y = box1.z = 1.;
box2.x = 0.2; box2.y = 0.5; box2.z = 1.;
box2.x = box2.y = box2.z = 1.;
ccdVec3Set(&axis, 0., 0., 1.);
ccdQuatSetAngleAxis(&box1.quat, M_PI / 4., &axis);
ccdVec3Set(&axis, 1., 0., 0.);
ccdQuatSetAngleAxis(&rot, M_PI / 4., &axis);
ccdQuatMul(&box1.quat, &rot);
ccdVec3Set(&box1.pos, -1.3, 0., 0.);
ccdVec3Set(&box2.pos, 0., 0., 0.);
res = ccdGJKPenetration(&box1, &box2, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 8");
//TOSVT();
}
================================================
FILE: src/testsuites/boxbox.h
================================================
#ifndef BOX_BOX
#define BOX_BOX
#include <cu/cu.h>
TEST(boxboxSetUp);
TEST(boxboxTearDown);
TEST(boxboxAlignedX);
TEST(boxboxAlignedY);
TEST(boxboxAlignedZ);
TEST(boxboxRot);
TEST(boxboxSeparate);
TEST(boxboxPenetration);
TEST_SUITE(TSBoxBox) {
TEST_ADD(boxboxSetUp),
TEST_ADD(boxboxAlignedX),
TEST_ADD(boxboxAlignedY),
TEST_ADD(boxboxAlignedZ),
TEST_ADD(boxboxRot),
TEST_ADD(boxboxSeparate),
TEST_ADD(boxboxPenetration),
TEST_ADD(boxboxTearDown),
TEST_SUITE_CLOSURE
};
#endif
================================================
FILE: src/testsuites/boxcyl.c
================================================
#include <cu/cu.h>
#include <ccd/ccd.h>
#include "common.h"
#include "support.h"
#define TOSVT() \
svtObjPen(&box, &cyl, stdout, "Pen 1", depth, &dir, &pos); \
ccdVec3Scale(&dir, depth); \
ccdVec3Add(&cyl.pos, &dir); \
svtObjPen(&box, &cyl, stdout, "Pen 1", depth, &dir, &pos)
TEST(boxcylIntersect)
{
ccd_t ccd;
CCD_BOX(box);
CCD_CYL(cyl);
int res;
ccd_vec3_t axis;
box.x = 0.5;
box.y = 1.;
box.z = 1.5;
cyl.radius = 0.4;
cyl.height = 0.7;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
ccdVec3Set(&cyl.pos, 0.1, 0., 0.);
res = ccdGJKIntersect(&box, &cyl, &ccd);
assertTrue(res);
ccdVec3Set(&cyl.pos, .6, 0., 0.);
res = ccdGJKIntersect(&box, &cyl, &ccd);
assertTrue(res);
ccdVec3Set(&cyl.pos, .6, 0.6, 0.);
res = ccdGJKIntersect(&box, &cyl, &ccd);
assertTrue(res);
ccdVec3Set(&cyl.pos, .6, 0.6, 0.5);
res = ccdGJKIntersect(&box, &cyl, &ccd);
assertTrue(res);
ccdVec3Set(&axis, 0., 1., 0.);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 3., &axis);
ccdVec3Set(&cyl.pos, .6, 0.6, 0.5);
res = ccdGJKIntersect(&box, &cyl, &ccd);
assertTrue(res);
ccdVec3Set(&axis, 0.67, 1.1, 0.12);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 4., &axis);
ccdVec3Set(&cyl.pos, .6, 0., 0.5);
res = ccdGJKIntersect(&box, &cyl, &ccd);
assertTrue(res);
ccdVec3Set(&axis, -0.1, 2.2, -1.);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 5., &axis);
ccdVec3Set(&cyl.pos, .6, 0., 0.5);
ccdVec3Set(&axis, 1., 1., 0.);
ccdQuatSetAngleAxis(&box.quat, -M_PI / 4., &axis);
ccdVec3Set(&box.pos, .6, 0., 0.5);
res = ccdGJKIntersect(&box, &cyl, &ccd);
assertTrue(res);
ccdVec3Set(&axis, -0.1, 2.2, -1.);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 5., &axis);
ccdVec3Set(&cyl.pos, .6, 0., 0.5);
ccdVec3Set(&axis, 1., 1., 0.);
ccdQuatSetAngleAxis(&box.quat, -M_PI / 4., &axis);
ccdVec3Set(&box.pos, .9, 0.8, 0.5);
res = ccdGJKIntersect(&box, &cyl, &ccd);
assertTrue(res);
}
TEST(boxcylPenEPA)
{
ccd_t ccd;
CCD_BOX(box);
CCD_CYL(cyl);
int res;
ccd_vec3_t axis;
ccd_real_t depth;
ccd_vec3_t dir, pos;
box.x = 0.5;
box.y = 1.;
box.z = 1.5;
cyl.radius = 0.4;
cyl.height = 0.7;
CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
ccdVec3Set(&cyl.pos, 0.1, 0., 0.);
res = ccdGJKPenetration(&box, &cyl, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 1");
//TOSVT();
ccdVec3Set(&cyl.pos, .6, 0., 0.);
res = ccdGJKPenetration(&box, &cyl, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 2");
//TOSVT(); <<<
ccdVec3Set(&cyl.pos, .6, 0.6, 0.);
res = ccdGJKPenetration(&box, &cyl, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 3");
//TOSVT();
ccdVec3Set(&cyl.pos, .6, 0.6, 0.5);
res = ccdGJKPenetration(&box, &cyl, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 4");
//TOSVT();
ccdVec3Set(&axis, 0., 1., 0.);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 3., &axis);
ccdVec3Set(&cyl.pos, .6, 0.6, 0.5);
res = ccdGJKPenetration(&box, &cyl, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 5");
//TOSVT();
ccdVec3Set(&axis, 0.67, 1.1, 0.12);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 4., &axis);
ccdVec3Set(&cyl.pos, .6, 0., 0.5);
res = ccdGJKPenetration(&box, &cyl, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 6");
//TOSVT();
ccdVec3Set(&axis, -0.1, 2.2, -1.);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 5., &axis);
ccdVec3Set(&cyl.pos, .6, 0., 0.5);
ccdVec3Set(&axis, 1., 1., 0.);
ccdQuatSetAngleAxis(&box.quat, -M_PI / 4., &axis);
ccdVec3Set(&box.pos, .6, 0., 0.5);
res = ccdGJKPenetration(&box, &cyl, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 7");
//TOSVT();
ccdVec3Set(&axis, -0.1, 2.2, -1.);
ccdQuatSetAngleAxis(&cyl.quat, M_PI / 5., &axis);
ccdVec3Set(&cyl.pos, .6, 0., 0.5);
ccdVec3Set(&axis, 1., 1., 0.);
ccdQuatSetAngleAxis(&box.quat, -M_PI / 4., &axis);
ccdVec3Set(&box.pos, .9, 0.8, 0.5);
res = ccdGJKPenetration(&box, &cyl, &ccd, &depth, &dir, &pos);
assertTrue(res == 0);
recPen(depth, &dir, &pos, stdout, "Pen 8");
//TOSVT();
}
================================================
FILE: src/testsuites/boxcyl.h
================================================
#ifndef TEST_BOXCYL_H
#define TEST_BOXCYL_H
#include <cu/cu.h>
TEST(boxcylIntersect);
TEST(boxcylPenEPA);
TEST_SUITE(TSBoxCyl){
TEST_ADD(boxcylIntersect),
TEST_ADD(boxcylPenEPA),
TEST_SUITE_CLOSURE
};
#endif
================================================
FILE: src/testsuites/common.c
================================================
#include <ccd/vec3.h>
#include <ccd/quat.h>
#include "common.h"
#include "support.h"
static void svtCyl(ccd_cyl_t *c, FILE *out, const char *color, const char *name)
{
ccd_vec3_t v[32];
ccd_quat_t rot;
ccd_vec3_t axis, vpos, vpos2;
ccd_real_t angle, x, y;
int i;
ccdVec3Set(&axis, 0., 0., 1.);
ccdVec3Set(&vpos, 0., c->radius, 0.);
angle = 0.;
for (i = 0; i < 16; i++){
angle = (ccd_real_t)i * (2. * M_PI / 16.);
ccdQuatSetAngleAxis(&rot, angle, &axis);
ccdVec3Copy(&vpos2, &vpos);
ccdQuatRotVec(&vpos2, &rot);
x = ccdVec3X(&vpos2);
y = ccdVec3Y(&vpos2);
ccdVec3Set(&v[i], x, y, c->height / 2.);
ccdVec3Set(&v[i + 16], x, y, -c->height / 2.);
}
for (i = 0; i < 32; i++){
ccdQuatRotVec(&v[i], &c->quat);
ccdVec3Add(&v[i], &c->pos);
}
fprintf(out, "-----\n");
if (name)
fprintf(out, "Name: %s\n", name);
fprintf(out, "Face color: %s\n", color);
fprintf(out, "Edge color: %s\n", color);
fprintf(out, "Point color: %s\n", color);
fprintf(out, "Points:\n");
for (i = 0; i < 32; i++){
fprintf(out, "%lf %lf %lf\n", ccdVec3X(&v[i]), ccdVec3Y(&v[i]), ccdVec3Z(&v[i]));
}
fprintf(out, "Edges:\n");
fprintf(out, "0 16\n");
fprintf(out, "0 31\n");
for (i = 1; i < 16; i++){
fprintf(out, "0 %d\n", i);
fprintf(out, "16 %d\n", i + 16);
if (i != 0){
fprintf(out, "%d %d\n", i - 1, i);
fprintf(out, "%d %d\n", i + 16 - 1, i + 16);
}
fprintf(out, "%d %d\n", i, i + 16);
fprintf(out, "%d %d\n", i, i + 16 - 1);
}
fprintf(out, "Faces:\n");
for (i = 2; i < 16; i++){
fprintf(out, "0 %d %d\n", i, i -1);
fprintf(out, "16 %d %d\n", i + 16, i + 16 -1);
}
fprintf(out, "0 16 31\n");
fprintf(out, "0 31 15\n");
for (i = 1; i < 16; i++){
fprintf(out, "%d %d %d\n", i, i + 16, i + 16 - 1);
fprintf(out, "%d %d %d\n", i, i + 16 - 1, i - 1);
}
fprintf(out, "-----\n");
}
static void svtBox(ccd_box_t *b, FILE *out, const char *color, const char *name)
{
ccd_vec3_t v[8];
size_t i;
ccdVec3Set(&v[0], b->x * 0.5, b->y * 0.5, b->z * 0.5);
ccdVec3Set(&v[1], b->x * 0.5, b->y * -0.5, b->z * 0.5);
ccdVec3Set(&v[2], b->x * 0.5, b->y * 0.5, b->z * -0.5);
ccdVec3Set(&v[3], b->x * 0.5, b->y * -0.5, b->z * -0.5);
ccdVec3Set(&v[4], b->x * -0.5, b->y * 0.5, b->z * 0.5);
ccdVec3Set(&v[5], b->x * -0.5, b->y * -0.5, b->z * 0.5);
ccdVec3Set(&v[6], b->x * -0.5, b->y * 0.5, b->z * -0.5);
ccdVec3Set(&v[7], b->x * -0.5, b->y * -0.5, b->z * -0.5);
for (i = 0; i < 8; i++){
ccdQuatRotVec(&v[i], &b->quat);
ccdVec3Add(&v[i], &b->pos);
}
fprintf(out, "-----\n");
if (name)
fprintf(out, "Name: %s\n", name);
fprintf(out, "Face color: %s\n", color);
fprintf(out, "Edge color: %s\n", color);
fprintf(out, "Point color: %s\n", color);
fprintf(out, "Points:\n");
for (i = 0; i < 8; i++){
fprintf(out, "%lf %lf %lf\n", ccdVec3X(&v[i]), ccdVec3Y(&v[i]), ccdVec3Z(&v[i]));
}
fprintf(out, "Edges:\n");
fprintf(out, "0 1\n 0 2\n2 3\n3 1\n1 2\n6 2\n1 7\n1 5\n");
fprintf(out, "5 0\n0 4\n4 2\n6 4\n6 5\n5 7\n6 7\n7 2\n7 3\n4 5\n");
fprintf(out, "Faces:\n");
fprintf(out, "0 2 1\n1 2 3\n6 2 4\n4 2 0\n4 0 5\n5 0 1\n");
fprintf(out, "5 1 7\n7 1 3\n6 4 5\n6 5 7\n2 6 7\n2 7 3\n");
fprintf(out, "-----\n");
}
void svtObj(void *_o, FILE *out, const char *color, const char *name)
{
ccd_obj_t *o = (ccd_obj_t *)_o;
if (o->type == CCD_OBJ_CYL){
svtCyl((ccd_cyl_t *)o, out, color, name);
}else if (o->type == CCD_OBJ_BOX){
svtBox((ccd_box_t *)o, out, color, name);
}
}
void svtObjPen(void *o1, void *o2,
FILE *out, const char *name,
ccd_real_t depth, const ccd_vec3_t *dir, const ccd_vec3_t *pos)
{
ccd_vec3_t sep;
char oname[500];
ccdVec3Copy(&sep, dir);
ccdVec3Scale(&sep, depth);
ccdVec3Add(&sep, pos);
fprintf(out, "------\n");
if (name)
fprintf(out, "Name: %s\n", name);
fprintf(out, "Point color: 0.1 0.1 0.9\n");
fprintf(out, "Points:\n%lf %lf %lf\n", ccdVec3X(pos), ccdVec3Y(pos), ccdVec3Z(pos));
fprintf(out, "------\n");
fprintf(out, "Point color: 0.1 0.9 0.9\n");
fprintf(out, "Edge color: 0.1 0.9 0.9\n");
fprintf(out, "Points:\n%lf %lf %lf\n", ccdVec3X(pos), ccdVec3Y(pos), ccdVec3Z(pos));
fprintf(out, "%lf %lf %lf\n", ccdVec3X(&sep), ccdVec3Y(&sep), ccdVec3Z(&sep));
fprintf(out, "Edges: 0 1\n");
oname[0] = 0x0;
if (name)
sprintf(oname, "%s o1", name);
svtObj(o1, out, "0.9 0.1 0.1", oname);
oname[0] = 0x0;
if (name)
sprintf(oname, "%s o1", name);
svtObj(o2, out, "0.1 0.9 0.1", oname);
}
void recPen(ccd_real_t depth, const ccd_vec3_t *dir, const ccd_vec3_t *pos,
FILE *out, const char *note)
{
if (!note)
note = "";
fprintf(out, "# %s: depth: %lf\n", note, depth);
fprintf(out, "# %s: dir: [%lf %lf %lf]\n", note, ccdVec3X(dir), ccdVec3Y(dir), ccdVec3Z(dir));
fprintf(out, "# %s: pos: [%lf %lf %lf]\n", note, ccdVec3X(pos), ccdVec3Y(pos), ccdVec3Z(pos));
fprintf(out, "#\n");
}
================================================
FILE: src/testsuites/common.h
================================================
#ifndef TEST_COMMON
#define TEST_COMMON
#include <stdio.h>
#include <ccd/vec3.h>
void svtObj(void *o, FILE *out, const char *color, const char *name);
void svtObjPen(void *o1, void *o2,
FILE *out, const char *name,
ccd_real_t depth, const ccd_vec3_t *dir, const ccd_vec3_t *pos);
void recPen(ccd_real_t depth, const ccd_vec3_t *dir, const ccd_vec3_t *pos,
FILE *out, const char *note);
#endif
================================================
FILE: src/testsuites/cu/.dir
================================================
================================================
FILE: src/testsuites/cu/.gitignore
================================================
*~
*.o
*.a
tmp.*
test
================================================
FILE: src/testsuites/cu/CMakeLists.txt
================================================
set(CU_SOURCES
cu.c
cu.h)
add_library(cu STATIC ${CU_SOURCES})
if(NOT APPLE)
target_compile_definitions(cu PUBLIC CU_ENABLE_TIMER)
find_library(LIBRT_LIBRARY NAMES rt)
if(NOT LIBRT_LIBRARY)
message(FATAL_ERROR "Could NOT find required library librt")
endif()
target_link_libraries(cu "${LIBRT_LIBRARY}")
endif()
get_filename_component(CU_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" DIRECTORY)
target_include_directories(cu PUBLIC "${CU_INCLUDE_DIR}")
================================================
FILE: src/testsuites/cu/COPYING
================================================
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedo
gitextract_m4hhryw2/
├── .gitignore
├── .travis.yml
├── BSD-LICENSE
├── CMakeLists.txt
├── Makefile.am
├── README.md
├── bootstrap
├── ccd-config.cmake.in
├── ccd.pc.in
├── configure.ac
├── doc/
│ ├── CMakeLists.txt
│ ├── Makefile
│ ├── _build/
│ │ └── .dir
│ ├── _static/
│ │ └── .dir
│ ├── _templates/
│ │ └── .dir
│ ├── compile-and-install.rst
│ ├── conf.py
│ ├── examples.rst
│ ├── index.rst
│ └── reference.rst
├── make-release.sh
└── src/
├── .gitignore
├── CMakeLists.txt
├── Makefile
├── Makefile.am
├── Makefile.include
├── alloc.h
├── ccd/
│ ├── ccd.h
│ ├── ccd_export.h
│ ├── compiler.h
│ ├── config.h.cmake.in
│ ├── config.h.m4
│ ├── quat.h
│ └── vec3.h
├── ccd.c
├── dbg.h
├── list.h
├── mpr.c
├── polytope.c
├── polytope.h
├── simplex.h
├── support.c
├── support.h
├── testsuites/
│ ├── .gitignore
│ ├── CMakeLists.txt
│ ├── Makefile
│ ├── Makefile.am
│ ├── bench.c
│ ├── bench2.c
│ ├── boxbox.c
│ ├── boxbox.h
│ ├── boxcyl.c
│ ├── boxcyl.h
│ ├── common.c
│ ├── common.h
│ ├── cu/
│ │ ├── .dir
│ │ ├── .gitignore
│ │ ├── CMakeLists.txt
│ │ ├── COPYING
│ │ ├── COPYING.LESSER
│ │ ├── Makefile
│ │ ├── Makefile.am
│ │ ├── check-regressions
│ │ ├── cu.c
│ │ ├── cu.h
│ │ └── latest.sh
│ ├── cylcyl.c
│ ├── cylcyl.h
│ ├── main.c
│ ├── mpr_boxbox.c
│ ├── mpr_boxbox.h
│ ├── mpr_boxcyl.c
│ ├── mpr_boxcyl.h
│ ├── mpr_cylcyl.c
│ ├── mpr_cylcyl.h
│ ├── polytope.c
│ ├── polytope.h
│ ├── regressions/
│ │ ├── .dir
│ │ ├── TSBoxBox.err
│ │ ├── TSBoxBox.out
│ │ ├── TSBoxCyl.err
│ │ ├── TSBoxCyl.out
│ │ ├── TSCylCyl.err
│ │ ├── TSCylCyl.out
│ │ ├── TSMPRBoxBox.err
│ │ ├── TSMPRBoxBox.out
│ │ ├── TSMPRBoxCyl.err
│ │ ├── TSMPRBoxCyl.out
│ │ ├── TSMPRCylCyl.err
│ │ ├── TSMPRCylCyl.out
│ │ ├── TSPt.err
│ │ ├── TSPt.out
│ │ ├── TSSphereSphere.err
│ │ ├── TSSphereSphere.out
│ │ ├── TSVec3.err
│ │ └── TSVec3.out
│ ├── spheresphere.c
│ ├── spheresphere.h
│ ├── support.c
│ ├── support.h
│ ├── vec3.c
│ └── vec3.h
└── vec3.c
SYMBOL INDEX (227 symbols across 37 files)
FILE: src/ccd.c
function ccdFirstDirDefault (line 86) | void ccdFirstDirDefault(const void *o1, const void *o2, ccd_vec3_t *dir)
function ccdGJKIntersect (line 91) | int ccdGJKIntersect(const void *obj1, const void *obj2, const ccd_t *ccd)
function ccdGJKSeparate (line 97) | int ccdGJKSeparate(const void *obj1, const void *obj2, const ccd_t *ccd,
function penEPAPosCmp (line 118) | static int penEPAPosCmp(const void *a, const void *b)
function penEPAPos (line 133) | static int penEPAPos(const ccd_pt_t *pt, const ccd_pt_el_t *nearest,
function ccdGJKPenetration (line 175) | int ccdGJKPenetration(const void *obj1, const void *obj2, const ccd_t *ccd,
function __ccdGJK (line 208) | static int __ccdGJK(const void *obj1, const void *obj2,
function __ccdGJKEPA (line 263) | static int __ccdGJKEPA(const void *obj1, const void *obj2,
function doSimplex2 (line 315) | static int doSimplex2(ccd_simplex_t *simplex, ccd_vec3_t *dir)
function doSimplex3 (line 357) | static int doSimplex3(ccd_simplex_t *simplex, ccd_vec3_t *dir)
function doSimplex4 (line 437) | static int doSimplex4(ccd_simplex_t *simplex, ccd_vec3_t *dir)
function doSimplex (line 526) | static int doSimplex(ccd_simplex_t *simplex, ccd_vec3_t *dir)
function _ccd_inline (line 542) | _ccd_inline void tripleCross(const ccd_vec3_t *a, const ccd_vec3_t *b,
function simplexToPolytope4 (line 554) | static int simplexToPolytope4(const void *obj1, const void *obj2,
function simplexToPolytope3 (line 629) | static int simplexToPolytope3(const void *obj1, const void *obj2,
function simplexToPolytope2 (line 712) | static int simplexToPolytope2(const void *obj1, const void *obj2,
function expandPolytope (line 819) | static int expandPolytope(ccd_pt_t *pt, ccd_pt_el_t *el,
function nextSupport (line 954) | static int nextSupport(const void *obj1, const void *obj2, const ccd_t *...
FILE: src/ccd/ccd.h
type _ccd_t (line 52) | struct _ccd_t {
type ccd_t (line 70) | typedef struct _ccd_t ccd_t;
FILE: src/ccd/quat.h
type _ccd_quat_t (line 28) | struct _ccd_quat_t {
type ccd_quat_t (line 31) | typedef struct _ccd_quat_t ccd_quat_t;
function _ccd_inline (line 75) | _ccd_inline ccd_real_t ccdQuatLen2(const ccd_quat_t *q)
function _ccd_inline (line 87) | _ccd_inline ccd_real_t ccdQuatLen(const ccd_quat_t *q)
function _ccd_inline (line 92) | _ccd_inline void ccdQuatSet(ccd_quat_t *q, ccd_real_t x, ccd_real_t y, c...
function _ccd_inline (line 100) | _ccd_inline void ccdQuatCopy(ccd_quat_t *dest, const ccd_quat_t *src)
function _ccd_inline (line 106) | _ccd_inline int ccdQuatNormalize(ccd_quat_t *q)
function _ccd_inline (line 116) | _ccd_inline void ccdQuatSetAngleAxis(ccd_quat_t *q,
function _ccd_inline (line 144) | _ccd_inline void ccdQuatScale(ccd_quat_t *q, ccd_real_t k)
function _ccd_inline (line 151) | _ccd_inline void ccdQuatMul(ccd_quat_t *q, const ccd_quat_t *q2)
function _ccd_inline (line 158) | _ccd_inline void ccdQuatMul2(ccd_quat_t *q,
function _ccd_inline (line 179) | _ccd_inline int ccdQuatInvert(ccd_quat_t *q)
function _ccd_inline (line 194) | _ccd_inline int ccdQuatInvert2(ccd_quat_t *dest, const ccd_quat_t *src)
function _ccd_inline (line 200) | _ccd_inline void ccdQuatRotVec(ccd_vec3_t *v, const ccd_quat_t *q)
FILE: src/ccd/vec3.h
type ccd_real_t (line 48) | typedef float ccd_real_t;
type ccd_real_t (line 67) | typedef double ccd_real_t;
type _ccd_vec3_t (line 88) | struct _ccd_vec3_t {
type ccd_vec3_t (line 91) | typedef struct _ccd_vec3_t ccd_vec3_t;
function _ccd_inline (line 206) | _ccd_inline int ccdSign(ccd_real_t val)
function _ccd_inline (line 216) | _ccd_inline int ccdIsZero(ccd_real_t val)
function _ccd_inline (line 221) | _ccd_inline int ccdEq(ccd_real_t _a, ccd_real_t _b)
function _ccd_inline (line 240) | _ccd_inline ccd_real_t ccdVec3X(const ccd_vec3_t *v)
function _ccd_inline (line 245) | _ccd_inline ccd_real_t ccdVec3Y(const ccd_vec3_t *v)
function _ccd_inline (line 250) | _ccd_inline ccd_real_t ccdVec3Z(const ccd_vec3_t *v)
function _ccd_inline (line 255) | _ccd_inline int ccdVec3Eq(const ccd_vec3_t *a, const ccd_vec3_t *b)
function _ccd_inline (line 262) | _ccd_inline ccd_real_t ccdVec3Len2(const ccd_vec3_t *v)
function _ccd_inline (line 267) | _ccd_inline ccd_real_t ccdVec3Dist2(const ccd_vec3_t *a, const ccd_vec3_...
function _ccd_inline (line 274) | _ccd_inline void ccdVec3Set(ccd_vec3_t *v, ccd_real_t x, ccd_real_t y, c...
function _ccd_inline (line 281) | _ccd_inline void ccdVec3Copy(ccd_vec3_t *v, const ccd_vec3_t *w)
function _ccd_inline (line 286) | _ccd_inline void ccdVec3Sub(ccd_vec3_t *v, const ccd_vec3_t *w)
function _ccd_inline (line 292) | _ccd_inline void ccdVec3Sub2(ccd_vec3_t *d, const ccd_vec3_t *v, const c...
function _ccd_inline (line 299) | _ccd_inline void ccdVec3Add(ccd_vec3_t *v, const ccd_vec3_t *w)
function _ccd_inline (line 306) | _ccd_inline void ccdVec3Scale(ccd_vec3_t *d, ccd_real_t k)
function _ccd_inline (line 313) | _ccd_inline void ccdVec3Normalize(ccd_vec3_t *d)
function _ccd_inline (line 319) | _ccd_inline ccd_real_t ccdVec3Dot(const ccd_vec3_t *a, const ccd_vec3_t *b)
function _ccd_inline (line 329) | _ccd_inline void ccdVec3Cross(ccd_vec3_t *d, const ccd_vec3_t *a, const ...
FILE: src/list.h
type _ccd_list_t (line 28) | struct _ccd_list_t {
type ccd_list_t (line 31) | typedef struct _ccd_list_t ccd_list_t;
function _ccd_inline (line 114) | _ccd_inline void ccdListInit(ccd_list_t *l)
function _ccd_inline (line 120) | _ccd_inline ccd_list_t *ccdListNext(ccd_list_t *l)
function _ccd_inline (line 125) | _ccd_inline ccd_list_t *ccdListPrev(ccd_list_t *l)
function _ccd_inline (line 130) | _ccd_inline int ccdListEmpty(const ccd_list_t *head)
function _ccd_inline (line 135) | _ccd_inline void ccdListAppend(ccd_list_t *l, ccd_list_t *new)
function _ccd_inline (line 143) | _ccd_inline void ccdListDel(ccd_list_t *item)
FILE: src/mpr.c
function ccdMPRIntersect (line 99) | int ccdMPRIntersect(const void *obj1, const void *obj2, const ccd_t *ccd)
function ccdMPRPenetration (line 117) | int ccdMPRPenetration(const void *obj1, const void *obj2, const ccd_t *ccd,
function _ccd_inline (line 152) | _ccd_inline void findOrigin(const void *obj1, const void *obj2, const cc...
function discoverPortal (line 160) | static int discoverPortal(const void *obj1, const void *obj2,
function refinePortal (line 274) | static int refinePortal(const void *obj1, const void *obj2,
function findPenetr (line 308) | static void findPenetr(const void *obj1, const void *obj2, const ccd_t *...
function findPenetrTouch (line 354) | static void findPenetrTouch(const void *obj1, const void *obj2, const cc...
function findPenetrSegment (line 368) | static void findPenetrSegment(const void *obj1, const void *obj2, const ...
function findPos (line 400) | static void findPos(const void *obj1, const void *obj2, const ccd_t *ccd,
function _ccd_inline (line 466) | _ccd_inline void expandPortal(ccd_simplex_t *portal,
function _ccd_inline (line 491) | _ccd_inline void portalDir(const ccd_simplex_t *portal, ccd_vec3_t *dir)
function _ccd_inline (line 503) | _ccd_inline int portalEncapsulesOrigin(const ccd_simplex_t *portal,
function _ccd_inline (line 511) | _ccd_inline int portalReachTolerance(const ccd_simplex_t *portal,
function _ccd_inline (line 536) | _ccd_inline int portalCanEncapsuleOrigin(const ccd_simplex_t *portal,
FILE: src/polytope.c
function _ccd_inline (line 23) | _ccd_inline void _ccdPtNearestUpdate(ccd_pt_t *pt, ccd_pt_el_t *el)
function _ccdPtNearestRenew (line 38) | static void _ccdPtNearestRenew(ccd_pt_t *pt)
function ccdPtInit (line 63) | void ccdPtInit(ccd_pt_t *pt)
function ccdPtDestroy (line 74) | void ccdPtDestroy(ccd_pt_t *pt)
function ccd_pt_vertex_t (line 97) | ccd_pt_vertex_t *ccdPtAddVertex(ccd_pt_t *pt, const ccd_support_t *v)
function ccd_pt_edge_t (line 122) | ccd_pt_edge_t *ccdPtAddEdge(ccd_pt_t *pt, ccd_pt_vertex_t *v1,
function ccd_pt_face_t (line 155) | ccd_pt_face_t *ccdPtAddFace(ccd_pt_t *pt, ccd_pt_edge_t *e1,
function ccdPtRecomputeDistances (line 206) | void ccdPtRecomputeDistances(ccd_pt_t *pt)
function ccd_pt_el_t (line 244) | ccd_pt_el_t *ccdPtNearest(ccd_pt_t *pt)
function ccdPtDumpSVT (line 253) | void ccdPtDumpSVT(ccd_pt_t *pt, const char *fn)
function ccdPtDumpSVT2 (line 266) | void ccdPtDumpSVT2(ccd_pt_t *pt, FILE *fout)
FILE: src/polytope.h
type _ccd_pt_el_t (line 45) | struct _ccd_pt_el_t {
type ccd_pt_el_t (line 48) | typedef struct _ccd_pt_el_t ccd_pt_el_t;
type _ccd_pt_edge_t (line 50) | struct _ccd_pt_edge_t
type _ccd_pt_face_t (line 51) | struct _ccd_pt_face_t
type _ccd_pt_vertex_t (line 56) | struct _ccd_pt_vertex_t {
type ccd_pt_vertex_t (line 63) | typedef struct _ccd_pt_vertex_t ccd_pt_vertex_t;
type _ccd_pt_edge_t (line 68) | struct _ccd_pt_edge_t {
type ccd_pt_edge_t (line 76) | typedef struct _ccd_pt_edge_t ccd_pt_edge_t;
type _ccd_pt_face_t (line 81) | struct _ccd_pt_face_t {
type ccd_pt_face_t (line 86) | typedef struct _ccd_pt_face_t ccd_pt_face_t;
type _ccd_pt_t (line 92) | struct _ccd_pt_t {
type ccd_pt_t (line 101) | typedef struct _ccd_pt_t ccd_pt_t;
function _ccd_inline (line 179) | _ccd_inline ccd_pt_vertex_t *ccdPtAddVertexCoords(ccd_pt_t *pt,
function _ccd_inline (line 187) | _ccd_inline int ccdPtDelVertex(ccd_pt_t *pt, ccd_pt_vertex_t *v)
function _ccd_inline (line 204) | _ccd_inline int ccdPtDelEdge(ccd_pt_t *pt, ccd_pt_edge_t *e)
function _ccd_inline (line 226) | _ccd_inline int ccdPtDelFace(ccd_pt_t *pt, ccd_pt_face_t *f)
function _ccd_inline (line 251) | _ccd_inline void ccdPtFaceVec3(const ccd_pt_face_t *face,
function _ccd_inline (line 267) | _ccd_inline void ccdPtFaceVertices(const ccd_pt_face_t *face,
function _ccd_inline (line 283) | _ccd_inline void ccdPtFaceEdges(const ccd_pt_face_t *f,
function _ccd_inline (line 293) | _ccd_inline void ccdPtEdgeVec3(const ccd_pt_edge_t *e,
function _ccd_inline (line 301) | _ccd_inline void ccdPtEdgeVertices(const ccd_pt_edge_t *e,
function _ccd_inline (line 309) | _ccd_inline void ccdPtEdgeFaces(const ccd_pt_edge_t *e,
FILE: src/simplex.h
type _ccd_simplex_t (line 28) | struct _ccd_simplex_t {
type ccd_simplex_t (line 32) | typedef struct _ccd_simplex_t ccd_simplex_t;
function _ccd_inline (line 49) | _ccd_inline void ccdSimplexInit(ccd_simplex_t *s)
function _ccd_inline (line 54) | _ccd_inline int ccdSimplexSize(const ccd_simplex_t *s)
function _ccd_inline (line 59) | _ccd_inline const ccd_support_t *ccdSimplexLast(const ccd_simplex_t *s)
function _ccd_inline (line 64) | _ccd_inline const ccd_support_t *ccdSimplexPoint(const ccd_simplex_t *s,...
function _ccd_inline (line 69) | _ccd_inline ccd_support_t *ccdSimplexPointW(ccd_simplex_t *s, int idx)
function _ccd_inline (line 74) | _ccd_inline void ccdSimplexAdd(ccd_simplex_t *s, const ccd_support_t *v)
function _ccd_inline (line 81) | _ccd_inline void ccdSimplexSet(ccd_simplex_t *s, size_t pos, const ccd_s...
function _ccd_inline (line 86) | _ccd_inline void ccdSimplexSetSize(ccd_simplex_t *s, int size)
function _ccd_inline (line 91) | _ccd_inline void ccdSimplexSwap(ccd_simplex_t *s, size_t pos1, size_t pos2)
FILE: src/support.c
function __ccdSupport (line 20) | void __ccdSupport(const void *obj1, const void *obj2,
FILE: src/support.h
type _ccd_support_t (line 27) | struct _ccd_support_t {
type ccd_support_t (line 32) | typedef struct _ccd_support_t ccd_support_t;
function _ccd_inline (line 46) | _ccd_inline void ccdSupportCopy(ccd_support_t *d, const ccd_support_t *s)
FILE: src/testsuites/bench.c
function runBench (line 15) | static void runBench(const void *o1, const void *o2, const ccd_t *ccd)
function boxbox (line 34) | static void boxbox(void)
function cylcyl (line 123) | void cylcyl(void)
function boxcyl (line 175) | void boxcyl(void)
function main (line 242) | int main(int argc, char *argv[])
FILE: src/testsuites/bench2.c
function runBench (line 15) | static void runBench(const void *o1, const void *o2, const ccd_t *ccd)
function boxbox (line 34) | static void boxbox(void)
function cylcyl (line 125) | void cylcyl(void)
function boxcyl (line 179) | void boxcyl(void)
function main (line 248) | int main(int argc, char *argv[])
FILE: src/testsuites/boxbox.c
function TEST (line 10) | TEST(boxboxSetUp)
function TEST (line 14) | TEST(boxboxTearDown)
function TEST (line 18) | TEST(boxboxAlignedX)
function TEST (line 102) | TEST(boxboxAlignedY)
function TEST (line 138) | TEST(boxboxAlignedZ)
function TEST (line 175) | TEST(boxboxRot)
function pConf (line 245) | static void pConf(ccd_box_t *box1, ccd_box_t *box2, const ccd_vec3_t *v)
function TEST (line 260) | TEST(boxboxSeparate)
function TEST (line 347) | TEST(boxboxPenetration)
FILE: src/testsuites/boxcyl.c
function TEST (line 14) | TEST(boxcylIntersect)
function TEST (line 80) | TEST(boxcylPenEPA)
FILE: src/testsuites/boxcyl.h
function TEST_SUITE (line 9) | TEST_SUITE(TSBoxCyl){
FILE: src/testsuites/common.c
function svtCyl (line 6) | static void svtCyl(ccd_cyl_t *c, FILE *out, const char *color, const cha...
function svtBox (line 77) | static void svtBox(ccd_box_t *b, FILE *out, const char *color, const cha...
function svtObj (line 118) | void svtObj(void *_o, FILE *out, const char *color, const char *name)
function svtObjPen (line 129) | void svtObjPen(void *o1, void *o2,
function recPen (line 164) | void recPen(ccd_real_t depth, const ccd_vec3_t *dir, const ccd_vec3_t *pos,
FILE: src/testsuites/cu/cu.c
function cu_run (line 82) | void cu_run(int argc, char *argv[])
function cu_run_fork (line 120) | static void cu_run_fork(const char *ts_name, cu_test_suite_t *ts)
function run_test_suite (line 186) | static void run_test_suite(const char *ts_name, cu_test_suite_t *ts)
function receive_messages (line 233) | static void receive_messages(void)
function cu_success_assertation (line 291) | void cu_success_assertation(void)
function cu_fail_assertation (line 296) | void cu_fail_assertation(const char *file, int line, const char *msg)
function cu_print_results (line 310) | static void cu_print_results(void)
function cu_set_out_prefix (line 328) | void cu_set_out_prefix(const char *str)
function redirect_out_err (line 333) | static void redirect_out_err(const char *test_name)
function close_out_err (line 350) | static void close_out_err(void)
type timespec (line 359) | struct timespec
type timespec (line 360) | struct timespec
type timespec (line 362) | struct timespec
function cuTimerStart (line 367) | void cuTimerStart(void)
type timespec (line 372) | struct timespec
FILE: src/testsuites/cu/cu.h
type cu_test_suite_t (line 110) | typedef struct _cu_test_suite_t {
type cu_test_suites_t (line 114) | typedef struct _cu_test_suites_t {
type timespec (line 141) | struct timespec
type timespec (line 146) | struct timespec
type timespec (line 157) | struct timespec
FILE: src/testsuites/cylcyl.c
function TEST (line 8) | TEST(cylcylSetUp)
function TEST (line 12) | TEST(cylcylTearDown)
function TEST (line 17) | TEST(cylcylAlignedX)
function TEST (line 48) | TEST(cylcylAlignedY)
function TEST (line 79) | TEST(cylcylAlignedZ)
function TEST (line 116) | TEST(cylcylPenetrationEPA)
FILE: src/testsuites/cylcyl.h
function TEST_SUITE (line 15) | TEST_SUITE(TSCylCyl) {
FILE: src/testsuites/main.c
function main (line 26) | int main(int argc, char *argv[])
FILE: src/testsuites/mpr_boxbox.c
function TEST (line 11) | TEST(mprBoxboxAlignedX)
function TEST (line 95) | TEST(mprBoxboxAlignedY)
function TEST (line 133) | TEST(mprBoxboxAlignedZ)
function TEST (line 172) | TEST(mprBoxboxRot)
function pConf (line 244) | static void pConf(ccd_box_t *box1, ccd_box_t *box2, const ccd_vec3_t *v)
function TEST (line 259) | TEST(mprBoxboxSeparate)
function TEST (line 348) | TEST(mprBoxboxPenetration)
FILE: src/testsuites/mpr_boxbox.h
function TEST_SUITE (line 15) | TEST_SUITE(TSMPRBoxBox) {
FILE: src/testsuites/mpr_boxcyl.c
function TEST (line 12) | TEST(mprBoxcylIntersect)
function TEST (line 81) | TEST(mprBoxcylPen)
FILE: src/testsuites/mpr_boxcyl.h
function TEST_SUITE (line 9) | TEST_SUITE(TSMPRBoxCyl){
FILE: src/testsuites/mpr_cylcyl.c
function TEST (line 8) | TEST(mprCylcylAlignedX)
function TEST (line 41) | TEST(mprCylcylAlignedY)
function TEST (line 74) | TEST(mprCylcylAlignedZ)
function TEST (line 113) | TEST(mprCylcylPenetration)
FILE: src/testsuites/mpr_cylcyl.h
function TEST_SUITE (line 12) | TEST_SUITE(TSMPRCylCyl) {
FILE: src/testsuites/polytope.c
function TEST (line 6) | TEST(ptSetUp)
function TEST (line 10) | TEST(ptTearDown)
function TEST (line 15) | TEST(ptCreate1)
function TEST (line 95) | TEST(ptCreate2)
function TEST (line 221) | TEST(ptNearest)
FILE: src/testsuites/polytope.h
function TEST_SUITE (line 13) | TEST_SUITE(TSPt) {
FILE: src/testsuites/spheresphere.c
function TEST (line 6) | TEST(spheresphereSetUp)
function TEST (line 10) | TEST(spheresphereTearDown)
function TEST (line 14) | TEST(spheresphereAlignedX)
function TEST (line 43) | TEST(spheresphereAlignedY)
function TEST (line 72) | TEST(spheresphereAlignedZ)
FILE: src/testsuites/spheresphere.h
function TEST_SUITE (line 13) | TEST_SUITE(TSSphereSphere) {
FILE: src/testsuites/support.c
function ccdSupport (line 22) | void ccdSupport(const void *_obj, const ccd_vec3_t *_dir,
function ccdObjCenter (line 77) | void ccdObjCenter(const void *_obj, ccd_vec3_t *center)
FILE: src/testsuites/support.h
type _ccd_obj_t (line 40) | struct _ccd_obj_t {
type ccd_obj_t (line 43) | typedef struct _ccd_obj_t ccd_obj_t;
type _ccd_box_t (line 45) | struct _ccd_box_t {
type ccd_box_t (line 49) | typedef struct _ccd_box_t ccd_box_t;
type _ccd_sphere_t (line 51) | struct _ccd_sphere_t {
type ccd_sphere_t (line 55) | typedef struct _ccd_sphere_t ccd_sphere_t;
type _ccd_cyl_t (line 57) | struct _ccd_cyl_t {
type ccd_cyl_t (line 62) | typedef struct _ccd_cyl_t ccd_cyl_t;
FILE: src/testsuites/vec3.c
function TEST (line 5) | TEST(vec3SetUp)
function TEST (line 9) | TEST(vec3TearDown)
function TEST (line 14) | TEST(vec3PointSegmentDist)
function TEST (line 156) | TEST(vec3PointTriDist)
FILE: src/testsuites/vec3.h
function TEST_SUITE (line 11) | TEST_SUITE(TSVec3) {
FILE: src/vec3.c
function _ccd_inline (line 73) | _ccd_inline ccd_real_t __ccdVec3PointSegmentDist2(const ccd_vec3_t *P,
function ccd_real_t (line 130) | ccd_real_t ccdVec3PointSegmentDist2(const ccd_vec3_t *P,
function ccd_real_t (line 137) | ccd_real_t ccdVec3PointTriDist2(const ccd_vec3_t *P,
Condensed preview — 103 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (356K chars).
[
{
"path": ".gitignore",
"chars": 149,
"preview": "Makefile.in\nautom4te.cache/*\naclocal.m4\nconfig.guess\nconfig.sub\nconfigure\ndepcomp\ninstall-sh\nltmain.sh\nmissing\n*~\nsrc/gj"
},
{
"path": ".travis.yml",
"chars": 581,
"preview": "dist: trusty\nsudo: required\n\nlanguage: c\ncompiler:\n - gcc\n - clang\n\nenv:\n global:\n - PREFIX=\"$TRAVIS_BUILD_DIR/bui"
},
{
"path": "BSD-LICENSE",
"chars": 2070,
"preview": "libccd\n-------\n\nCopyright (c)2010-2012 Daniel Fiser <danfis@danfis.cz>,\nIntelligent and Mobile Robotics Group, Departmen"
},
{
"path": "CMakeLists.txt",
"chars": 2204,
"preview": "cmake_minimum_required(VERSION 2.8.11)\n\nif(POLICY CMP0042)\n cmake_policy(SET CMP0042 NEW)\nendif()\n\n# Can not explicitly"
},
{
"path": "Makefile.am",
"chars": 79,
"preview": "SUBDIRS = src\n\nEXTRA_DIST = doc \\\n\tBSD-LICENSE \\\n\tREADME.md \\\n\tmake-release.sh\n"
},
{
"path": "README.md",
"chars": 9765,
"preview": "# libccd [](https://travis-ci.org/danfis/libccd)\n\n"
},
{
"path": "bootstrap",
"chars": 87,
"preview": "#!/bin/sh\n\nlibtoolize -f -c\naclocal\nautoheader -f\nautoconf\nautomake -a --foreign -f -c\n"
},
{
"path": "ccd-config.cmake.in",
"chars": 401,
"preview": "@PACKAGE_INIT@\n\nset(CCD_VERSION_MAJOR @CCD_VERSION_MAJOR@)\nset(CCD_VERSION_MINOR @CCD_VERSION_MINOR@)\nset(CCD_VERSION @C"
},
{
"path": "ccd.pc.in",
"chars": 382,
"preview": "# Generated by CMake @CMAKE_VERSION@ for ccd\n\nprefix=@CMAKE_INSTALL_PREFIX@\nexec_prefix=${prefix}\nlibdir=${prefix}/@CMAK"
},
{
"path": "configure.ac",
"chars": 1304,
"preview": "# -*- Autoconf -*-\n# Process this file with autoconf to produce a configur"
},
{
"path": "doc/CMakeLists.txt",
"chars": 1231,
"preview": "find_program(SPHINX_EXECUTABLE NAMES sphinx-build sphinx-build2)\n\nif(NOT SPHINX_EXECUTABLE)\n message(FATAL_ERROR \"Could"
},
{
"path": "doc/Makefile",
"chars": 7606,
"preview": "# Makefile for Sphinx documentation\n#\n\n# You can set these variables from the command line.\nSPHINXOPTS =\nSPHINXBUILD "
},
{
"path": "doc/_build/.dir",
"chars": 0,
"preview": ""
},
{
"path": "doc/_static/.dir",
"chars": 0,
"preview": ""
},
{
"path": "doc/_templates/.dir",
"chars": 0,
"preview": ""
},
{
"path": "doc/compile-and-install.rst",
"chars": 2720,
"preview": "Compile And Install\n====================\n\nlibccd contains several mechanisms for compiling and installing.\nUsing a simpl"
},
{
"path": "doc/conf.py",
"chars": 9814,
"preview": "# -*- coding: utf-8 -*-\n#\n# libccd documentation build configuration file, created by\n# sphinx-quickstart on Fri Sep 9 "
},
{
"path": "doc/examples.rst",
"chars": 6269,
"preview": "Example of Usage\n=================\n\n1. GJK - Intersection Test\n---------------------------\nThis section describes how to"
},
{
"path": "doc/index.rst",
"chars": 397,
"preview": ".. libccd documentation master file, created by\n sphinx-quickstart2 on Thu May 23 13:49:12 2013.\n\nlibccd's documentati"
},
{
"path": "doc/reference.rst",
"chars": 88,
"preview": "Reference\n==========\n\n.. literalinclude:: ../src/ccd/ccd.h\n :language: c\n :linenos:\n"
},
{
"path": "make-release.sh",
"chars": 636,
"preview": "#!/bin/bash\n\n# Creates .tar.gz package of specified version.\n# Takes one argument - identification of commit\n\nNAME=libcc"
},
{
"path": "src/.gitignore",
"chars": 38,
"preview": "*.o\n*.a\nccd/config.h\nccd/config.h.in\n\n"
},
{
"path": "src/CMakeLists.txt",
"chars": 2180,
"preview": "if(DEFINED CCD_SINGLE OR DEFINED CCD_DOUBLE)\n # make sure only DOUBLE or SINGLE is set; default to SINGLE\n if(CCD_SING"
},
{
"path": "src/Makefile",
"chars": 2353,
"preview": "###\n# libccd\n# ---------------------------------\n# Copyright (c)2010 Daniel Fiser <danfis@danfis.cz>\n#\n#\n# This file is"
},
{
"path": "src/Makefile.am",
"chars": 319,
"preview": "SUBDIRS = . testsuites\n\nlib_LTLIBRARIES = libccd.la\n\nlibccd_la_SOURCES = alloc.h \\\n\t\tccd/compiler.h \\\n\t\tdbg.h \\\n\t\tccd.c "
},
{
"path": "src/Makefile.include",
"chars": 1928,
"preview": "###\n# libccd\n# ---------------------------------\n# Copyright (c)2010 Daniel Fiser <danfis@danfis.cz>\n#\n#\n# This file is"
},
{
"path": "src/alloc.h",
"chars": 1349,
"preview": "/***\n * libccd\n * ---------------------------------\n * Copyright (c)2010 Daniel Fiser <danfis@danfis.cz>\n *\n *\n * This "
},
{
"path": "src/ccd/ccd.h",
"chars": 5287,
"preview": "/***\n * libccd\n * ---------------------------------\n * Copyright (c)2010,2011 Daniel Fiser <danfis@danfis.cz>\n *\n *\n * "
},
{
"path": "src/ccd/ccd_export.h",
"chars": 620,
"preview": "#ifndef CCD_EXPORT_H\n#define CCD_EXPORT_H\n\n#ifdef CCD_STATIC_DEFINE\n# define CCD_EXPORT\n#else\n# ifdef _MSC_VER\n# if"
},
{
"path": "src/ccd/compiler.h",
"chars": 1672,
"preview": "/***\n * libccd\n * ---------------------------------\n * Copyright (c)2010 Daniel Fiser <danfis@danfis.cz>\n *\n *\n * This "
},
{
"path": "src/ccd/config.h.cmake.in",
"chars": 130,
"preview": "#ifndef __CCD_CONFIG_H__\n#define __CCD_CONFIG_H__\n\n#cmakedefine CCD_SINGLE\n#cmakedefine CCD_DOUBLE\n\n#endif /* __CCD_CONF"
},
{
"path": "src/ccd/config.h.m4",
"chars": 166,
"preview": "#ifndef __CCD_CONFIG_H__\n#define __CCD_CONFIG_H__\n\nifdef(`USE_SINGLE', `#define CCD_SINGLE')\nifdef(`USE_DOUBLE', `#defin"
},
{
"path": "src/ccd/quat.h",
"chars": 5621,
"preview": "/***\n * libccd\n * ---------------------------------\n * Copyright (c)2010 Daniel Fiser <danfis@danfis.cz>\n *\n *\n * This "
},
{
"path": "src/ccd/vec3.h",
"chars": 8187,
"preview": "/***\n * libccd\n * ---------------------------------\n * Copyright (c)2010-2013 Daniel Fiser <danfis@danfis.cz>\n *\n *\n * "
},
{
"path": "src/ccd.c",
"chars": 31674,
"preview": "/***\n * libccd\n * ---------------------------------\n * Copyright (c)2012 Daniel Fiser <danfis@danfis.cz>\n *\n *\n * This "
},
{
"path": "src/dbg.h",
"chars": 1713,
"preview": "/***\n * libccd\n * ---------------------------------\n * Copyright (c)2010 Daniel Fiser <danfis@danfis.cz>\n *\n *\n * This "
},
{
"path": "src/list.h",
"chars": 3750,
"preview": "/***\n * libccd\n * ---------------------------------\n * Copyright (c)2010 Daniel Fiser <danfis@danfis.cz>\n *\n *\n * This "
},
{
"path": "src/mpr.c",
"chars": 18667,
"preview": "/***\n * libccd\n * ---------------------------------\n * Copyright (c)2010,2011 Daniel Fiser <danfis@danfis.cz>\n *\n *\n * "
},
{
"path": "src/polytope.c",
"chars": 7476,
"preview": "/***\n * libccd\n * ---------------------------------\n * Copyright (c)2010 Daniel Fiser <danfis@danfis.cz>\n *\n *\n * This "
},
{
"path": "src/polytope.h",
"chars": 8569,
"preview": "/***\n * libccd\n * ---------------------------------\n * Copyright (c)2010 Daniel Fiser <danfis@danfis.cz>\n *\n *\n * This "
},
{
"path": "src/simplex.h",
"chars": 2751,
"preview": "/***\n * libccd\n * ---------------------------------\n * Copyright (c)2010 Daniel Fiser <danfis@danfis.cz>\n *\n *\n * This "
},
{
"path": "src/support.c",
"chars": 928,
"preview": "/***\n * libccd\n * ---------------------------------\n * Copyright (c)2010 Daniel Fiser <danfis@danfis.cz>\n *\n *\n * This "
},
{
"path": "src/support.h",
"chars": 1438,
"preview": "/***\n * libccd\n * ---------------------------------\n * Copyright (c)2010 Daniel Fiser <danfis@danfis.cz>\n *\n *\n * This "
},
{
"path": "src/testsuites/.gitignore",
"chars": 52,
"preview": "regressions/tmp.*\nbench-out/*\n*.o\ntest\nbench\nbench2\n"
},
{
"path": "src/testsuites/CMakeLists.txt",
"chars": 847,
"preview": "add_subdirectory(cu)\n\nset(MAIN_SOURCES\n main.c\n common.c\n common.h\n support.c\n support.h\n vec3.c\n vec3.h\n polyto"
},
{
"path": "src/testsuites/Makefile",
"chars": 1467,
"preview": "# force some options\nDEBUG = yes\n\n-include ../Makefile.include\nCFLAGS += -I./ -I../ -Icu/\nLDFLAGS += -L./ -Lcu/ -lcu -lr"
},
{
"path": "src/testsuites/Makefile.am",
"chars": 595,
"preview": "SUBDIRS = cu\n\nAM_CPPFLAGS = -I $(srcdir)/.. -I $(builddir)/.. -I $(srcdir)/cu\n\nLDADD = $(builddir)/cu/libcu.la $(builddi"
},
{
"path": "src/testsuites/bench.c",
"chars": 6499,
"preview": "#define CU_ENABLE_TIMER\n#include <cu/cu.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <ccd/ccd.h>\n#include \"support"
},
{
"path": "src/testsuites/bench2.c",
"chars": 6691,
"preview": "#define CU_ENABLE_TIMER\n#include <cu/cu.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <ccd/ccd.h>\n#include \"support"
},
{
"path": "src/testsuites/boxbox.c",
"chars": 11212,
"preview": "#include <stdio.h>\n#include <cu/cu.h>\n\n#include <ccd/ccd.h>\n#include \"support.h\"\n#include \"../dbg.h\"\n#include \"common.h\""
},
{
"path": "src/testsuites/boxbox.h",
"chars": 522,
"preview": "#ifndef BOX_BOX\n#define BOX_BOX\n\n#include <cu/cu.h>\n\nTEST(boxboxSetUp);\nTEST(boxboxTearDown);\n\nTEST(boxboxAlignedX);\nTES"
},
{
"path": "src/testsuites/boxcyl.c",
"chars": 4600,
"preview": "#include <cu/cu.h>\n#include <ccd/ccd.h>\n#include \"common.h\"\n#include \"support.h\"\n\n\n#define TOSVT() \\\n svtObjPen(&box,"
},
{
"path": "src/testsuites/boxcyl.h",
"chars": 225,
"preview": "#ifndef TEST_BOXCYL_H\n#define TEST_BOXCYL_H\n\n#include <cu/cu.h>\n\nTEST(boxcylIntersect);\nTEST(boxcylPenEPA);\n\nTEST_SUITE("
},
{
"path": "src/testsuites/common.c",
"chars": 5345,
"preview": "#include <ccd/vec3.h>\n#include <ccd/quat.h>\n#include \"common.h\"\n#include \"support.h\"\n\nstatic void svtCyl(ccd_cyl_t *c, F"
},
{
"path": "src/testsuites/common.h",
"chars": 438,
"preview": "#ifndef TEST_COMMON\n#define TEST_COMMON\n\n#include <stdio.h>\n#include <ccd/vec3.h>\n\nvoid svtObj(void *o, FILE *out, const"
},
{
"path": "src/testsuites/cu/.dir",
"chars": 0,
"preview": ""
},
{
"path": "src/testsuites/cu/.gitignore",
"chars": 23,
"preview": "*~\n*.o\n*.a\ntmp.*\ntest\n\n"
},
{
"path": "src/testsuites/cu/CMakeLists.txt",
"chars": 470,
"preview": "set(CU_SOURCES\n cu.c\n cu.h)\n\nadd_library(cu STATIC ${CU_SOURCES})\n\nif(NOT APPLE)\n target_compile_definitions(cu PUBLI"
},
{
"path": "src/testsuites/cu/COPYING",
"chars": 35147,
"preview": " GNU GENERAL PUBLIC LICENSE\n Version 3, 29 June 2007\n\n Copyright (C) 2007 Free "
},
{
"path": "src/testsuites/cu/COPYING.LESSER",
"chars": 7639,
"preview": "\t\t GNU LESSER GENERAL PUBLIC LICENSE\n Version 3, 29 June 2007\n\n Copyright (C) 2007 Free Software"
},
{
"path": "src/testsuites/cu/Makefile",
"chars": 853,
"preview": "CC ?= gcc\nCFLAGS = -g -Wall -pedantic\n\nENABLE_TIMER ?= no\n\nifeq '$(ENABLE_TIMER)' 'yes'\n CFLAGS += -DCU_ENABLE_TIMER\nen"
},
{
"path": "src/testsuites/cu/Makefile.am",
"chars": 93,
"preview": "AM_CPPFLAGS = -DCU_ENABLE_TIMER\n\ncheck_LTLIBRARIES = libcu.la\n\nlibcu_la_SOURCES = cu.c cu.h\n\n"
},
{
"path": "src/testsuites/cu/check-regressions",
"chars": 13205,
"preview": "#!/usr/bin/python\n##\n# CU - C unit testing framework\n# ---------------------------------\n# Copyright (c)2007,2008 Daniel"
},
{
"path": "src/testsuites/cu/cu.c",
"chars": 10691,
"preview": "/***\n * CU - C unit testing framework\n * ---------------------------------\n * Copyright (c)2007,2008,2009 Daniel Fiser <"
},
{
"path": "src/testsuites/cu/cu.h",
"chars": 3902,
"preview": "/***\n * CU - C unit testing framework\n * ---------------------------------\n * Copyright (c)2007,2008,2009 Daniel Fiser <"
},
{
"path": "src/testsuites/cu/latest.sh",
"chars": 274,
"preview": "#!/bin/bash\n\nrepo=http://git.danfis.cz/cu.git\nfiles=\"COPYING \\\n COPYING.LESSER \\\n cu.h \\\n cu.c \\\n "
},
{
"path": "src/testsuites/cylcyl.c",
"chars": 3967,
"preview": "#include <stdio.h>\n#include <cu/cu.h>\n#include <ccd/ccd.h>\n#include \"support.h\"\n#include \"common.h\"\n\n\nTEST(cylcylSetUp)\n"
},
{
"path": "src/testsuites/cylcyl.h",
"chars": 435,
"preview": "#ifndef CYL_CYL\n#define CYL_CYL\n\n#include <cu/cu.h>\n\nTEST(cylcylSetUp);\nTEST(cylcylTearDown);\n\nTEST(cylcylAlignedX);\nTES"
},
{
"path": "src/testsuites/main.c",
"chars": 637,
"preview": "#include \"vec3.h\"\n#include \"polytope.h\"\n#include \"boxbox.h\"\n#include \"spheresphere.h\"\n#include \"cylcyl.h\"\n#include \"boxc"
},
{
"path": "src/testsuites/mpr_boxbox.c",
"chars": 12589,
"preview": "#include <stdio.h>\n#include <cu/cu.h>\n\n#include <ccd/ccd.h>\n#include <ccd/vec3.h>\n#include \"../dbg.h\"\n#include \"support."
},
{
"path": "src/testsuites/mpr_boxbox.h",
"chars": 469,
"preview": "#ifndef MPR_BOX_BOX\n#define MPR_BOX_BOX\n\n#include <cu/cu.h>\n\nTEST(mprBoxboxAlignedX);\nTEST(mprBoxboxAlignedY);\nTEST(mprB"
},
{
"path": "src/testsuites/mpr_boxcyl.c",
"chars": 4730,
"preview": "#include <cu/cu.h>\n#include <ccd/ccd.h>\n#include \"common.h\"\n#include \"support.h\"\n\n#define TOSVT() \\\n svtObjPen(&box, "
},
{
"path": "src/testsuites/mpr_boxcyl.h",
"chars": 242,
"preview": "#ifndef MPR_TEST_BOXCYL_H\n#define MPR_TEST_BOXCYL_H\n\n#include <cu/cu.h>\n\nTEST(mprBoxcylIntersect);\nTEST(mprBoxcylPen);\n\n"
},
{
"path": "src/testsuites/mpr_cylcyl.c",
"chars": 4189,
"preview": "#include <stdio.h>\n#include <cu/cu.h>\n#include <ccd/ccd.h>\n#include \"support.h\"\n#include \"common.h\"\n\n\nTEST(mprCylcylAlig"
},
{
"path": "src/testsuites/mpr_cylcyl.h",
"chars": 364,
"preview": "#ifndef MPR_CYL_CYL\n#define MPR_CYL_CYL\n\n#include <cu/cu.h>\n\nTEST(mprCylcylAlignedX);\nTEST(mprCylcylAlignedY);\nTEST(mprC"
},
{
"path": "src/testsuites/polytope.c",
"chars": 12558,
"preview": "//#undef NDEBUG\n#include <cu/cu.h>\n#include \"../polytope.h\"\n#include \"../dbg.h\"\n\nTEST(ptSetUp)\n{\n}\n\nTEST(ptTearDown)\n{\n}"
},
{
"path": "src/testsuites/polytope.h",
"chars": 334,
"preview": "#ifndef TEST_POLYTOPE_H\n#define TEST_POLYTOPE_H\n\n#include <cu/cu.h>\n\nTEST(ptSetUp);\nTEST(ptTearDown);\n\nTEST(ptCreate1);\n"
},
{
"path": "src/testsuites/regressions/.dir",
"chars": 0,
"preview": ""
},
{
"path": "src/testsuites/regressions/TSBoxBox.err",
"chars": 63,
"preview": "\n\n\n---- boxboxSeparate ----\n\n\n\n\n\n---- boxboxPenetration ----\n\n\n"
},
{
"path": "src/testsuites/regressions/TSBoxBox.out",
"chars": 1402,
"preview": "# box1.pos: [-0.500000 0.000000 0.000000]\n# box1->quat: [0.000000 0.000000 0.382683 0.923880]\n# box2->pos: [0.000000 0.0"
},
{
"path": "src/testsuites/regressions/TSBoxCyl.err",
"chars": 0,
"preview": ""
},
{
"path": "src/testsuites/regressions/TSBoxCyl.out",
"chars": 943,
"preview": "# Pen 1: depth: 0.549996\n# Pen 1: dir: [0.999992 -0.003902 0.000000]\n# Pen 1: pos: [0.020284 0.000000 0.000000]\n#\n# "
},
{
"path": "src/testsuites/regressions/TSCylCyl.err",
"chars": 33,
"preview": "\n\n\n---- cylcylPenetration ----\n\n\n"
},
{
"path": "src/testsuites/regressions/TSCylCyl.out",
"chars": 716,
"preview": "# Pen 1: depth: 0.750000\n# Pen 1: dir: [0.000000 0.000000 1.000000]\n# Pen 1: pos: [0.004079 -0.012238 0.009615]\n#\n# "
},
{
"path": "src/testsuites/regressions/TSMPRBoxBox.err",
"chars": 63,
"preview": "\n\n\n---- boxboxSeparate ----\n\n\n\n\n\n---- boxboxPenetration ----\n\n\n"
},
{
"path": "src/testsuites/regressions/TSMPRBoxBox.out",
"chars": 1640,
"preview": "# box1.pos: [-0.500000 0.000000 0.000000]\n# box1->quat: [0.000000 0.000000 0.382683 0.923880]\n# box2->pos: [0.000000 0.0"
},
{
"path": "src/testsuites/regressions/TSMPRBoxCyl.err",
"chars": 0,
"preview": ""
},
{
"path": "src/testsuites/regressions/TSMPRBoxCyl.out",
"chars": 945,
"preview": "# Pen 1: depth: 0.550000\n# Pen 1: dir: [1.000000 0.000000 0.000000]\n# Pen 1: pos: [-0.025000 0.000000 0.000000]\n#\n# "
},
{
"path": "src/testsuites/regressions/TSMPRCylCyl.err",
"chars": 36,
"preview": "\n\n\n---- mprCylcylPenetration ----\n\n\n"
},
{
"path": "src/testsuites/regressions/TSMPRCylCyl.out",
"chars": 714,
"preview": "# Pen 1: depth: 0.450000\n# Pen 1: dir: [0.000000 0.000000 1.000000]\n# Pen 1: pos: [0.000000 0.000000 0.025000]\n#\n# P"
},
{
"path": "src/testsuites/regressions/TSPt.err",
"chars": 1725,
"preview": "ptCreate1 :: ------\nptCreate1 :: e[0]->dist: 0.200000\nptCreate1 :: ->witness: [0.200000 -0.400000 0.000000]\nptCreat"
},
{
"path": "src/testsuites/regressions/TSPt.out",
"chars": 0,
"preview": ""
},
{
"path": "src/testsuites/regressions/TSSphereSphere.err",
"chars": 0,
"preview": ""
},
{
"path": "src/testsuites/regressions/TSSphereSphere.out",
"chars": 0,
"preview": ""
},
{
"path": "src/testsuites/regressions/TSVec3.err",
"chars": 0,
"preview": ""
},
{
"path": "src/testsuites/regressions/TSVec3.out",
"chars": 0,
"preview": ""
},
{
"path": "src/testsuites/spheresphere.c",
"chars": 1665,
"preview": "#include <stdio.h>\n#include <cu/cu.h>\n#include <ccd/ccd.h>\n#include \"support.h\"\n\nTEST(spheresphereSetUp)\n{\n}\n\nTEST(spher"
},
{
"path": "src/testsuites/spheresphere.h",
"chars": 446,
"preview": "#ifndef SPHERE_SPHERE\n#define SPHERE_SPHERE\n\n#include <cu/cu.h>\n\nTEST(spheresphereSetUp);\nTEST(spheresphereTearDown);\n\nT"
},
{
"path": "src/testsuites/support.c",
"chars": 2636,
"preview": "/***\n * libccd\n * ---------------------------------\n * Copyright (c)2010 Daniel Fiser <danfis@danfis.cz>\n *\n *\n * This "
},
{
"path": "src/testsuites/support.h",
"chars": 2514,
"preview": "/***\n * libccd\n * ---------------------------------\n * Copyright (c)2010 Daniel Fiser <danfis@danfis.cz>\n *\n *\n * This "
},
{
"path": "src/testsuites/vec3.c",
"chars": 8457,
"preview": "#include <stdio.h>\n#include <cu/cu.h>\n#include <ccd/vec3.h>\n\nTEST(vec3SetUp)\n{\n}\n\nTEST(vec3TearDown)\n{\n}\n\n\nTEST(vec3Poin"
},
{
"path": "src/testsuites/vec3.h",
"chars": 328,
"preview": "#ifndef TEST_VEC3_H\n#define TEST_VEC3_H\n\n#include <cu/cu.h>\n\nTEST(vec3SetUp);\nTEST(vec3TearDown);\nTEST(vec3PointSegmentD"
},
{
"path": "src/vec3.c",
"chars": 8969,
"preview": "/***\n * libccd\n * ---------------------------------\n * Copyright (c)2010 Daniel Fiser <danfis@danfis.cz>\n *\n *\n * This "
}
]
About this extraction
This page contains the full source code of the danfis/libccd GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 103 files (329.3 KB), approximately 110.0k tokens, and a symbol index with 227 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.