Commit f2f96fc3 authored by Leopold Palomo's avatar Leopold Palomo

Imported Upstream version 0.13.1

parent 38c1d387
This diff is collapsed.
ODE is dual-licensed under either:
* GNU Lesser General Public License v 2.1 or later.
see LICENSE.TXT
* Modified 3-clause BSD license.
see LICENSE-BSD.TXT
Third-party libraries bundled with ODE:
* GIMPACT: dual-licensed under either:
- GNU Lesser General Public License v 2.1 or later.
see GIMPACT-LICENSE-LGPL.TXT
- Modified 3-clause BSD license.
see GIMPACT/GIMPACT-LICENSE-BSD.TXT
* libccd: Modified 3-clause BSD License
see libccd/BSD-LICENSE
* OU/ODER: triple-licensed under either:
- GNU Lesser General Public License v 3 or later.
see ou/LICENSE.TXT
see ou/LICENSE-LESSER.TXT
- Modified 3-clause BSD license.
see ou/LICENSE-BSD.TXT
- ZLIB license.
see ou/LICENSE-ZLIB.TXT
* OPCODE: under the same terms as ODE
see OPCODE/COPYING
GIMPACT : Geometric tools for VR.
Copyright (c) 2006 , Francisco León.
All rights reserved.
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 GIMPACT 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 OWNER 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.
\ No newline at end of file
This diff is collapsed.
EXTRA_DIST = GIMPACT-LICENSE-BSD.TXT GIMPACT-LICENSE-LGPL.TXT
SUBDIRS = include src
This diff is collapsed.
noinst_HEADERS = \
gim_boxpruning.h gim_contact.h gim_geometry.h \
gim_math.h gim_memory.h gimpact.h \
gim_radixsort.h gim_tri_capsule_collision.h gim_tri_collision.h \
gim_trimesh.h gim_tri_sphere_collision.h
This diff is collapsed.
This diff is collapsed.
#ifndef GIM_CONTACT_H_INCLUDED
#define GIM_CONTACT_H_INCLUDED
/*! \file gim_contact.h
\author Francisco Len
*/
/*
-----------------------------------------------------------------------------
This source file is part of GIMPACT Library.
For the latest info, see http://gimpact.sourceforge.net/
Copyright (c) 2006 Francisco Leon. C.C. 80087371.
email: projectileman@yahoo.com
This library is free software; you can redistribute it and/or
modify it under the terms of EITHER:
(1) The GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at
your option) any later version. The text of the GNU Lesser
General Public License is included with this library in the
file GIMPACT-LICENSE-LGPL.TXT.
(2) The BSD-style license that is included with this library in
the file GIMPACT-LICENSE-BSD.TXT.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files
GIMPACT-LICENSE-LGPL.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
-----------------------------------------------------------------------------
*/
#include "GIMPACT/gim_geometry.h"
#include "GIMPACT/gim_radixsort.h"
/*! \defgroup CONTACTS
\brief
Functions for managing and sorting contacts resulting from a collision query.
<ul>
<li> Contact lists must be create by calling \ref GIM_CREATE_CONTACT_LIST
<li> After querys, contact lists must be destroy by calling \ref GIM_DYNARRAY_DESTROY
<li> Contacts can be merge for avoid duplicate results by calling \ref gim_merge_contacts
</ul>
*/
//! @{
/// Structure for collision results
struct GIM_CONTACT
{
vec3f m_point;
vec3f m_normal;
GREAL m_depth;//Positive value indicates interpenetration
void * m_handle1;
void * m_handle2;
GUINT32 m_feature1;//Face number
GUINT32 m_feature2;//Face number
};
//typedef struct _GIM_CONTACT GIM_CONTACT;
#define CONTACT_DIFF_EPSILON 0.00001f
#define GIM_CALC_KEY_CONTACT(pos,hash)\
{\
GINT32 _coords[] = {(GINT32)(pos[0]*1000.0f+1.0f),(GINT32)(pos[1]*1333.0f),(GINT32)(pos[2]*2133.0f+3.0f)};\
GUINT32 _hash=0;\
GUINT32 *_uitmp = (GUINT32 *)(&_coords[0]);\
_hash = *_uitmp;\
_uitmp++;\
_hash += (*_uitmp)<<4;\
_uitmp++;\
_hash += (*_uitmp)<<8;\
hash = _hash;\
}\
///Creates a contact list for queries
#define GIM_CREATE_CONTACT_LIST(contact_array) GIM_DYNARRAY_CREATE(GIM_CONTACT,contact_array,100)
#define GIM_PUSH_CONTACT(contact_array, point, normal, deep,handle1, handle2, feat1, feat2)\
{\
GIM_DYNARRAY_PUSH_EMPTY(GIM_CONTACT,contact_array);\
GIM_CONTACT * _last = GIM_DYNARRAY_POINTER_LAST(GIM_CONTACT,contact_array);\
VEC_COPY(_last->m_point,point);\
VEC_COPY(_last->m_normal,normal);\
_last->m_depth = deep;\
_last->m_handle1 = handle1;\
_last->m_handle2 = handle2;\
_last->m_feature1 = feat1;\
_last->m_feature2 = feat2;\
}\
///Receive pointer to contacts
#define GIM_COPY_CONTACTS(dest_contact, source_contact)\
{\
VEC_COPY(dest_contact->m_point,source_contact->m_point);\
VEC_COPY(dest_contact->m_normal,source_contact->m_normal);\
dest_contact->m_depth = source_contact->m_depth;\
dest_contact->m_handle1 = source_contact->m_handle1;\
dest_contact->m_handle2 = source_contact->m_handle2;\
dest_contact->m_feature1 = source_contact->m_feature1;\
dest_contact->m_feature2 = source_contact->m_feature2;\
}\
//! Merges duplicate contacts with minimum depth criterion
void gim_merge_contacts(GDYNAMIC_ARRAY * source_contacts,
GDYNAMIC_ARRAY * dest_contacts);
//! Merges to an unique contact
void gim_merge_contacts_unique(GDYNAMIC_ARRAY * source_contacts,
GDYNAMIC_ARRAY * dest_contacts);
//! @}
#endif // GIM_CONTACT_H_INCLUDED
This diff is collapsed.
#ifndef GIM_MATH_H_INCLUDED
#define GIM_MATH_H_INCLUDED
/*! \file gim_math.h
\author Francisco Len
*/
/*
-----------------------------------------------------------------------------
This source file is part of GIMPACT Library.
For the latest info, see http://gimpact.sourceforge.net/
Copyright (c) 2006 Francisco Leon. C.C. 80087371.
email: projectileman@yahoo.com
This library is free software; you can redistribute it and/or
modify it under the terms of EITHER:
(1) The GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at
your option) any later version. The text of the GNU Lesser
General Public License is included with this library in the
file GIMPACT-LICENSE-LGPL.TXT.
(2) The BSD-style license that is included with this library in
the file GIMPACT-LICENSE-BSD.TXT.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files
GIMPACT-LICENSE-LGPL.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
-----------------------------------------------------------------------------
*/
#include "config.h"
#include <math.h>
#include <float.h>
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#elif defined(_MSC_VER)
typedef __int32 int32_t;
typedef unsigned __int32 uint32_t;
#elif defined(__GNUC__)
#include <inttypes.h>
#else
#error "GIMPACT: Must define int32_t and uint32_t"
#endif
/*! \defgroup BASIC_TYPES
Basic types and constants
Conventions:
Types starting with G
Constants starting with G_
*/
//! @{
/*! Types */
#define GREAL float
#define GINT32 int32_t
#define GUINT32 uint32_t
#define GPTR void*
/*! Constants for integers*/
#define GUINT32_BIT_COUNT 32
#define GUINT32_EXPONENT 5
#define G_FASTMATH 1
#define G_PI 3.14159265358979f
#define G_HALF_PI 1.5707963f
//267948966
#define G_TWO_PI 6.28318530f
//71795864
#define G_ROOT3 1.73205f
#define G_ROOT2 1.41421f
#define G_UINT_INFINITY 65534
#define G_REAL_INFINITY FLT_MAX
#define G_SIGN_BITMASK 0x80000000
#define G_USE_EPSILON_TEST
#define G_EPSILON 0.0000001f
//! @}
/*! \defgroup MATH_FUNCTIONS
mathematical functions
*/
//! @{
#define G_DEGTORAD(X) ((X)*3.1415926f/180.0f)
#define G_RADTODEG(X) ((X)*180.0f/3.1415926f)
//! Integer representation of a floating-point value.
#define IR(x) ((GUINT32&)(x))
//! Signed integer representation of a floating-point value.
#define SIR(x) ((GINT32&)(x))
//! Absolute integer representation of a floating-point value
#define AIR(x) (IR(x)&0x7fffffff)
//! Floating-point representation of an integer value.
#define FR(x) ((GREAL&)(x))
#define MAX(a,b) ((a)<(b)?(b):(a))
#define MIN(a,b) ((a)>(b)?(b):(a))
#define MAX3(a,b,c) MAX(a,MAX(b,c))
#define MIN3(a,b,c) MIN(a,MIN(b,c))
#define IS_ZERO(value) ((value) < G_EPSILON && (value) > -G_EPSILON)
#define IS_NEGATIVE(value) ((value) <= -G_EPSILON)
#define IS_POSISITVE(value) ((value) >= G_EPSILON)
///returns a clamped number
#define CLAMP(number,minval,maxval) ((number)<(minval)?(minval):((number)>(maxval)?(maxval):(number)))
///Swap numbers
#define SWAP_NUMBERS(a,b){ \
(a) = (a)+(b); \
(b) = (a)-(b); \
(a) = (a)-(b); \
}\
#define GIM_INV_SQRT(va,isva)\
{\
if((va)<=0.0000001f)\
{\
(isva) = G_REAL_INFINITY;\
}\
else\
{\
GREAL _x = (va) * 0.5f;\
GUINT32 _y = 0x5f3759df - ( IR(va) >> 1);\
(isva) = FR(_y);\
(isva) = (isva) * ( 1.5f - ( _x * (isva) * (isva) ) );\
}\
}\
#define GIM_SQRT(va,sva)\
{\
GIM_INV_SQRT(va,sva);\
(sva) = 1.0f/(sva);\
}\
//! Computes 1.0f / sqrtf(x). Comes from Quake3. See http://www.magic-software.com/3DGEDInvSqrt.html
GREAL gim_inv_sqrt(GREAL f);
//! Computes sqrtf(x) faster.
/*!
\sa gim_inv_sqrt
*/
GREAL gim_sqrt(GREAL f);
//!Initializes mathematical functions
void gim_init_math();
//! Generates an unit random
GREAL gim_unit_random();
//! @}
#endif // GIM_MATH_H_INCLUDED
This diff is collapsed.
#ifndef GIM_RADIXSORT_H_INCLUDED
#define GIM_RADIXSORT_H_INCLUDED
/*! \file gim_radixsort.h
\author Francisco Len.
Based on the work of Michael Herf : "fast floating-point radix sort"
Avaliable on http://www.stereopsis.com/radix.html
*/
/*
-----------------------------------------------------------------------------
This source file is part of GIMPACT Library.
For the latest info, see http://gimpact.sourceforge.net/
Copyright (c) 2006 Francisco Leon. C.C. 80087371.
email: projectileman@yahoo.com
This library is free software; you can redistribute it and/or
modify it under the terms of EITHER:
(1) The GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at
your option) any later version. The text of the GNU Lesser
General Public License is included with this library in the
file GIMPACT-LICENSE-LGPL.TXT.
(2) The BSD-style license that is included with this library in
the file GIMPACT-LICENSE-BSD.TXT.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files
GIMPACT-LICENSE-LGPL.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
-----------------------------------------------------------------------------
*/
#include "GIMPACT/gim_memory.h"
/*! \defgroup SORTING
\brief
Macros for sorting.
*/
//! @{
struct GIM_RSORT_TOKEN
{
GUINT32 m_key;
GUINT32 m_value;
};
//typedef struct _GIM_RSORT_TOKEN GIM_RSORT_TOKEN;
//comparator for sorting
#define RSORT_TOKEN_COMPARATOR(x, y) ((int)((x.m_key) - (y.m_key)))
// ---- utils for accessing 11-bit quantities
#define D11_0(x) (x & 0x7FF)
#define D11_1(x) (x >> 11 & 0x7FF)
#define D11_2(x) (x >> 22 )
//COMMON FUNCTIONS FOR ACCESSING THE KEY OF AN ELEMENT
//For the type of your array, you need to declare a macro for obtaining the key, like these:
#define SIMPLE_GET_FLOAT32KEY(e,key) {key =(GREAL)(e);}
#define SIMPLE_GET_INTKEY(e,key) {key =(GINT32)(e);}
#define SIMPLE_GET_UINTKEY(e,key) {key =(GUINT32)(e);}
//For the type of your array, you need to declare a macro for copy elements, like this:
#define SIMPLE_COPY_ELEMENTS(dest,src) {dest = src;}
#define kHist 2048
///Radix sort for unsigned integer keys
#define GIM_RADIX_SORT_RTOKENS(array,sorted,element_count)\
{\
GUINT32 i;\
GUINT32 b0[kHist * 3];\
GUINT32 *b1 = b0 + kHist;\
GUINT32 *b2 = b1 + kHist;\
for (i = 0; i < kHist * 3; i++)\
{\
b0[i] = 0;\
}\
GUINT32 fi;\
GUINT32 pos;\
for (i = 0; i < element_count; i++)\
{\
fi = array[i].m_key;\
b0[D11_0(fi)] ++;\
b1[D11_1(fi)] ++;\
b2[D11_2(fi)] ++;\
}\
{\
GUINT32 sum0 = 0, sum1 = 0, sum2 = 0;\
GUINT32 tsum;\
for (i = 0; i < kHist; i++)\
{\
tsum = b0[i] + sum0;\
b0[i] = sum0 - 1;\
sum0 = tsum;\