moved Extras/Gimpact to src/BulletCollision/Gimpact
moved Extras/BulletMultiThreaded to src/BulletMultiThreaded (build systems will be updated soon)
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
INCLUDE_DIRECTORIES(
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/Extras/GIMPACT/include
|
||||
${BULLET_PHYSICS_SOURCE_DIR}/src
|
||||
)
|
||||
|
||||
ADD_LIBRARY(LibGIMPACT
|
||||
src/Bullet/btContactProcessing.cpp
|
||||
src/Bullet/btGImpactBvh.cpp
|
||||
src/Bullet/btGImpactQuantizedBvh.cpp
|
||||
src/Bullet/btTriangleShapeEx.cpp
|
||||
src/Bullet/btGImpactCollisionAlgorithm.cpp
|
||||
src/Bullet/btGImpactShape.cpp
|
||||
src/core/gim_box_set.cpp
|
||||
src/core/gim_contact.cpp
|
||||
src/core/gim_memory.cpp
|
||||
src/core/gim_tri_collision.cpp
|
||||
)
|
||||
@@ -1,263 +0,0 @@
|
||||
# Doxyfile 1.5.2
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Project related configuration options
|
||||
#---------------------------------------------------------------------------
|
||||
DOXYFILE_ENCODING = UTF-8
|
||||
PROJECT_NAME = GIMPACT
|
||||
PROJECT_NUMBER = 0.2
|
||||
OUTPUT_DIRECTORY = docs
|
||||
CREATE_SUBDIRS = NO
|
||||
OUTPUT_LANGUAGE = English
|
||||
BRIEF_MEMBER_DESC = YES
|
||||
REPEAT_BRIEF = YES
|
||||
ABBREVIATE_BRIEF = "The $name class" \
|
||||
"The $name widget" \
|
||||
"The $name file" \
|
||||
is \
|
||||
provides \
|
||||
specifies \
|
||||
contains \
|
||||
represents \
|
||||
a \
|
||||
an \
|
||||
the
|
||||
ALWAYS_DETAILED_SEC = NO
|
||||
INLINE_INHERITED_MEMB = NO
|
||||
FULL_PATH_NAMES = YES
|
||||
STRIP_FROM_PATH = "C:/Documents and Settings/Administrador/"
|
||||
STRIP_FROM_INC_PATH =
|
||||
SHORT_NAMES = NO
|
||||
JAVADOC_AUTOBRIEF = NO
|
||||
MULTILINE_CPP_IS_BRIEF = NO
|
||||
DETAILS_AT_TOP = NO
|
||||
INHERIT_DOCS = YES
|
||||
SEPARATE_MEMBER_PAGES = NO
|
||||
TAB_SIZE = 8
|
||||
ALIASES =
|
||||
OPTIMIZE_OUTPUT_FOR_C = NO
|
||||
OPTIMIZE_OUTPUT_JAVA = NO
|
||||
BUILTIN_STL_SUPPORT = NO
|
||||
CPP_CLI_SUPPORT = NO
|
||||
DISTRIBUTE_GROUP_DOC = NO
|
||||
SUBGROUPING = YES
|
||||
#---------------------------------------------------------------------------
|
||||
# Build related configuration options
|
||||
#---------------------------------------------------------------------------
|
||||
EXTRACT_ALL = YES
|
||||
EXTRACT_PRIVATE = YES
|
||||
EXTRACT_STATIC = YES
|
||||
EXTRACT_LOCAL_CLASSES = YES
|
||||
EXTRACT_LOCAL_METHODS = NO
|
||||
HIDE_UNDOC_MEMBERS = NO
|
||||
HIDE_UNDOC_CLASSES = NO
|
||||
HIDE_FRIEND_COMPOUNDS = NO
|
||||
HIDE_IN_BODY_DOCS = NO
|
||||
INTERNAL_DOCS = NO
|
||||
CASE_SENSE_NAMES = NO
|
||||
HIDE_SCOPE_NAMES = NO
|
||||
SHOW_INCLUDE_FILES = YES
|
||||
INLINE_INFO = YES
|
||||
SORT_MEMBER_DOCS = YES
|
||||
SORT_BRIEF_DOCS = NO
|
||||
SORT_BY_SCOPE_NAME = NO
|
||||
GENERATE_TODOLIST = YES
|
||||
GENERATE_TESTLIST = YES
|
||||
GENERATE_BUGLIST = YES
|
||||
GENERATE_DEPRECATEDLIST= YES
|
||||
ENABLED_SECTIONS =
|
||||
MAX_INITIALIZER_LINES = 30
|
||||
SHOW_USED_FILES = YES
|
||||
SHOW_DIRECTORIES = NO
|
||||
FILE_VERSION_FILTER =
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to warning and progress messages
|
||||
#---------------------------------------------------------------------------
|
||||
QUIET = NO
|
||||
WARNINGS = YES
|
||||
WARN_IF_UNDOCUMENTED = YES
|
||||
WARN_IF_DOC_ERROR = YES
|
||||
WARN_NO_PARAMDOC = NO
|
||||
WARN_FORMAT = "$file:$line: $text"
|
||||
WARN_LOGFILE =
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the input files
|
||||
#---------------------------------------------------------------------------
|
||||
INPUT = include
|
||||
INPUT_ENCODING = UTF-8
|
||||
FILE_PATTERNS = *.c \
|
||||
*.cc \
|
||||
*.cxx \
|
||||
*.cpp \
|
||||
*.c++ \
|
||||
*.d \
|
||||
*.java \
|
||||
*.ii \
|
||||
*.ixx \
|
||||
*.ipp \
|
||||
*.i++ \
|
||||
*.inl \
|
||||
*.h \
|
||||
*.hh \
|
||||
*.hxx \
|
||||
*.hpp \
|
||||
*.h++ \
|
||||
*.idl \
|
||||
*.odl \
|
||||
*.cs \
|
||||
*.php \
|
||||
*.php3 \
|
||||
*.inc \
|
||||
*.m \
|
||||
*.mm \
|
||||
*.dox \
|
||||
*.py
|
||||
RECURSIVE = YES
|
||||
EXCLUDE =
|
||||
EXCLUDE_SYMLINKS = NO
|
||||
EXCLUDE_PATTERNS =
|
||||
EXCLUDE_SYMBOLS =
|
||||
EXAMPLE_PATH =
|
||||
EXAMPLE_PATTERNS = *
|
||||
EXAMPLE_RECURSIVE = NO
|
||||
IMAGE_PATH =
|
||||
INPUT_FILTER =
|
||||
FILTER_PATTERNS =
|
||||
FILTER_SOURCE_FILES = NO
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to source browsing
|
||||
#---------------------------------------------------------------------------
|
||||
SOURCE_BROWSER = NO
|
||||
INLINE_SOURCES = NO
|
||||
STRIP_CODE_COMMENTS = YES
|
||||
REFERENCED_BY_RELATION = NO
|
||||
REFERENCES_RELATION = NO
|
||||
REFERENCES_LINK_SOURCE = YES
|
||||
USE_HTAGS = NO
|
||||
VERBATIM_HEADERS = NO
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the alphabetical class index
|
||||
#---------------------------------------------------------------------------
|
||||
ALPHABETICAL_INDEX = NO
|
||||
COLS_IN_ALPHA_INDEX = 5
|
||||
IGNORE_PREFIX =
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the HTML output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_HTML = YES
|
||||
HTML_OUTPUT = html
|
||||
HTML_FILE_EXTENSION = .html
|
||||
HTML_HEADER =
|
||||
HTML_FOOTER =
|
||||
HTML_STYLESHEET =
|
||||
HTML_ALIGN_MEMBERS = YES
|
||||
GENERATE_HTMLHELP = NO
|
||||
CHM_FILE =
|
||||
HHC_LOCATION =
|
||||
GENERATE_CHI = NO
|
||||
BINARY_TOC = NO
|
||||
TOC_EXPAND = NO
|
||||
DISABLE_INDEX = NO
|
||||
ENUM_VALUES_PER_LINE = 4
|
||||
GENERATE_TREEVIEW = NO
|
||||
TREEVIEW_WIDTH = 250
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the LaTeX output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_LATEX = YES
|
||||
LATEX_OUTPUT = latex
|
||||
LATEX_CMD_NAME = latex
|
||||
MAKEINDEX_CMD_NAME = makeindex
|
||||
COMPACT_LATEX = NO
|
||||
PAPER_TYPE = a4wide
|
||||
EXTRA_PACKAGES =
|
||||
LATEX_HEADER =
|
||||
PDF_HYPERLINKS = NO
|
||||
USE_PDFLATEX = NO
|
||||
LATEX_BATCHMODE = NO
|
||||
LATEX_HIDE_INDICES = NO
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the RTF output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_RTF = NO
|
||||
RTF_OUTPUT = rtf
|
||||
COMPACT_RTF = NO
|
||||
RTF_HYPERLINKS = NO
|
||||
RTF_STYLESHEET_FILE =
|
||||
RTF_EXTENSIONS_FILE =
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the man page output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_MAN = NO
|
||||
MAN_OUTPUT = man
|
||||
MAN_EXTENSION = .3
|
||||
MAN_LINKS = NO
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the XML output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_XML = NO
|
||||
XML_OUTPUT = xml
|
||||
XML_SCHEMA =
|
||||
XML_DTD =
|
||||
XML_PROGRAMLISTING = YES
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options for the AutoGen Definitions output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_AUTOGEN_DEF = NO
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the Perl module output
|
||||
#---------------------------------------------------------------------------
|
||||
GENERATE_PERLMOD = NO
|
||||
PERLMOD_LATEX = NO
|
||||
PERLMOD_PRETTY = YES
|
||||
PERLMOD_MAKEVAR_PREFIX =
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to the preprocessor
|
||||
#---------------------------------------------------------------------------
|
||||
ENABLE_PREPROCESSING = YES
|
||||
MACRO_EXPANSION = NO
|
||||
EXPAND_ONLY_PREDEF = NO
|
||||
SEARCH_INCLUDES = YES
|
||||
INCLUDE_PATH =
|
||||
INCLUDE_FILE_PATTERNS =
|
||||
PREDEFINED =
|
||||
EXPAND_AS_DEFINED =
|
||||
SKIP_FUNCTION_MACROS = YES
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration::additions related to external references
|
||||
#---------------------------------------------------------------------------
|
||||
TAGFILES =
|
||||
GENERATE_TAGFILE =
|
||||
ALLEXTERNALS = NO
|
||||
EXTERNAL_GROUPS = YES
|
||||
PERL_PATH = /usr/bin/perl
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to the dot tool
|
||||
#---------------------------------------------------------------------------
|
||||
CLASS_DIAGRAMS = YES
|
||||
MSCGEN_PATH =
|
||||
HIDE_UNDOC_RELATIONS = YES
|
||||
HAVE_DOT = NO
|
||||
CLASS_GRAPH = YES
|
||||
COLLABORATION_GRAPH = YES
|
||||
GROUP_GRAPHS = YES
|
||||
UML_LOOK = NO
|
||||
TEMPLATE_RELATIONS = NO
|
||||
INCLUDE_GRAPH = YES
|
||||
INCLUDED_BY_GRAPH = YES
|
||||
CALL_GRAPH = NO
|
||||
CALLER_GRAPH = NO
|
||||
GRAPHICAL_HIERARCHY = YES
|
||||
DIRECTORY_GRAPH = YES
|
||||
DOT_IMAGE_FORMAT = png
|
||||
DOT_PATH =
|
||||
DOTFILE_DIRS =
|
||||
DOT_GRAPH_MAX_NODES = 50
|
||||
DOT_TRANSPARENT = NO
|
||||
DOT_MULTI_TARGETS = NO
|
||||
GENERATE_LEGEND = YES
|
||||
DOT_CLEANUP = YES
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration::additions related to the search engine
|
||||
#---------------------------------------------------------------------------
|
||||
SEARCHENGINE = NO
|
||||
@@ -1,29 +0,0 @@
|
||||
GIMPACT : Geometric tools for VR.
|
||||
|
||||
Copyright (c) 2006 , Francisco Le<4C>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.
|
||||
@@ -1,502 +0,0 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 2.1, February 1999
|
||||
|
||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[This is the first released version of the Lesser GPL. It also counts
|
||||
as the successor of the GNU Library Public License, version 2, hence
|
||||
the version number 2.1.]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Lesser General Public License, applies to some
|
||||
specially designated software packages--typically libraries--of the
|
||||
Free Software Foundation and other authors who decide to use it. You
|
||||
can use it too, but we suggest you first think carefully about whether
|
||||
this license or the ordinary General Public License is the better
|
||||
strategy to use in any particular case, based on the explanations below.
|
||||
|
||||
When we speak of free software, we are referring to freedom of use,
|
||||
not price. Our General Public Licenses are designed to make sure that
|
||||
you have the freedom to distribute copies of free software (and charge
|
||||
for this service if you wish); that you receive source code or can get
|
||||
it if you want it; that you can change the software and use pieces of
|
||||
it in new free programs; and that you are informed that you can do
|
||||
these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
distributors to deny you these rights or to ask you to surrender these
|
||||
rights. These restrictions translate to certain responsibilities for
|
||||
you if you distribute copies of the library or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link other code with the library, you must provide
|
||||
complete object files to the recipients, so that they can relink them
|
||||
with the library after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with a two-step method: (1) we copyright the
|
||||
library, and (2) we offer you this license, which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
To protect each distributor, we want to make it very clear that
|
||||
there is no warranty for the free library. Also, if the library is
|
||||
modified by someone else and passed on, the recipients should know
|
||||
that what they have is not the original version, so that the original
|
||||
author's reputation will not be affected by problems that might be
|
||||
introduced by others.
|
||||
|
||||
Finally, software patents pose a constant threat to the existence of
|
||||
any free program. We wish to make sure that a company cannot
|
||||
effectively restrict the users of a free program by obtaining a
|
||||
restrictive license from a patent holder. Therefore, we insist that
|
||||
any patent license obtained for a version of the library must be
|
||||
consistent with the full freedom of use specified in this license.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the
|
||||
ordinary GNU General Public License. This license, the GNU Lesser
|
||||
General Public License, applies to certain designated libraries, and
|
||||
is quite different from the ordinary General Public License. We use
|
||||
this license for certain libraries in order to permit linking those
|
||||
libraries into non-free programs.
|
||||
|
||||
When a program is linked with a library, whether statically or using
|
||||
a shared library, the combination of the two is legally speaking a
|
||||
combined work, a derivative of the original library. The ordinary
|
||||
General Public License therefore permits such linking only if the
|
||||
entire combination fits its criteria of freedom. The Lesser General
|
||||
Public License permits more lax criteria for linking other code with
|
||||
the library.
|
||||
|
||||
We call this license the "Lesser" General Public License because it
|
||||
does Less to protect the user's freedom than the ordinary General
|
||||
Public License. It also provides other free software developers Less
|
||||
of an advantage over competing non-free programs. These disadvantages
|
||||
are the reason we use the ordinary General Public License for many
|
||||
libraries. However, the Lesser license provides advantages in certain
|
||||
special circumstances.
|
||||
|
||||
For example, on rare occasions, there may be a special need to
|
||||
encourage the widest possible use of a certain library, so that it becomes
|
||||
a de-facto standard. To achieve this, non-free programs must be
|
||||
allowed to use the library. A more frequent case is that a free
|
||||
library does the same job as widely used non-free libraries. In this
|
||||
case, there is little to gain by limiting the free library to free
|
||||
software only, so we use the Lesser General Public License.
|
||||
|
||||
In other cases, permission to use a particular library in non-free
|
||||
programs enables a greater number of people to use a large body of
|
||||
free software. For example, permission to use the GNU C Library in
|
||||
non-free programs enables many more people to use the whole GNU
|
||||
operating system, as well as its variant, the GNU/Linux operating
|
||||
system.
|
||||
|
||||
Although the Lesser General Public License is Less protective of the
|
||||
users' freedom, it does ensure that the user of a program that is
|
||||
linked with the Library has the freedom and the wherewithal to run
|
||||
that program using a modified version of the Library.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, whereas the latter must
|
||||
be combined with the library in order to run.
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library or other
|
||||
program which contains a notice placed by the copyright holder or
|
||||
other authorized party saying it may be distributed under the terms of
|
||||
this Lesser General Public License (also called "this License").
|
||||
Each licensee is addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also combine or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (1) uses at run time a
|
||||
copy of the library already present on the user's computer system,
|
||||
rather than copying library functions into the executable, and (2)
|
||||
will operate properly with a modified version of the library, if
|
||||
the user installs one, as long as the modified version is
|
||||
interface-compatible with the version that the work was made with.
|
||||
|
||||
c) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
d) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
e) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the materials to be distributed need not include anything that is
|
||||
normally distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties with
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Lesser General Public License from time to time.
|
||||
Such new versions will be similar in spirit to the present version,
|
||||
but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Libraries
|
||||
|
||||
If you develop a new library, and you want it to be of the greatest
|
||||
possible use to the public, we recommend making it free software that
|
||||
everyone can redistribute and change. You can do so by permitting
|
||||
redistribution under these terms (or, alternatively, under the terms of the
|
||||
ordinary General Public License).
|
||||
|
||||
To apply these terms, attach the following notices to the library. It is
|
||||
safest to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least the
|
||||
"copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the library's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of 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.
|
||||
|
||||
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 GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the library, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
||||
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1990
|
||||
Ty Coon, President of Vice
|
||||
|
||||
That's all there is to it!
|
||||
@@ -1,23 +0,0 @@
|
||||
GIMPACT : Geometric tools for VR.
|
||||
|
||||
Copyright (c) 2006 , Francisco Le<4C>n.
|
||||
All rights reserved.
|
||||
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty. In no
|
||||
event will the authors be held liable for any damages arising from the use of this
|
||||
software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose, including commercial
|
||||
applications, and to alter it and redistribute it freely, subject to the following
|
||||
restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that
|
||||
you wrote the original software. If you use this software in a product, an
|
||||
acknowledgment in the product documentation would be appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
SubDir TOP Extras GIMPACT ;
|
||||
|
||||
#IncludeDir Extras/GIMPACT/include ;
|
||||
SubInclude TOP Extras GIMPACT include ;
|
||||
|
||||
Library GIMPACT : [ Wildcard src/Bullet : */.h *.cpp ] [ Wildcard src/core : *.cpp ] : noinstall ;
|
||||
CFlags GIMPACT : [ FIncludes $(TOP)/Extras/GIMPACT/include ] ;
|
||||
LibDepends GIMPACT : ;
|
||||
|
||||
MsvcIncDirs GIMPACT :
|
||||
"../../Extras/GIMPACT/include" ;
|
||||
|
||||
InstallHeader [ Wildcard *.h ] : GIMPACT ;
|
||||
@@ -1,137 +0,0 @@
|
||||
#ifndef GIM_MANUAL_H_INCLUDED
|
||||
#define GIM_MANUAL_H_INCLUDED
|
||||
|
||||
/*! \file gim_manual.h
|
||||
*\author Francisco Le<4C>n N<>jera
|
||||
GIMPACT documentation
|
||||
|
||||
*/
|
||||
/*
|
||||
This source file is part of GIMPACT Library.
|
||||
|
||||
For the latest info, see http://gimpact.sourceforge.net/
|
||||
|
||||
Copyright (c) 2007 Francisco Leon Najera. C.C. 80087371.
|
||||
email: projectileman@yahoo.com
|
||||
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
/*! \mainpage GIMPACT
|
||||
*\section INTRO INTRODUCTION
|
||||
<p>
|
||||
<b>GIMPACT</b> is a software library with tools for geometry processing and collision detection, focused on solving most common problems on Virtual Reality development.
|
||||
</p>
|
||||
<p>
|
||||
Since Version 0.2, <b>GIMPACT</b> will work integrated with the <b>Bullet Engine</b> for general collision detection and physics. For more details, please visit http://www.continuousphysics.com/Bullet/
|
||||
</p>
|
||||
<p>For updates, please visit http://sourceforge.net/projects/gimpact/ </p>
|
||||
|
||||
*\section CONTENT
|
||||
- \subpage FEATURES
|
||||
- \subpage REQUIREMENTS
|
||||
- \subpage PROGRAMMERS_GUIDE "PROGRAMMERS GUIDE"
|
||||
- \subpage TODO
|
||||
*/
|
||||
/*! \page FEATURES
|
||||
- C++ oriented.
|
||||
- Extensible design.
|
||||
- Collision detection algorithm for concave shapes in the <b>Bullet Physics Engine</b>. See btGImpactCollisionAlgorithm.
|
||||
- Efficient Dynamic <b>Hierarcht Bounding Box tree structures</b> for handle collisions with composed shapes whose have large sets of primitives (triangles or convex shapes) See the GIM_BOX_TREE_SET class.
|
||||
- Collision detection for trimeshes with the btGImpactMeshShape class. Now <b>GIMPACT</b> works fine with the btStridingInterface class for getting the data from trimesh models.
|
||||
- Support for deformable trimeshes.
|
||||
- Collision detection for compound shapes through the btGImpactCompoundShape class. This class takes advantage from the Hierarcht Bounding Box structure (GIM_BOX_TREE_SET class).
|
||||
- Collision Shapes (Both btGImpactCompoundSape and btGImpactTrimeshShape ) can be shared by two or more Rigid Bodies in <b>Bullet</b>.
|
||||
|
||||
*/
|
||||
/*! \page REQUIREMENTS
|
||||
- GIMPACT has dependencies to the <a href = "http://www.continuousphysics.com/Bullet/"> Bullet Physics Engine</a>.
|
||||
- Ansi C++ compiler,
|
||||
*/
|
||||
/*! \page PROGRAMMERS_GUIDE PROGRAMMERS GUIDE
|
||||
This guide will show how to incorpore the GIMPACt functionality on the Bullet Engine:
|
||||
*\section REG Registering the Algorithm
|
||||
For register this algorithm in Bullet, proceed as following:
|
||||
\code
|
||||
btCollisionDispatcher * dispatcher = static_cast<btCollisionDispatcher *>(m_dynamicsWorld ->getDispatcher());
|
||||
btGImpactCollisionAlgorithm::registerAlgorithm(dispatcher);
|
||||
\endcode
|
||||
</p>
|
||||
With the instructon above, btGImpactCollisionAlgorithm will handle:
|
||||
- Convex shapes vs GImpact shapes.
|
||||
- Concave shapes vs GImpact shapes.
|
||||
- Compoind shapes vs GImpact shapes.
|
||||
|
||||
*\section CREATING_SHAPES Creating Shapes.
|
||||
*\subsection TRIMESH Creating trimeshes.
|
||||
<p>For creating trimeshes you must provide an interface for your model data. You could use btTriangleIndexVertexArray class for providing the indices and the vertices from your triangle models.</p>
|
||||
<p>
|
||||
For example, you could create a trimesh from memory as following:
|
||||
\code
|
||||
btTriangleIndexVertexArray* indexVertexArrays = new btTriangleIndexVertexArray(NUM_TRIANGLES,
|
||||
&gIndices[0][0],
|
||||
3*sizeof(int),
|
||||
NUM_VERTICES,(REAL*) &gVertices[0],sizeof(REAL)*3);
|
||||
\endcode
|
||||
</p>
|
||||
<p>
|
||||
Where gIndices is an array of integers and gVertices is an array of float with 3 components.
|
||||
</p>
|
||||
Then you must create the Trimesh shape as following:
|
||||
\code
|
||||
btGImpactMeshShape * trimesh = new btGImpactMeshShape(indexVertexArrays);
|
||||
\endcode
|
||||
The next step is configuring the trimesh, for example changing the scale:
|
||||
\code
|
||||
trimesh->setLocalScaling(btVector3(4.f,4.f,4.f));
|
||||
\endcode
|
||||
At end, you must call btGImpactMeshShape.updateBound for ensure that the shape will build its internal Box set structure:
|
||||
\code
|
||||
trimesh->updateBound();// Call this method once before doing collisions
|
||||
\endcode
|
||||
Also you must call btGImpactMeshShape.postUpdate() each time when changing the trimesh data ( For deformable meshes), this will enable a flag to the trimesh shape which tells that the trimesh data has been changed and btGImpactMeshShape.updateBound will be called in collision routines.
|
||||
<
|
||||
|
||||
*\subsection COMPOUND Compound Shapes.
|
||||
For compound shapes, you must create btGImpactCompoundShape objects. Then you could add
|
||||
sub shapes as following;
|
||||
\code
|
||||
btGImpactCompoundShape * mycompound = new btGImpactCompoundShape();
|
||||
|
||||
btTransform localtransform;
|
||||
.... Setting transformation
|
||||
|
||||
//add shapes with transformation
|
||||
btCollisionShape * subshape = creatingShape(0);
|
||||
mycompound->addChildShape(localtransform,subshape);
|
||||
.... Setting transformation
|
||||
btCollisionShape * subshape2 = creatingShape(1);
|
||||
mycompound->addChildShape(localtransform,subshape);
|
||||
.... add more shapes
|
||||
\endcode
|
||||
At end, you must call btGImpactCompoundShape.updateBound for ensure that the shape will build its internal Box set structure:
|
||||
*/
|
||||
|
||||
/*! \page TODO
|
||||
*\section FEATURE FEATURE REQUESTS
|
||||
- Tetrahedrization for solid trimeshes.
|
||||
- Examples for implement deformable collisions, like cloth simulations and finite elements dynamics.
|
||||
- Generic Ray collision functionality.
|
||||
- Implement Low level SAT algorithms for speed up convex collisions.
|
||||
*\section MISCELANEOUS
|
||||
- Improve the documentation.
|
||||
- Benchmarking.
|
||||
- Bug reports and Bug Fixes.
|
||||
*/
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,4 +0,0 @@
|
||||
SubDir TOP Extras GIMPACT include ;
|
||||
|
||||
|
||||
Recurse InstallHeader : .h ;
|
||||
@@ -2,7 +2,7 @@
|
||||
#define BT_BOX_COLLISION_H_INCLUDED
|
||||
|
||||
/*! \file gim_box_collision.h
|
||||
\author Francisco León Nájera
|
||||
\author Francisco Len Nßjera
|
||||
*/
|
||||
/*
|
||||
This source file is part of GIMPACT Library.
|
||||
@@ -2,7 +2,7 @@
|
||||
#define BT_CLIP_POLYGON_H_INCLUDED
|
||||
|
||||
/*! \file btClipPolygon.h
|
||||
\author Francisco León Nájera
|
||||
\author Francisco Len Nßjera
|
||||
*/
|
||||
/*
|
||||
This source file is part of GIMPACT Library.
|
||||
@@ -1,181 +1,181 @@
|
||||
|
||||
/*
|
||||
This source file is part of GIMPACT Library.
|
||||
|
||||
For the latest info, see http://gimpact.sourceforge.net/
|
||||
|
||||
Copyright (c) 2007 Francisco Leon Najera. C.C. 80087371.
|
||||
email: projectileman@yahoo.com
|
||||
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "GIMPACT/Bullet/btContactProcessing.h"
|
||||
|
||||
#define MAX_COINCIDENT 8
|
||||
|
||||
struct CONTACT_KEY_TOKEN
|
||||
{
|
||||
unsigned int m_key;
|
||||
int m_value;
|
||||
CONTACT_KEY_TOKEN()
|
||||
{
|
||||
}
|
||||
|
||||
CONTACT_KEY_TOKEN(unsigned int key,int token)
|
||||
{
|
||||
m_key = key;
|
||||
m_value = token;
|
||||
}
|
||||
|
||||
CONTACT_KEY_TOKEN(const CONTACT_KEY_TOKEN& rtoken)
|
||||
{
|
||||
m_key = rtoken.m_key;
|
||||
m_value = rtoken.m_value;
|
||||
}
|
||||
|
||||
inline bool operator <(const CONTACT_KEY_TOKEN& other) const
|
||||
{
|
||||
return (m_key < other.m_key);
|
||||
}
|
||||
|
||||
inline bool operator >(const CONTACT_KEY_TOKEN& other) const
|
||||
{
|
||||
return (m_key > other.m_key);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class CONTACT_KEY_TOKEN_COMP
|
||||
{
|
||||
public:
|
||||
|
||||
bool operator() ( const CONTACT_KEY_TOKEN& a, const CONTACT_KEY_TOKEN& b )
|
||||
{
|
||||
return ( a < b );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void btContactArray::merge_contacts(
|
||||
const btContactArray & contacts, bool normal_contact_average)
|
||||
{
|
||||
clear();
|
||||
|
||||
int i;
|
||||
if(contacts.size()==0) return;
|
||||
|
||||
|
||||
if(contacts.size()==1)
|
||||
{
|
||||
push_back(contacts[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
btAlignedObjectArray<CONTACT_KEY_TOKEN> keycontacts;
|
||||
|
||||
keycontacts.reserve(contacts.size());
|
||||
|
||||
//fill key contacts
|
||||
|
||||
for ( i = 0;i<contacts.size() ;i++ )
|
||||
{
|
||||
keycontacts.push_back(CONTACT_KEY_TOKEN(contacts[i].calc_key_contact(),i));
|
||||
}
|
||||
|
||||
//sort keys
|
||||
keycontacts.quickSort(CONTACT_KEY_TOKEN_COMP());
|
||||
|
||||
// Merge contacts
|
||||
int coincident_count=0;
|
||||
btVector3 coincident_normals[MAX_COINCIDENT];
|
||||
|
||||
unsigned int last_key = keycontacts[0].m_key;
|
||||
unsigned int key = 0;
|
||||
|
||||
push_back(contacts[keycontacts[0].m_value]);
|
||||
|
||||
BT_CONTACT * pcontact = &(*this)[0];
|
||||
|
||||
for( i=1;i<keycontacts.size();i++)
|
||||
{
|
||||
key = keycontacts[i].m_key;
|
||||
const BT_CONTACT * scontact = &contacts[keycontacts[i].m_value];
|
||||
|
||||
if(last_key == key)//same points
|
||||
{
|
||||
//merge contact
|
||||
if(pcontact->m_depth - CONTACT_DIFF_EPSILON > scontact->m_depth)//)
|
||||
{
|
||||
*pcontact = *scontact;
|
||||
coincident_count = 0;
|
||||
}
|
||||
else if(normal_contact_average)
|
||||
{
|
||||
if(btFabs(pcontact->m_depth - scontact->m_depth)<CONTACT_DIFF_EPSILON)
|
||||
{
|
||||
if(coincident_count<MAX_COINCIDENT)
|
||||
{
|
||||
coincident_normals[coincident_count] = scontact->m_normal;
|
||||
coincident_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{//add new contact
|
||||
|
||||
if(normal_contact_average && coincident_count>0)
|
||||
{
|
||||
pcontact->interpolate_normals(coincident_normals,coincident_count);
|
||||
coincident_count = 0;
|
||||
}
|
||||
|
||||
push_back(*scontact);
|
||||
pcontact = &(*this)[this->size()-1];
|
||||
}
|
||||
last_key = key;
|
||||
}
|
||||
}
|
||||
|
||||
void btContactArray::merge_contacts_unique(const btContactArray & contacts)
|
||||
{
|
||||
clear();
|
||||
|
||||
if(contacts.size()==0) return;
|
||||
|
||||
if(contacts.size()==1)
|
||||
{
|
||||
push_back(contacts[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
BT_CONTACT average_contact = contacts[0];
|
||||
|
||||
for (int i=1;i<contacts.size() ;i++ )
|
||||
{
|
||||
average_contact.m_point += contacts[i].m_point;
|
||||
average_contact.m_normal += contacts[i].m_normal * contacts[i].m_depth;
|
||||
}
|
||||
|
||||
//divide
|
||||
btScalar divide_average = 1.0f/((btScalar)contacts.size());
|
||||
|
||||
average_contact.m_point *= divide_average;
|
||||
|
||||
average_contact.m_normal *= divide_average;
|
||||
|
||||
average_contact.m_depth = average_contact.m_normal.length();
|
||||
|
||||
average_contact.m_normal /= average_contact.m_depth;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
This source file is part of GIMPACT Library.
|
||||
|
||||
For the latest info, see http://gimpact.sourceforge.net/
|
||||
|
||||
Copyright (c) 2007 Francisco Leon Najera. C.C. 80087371.
|
||||
email: projectileman@yahoo.com
|
||||
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "btContactProcessing.h"
|
||||
|
||||
#define MAX_COINCIDENT 8
|
||||
|
||||
struct CONTACT_KEY_TOKEN
|
||||
{
|
||||
unsigned int m_key;
|
||||
int m_value;
|
||||
CONTACT_KEY_TOKEN()
|
||||
{
|
||||
}
|
||||
|
||||
CONTACT_KEY_TOKEN(unsigned int key,int token)
|
||||
{
|
||||
m_key = key;
|
||||
m_value = token;
|
||||
}
|
||||
|
||||
CONTACT_KEY_TOKEN(const CONTACT_KEY_TOKEN& rtoken)
|
||||
{
|
||||
m_key = rtoken.m_key;
|
||||
m_value = rtoken.m_value;
|
||||
}
|
||||
|
||||
inline bool operator <(const CONTACT_KEY_TOKEN& other) const
|
||||
{
|
||||
return (m_key < other.m_key);
|
||||
}
|
||||
|
||||
inline bool operator >(const CONTACT_KEY_TOKEN& other) const
|
||||
{
|
||||
return (m_key > other.m_key);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class CONTACT_KEY_TOKEN_COMP
|
||||
{
|
||||
public:
|
||||
|
||||
bool operator() ( const CONTACT_KEY_TOKEN& a, const CONTACT_KEY_TOKEN& b )
|
||||
{
|
||||
return ( a < b );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void btContactArray::merge_contacts(
|
||||
const btContactArray & contacts, bool normal_contact_average)
|
||||
{
|
||||
clear();
|
||||
|
||||
int i;
|
||||
if(contacts.size()==0) return;
|
||||
|
||||
|
||||
if(contacts.size()==1)
|
||||
{
|
||||
push_back(contacts[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
btAlignedObjectArray<CONTACT_KEY_TOKEN> keycontacts;
|
||||
|
||||
keycontacts.reserve(contacts.size());
|
||||
|
||||
//fill key contacts
|
||||
|
||||
for ( i = 0;i<contacts.size() ;i++ )
|
||||
{
|
||||
keycontacts.push_back(CONTACT_KEY_TOKEN(contacts[i].calc_key_contact(),i));
|
||||
}
|
||||
|
||||
//sort keys
|
||||
keycontacts.quickSort(CONTACT_KEY_TOKEN_COMP());
|
||||
|
||||
// Merge contacts
|
||||
int coincident_count=0;
|
||||
btVector3 coincident_normals[MAX_COINCIDENT];
|
||||
|
||||
unsigned int last_key = keycontacts[0].m_key;
|
||||
unsigned int key = 0;
|
||||
|
||||
push_back(contacts[keycontacts[0].m_value]);
|
||||
|
||||
BT_CONTACT * pcontact = &(*this)[0];
|
||||
|
||||
for( i=1;i<keycontacts.size();i++)
|
||||
{
|
||||
key = keycontacts[i].m_key;
|
||||
const BT_CONTACT * scontact = &contacts[keycontacts[i].m_value];
|
||||
|
||||
if(last_key == key)//same points
|
||||
{
|
||||
//merge contact
|
||||
if(pcontact->m_depth - CONTACT_DIFF_EPSILON > scontact->m_depth)//)
|
||||
{
|
||||
*pcontact = *scontact;
|
||||
coincident_count = 0;
|
||||
}
|
||||
else if(normal_contact_average)
|
||||
{
|
||||
if(btFabs(pcontact->m_depth - scontact->m_depth)<CONTACT_DIFF_EPSILON)
|
||||
{
|
||||
if(coincident_count<MAX_COINCIDENT)
|
||||
{
|
||||
coincident_normals[coincident_count] = scontact->m_normal;
|
||||
coincident_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{//add new contact
|
||||
|
||||
if(normal_contact_average && coincident_count>0)
|
||||
{
|
||||
pcontact->interpolate_normals(coincident_normals,coincident_count);
|
||||
coincident_count = 0;
|
||||
}
|
||||
|
||||
push_back(*scontact);
|
||||
pcontact = &(*this)[this->size()-1];
|
||||
}
|
||||
last_key = key;
|
||||
}
|
||||
}
|
||||
|
||||
void btContactArray::merge_contacts_unique(const btContactArray & contacts)
|
||||
{
|
||||
clear();
|
||||
|
||||
if(contacts.size()==0) return;
|
||||
|
||||
if(contacts.size()==1)
|
||||
{
|
||||
push_back(contacts[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
BT_CONTACT average_contact = contacts[0];
|
||||
|
||||
for (int i=1;i<contacts.size() ;i++ )
|
||||
{
|
||||
average_contact.m_point += contacts[i].m_point;
|
||||
average_contact.m_normal += contacts[i].m_normal * contacts[i].m_depth;
|
||||
}
|
||||
|
||||
//divide
|
||||
btScalar divide_average = 1.0f/((btScalar)contacts.size());
|
||||
|
||||
average_contact.m_point *= divide_average;
|
||||
|
||||
average_contact.m_normal *= divide_average;
|
||||
|
||||
average_contact.m_depth = average_contact.m_normal.length();
|
||||
|
||||
average_contact.m_normal /= average_contact.m_depth;
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define BT_CONTACT_H_INCLUDED
|
||||
|
||||
/*! \file gim_contact.h
|
||||
\author Francisco León Nájera
|
||||
\author Francisco Len Nßjera
|
||||
*/
|
||||
/*
|
||||
This source file is part of GIMPACT Library.
|
||||
@@ -26,7 +26,7 @@ subject to the following restrictions:
|
||||
|
||||
#include "LinearMath/btTransform.h"
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
#include "GIMPACT/Bullet/btTriangleShapeEx.h"
|
||||
#include "btTriangleShapeEx.h"
|
||||
|
||||
|
||||
/*! \defgroup CONTACTS
|
||||
@@ -1,5 +1,5 @@
|
||||
/*! \file gim_box_set.h
|
||||
\author Francisco León Nájera
|
||||
\author Francisco Len Nßjera
|
||||
*/
|
||||
/*
|
||||
This source file is part of GIMPACT Library.
|
||||
@@ -20,7 +20,7 @@ subject to the following restrictions:
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "GIMPACT/Bullet/btGImpactBvh.h"
|
||||
#include "btGImpactBvh.h"
|
||||
#include "LinearMath/btQuickprof.h"
|
||||
|
||||
#ifdef TRI_COLLISION_PROFILING
|
||||
@@ -2,7 +2,7 @@
|
||||
#define GIM_BOX_SET_H_INCLUDED
|
||||
|
||||
/*! \file gim_box_set.h
|
||||
\author Francisco León Nájera
|
||||
\author Francisco Len Nßjera
|
||||
*/
|
||||
/*
|
||||
This source file is part of GIMPACT Library.
|
||||
@@ -27,8 +27,8 @@ subject to the following restrictions:
|
||||
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
|
||||
#include "GIMPACT/Bullet/btBoxCollision.h"
|
||||
#include "GIMPACT/Bullet/btTriangleShapeEx.h"
|
||||
#include "btBoxCollision.h"
|
||||
#include "btTriangleShapeEx.h"
|
||||
|
||||
|
||||
|
||||
1792
Extras/GIMPACT/src/Bullet/btGImpactCollisionAlgorithm.cpp → src/BulletCollision/Gimpact/btGImpactCollisionAlgorithm.cpp
Executable file → Normal file
1792
Extras/GIMPACT/src/Bullet/btGImpactCollisionAlgorithm.cpp → src/BulletCollision/Gimpact/btGImpactCollisionAlgorithm.cpp
Executable file → Normal file
File diff suppressed because it is too large
Load Diff
612
Extras/GIMPACT/include/GIMPACT/Bullet/btGImpactCollisionAlgorithm.h → src/BulletCollision/Gimpact/btGImpactCollisionAlgorithm.h
Executable file → Normal file
612
Extras/GIMPACT/include/GIMPACT/Bullet/btGImpactCollisionAlgorithm.h → src/BulletCollision/Gimpact/btGImpactCollisionAlgorithm.h
Executable file → Normal file
@@ -1,306 +1,306 @@
|
||||
/*! \file btGImpactShape.h
|
||||
\author Francisco León Nájera
|
||||
*/
|
||||
/*
|
||||
This source file is part of GIMPACT Library.
|
||||
|
||||
For the latest info, see http://gimpact.sourceforge.net/
|
||||
|
||||
Copyright (c) 2007 Francisco Leon Najera. C.C. 80087371.
|
||||
email: projectileman@yahoo.com
|
||||
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef BVH_CONCAVE_COLLISION_ALGORITHM_H
|
||||
#define BVH_CONCAVE_COLLISION_ALGORITHM_H
|
||||
|
||||
#include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h"
|
||||
#include "BulletCollision/BroadphaseCollision/btDispatcher.h"
|
||||
#include "BulletCollision/BroadphaseCollision/btBroadphaseInterface.h"
|
||||
#include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
|
||||
class btDispatcher;
|
||||
#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
|
||||
#include "BulletCollision/CollisionDispatch/btCollisionCreateFunc.h"
|
||||
#include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h"
|
||||
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
|
||||
#include "GIMPACT/Bullet/btGImpactShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btStaticPlaneShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btCompoundShape.h"
|
||||
#include "BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h"
|
||||
#include "LinearMath/btIDebugDraw.h"
|
||||
|
||||
|
||||
|
||||
//! Collision Algorithm for GImpact Shapes
|
||||
/*!
|
||||
For register this algorithm in Bullet, proceed as following:
|
||||
\code
|
||||
btCollisionDispatcher * dispatcher = static_cast<btCollisionDispatcher *>(m_dynamicsWorld ->getDispatcher());
|
||||
btGImpactCollisionAlgorithm::registerAlgorithm(dispatcher);
|
||||
\endcode
|
||||
*/
|
||||
class btGImpactCollisionAlgorithm : public btCollisionAlgorithm
|
||||
{
|
||||
protected:
|
||||
btCollisionAlgorithm * m_convex_algorithm;
|
||||
btPersistentManifold * m_manifoldPtr;
|
||||
btManifoldResult* m_resultOut;
|
||||
const btDispatcherInfo * m_dispatchInfo;
|
||||
int m_triface0;
|
||||
int m_part0;
|
||||
int m_triface1;
|
||||
int m_part1;
|
||||
|
||||
|
||||
//! Creates a new contact point
|
||||
SIMD_FORCE_INLINE btPersistentManifold* newContactManifold(btCollisionObject* body0,btCollisionObject* body1)
|
||||
{
|
||||
m_manifoldPtr = m_dispatcher->getNewManifold(body0,body1);
|
||||
return m_manifoldPtr;
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE void destroyConvexAlgorithm()
|
||||
{
|
||||
if(m_convex_algorithm)
|
||||
{
|
||||
m_convex_algorithm->~btCollisionAlgorithm();
|
||||
m_dispatcher->freeCollisionAlgorithm( m_convex_algorithm);
|
||||
m_convex_algorithm = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE void destroyContactManifolds()
|
||||
{
|
||||
if(m_manifoldPtr == NULL) return;
|
||||
m_dispatcher->releaseManifold(m_manifoldPtr);
|
||||
m_manifoldPtr = NULL;
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE void clearCache()
|
||||
{
|
||||
destroyContactManifolds();
|
||||
destroyConvexAlgorithm();
|
||||
|
||||
m_triface0 = -1;
|
||||
m_part0 = -1;
|
||||
m_triface1 = -1;
|
||||
m_part1 = -1;
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE btPersistentManifold* getLastManifold()
|
||||
{
|
||||
return m_manifoldPtr;
|
||||
}
|
||||
|
||||
|
||||
// Call before process collision
|
||||
SIMD_FORCE_INLINE void checkManifold(btCollisionObject* body0,btCollisionObject* body1)
|
||||
{
|
||||
if(getLastManifold() == 0)
|
||||
{
|
||||
newContactManifold(body0,body1);
|
||||
}
|
||||
|
||||
m_resultOut->setPersistentManifold(getLastManifold());
|
||||
}
|
||||
|
||||
// Call before process collision
|
||||
SIMD_FORCE_INLINE btCollisionAlgorithm * newAlgorithm(btCollisionObject* body0,btCollisionObject* body1)
|
||||
{
|
||||
checkManifold(body0,body1);
|
||||
|
||||
btCollisionAlgorithm * convex_algorithm = m_dispatcher->findAlgorithm(
|
||||
body0,body1,getLastManifold());
|
||||
return convex_algorithm ;
|
||||
}
|
||||
|
||||
// Call before process collision
|
||||
SIMD_FORCE_INLINE void checkConvexAlgorithm(btCollisionObject* body0,btCollisionObject* body1)
|
||||
{
|
||||
if(m_convex_algorithm) return;
|
||||
m_convex_algorithm = newAlgorithm(body0,body1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void addContactPoint(btCollisionObject * body0,
|
||||
btCollisionObject * body1,
|
||||
const btVector3 & point,
|
||||
const btVector3 & normal,
|
||||
btScalar distance);
|
||||
|
||||
//! Collision routines
|
||||
//!@{
|
||||
|
||||
void collide_gjk_triangles(btCollisionObject * body0,
|
||||
btCollisionObject * body1,
|
||||
btGImpactMeshShapePart * shape0,
|
||||
btGImpactMeshShapePart * shape1,
|
||||
const int * pairs, int pair_count);
|
||||
|
||||
void collide_sat_triangles(btCollisionObject * body0,
|
||||
btCollisionObject * body1,
|
||||
btGImpactMeshShapePart * shape0,
|
||||
btGImpactMeshShapePart * shape1,
|
||||
const int * pairs, int pair_count);
|
||||
|
||||
|
||||
|
||||
|
||||
void shape_vs_shape_collision(
|
||||
btCollisionObject * body0,
|
||||
btCollisionObject * body1,
|
||||
btCollisionShape * shape0,
|
||||
btCollisionShape * shape1);
|
||||
|
||||
void convex_vs_convex_collision(btCollisionObject * body0,
|
||||
btCollisionObject * body1,
|
||||
btCollisionShape * shape0,
|
||||
btCollisionShape * shape1);
|
||||
|
||||
|
||||
|
||||
void gimpact_vs_gimpact_find_pairs(
|
||||
const btTransform & trans0,
|
||||
const btTransform & trans1,
|
||||
btGImpactShapeInterface * shape0,
|
||||
btGImpactShapeInterface * shape1,btPairSet & pairset);
|
||||
|
||||
void gimpact_vs_shape_find_pairs(
|
||||
const btTransform & trans0,
|
||||
const btTransform & trans1,
|
||||
btGImpactShapeInterface * shape0,
|
||||
btCollisionShape * shape1,
|
||||
btAlignedObjectArray<int> & collided_primitives);
|
||||
|
||||
|
||||
void gimpacttrimeshpart_vs_plane_collision(
|
||||
btCollisionObject * body0,
|
||||
btCollisionObject * body1,
|
||||
btGImpactMeshShapePart * shape0,
|
||||
btStaticPlaneShape * shape1,bool swapped);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
btGImpactCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1);
|
||||
|
||||
virtual ~btGImpactCollisionAlgorithm();
|
||||
|
||||
virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
|
||||
|
||||
btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
|
||||
|
||||
virtual void getAllContactManifolds(btManifoldArray& manifoldArray)
|
||||
{
|
||||
if (m_manifoldPtr)
|
||||
manifoldArray.push_back(m_manifoldPtr);
|
||||
}
|
||||
|
||||
|
||||
struct CreateFunc :public btCollisionAlgorithmCreateFunc
|
||||
{
|
||||
virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
|
||||
{
|
||||
void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btGImpactCollisionAlgorithm));
|
||||
return new(mem) btGImpactCollisionAlgorithm(ci,body0,body1);
|
||||
}
|
||||
};
|
||||
|
||||
//! Use this function for register the algorithm externally
|
||||
static void registerAlgorithm(btCollisionDispatcher * dispatcher);
|
||||
|
||||
//! Gets the average time in miliseconds of tree collisions
|
||||
static float getAverageTreeCollisionTime();
|
||||
|
||||
//! Gets the average time in miliseconds of triangle collisions
|
||||
static float getAverageTriangleCollisionTime();
|
||||
|
||||
|
||||
//! Collides two gimpact shapes
|
||||
/*!
|
||||
\pre shape0 and shape1 couldn't be btGImpactMeshShape objects
|
||||
*/
|
||||
|
||||
|
||||
void gimpact_vs_gimpact(btCollisionObject * body0,
|
||||
btCollisionObject * body1,
|
||||
btGImpactShapeInterface * shape0,
|
||||
btGImpactShapeInterface * shape1);
|
||||
|
||||
void gimpact_vs_shape(btCollisionObject * body0,
|
||||
btCollisionObject * body1,
|
||||
btGImpactShapeInterface * shape0,
|
||||
btCollisionShape * shape1,bool swapped);
|
||||
|
||||
void gimpact_vs_compoundshape(btCollisionObject * body0,
|
||||
btCollisionObject * body1,
|
||||
btGImpactShapeInterface * shape0,
|
||||
btCompoundShape * shape1,bool swapped);
|
||||
|
||||
void gimpact_vs_concave(
|
||||
btCollisionObject * body0,
|
||||
btCollisionObject * body1,
|
||||
btGImpactShapeInterface * shape0,
|
||||
btConcaveShape * shape1,bool swapped);
|
||||
|
||||
|
||||
|
||||
|
||||
/// Accessor/Mutator pairs for Part and triangleID
|
||||
void setFace0(int value)
|
||||
{
|
||||
m_triface0 = value;
|
||||
}
|
||||
int getFace0()
|
||||
{
|
||||
return m_triface0;
|
||||
}
|
||||
void setFace1(int value)
|
||||
{
|
||||
m_triface1 = value;
|
||||
}
|
||||
int getFace1()
|
||||
{
|
||||
return m_triface1;
|
||||
}
|
||||
void setPart0(int value)
|
||||
{
|
||||
m_part0 = value;
|
||||
}
|
||||
int getPart0()
|
||||
{
|
||||
return m_part0;
|
||||
}
|
||||
void setPart1(int value)
|
||||
{
|
||||
m_part1 = value;
|
||||
}
|
||||
int getPart1()
|
||||
{
|
||||
return m_part1;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
//algorithm details
|
||||
//#define BULLET_TRIANGLE_COLLISION 1
|
||||
#define GIMPACT_VS_PLANE_COLLISION 1
|
||||
|
||||
|
||||
|
||||
#endif //BVH_CONCAVE_COLLISION_ALGORITHM_H
|
||||
/*! \file btGImpactShape.h
|
||||
\author Francisco Len Nßjera
|
||||
*/
|
||||
/*
|
||||
This source file is part of GIMPACT Library.
|
||||
|
||||
For the latest info, see http://gimpact.sourceforge.net/
|
||||
|
||||
Copyright (c) 2007 Francisco Leon Najera. C.C. 80087371.
|
||||
email: projectileman@yahoo.com
|
||||
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef BVH_CONCAVE_COLLISION_ALGORITHM_H
|
||||
#define BVH_CONCAVE_COLLISION_ALGORITHM_H
|
||||
|
||||
#include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h"
|
||||
#include "BulletCollision/BroadphaseCollision/btDispatcher.h"
|
||||
#include "BulletCollision/BroadphaseCollision/btBroadphaseInterface.h"
|
||||
#include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
|
||||
class btDispatcher;
|
||||
#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
|
||||
#include "BulletCollision/CollisionDispatch/btCollisionCreateFunc.h"
|
||||
#include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h"
|
||||
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
|
||||
#include "btGImpactShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btStaticPlaneShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btCompoundShape.h"
|
||||
#include "BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h"
|
||||
#include "LinearMath/btIDebugDraw.h"
|
||||
|
||||
|
||||
|
||||
//! Collision Algorithm for GImpact Shapes
|
||||
/*!
|
||||
For register this algorithm in Bullet, proceed as following:
|
||||
\code
|
||||
btCollisionDispatcher * dispatcher = static_cast<btCollisionDispatcher *>(m_dynamicsWorld ->getDispatcher());
|
||||
btGImpactCollisionAlgorithm::registerAlgorithm(dispatcher);
|
||||
\endcode
|
||||
*/
|
||||
class btGImpactCollisionAlgorithm : public btCollisionAlgorithm
|
||||
{
|
||||
protected:
|
||||
btCollisionAlgorithm * m_convex_algorithm;
|
||||
btPersistentManifold * m_manifoldPtr;
|
||||
btManifoldResult* m_resultOut;
|
||||
const btDispatcherInfo * m_dispatchInfo;
|
||||
int m_triface0;
|
||||
int m_part0;
|
||||
int m_triface1;
|
||||
int m_part1;
|
||||
|
||||
|
||||
//! Creates a new contact point
|
||||
SIMD_FORCE_INLINE btPersistentManifold* newContactManifold(btCollisionObject* body0,btCollisionObject* body1)
|
||||
{
|
||||
m_manifoldPtr = m_dispatcher->getNewManifold(body0,body1);
|
||||
return m_manifoldPtr;
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE void destroyConvexAlgorithm()
|
||||
{
|
||||
if(m_convex_algorithm)
|
||||
{
|
||||
m_convex_algorithm->~btCollisionAlgorithm();
|
||||
m_dispatcher->freeCollisionAlgorithm( m_convex_algorithm);
|
||||
m_convex_algorithm = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE void destroyContactManifolds()
|
||||
{
|
||||
if(m_manifoldPtr == NULL) return;
|
||||
m_dispatcher->releaseManifold(m_manifoldPtr);
|
||||
m_manifoldPtr = NULL;
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE void clearCache()
|
||||
{
|
||||
destroyContactManifolds();
|
||||
destroyConvexAlgorithm();
|
||||
|
||||
m_triface0 = -1;
|
||||
m_part0 = -1;
|
||||
m_triface1 = -1;
|
||||
m_part1 = -1;
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE btPersistentManifold* getLastManifold()
|
||||
{
|
||||
return m_manifoldPtr;
|
||||
}
|
||||
|
||||
|
||||
// Call before process collision
|
||||
SIMD_FORCE_INLINE void checkManifold(btCollisionObject* body0,btCollisionObject* body1)
|
||||
{
|
||||
if(getLastManifold() == 0)
|
||||
{
|
||||
newContactManifold(body0,body1);
|
||||
}
|
||||
|
||||
m_resultOut->setPersistentManifold(getLastManifold());
|
||||
}
|
||||
|
||||
// Call before process collision
|
||||
SIMD_FORCE_INLINE btCollisionAlgorithm * newAlgorithm(btCollisionObject* body0,btCollisionObject* body1)
|
||||
{
|
||||
checkManifold(body0,body1);
|
||||
|
||||
btCollisionAlgorithm * convex_algorithm = m_dispatcher->findAlgorithm(
|
||||
body0,body1,getLastManifold());
|
||||
return convex_algorithm ;
|
||||
}
|
||||
|
||||
// Call before process collision
|
||||
SIMD_FORCE_INLINE void checkConvexAlgorithm(btCollisionObject* body0,btCollisionObject* body1)
|
||||
{
|
||||
if(m_convex_algorithm) return;
|
||||
m_convex_algorithm = newAlgorithm(body0,body1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void addContactPoint(btCollisionObject * body0,
|
||||
btCollisionObject * body1,
|
||||
const btVector3 & point,
|
||||
const btVector3 & normal,
|
||||
btScalar distance);
|
||||
|
||||
//! Collision routines
|
||||
//!@{
|
||||
|
||||
void collide_gjk_triangles(btCollisionObject * body0,
|
||||
btCollisionObject * body1,
|
||||
btGImpactMeshShapePart * shape0,
|
||||
btGImpactMeshShapePart * shape1,
|
||||
const int * pairs, int pair_count);
|
||||
|
||||
void collide_sat_triangles(btCollisionObject * body0,
|
||||
btCollisionObject * body1,
|
||||
btGImpactMeshShapePart * shape0,
|
||||
btGImpactMeshShapePart * shape1,
|
||||
const int * pairs, int pair_count);
|
||||
|
||||
|
||||
|
||||
|
||||
void shape_vs_shape_collision(
|
||||
btCollisionObject * body0,
|
||||
btCollisionObject * body1,
|
||||
btCollisionShape * shape0,
|
||||
btCollisionShape * shape1);
|
||||
|
||||
void convex_vs_convex_collision(btCollisionObject * body0,
|
||||
btCollisionObject * body1,
|
||||
btCollisionShape * shape0,
|
||||
btCollisionShape * shape1);
|
||||
|
||||
|
||||
|
||||
void gimpact_vs_gimpact_find_pairs(
|
||||
const btTransform & trans0,
|
||||
const btTransform & trans1,
|
||||
btGImpactShapeInterface * shape0,
|
||||
btGImpactShapeInterface * shape1,btPairSet & pairset);
|
||||
|
||||
void gimpact_vs_shape_find_pairs(
|
||||
const btTransform & trans0,
|
||||
const btTransform & trans1,
|
||||
btGImpactShapeInterface * shape0,
|
||||
btCollisionShape * shape1,
|
||||
btAlignedObjectArray<int> & collided_primitives);
|
||||
|
||||
|
||||
void gimpacttrimeshpart_vs_plane_collision(
|
||||
btCollisionObject * body0,
|
||||
btCollisionObject * body1,
|
||||
btGImpactMeshShapePart * shape0,
|
||||
btStaticPlaneShape * shape1,bool swapped);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
btGImpactCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1);
|
||||
|
||||
virtual ~btGImpactCollisionAlgorithm();
|
||||
|
||||
virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
|
||||
|
||||
btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
|
||||
|
||||
virtual void getAllContactManifolds(btManifoldArray& manifoldArray)
|
||||
{
|
||||
if (m_manifoldPtr)
|
||||
manifoldArray.push_back(m_manifoldPtr);
|
||||
}
|
||||
|
||||
|
||||
struct CreateFunc :public btCollisionAlgorithmCreateFunc
|
||||
{
|
||||
virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
|
||||
{
|
||||
void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btGImpactCollisionAlgorithm));
|
||||
return new(mem) btGImpactCollisionAlgorithm(ci,body0,body1);
|
||||
}
|
||||
};
|
||||
|
||||
//! Use this function for register the algorithm externally
|
||||
static void registerAlgorithm(btCollisionDispatcher * dispatcher);
|
||||
|
||||
//! Gets the average time in miliseconds of tree collisions
|
||||
static float getAverageTreeCollisionTime();
|
||||
|
||||
//! Gets the average time in miliseconds of triangle collisions
|
||||
static float getAverageTriangleCollisionTime();
|
||||
|
||||
|
||||
//! Collides two gimpact shapes
|
||||
/*!
|
||||
\pre shape0 and shape1 couldn't be btGImpactMeshShape objects
|
||||
*/
|
||||
|
||||
|
||||
void gimpact_vs_gimpact(btCollisionObject * body0,
|
||||
btCollisionObject * body1,
|
||||
btGImpactShapeInterface * shape0,
|
||||
btGImpactShapeInterface * shape1);
|
||||
|
||||
void gimpact_vs_shape(btCollisionObject * body0,
|
||||
btCollisionObject * body1,
|
||||
btGImpactShapeInterface * shape0,
|
||||
btCollisionShape * shape1,bool swapped);
|
||||
|
||||
void gimpact_vs_compoundshape(btCollisionObject * body0,
|
||||
btCollisionObject * body1,
|
||||
btGImpactShapeInterface * shape0,
|
||||
btCompoundShape * shape1,bool swapped);
|
||||
|
||||
void gimpact_vs_concave(
|
||||
btCollisionObject * body0,
|
||||
btCollisionObject * body1,
|
||||
btGImpactShapeInterface * shape0,
|
||||
btConcaveShape * shape1,bool swapped);
|
||||
|
||||
|
||||
|
||||
|
||||
/// Accessor/Mutator pairs for Part and triangleID
|
||||
void setFace0(int value)
|
||||
{
|
||||
m_triface0 = value;
|
||||
}
|
||||
int getFace0()
|
||||
{
|
||||
return m_triface0;
|
||||
}
|
||||
void setFace1(int value)
|
||||
{
|
||||
m_triface1 = value;
|
||||
}
|
||||
int getFace1()
|
||||
{
|
||||
return m_triface1;
|
||||
}
|
||||
void setPart0(int value)
|
||||
{
|
||||
m_part0 = value;
|
||||
}
|
||||
int getPart0()
|
||||
{
|
||||
return m_part0;
|
||||
}
|
||||
void setPart1(int value)
|
||||
{
|
||||
m_part1 = value;
|
||||
}
|
||||
int getPart1()
|
||||
{
|
||||
return m_part1;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
//algorithm details
|
||||
//#define BULLET_TRIANGLE_COLLISION 1
|
||||
#define GIMPACT_VS_PLANE_COLLISION 1
|
||||
|
||||
|
||||
|
||||
#endif //BVH_CONCAVE_COLLISION_ALGORITHM_H
|
||||
120
Extras/GIMPACT/include/GIMPACT/Bullet/btGImpactMassUtil.h → src/BulletCollision/Gimpact/btGImpactMassUtil.h
Executable file → Normal file
120
Extras/GIMPACT/include/GIMPACT/Bullet/btGImpactMassUtil.h → src/BulletCollision/Gimpact/btGImpactMassUtil.h
Executable file → Normal file
@@ -1,60 +1,60 @@
|
||||
/*! \file btGImpactMassUtil.h
|
||||
\author Francisco León Nájera
|
||||
*/
|
||||
/*
|
||||
This source file is part of GIMPACT Library.
|
||||
|
||||
For the latest info, see http://gimpact.sourceforge.net/
|
||||
|
||||
Copyright (c) 2007 Francisco Leon Najera. C.C. 80087371.
|
||||
email: projectileman@yahoo.com
|
||||
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef GIMPACT_MASS_UTIL_H
|
||||
#define GIMPACT_MASS_UTIL_H
|
||||
|
||||
#include "LinearMath/btTransform.h"
|
||||
|
||||
|
||||
|
||||
SIMD_FORCE_INLINE btVector3 gim_inertia_add_transformed(
|
||||
const btVector3 & source_inertia, const btVector3 & added_inertia, const btTransform & transform)
|
||||
{
|
||||
btMatrix3x3 rotatedTensor = transform.getBasis().scaled(added_inertia) * transform.getBasis().transpose();
|
||||
|
||||
btScalar x2 = transform.getOrigin()[0];
|
||||
x2*= x2;
|
||||
btScalar y2 = transform.getOrigin()[1];
|
||||
y2*= y2;
|
||||
btScalar z2 = transform.getOrigin()[2];
|
||||
z2*= z2;
|
||||
|
||||
btScalar ix = rotatedTensor[0][0]*(y2+z2);
|
||||
btScalar iy = rotatedTensor[1][1]*(x2+z2);
|
||||
btScalar iz = rotatedTensor[2][2]*(x2+y2);
|
||||
|
||||
return btVector3(source_inertia[0]+ix,source_inertia[1]+iy,source_inertia[2] + iz);
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE btVector3 gim_get_point_inertia(const btVector3 & point, btScalar mass)
|
||||
{
|
||||
btScalar x2 = point[0]*point[0];
|
||||
btScalar y2 = point[1]*point[1];
|
||||
btScalar z2 = point[2]*point[2];
|
||||
return btVector3(mass*(y2+z2),mass*(x2+z2),mass*(x2+y2));
|
||||
}
|
||||
|
||||
|
||||
#endif //GIMPACT_MESH_SHAPE_H
|
||||
/*! \file btGImpactMassUtil.h
|
||||
\author Francisco Len Nßjera
|
||||
*/
|
||||
/*
|
||||
This source file is part of GIMPACT Library.
|
||||
|
||||
For the latest info, see http://gimpact.sourceforge.net/
|
||||
|
||||
Copyright (c) 2007 Francisco Leon Najera. C.C. 80087371.
|
||||
email: projectileman@yahoo.com
|
||||
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef GIMPACT_MASS_UTIL_H
|
||||
#define GIMPACT_MASS_UTIL_H
|
||||
|
||||
#include "LinearMath/btTransform.h"
|
||||
|
||||
|
||||
|
||||
SIMD_FORCE_INLINE btVector3 gim_inertia_add_transformed(
|
||||
const btVector3 & source_inertia, const btVector3 & added_inertia, const btTransform & transform)
|
||||
{
|
||||
btMatrix3x3 rotatedTensor = transform.getBasis().scaled(added_inertia) * transform.getBasis().transpose();
|
||||
|
||||
btScalar x2 = transform.getOrigin()[0];
|
||||
x2*= x2;
|
||||
btScalar y2 = transform.getOrigin()[1];
|
||||
y2*= y2;
|
||||
btScalar z2 = transform.getOrigin()[2];
|
||||
z2*= z2;
|
||||
|
||||
btScalar ix = rotatedTensor[0][0]*(y2+z2);
|
||||
btScalar iy = rotatedTensor[1][1]*(x2+z2);
|
||||
btScalar iz = rotatedTensor[2][2]*(x2+y2);
|
||||
|
||||
return btVector3(source_inertia[0]+ix,source_inertia[1]+iy,source_inertia[2] + iz);
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE btVector3 gim_get_point_inertia(const btVector3 & point, btScalar mass)
|
||||
{
|
||||
btScalar x2 = point[0]*point[0];
|
||||
btScalar y2 = point[1]*point[1];
|
||||
btScalar z2 = point[2]*point[2];
|
||||
return btVector3(mass*(y2+z2),mass*(x2+z2),mass*(x2+y2));
|
||||
}
|
||||
|
||||
|
||||
#endif //GIMPACT_MESH_SHAPE_H
|
||||
@@ -1,5 +1,5 @@
|
||||
/*! \file gim_box_set.h
|
||||
\author Francisco León Nájera
|
||||
\author Francisco Len Nßjera
|
||||
*/
|
||||
/*
|
||||
This source file is part of GIMPACT Library.
|
||||
@@ -21,7 +21,7 @@ subject to the following restrictions:
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "GIMPACT/Bullet/btGImpactQuantizedBvh.h"
|
||||
#include "btGImpactQuantizedBvh.h"
|
||||
#include "LinearMath/btQuickprof.h"
|
||||
|
||||
#ifdef TRI_COLLISION_PROFILING
|
||||
@@ -2,7 +2,7 @@
|
||||
#define GIM_QUANTIZED_SET_H_INCLUDED
|
||||
|
||||
/*! \file btGImpactQuantizedBvh.h
|
||||
\author Francisco León Nájera
|
||||
\author Francisco Len Nßjera
|
||||
*/
|
||||
/*
|
||||
This source file is part of GIMPACT Library.
|
||||
@@ -24,8 +24,8 @@ subject to the following restrictions:
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "GIMPACT/Bullet/btGImpactBvh.h"
|
||||
#include "GIMPACT/Bullet/btQuantization.h"
|
||||
#include "btGImpactBvh.h"
|
||||
#include "btQuantization.h"
|
||||
|
||||
|
||||
|
||||
366
Extras/GIMPACT/src/Bullet/btGImpactShape.cpp → src/BulletCollision/Gimpact/btGImpactShape.cpp
Executable file → Normal file
366
Extras/GIMPACT/src/Bullet/btGImpactShape.cpp → src/BulletCollision/Gimpact/btGImpactShape.cpp
Executable file → Normal file
@@ -1,183 +1,183 @@
|
||||
/*
|
||||
This source file is part of GIMPACT Library.
|
||||
|
||||
For the latest info, see http://gimpact.sourceforge.net/
|
||||
|
||||
Copyright (c) 2007 Francisco Leon Najera. C.C. 80087371.
|
||||
email: projectileman@yahoo.com
|
||||
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
|
||||
#include "GIMPACT/Bullet/btGImpactShape.h"
|
||||
#include "GIMPACT/Bullet/btGImpactMassUtil.h"
|
||||
|
||||
|
||||
#define CALC_EXACT_INERTIA 1
|
||||
|
||||
void btGImpactCompoundShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
|
||||
{
|
||||
lockChildShapes();
|
||||
#ifdef CALC_EXACT_INERTIA
|
||||
inertia.setValue(0.f,0.f,0.f);
|
||||
|
||||
int i = this->getNumChildShapes();
|
||||
btScalar shapemass = mass/btScalar(i);
|
||||
|
||||
while(i--)
|
||||
{
|
||||
btVector3 temp_inertia;
|
||||
m_childShapes[i]->calculateLocalInertia(shapemass,temp_inertia);
|
||||
if(childrenHasTransform())
|
||||
{
|
||||
inertia = gim_inertia_add_transformed( inertia,temp_inertia,m_childTransforms[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
inertia = gim_inertia_add_transformed( inertia,temp_inertia,btTransform::getIdentity());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// Calc box inertia
|
||||
|
||||
btScalar lx= m_localAABB.m_max[0] - m_localAABB.m_min[0];
|
||||
btScalar ly= m_localAABB.m_max[1] - m_localAABB.m_min[1];
|
||||
btScalar lz= m_localAABB.m_max[2] - m_localAABB.m_min[2];
|
||||
const btScalar x2 = lx*lx;
|
||||
const btScalar y2 = ly*ly;
|
||||
const btScalar z2 = lz*lz;
|
||||
const btScalar scaledmass = mass * btScalar(0.08333333);
|
||||
|
||||
inertia = scaledmass * (btVector3(y2+z2,x2+z2,x2+y2));
|
||||
|
||||
#endif
|
||||
unlockChildShapes();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void btGImpactMeshShapePart::calculateLocalInertia(btScalar mass,btVector3& inertia) const
|
||||
{
|
||||
lockChildShapes();
|
||||
|
||||
|
||||
#ifdef CALC_EXACT_INERTIA
|
||||
inertia.setValue(0.f,0.f,0.f);
|
||||
|
||||
int i = this->getVertexCount();
|
||||
btScalar pointmass = mass/btScalar(i);
|
||||
|
||||
while(i--)
|
||||
{
|
||||
btVector3 pointintertia;
|
||||
this->getVertex(i,pointintertia);
|
||||
pointintertia = gim_get_point_inertia(pointintertia,pointmass);
|
||||
inertia+=pointintertia;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// Calc box inertia
|
||||
|
||||
btScalar lx= m_localAABB.m_max[0] - m_localAABB.m_min[0];
|
||||
btScalar ly= m_localAABB.m_max[1] - m_localAABB.m_min[1];
|
||||
btScalar lz= m_localAABB.m_max[2] - m_localAABB.m_min[2];
|
||||
const btScalar x2 = lx*lx;
|
||||
const btScalar y2 = ly*ly;
|
||||
const btScalar z2 = lz*lz;
|
||||
const btScalar scaledmass = mass * btScalar(0.08333333);
|
||||
|
||||
inertia = scaledmass * (btVector3(y2+z2,x2+z2,x2+y2));
|
||||
|
||||
#endif
|
||||
|
||||
unlockChildShapes();
|
||||
}
|
||||
|
||||
void btGImpactMeshShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
|
||||
{
|
||||
|
||||
#ifdef CALC_EXACT_INERTIA
|
||||
inertia.setValue(0.f,0.f,0.f);
|
||||
|
||||
int i = this->getMeshPartCount();
|
||||
btScalar partmass = mass/btScalar(i);
|
||||
|
||||
while(i--)
|
||||
{
|
||||
btVector3 partinertia;
|
||||
getMeshPart(i)->calculateLocalInertia(partmass,partinertia);
|
||||
inertia+=partinertia;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// Calc box inertia
|
||||
|
||||
btScalar lx= m_localAABB.m_max[0] - m_localAABB.m_min[0];
|
||||
btScalar ly= m_localAABB.m_max[1] - m_localAABB.m_min[1];
|
||||
btScalar lz= m_localAABB.m_max[2] - m_localAABB.m_min[2];
|
||||
const btScalar x2 = lx*lx;
|
||||
const btScalar y2 = ly*ly;
|
||||
const btScalar z2 = lz*lz;
|
||||
const btScalar scaledmass = mass * btScalar(0.08333333);
|
||||
|
||||
inertia = scaledmass * (btVector3(y2+z2,x2+z2,x2+y2));
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void btGImpactMeshShape::rayTest(const btVector3& rayFrom, const btVector3& rayTo, btCollisionWorld::RayResultCallback& resultCallback) const
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void btGImpactMeshShapePart::processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const
|
||||
{
|
||||
lockChildShapes();
|
||||
btAABB box;
|
||||
box.m_min = aabbMin;
|
||||
box.m_max = aabbMax;
|
||||
|
||||
btAlignedObjectArray<int> collided;
|
||||
m_box_set.boxQuery(box,collided);
|
||||
|
||||
if(collided.size()==0)
|
||||
{
|
||||
unlockChildShapes();
|
||||
return;
|
||||
}
|
||||
|
||||
int part = (int)getPart();
|
||||
btPrimitiveTriangle triangle;
|
||||
int i = collided.size();
|
||||
while(i--)
|
||||
{
|
||||
this->getPrimitiveTriangle(collided[i],triangle);
|
||||
callback->processTriangle(triangle.m_vertices,part,collided[i]);
|
||||
}
|
||||
unlockChildShapes();
|
||||
|
||||
}
|
||||
|
||||
void btGImpactMeshShape::processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const
|
||||
{
|
||||
int i = m_mesh_parts.size();
|
||||
while(i--)
|
||||
{
|
||||
m_mesh_parts[i]->processAllTriangles(callback,aabbMin,aabbMax);
|
||||
}
|
||||
}
|
||||
/*
|
||||
This source file is part of GIMPACT Library.
|
||||
|
||||
For the latest info, see http://gimpact.sourceforge.net/
|
||||
|
||||
Copyright (c) 2007 Francisco Leon Najera. C.C. 80087371.
|
||||
email: projectileman@yahoo.com
|
||||
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
|
||||
#include "btGImpactShape.h"
|
||||
#include "btGImpactMassUtil.h"
|
||||
|
||||
|
||||
#define CALC_EXACT_INERTIA 1
|
||||
|
||||
void btGImpactCompoundShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
|
||||
{
|
||||
lockChildShapes();
|
||||
#ifdef CALC_EXACT_INERTIA
|
||||
inertia.setValue(0.f,0.f,0.f);
|
||||
|
||||
int i = this->getNumChildShapes();
|
||||
btScalar shapemass = mass/btScalar(i);
|
||||
|
||||
while(i--)
|
||||
{
|
||||
btVector3 temp_inertia;
|
||||
m_childShapes[i]->calculateLocalInertia(shapemass,temp_inertia);
|
||||
if(childrenHasTransform())
|
||||
{
|
||||
inertia = gim_inertia_add_transformed( inertia,temp_inertia,m_childTransforms[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
inertia = gim_inertia_add_transformed( inertia,temp_inertia,btTransform::getIdentity());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// Calc box inertia
|
||||
|
||||
btScalar lx= m_localAABB.m_max[0] - m_localAABB.m_min[0];
|
||||
btScalar ly= m_localAABB.m_max[1] - m_localAABB.m_min[1];
|
||||
btScalar lz= m_localAABB.m_max[2] - m_localAABB.m_min[2];
|
||||
const btScalar x2 = lx*lx;
|
||||
const btScalar y2 = ly*ly;
|
||||
const btScalar z2 = lz*lz;
|
||||
const btScalar scaledmass = mass * btScalar(0.08333333);
|
||||
|
||||
inertia = scaledmass * (btVector3(y2+z2,x2+z2,x2+y2));
|
||||
|
||||
#endif
|
||||
unlockChildShapes();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void btGImpactMeshShapePart::calculateLocalInertia(btScalar mass,btVector3& inertia) const
|
||||
{
|
||||
lockChildShapes();
|
||||
|
||||
|
||||
#ifdef CALC_EXACT_INERTIA
|
||||
inertia.setValue(0.f,0.f,0.f);
|
||||
|
||||
int i = this->getVertexCount();
|
||||
btScalar pointmass = mass/btScalar(i);
|
||||
|
||||
while(i--)
|
||||
{
|
||||
btVector3 pointintertia;
|
||||
this->getVertex(i,pointintertia);
|
||||
pointintertia = gim_get_point_inertia(pointintertia,pointmass);
|
||||
inertia+=pointintertia;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// Calc box inertia
|
||||
|
||||
btScalar lx= m_localAABB.m_max[0] - m_localAABB.m_min[0];
|
||||
btScalar ly= m_localAABB.m_max[1] - m_localAABB.m_min[1];
|
||||
btScalar lz= m_localAABB.m_max[2] - m_localAABB.m_min[2];
|
||||
const btScalar x2 = lx*lx;
|
||||
const btScalar y2 = ly*ly;
|
||||
const btScalar z2 = lz*lz;
|
||||
const btScalar scaledmass = mass * btScalar(0.08333333);
|
||||
|
||||
inertia = scaledmass * (btVector3(y2+z2,x2+z2,x2+y2));
|
||||
|
||||
#endif
|
||||
|
||||
unlockChildShapes();
|
||||
}
|
||||
|
||||
void btGImpactMeshShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
|
||||
{
|
||||
|
||||
#ifdef CALC_EXACT_INERTIA
|
||||
inertia.setValue(0.f,0.f,0.f);
|
||||
|
||||
int i = this->getMeshPartCount();
|
||||
btScalar partmass = mass/btScalar(i);
|
||||
|
||||
while(i--)
|
||||
{
|
||||
btVector3 partinertia;
|
||||
getMeshPart(i)->calculateLocalInertia(partmass,partinertia);
|
||||
inertia+=partinertia;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// Calc box inertia
|
||||
|
||||
btScalar lx= m_localAABB.m_max[0] - m_localAABB.m_min[0];
|
||||
btScalar ly= m_localAABB.m_max[1] - m_localAABB.m_min[1];
|
||||
btScalar lz= m_localAABB.m_max[2] - m_localAABB.m_min[2];
|
||||
const btScalar x2 = lx*lx;
|
||||
const btScalar y2 = ly*ly;
|
||||
const btScalar z2 = lz*lz;
|
||||
const btScalar scaledmass = mass * btScalar(0.08333333);
|
||||
|
||||
inertia = scaledmass * (btVector3(y2+z2,x2+z2,x2+y2));
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void btGImpactMeshShape::rayTest(const btVector3& rayFrom, const btVector3& rayTo, btCollisionWorld::RayResultCallback& resultCallback) const
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void btGImpactMeshShapePart::processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const
|
||||
{
|
||||
lockChildShapes();
|
||||
btAABB box;
|
||||
box.m_min = aabbMin;
|
||||
box.m_max = aabbMax;
|
||||
|
||||
btAlignedObjectArray<int> collided;
|
||||
m_box_set.boxQuery(box,collided);
|
||||
|
||||
if(collided.size()==0)
|
||||
{
|
||||
unlockChildShapes();
|
||||
return;
|
||||
}
|
||||
|
||||
int part = (int)getPart();
|
||||
btPrimitiveTriangle triangle;
|
||||
int i = collided.size();
|
||||
while(i--)
|
||||
{
|
||||
this->getPrimitiveTriangle(collided[i],triangle);
|
||||
callback->processTriangle(triangle.m_vertices,part,collided[i]);
|
||||
}
|
||||
unlockChildShapes();
|
||||
|
||||
}
|
||||
|
||||
void btGImpactMeshShape::processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const
|
||||
{
|
||||
int i = m_mesh_parts.size();
|
||||
while(i--)
|
||||
{
|
||||
m_mesh_parts[i]->processAllTriangles(callback,aabbMin,aabbMax);
|
||||
}
|
||||
}
|
||||
2216
Extras/GIMPACT/include/GIMPACT/Bullet/btGImpactShape.h → src/BulletCollision/Gimpact/btGImpactShape.h
Executable file → Normal file
2216
Extras/GIMPACT/include/GIMPACT/Bullet/btGImpactShape.h → src/BulletCollision/Gimpact/btGImpactShape.h
Executable file → Normal file
File diff suppressed because it is too large
Load Diff
566
Extras/GIMPACT/src/Bullet/btGenericPoolAllocator.cpp → src/BulletCollision/Gimpact/btGenericPoolAllocator.cpp
Executable file → Normal file
566
Extras/GIMPACT/src/Bullet/btGenericPoolAllocator.cpp → src/BulletCollision/Gimpact/btGenericPoolAllocator.cpp
Executable file → Normal file
@@ -1,283 +1,283 @@
|
||||
/*! \file btGenericPoolAllocator.cpp
|
||||
\author Francisco León Nájera. email projectileman@yahoo.com
|
||||
|
||||
General purpose allocator class
|
||||
*/
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "GIMPACT/Bullet/btGenericPoolAllocator.h"
|
||||
|
||||
|
||||
|
||||
/// *************** btGenericMemoryPool ******************///////////
|
||||
|
||||
size_t btGenericMemoryPool::allocate_from_free_nodes(size_t num_elements)
|
||||
{
|
||||
size_t ptr = BT_UINT_MAX;
|
||||
|
||||
if(m_free_nodes_count == 0) return BT_UINT_MAX;
|
||||
// find an avaliable free node with the correct size
|
||||
size_t revindex = m_free_nodes_count;
|
||||
|
||||
while(revindex-- && ptr == BT_UINT_MAX)
|
||||
{
|
||||
if(m_allocated_sizes[m_free_nodes[revindex]]>=num_elements)
|
||||
{
|
||||
ptr = revindex;
|
||||
}
|
||||
}
|
||||
if(ptr == BT_UINT_MAX) return BT_UINT_MAX; // not found
|
||||
|
||||
|
||||
revindex = ptr;
|
||||
ptr = m_free_nodes[revindex];
|
||||
// post: ptr contains the node index, and revindex the index in m_free_nodes
|
||||
|
||||
size_t finalsize = m_allocated_sizes[ptr];
|
||||
finalsize -= num_elements;
|
||||
|
||||
m_allocated_sizes[ptr] = num_elements;
|
||||
|
||||
// post: finalsize>=0, m_allocated_sizes[ptr] has the requested size
|
||||
|
||||
if(finalsize>0) // preserve free node, there are some free memory
|
||||
{
|
||||
m_free_nodes[revindex] = ptr + num_elements;
|
||||
m_allocated_sizes[ptr + num_elements] = finalsize;
|
||||
}
|
||||
else // delete free node
|
||||
{
|
||||
// swap with end
|
||||
m_free_nodes[revindex] = m_free_nodes[m_free_nodes_count-1];
|
||||
m_free_nodes_count--;
|
||||
}
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
size_t btGenericMemoryPool::allocate_from_pool(size_t num_elements)
|
||||
{
|
||||
if(m_allocated_count+num_elements>m_max_element_count) return BT_UINT_MAX;
|
||||
|
||||
size_t ptr = m_allocated_count;
|
||||
|
||||
m_allocated_sizes[m_allocated_count] = num_elements;
|
||||
m_allocated_count+=num_elements;
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
||||
void btGenericMemoryPool::init_pool(size_t element_size, size_t element_count)
|
||||
{
|
||||
m_allocated_count = 0;
|
||||
m_free_nodes_count = 0;
|
||||
|
||||
m_element_size = element_size;
|
||||
m_max_element_count = element_count;
|
||||
|
||||
|
||||
|
||||
|
||||
m_pool = (unsigned char *) btAlignedAlloc(m_element_size*m_max_element_count,16);
|
||||
m_free_nodes = (size_t *) btAlignedAlloc(sizeof(size_t)*m_max_element_count,16);
|
||||
m_allocated_sizes = (size_t *) btAlignedAlloc(sizeof(size_t)*m_max_element_count,16);
|
||||
|
||||
for (size_t i = 0;i< m_max_element_count;i++ )
|
||||
{
|
||||
m_allocated_sizes[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void btGenericMemoryPool::end_pool()
|
||||
{
|
||||
btAlignedFree(m_pool);
|
||||
btAlignedFree(m_free_nodes);
|
||||
btAlignedFree(m_allocated_sizes);
|
||||
m_allocated_count = 0;
|
||||
m_free_nodes_count = 0;
|
||||
}
|
||||
|
||||
|
||||
//! Allocates memory in pool
|
||||
/*!
|
||||
\param size_bytes size in bytes of the buffer
|
||||
*/
|
||||
void * btGenericMemoryPool::allocate(size_t size_bytes)
|
||||
{
|
||||
|
||||
size_t module = size_bytes%m_element_size;
|
||||
size_t element_count = size_bytes/m_element_size;
|
||||
if(module>0) element_count++;
|
||||
|
||||
size_t alloc_pos = allocate_from_free_nodes(element_count);
|
||||
// a free node is found
|
||||
if(alloc_pos != BT_UINT_MAX)
|
||||
{
|
||||
return get_element_data(alloc_pos);
|
||||
}
|
||||
// allocate directly on pool
|
||||
alloc_pos = allocate_from_pool(element_count);
|
||||
|
||||
if(alloc_pos == BT_UINT_MAX) return NULL; // not space
|
||||
return get_element_data(alloc_pos);
|
||||
}
|
||||
|
||||
bool btGenericMemoryPool::freeMemory(void * pointer)
|
||||
{
|
||||
unsigned char * pointer_pos = (unsigned char *)pointer;
|
||||
unsigned char * pool_pos = (unsigned char *)m_pool;
|
||||
// calc offset
|
||||
if(pointer_pos<pool_pos) return false;//other pool
|
||||
size_t offset = size_t(pointer_pos - pool_pos);
|
||||
if(offset>=get_pool_capacity()) return false;// far away
|
||||
|
||||
// find free position
|
||||
m_free_nodes[m_free_nodes_count] = offset/m_element_size;
|
||||
m_free_nodes_count++;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/// *******************! btGenericPoolAllocator *******************!///
|
||||
|
||||
|
||||
btGenericPoolAllocator::~btGenericPoolAllocator()
|
||||
{
|
||||
// destroy pools
|
||||
size_t i;
|
||||
for (i=0;i<m_pool_count;i++)
|
||||
{
|
||||
m_pools[i]->end_pool();
|
||||
btAlignedFree(m_pools[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// creates a pool
|
||||
btGenericMemoryPool * btGenericPoolAllocator::push_new_pool()
|
||||
{
|
||||
if(m_pool_count >= BT_DEFAULT_MAX_POOLS) return NULL;
|
||||
|
||||
btGenericMemoryPool * newptr = (btGenericMemoryPool *)btAlignedAlloc(sizeof(btGenericMemoryPool),16);
|
||||
|
||||
m_pools[m_pool_count] = newptr;
|
||||
|
||||
m_pools[m_pool_count]->init_pool(m_pool_element_size,m_pool_element_count);
|
||||
|
||||
m_pool_count++;
|
||||
return newptr;
|
||||
}
|
||||
|
||||
void * btGenericPoolAllocator::failback_alloc(size_t size_bytes)
|
||||
{
|
||||
|
||||
btGenericMemoryPool * pool = NULL;
|
||||
|
||||
|
||||
if(size_bytes<=get_pool_capacity())
|
||||
{
|
||||
pool = push_new_pool();
|
||||
}
|
||||
|
||||
if(pool==NULL) // failback
|
||||
{
|
||||
return btAlignedAlloc(size_bytes,16);
|
||||
}
|
||||
|
||||
return pool->allocate(size_bytes);
|
||||
}
|
||||
|
||||
bool btGenericPoolAllocator::failback_free(void * pointer)
|
||||
{
|
||||
btAlignedFree(pointer);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//! Allocates memory in pool
|
||||
/*!
|
||||
\param size_bytes size in bytes of the buffer
|
||||
*/
|
||||
void * btGenericPoolAllocator::allocate(size_t size_bytes)
|
||||
{
|
||||
void * ptr = NULL;
|
||||
|
||||
size_t i = 0;
|
||||
while(i<m_pool_count && ptr == NULL)
|
||||
{
|
||||
ptr = m_pools[i]->allocate(size_bytes);
|
||||
++i;
|
||||
}
|
||||
|
||||
if(ptr) return ptr;
|
||||
|
||||
return failback_alloc(size_bytes);
|
||||
}
|
||||
|
||||
bool btGenericPoolAllocator::freeMemory(void * pointer)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
size_t i = 0;
|
||||
while(i<m_pool_count && result == false)
|
||||
{
|
||||
result = m_pools[i]->freeMemory(pointer);
|
||||
++i;
|
||||
}
|
||||
|
||||
if(result) return true;
|
||||
|
||||
return failback_free(pointer);
|
||||
}
|
||||
|
||||
/// ************** STANDARD ALLOCATOR ***************************///
|
||||
|
||||
|
||||
#define BT_DEFAULT_POOL_SIZE 32768
|
||||
#define BT_DEFAULT_POOL_ELEMENT_SIZE 8
|
||||
|
||||
// main allocator
|
||||
class BT_STANDARD_ALLOCATOR: public btGenericPoolAllocator
|
||||
{
|
||||
public:
|
||||
BT_STANDARD_ALLOCATOR():btGenericPoolAllocator(BT_DEFAULT_POOL_ELEMENT_SIZE,BT_DEFAULT_POOL_SIZE)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
// global allocator
|
||||
BT_STANDARD_ALLOCATOR g_main_allocator;
|
||||
|
||||
|
||||
void * btPoolAlloc(size_t size)
|
||||
{
|
||||
return g_main_allocator.allocate(size);
|
||||
}
|
||||
|
||||
void * btPoolRealloc(void *ptr, size_t oldsize, size_t newsize)
|
||||
{
|
||||
void * newptr = btPoolAlloc(newsize);
|
||||
size_t copysize = oldsize<newsize?oldsize:newsize;
|
||||
memcpy(newptr,ptr,copysize);
|
||||
btPoolFree(ptr);
|
||||
return newptr;
|
||||
}
|
||||
|
||||
void btPoolFree(void *ptr)
|
||||
{
|
||||
g_main_allocator.freeMemory(ptr);
|
||||
}
|
||||
/*! \file btGenericPoolAllocator.cpp
|
||||
\author Francisco Len Nßjera. email projectileman@yahoo.com
|
||||
|
||||
General purpose allocator class
|
||||
*/
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "btGenericPoolAllocator.h"
|
||||
|
||||
|
||||
|
||||
/// *************** btGenericMemoryPool ******************///////////
|
||||
|
||||
size_t btGenericMemoryPool::allocate_from_free_nodes(size_t num_elements)
|
||||
{
|
||||
size_t ptr = BT_UINT_MAX;
|
||||
|
||||
if(m_free_nodes_count == 0) return BT_UINT_MAX;
|
||||
// find an avaliable free node with the correct size
|
||||
size_t revindex = m_free_nodes_count;
|
||||
|
||||
while(revindex-- && ptr == BT_UINT_MAX)
|
||||
{
|
||||
if(m_allocated_sizes[m_free_nodes[revindex]]>=num_elements)
|
||||
{
|
||||
ptr = revindex;
|
||||
}
|
||||
}
|
||||
if(ptr == BT_UINT_MAX) return BT_UINT_MAX; // not found
|
||||
|
||||
|
||||
revindex = ptr;
|
||||
ptr = m_free_nodes[revindex];
|
||||
// post: ptr contains the node index, and revindex the index in m_free_nodes
|
||||
|
||||
size_t finalsize = m_allocated_sizes[ptr];
|
||||
finalsize -= num_elements;
|
||||
|
||||
m_allocated_sizes[ptr] = num_elements;
|
||||
|
||||
// post: finalsize>=0, m_allocated_sizes[ptr] has the requested size
|
||||
|
||||
if(finalsize>0) // preserve free node, there are some free memory
|
||||
{
|
||||
m_free_nodes[revindex] = ptr + num_elements;
|
||||
m_allocated_sizes[ptr + num_elements] = finalsize;
|
||||
}
|
||||
else // delete free node
|
||||
{
|
||||
// swap with end
|
||||
m_free_nodes[revindex] = m_free_nodes[m_free_nodes_count-1];
|
||||
m_free_nodes_count--;
|
||||
}
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
size_t btGenericMemoryPool::allocate_from_pool(size_t num_elements)
|
||||
{
|
||||
if(m_allocated_count+num_elements>m_max_element_count) return BT_UINT_MAX;
|
||||
|
||||
size_t ptr = m_allocated_count;
|
||||
|
||||
m_allocated_sizes[m_allocated_count] = num_elements;
|
||||
m_allocated_count+=num_elements;
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
||||
void btGenericMemoryPool::init_pool(size_t element_size, size_t element_count)
|
||||
{
|
||||
m_allocated_count = 0;
|
||||
m_free_nodes_count = 0;
|
||||
|
||||
m_element_size = element_size;
|
||||
m_max_element_count = element_count;
|
||||
|
||||
|
||||
|
||||
|
||||
m_pool = (unsigned char *) btAlignedAlloc(m_element_size*m_max_element_count,16);
|
||||
m_free_nodes = (size_t *) btAlignedAlloc(sizeof(size_t)*m_max_element_count,16);
|
||||
m_allocated_sizes = (size_t *) btAlignedAlloc(sizeof(size_t)*m_max_element_count,16);
|
||||
|
||||
for (size_t i = 0;i< m_max_element_count;i++ )
|
||||
{
|
||||
m_allocated_sizes[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void btGenericMemoryPool::end_pool()
|
||||
{
|
||||
btAlignedFree(m_pool);
|
||||
btAlignedFree(m_free_nodes);
|
||||
btAlignedFree(m_allocated_sizes);
|
||||
m_allocated_count = 0;
|
||||
m_free_nodes_count = 0;
|
||||
}
|
||||
|
||||
|
||||
//! Allocates memory in pool
|
||||
/*!
|
||||
\param size_bytes size in bytes of the buffer
|
||||
*/
|
||||
void * btGenericMemoryPool::allocate(size_t size_bytes)
|
||||
{
|
||||
|
||||
size_t module = size_bytes%m_element_size;
|
||||
size_t element_count = size_bytes/m_element_size;
|
||||
if(module>0) element_count++;
|
||||
|
||||
size_t alloc_pos = allocate_from_free_nodes(element_count);
|
||||
// a free node is found
|
||||
if(alloc_pos != BT_UINT_MAX)
|
||||
{
|
||||
return get_element_data(alloc_pos);
|
||||
}
|
||||
// allocate directly on pool
|
||||
alloc_pos = allocate_from_pool(element_count);
|
||||
|
||||
if(alloc_pos == BT_UINT_MAX) return NULL; // not space
|
||||
return get_element_data(alloc_pos);
|
||||
}
|
||||
|
||||
bool btGenericMemoryPool::freeMemory(void * pointer)
|
||||
{
|
||||
unsigned char * pointer_pos = (unsigned char *)pointer;
|
||||
unsigned char * pool_pos = (unsigned char *)m_pool;
|
||||
// calc offset
|
||||
if(pointer_pos<pool_pos) return false;//other pool
|
||||
size_t offset = size_t(pointer_pos - pool_pos);
|
||||
if(offset>=get_pool_capacity()) return false;// far away
|
||||
|
||||
// find free position
|
||||
m_free_nodes[m_free_nodes_count] = offset/m_element_size;
|
||||
m_free_nodes_count++;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/// *******************! btGenericPoolAllocator *******************!///
|
||||
|
||||
|
||||
btGenericPoolAllocator::~btGenericPoolAllocator()
|
||||
{
|
||||
// destroy pools
|
||||
size_t i;
|
||||
for (i=0;i<m_pool_count;i++)
|
||||
{
|
||||
m_pools[i]->end_pool();
|
||||
btAlignedFree(m_pools[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// creates a pool
|
||||
btGenericMemoryPool * btGenericPoolAllocator::push_new_pool()
|
||||
{
|
||||
if(m_pool_count >= BT_DEFAULT_MAX_POOLS) return NULL;
|
||||
|
||||
btGenericMemoryPool * newptr = (btGenericMemoryPool *)btAlignedAlloc(sizeof(btGenericMemoryPool),16);
|
||||
|
||||
m_pools[m_pool_count] = newptr;
|
||||
|
||||
m_pools[m_pool_count]->init_pool(m_pool_element_size,m_pool_element_count);
|
||||
|
||||
m_pool_count++;
|
||||
return newptr;
|
||||
}
|
||||
|
||||
void * btGenericPoolAllocator::failback_alloc(size_t size_bytes)
|
||||
{
|
||||
|
||||
btGenericMemoryPool * pool = NULL;
|
||||
|
||||
|
||||
if(size_bytes<=get_pool_capacity())
|
||||
{
|
||||
pool = push_new_pool();
|
||||
}
|
||||
|
||||
if(pool==NULL) // failback
|
||||
{
|
||||
return btAlignedAlloc(size_bytes,16);
|
||||
}
|
||||
|
||||
return pool->allocate(size_bytes);
|
||||
}
|
||||
|
||||
bool btGenericPoolAllocator::failback_free(void * pointer)
|
||||
{
|
||||
btAlignedFree(pointer);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//! Allocates memory in pool
|
||||
/*!
|
||||
\param size_bytes size in bytes of the buffer
|
||||
*/
|
||||
void * btGenericPoolAllocator::allocate(size_t size_bytes)
|
||||
{
|
||||
void * ptr = NULL;
|
||||
|
||||
size_t i = 0;
|
||||
while(i<m_pool_count && ptr == NULL)
|
||||
{
|
||||
ptr = m_pools[i]->allocate(size_bytes);
|
||||
++i;
|
||||
}
|
||||
|
||||
if(ptr) return ptr;
|
||||
|
||||
return failback_alloc(size_bytes);
|
||||
}
|
||||
|
||||
bool btGenericPoolAllocator::freeMemory(void * pointer)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
size_t i = 0;
|
||||
while(i<m_pool_count && result == false)
|
||||
{
|
||||
result = m_pools[i]->freeMemory(pointer);
|
||||
++i;
|
||||
}
|
||||
|
||||
if(result) return true;
|
||||
|
||||
return failback_free(pointer);
|
||||
}
|
||||
|
||||
/// ************** STANDARD ALLOCATOR ***************************///
|
||||
|
||||
|
||||
#define BT_DEFAULT_POOL_SIZE 32768
|
||||
#define BT_DEFAULT_POOL_ELEMENT_SIZE 8
|
||||
|
||||
// main allocator
|
||||
class BT_STANDARD_ALLOCATOR: public btGenericPoolAllocator
|
||||
{
|
||||
public:
|
||||
BT_STANDARD_ALLOCATOR():btGenericPoolAllocator(BT_DEFAULT_POOL_ELEMENT_SIZE,BT_DEFAULT_POOL_SIZE)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
// global allocator
|
||||
BT_STANDARD_ALLOCATOR g_main_allocator;
|
||||
|
||||
|
||||
void * btPoolAlloc(size_t size)
|
||||
{
|
||||
return g_main_allocator.allocate(size);
|
||||
}
|
||||
|
||||
void * btPoolRealloc(void *ptr, size_t oldsize, size_t newsize)
|
||||
{
|
||||
void * newptr = btPoolAlloc(newsize);
|
||||
size_t copysize = oldsize<newsize?oldsize:newsize;
|
||||
memcpy(newptr,ptr,copysize);
|
||||
btPoolFree(ptr);
|
||||
return newptr;
|
||||
}
|
||||
|
||||
void btPoolFree(void *ptr)
|
||||
{
|
||||
g_main_allocator.freeMemory(ptr);
|
||||
}
|
||||
336
Extras/GIMPACT/include/GIMPACT/Bullet/btGenericPoolAllocator.h → src/BulletCollision/Gimpact/btGenericPoolAllocator.h
Executable file → Normal file
336
Extras/GIMPACT/include/GIMPACT/Bullet/btGenericPoolAllocator.h → src/BulletCollision/Gimpact/btGenericPoolAllocator.h
Executable file → Normal file
@@ -1,168 +1,168 @@
|
||||
/*! \file btGenericPoolAllocator.h
|
||||
\author Francisco León Nájera. email projectileman@yahoo.com
|
||||
|
||||
General purpose allocator class
|
||||
*/
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef BT_GENERIC_POOL_ALLOCATOR_H
|
||||
#define BT_GENERIC_POOL_ALLOCATOR_H
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <memory.h>
|
||||
#include "LinearMath/btAlignedAllocator.h"
|
||||
|
||||
#define BT_UINT_MAX UINT_MAX
|
||||
#define BT_DEFAULT_MAX_POOLS 16
|
||||
|
||||
|
||||
//! Generic Pool class
|
||||
class btGenericMemoryPool
|
||||
{
|
||||
public:
|
||||
unsigned char * m_pool; //[m_element_size*m_max_element_count];
|
||||
size_t * m_free_nodes; //[m_max_element_count];//! free nodes
|
||||
size_t * m_allocated_sizes;//[m_max_element_count];//! Number of elements allocated per node
|
||||
size_t m_allocated_count;
|
||||
size_t m_free_nodes_count;
|
||||
protected:
|
||||
size_t m_element_size;
|
||||
size_t m_max_element_count;
|
||||
|
||||
size_t allocate_from_free_nodes(size_t num_elements);
|
||||
size_t allocate_from_pool(size_t num_elements);
|
||||
|
||||
public:
|
||||
|
||||
void init_pool(size_t element_size, size_t element_count);
|
||||
|
||||
void end_pool();
|
||||
|
||||
|
||||
btGenericMemoryPool(size_t element_size, size_t element_count)
|
||||
{
|
||||
init_pool(element_size, element_count);
|
||||
}
|
||||
|
||||
~btGenericMemoryPool()
|
||||
{
|
||||
end_pool();
|
||||
}
|
||||
|
||||
|
||||
inline size_t get_pool_capacity()
|
||||
{
|
||||
return m_element_size*m_max_element_count;
|
||||
}
|
||||
|
||||
inline size_t gem_element_size()
|
||||
{
|
||||
return m_element_size;
|
||||
}
|
||||
|
||||
inline size_t get_max_element_count()
|
||||
{
|
||||
return m_max_element_count;
|
||||
}
|
||||
|
||||
inline size_t get_allocated_count()
|
||||
{
|
||||
return m_allocated_count;
|
||||
}
|
||||
|
||||
inline size_t get_free_positions_count()
|
||||
{
|
||||
return m_free_nodes_count;
|
||||
}
|
||||
|
||||
inline void * get_element_data(size_t element_index)
|
||||
{
|
||||
return &m_pool[element_index*m_element_size];
|
||||
}
|
||||
|
||||
//! Allocates memory in pool
|
||||
/*!
|
||||
\param size_bytes size in bytes of the buffer
|
||||
*/
|
||||
void * allocate(size_t size_bytes);
|
||||
|
||||
bool freeMemory(void * pointer);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
//! Generic Allocator with pools
|
||||
/*!
|
||||
General purpose Allocator which can create Memory Pools dynamiacally as needed.
|
||||
*/
|
||||
class btGenericPoolAllocator
|
||||
{
|
||||
protected:
|
||||
size_t m_pool_element_size;
|
||||
size_t m_pool_element_count;
|
||||
public:
|
||||
btGenericMemoryPool * m_pools[BT_DEFAULT_MAX_POOLS];
|
||||
size_t m_pool_count;
|
||||
|
||||
|
||||
inline size_t get_pool_capacity()
|
||||
{
|
||||
return m_pool_element_size*m_pool_element_count;
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
// creates a pool
|
||||
btGenericMemoryPool * push_new_pool();
|
||||
|
||||
void * failback_alloc(size_t size_bytes);
|
||||
|
||||
bool failback_free(void * pointer);
|
||||
public:
|
||||
|
||||
btGenericPoolAllocator(size_t pool_element_size, size_t pool_element_count)
|
||||
{
|
||||
m_pool_count = 0;
|
||||
m_pool_element_size = pool_element_size;
|
||||
m_pool_element_count = pool_element_count;
|
||||
}
|
||||
|
||||
virtual ~btGenericPoolAllocator();
|
||||
|
||||
//! Allocates memory in pool
|
||||
/*!
|
||||
\param size_bytes size in bytes of the buffer
|
||||
*/
|
||||
void * allocate(size_t size_bytes);
|
||||
|
||||
bool freeMemory(void * pointer);
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*! \defgroup POOL_MEMORY_FUNCTIONS
|
||||
standar managed Memory functions. Memory pools are used.
|
||||
*/
|
||||
//! @{
|
||||
void * btPoolAlloc(size_t size);
|
||||
void * btPoolRealloc(void *ptr, size_t oldsize, size_t newsize);
|
||||
void btPoolFree(void *ptr);
|
||||
//! @}
|
||||
|
||||
|
||||
#endif
|
||||
/*! \file btGenericPoolAllocator.h
|
||||
\author Francisco Len Nßjera. email projectileman@yahoo.com
|
||||
|
||||
General purpose allocator class
|
||||
*/
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef BT_GENERIC_POOL_ALLOCATOR_H
|
||||
#define BT_GENERIC_POOL_ALLOCATOR_H
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <memory.h>
|
||||
#include "LinearMath/btAlignedAllocator.h"
|
||||
|
||||
#define BT_UINT_MAX UINT_MAX
|
||||
#define BT_DEFAULT_MAX_POOLS 16
|
||||
|
||||
|
||||
//! Generic Pool class
|
||||
class btGenericMemoryPool
|
||||
{
|
||||
public:
|
||||
unsigned char * m_pool; //[m_element_size*m_max_element_count];
|
||||
size_t * m_free_nodes; //[m_max_element_count];//! free nodes
|
||||
size_t * m_allocated_sizes;//[m_max_element_count];//! Number of elements allocated per node
|
||||
size_t m_allocated_count;
|
||||
size_t m_free_nodes_count;
|
||||
protected:
|
||||
size_t m_element_size;
|
||||
size_t m_max_element_count;
|
||||
|
||||
size_t allocate_from_free_nodes(size_t num_elements);
|
||||
size_t allocate_from_pool(size_t num_elements);
|
||||
|
||||
public:
|
||||
|
||||
void init_pool(size_t element_size, size_t element_count);
|
||||
|
||||
void end_pool();
|
||||
|
||||
|
||||
btGenericMemoryPool(size_t element_size, size_t element_count)
|
||||
{
|
||||
init_pool(element_size, element_count);
|
||||
}
|
||||
|
||||
~btGenericMemoryPool()
|
||||
{
|
||||
end_pool();
|
||||
}
|
||||
|
||||
|
||||
inline size_t get_pool_capacity()
|
||||
{
|
||||
return m_element_size*m_max_element_count;
|
||||
}
|
||||
|
||||
inline size_t gem_element_size()
|
||||
{
|
||||
return m_element_size;
|
||||
}
|
||||
|
||||
inline size_t get_max_element_count()
|
||||
{
|
||||
return m_max_element_count;
|
||||
}
|
||||
|
||||
inline size_t get_allocated_count()
|
||||
{
|
||||
return m_allocated_count;
|
||||
}
|
||||
|
||||
inline size_t get_free_positions_count()
|
||||
{
|
||||
return m_free_nodes_count;
|
||||
}
|
||||
|
||||
inline void * get_element_data(size_t element_index)
|
||||
{
|
||||
return &m_pool[element_index*m_element_size];
|
||||
}
|
||||
|
||||
//! Allocates memory in pool
|
||||
/*!
|
||||
\param size_bytes size in bytes of the buffer
|
||||
*/
|
||||
void * allocate(size_t size_bytes);
|
||||
|
||||
bool freeMemory(void * pointer);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
//! Generic Allocator with pools
|
||||
/*!
|
||||
General purpose Allocator which can create Memory Pools dynamiacally as needed.
|
||||
*/
|
||||
class btGenericPoolAllocator
|
||||
{
|
||||
protected:
|
||||
size_t m_pool_element_size;
|
||||
size_t m_pool_element_count;
|
||||
public:
|
||||
btGenericMemoryPool * m_pools[BT_DEFAULT_MAX_POOLS];
|
||||
size_t m_pool_count;
|
||||
|
||||
|
||||
inline size_t get_pool_capacity()
|
||||
{
|
||||
return m_pool_element_size*m_pool_element_count;
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
// creates a pool
|
||||
btGenericMemoryPool * push_new_pool();
|
||||
|
||||
void * failback_alloc(size_t size_bytes);
|
||||
|
||||
bool failback_free(void * pointer);
|
||||
public:
|
||||
|
||||
btGenericPoolAllocator(size_t pool_element_size, size_t pool_element_count)
|
||||
{
|
||||
m_pool_count = 0;
|
||||
m_pool_element_size = pool_element_size;
|
||||
m_pool_element_count = pool_element_count;
|
||||
}
|
||||
|
||||
virtual ~btGenericPoolAllocator();
|
||||
|
||||
//! Allocates memory in pool
|
||||
/*!
|
||||
\param size_bytes size in bytes of the buffer
|
||||
*/
|
||||
void * allocate(size_t size_bytes);
|
||||
|
||||
bool freeMemory(void * pointer);
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*! \defgroup POOL_MEMORY_FUNCTIONS
|
||||
standar managed Memory functions. Memory pools are used.
|
||||
*/
|
||||
//! @{
|
||||
void * btPoolAlloc(size_t size);
|
||||
void * btPoolRealloc(void *ptr, size_t oldsize, size_t newsize);
|
||||
void btPoolFree(void *ptr);
|
||||
//! @}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -2,7 +2,7 @@
|
||||
#define BT_BASIC_GEOMETRY_OPERATIONS_H_INCLUDED
|
||||
|
||||
/*! \file btGeometryOperations.h
|
||||
*\author Francisco León Nájera
|
||||
*\author Francisco Len Nßjera
|
||||
|
||||
*/
|
||||
/*
|
||||
@@ -25,7 +25,7 @@ subject to the following restrictions:
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "GIMPACT/Bullet/btBoxCollision.h"
|
||||
#include "btBoxCollision.h"
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define BT_QUANTIZATION_H_INCLUDED
|
||||
|
||||
/*! \file btQuantization.h
|
||||
*\author Francisco León Nájera
|
||||
*\author Francisco Len Nßjera
|
||||
|
||||
*/
|
||||
/*
|
||||
@@ -1,5 +1,5 @@
|
||||
/*! \file btGImpactTriangleShape.h
|
||||
\author Francisco León Nájera
|
||||
\author Francisco Len Nßjera
|
||||
*/
|
||||
/*
|
||||
This source file is part of GIMPACT Library.
|
||||
@@ -21,7 +21,7 @@ subject to the following restrictions:
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "GIMPACT/Bullet/btTriangleShapeEx.h"
|
||||
#include "btTriangleShapeEx.h"
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*! \file btGImpactShape.h
|
||||
\author Francisco León Nájera
|
||||
\author Francisco Len Nßjera
|
||||
*/
|
||||
/*
|
||||
This source file is part of GIMPACT Library.
|
||||
@@ -27,9 +27,9 @@ subject to the following restrictions:
|
||||
|
||||
#include "BulletCollision/CollisionShapes/btCollisionShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btTriangleShape.h"
|
||||
#include "GIMPACT/Bullet/btBoxCollision.h"
|
||||
#include "GIMPACT/Bullet/btClipPolygon.h"
|
||||
#include "GIMPACT/Bullet/btGeometryOperations.h"
|
||||
#include "btBoxCollision.h"
|
||||
#include "btClipPolygon.h"
|
||||
#include "btGeometryOperations.h"
|
||||
|
||||
|
||||
#define MAX_TRI_CLIPPING 16
|
||||
664
Extras/GIMPACT/include/GIMPACT/core/gim_array.h → src/BulletCollision/Gimpact/gim_array.h
Executable file → Normal file
664
Extras/GIMPACT/include/GIMPACT/core/gim_array.h → src/BulletCollision/Gimpact/gim_array.h
Executable file → Normal file
@@ -1,332 +1,332 @@
|
||||
#ifndef GIM_ARRAY_H_INCLUDED
|
||||
#define GIM_ARRAY_H_INCLUDED
|
||||
/*! \file gim_array.h
|
||||
\author Francisco León Nájera
|
||||
*/
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
This source file is part of GIMPACT Library.
|
||||
|
||||
For the latest info, see http://gimpact.sourceforge.net/
|
||||
|
||||
Copyright (c) 2006 Francisco Leon Najera. 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.
|
||||
(3) The zlib/libpng license that is included with this library in
|
||||
the file GIMPACT-LICENSE-ZLIB.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, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "GIMPACT/core/gim_memory.h"
|
||||
|
||||
/*! \addtogroup CONTAINERS
|
||||
\brief
|
||||
Abstract class for template containers
|
||||
*/
|
||||
//! @{
|
||||
|
||||
#define GIM_ARRAY_GROW_INCREMENT 2
|
||||
#define GIM_ARRAY_GROW_FACTOR 2
|
||||
|
||||
//! Very simple array container with fast access and simd memory
|
||||
template<typename T>
|
||||
class gim_array
|
||||
{
|
||||
public:
|
||||
//! properties
|
||||
//!@{
|
||||
T *m_data;
|
||||
GUINT m_size;
|
||||
GUINT m_allocated_size;
|
||||
//!@}
|
||||
//! protected operations
|
||||
//!@{
|
||||
|
||||
inline void destroyData()
|
||||
{
|
||||
m_allocated_size = 0;
|
||||
if(m_data==NULL) return;
|
||||
gim_free(m_data);
|
||||
m_data = NULL;
|
||||
}
|
||||
|
||||
inline bool resizeData(GUINT newsize)
|
||||
{
|
||||
if(newsize==0)
|
||||
{
|
||||
destroyData();
|
||||
return true;
|
||||
}
|
||||
|
||||
if(m_size>0)
|
||||
{
|
||||
m_data = (T*)gim_realloc(m_data,m_size*sizeof(T),newsize*sizeof(T));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_data = (T*)gim_alloc(newsize*sizeof(T));
|
||||
}
|
||||
m_allocated_size = newsize;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool growingCheck()
|
||||
{
|
||||
if(m_allocated_size<=m_size)
|
||||
{
|
||||
GUINT requestsize = m_size;
|
||||
m_size = m_allocated_size;
|
||||
if(resizeData((requestsize+GIM_ARRAY_GROW_INCREMENT)*GIM_ARRAY_GROW_FACTOR)==false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//!@}
|
||||
//! public operations
|
||||
//!@{
|
||||
inline bool reserve(GUINT size)
|
||||
{
|
||||
if(m_allocated_size>=size) return false;
|
||||
return resizeData(size);
|
||||
}
|
||||
|
||||
inline void clear_range(GUINT start_range)
|
||||
{
|
||||
while(m_size>start_range)
|
||||
{
|
||||
m_data[--m_size].~T();
|
||||
}
|
||||
}
|
||||
|
||||
inline void clear()
|
||||
{
|
||||
if(m_size==0)return;
|
||||
clear_range(0);
|
||||
}
|
||||
|
||||
inline void clear_memory()
|
||||
{
|
||||
clear();
|
||||
destroyData();
|
||||
}
|
||||
|
||||
gim_array()
|
||||
{
|
||||
m_data = 0;
|
||||
m_size = 0;
|
||||
m_allocated_size = 0;
|
||||
}
|
||||
|
||||
gim_array(GUINT reservesize)
|
||||
{
|
||||
m_data = 0;
|
||||
m_size = 0;
|
||||
|
||||
m_allocated_size = 0;
|
||||
reserve(reservesize);
|
||||
}
|
||||
|
||||
~gim_array()
|
||||
{
|
||||
clear_memory();
|
||||
}
|
||||
|
||||
inline GUINT size() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
inline GUINT max_size() const
|
||||
{
|
||||
return m_allocated_size;
|
||||
}
|
||||
|
||||
inline T & operator[](size_t i)
|
||||
{
|
||||
return m_data[i];
|
||||
}
|
||||
inline const T & operator[](size_t i) const
|
||||
{
|
||||
return m_data[i];
|
||||
}
|
||||
|
||||
inline T * pointer(){ return m_data;}
|
||||
inline const T * pointer() const
|
||||
{ return m_data;}
|
||||
|
||||
|
||||
inline T * get_pointer_at(GUINT i)
|
||||
{
|
||||
return m_data + i;
|
||||
}
|
||||
|
||||
inline const T * get_pointer_at(GUINT i) const
|
||||
{
|
||||
return m_data + i;
|
||||
}
|
||||
|
||||
inline T & at(GUINT i)
|
||||
{
|
||||
return m_data[i];
|
||||
}
|
||||
|
||||
inline const T & at(GUINT i) const
|
||||
{
|
||||
return m_data[i];
|
||||
}
|
||||
|
||||
inline T & front()
|
||||
{
|
||||
return *m_data;
|
||||
}
|
||||
|
||||
inline const T & front() const
|
||||
{
|
||||
return *m_data;
|
||||
}
|
||||
|
||||
inline T & back()
|
||||
{
|
||||
return m_data[m_size-1];
|
||||
}
|
||||
|
||||
inline const T & back() const
|
||||
{
|
||||
return m_data[m_size-1];
|
||||
}
|
||||
|
||||
|
||||
inline void swap(GUINT i, GUINT j)
|
||||
{
|
||||
gim_swap_elements(m_data,i,j);
|
||||
}
|
||||
|
||||
inline void push_back(const T & obj)
|
||||
{
|
||||
this->growingCheck();
|
||||
m_data[m_size] = obj;
|
||||
m_size++;
|
||||
}
|
||||
|
||||
//!Simply increase the m_size, doesn't call the new element constructor
|
||||
inline void push_back_mem()
|
||||
{
|
||||
this->growingCheck();
|
||||
m_size++;
|
||||
}
|
||||
|
||||
inline void push_back_memcpy(const T & obj)
|
||||
{
|
||||
this->growingCheck();
|
||||
irr_simd_memcpy(&m_data[m_size],&obj,sizeof(T));
|
||||
m_size++;
|
||||
}
|
||||
|
||||
inline void pop_back()
|
||||
{
|
||||
m_size--;
|
||||
m_data[m_size].~T();
|
||||
}
|
||||
|
||||
//!Simply decrease the m_size, doesn't call the deleted element destructor
|
||||
inline void pop_back_mem()
|
||||
{
|
||||
m_size--;
|
||||
}
|
||||
|
||||
//! fast erase
|
||||
inline void erase(GUINT index)
|
||||
{
|
||||
if(index<m_size-1)
|
||||
{
|
||||
swap(index,m_size-1);
|
||||
}
|
||||
pop_back();
|
||||
}
|
||||
|
||||
inline void erase_sorted_mem(GUINT index)
|
||||
{
|
||||
m_size--;
|
||||
for(GUINT i = index;i<m_size;i++)
|
||||
{
|
||||
gim_simd_memcpy(m_data+i,m_data+i+1,sizeof(T));
|
||||
}
|
||||
}
|
||||
|
||||
inline void erase_sorted(GUINT index)
|
||||
{
|
||||
m_data[index].~T();
|
||||
erase_sorted_mem(index);
|
||||
}
|
||||
|
||||
inline void insert_mem(GUINT index)
|
||||
{
|
||||
this->growingCheck();
|
||||
for(GUINT i = m_size;i>index;i--)
|
||||
{
|
||||
gim_simd_memcpy(m_data+i,m_data+i-1,sizeof(T));
|
||||
}
|
||||
m_size++;
|
||||
}
|
||||
|
||||
inline void insert(const T & obj,GUINT index)
|
||||
{
|
||||
insert_mem(index);
|
||||
m_data[index] = obj;
|
||||
}
|
||||
|
||||
inline void resize(GUINT size, bool call_constructor = true)
|
||||
{
|
||||
|
||||
if(size>m_size)
|
||||
{
|
||||
reserve(size);
|
||||
if(call_constructor)
|
||||
{
|
||||
T obj;
|
||||
while(m_size<size)
|
||||
{
|
||||
m_data[m_size] = obj;
|
||||
m_size++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_size = size;
|
||||
}
|
||||
}
|
||||
else if(size<m_size)
|
||||
{
|
||||
if(call_constructor) clear_range(size);
|
||||
m_size = size;
|
||||
}
|
||||
}
|
||||
|
||||
inline void refit()
|
||||
{
|
||||
resizeData(m_size);
|
||||
}
|
||||
//!@}
|
||||
};
|
||||
|
||||
|
||||
//! @}
|
||||
|
||||
|
||||
|
||||
#endif // GIM_CONTAINERS_H_INCLUDED
|
||||
#ifndef GIM_ARRAY_H_INCLUDED
|
||||
#define GIM_ARRAY_H_INCLUDED
|
||||
/*! \file gim_array.h
|
||||
\author Francisco Len Nßjera
|
||||
*/
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
This source file is part of GIMPACT Library.
|
||||
|
||||
For the latest info, see http://gimpact.sourceforge.net/
|
||||
|
||||
Copyright (c) 2006 Francisco Leon Najera. 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.
|
||||
(3) The zlib/libpng license that is included with this library in
|
||||
the file GIMPACT-LICENSE-ZLIB.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, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "gim_memory.h"
|
||||
|
||||
/*! \addtogroup CONTAINERS
|
||||
\brief
|
||||
Abstract class for template containers
|
||||
*/
|
||||
//! @{
|
||||
|
||||
#define GIM_ARRAY_GROW_INCREMENT 2
|
||||
#define GIM_ARRAY_GROW_FACTOR 2
|
||||
|
||||
//! Very simple array container with fast access and simd memory
|
||||
template<typename T>
|
||||
class gim_array
|
||||
{
|
||||
public:
|
||||
//! properties
|
||||
//!@{
|
||||
T *m_data;
|
||||
GUINT m_size;
|
||||
GUINT m_allocated_size;
|
||||
//!@}
|
||||
//! protected operations
|
||||
//!@{
|
||||
|
||||
inline void destroyData()
|
||||
{
|
||||
m_allocated_size = 0;
|
||||
if(m_data==NULL) return;
|
||||
gim_free(m_data);
|
||||
m_data = NULL;
|
||||
}
|
||||
|
||||
inline bool resizeData(GUINT newsize)
|
||||
{
|
||||
if(newsize==0)
|
||||
{
|
||||
destroyData();
|
||||
return true;
|
||||
}
|
||||
|
||||
if(m_size>0)
|
||||
{
|
||||
m_data = (T*)gim_realloc(m_data,m_size*sizeof(T),newsize*sizeof(T));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_data = (T*)gim_alloc(newsize*sizeof(T));
|
||||
}
|
||||
m_allocated_size = newsize;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool growingCheck()
|
||||
{
|
||||
if(m_allocated_size<=m_size)
|
||||
{
|
||||
GUINT requestsize = m_size;
|
||||
m_size = m_allocated_size;
|
||||
if(resizeData((requestsize+GIM_ARRAY_GROW_INCREMENT)*GIM_ARRAY_GROW_FACTOR)==false) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//!@}
|
||||
//! public operations
|
||||
//!@{
|
||||
inline bool reserve(GUINT size)
|
||||
{
|
||||
if(m_allocated_size>=size) return false;
|
||||
return resizeData(size);
|
||||
}
|
||||
|
||||
inline void clear_range(GUINT start_range)
|
||||
{
|
||||
while(m_size>start_range)
|
||||
{
|
||||
m_data[--m_size].~T();
|
||||
}
|
||||
}
|
||||
|
||||
inline void clear()
|
||||
{
|
||||
if(m_size==0)return;
|
||||
clear_range(0);
|
||||
}
|
||||
|
||||
inline void clear_memory()
|
||||
{
|
||||
clear();
|
||||
destroyData();
|
||||
}
|
||||
|
||||
gim_array()
|
||||
{
|
||||
m_data = 0;
|
||||
m_size = 0;
|
||||
m_allocated_size = 0;
|
||||
}
|
||||
|
||||
gim_array(GUINT reservesize)
|
||||
{
|
||||
m_data = 0;
|
||||
m_size = 0;
|
||||
|
||||
m_allocated_size = 0;
|
||||
reserve(reservesize);
|
||||
}
|
||||
|
||||
~gim_array()
|
||||
{
|
||||
clear_memory();
|
||||
}
|
||||
|
||||
inline GUINT size() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
inline GUINT max_size() const
|
||||
{
|
||||
return m_allocated_size;
|
||||
}
|
||||
|
||||
inline T & operator[](size_t i)
|
||||
{
|
||||
return m_data[i];
|
||||
}
|
||||
inline const T & operator[](size_t i) const
|
||||
{
|
||||
return m_data[i];
|
||||
}
|
||||
|
||||
inline T * pointer(){ return m_data;}
|
||||
inline const T * pointer() const
|
||||
{ return m_data;}
|
||||
|
||||
|
||||
inline T * get_pointer_at(GUINT i)
|
||||
{
|
||||
return m_data + i;
|
||||
}
|
||||
|
||||
inline const T * get_pointer_at(GUINT i) const
|
||||
{
|
||||
return m_data + i;
|
||||
}
|
||||
|
||||
inline T & at(GUINT i)
|
||||
{
|
||||
return m_data[i];
|
||||
}
|
||||
|
||||
inline const T & at(GUINT i) const
|
||||
{
|
||||
return m_data[i];
|
||||
}
|
||||
|
||||
inline T & front()
|
||||
{
|
||||
return *m_data;
|
||||
}
|
||||
|
||||
inline const T & front() const
|
||||
{
|
||||
return *m_data;
|
||||
}
|
||||
|
||||
inline T & back()
|
||||
{
|
||||
return m_data[m_size-1];
|
||||
}
|
||||
|
||||
inline const T & back() const
|
||||
{
|
||||
return m_data[m_size-1];
|
||||
}
|
||||
|
||||
|
||||
inline void swap(GUINT i, GUINT j)
|
||||
{
|
||||
gim_swap_elements(m_data,i,j);
|
||||
}
|
||||
|
||||
inline void push_back(const T & obj)
|
||||
{
|
||||
this->growingCheck();
|
||||
m_data[m_size] = obj;
|
||||
m_size++;
|
||||
}
|
||||
|
||||
//!Simply increase the m_size, doesn't call the new element constructor
|
||||
inline void push_back_mem()
|
||||
{
|
||||
this->growingCheck();
|
||||
m_size++;
|
||||
}
|
||||
|
||||
inline void push_back_memcpy(const T & obj)
|
||||
{
|
||||
this->growingCheck();
|
||||
irr_simd_memcpy(&m_data[m_size],&obj,sizeof(T));
|
||||
m_size++;
|
||||
}
|
||||
|
||||
inline void pop_back()
|
||||
{
|
||||
m_size--;
|
||||
m_data[m_size].~T();
|
||||
}
|
||||
|
||||
//!Simply decrease the m_size, doesn't call the deleted element destructor
|
||||
inline void pop_back_mem()
|
||||
{
|
||||
m_size--;
|
||||
}
|
||||
|
||||
//! fast erase
|
||||
inline void erase(GUINT index)
|
||||
{
|
||||
if(index<m_size-1)
|
||||
{
|
||||
swap(index,m_size-1);
|
||||
}
|
||||
pop_back();
|
||||
}
|
||||
|
||||
inline void erase_sorted_mem(GUINT index)
|
||||
{
|
||||
m_size--;
|
||||
for(GUINT i = index;i<m_size;i++)
|
||||
{
|
||||
gim_simd_memcpy(m_data+i,m_data+i+1,sizeof(T));
|
||||
}
|
||||
}
|
||||
|
||||
inline void erase_sorted(GUINT index)
|
||||
{
|
||||
m_data[index].~T();
|
||||
erase_sorted_mem(index);
|
||||
}
|
||||
|
||||
inline void insert_mem(GUINT index)
|
||||
{
|
||||
this->growingCheck();
|
||||
for(GUINT i = m_size;i>index;i--)
|
||||
{
|
||||
gim_simd_memcpy(m_data+i,m_data+i-1,sizeof(T));
|
||||
}
|
||||
m_size++;
|
||||
}
|
||||
|
||||
inline void insert(const T & obj,GUINT index)
|
||||
{
|
||||
insert_mem(index);
|
||||
m_data[index] = obj;
|
||||
}
|
||||
|
||||
inline void resize(GUINT size, bool call_constructor = true)
|
||||
{
|
||||
|
||||
if(size>m_size)
|
||||
{
|
||||
reserve(size);
|
||||
if(call_constructor)
|
||||
{
|
||||
T obj;
|
||||
while(m_size<size)
|
||||
{
|
||||
m_data[m_size] = obj;
|
||||
m_size++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_size = size;
|
||||
}
|
||||
}
|
||||
else if(size<m_size)
|
||||
{
|
||||
if(call_constructor) clear_range(size);
|
||||
m_size = size;
|
||||
}
|
||||
}
|
||||
|
||||
inline void refit()
|
||||
{
|
||||
resizeData(m_size);
|
||||
}
|
||||
//!@}
|
||||
};
|
||||
|
||||
|
||||
//! @}
|
||||
|
||||
|
||||
|
||||
#endif // GIM_CONTAINERS_H_INCLUDED
|
||||
1094
Extras/GIMPACT/include/GIMPACT/core/gim_basic_geometry_operations.h → src/BulletCollision/Gimpact/gim_basic_geometry_operations.h
Executable file → Normal file
1094
Extras/GIMPACT/include/GIMPACT/core/gim_basic_geometry_operations.h → src/BulletCollision/Gimpact/gim_basic_geometry_operations.h
Executable file → Normal file
File diff suppressed because it is too large
Load Diff
258
Extras/GIMPACT/include/GIMPACT/core/gim_bitset.h → src/BulletCollision/Gimpact/gim_bitset.h
Executable file → Normal file
258
Extras/GIMPACT/include/GIMPACT/core/gim_bitset.h → src/BulletCollision/Gimpact/gim_bitset.h
Executable file → Normal file
@@ -1,129 +1,129 @@
|
||||
#ifndef GIM_BITSET_H_INCLUDED
|
||||
#define GIM_BITSET_H_INCLUDED
|
||||
/*! \file gim_bitset.h
|
||||
\author Francisco León Nájera
|
||||
*/
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
This source file is part of GIMPACT Library.
|
||||
|
||||
For the latest info, see http://gimpact.sourceforge.net/
|
||||
|
||||
Copyright (c) 2006 Francisco Leon Najera. 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.
|
||||
(3) The zlib/libpng license that is included with this library in
|
||||
the file GIMPACT-LICENSE-ZLIB.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, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "GIMPACT/core/gim_array.h"
|
||||
|
||||
/*! \addtogroup CONTAINERS
|
||||
\brief
|
||||
Abstract class for template containers
|
||||
*/
|
||||
//! @{
|
||||
|
||||
#define GUINT_BIT_COUNT 32
|
||||
#define GUINT_EXPONENT 5
|
||||
|
||||
class gim_bitset
|
||||
{
|
||||
public:
|
||||
gim_array<GUINT> m_container;
|
||||
|
||||
gim_bitset()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
gim_bitset(GUINT bits_count)
|
||||
{
|
||||
resize(bits_count);
|
||||
}
|
||||
|
||||
~gim_bitset()
|
||||
{
|
||||
}
|
||||
|
||||
inline bool resize(GUINT newsize)
|
||||
{
|
||||
GUINT oldsize = m_container.size();
|
||||
m_container.resize(newsize/GUINT_BIT_COUNT + 1,false);
|
||||
while(oldsize<m_container.size())
|
||||
{
|
||||
m_container[oldsize] = 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
inline GUINT size()
|
||||
{
|
||||
return m_container.size()*GUINT_BIT_COUNT;
|
||||
}
|
||||
|
||||
inline void set_all()
|
||||
{
|
||||
for(GUINT i = 0;i<m_container.size();++i)
|
||||
{
|
||||
m_container[i] = 0xffffffff;
|
||||
}
|
||||
}
|
||||
|
||||
inline void clear_all()
|
||||
{
|
||||
for(GUINT i = 0;i<m_container.size();++i)
|
||||
{
|
||||
m_container[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
inline void set(GUINT bit_index)
|
||||
{
|
||||
if(bit_index>=size())
|
||||
{
|
||||
resize(bit_index);
|
||||
}
|
||||
m_container[bit_index >> GUINT_EXPONENT] |= (1 << (bit_index & (GUINT_BIT_COUNT-1)));
|
||||
}
|
||||
|
||||
///Return 0 or 1
|
||||
inline char get(GUINT bit_index)
|
||||
{
|
||||
if(bit_index>=size())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
char value = m_container[bit_index >> GUINT_EXPONENT] &
|
||||
(1 << (bit_index & (GUINT_BIT_COUNT-1)));
|
||||
return value;
|
||||
}
|
||||
|
||||
inline void clear(GUINT bit_index)
|
||||
{
|
||||
m_container[bit_index >> GUINT_EXPONENT] &= ~(1 << (bit_index & (GUINT_BIT_COUNT-1)));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//! @}
|
||||
|
||||
|
||||
|
||||
#endif // GIM_CONTAINERS_H_INCLUDED
|
||||
#ifndef GIM_BITSET_H_INCLUDED
|
||||
#define GIM_BITSET_H_INCLUDED
|
||||
/*! \file gim_bitset.h
|
||||
\author Francisco Len Nßjera
|
||||
*/
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
This source file is part of GIMPACT Library.
|
||||
|
||||
For the latest info, see http://gimpact.sourceforge.net/
|
||||
|
||||
Copyright (c) 2006 Francisco Leon Najera. 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.
|
||||
(3) The zlib/libpng license that is included with this library in
|
||||
the file GIMPACT-LICENSE-ZLIB.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, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "gim_array.h"
|
||||
|
||||
/*! \addtogroup CONTAINERS
|
||||
\brief
|
||||
Abstract class for template containers
|
||||
*/
|
||||
//! @{
|
||||
|
||||
#define GUINT_BIT_COUNT 32
|
||||
#define GUINT_EXPONENT 5
|
||||
|
||||
class gim_bitset
|
||||
{
|
||||
public:
|
||||
gim_array<GUINT> m_container;
|
||||
|
||||
gim_bitset()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
gim_bitset(GUINT bits_count)
|
||||
{
|
||||
resize(bits_count);
|
||||
}
|
||||
|
||||
~gim_bitset()
|
||||
{
|
||||
}
|
||||
|
||||
inline bool resize(GUINT newsize)
|
||||
{
|
||||
GUINT oldsize = m_container.size();
|
||||
m_container.resize(newsize/GUINT_BIT_COUNT + 1,false);
|
||||
while(oldsize<m_container.size())
|
||||
{
|
||||
m_container[oldsize] = 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
inline GUINT size()
|
||||
{
|
||||
return m_container.size()*GUINT_BIT_COUNT;
|
||||
}
|
||||
|
||||
inline void set_all()
|
||||
{
|
||||
for(GUINT i = 0;i<m_container.size();++i)
|
||||
{
|
||||
m_container[i] = 0xffffffff;
|
||||
}
|
||||
}
|
||||
|
||||
inline void clear_all()
|
||||
{
|
||||
for(GUINT i = 0;i<m_container.size();++i)
|
||||
{
|
||||
m_container[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
inline void set(GUINT bit_index)
|
||||
{
|
||||
if(bit_index>=size())
|
||||
{
|
||||
resize(bit_index);
|
||||
}
|
||||
m_container[bit_index >> GUINT_EXPONENT] |= (1 << (bit_index & (GUINT_BIT_COUNT-1)));
|
||||
}
|
||||
|
||||
///Return 0 or 1
|
||||
inline char get(GUINT bit_index)
|
||||
{
|
||||
if(bit_index>=size())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
char value = m_container[bit_index >> GUINT_EXPONENT] &
|
||||
(1 << (bit_index & (GUINT_BIT_COUNT-1)));
|
||||
return value;
|
||||
}
|
||||
|
||||
inline void clear(GUINT bit_index)
|
||||
{
|
||||
m_container[bit_index >> GUINT_EXPONENT] &= ~(1 << (bit_index & (GUINT_BIT_COUNT-1)));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//! @}
|
||||
|
||||
|
||||
|
||||
#endif // GIM_CONTAINERS_H_INCLUDED
|
||||
1188
Extras/GIMPACT/include/GIMPACT/core/gim_box_collision.h → src/BulletCollision/Gimpact/gim_box_collision.h
Executable file → Normal file
1188
Extras/GIMPACT/include/GIMPACT/core/gim_box_collision.h → src/BulletCollision/Gimpact/gim_box_collision.h
Executable file → Normal file
File diff suppressed because it is too large
Load Diff
364
Extras/GIMPACT/src/core/gim_box_set.cpp → src/BulletCollision/Gimpact/gim_box_set.cpp
Executable file → Normal file
364
Extras/GIMPACT/src/core/gim_box_set.cpp → src/BulletCollision/Gimpact/gim_box_set.cpp
Executable file → Normal file
@@ -1,182 +1,182 @@
|
||||
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
This source file is part of GIMPACT Library.
|
||||
|
||||
For the latest info, see http://gimpact.sourceforge.net/
|
||||
|
||||
Copyright (c) 2006 Francisco Leon Najera. 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.
|
||||
(3) The zlib/libpng license that is included with this library in
|
||||
the file GIMPACT-LICENSE-ZLIB.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, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#include "GIMPACT/core/gim_box_set.h"
|
||||
|
||||
|
||||
GUINT GIM_BOX_TREE::_calc_splitting_axis(
|
||||
gim_array<GIM_AABB_DATA> & primitive_boxes, GUINT startIndex, GUINT endIndex)
|
||||
{
|
||||
GUINT i;
|
||||
|
||||
btVector3 means(btScalar(0.),btScalar(0.),btScalar(0.));
|
||||
btVector3 variance(btScalar(0.),btScalar(0.),btScalar(0.));
|
||||
GUINT numIndices = endIndex-startIndex;
|
||||
|
||||
for (i=startIndex;i<endIndex;i++)
|
||||
{
|
||||
btVector3 center = btScalar(0.5)*(primitive_boxes[i].m_bound.m_max +
|
||||
primitive_boxes[i].m_bound.m_min);
|
||||
means+=center;
|
||||
}
|
||||
means *= (btScalar(1.)/(btScalar)numIndices);
|
||||
|
||||
for (i=startIndex;i<endIndex;i++)
|
||||
{
|
||||
btVector3 center = btScalar(0.5)*(primitive_boxes[i].m_bound.m_max +
|
||||
primitive_boxes[i].m_bound.m_min);
|
||||
btVector3 diff2 = center-means;
|
||||
diff2 = diff2 * diff2;
|
||||
variance += diff2;
|
||||
}
|
||||
variance *= (btScalar(1.)/ ((btScalar)numIndices-1) );
|
||||
|
||||
return variance.maxAxis();
|
||||
}
|
||||
|
||||
|
||||
GUINT GIM_BOX_TREE::_sort_and_calc_splitting_index(
|
||||
gim_array<GIM_AABB_DATA> & primitive_boxes, GUINT startIndex,
|
||||
GUINT endIndex, GUINT splitAxis)
|
||||
{
|
||||
GUINT i;
|
||||
GUINT splitIndex =startIndex;
|
||||
GUINT numIndices = endIndex - startIndex;
|
||||
|
||||
// average of centers
|
||||
btScalar splitValue = 0.0f;
|
||||
for (i=startIndex;i<endIndex;i++)
|
||||
{
|
||||
splitValue+= 0.5f*(primitive_boxes[i].m_bound.m_max[splitAxis] +
|
||||
primitive_boxes[i].m_bound.m_min[splitAxis]);
|
||||
}
|
||||
splitValue /= (btScalar)numIndices;
|
||||
|
||||
//sort leafNodes so all values larger then splitValue comes first, and smaller values start from 'splitIndex'.
|
||||
for (i=startIndex;i<endIndex;i++)
|
||||
{
|
||||
btScalar center = 0.5f*(primitive_boxes[i].m_bound.m_max[splitAxis] +
|
||||
primitive_boxes[i].m_bound.m_min[splitAxis]);
|
||||
if (center > splitValue)
|
||||
{
|
||||
//swap
|
||||
primitive_boxes.swap(i,splitIndex);
|
||||
splitIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
//if the splitIndex causes unbalanced trees, fix this by using the center in between startIndex and endIndex
|
||||
//otherwise the tree-building might fail due to stack-overflows in certain cases.
|
||||
//unbalanced1 is unsafe: it can cause stack overflows
|
||||
//bool unbalanced1 = ((splitIndex==startIndex) || (splitIndex == (endIndex-1)));
|
||||
|
||||
//unbalanced2 should work too: always use center (perfect balanced trees)
|
||||
//bool unbalanced2 = true;
|
||||
|
||||
//this should be safe too:
|
||||
GUINT rangeBalancedIndices = numIndices/3;
|
||||
bool unbalanced = ((splitIndex<=(startIndex+rangeBalancedIndices)) || (splitIndex >=(endIndex-1-rangeBalancedIndices)));
|
||||
|
||||
if (unbalanced)
|
||||
{
|
||||
splitIndex = startIndex+ (numIndices>>1);
|
||||
}
|
||||
|
||||
bool unbal = (splitIndex==startIndex) || (splitIndex == (endIndex));
|
||||
btAssert(!unbal);
|
||||
|
||||
return splitIndex;
|
||||
}
|
||||
|
||||
|
||||
void GIM_BOX_TREE::_build_sub_tree(gim_array<GIM_AABB_DATA> & primitive_boxes, GUINT startIndex, GUINT endIndex)
|
||||
{
|
||||
GUINT current_index = m_num_nodes++;
|
||||
|
||||
btAssert((endIndex-startIndex)>0);
|
||||
|
||||
if((endIndex-startIndex) == 1) //we got a leaf
|
||||
{
|
||||
m_node_array[current_index].m_left = 0;
|
||||
m_node_array[current_index].m_right = 0;
|
||||
m_node_array[current_index].m_escapeIndex = 0;
|
||||
|
||||
m_node_array[current_index].m_bound = primitive_boxes[startIndex].m_bound;
|
||||
m_node_array[current_index].m_data = primitive_boxes[startIndex].m_data;
|
||||
return;
|
||||
}
|
||||
|
||||
//configure inner node
|
||||
|
||||
GUINT splitIndex;
|
||||
|
||||
//calc this node bounding box
|
||||
m_node_array[current_index].m_bound.invalidate();
|
||||
for (splitIndex=startIndex;splitIndex<endIndex;splitIndex++)
|
||||
{
|
||||
m_node_array[current_index].m_bound.merge(primitive_boxes[splitIndex].m_bound);
|
||||
}
|
||||
|
||||
//calculate Best Splitting Axis and where to split it. Sort the incoming 'leafNodes' array within range 'startIndex/endIndex'.
|
||||
|
||||
//split axis
|
||||
splitIndex = _calc_splitting_axis(primitive_boxes,startIndex,endIndex);
|
||||
|
||||
splitIndex = _sort_and_calc_splitting_index(
|
||||
primitive_boxes,startIndex,endIndex,splitIndex);
|
||||
|
||||
//configure this inner node : the left node index
|
||||
m_node_array[current_index].m_left = m_num_nodes;
|
||||
//build left child tree
|
||||
_build_sub_tree(primitive_boxes, startIndex, splitIndex );
|
||||
|
||||
//configure this inner node : the right node index
|
||||
m_node_array[current_index].m_right = m_num_nodes;
|
||||
|
||||
//build right child tree
|
||||
_build_sub_tree(primitive_boxes, splitIndex ,endIndex);
|
||||
|
||||
//configure this inner node : the escape index
|
||||
m_node_array[current_index].m_escapeIndex = m_num_nodes - current_index;
|
||||
}
|
||||
|
||||
//! stackless build tree
|
||||
void GIM_BOX_TREE::build_tree(
|
||||
gim_array<GIM_AABB_DATA> & primitive_boxes)
|
||||
{
|
||||
// initialize node count to 0
|
||||
m_num_nodes = 0;
|
||||
// allocate nodes
|
||||
m_node_array.resize(primitive_boxes.size()*2);
|
||||
|
||||
_build_sub_tree(primitive_boxes, 0, primitive_boxes.size());
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
This source file is part of GIMPACT Library.
|
||||
|
||||
For the latest info, see http://gimpact.sourceforge.net/
|
||||
|
||||
Copyright (c) 2006 Francisco Leon Najera. 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.
|
||||
(3) The zlib/libpng license that is included with this library in
|
||||
the file GIMPACT-LICENSE-ZLIB.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, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#include "gim_box_set.h"
|
||||
|
||||
|
||||
GUINT GIM_BOX_TREE::_calc_splitting_axis(
|
||||
gim_array<GIM_AABB_DATA> & primitive_boxes, GUINT startIndex, GUINT endIndex)
|
||||
{
|
||||
GUINT i;
|
||||
|
||||
btVector3 means(btScalar(0.),btScalar(0.),btScalar(0.));
|
||||
btVector3 variance(btScalar(0.),btScalar(0.),btScalar(0.));
|
||||
GUINT numIndices = endIndex-startIndex;
|
||||
|
||||
for (i=startIndex;i<endIndex;i++)
|
||||
{
|
||||
btVector3 center = btScalar(0.5)*(primitive_boxes[i].m_bound.m_max +
|
||||
primitive_boxes[i].m_bound.m_min);
|
||||
means+=center;
|
||||
}
|
||||
means *= (btScalar(1.)/(btScalar)numIndices);
|
||||
|
||||
for (i=startIndex;i<endIndex;i++)
|
||||
{
|
||||
btVector3 center = btScalar(0.5)*(primitive_boxes[i].m_bound.m_max +
|
||||
primitive_boxes[i].m_bound.m_min);
|
||||
btVector3 diff2 = center-means;
|
||||
diff2 = diff2 * diff2;
|
||||
variance += diff2;
|
||||
}
|
||||
variance *= (btScalar(1.)/ ((btScalar)numIndices-1) );
|
||||
|
||||
return variance.maxAxis();
|
||||
}
|
||||
|
||||
|
||||
GUINT GIM_BOX_TREE::_sort_and_calc_splitting_index(
|
||||
gim_array<GIM_AABB_DATA> & primitive_boxes, GUINT startIndex,
|
||||
GUINT endIndex, GUINT splitAxis)
|
||||
{
|
||||
GUINT i;
|
||||
GUINT splitIndex =startIndex;
|
||||
GUINT numIndices = endIndex - startIndex;
|
||||
|
||||
// average of centers
|
||||
btScalar splitValue = 0.0f;
|
||||
for (i=startIndex;i<endIndex;i++)
|
||||
{
|
||||
splitValue+= 0.5f*(primitive_boxes[i].m_bound.m_max[splitAxis] +
|
||||
primitive_boxes[i].m_bound.m_min[splitAxis]);
|
||||
}
|
||||
splitValue /= (btScalar)numIndices;
|
||||
|
||||
//sort leafNodes so all values larger then splitValue comes first, and smaller values start from 'splitIndex'.
|
||||
for (i=startIndex;i<endIndex;i++)
|
||||
{
|
||||
btScalar center = 0.5f*(primitive_boxes[i].m_bound.m_max[splitAxis] +
|
||||
primitive_boxes[i].m_bound.m_min[splitAxis]);
|
||||
if (center > splitValue)
|
||||
{
|
||||
//swap
|
||||
primitive_boxes.swap(i,splitIndex);
|
||||
splitIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
//if the splitIndex causes unbalanced trees, fix this by using the center in between startIndex and endIndex
|
||||
//otherwise the tree-building might fail due to stack-overflows in certain cases.
|
||||
//unbalanced1 is unsafe: it can cause stack overflows
|
||||
//bool unbalanced1 = ((splitIndex==startIndex) || (splitIndex == (endIndex-1)));
|
||||
|
||||
//unbalanced2 should work too: always use center (perfect balanced trees)
|
||||
//bool unbalanced2 = true;
|
||||
|
||||
//this should be safe too:
|
||||
GUINT rangeBalancedIndices = numIndices/3;
|
||||
bool unbalanced = ((splitIndex<=(startIndex+rangeBalancedIndices)) || (splitIndex >=(endIndex-1-rangeBalancedIndices)));
|
||||
|
||||
if (unbalanced)
|
||||
{
|
||||
splitIndex = startIndex+ (numIndices>>1);
|
||||
}
|
||||
|
||||
bool unbal = (splitIndex==startIndex) || (splitIndex == (endIndex));
|
||||
btAssert(!unbal);
|
||||
|
||||
return splitIndex;
|
||||
}
|
||||
|
||||
|
||||
void GIM_BOX_TREE::_build_sub_tree(gim_array<GIM_AABB_DATA> & primitive_boxes, GUINT startIndex, GUINT endIndex)
|
||||
{
|
||||
GUINT current_index = m_num_nodes++;
|
||||
|
||||
btAssert((endIndex-startIndex)>0);
|
||||
|
||||
if((endIndex-startIndex) == 1) //we got a leaf
|
||||
{
|
||||
m_node_array[current_index].m_left = 0;
|
||||
m_node_array[current_index].m_right = 0;
|
||||
m_node_array[current_index].m_escapeIndex = 0;
|
||||
|
||||
m_node_array[current_index].m_bound = primitive_boxes[startIndex].m_bound;
|
||||
m_node_array[current_index].m_data = primitive_boxes[startIndex].m_data;
|
||||
return;
|
||||
}
|
||||
|
||||
//configure inner node
|
||||
|
||||
GUINT splitIndex;
|
||||
|
||||
//calc this node bounding box
|
||||
m_node_array[current_index].m_bound.invalidate();
|
||||
for (splitIndex=startIndex;splitIndex<endIndex;splitIndex++)
|
||||
{
|
||||
m_node_array[current_index].m_bound.merge(primitive_boxes[splitIndex].m_bound);
|
||||
}
|
||||
|
||||
//calculate Best Splitting Axis and where to split it. Sort the incoming 'leafNodes' array within range 'startIndex/endIndex'.
|
||||
|
||||
//split axis
|
||||
splitIndex = _calc_splitting_axis(primitive_boxes,startIndex,endIndex);
|
||||
|
||||
splitIndex = _sort_and_calc_splitting_index(
|
||||
primitive_boxes,startIndex,endIndex,splitIndex);
|
||||
|
||||
//configure this inner node : the left node index
|
||||
m_node_array[current_index].m_left = m_num_nodes;
|
||||
//build left child tree
|
||||
_build_sub_tree(primitive_boxes, startIndex, splitIndex );
|
||||
|
||||
//configure this inner node : the right node index
|
||||
m_node_array[current_index].m_right = m_num_nodes;
|
||||
|
||||
//build right child tree
|
||||
_build_sub_tree(primitive_boxes, splitIndex ,endIndex);
|
||||
|
||||
//configure this inner node : the escape index
|
||||
m_node_array[current_index].m_escapeIndex = m_num_nodes - current_index;
|
||||
}
|
||||
|
||||
//! stackless build tree
|
||||
void GIM_BOX_TREE::build_tree(
|
||||
gim_array<GIM_AABB_DATA> & primitive_boxes)
|
||||
{
|
||||
// initialize node count to 0
|
||||
m_num_nodes = 0;
|
||||
// allocate nodes
|
||||
m_node_array.resize(primitive_boxes.size()*2);
|
||||
|
||||
_build_sub_tree(primitive_boxes, 0, primitive_boxes.size());
|
||||
}
|
||||
|
||||
1356
Extras/GIMPACT/include/GIMPACT/core/gim_box_set.h → src/BulletCollision/Gimpact/gim_box_set.h
Executable file → Normal file
1356
Extras/GIMPACT/include/GIMPACT/core/gim_box_set.h → src/BulletCollision/Gimpact/gim_box_set.h
Executable file → Normal file
File diff suppressed because it is too large
Load Diff
428
Extras/GIMPACT/include/GIMPACT/core/gim_clip_polygon.h → src/BulletCollision/Gimpact/gim_clip_polygon.h
Executable file → Normal file
428
Extras/GIMPACT/include/GIMPACT/core/gim_clip_polygon.h → src/BulletCollision/Gimpact/gim_clip_polygon.h
Executable file → Normal file
@@ -1,214 +1,214 @@
|
||||
#ifndef GIM_CLIP_POLYGON_H_INCLUDED
|
||||
#define GIM_CLIP_POLYGON_H_INCLUDED
|
||||
|
||||
/*! \file gim_tri_collision.h
|
||||
\author Francisco León Nájera
|
||||
*/
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
This source file is part of GIMPACT Library.
|
||||
|
||||
For the latest info, see http://gimpact.sourceforge.net/
|
||||
|
||||
Copyright (c) 2006 Francisco Leon Najera. 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.
|
||||
(3) The zlib/libpng license that is included with this library in
|
||||
the file GIMPACT-LICENSE-ZLIB.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, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*! \addtogroup GEOMETRIC_OPERATIONS
|
||||
*/
|
||||
//! @{
|
||||
|
||||
//! This function calcs the distance from a 3D plane
|
||||
class DISTANCE_PLANE_3D_FUNC
|
||||
{
|
||||
public:
|
||||
template<typename CLASS_POINT,typename CLASS_PLANE>
|
||||
inline GREAL operator()(const CLASS_PLANE & plane, const CLASS_POINT & point)
|
||||
{
|
||||
return DISTANCE_PLANE_POINT(plane, point);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
template<typename CLASS_POINT>
|
||||
SIMD_FORCE_INLINE void PLANE_CLIP_POLYGON_COLLECT(
|
||||
const CLASS_POINT & point0,
|
||||
const CLASS_POINT & point1,
|
||||
GREAL dist0,
|
||||
GREAL dist1,
|
||||
CLASS_POINT * clipped,
|
||||
GUINT & clipped_count)
|
||||
{
|
||||
GUINT _prevclassif = (dist0>G_EPSILON);
|
||||
GUINT _classif = (dist1>G_EPSILON);
|
||||
if(_classif!=_prevclassif)
|
||||
{
|
||||
GREAL blendfactor = -dist0/(dist1-dist0);
|
||||
VEC_BLEND(clipped[clipped_count],point0,point1,blendfactor);
|
||||
clipped_count++;
|
||||
}
|
||||
if(!_classif)
|
||||
{
|
||||
VEC_COPY(clipped[clipped_count],point1);
|
||||
clipped_count++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//! Clips a polygon by a plane
|
||||
/*!
|
||||
*\return The count of the clipped counts
|
||||
*/
|
||||
template<typename CLASS_POINT,typename CLASS_PLANE, typename DISTANCE_PLANE_FUNC>
|
||||
SIMD_FORCE_INLINE GUINT PLANE_CLIP_POLYGON_GENERIC(
|
||||
const CLASS_PLANE & plane,
|
||||
const CLASS_POINT * polygon_points,
|
||||
GUINT polygon_point_count,
|
||||
CLASS_POINT * clipped,DISTANCE_PLANE_FUNC distance_func)
|
||||
{
|
||||
GUINT clipped_count = 0;
|
||||
|
||||
|
||||
//clip first point
|
||||
GREAL firstdist = distance_func(plane,polygon_points[0]);;
|
||||
if(!(firstdist>G_EPSILON))
|
||||
{
|
||||
VEC_COPY(clipped[clipped_count],polygon_points[0]);
|
||||
clipped_count++;
|
||||
}
|
||||
|
||||
GREAL olddist = firstdist;
|
||||
for(GUINT _i=1;_i<polygon_point_count;_i++)
|
||||
{
|
||||
GREAL dist = distance_func(plane,polygon_points[_i]);
|
||||
|
||||
PLANE_CLIP_POLYGON_COLLECT(
|
||||
polygon_points[_i-1],polygon_points[_i],
|
||||
olddist,
|
||||
dist,
|
||||
clipped,
|
||||
clipped_count);
|
||||
|
||||
|
||||
olddist = dist;
|
||||
}
|
||||
|
||||
//RETURN TO FIRST point
|
||||
|
||||
PLANE_CLIP_POLYGON_COLLECT(
|
||||
polygon_points[polygon_point_count-1],polygon_points[0],
|
||||
olddist,
|
||||
firstdist,
|
||||
clipped,
|
||||
clipped_count);
|
||||
|
||||
return clipped_count;
|
||||
}
|
||||
|
||||
//! Clips a polygon by a plane
|
||||
/*!
|
||||
*\return The count of the clipped counts
|
||||
*/
|
||||
template<typename CLASS_POINT,typename CLASS_PLANE, typename DISTANCE_PLANE_FUNC>
|
||||
SIMD_FORCE_INLINE GUINT PLANE_CLIP_TRIANGLE_GENERIC(
|
||||
const CLASS_PLANE & plane,
|
||||
const CLASS_POINT & point0,
|
||||
const CLASS_POINT & point1,
|
||||
const CLASS_POINT & point2,
|
||||
CLASS_POINT * clipped,DISTANCE_PLANE_FUNC distance_func)
|
||||
{
|
||||
GUINT clipped_count = 0;
|
||||
|
||||
//clip first point
|
||||
GREAL firstdist = distance_func(plane,point0);;
|
||||
if(!(firstdist>G_EPSILON))
|
||||
{
|
||||
VEC_COPY(clipped[clipped_count],point0);
|
||||
clipped_count++;
|
||||
}
|
||||
|
||||
// point 1
|
||||
GREAL olddist = firstdist;
|
||||
GREAL dist = distance_func(plane,point1);
|
||||
|
||||
PLANE_CLIP_POLYGON_COLLECT(
|
||||
point0,point1,
|
||||
olddist,
|
||||
dist,
|
||||
clipped,
|
||||
clipped_count);
|
||||
|
||||
olddist = dist;
|
||||
|
||||
|
||||
// point 2
|
||||
dist = distance_func(plane,point2);
|
||||
|
||||
PLANE_CLIP_POLYGON_COLLECT(
|
||||
point1,point2,
|
||||
olddist,
|
||||
dist,
|
||||
clipped,
|
||||
clipped_count);
|
||||
olddist = dist;
|
||||
|
||||
|
||||
|
||||
//RETURN TO FIRST point
|
||||
PLANE_CLIP_POLYGON_COLLECT(
|
||||
point2,point0,
|
||||
olddist,
|
||||
firstdist,
|
||||
clipped,
|
||||
clipped_count);
|
||||
|
||||
return clipped_count;
|
||||
}
|
||||
|
||||
|
||||
template<typename CLASS_POINT,typename CLASS_PLANE>
|
||||
SIMD_FORCE_INLINE GUINT PLANE_CLIP_POLYGON3D(
|
||||
const CLASS_PLANE & plane,
|
||||
const CLASS_POINT * polygon_points,
|
||||
GUINT polygon_point_count,
|
||||
CLASS_POINT * clipped)
|
||||
{
|
||||
return PLANE_CLIP_POLYGON_GENERIC<CLASS_POINT,CLASS_PLANE>(plane,polygon_points,polygon_point_count,clipped,DISTANCE_PLANE_3D_FUNC());
|
||||
}
|
||||
|
||||
|
||||
template<typename CLASS_POINT,typename CLASS_PLANE>
|
||||
SIMD_FORCE_INLINE GUINT PLANE_CLIP_TRIANGLE3D(
|
||||
const CLASS_PLANE & plane,
|
||||
const CLASS_POINT & point0,
|
||||
const CLASS_POINT & point1,
|
||||
const CLASS_POINT & point2,
|
||||
CLASS_POINT * clipped)
|
||||
{
|
||||
return PLANE_CLIP_TRIANGLE_GENERIC<CLASS_POINT,CLASS_PLANE>(plane,point0,point1,point2,clipped,DISTANCE_PLANE_3D_FUNC());
|
||||
}
|
||||
|
||||
|
||||
//! @}
|
||||
|
||||
#endif // GIM_TRI_COLLISION_H_INCLUDED
|
||||
#ifndef GIM_CLIP_POLYGON_H_INCLUDED
|
||||
#define GIM_CLIP_POLYGON_H_INCLUDED
|
||||
|
||||
/*! \file gim_tri_collision.h
|
||||
\author Francisco Len Nßjera
|
||||
*/
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
This source file is part of GIMPACT Library.
|
||||
|
||||
For the latest info, see http://gimpact.sourceforge.net/
|
||||
|
||||
Copyright (c) 2006 Francisco Leon Najera. 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.
|
||||
(3) The zlib/libpng license that is included with this library in
|
||||
the file GIMPACT-LICENSE-ZLIB.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, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*! \addtogroup GEOMETRIC_OPERATIONS
|
||||
*/
|
||||
//! @{
|
||||
|
||||
//! This function calcs the distance from a 3D plane
|
||||
class DISTANCE_PLANE_3D_FUNC
|
||||
{
|
||||
public:
|
||||
template<typename CLASS_POINT,typename CLASS_PLANE>
|
||||
inline GREAL operator()(const CLASS_PLANE & plane, const CLASS_POINT & point)
|
||||
{
|
||||
return DISTANCE_PLANE_POINT(plane, point);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
template<typename CLASS_POINT>
|
||||
SIMD_FORCE_INLINE void PLANE_CLIP_POLYGON_COLLECT(
|
||||
const CLASS_POINT & point0,
|
||||
const CLASS_POINT & point1,
|
||||
GREAL dist0,
|
||||
GREAL dist1,
|
||||
CLASS_POINT * clipped,
|
||||
GUINT & clipped_count)
|
||||
{
|
||||
GUINT _prevclassif = (dist0>G_EPSILON);
|
||||
GUINT _classif = (dist1>G_EPSILON);
|
||||
if(_classif!=_prevclassif)
|
||||
{
|
||||
GREAL blendfactor = -dist0/(dist1-dist0);
|
||||
VEC_BLEND(clipped[clipped_count],point0,point1,blendfactor);
|
||||
clipped_count++;
|
||||
}
|
||||
if(!_classif)
|
||||
{
|
||||
VEC_COPY(clipped[clipped_count],point1);
|
||||
clipped_count++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//! Clips a polygon by a plane
|
||||
/*!
|
||||
*\return The count of the clipped counts
|
||||
*/
|
||||
template<typename CLASS_POINT,typename CLASS_PLANE, typename DISTANCE_PLANE_FUNC>
|
||||
SIMD_FORCE_INLINE GUINT PLANE_CLIP_POLYGON_GENERIC(
|
||||
const CLASS_PLANE & plane,
|
||||
const CLASS_POINT * polygon_points,
|
||||
GUINT polygon_point_count,
|
||||
CLASS_POINT * clipped,DISTANCE_PLANE_FUNC distance_func)
|
||||
{
|
||||
GUINT clipped_count = 0;
|
||||
|
||||
|
||||
//clip first point
|
||||
GREAL firstdist = distance_func(plane,polygon_points[0]);;
|
||||
if(!(firstdist>G_EPSILON))
|
||||
{
|
||||
VEC_COPY(clipped[clipped_count],polygon_points[0]);
|
||||
clipped_count++;
|
||||
}
|
||||
|
||||
GREAL olddist = firstdist;
|
||||
for(GUINT _i=1;_i<polygon_point_count;_i++)
|
||||
{
|
||||
GREAL dist = distance_func(plane,polygon_points[_i]);
|
||||
|
||||
PLANE_CLIP_POLYGON_COLLECT(
|
||||
polygon_points[_i-1],polygon_points[_i],
|
||||
olddist,
|
||||
dist,
|
||||
clipped,
|
||||
clipped_count);
|
||||
|
||||
|
||||
olddist = dist;
|
||||
}
|
||||
|
||||
//RETURN TO FIRST point
|
||||
|
||||
PLANE_CLIP_POLYGON_COLLECT(
|
||||
polygon_points[polygon_point_count-1],polygon_points[0],
|
||||
olddist,
|
||||
firstdist,
|
||||
clipped,
|
||||
clipped_count);
|
||||
|
||||
return clipped_count;
|
||||
}
|
||||
|
||||
//! Clips a polygon by a plane
|
||||
/*!
|
||||
*\return The count of the clipped counts
|
||||
*/
|
||||
template<typename CLASS_POINT,typename CLASS_PLANE, typename DISTANCE_PLANE_FUNC>
|
||||
SIMD_FORCE_INLINE GUINT PLANE_CLIP_TRIANGLE_GENERIC(
|
||||
const CLASS_PLANE & plane,
|
||||
const CLASS_POINT & point0,
|
||||
const CLASS_POINT & point1,
|
||||
const CLASS_POINT & point2,
|
||||
CLASS_POINT * clipped,DISTANCE_PLANE_FUNC distance_func)
|
||||
{
|
||||
GUINT clipped_count = 0;
|
||||
|
||||
//clip first point
|
||||
GREAL firstdist = distance_func(plane,point0);;
|
||||
if(!(firstdist>G_EPSILON))
|
||||
{
|
||||
VEC_COPY(clipped[clipped_count],point0);
|
||||
clipped_count++;
|
||||
}
|
||||
|
||||
// point 1
|
||||
GREAL olddist = firstdist;
|
||||
GREAL dist = distance_func(plane,point1);
|
||||
|
||||
PLANE_CLIP_POLYGON_COLLECT(
|
||||
point0,point1,
|
||||
olddist,
|
||||
dist,
|
||||
clipped,
|
||||
clipped_count);
|
||||
|
||||
olddist = dist;
|
||||
|
||||
|
||||
// point 2
|
||||
dist = distance_func(plane,point2);
|
||||
|
||||
PLANE_CLIP_POLYGON_COLLECT(
|
||||
point1,point2,
|
||||
olddist,
|
||||
dist,
|
||||
clipped,
|
||||
clipped_count);
|
||||
olddist = dist;
|
||||
|
||||
|
||||
|
||||
//RETURN TO FIRST point
|
||||
PLANE_CLIP_POLYGON_COLLECT(
|
||||
point2,point0,
|
||||
olddist,
|
||||
firstdist,
|
||||
clipped,
|
||||
clipped_count);
|
||||
|
||||
return clipped_count;
|
||||
}
|
||||
|
||||
|
||||
template<typename CLASS_POINT,typename CLASS_PLANE>
|
||||
SIMD_FORCE_INLINE GUINT PLANE_CLIP_POLYGON3D(
|
||||
const CLASS_PLANE & plane,
|
||||
const CLASS_POINT * polygon_points,
|
||||
GUINT polygon_point_count,
|
||||
CLASS_POINT * clipped)
|
||||
{
|
||||
return PLANE_CLIP_POLYGON_GENERIC<CLASS_POINT,CLASS_PLANE>(plane,polygon_points,polygon_point_count,clipped,DISTANCE_PLANE_3D_FUNC());
|
||||
}
|
||||
|
||||
|
||||
template<typename CLASS_POINT,typename CLASS_PLANE>
|
||||
SIMD_FORCE_INLINE GUINT PLANE_CLIP_TRIANGLE3D(
|
||||
const CLASS_PLANE & plane,
|
||||
const CLASS_POINT & point0,
|
||||
const CLASS_POINT & point1,
|
||||
const CLASS_POINT & point2,
|
||||
CLASS_POINT * clipped)
|
||||
{
|
||||
return PLANE_CLIP_TRIANGLE_GENERIC<CLASS_POINT,CLASS_PLANE>(plane,point0,point1,point2,clipped,DISTANCE_PLANE_3D_FUNC());
|
||||
}
|
||||
|
||||
|
||||
//! @}
|
||||
|
||||
#endif // GIM_TRI_COLLISION_H_INCLUDED
|
||||
292
Extras/GIMPACT/src/core/gim_contact.cpp → src/BulletCollision/Gimpact/gim_contact.cpp
Executable file → Normal file
292
Extras/GIMPACT/src/core/gim_contact.cpp → src/BulletCollision/Gimpact/gim_contact.cpp
Executable file → Normal file
@@ -1,146 +1,146 @@
|
||||
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
This source file is part of GIMPACT Library.
|
||||
|
||||
For the latest info, see http://gimpact.sourceforge.net/
|
||||
|
||||
Copyright (c) 2006 Francisco Leon Najera. 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.
|
||||
(3) The zlib/libpng license that is included with this library in
|
||||
the file GIMPACT-LICENSE-ZLIB.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, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "GIMPACT/core/gim_contact.h"
|
||||
|
||||
#define MAX_COINCIDENT 8
|
||||
|
||||
void gim_contact_array::merge_contacts(
|
||||
const gim_contact_array & contacts, bool normal_contact_average)
|
||||
{
|
||||
clear();
|
||||
|
||||
if(contacts.size()==1)
|
||||
{
|
||||
push_back(contacts.back());
|
||||
return;
|
||||
}
|
||||
|
||||
gim_array<GIM_RSORT_TOKEN> keycontacts(contacts.size());
|
||||
keycontacts.resize(contacts.size(),false);
|
||||
|
||||
//fill key contacts
|
||||
|
||||
GUINT i;
|
||||
|
||||
for (i = 0;i<contacts.size() ;i++ )
|
||||
{
|
||||
keycontacts[i].m_key = contacts[i].calc_key_contact();
|
||||
keycontacts[i].m_value = i;
|
||||
}
|
||||
|
||||
//sort keys
|
||||
gim_heap_sort(keycontacts.pointer(),keycontacts.size(),GIM_RSORT_TOKEN_COMPARATOR());
|
||||
|
||||
// Merge contacts
|
||||
|
||||
GUINT coincident_count=0;
|
||||
btVector3 coincident_normals[MAX_COINCIDENT];
|
||||
|
||||
GUINT last_key = keycontacts[0].m_key;
|
||||
GUINT key = 0;
|
||||
|
||||
push_back(contacts[keycontacts[0].m_value]);
|
||||
GIM_CONTACT * pcontact = &back();
|
||||
|
||||
|
||||
|
||||
for( i=1;i<keycontacts.size();i++)
|
||||
{
|
||||
key = keycontacts[i].m_key;
|
||||
const GIM_CONTACT * scontact = &contacts[keycontacts[i].m_value];
|
||||
|
||||
if(last_key == key)//same points
|
||||
{
|
||||
//merge contact
|
||||
if(pcontact->m_depth - CONTACT_DIFF_EPSILON > scontact->m_depth)//)
|
||||
{
|
||||
*pcontact = *scontact;
|
||||
coincident_count = 0;
|
||||
}
|
||||
else if(normal_contact_average)
|
||||
{
|
||||
if(btFabs(pcontact->m_depth - scontact->m_depth)<CONTACT_DIFF_EPSILON)
|
||||
{
|
||||
if(coincident_count<MAX_COINCIDENT)
|
||||
{
|
||||
coincident_normals[coincident_count] = scontact->m_normal;
|
||||
coincident_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{//add new contact
|
||||
|
||||
if(normal_contact_average && coincident_count>0)
|
||||
{
|
||||
pcontact->interpolate_normals(coincident_normals,coincident_count);
|
||||
coincident_count = 0;
|
||||
}
|
||||
|
||||
push_back(*scontact);
|
||||
pcontact = &back();
|
||||
}
|
||||
last_key = key;
|
||||
}
|
||||
}
|
||||
|
||||
void gim_contact_array::merge_contacts_unique(const gim_contact_array & contacts)
|
||||
{
|
||||
clear();
|
||||
|
||||
if(contacts.size()==1)
|
||||
{
|
||||
push_back(contacts.back());
|
||||
return;
|
||||
}
|
||||
|
||||
GIM_CONTACT average_contact = contacts.back();
|
||||
|
||||
for (GUINT i=1;i<contacts.size() ;i++ )
|
||||
{
|
||||
average_contact.m_point += contacts[i].m_point;
|
||||
average_contact.m_normal += contacts[i].m_normal * contacts[i].m_depth;
|
||||
}
|
||||
|
||||
//divide
|
||||
GREAL divide_average = 1.0f/((GREAL)contacts.size());
|
||||
|
||||
average_contact.m_point *= divide_average;
|
||||
|
||||
average_contact.m_normal *= divide_average;
|
||||
|
||||
average_contact.m_depth = average_contact.m_normal.length();
|
||||
|
||||
average_contact.m_normal /= average_contact.m_depth;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
This source file is part of GIMPACT Library.
|
||||
|
||||
For the latest info, see http://gimpact.sourceforge.net/
|
||||
|
||||
Copyright (c) 2006 Francisco Leon Najera. 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.
|
||||
(3) The zlib/libpng license that is included with this library in
|
||||
the file GIMPACT-LICENSE-ZLIB.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, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "gim_contact.h"
|
||||
|
||||
#define MAX_COINCIDENT 8
|
||||
|
||||
void gim_contact_array::merge_contacts(
|
||||
const gim_contact_array & contacts, bool normal_contact_average)
|
||||
{
|
||||
clear();
|
||||
|
||||
if(contacts.size()==1)
|
||||
{
|
||||
push_back(contacts.back());
|
||||
return;
|
||||
}
|
||||
|
||||
gim_array<GIM_RSORT_TOKEN> keycontacts(contacts.size());
|
||||
keycontacts.resize(contacts.size(),false);
|
||||
|
||||
//fill key contacts
|
||||
|
||||
GUINT i;
|
||||
|
||||
for (i = 0;i<contacts.size() ;i++ )
|
||||
{
|
||||
keycontacts[i].m_key = contacts[i].calc_key_contact();
|
||||
keycontacts[i].m_value = i;
|
||||
}
|
||||
|
||||
//sort keys
|
||||
gim_heap_sort(keycontacts.pointer(),keycontacts.size(),GIM_RSORT_TOKEN_COMPARATOR());
|
||||
|
||||
// Merge contacts
|
||||
|
||||
GUINT coincident_count=0;
|
||||
btVector3 coincident_normals[MAX_COINCIDENT];
|
||||
|
||||
GUINT last_key = keycontacts[0].m_key;
|
||||
GUINT key = 0;
|
||||
|
||||
push_back(contacts[keycontacts[0].m_value]);
|
||||
GIM_CONTACT * pcontact = &back();
|
||||
|
||||
|
||||
|
||||
for( i=1;i<keycontacts.size();i++)
|
||||
{
|
||||
key = keycontacts[i].m_key;
|
||||
const GIM_CONTACT * scontact = &contacts[keycontacts[i].m_value];
|
||||
|
||||
if(last_key == key)//same points
|
||||
{
|
||||
//merge contact
|
||||
if(pcontact->m_depth - CONTACT_DIFF_EPSILON > scontact->m_depth)//)
|
||||
{
|
||||
*pcontact = *scontact;
|
||||
coincident_count = 0;
|
||||
}
|
||||
else if(normal_contact_average)
|
||||
{
|
||||
if(btFabs(pcontact->m_depth - scontact->m_depth)<CONTACT_DIFF_EPSILON)
|
||||
{
|
||||
if(coincident_count<MAX_COINCIDENT)
|
||||
{
|
||||
coincident_normals[coincident_count] = scontact->m_normal;
|
||||
coincident_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{//add new contact
|
||||
|
||||
if(normal_contact_average && coincident_count>0)
|
||||
{
|
||||
pcontact->interpolate_normals(coincident_normals,coincident_count);
|
||||
coincident_count = 0;
|
||||
}
|
||||
|
||||
push_back(*scontact);
|
||||
pcontact = &back();
|
||||
}
|
||||
last_key = key;
|
||||
}
|
||||
}
|
||||
|
||||
void gim_contact_array::merge_contacts_unique(const gim_contact_array & contacts)
|
||||
{
|
||||
clear();
|
||||
|
||||
if(contacts.size()==1)
|
||||
{
|
||||
push_back(contacts.back());
|
||||
return;
|
||||
}
|
||||
|
||||
GIM_CONTACT average_contact = contacts.back();
|
||||
|
||||
for (GUINT i=1;i<contacts.size() ;i++ )
|
||||
{
|
||||
average_contact.m_point += contacts[i].m_point;
|
||||
average_contact.m_normal += contacts[i].m_normal * contacts[i].m_depth;
|
||||
}
|
||||
|
||||
//divide
|
||||
GREAL divide_average = 1.0f/((GREAL)contacts.size());
|
||||
|
||||
average_contact.m_point *= divide_average;
|
||||
|
||||
average_contact.m_normal *= divide_average;
|
||||
|
||||
average_contact.m_depth = average_contact.m_normal.length();
|
||||
|
||||
average_contact.m_normal /= average_contact.m_depth;
|
||||
|
||||
}
|
||||
|
||||
344
Extras/GIMPACT/include/GIMPACT/core/gim_contact.h → src/BulletCollision/Gimpact/gim_contact.h
Executable file → Normal file
344
Extras/GIMPACT/include/GIMPACT/core/gim_contact.h → src/BulletCollision/Gimpact/gim_contact.h
Executable file → Normal file
@@ -1,172 +1,172 @@
|
||||
#ifndef GIM_CONTACT_H_INCLUDED
|
||||
#define GIM_CONTACT_H_INCLUDED
|
||||
|
||||
/*! \file gim_contact.h
|
||||
\author Francisco León Nájera
|
||||
*/
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
This source file is part of GIMPACT Library.
|
||||
|
||||
For the latest info, see http://gimpact.sourceforge.net/
|
||||
|
||||
Copyright (c) 2006 Francisco Leon Najera. 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.
|
||||
(3) The zlib/libpng license that is included with this library in
|
||||
the file GIMPACT-LICENSE-ZLIB.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, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
#include "GIMPACT/core/gim_geometry.h"
|
||||
#include "GIMPACT/core/gim_radixsort.h"
|
||||
#include "GIMPACT/core/gim_array.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>
|
||||
|
||||
*/
|
||||
//! @{
|
||||
|
||||
/**
|
||||
Configuration var for applying interpolation of contact normals
|
||||
*/
|
||||
#define NORMAL_CONTACT_AVERAGE 1
|
||||
#define CONTACT_DIFF_EPSILON 0.00001f
|
||||
|
||||
/// Structure for collision results
|
||||
class GIM_CONTACT
|
||||
{
|
||||
public:
|
||||
btVector3 m_point;
|
||||
btVector3 m_normal;
|
||||
GREAL m_depth;//Positive value indicates interpenetration
|
||||
GREAL m_distance;//Padding not for use
|
||||
GUINT m_feature1;//Face number
|
||||
GUINT m_feature2;//Face number
|
||||
public:
|
||||
GIM_CONTACT()
|
||||
{
|
||||
}
|
||||
|
||||
GIM_CONTACT(const GIM_CONTACT & contact):
|
||||
m_point(contact.m_point),
|
||||
m_normal(contact.m_normal),
|
||||
m_depth(contact.m_depth),
|
||||
m_feature1(contact.m_feature1),
|
||||
m_feature2(contact.m_feature2)
|
||||
{
|
||||
m_point = contact.m_point;
|
||||
m_normal = contact.m_normal;
|
||||
m_depth = contact.m_depth;
|
||||
m_feature1 = contact.m_feature1;
|
||||
m_feature2 = contact.m_feature2;
|
||||
}
|
||||
|
||||
GIM_CONTACT(const btVector3 &point,const btVector3 & normal,
|
||||
GREAL depth, GUINT feature1, GUINT feature2):
|
||||
m_point(point),
|
||||
m_normal(normal),
|
||||
m_depth(depth),
|
||||
m_feature1(feature1),
|
||||
m_feature2(feature2)
|
||||
{
|
||||
}
|
||||
|
||||
//! Calcs key for coord classification
|
||||
SIMD_FORCE_INLINE GUINT calc_key_contact() const
|
||||
{
|
||||
GINT _coords[] = {
|
||||
(GINT)(m_point[0]*1000.0f+1.0f),
|
||||
(GINT)(m_point[1]*1333.0f),
|
||||
(GINT)(m_point[2]*2133.0f+3.0f)};
|
||||
GUINT _hash=0;
|
||||
GUINT *_uitmp = (GUINT *)(&_coords[0]);
|
||||
_hash = *_uitmp;
|
||||
_uitmp++;
|
||||
_hash += (*_uitmp)<<4;
|
||||
_uitmp++;
|
||||
_hash += (*_uitmp)<<8;
|
||||
return _hash;
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE void interpolate_normals( btVector3 * normals,GUINT normal_count)
|
||||
{
|
||||
btVector3 vec_sum(m_normal);
|
||||
for(GUINT i=0;i<normal_count;i++)
|
||||
{
|
||||
vec_sum += normals[i];
|
||||
}
|
||||
|
||||
GREAL vec_sum_len = vec_sum.length2();
|
||||
if(vec_sum_len <CONTACT_DIFF_EPSILON) return;
|
||||
|
||||
GIM_INV_SQRT(vec_sum_len,vec_sum_len); // 1/sqrt(vec_sum_len)
|
||||
|
||||
m_normal = vec_sum*vec_sum_len;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
class gim_contact_array:public gim_array<GIM_CONTACT>
|
||||
{
|
||||
public:
|
||||
gim_contact_array():gim_array<GIM_CONTACT>(64)
|
||||
{
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE void push_contact(const btVector3 &point,const btVector3 & normal,
|
||||
GREAL depth, GUINT feature1, GUINT feature2)
|
||||
{
|
||||
push_back_mem();
|
||||
GIM_CONTACT & newele = back();
|
||||
newele.m_point = point;
|
||||
newele.m_normal = normal;
|
||||
newele.m_depth = depth;
|
||||
newele.m_feature1 = feature1;
|
||||
newele.m_feature2 = feature2;
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE void push_triangle_contacts(
|
||||
const GIM_TRIANGLE_CONTACT_DATA & tricontact,
|
||||
GUINT feature1,GUINT feature2)
|
||||
{
|
||||
for(GUINT i = 0;i<tricontact.m_point_count ;i++ )
|
||||
{
|
||||
push_back_mem();
|
||||
GIM_CONTACT & newele = back();
|
||||
newele.m_point = tricontact.m_points[i];
|
||||
newele.m_normal = tricontact.m_separating_normal;
|
||||
newele.m_depth = tricontact.m_penetration_depth;
|
||||
newele.m_feature1 = feature1;
|
||||
newele.m_feature2 = feature2;
|
||||
}
|
||||
}
|
||||
|
||||
void merge_contacts(const gim_contact_array & contacts, bool normal_contact_average = true);
|
||||
void merge_contacts_unique(const gim_contact_array & contacts);
|
||||
};
|
||||
|
||||
//! @}
|
||||
#endif // GIM_CONTACT_H_INCLUDED
|
||||
#ifndef GIM_CONTACT_H_INCLUDED
|
||||
#define GIM_CONTACT_H_INCLUDED
|
||||
|
||||
/*! \file gim_contact.h
|
||||
\author Francisco Len Nßjera
|
||||
*/
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
This source file is part of GIMPACT Library.
|
||||
|
||||
For the latest info, see http://gimpact.sourceforge.net/
|
||||
|
||||
Copyright (c) 2006 Francisco Leon Najera. 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.
|
||||
(3) The zlib/libpng license that is included with this library in
|
||||
the file GIMPACT-LICENSE-ZLIB.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, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
#include "gim_geometry.h"
|
||||
#include "gim_radixsort.h"
|
||||
#include "gim_array.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>
|
||||
|
||||
*/
|
||||
//! @{
|
||||
|
||||
/**
|
||||
Configuration var for applying interpolation of contact normals
|
||||
*/
|
||||
#define NORMAL_CONTACT_AVERAGE 1
|
||||
#define CONTACT_DIFF_EPSILON 0.00001f
|
||||
|
||||
/// Structure for collision results
|
||||
class GIM_CONTACT
|
||||
{
|
||||
public:
|
||||
btVector3 m_point;
|
||||
btVector3 m_normal;
|
||||
GREAL m_depth;//Positive value indicates interpenetration
|
||||
GREAL m_distance;//Padding not for use
|
||||
GUINT m_feature1;//Face number
|
||||
GUINT m_feature2;//Face number
|
||||
public:
|
||||
GIM_CONTACT()
|
||||
{
|
||||
}
|
||||
|
||||
GIM_CONTACT(const GIM_CONTACT & contact):
|
||||
m_point(contact.m_point),
|
||||
m_normal(contact.m_normal),
|
||||
m_depth(contact.m_depth),
|
||||
m_feature1(contact.m_feature1),
|
||||
m_feature2(contact.m_feature2)
|
||||
{
|
||||
m_point = contact.m_point;
|
||||
m_normal = contact.m_normal;
|
||||
m_depth = contact.m_depth;
|
||||
m_feature1 = contact.m_feature1;
|
||||
m_feature2 = contact.m_feature2;
|
||||
}
|
||||
|
||||
GIM_CONTACT(const btVector3 &point,const btVector3 & normal,
|
||||
GREAL depth, GUINT feature1, GUINT feature2):
|
||||
m_point(point),
|
||||
m_normal(normal),
|
||||
m_depth(depth),
|
||||
m_feature1(feature1),
|
||||
m_feature2(feature2)
|
||||
{
|
||||
}
|
||||
|
||||
//! Calcs key for coord classification
|
||||
SIMD_FORCE_INLINE GUINT calc_key_contact() const
|
||||
{
|
||||
GINT _coords[] = {
|
||||
(GINT)(m_point[0]*1000.0f+1.0f),
|
||||
(GINT)(m_point[1]*1333.0f),
|
||||
(GINT)(m_point[2]*2133.0f+3.0f)};
|
||||
GUINT _hash=0;
|
||||
GUINT *_uitmp = (GUINT *)(&_coords[0]);
|
||||
_hash = *_uitmp;
|
||||
_uitmp++;
|
||||
_hash += (*_uitmp)<<4;
|
||||
_uitmp++;
|
||||
_hash += (*_uitmp)<<8;
|
||||
return _hash;
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE void interpolate_normals( btVector3 * normals,GUINT normal_count)
|
||||
{
|
||||
btVector3 vec_sum(m_normal);
|
||||
for(GUINT i=0;i<normal_count;i++)
|
||||
{
|
||||
vec_sum += normals[i];
|
||||
}
|
||||
|
||||
GREAL vec_sum_len = vec_sum.length2();
|
||||
if(vec_sum_len <CONTACT_DIFF_EPSILON) return;
|
||||
|
||||
GIM_INV_SQRT(vec_sum_len,vec_sum_len); // 1/sqrt(vec_sum_len)
|
||||
|
||||
m_normal = vec_sum*vec_sum_len;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
class gim_contact_array:public gim_array<GIM_CONTACT>
|
||||
{
|
||||
public:
|
||||
gim_contact_array():gim_array<GIM_CONTACT>(64)
|
||||
{
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE void push_contact(const btVector3 &point,const btVector3 & normal,
|
||||
GREAL depth, GUINT feature1, GUINT feature2)
|
||||
{
|
||||
push_back_mem();
|
||||
GIM_CONTACT & newele = back();
|
||||
newele.m_point = point;
|
||||
newele.m_normal = normal;
|
||||
newele.m_depth = depth;
|
||||
newele.m_feature1 = feature1;
|
||||
newele.m_feature2 = feature2;
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE void push_triangle_contacts(
|
||||
const GIM_TRIANGLE_CONTACT_DATA & tricontact,
|
||||
GUINT feature1,GUINT feature2)
|
||||
{
|
||||
for(GUINT i = 0;i<tricontact.m_point_count ;i++ )
|
||||
{
|
||||
push_back_mem();
|
||||
GIM_CONTACT & newele = back();
|
||||
newele.m_point = tricontact.m_points[i];
|
||||
newele.m_normal = tricontact.m_separating_normal;
|
||||
newele.m_depth = tricontact.m_penetration_depth;
|
||||
newele.m_feature1 = feature1;
|
||||
newele.m_feature2 = feature2;
|
||||
}
|
||||
}
|
||||
|
||||
void merge_contacts(const gim_contact_array & contacts, bool normal_contact_average = true);
|
||||
void merge_contacts_unique(const gim_contact_array & contacts);
|
||||
};
|
||||
|
||||
//! @}
|
||||
#endif // GIM_CONTACT_H_INCLUDED
|
||||
204
Extras/GIMPACT/include/GIMPACT/core/gim_geom_types.h → src/BulletCollision/Gimpact/gim_geom_types.h
Executable file → Normal file
204
Extras/GIMPACT/include/GIMPACT/core/gim_geom_types.h → src/BulletCollision/Gimpact/gim_geom_types.h
Executable file → Normal file
@@ -1,102 +1,102 @@
|
||||
#ifndef GIM_GEOM_TYPES_H_INCLUDED
|
||||
#define GIM_GEOM_TYPES_H_INCLUDED
|
||||
|
||||
/*! \file gim_geom_types.h
|
||||
\author Francisco León Nájera
|
||||
*/
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
This source file is part of GIMPACT Library.
|
||||
|
||||
For the latest info, see http://gimpact.sourceforge.net/
|
||||
|
||||
Copyright (c) 2006 Francisco Leon Najera. 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.
|
||||
(3) The zlib/libpng license that is included with this library in
|
||||
the file GIMPACT-LICENSE-ZLIB.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, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#include "GIMPACT/core/gim_math.h"
|
||||
|
||||
/*! \defgroup GEOMETRIC_TYPES
|
||||
\brief
|
||||
Basic types and constants for geometry
|
||||
*/
|
||||
//! @{
|
||||
|
||||
//! Short Integer vector 2D
|
||||
typedef GSHORT vec2s[2];
|
||||
//! Integer vector 3D
|
||||
typedef GSHORT vec3s[3];
|
||||
//! Integer vector 4D
|
||||
typedef GSHORT vec4s[4];
|
||||
|
||||
//! Short Integer vector 2D
|
||||
typedef GUSHORT vec2us[2];
|
||||
//! Integer vector 3D
|
||||
typedef GUSHORT vec3us[3];
|
||||
//! Integer vector 4D
|
||||
typedef GUSHORT vec4us[4];
|
||||
|
||||
//! Integer vector 2D
|
||||
typedef GINT vec2i[2];
|
||||
//! Integer vector 3D
|
||||
typedef GINT vec3i[3];
|
||||
//! Integer vector 4D
|
||||
typedef GINT vec4i[4];
|
||||
|
||||
//! Unsigned Integer vector 2D
|
||||
typedef GUINT vec2ui[2];
|
||||
//! Unsigned Integer vector 3D
|
||||
typedef GUINT vec3ui[3];
|
||||
//! Unsigned Integer vector 4D
|
||||
typedef GUINT vec4ui[4];
|
||||
|
||||
//! Float vector 2D
|
||||
typedef GREAL vec2f[2];
|
||||
//! Float vector 3D
|
||||
typedef GREAL vec3f[3];
|
||||
//! Float vector 4D
|
||||
typedef GREAL vec4f[4];
|
||||
|
||||
//! Double vector 2D
|
||||
typedef GREAL2 vec2d[2];
|
||||
//! Float vector 3D
|
||||
typedef GREAL2 vec3d[3];
|
||||
//! Float vector 4D
|
||||
typedef GREAL2 vec4d[4];
|
||||
|
||||
//! Matrix 2D, row ordered
|
||||
typedef GREAL mat2f[2][2];
|
||||
//! Matrix 3D, row ordered
|
||||
typedef GREAL mat3f[3][3];
|
||||
//! Matrix 4D, row ordered
|
||||
typedef GREAL mat4f[4][4];
|
||||
|
||||
//! Quaternion
|
||||
typedef GREAL quatf[4];
|
||||
|
||||
//typedef struct _aabb3f aabb3f;
|
||||
//! @}
|
||||
|
||||
|
||||
|
||||
#endif // GIM_GEOM_TYPES_H_INCLUDED
|
||||
#ifndef GIM_GEOM_TYPES_H_INCLUDED
|
||||
#define GIM_GEOM_TYPES_H_INCLUDED
|
||||
|
||||
/*! \file gim_geom_types.h
|
||||
\author Francisco Len Nßjera
|
||||
*/
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
This source file is part of GIMPACT Library.
|
||||
|
||||
For the latest info, see http://gimpact.sourceforge.net/
|
||||
|
||||
Copyright (c) 2006 Francisco Leon Najera. 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.
|
||||
(3) The zlib/libpng license that is included with this library in
|
||||
the file GIMPACT-LICENSE-ZLIB.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, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#include "gim_math.h"
|
||||
|
||||
/*! \defgroup GEOMETRIC_TYPES
|
||||
\brief
|
||||
Basic types and constants for geometry
|
||||
*/
|
||||
//! @{
|
||||
|
||||
//! Short Integer vector 2D
|
||||
typedef GSHORT vec2s[2];
|
||||
//! Integer vector 3D
|
||||
typedef GSHORT vec3s[3];
|
||||
//! Integer vector 4D
|
||||
typedef GSHORT vec4s[4];
|
||||
|
||||
//! Short Integer vector 2D
|
||||
typedef GUSHORT vec2us[2];
|
||||
//! Integer vector 3D
|
||||
typedef GUSHORT vec3us[3];
|
||||
//! Integer vector 4D
|
||||
typedef GUSHORT vec4us[4];
|
||||
|
||||
//! Integer vector 2D
|
||||
typedef GINT vec2i[2];
|
||||
//! Integer vector 3D
|
||||
typedef GINT vec3i[3];
|
||||
//! Integer vector 4D
|
||||
typedef GINT vec4i[4];
|
||||
|
||||
//! Unsigned Integer vector 2D
|
||||
typedef GUINT vec2ui[2];
|
||||
//! Unsigned Integer vector 3D
|
||||
typedef GUINT vec3ui[3];
|
||||
//! Unsigned Integer vector 4D
|
||||
typedef GUINT vec4ui[4];
|
||||
|
||||
//! Float vector 2D
|
||||
typedef GREAL vec2f[2];
|
||||
//! Float vector 3D
|
||||
typedef GREAL vec3f[3];
|
||||
//! Float vector 4D
|
||||
typedef GREAL vec4f[4];
|
||||
|
||||
//! Double vector 2D
|
||||
typedef GREAL2 vec2d[2];
|
||||
//! Float vector 3D
|
||||
typedef GREAL2 vec3d[3];
|
||||
//! Float vector 4D
|
||||
typedef GREAL2 vec4d[4];
|
||||
|
||||
//! Matrix 2D, row ordered
|
||||
typedef GREAL mat2f[2][2];
|
||||
//! Matrix 3D, row ordered
|
||||
typedef GREAL mat3f[3][3];
|
||||
//! Matrix 4D, row ordered
|
||||
typedef GREAL mat4f[4][4];
|
||||
|
||||
//! Quaternion
|
||||
typedef GREAL quatf[4];
|
||||
|
||||
//typedef struct _aabb3f aabb3f;
|
||||
//! @}
|
||||
|
||||
|
||||
|
||||
#endif // GIM_GEOM_TYPES_H_INCLUDED
|
||||
86
Extras/GIMPACT/include/GIMPACT/core/gim_geometry.h → src/BulletCollision/Gimpact/gim_geometry.h
Executable file → Normal file
86
Extras/GIMPACT/include/GIMPACT/core/gim_geometry.h → src/BulletCollision/Gimpact/gim_geometry.h
Executable file → Normal file
@@ -1,44 +1,42 @@
|
||||
#ifndef GIM_GEOMETRY_H_INCLUDED
|
||||
#define GIM_GEOMETRY_H_INCLUDED
|
||||
|
||||
/*! \file gim_geometry.h
|
||||
\author Francisco León Nájera
|
||||
*/
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
This source file is part of GIMPACT Library.
|
||||
|
||||
For the latest info, see http://gimpact.sourceforge.net/
|
||||
|
||||
Copyright (c) 2006 Francisco Leon Najera. 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.
|
||||
(3) The zlib/libpng license that is included with this library in
|
||||
the file GIMPACT-LICENSE-ZLIB.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, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
///Additional Headers for Collision
|
||||
#include "GIMPACT/core/gim_basic_geometry_operations.h"
|
||||
#include "GIMPACT/core/gim_clip_polygon.h"
|
||||
#include "GIMPACT/core/gim_box_collision.h"
|
||||
#include "GIMPACT/core/gim_tri_collision.h"
|
||||
//#include "GIMPACT/core/gim_tri_sphere_collision.h"
|
||||
//#include "GIMPACT/core/gim_tri_capsule_collision.h"
|
||||
|
||||
#endif // GIM_VECTOR_H_INCLUDED
|
||||
#ifndef GIM_GEOMETRY_H_INCLUDED
|
||||
#define GIM_GEOMETRY_H_INCLUDED
|
||||
|
||||
/*! \file gim_geometry.h
|
||||
\author Francisco Len Nßjera
|
||||
*/
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
This source file is part of GIMPACT Library.
|
||||
|
||||
For the latest info, see http://gimpact.sourceforge.net/
|
||||
|
||||
Copyright (c) 2006 Francisco Leon Najera. 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.
|
||||
(3) The zlib/libpng license that is included with this library in
|
||||
the file GIMPACT-LICENSE-ZLIB.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, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
///Additional Headers for Collision
|
||||
#include "gim_basic_geometry_operations.h"
|
||||
#include "gim_clip_polygon.h"
|
||||
#include "gim_box_collision.h"
|
||||
#include "gim_tri_collision.h"
|
||||
|
||||
#endif // GIM_VECTOR_H_INCLUDED
|
||||
1840
Extras/GIMPACT/include/GIMPACT/core/gim_hash_table.h → src/BulletCollision/Gimpact/gim_hash_table.h
Executable file → Normal file
1840
Extras/GIMPACT/include/GIMPACT/core/gim_hash_table.h → src/BulletCollision/Gimpact/gim_hash_table.h
Executable file → Normal file
File diff suppressed because it is too large
Load Diff
3168
Extras/GIMPACT/include/GIMPACT/core/gim_linear_math.h → src/BulletCollision/Gimpact/gim_linear_math.h
Executable file → Normal file
3168
Extras/GIMPACT/include/GIMPACT/core/gim_linear_math.h → src/BulletCollision/Gimpact/gim_linear_math.h
Executable file → Normal file
File diff suppressed because it is too large
Load Diff
362
Extras/GIMPACT/include/GIMPACT/core/gim_math.h → src/BulletCollision/Gimpact/gim_math.h
Executable file → Normal file
362
Extras/GIMPACT/include/GIMPACT/core/gim_math.h → src/BulletCollision/Gimpact/gim_math.h
Executable file → Normal file
@@ -1,181 +1,181 @@
|
||||
#ifndef GIM_MATH_H_INCLUDED
|
||||
#define GIM_MATH_H_INCLUDED
|
||||
/*! \file gim_math.h
|
||||
\author Francisco León Nájera
|
||||
*/
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
This source file is part of GIMPACT Library.
|
||||
|
||||
For the latest info, see http://gimpact.sourceforge.net/
|
||||
|
||||
Copyright (c) 2006 Francisco Leon Najera. 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.
|
||||
(3) The zlib/libpng license that is included with this library in
|
||||
the file GIMPACT-LICENSE-ZLIB.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, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "LinearMath/btScalar.h"
|
||||
|
||||
|
||||
/*! \defgroup BASIC_TYPES
|
||||
Basic types and constants
|
||||
Conventions:
|
||||
Types starting with G
|
||||
Constants starting with G_
|
||||
*/
|
||||
//! @{
|
||||
|
||||
#define GREAL btScalar
|
||||
#define GREAL2 double
|
||||
#define GINT int
|
||||
#define GUINT unsigned int
|
||||
#define GSHORT short
|
||||
#define GUSHORT unsigned short
|
||||
#define GINT64 long long
|
||||
#define GUINT64 unsigned long long
|
||||
|
||||
//! @}
|
||||
|
||||
/*! \defgroup BASIC_CONSTANTS
|
||||
Basic constants
|
||||
Conventions:
|
||||
Types starting with G
|
||||
Constants starting with G_
|
||||
*/
|
||||
//! @{
|
||||
|
||||
#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 0xffffffff //!< A very very high value
|
||||
#define G_REAL_INFINITY FLT_MAX
|
||||
#define G_SIGN_BITMASK 0x80000000
|
||||
#define G_EPSILON SIMD_EPSILON
|
||||
//! @}
|
||||
|
||||
|
||||
/*! \defgroup SCALAR_TYPES
|
||||
\brief
|
||||
Precision type constants
|
||||
*/
|
||||
//! @{
|
||||
enum GIM_SCALAR_TYPES
|
||||
{
|
||||
G_STYPE_REAL =0,
|
||||
G_STYPE_REAL2,
|
||||
G_STYPE_SHORT,
|
||||
G_STYPE_USHORT,
|
||||
G_STYPE_INT,
|
||||
G_STYPE_UINT,
|
||||
G_STYPE_INT64,
|
||||
G_STYPE_UINT64
|
||||
};
|
||||
//! @}
|
||||
|
||||
/*! \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 GIM_IR(x) ((GUINT&)(x))
|
||||
|
||||
//! Signed integer representation of a floating-point value.
|
||||
#define GIM_SIR(x) ((GINT&)(x))
|
||||
|
||||
//! Absolute integer representation of a floating-point value
|
||||
#define GIM_AIR(x) (GIM_IR(x)&0x7fffffff)
|
||||
|
||||
//! Floating-point representation of an integer value.
|
||||
#define GIM_FR(x) ((GREAL&)(x))
|
||||
|
||||
#define GIM_MAX(a,b) (a<b?b:a)
|
||||
#define GIM_MIN(a,b) (a>b?b:a)
|
||||
|
||||
#define GIM_MAX3(a,b,c) GIM_MAX(a,GIM_MAX(b,c))
|
||||
#define GIM_MIN3(a,b,c) GIM_MIN(a,GIM_MIN(b,c))
|
||||
|
||||
#define GIM_IS_ZERO(value) (value < G_EPSILON && value > -G_EPSILON)
|
||||
|
||||
#define GIM_IS_NEGATIVE(value) (value <= -G_EPSILON)
|
||||
|
||||
#define GIM_IS_POSISITVE(value) (value >= G_EPSILON)
|
||||
|
||||
#define GIM_NEAR_EQUAL(v1,v2) GIM_IS_ZERO((v1-v2))
|
||||
|
||||
///returns a clamped number
|
||||
#define GIM_CLAMP(number,minval,maxval) (number<minval?minval:(number>maxval?maxval:number))
|
||||
|
||||
#define GIM_GREATER(x, y) fabsf(x) > (y)
|
||||
|
||||
///Swap numbers
|
||||
#define GIM_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;\
|
||||
GUINT _y = 0x5f3759df - ( GIM_IR(va) >> 1);\
|
||||
isva = GIM_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
|
||||
inline GREAL gim_inv_sqrt(GREAL f)
|
||||
{
|
||||
GREAL r;
|
||||
GIM_INV_SQRT(f,r);
|
||||
return r;
|
||||
}
|
||||
|
||||
inline GREAL gim_sqrt(GREAL f)
|
||||
{
|
||||
GREAL r;
|
||||
GIM_SQRT(f,r);
|
||||
return r;
|
||||
}
|
||||
|
||||
//! @}
|
||||
|
||||
#endif // GIM_MATH_H_INCLUDED
|
||||
#ifndef GIM_MATH_H_INCLUDED
|
||||
#define GIM_MATH_H_INCLUDED
|
||||
/*! \file gim_math.h
|
||||
\author Francisco Len Nßjera
|
||||
*/
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
This source file is part of GIMPACT Library.
|
||||
|
||||
For the latest info, see http://gimpact.sourceforge.net/
|
||||
|
||||
Copyright (c) 2006 Francisco Leon Najera. 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.
|
||||
(3) The zlib/libpng license that is included with this library in
|
||||
the file GIMPACT-LICENSE-ZLIB.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, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "LinearMath/btScalar.h"
|
||||
|
||||
|
||||
/*! \defgroup BASIC_TYPES
|
||||
Basic types and constants
|
||||
Conventions:
|
||||
Types starting with G
|
||||
Constants starting with G_
|
||||
*/
|
||||
//! @{
|
||||
|
||||
#define GREAL btScalar
|
||||
#define GREAL2 double
|
||||
#define GINT int
|
||||
#define GUINT unsigned int
|
||||
#define GSHORT short
|
||||
#define GUSHORT unsigned short
|
||||
#define GINT64 long long
|
||||
#define GUINT64 unsigned long long
|
||||
|
||||
//! @}
|
||||
|
||||
/*! \defgroup BASIC_CONSTANTS
|
||||
Basic constants
|
||||
Conventions:
|
||||
Types starting with G
|
||||
Constants starting with G_
|
||||
*/
|
||||
//! @{
|
||||
|
||||
#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 0xffffffff //!< A very very high value
|
||||
#define G_REAL_INFINITY FLT_MAX
|
||||
#define G_SIGN_BITMASK 0x80000000
|
||||
#define G_EPSILON SIMD_EPSILON
|
||||
//! @}
|
||||
|
||||
|
||||
/*! \defgroup SCALAR_TYPES
|
||||
\brief
|
||||
Precision type constants
|
||||
*/
|
||||
//! @{
|
||||
enum GIM_SCALAR_TYPES
|
||||
{
|
||||
G_STYPE_REAL =0,
|
||||
G_STYPE_REAL2,
|
||||
G_STYPE_SHORT,
|
||||
G_STYPE_USHORT,
|
||||
G_STYPE_INT,
|
||||
G_STYPE_UINT,
|
||||
G_STYPE_INT64,
|
||||
G_STYPE_UINT64
|
||||
};
|
||||
//! @}
|
||||
|
||||
/*! \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 GIM_IR(x) ((GUINT&)(x))
|
||||
|
||||
//! Signed integer representation of a floating-point value.
|
||||
#define GIM_SIR(x) ((GINT&)(x))
|
||||
|
||||
//! Absolute integer representation of a floating-point value
|
||||
#define GIM_AIR(x) (GIM_IR(x)&0x7fffffff)
|
||||
|
||||
//! Floating-point representation of an integer value.
|
||||
#define GIM_FR(x) ((GREAL&)(x))
|
||||
|
||||
#define GIM_MAX(a,b) (a<b?b:a)
|
||||
#define GIM_MIN(a,b) (a>b?b:a)
|
||||
|
||||
#define GIM_MAX3(a,b,c) GIM_MAX(a,GIM_MAX(b,c))
|
||||
#define GIM_MIN3(a,b,c) GIM_MIN(a,GIM_MIN(b,c))
|
||||
|
||||
#define GIM_IS_ZERO(value) (value < G_EPSILON && value > -G_EPSILON)
|
||||
|
||||
#define GIM_IS_NEGATIVE(value) (value <= -G_EPSILON)
|
||||
|
||||
#define GIM_IS_POSISITVE(value) (value >= G_EPSILON)
|
||||
|
||||
#define GIM_NEAR_EQUAL(v1,v2) GIM_IS_ZERO((v1-v2))
|
||||
|
||||
///returns a clamped number
|
||||
#define GIM_CLAMP(number,minval,maxval) (number<minval?minval:(number>maxval?maxval:number))
|
||||
|
||||
#define GIM_GREATER(x, y) fabsf(x) > (y)
|
||||
|
||||
///Swap numbers
|
||||
#define GIM_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;\
|
||||
GUINT _y = 0x5f3759df - ( GIM_IR(va) >> 1);\
|
||||
isva = GIM_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
|
||||
inline GREAL gim_inv_sqrt(GREAL f)
|
||||
{
|
||||
GREAL r;
|
||||
GIM_INV_SQRT(f,r);
|
||||
return r;
|
||||
}
|
||||
|
||||
inline GREAL gim_sqrt(GREAL f)
|
||||
{
|
||||
GREAL r;
|
||||
GIM_SQRT(f,r);
|
||||
return r;
|
||||
}
|
||||
|
||||
//! @}
|
||||
|
||||
#endif // GIM_MATH_H_INCLUDED
|
||||
270
Extras/GIMPACT/src/core/gim_memory.cpp → src/BulletCollision/Gimpact/gim_memory.cpp
Executable file → Normal file
270
Extras/GIMPACT/src/core/gim_memory.cpp → src/BulletCollision/Gimpact/gim_memory.cpp
Executable file → Normal file
@@ -1,135 +1,135 @@
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
This source file is part of GIMPACT Library.
|
||||
|
||||
For the latest info, see http://gimpact.sourceforge.net/
|
||||
|
||||
Copyright (c) 2006 Francisco Leon Najera. 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.
|
||||
(3) The zlib/libpng license that is included with this library in
|
||||
the file GIMPACT-LICENSE-ZLIB.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, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#include "GIMPACT/core/gim_memory.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
#ifdef GIM_SIMD_MEMORY
|
||||
#include "LinearMath/btAlignedAllocator.h"
|
||||
#endif
|
||||
|
||||
static gim_alloc_function *g_allocfn = 0;
|
||||
static gim_alloca_function *g_allocafn = 0;
|
||||
static gim_realloc_function *g_reallocfn = 0;
|
||||
static gim_free_function *g_freefn = 0;
|
||||
|
||||
void gim_set_alloc_handler (gim_alloc_function *fn)
|
||||
{
|
||||
g_allocfn = fn;
|
||||
}
|
||||
|
||||
void gim_set_alloca_handler (gim_alloca_function *fn)
|
||||
{
|
||||
g_allocafn = fn;
|
||||
}
|
||||
|
||||
void gim_set_realloc_handler (gim_realloc_function *fn)
|
||||
{
|
||||
g_reallocfn = fn;
|
||||
}
|
||||
|
||||
void gim_set_free_handler (gim_free_function *fn)
|
||||
{
|
||||
g_freefn = fn;
|
||||
}
|
||||
|
||||
gim_alloc_function *gim_get_alloc_handler()
|
||||
{
|
||||
return g_allocfn;
|
||||
}
|
||||
|
||||
gim_alloca_function *gim_get_alloca_handler()
|
||||
{
|
||||
return g_allocafn;
|
||||
}
|
||||
|
||||
|
||||
gim_realloc_function *gim_get_realloc_handler ()
|
||||
{
|
||||
return g_reallocfn;
|
||||
}
|
||||
|
||||
|
||||
gim_free_function *gim_get_free_handler ()
|
||||
{
|
||||
return g_freefn;
|
||||
}
|
||||
|
||||
|
||||
void * gim_alloc(size_t size)
|
||||
{
|
||||
void * ptr;
|
||||
if (g_allocfn)
|
||||
{
|
||||
ptr = g_allocfn(size);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef GIM_SIMD_MEMORY
|
||||
ptr = btAlignedAlloc(size,16);
|
||||
#else
|
||||
ptr = malloc(size);
|
||||
#endif
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void * gim_alloca(size_t size)
|
||||
{
|
||||
if (g_allocafn) return g_allocafn(size); else return gim_alloc(size);
|
||||
}
|
||||
|
||||
|
||||
void * gim_realloc(void *ptr, size_t oldsize, size_t newsize)
|
||||
{
|
||||
void * newptr = gim_alloc(newsize);
|
||||
size_t copysize = oldsize<newsize?oldsize:newsize;
|
||||
gim_simd_memcpy(newptr,ptr,copysize);
|
||||
gim_free(ptr);
|
||||
return newptr;
|
||||
}
|
||||
|
||||
void gim_free(void *ptr)
|
||||
{
|
||||
if (!ptr) return;
|
||||
if (g_freefn)
|
||||
{
|
||||
g_freefn(ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef GIM_SIMD_MEMORY
|
||||
btAlignedFree(ptr);
|
||||
#else
|
||||
free(ptr);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
This source file is part of GIMPACT Library.
|
||||
|
||||
For the latest info, see http://gimpact.sourceforge.net/
|
||||
|
||||
Copyright (c) 2006 Francisco Leon Najera. 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.
|
||||
(3) The zlib/libpng license that is included with this library in
|
||||
the file GIMPACT-LICENSE-ZLIB.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, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#include "gim_memory.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
#ifdef GIM_SIMD_MEMORY
|
||||
#include "LinearMath/btAlignedAllocator.h"
|
||||
#endif
|
||||
|
||||
static gim_alloc_function *g_allocfn = 0;
|
||||
static gim_alloca_function *g_allocafn = 0;
|
||||
static gim_realloc_function *g_reallocfn = 0;
|
||||
static gim_free_function *g_freefn = 0;
|
||||
|
||||
void gim_set_alloc_handler (gim_alloc_function *fn)
|
||||
{
|
||||
g_allocfn = fn;
|
||||
}
|
||||
|
||||
void gim_set_alloca_handler (gim_alloca_function *fn)
|
||||
{
|
||||
g_allocafn = fn;
|
||||
}
|
||||
|
||||
void gim_set_realloc_handler (gim_realloc_function *fn)
|
||||
{
|
||||
g_reallocfn = fn;
|
||||
}
|
||||
|
||||
void gim_set_free_handler (gim_free_function *fn)
|
||||
{
|
||||
g_freefn = fn;
|
||||
}
|
||||
|
||||
gim_alloc_function *gim_get_alloc_handler()
|
||||
{
|
||||
return g_allocfn;
|
||||
}
|
||||
|
||||
gim_alloca_function *gim_get_alloca_handler()
|
||||
{
|
||||
return g_allocafn;
|
||||
}
|
||||
|
||||
|
||||
gim_realloc_function *gim_get_realloc_handler ()
|
||||
{
|
||||
return g_reallocfn;
|
||||
}
|
||||
|
||||
|
||||
gim_free_function *gim_get_free_handler ()
|
||||
{
|
||||
return g_freefn;
|
||||
}
|
||||
|
||||
|
||||
void * gim_alloc(size_t size)
|
||||
{
|
||||
void * ptr;
|
||||
if (g_allocfn)
|
||||
{
|
||||
ptr = g_allocfn(size);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef GIM_SIMD_MEMORY
|
||||
ptr = btAlignedAlloc(size,16);
|
||||
#else
|
||||
ptr = malloc(size);
|
||||
#endif
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void * gim_alloca(size_t size)
|
||||
{
|
||||
if (g_allocafn) return g_allocafn(size); else return gim_alloc(size);
|
||||
}
|
||||
|
||||
|
||||
void * gim_realloc(void *ptr, size_t oldsize, size_t newsize)
|
||||
{
|
||||
void * newptr = gim_alloc(newsize);
|
||||
size_t copysize = oldsize<newsize?oldsize:newsize;
|
||||
gim_simd_memcpy(newptr,ptr,copysize);
|
||||
gim_free(ptr);
|
||||
return newptr;
|
||||
}
|
||||
|
||||
void gim_free(void *ptr)
|
||||
{
|
||||
if (!ptr) return;
|
||||
if (g_freefn)
|
||||
{
|
||||
g_freefn(ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef GIM_SIMD_MEMORY
|
||||
btAlignedFree(ptr);
|
||||
#else
|
||||
free(ptr);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
422
Extras/GIMPACT/include/GIMPACT/core/gim_memory.h → src/BulletCollision/Gimpact/gim_memory.h
Executable file → Normal file
422
Extras/GIMPACT/include/GIMPACT/core/gim_memory.h → src/BulletCollision/Gimpact/gim_memory.h
Executable file → Normal file
@@ -1,211 +1,211 @@
|
||||
#ifndef GIM_MEMORY_H_INCLUDED
|
||||
#define GIM_MEMORY_H_INCLUDED
|
||||
/*! \file gim_memory.h
|
||||
\author Francisco León Nájera
|
||||
*/
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
This source file is part of GIMPACT Library.
|
||||
|
||||
For the latest info, see http://gimpact.sourceforge.net/
|
||||
|
||||
Copyright (c) 2006 Francisco Leon Najera. 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.
|
||||
(3) The zlib/libpng license that is included with this library in
|
||||
the file GIMPACT-LICENSE-ZLIB.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, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#include "GIMPACT/core/gim_math.h"
|
||||
#include <memory.h>
|
||||
|
||||
//#define PREFETCH 1
|
||||
//! \defgroup PREFETCH
|
||||
//! @{
|
||||
#ifdef PREFETCH
|
||||
#include <xmmintrin.h> // for prefetch
|
||||
#define pfval 64
|
||||
#define pfval2 128
|
||||
//! Prefetch 64
|
||||
#define pf(_x,_i) _mm_prefetch((void *)(_x + _i + pfval), 0)
|
||||
//! Prefetch 128
|
||||
#define pf2(_x,_i) _mm_prefetch((void *)(_x + _i + pfval2), 0)
|
||||
#else
|
||||
//! Prefetch 64
|
||||
#define pf(_x,_i)
|
||||
//! Prefetch 128
|
||||
#define pf2(_x,_i)
|
||||
#endif
|
||||
//! @}
|
||||
|
||||
/*! \defgroup ARRAY_UTILITIES
|
||||
\brief
|
||||
Functions for manip packed arrays of numbers
|
||||
*/
|
||||
//! @{
|
||||
#define GIM_COPY_ARRAYS(dest_array,source_array,element_count)\
|
||||
{\
|
||||
for (GUINT _i_=0;_i_<element_count ;++_i_)\
|
||||
{\
|
||||
dest_array[_i_] = source_array[_i_];\
|
||||
}\
|
||||
}\
|
||||
|
||||
#define GIM_COPY_ARRAYS_1(dest_array,source_array,element_count,copy_macro)\
|
||||
{\
|
||||
for (GUINT _i_=0;_i_<element_count ;++_i_)\
|
||||
{\
|
||||
copy_macro(dest_array[_i_],source_array[_i_]);\
|
||||
}\
|
||||
}\
|
||||
|
||||
|
||||
#define GIM_ZERO_ARRAY(array,element_count)\
|
||||
{\
|
||||
for (GUINT _i_=0;_i_<element_count ;++_i_)\
|
||||
{\
|
||||
array[_i_] = 0;\
|
||||
}\
|
||||
}\
|
||||
|
||||
#define GIM_CONSTANT_ARRAY(array,element_count,constant)\
|
||||
{\
|
||||
for (GUINT _i_=0;_i_<element_count ;++_i_)\
|
||||
{\
|
||||
array[_i_] = constant;\
|
||||
}\
|
||||
}\
|
||||
//! @}
|
||||
|
||||
/*! \defgroup MEMORY_FUNCTION_PROTOTYPES
|
||||
Function prototypes to allocate and free memory.
|
||||
*/
|
||||
//! @{
|
||||
typedef void * gim_alloc_function (size_t size);
|
||||
typedef void * gim_alloca_function (size_t size);//Allocs on the heap
|
||||
typedef void * gim_realloc_function (void *ptr, size_t oldsize, size_t newsize);
|
||||
typedef void gim_free_function (void *ptr);
|
||||
//! @}
|
||||
|
||||
/*! \defgroup MEMORY_FUNCTION_HANDLERS
|
||||
\brief
|
||||
Memory Function Handlers
|
||||
set new memory management functions. if fn is 0, the default handlers are
|
||||
used. */
|
||||
//! @{
|
||||
void gim_set_alloc_handler (gim_alloc_function *fn);
|
||||
void gim_set_alloca_handler (gim_alloca_function *fn);
|
||||
void gim_set_realloc_handler (gim_realloc_function *fn);
|
||||
void gim_set_free_handler (gim_free_function *fn);
|
||||
//! @}
|
||||
|
||||
/*! \defgroup MEMORY_FUNCTION_GET_HANDLERS
|
||||
\brief
|
||||
get current memory management functions.
|
||||
*/
|
||||
//! @{
|
||||
gim_alloc_function *gim_get_alloc_handler (void);
|
||||
gim_alloca_function *gim_get_alloca_handler(void);
|
||||
gim_realloc_function *gim_get_realloc_handler (void);
|
||||
gim_free_function *gim_get_free_handler (void);
|
||||
//! @}
|
||||
|
||||
/*! \defgroup MEMORY_FUNCTIONS
|
||||
Standar Memory functions
|
||||
*/
|
||||
//! @{
|
||||
void * gim_alloc(size_t size);
|
||||
void * gim_alloca(size_t size);
|
||||
void * gim_realloc(void *ptr, size_t oldsize, size_t newsize);
|
||||
void gim_free(void *ptr);
|
||||
//! @}
|
||||
|
||||
|
||||
#if defined (WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__)
|
||||
#define GIM_SIMD_MEMORY 1
|
||||
#endif
|
||||
|
||||
//! SIMD POINTER INTEGER
|
||||
#define SIMD_T GUINT64
|
||||
//! SIMD INTEGER SIZE
|
||||
#define SIMD_T_SIZE sizeof(SIMD_T)
|
||||
|
||||
|
||||
inline void gim_simd_memcpy(void * dst, const void * src, size_t copysize)
|
||||
{
|
||||
#ifdef GIM_SIMD_MEMORY
|
||||
/*
|
||||
//'long long int' is incompatible with visual studio 6...
|
||||
//copy words
|
||||
SIMD_T * ui_src_ptr = (SIMD_T *)src;
|
||||
SIMD_T * ui_dst_ptr = (SIMD_T *)dst;
|
||||
while(copysize>=SIMD_T_SIZE)
|
||||
{
|
||||
*(ui_dst_ptr++) = *(ui_src_ptr++);
|
||||
copysize-=SIMD_T_SIZE;
|
||||
}
|
||||
if(copysize==0) return;
|
||||
*/
|
||||
|
||||
char * c_src_ptr = (char *)src;
|
||||
char * c_dst_ptr = (char *)dst;
|
||||
while(copysize>0)
|
||||
{
|
||||
*(c_dst_ptr++) = *(c_src_ptr++);
|
||||
copysize--;
|
||||
}
|
||||
return;
|
||||
#else
|
||||
memcpy(dst,src,copysize);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class T>
|
||||
inline void gim_swap_elements(T* _array,size_t _i,size_t _j)
|
||||
{
|
||||
T _e_tmp_ = _array[_i];
|
||||
_array[_i] = _array[_j];
|
||||
_array[_j] = _e_tmp_;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline void gim_swap_elements_memcpy(T* _array,size_t _i,size_t _j)
|
||||
{
|
||||
char _e_tmp_[sizeof(T)];
|
||||
gim_simd_memcpy(_e_tmp_,&_array[_i],sizeof(T));
|
||||
gim_simd_memcpy(&_array[_i],&_array[_j],sizeof(T));
|
||||
gim_simd_memcpy(&_array[_j],_e_tmp_,sizeof(T));
|
||||
}
|
||||
|
||||
template <int SIZE>
|
||||
inline void gim_swap_elements_ptr(char * _array,size_t _i,size_t _j)
|
||||
{
|
||||
char _e_tmp_[SIZE];
|
||||
_i*=SIZE;
|
||||
_j*=SIZE;
|
||||
gim_simd_memcpy(_e_tmp_,_array+_i,SIZE);
|
||||
gim_simd_memcpy(_array+_i,_array+_j,SIZE);
|
||||
gim_simd_memcpy(_array+_j,_e_tmp_,SIZE);
|
||||
}
|
||||
|
||||
#endif // GIM_MEMORY_H_INCLUDED
|
||||
#ifndef GIM_MEMORY_H_INCLUDED
|
||||
#define GIM_MEMORY_H_INCLUDED
|
||||
/*! \file gim_memory.h
|
||||
\author Francisco Len Nßjera
|
||||
*/
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
This source file is part of GIMPACT Library.
|
||||
|
||||
For the latest info, see http://gimpact.sourceforge.net/
|
||||
|
||||
Copyright (c) 2006 Francisco Leon Najera. 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.
|
||||
(3) The zlib/libpng license that is included with this library in
|
||||
the file GIMPACT-LICENSE-ZLIB.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, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#include "gim_math.h"
|
||||
#include <memory.h>
|
||||
|
||||
//#define PREFETCH 1
|
||||
//! \defgroup PREFETCH
|
||||
//! @{
|
||||
#ifdef PREFETCH
|
||||
#include <xmmintrin.h> // for prefetch
|
||||
#define pfval 64
|
||||
#define pfval2 128
|
||||
//! Prefetch 64
|
||||
#define pf(_x,_i) _mm_prefetch((void *)(_x + _i + pfval), 0)
|
||||
//! Prefetch 128
|
||||
#define pf2(_x,_i) _mm_prefetch((void *)(_x + _i + pfval2), 0)
|
||||
#else
|
||||
//! Prefetch 64
|
||||
#define pf(_x,_i)
|
||||
//! Prefetch 128
|
||||
#define pf2(_x,_i)
|
||||
#endif
|
||||
//! @}
|
||||
|
||||
/*! \defgroup ARRAY_UTILITIES
|
||||
\brief
|
||||
Functions for manip packed arrays of numbers
|
||||
*/
|
||||
//! @{
|
||||
#define GIM_COPY_ARRAYS(dest_array,source_array,element_count)\
|
||||
{\
|
||||
for (GUINT _i_=0;_i_<element_count ;++_i_)\
|
||||
{\
|
||||
dest_array[_i_] = source_array[_i_];\
|
||||
}\
|
||||
}\
|
||||
|
||||
#define GIM_COPY_ARRAYS_1(dest_array,source_array,element_count,copy_macro)\
|
||||
{\
|
||||
for (GUINT _i_=0;_i_<element_count ;++_i_)\
|
||||
{\
|
||||
copy_macro(dest_array[_i_],source_array[_i_]);\
|
||||
}\
|
||||
}\
|
||||
|
||||
|
||||
#define GIM_ZERO_ARRAY(array,element_count)\
|
||||
{\
|
||||
for (GUINT _i_=0;_i_<element_count ;++_i_)\
|
||||
{\
|
||||
array[_i_] = 0;\
|
||||
}\
|
||||
}\
|
||||
|
||||
#define GIM_CONSTANT_ARRAY(array,element_count,constant)\
|
||||
{\
|
||||
for (GUINT _i_=0;_i_<element_count ;++_i_)\
|
||||
{\
|
||||
array[_i_] = constant;\
|
||||
}\
|
||||
}\
|
||||
//! @}
|
||||
|
||||
/*! \defgroup MEMORY_FUNCTION_PROTOTYPES
|
||||
Function prototypes to allocate and free memory.
|
||||
*/
|
||||
//! @{
|
||||
typedef void * gim_alloc_function (size_t size);
|
||||
typedef void * gim_alloca_function (size_t size);//Allocs on the heap
|
||||
typedef void * gim_realloc_function (void *ptr, size_t oldsize, size_t newsize);
|
||||
typedef void gim_free_function (void *ptr);
|
||||
//! @}
|
||||
|
||||
/*! \defgroup MEMORY_FUNCTION_HANDLERS
|
||||
\brief
|
||||
Memory Function Handlers
|
||||
set new memory management functions. if fn is 0, the default handlers are
|
||||
used. */
|
||||
//! @{
|
||||
void gim_set_alloc_handler (gim_alloc_function *fn);
|
||||
void gim_set_alloca_handler (gim_alloca_function *fn);
|
||||
void gim_set_realloc_handler (gim_realloc_function *fn);
|
||||
void gim_set_free_handler (gim_free_function *fn);
|
||||
//! @}
|
||||
|
||||
/*! \defgroup MEMORY_FUNCTION_GET_HANDLERS
|
||||
\brief
|
||||
get current memory management functions.
|
||||
*/
|
||||
//! @{
|
||||
gim_alloc_function *gim_get_alloc_handler (void);
|
||||
gim_alloca_function *gim_get_alloca_handler(void);
|
||||
gim_realloc_function *gim_get_realloc_handler (void);
|
||||
gim_free_function *gim_get_free_handler (void);
|
||||
//! @}
|
||||
|
||||
/*! \defgroup MEMORY_FUNCTIONS
|
||||
Standar Memory functions
|
||||
*/
|
||||
//! @{
|
||||
void * gim_alloc(size_t size);
|
||||
void * gim_alloca(size_t size);
|
||||
void * gim_realloc(void *ptr, size_t oldsize, size_t newsize);
|
||||
void gim_free(void *ptr);
|
||||
//! @}
|
||||
|
||||
|
||||
#if defined (WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__)
|
||||
#define GIM_SIMD_MEMORY 1
|
||||
#endif
|
||||
|
||||
//! SIMD POINTER INTEGER
|
||||
#define SIMD_T GUINT64
|
||||
//! SIMD INTEGER SIZE
|
||||
#define SIMD_T_SIZE sizeof(SIMD_T)
|
||||
|
||||
|
||||
inline void gim_simd_memcpy(void * dst, const void * src, size_t copysize)
|
||||
{
|
||||
#ifdef GIM_SIMD_MEMORY
|
||||
/*
|
||||
//'long long int' is incompatible with visual studio 6...
|
||||
//copy words
|
||||
SIMD_T * ui_src_ptr = (SIMD_T *)src;
|
||||
SIMD_T * ui_dst_ptr = (SIMD_T *)dst;
|
||||
while(copysize>=SIMD_T_SIZE)
|
||||
{
|
||||
*(ui_dst_ptr++) = *(ui_src_ptr++);
|
||||
copysize-=SIMD_T_SIZE;
|
||||
}
|
||||
if(copysize==0) return;
|
||||
*/
|
||||
|
||||
char * c_src_ptr = (char *)src;
|
||||
char * c_dst_ptr = (char *)dst;
|
||||
while(copysize>0)
|
||||
{
|
||||
*(c_dst_ptr++) = *(c_src_ptr++);
|
||||
copysize--;
|
||||
}
|
||||
return;
|
||||
#else
|
||||
memcpy(dst,src,copysize);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class T>
|
||||
inline void gim_swap_elements(T* _array,size_t _i,size_t _j)
|
||||
{
|
||||
T _e_tmp_ = _array[_i];
|
||||
_array[_i] = _array[_j];
|
||||
_array[_j] = _e_tmp_;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline void gim_swap_elements_memcpy(T* _array,size_t _i,size_t _j)
|
||||
{
|
||||
char _e_tmp_[sizeof(T)];
|
||||
gim_simd_memcpy(_e_tmp_,&_array[_i],sizeof(T));
|
||||
gim_simd_memcpy(&_array[_i],&_array[_j],sizeof(T));
|
||||
gim_simd_memcpy(&_array[_j],_e_tmp_,sizeof(T));
|
||||
}
|
||||
|
||||
template <int SIZE>
|
||||
inline void gim_swap_elements_ptr(char * _array,size_t _i,size_t _j)
|
||||
{
|
||||
char _e_tmp_[SIZE];
|
||||
_i*=SIZE;
|
||||
_j*=SIZE;
|
||||
gim_simd_memcpy(_e_tmp_,_array+_i,SIZE);
|
||||
gim_simd_memcpy(_array+_i,_array+_j,SIZE);
|
||||
gim_simd_memcpy(_array+_j,_e_tmp_,SIZE);
|
||||
}
|
||||
|
||||
#endif // GIM_MEMORY_H_INCLUDED
|
||||
820
Extras/GIMPACT/include/GIMPACT/core/gim_radixsort.h → src/BulletCollision/Gimpact/gim_radixsort.h
Executable file → Normal file
820
Extras/GIMPACT/include/GIMPACT/core/gim_radixsort.h → src/BulletCollision/Gimpact/gim_radixsort.h
Executable file → Normal file
@@ -1,410 +1,410 @@
|
||||
#ifndef GIM_RADIXSORT_H_INCLUDED
|
||||
#define GIM_RADIXSORT_H_INCLUDED
|
||||
/*! \file gim_radixsort.h
|
||||
\author Francisco León Nájera.
|
||||
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 Najera. 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.
|
||||
(3) The zlib/libpng license that is included with this library in
|
||||
the file GIMPACT-LICENSE-ZLIB.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, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "GIMPACT/core/gim_memory.h"
|
||||
|
||||
/*! \defgroup SORTING
|
||||
\brief
|
||||
Macros for sorting.
|
||||
*/
|
||||
|
||||
//! Prototype for comparators
|
||||
class less_comparator
|
||||
{
|
||||
public:
|
||||
|
||||
template<class T,class Z>
|
||||
inline int operator() ( const T& a, const Z& b )
|
||||
{
|
||||
return ( a<b?-1:(a>b?1:0));
|
||||
}
|
||||
};
|
||||
|
||||
//! Prototype for comparators
|
||||
class integer_comparator
|
||||
{
|
||||
public:
|
||||
|
||||
template<class T>
|
||||
inline int operator() ( const T& a, const T& b )
|
||||
{
|
||||
return (int)(a-b);
|
||||
}
|
||||
};
|
||||
|
||||
//!Prototype for getting the integer representation of an object
|
||||
class uint_key_func
|
||||
{
|
||||
public:
|
||||
template<class T>
|
||||
inline GUINT operator()( const T& a)
|
||||
{
|
||||
return (GUINT)a;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//!Prototype for copying elements
|
||||
class copy_elements_func
|
||||
{
|
||||
public:
|
||||
template<class T>
|
||||
inline void operator()(T& a,T& b)
|
||||
{
|
||||
a = b;
|
||||
}
|
||||
};
|
||||
|
||||
//!Prototype for copying elements
|
||||
class memcopy_elements_func
|
||||
{
|
||||
public:
|
||||
template<class T>
|
||||
inline void operator()(T& a,T& b)
|
||||
{
|
||||
gim_simd_memcpy(&a,&b,sizeof(T));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//! @{
|
||||
struct GIM_RSORT_TOKEN
|
||||
{
|
||||
GUINT m_key;
|
||||
GUINT m_value;
|
||||
GIM_RSORT_TOKEN()
|
||||
{
|
||||
}
|
||||
GIM_RSORT_TOKEN(const GIM_RSORT_TOKEN& rtoken)
|
||||
{
|
||||
m_key = rtoken.m_key;
|
||||
m_value = rtoken.m_value;
|
||||
}
|
||||
|
||||
inline bool operator <(const GIM_RSORT_TOKEN& other) const
|
||||
{
|
||||
return (m_key < other.m_key);
|
||||
}
|
||||
|
||||
inline bool operator >(const GIM_RSORT_TOKEN& other) const
|
||||
{
|
||||
return (m_key > other.m_key);
|
||||
}
|
||||
};
|
||||
|
||||
//! Prototype for comparators
|
||||
class GIM_RSORT_TOKEN_COMPARATOR
|
||||
{
|
||||
public:
|
||||
|
||||
inline int operator()( const GIM_RSORT_TOKEN& a, const GIM_RSORT_TOKEN& b )
|
||||
{
|
||||
return (int)((a.m_key) - (b.m_key));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#define kHist 2048
|
||||
// ---- 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 )
|
||||
|
||||
|
||||
|
||||
///Radix sort for unsigned integer keys
|
||||
inline void gim_radix_sort_rtokens(
|
||||
GIM_RSORT_TOKEN * array,
|
||||
GIM_RSORT_TOKEN * sorted, GUINT element_count)
|
||||
{
|
||||
GUINT i;
|
||||
GUINT b0[kHist * 3];
|
||||
GUINT *b1 = b0 + kHist;
|
||||
GUINT *b2 = b1 + kHist;
|
||||
for (i = 0; i < kHist * 3; ++i)
|
||||
{
|
||||
b0[i] = 0;
|
||||
}
|
||||
GUINT fi;
|
||||
GUINT 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)] ++;
|
||||
}
|
||||
{
|
||||
GUINT sum0 = 0, sum1 = 0, sum2 = 0;
|
||||
GUINT tsum;
|
||||
for (i = 0; i < kHist; ++i)
|
||||
{
|
||||
tsum = b0[i] + sum0;
|
||||
b0[i] = sum0 - 1;
|
||||
sum0 = tsum;
|
||||
tsum = b1[i] + sum1;
|
||||
b1[i] = sum1 - 1;
|
||||
sum1 = tsum;
|
||||
tsum = b2[i] + sum2;
|
||||
b2[i] = sum2 - 1;
|
||||
sum2 = tsum;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < element_count; ++i)
|
||||
{
|
||||
fi = array[i].m_key;
|
||||
pos = D11_0(fi);
|
||||
pos = ++b0[pos];
|
||||
sorted[pos].m_key = array[i].m_key;
|
||||
sorted[pos].m_value = array[i].m_value;
|
||||
}
|
||||
for (i = 0; i < element_count; ++i)
|
||||
{
|
||||
fi = sorted[i].m_key;
|
||||
pos = D11_1(fi);
|
||||
pos = ++b1[pos];
|
||||
array[pos].m_key = sorted[i].m_key;
|
||||
array[pos].m_value = sorted[i].m_value;
|
||||
}
|
||||
for (i = 0; i < element_count; ++i)
|
||||
{
|
||||
fi = array[i].m_key;
|
||||
pos = D11_2(fi);
|
||||
pos = ++b2[pos];
|
||||
sorted[pos].m_key = array[i].m_key;
|
||||
sorted[pos].m_value = array[i].m_value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// Get the sorted tokens from an array. For generic use. Tokens are IRR_RSORT_TOKEN
|
||||
/*!
|
||||
*\param array Array of elements to sort
|
||||
*\param sorted_tokens Tokens of sorted elements
|
||||
*\param element_count element count
|
||||
*\param uintkey_macro Functor which retrieves the integer representation of an array element
|
||||
*/
|
||||
template<typename T, class GETKEY_CLASS>
|
||||
void gim_radix_sort_array_tokens(
|
||||
T* array ,
|
||||
GIM_RSORT_TOKEN * sorted_tokens,
|
||||
GUINT element_count,GETKEY_CLASS uintkey_macro)
|
||||
{
|
||||
GIM_RSORT_TOKEN * _unsorted = (GIM_RSORT_TOKEN *) gim_alloc(sizeof(GIM_RSORT_TOKEN)*element_count);
|
||||
for (GUINT _i=0;_i<element_count;++_i)
|
||||
{
|
||||
_unsorted[_i].m_key = uintkey_macro(array[_i]);
|
||||
_unsorted[_i].m_value = _i;
|
||||
}
|
||||
gim_radix_sort_rtokens(_unsorted,sorted_tokens,element_count);
|
||||
gim_free(_unsorted);
|
||||
gim_free(_unsorted);
|
||||
}
|
||||
|
||||
/// Sorts array in place. For generic use
|
||||
/*!
|
||||
\param type Type of the array
|
||||
\param array
|
||||
\param element_count
|
||||
\param get_uintkey_macro Macro for extract the Integer value of the element. Similar to SIMPLE_GET_UINTKEY
|
||||
\param copy_elements_macro Macro for copy elements, similar to SIMPLE_COPY_ELEMENTS
|
||||
*/
|
||||
template<typename T, class GETKEY_CLASS, class COPY_CLASS>
|
||||
void gim_radix_sort(
|
||||
T * array, GUINT element_count,
|
||||
GETKEY_CLASS get_uintkey_macro, COPY_CLASS copy_elements_macro)
|
||||
{
|
||||
GIM_RSORT_TOKEN * _sorted = (GIM_RSORT_TOKEN *) gim_alloc(sizeof(GIM_RSORT_TOKEN)*element_count);
|
||||
gim_radix_sort_array_tokens(array,_sorted,element_count,get_uintkey_macro);
|
||||
T * _original_array = (T *) gim_alloc(sizeof(T)*element_count);
|
||||
gim_simd_memcpy(_original_array,array,sizeof(T)*element_count);
|
||||
for (GUINT _i=0;_i<element_count;++_i)
|
||||
{
|
||||
copy_elements_macro(array[_i],_original_array[_sorted[_i].m_value]);
|
||||
}
|
||||
gim_free(_original_array);
|
||||
gim_free(_sorted);
|
||||
}
|
||||
|
||||
//! Failsafe Iterative binary search,
|
||||
/*!
|
||||
If the element is not found, it returns the nearest upper element position, may be the further position after the last element.
|
||||
\param _array
|
||||
\param _start_i the beginning of the array
|
||||
\param _end_i the ending index of the array
|
||||
\param _search_key Value to find
|
||||
\param _comp_macro macro for comparing elements
|
||||
\param _found If true the value has found. Boolean
|
||||
\param _result_index the index of the found element, or if not found then it will get the index of the closest bigger value
|
||||
*/
|
||||
template<class T, typename KEYCLASS, typename COMP_CLASS>
|
||||
bool gim_binary_search_ex(
|
||||
const T* _array, GUINT _start_i,
|
||||
GUINT _end_i,GUINT & _result_index,
|
||||
const KEYCLASS & _search_key,
|
||||
COMP_CLASS _comp_macro)
|
||||
{
|
||||
GUINT _k;
|
||||
int _comp_result;
|
||||
GUINT _i = _start_i;
|
||||
GUINT _j = _end_i+1;
|
||||
while (_i < _j)
|
||||
{
|
||||
_k = (_j+_i-1)/2;
|
||||
_comp_result = _comp_macro(_array[_k], _search_key);
|
||||
if (_comp_result == 0)
|
||||
{
|
||||
_result_index = _k;
|
||||
return true;
|
||||
}
|
||||
else if (_comp_result < 0)
|
||||
{
|
||||
_i = _k+1;
|
||||
}
|
||||
else
|
||||
{
|
||||
_j = _k;
|
||||
}
|
||||
}
|
||||
_result_index = _i;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//! Failsafe Iterative binary search,Template version
|
||||
/*!
|
||||
If the element is not found, it returns the nearest upper element position, may be the further position after the last element.
|
||||
\param _array
|
||||
\param _start_i the beginning of the array
|
||||
\param _end_i the ending index of the array
|
||||
\param _search_key Value to find
|
||||
\param _result_index the index of the found element, or if not found then it will get the index of the closest bigger value
|
||||
\return true if found, else false
|
||||
*/
|
||||
template<class T>
|
||||
bool gim_binary_search(
|
||||
const T*_array,GUINT _start_i,
|
||||
GUINT _end_i,const T & _search_key,
|
||||
GUINT & _result_index)
|
||||
{
|
||||
GUINT _i = _start_i;
|
||||
GUINT _j = _end_i+1;
|
||||
GUINT _k;
|
||||
while(_i < _j)
|
||||
{
|
||||
_k = (_j+_i-1)/2;
|
||||
if(_array[_k]==_search_key)
|
||||
{
|
||||
_result_index = _k;
|
||||
return true;
|
||||
}
|
||||
else if (_array[_k]<_search_key)
|
||||
{
|
||||
_i = _k+1;
|
||||
}
|
||||
else
|
||||
{
|
||||
_j = _k;
|
||||
}
|
||||
}
|
||||
_result_index = _i;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
///heap sort from http://www.csse.monash.edu.au/~lloyd/tildeAlgDS/Sort/Heap/
|
||||
template <typename T, typename COMP_CLASS>
|
||||
void gim_down_heap(T *pArr, GUINT k, GUINT n,COMP_CLASS CompareFunc)
|
||||
{
|
||||
/* PRE: a[k+1..N] is a heap */
|
||||
/* POST: a[k..N] is a heap */
|
||||
|
||||
T temp = pArr[k - 1];
|
||||
/* k has child(s) */
|
||||
while (k <= n/2)
|
||||
{
|
||||
int child = 2*k;
|
||||
|
||||
if ((child < (int)n) && CompareFunc(pArr[child - 1] , pArr[child])<0)
|
||||
{
|
||||
child++;
|
||||
}
|
||||
/* pick larger child */
|
||||
if (CompareFunc(temp , pArr[child - 1])<0)
|
||||
{
|
||||
/* move child up */
|
||||
pArr[k - 1] = pArr[child - 1];
|
||||
k = child;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
pArr[k - 1] = temp;
|
||||
} /*downHeap*/
|
||||
|
||||
|
||||
template <typename T, typename COMP_CLASS>
|
||||
void gim_heap_sort(T *pArr, GUINT element_count, COMP_CLASS CompareFunc)
|
||||
{
|
||||
/* sort a[0..N-1], N.B. 0 to N-1 */
|
||||
GUINT k;
|
||||
GUINT n = element_count;
|
||||
for (k = n/2; k > 0; k--)
|
||||
{
|
||||
gim_down_heap(pArr, k, n, CompareFunc);
|
||||
}
|
||||
|
||||
/* a[1..N] is now a heap */
|
||||
while ( n>=2 )
|
||||
{
|
||||
gim_swap_elements(pArr,0,n-1); /* largest of a[0..n-1] */
|
||||
--n;
|
||||
/* restore a[1..i-1] heap */
|
||||
gim_down_heap(pArr, 1, n, CompareFunc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//! @}
|
||||
#endif // GIM_RADIXSORT_H_INCLUDED
|
||||
#ifndef GIM_RADIXSORT_H_INCLUDED
|
||||
#define GIM_RADIXSORT_H_INCLUDED
|
||||
/*! \file gim_radixsort.h
|
||||
\author Francisco Len Nßjera.
|
||||
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 Najera. 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.
|
||||
(3) The zlib/libpng license that is included with this library in
|
||||
the file GIMPACT-LICENSE-ZLIB.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, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "gim_memory.h"
|
||||
|
||||
/*! \defgroup SORTING
|
||||
\brief
|
||||
Macros for sorting.
|
||||
*/
|
||||
|
||||
//! Prototype for comparators
|
||||
class less_comparator
|
||||
{
|
||||
public:
|
||||
|
||||
template<class T,class Z>
|
||||
inline int operator() ( const T& a, const Z& b )
|
||||
{
|
||||
return ( a<b?-1:(a>b?1:0));
|
||||
}
|
||||
};
|
||||
|
||||
//! Prototype for comparators
|
||||
class integer_comparator
|
||||
{
|
||||
public:
|
||||
|
||||
template<class T>
|
||||
inline int operator() ( const T& a, const T& b )
|
||||
{
|
||||
return (int)(a-b);
|
||||
}
|
||||
};
|
||||
|
||||
//!Prototype for getting the integer representation of an object
|
||||
class uint_key_func
|
||||
{
|
||||
public:
|
||||
template<class T>
|
||||
inline GUINT operator()( const T& a)
|
||||
{
|
||||
return (GUINT)a;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//!Prototype for copying elements
|
||||
class copy_elements_func
|
||||
{
|
||||
public:
|
||||
template<class T>
|
||||
inline void operator()(T& a,T& b)
|
||||
{
|
||||
a = b;
|
||||
}
|
||||
};
|
||||
|
||||
//!Prototype for copying elements
|
||||
class memcopy_elements_func
|
||||
{
|
||||
public:
|
||||
template<class T>
|
||||
inline void operator()(T& a,T& b)
|
||||
{
|
||||
gim_simd_memcpy(&a,&b,sizeof(T));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//! @{
|
||||
struct GIM_RSORT_TOKEN
|
||||
{
|
||||
GUINT m_key;
|
||||
GUINT m_value;
|
||||
GIM_RSORT_TOKEN()
|
||||
{
|
||||
}
|
||||
GIM_RSORT_TOKEN(const GIM_RSORT_TOKEN& rtoken)
|
||||
{
|
||||
m_key = rtoken.m_key;
|
||||
m_value = rtoken.m_value;
|
||||
}
|
||||
|
||||
inline bool operator <(const GIM_RSORT_TOKEN& other) const
|
||||
{
|
||||
return (m_key < other.m_key);
|
||||
}
|
||||
|
||||
inline bool operator >(const GIM_RSORT_TOKEN& other) const
|
||||
{
|
||||
return (m_key > other.m_key);
|
||||
}
|
||||
};
|
||||
|
||||
//! Prototype for comparators
|
||||
class GIM_RSORT_TOKEN_COMPARATOR
|
||||
{
|
||||
public:
|
||||
|
||||
inline int operator()( const GIM_RSORT_TOKEN& a, const GIM_RSORT_TOKEN& b )
|
||||
{
|
||||
return (int)((a.m_key) - (b.m_key));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#define kHist 2048
|
||||
// ---- 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 )
|
||||
|
||||
|
||||
|
||||
///Radix sort for unsigned integer keys
|
||||
inline void gim_radix_sort_rtokens(
|
||||
GIM_RSORT_TOKEN * array,
|
||||
GIM_RSORT_TOKEN * sorted, GUINT element_count)
|
||||
{
|
||||
GUINT i;
|
||||
GUINT b0[kHist * 3];
|
||||
GUINT *b1 = b0 + kHist;
|
||||
GUINT *b2 = b1 + kHist;
|
||||
for (i = 0; i < kHist * 3; ++i)
|
||||
{
|
||||
b0[i] = 0;
|
||||
}
|
||||
GUINT fi;
|
||||
GUINT 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)] ++;
|
||||
}
|
||||
{
|
||||
GUINT sum0 = 0, sum1 = 0, sum2 = 0;
|
||||
GUINT tsum;
|
||||
for (i = 0; i < kHist; ++i)
|
||||
{
|
||||
tsum = b0[i] + sum0;
|
||||
b0[i] = sum0 - 1;
|
||||
sum0 = tsum;
|
||||
tsum = b1[i] + sum1;
|
||||
b1[i] = sum1 - 1;
|
||||
sum1 = tsum;
|
||||
tsum = b2[i] + sum2;
|
||||
b2[i] = sum2 - 1;
|
||||
sum2 = tsum;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < element_count; ++i)
|
||||
{
|
||||
fi = array[i].m_key;
|
||||
pos = D11_0(fi);
|
||||
pos = ++b0[pos];
|
||||
sorted[pos].m_key = array[i].m_key;
|
||||
sorted[pos].m_value = array[i].m_value;
|
||||
}
|
||||
for (i = 0; i < element_count; ++i)
|
||||
{
|
||||
fi = sorted[i].m_key;
|
||||
pos = D11_1(fi);
|
||||
pos = ++b1[pos];
|
||||
array[pos].m_key = sorted[i].m_key;
|
||||
array[pos].m_value = sorted[i].m_value;
|
||||
}
|
||||
for (i = 0; i < element_count; ++i)
|
||||
{
|
||||
fi = array[i].m_key;
|
||||
pos = D11_2(fi);
|
||||
pos = ++b2[pos];
|
||||
sorted[pos].m_key = array[i].m_key;
|
||||
sorted[pos].m_value = array[i].m_value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// Get the sorted tokens from an array. For generic use. Tokens are IRR_RSORT_TOKEN
|
||||
/*!
|
||||
*\param array Array of elements to sort
|
||||
*\param sorted_tokens Tokens of sorted elements
|
||||
*\param element_count element count
|
||||
*\param uintkey_macro Functor which retrieves the integer representation of an array element
|
||||
*/
|
||||
template<typename T, class GETKEY_CLASS>
|
||||
void gim_radix_sort_array_tokens(
|
||||
T* array ,
|
||||
GIM_RSORT_TOKEN * sorted_tokens,
|
||||
GUINT element_count,GETKEY_CLASS uintkey_macro)
|
||||
{
|
||||
GIM_RSORT_TOKEN * _unsorted = (GIM_RSORT_TOKEN *) gim_alloc(sizeof(GIM_RSORT_TOKEN)*element_count);
|
||||
for (GUINT _i=0;_i<element_count;++_i)
|
||||
{
|
||||
_unsorted[_i].m_key = uintkey_macro(array[_i]);
|
||||
_unsorted[_i].m_value = _i;
|
||||
}
|
||||
gim_radix_sort_rtokens(_unsorted,sorted_tokens,element_count);
|
||||
gim_free(_unsorted);
|
||||
gim_free(_unsorted);
|
||||
}
|
||||
|
||||
/// Sorts array in place. For generic use
|
||||
/*!
|
||||
\param type Type of the array
|
||||
\param array
|
||||
\param element_count
|
||||
\param get_uintkey_macro Macro for extract the Integer value of the element. Similar to SIMPLE_GET_UINTKEY
|
||||
\param copy_elements_macro Macro for copy elements, similar to SIMPLE_COPY_ELEMENTS
|
||||
*/
|
||||
template<typename T, class GETKEY_CLASS, class COPY_CLASS>
|
||||
void gim_radix_sort(
|
||||
T * array, GUINT element_count,
|
||||
GETKEY_CLASS get_uintkey_macro, COPY_CLASS copy_elements_macro)
|
||||
{
|
||||
GIM_RSORT_TOKEN * _sorted = (GIM_RSORT_TOKEN *) gim_alloc(sizeof(GIM_RSORT_TOKEN)*element_count);
|
||||
gim_radix_sort_array_tokens(array,_sorted,element_count,get_uintkey_macro);
|
||||
T * _original_array = (T *) gim_alloc(sizeof(T)*element_count);
|
||||
gim_simd_memcpy(_original_array,array,sizeof(T)*element_count);
|
||||
for (GUINT _i=0;_i<element_count;++_i)
|
||||
{
|
||||
copy_elements_macro(array[_i],_original_array[_sorted[_i].m_value]);
|
||||
}
|
||||
gim_free(_original_array);
|
||||
gim_free(_sorted);
|
||||
}
|
||||
|
||||
//! Failsafe Iterative binary search,
|
||||
/*!
|
||||
If the element is not found, it returns the nearest upper element position, may be the further position after the last element.
|
||||
\param _array
|
||||
\param _start_i the beginning of the array
|
||||
\param _end_i the ending index of the array
|
||||
\param _search_key Value to find
|
||||
\param _comp_macro macro for comparing elements
|
||||
\param _found If true the value has found. Boolean
|
||||
\param _result_index the index of the found element, or if not found then it will get the index of the closest bigger value
|
||||
*/
|
||||
template<class T, typename KEYCLASS, typename COMP_CLASS>
|
||||
bool gim_binary_search_ex(
|
||||
const T* _array, GUINT _start_i,
|
||||
GUINT _end_i,GUINT & _result_index,
|
||||
const KEYCLASS & _search_key,
|
||||
COMP_CLASS _comp_macro)
|
||||
{
|
||||
GUINT _k;
|
||||
int _comp_result;
|
||||
GUINT _i = _start_i;
|
||||
GUINT _j = _end_i+1;
|
||||
while (_i < _j)
|
||||
{
|
||||
_k = (_j+_i-1)/2;
|
||||
_comp_result = _comp_macro(_array[_k], _search_key);
|
||||
if (_comp_result == 0)
|
||||
{
|
||||
_result_index = _k;
|
||||
return true;
|
||||
}
|
||||
else if (_comp_result < 0)
|
||||
{
|
||||
_i = _k+1;
|
||||
}
|
||||
else
|
||||
{
|
||||
_j = _k;
|
||||
}
|
||||
}
|
||||
_result_index = _i;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//! Failsafe Iterative binary search,Template version
|
||||
/*!
|
||||
If the element is not found, it returns the nearest upper element position, may be the further position after the last element.
|
||||
\param _array
|
||||
\param _start_i the beginning of the array
|
||||
\param _end_i the ending index of the array
|
||||
\param _search_key Value to find
|
||||
\param _result_index the index of the found element, or if not found then it will get the index of the closest bigger value
|
||||
\return true if found, else false
|
||||
*/
|
||||
template<class T>
|
||||
bool gim_binary_search(
|
||||
const T*_array,GUINT _start_i,
|
||||
GUINT _end_i,const T & _search_key,
|
||||
GUINT & _result_index)
|
||||
{
|
||||
GUINT _i = _start_i;
|
||||
GUINT _j = _end_i+1;
|
||||
GUINT _k;
|
||||
while(_i < _j)
|
||||
{
|
||||
_k = (_j+_i-1)/2;
|
||||
if(_array[_k]==_search_key)
|
||||
{
|
||||
_result_index = _k;
|
||||
return true;
|
||||
}
|
||||
else if (_array[_k]<_search_key)
|
||||
{
|
||||
_i = _k+1;
|
||||
}
|
||||
else
|
||||
{
|
||||
_j = _k;
|
||||
}
|
||||
}
|
||||
_result_index = _i;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
///heap sort from http://www.csse.monash.edu.au/~lloyd/tildeAlgDS/Sort/Heap/
|
||||
template <typename T, typename COMP_CLASS>
|
||||
void gim_down_heap(T *pArr, GUINT k, GUINT n,COMP_CLASS CompareFunc)
|
||||
{
|
||||
/* PRE: a[k+1..N] is a heap */
|
||||
/* POST: a[k..N] is a heap */
|
||||
|
||||
T temp = pArr[k - 1];
|
||||
/* k has child(s) */
|
||||
while (k <= n/2)
|
||||
{
|
||||
int child = 2*k;
|
||||
|
||||
if ((child < (int)n) && CompareFunc(pArr[child - 1] , pArr[child])<0)
|
||||
{
|
||||
child++;
|
||||
}
|
||||
/* pick larger child */
|
||||
if (CompareFunc(temp , pArr[child - 1])<0)
|
||||
{
|
||||
/* move child up */
|
||||
pArr[k - 1] = pArr[child - 1];
|
||||
k = child;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
pArr[k - 1] = temp;
|
||||
} /*downHeap*/
|
||||
|
||||
|
||||
template <typename T, typename COMP_CLASS>
|
||||
void gim_heap_sort(T *pArr, GUINT element_count, COMP_CLASS CompareFunc)
|
||||
{
|
||||
/* sort a[0..N-1], N.B. 0 to N-1 */
|
||||
GUINT k;
|
||||
GUINT n = element_count;
|
||||
for (k = n/2; k > 0; k--)
|
||||
{
|
||||
gim_down_heap(pArr, k, n, CompareFunc);
|
||||
}
|
||||
|
||||
/* a[1..N] is now a heap */
|
||||
while ( n>=2 )
|
||||
{
|
||||
gim_swap_elements(pArr,0,n-1); /* largest of a[0..n-1] */
|
||||
--n;
|
||||
/* restore a[1..i-1] heap */
|
||||
gim_down_heap(pArr, 1, n, CompareFunc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//! @}
|
||||
#endif // GIM_RADIXSORT_H_INCLUDED
|
||||
1280
Extras/GIMPACT/src/core/gim_tri_collision.cpp → src/BulletCollision/Gimpact/gim_tri_collision.cpp
Executable file → Normal file
1280
Extras/GIMPACT/src/core/gim_tri_collision.cpp → src/BulletCollision/Gimpact/gim_tri_collision.cpp
Executable file → Normal file
File diff suppressed because it is too large
Load Diff
766
Extras/GIMPACT/include/GIMPACT/core/gim_tri_collision.h → src/BulletCollision/Gimpact/gim_tri_collision.h
Executable file → Normal file
766
Extras/GIMPACT/include/GIMPACT/core/gim_tri_collision.h → src/BulletCollision/Gimpact/gim_tri_collision.h
Executable file → Normal file
@@ -1,383 +1,383 @@
|
||||
#ifndef GIM_TRI_COLLISION_H_INCLUDED
|
||||
#define GIM_TRI_COLLISION_H_INCLUDED
|
||||
|
||||
/*! \file gim_tri_collision.h
|
||||
\author Francisco León Nájera
|
||||
*/
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
This source file is part of GIMPACT Library.
|
||||
|
||||
For the latest info, see http://gimpact.sourceforge.net/
|
||||
|
||||
Copyright (c) 2006 Francisco Leon Najera. 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.
|
||||
(3) The zlib/libpng license that is included with this library in
|
||||
the file GIMPACT-LICENSE-ZLIB.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, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "GIMPACT/core/gim_box_collision.h"
|
||||
#include "GIMPACT/core/gim_clip_polygon.h"
|
||||
|
||||
/*! \addtogroup GEOMETRIC_OPERATIONS
|
||||
*/
|
||||
//! @{
|
||||
|
||||
|
||||
|
||||
#define MAX_TRI_CLIPPING 16
|
||||
|
||||
//! Structure for collision
|
||||
struct GIM_TRIANGLE_CONTACT_DATA
|
||||
{
|
||||
GREAL m_penetration_depth;
|
||||
GUINT m_point_count;
|
||||
btVector4 m_separating_normal;
|
||||
btVector3 m_points[MAX_TRI_CLIPPING];
|
||||
|
||||
SIMD_FORCE_INLINE void copy_from(const GIM_TRIANGLE_CONTACT_DATA& other)
|
||||
{
|
||||
m_penetration_depth = other.m_penetration_depth;
|
||||
m_separating_normal = other.m_separating_normal;
|
||||
m_point_count = other.m_point_count;
|
||||
GUINT i = m_point_count;
|
||||
while(i--)
|
||||
{
|
||||
m_points[i] = other.m_points[i];
|
||||
}
|
||||
}
|
||||
|
||||
GIM_TRIANGLE_CONTACT_DATA()
|
||||
{
|
||||
}
|
||||
|
||||
GIM_TRIANGLE_CONTACT_DATA(const GIM_TRIANGLE_CONTACT_DATA& other)
|
||||
{
|
||||
copy_from(other);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//! classify points that are closer
|
||||
template<typename DISTANCE_FUNC,typename CLASS_PLANE>
|
||||
SIMD_FORCE_INLINE void mergepoints_generic(const CLASS_PLANE & plane,
|
||||
GREAL margin, const btVector3 * points, GUINT point_count, DISTANCE_FUNC distance_func)
|
||||
{
|
||||
m_point_count = 0;
|
||||
m_penetration_depth= -1000.0f;
|
||||
|
||||
GUINT point_indices[MAX_TRI_CLIPPING];
|
||||
|
||||
GUINT _k;
|
||||
|
||||
for(_k=0;_k<point_count;_k++)
|
||||
{
|
||||
GREAL _dist = -distance_func(plane,points[_k]) + margin;
|
||||
|
||||
if(_dist>=0.0f)
|
||||
{
|
||||
if(_dist>m_penetration_depth)
|
||||
{
|
||||
m_penetration_depth = _dist;
|
||||
point_indices[0] = _k;
|
||||
m_point_count=1;
|
||||
}
|
||||
else if((_dist+G_EPSILON)>=m_penetration_depth)
|
||||
{
|
||||
point_indices[m_point_count] = _k;
|
||||
m_point_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for( _k=0;_k<m_point_count;_k++)
|
||||
{
|
||||
m_points[_k] = points[point_indices[_k]];
|
||||
}
|
||||
}
|
||||
|
||||
//! classify points that are closer
|
||||
SIMD_FORCE_INLINE void merge_points(const btVector4 & plane, GREAL margin,
|
||||
const btVector3 * points, GUINT point_count)
|
||||
{
|
||||
m_separating_normal = plane;
|
||||
mergepoints_generic(plane, margin, points, point_count, DISTANCE_PLANE_3D_FUNC());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//! Class for colliding triangles
|
||||
class GIM_TRIANGLE
|
||||
{
|
||||
public:
|
||||
btScalar m_margin;
|
||||
btVector3 m_vertices[3];
|
||||
|
||||
GIM_TRIANGLE():m_margin(0.1f)
|
||||
{
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE GIM_AABB get_box() const
|
||||
{
|
||||
return GIM_AABB(m_vertices[0],m_vertices[1],m_vertices[2],m_margin);
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE void get_normal(btVector3 &normal) const
|
||||
{
|
||||
TRIANGLE_NORMAL(m_vertices[0],m_vertices[1],m_vertices[2],normal);
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE void get_plane(btVector4 &plane) const
|
||||
{
|
||||
TRIANGLE_PLANE(m_vertices[0],m_vertices[1],m_vertices[2],plane);;
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE void apply_transform(const btTransform & trans)
|
||||
{
|
||||
m_vertices[0] = trans(m_vertices[0]);
|
||||
m_vertices[1] = trans(m_vertices[1]);
|
||||
m_vertices[2] = trans(m_vertices[2]);
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE void get_edge_plane(GUINT edge_index,const btVector3 &triangle_normal,btVector4 &plane) const
|
||||
{
|
||||
const btVector3 & e0 = m_vertices[edge_index];
|
||||
const btVector3 & e1 = m_vertices[(edge_index+1)%3];
|
||||
EDGE_PLANE(e0,e1,triangle_normal,plane);
|
||||
}
|
||||
|
||||
//! Gets the relative transformation of this triangle
|
||||
/*!
|
||||
The transformation is oriented to the triangle normal , and aligned to the 1st edge of this triangle. The position corresponds to vertice 0:
|
||||
- triangle normal corresponds to Z axis.
|
||||
- 1st normalized edge corresponds to X axis,
|
||||
|
||||
*/
|
||||
SIMD_FORCE_INLINE void get_triangle_transform(btTransform & triangle_transform) const
|
||||
{
|
||||
btMatrix3x3 & matrix = triangle_transform.getBasis();
|
||||
|
||||
btVector3 zaxis;
|
||||
get_normal(zaxis);
|
||||
MAT_SET_Z(matrix,zaxis);
|
||||
|
||||
btVector3 xaxis = m_vertices[1] - m_vertices[0];
|
||||
VEC_NORMALIZE(xaxis);
|
||||
MAT_SET_X(matrix,xaxis);
|
||||
|
||||
//y axis
|
||||
xaxis = zaxis.cross(xaxis);
|
||||
MAT_SET_Y(matrix,xaxis);
|
||||
|
||||
triangle_transform.setOrigin(m_vertices[0]);
|
||||
}
|
||||
|
||||
|
||||
//! Test triangles by finding separating axis
|
||||
/*!
|
||||
\param other Triangle for collide
|
||||
\param contact_data Structure for holding contact points, normal and penetration depth; The normal is pointing toward this triangle from the other triangle
|
||||
*/
|
||||
bool collide_triangle_hard_test(
|
||||
const GIM_TRIANGLE & other,
|
||||
GIM_TRIANGLE_CONTACT_DATA & contact_data) const;
|
||||
|
||||
//! Test boxes before doing hard test
|
||||
/*!
|
||||
\param other Triangle for collide
|
||||
\param contact_data Structure for holding contact points, normal and penetration depth; The normal is pointing toward this triangle from the other triangle
|
||||
\
|
||||
*/
|
||||
SIMD_FORCE_INLINE bool collide_triangle(
|
||||
const GIM_TRIANGLE & other,
|
||||
GIM_TRIANGLE_CONTACT_DATA & contact_data) const
|
||||
{
|
||||
//test box collisioin
|
||||
GIM_AABB boxu(m_vertices[0],m_vertices[1],m_vertices[2],m_margin);
|
||||
GIM_AABB boxv(other.m_vertices[0],other.m_vertices[1],other.m_vertices[2],other.m_margin);
|
||||
if(!boxu.has_collision(boxv)) return false;
|
||||
|
||||
//do hard test
|
||||
return collide_triangle_hard_test(other,contact_data);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
Solve the System for u,v parameters:
|
||||
|
||||
u*axe1[i1] + v*axe2[i1] = vecproj[i1]
|
||||
u*axe1[i2] + v*axe2[i2] = vecproj[i2]
|
||||
|
||||
sustitute:
|
||||
v = (vecproj[i2] - u*axe1[i2])/axe2[i2]
|
||||
|
||||
then the first equation in terms of 'u':
|
||||
|
||||
--> u*axe1[i1] + ((vecproj[i2] - u*axe1[i2])/axe2[i2])*axe2[i1] = vecproj[i1]
|
||||
|
||||
--> u*axe1[i1] + vecproj[i2]*axe2[i1]/axe2[i2] - u*axe1[i2]*axe2[i1]/axe2[i2] = vecproj[i1]
|
||||
|
||||
--> u*(axe1[i1] - axe1[i2]*axe2[i1]/axe2[i2]) = vecproj[i1] - vecproj[i2]*axe2[i1]/axe2[i2]
|
||||
|
||||
--> u*((axe1[i1]*axe2[i2] - axe1[i2]*axe2[i1])/axe2[i2]) = (vecproj[i1]*axe2[i2] - vecproj[i2]*axe2[i1])/axe2[i2]
|
||||
|
||||
--> u*(axe1[i1]*axe2[i2] - axe1[i2]*axe2[i1]) = vecproj[i1]*axe2[i2] - vecproj[i2]*axe2[i1]
|
||||
|
||||
--> u = (vecproj[i1]*axe2[i2] - vecproj[i2]*axe2[i1]) /(axe1[i1]*axe2[i2] - axe1[i2]*axe2[i1])
|
||||
|
||||
if 0.0<= u+v <=1.0 then they are inside of triangle
|
||||
|
||||
\return false if the point is outside of triangle.This function doesn't take the margin
|
||||
*/
|
||||
SIMD_FORCE_INLINE bool get_uv_parameters(
|
||||
const btVector3 & point,
|
||||
const btVector3 & tri_plane,
|
||||
GREAL & u, GREAL & v) const
|
||||
{
|
||||
btVector3 _axe1 = m_vertices[1]-m_vertices[0];
|
||||
btVector3 _axe2 = m_vertices[2]-m_vertices[0];
|
||||
btVector3 _vecproj = point - m_vertices[0];
|
||||
GUINT _i1 = (tri_plane.closestAxis()+1)%3;
|
||||
GUINT _i2 = (_i1+1)%3;
|
||||
if(btFabs(_axe2[_i2])<G_EPSILON)
|
||||
{
|
||||
u = (_vecproj[_i2]*_axe2[_i1] - _vecproj[_i1]*_axe2[_i2]) /(_axe1[_i2]*_axe2[_i1] - _axe1[_i1]*_axe2[_i2]);
|
||||
v = (_vecproj[_i1] - u*_axe1[_i1])/_axe2[_i1];
|
||||
}
|
||||
else
|
||||
{
|
||||
u = (_vecproj[_i1]*_axe2[_i2] - _vecproj[_i2]*_axe2[_i1]) /(_axe1[_i1]*_axe2[_i2] - _axe1[_i2]*_axe2[_i1]);
|
||||
v = (_vecproj[_i2] - u*_axe1[_i2])/_axe2[_i2];
|
||||
}
|
||||
|
||||
if(u<-G_EPSILON)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if(v<-G_EPSILON)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
float sumuv;
|
||||
sumuv = u+v;
|
||||
if(sumuv<-G_EPSILON)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if(sumuv-1.0f>G_EPSILON)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//! is point in triangle beam?
|
||||
/*!
|
||||
Test if point is in triangle, with m_margin tolerance
|
||||
*/
|
||||
SIMD_FORCE_INLINE bool is_point_inside(const btVector3 & point, const btVector3 & tri_normal) const
|
||||
{
|
||||
//Test with edge 0
|
||||
btVector4 edge_plane;
|
||||
this->get_edge_plane(0,tri_normal,edge_plane);
|
||||
GREAL dist = DISTANCE_PLANE_POINT(edge_plane,point);
|
||||
if(dist-m_margin>0.0f) return false; // outside plane
|
||||
|
||||
this->get_edge_plane(1,tri_normal,edge_plane);
|
||||
dist = DISTANCE_PLANE_POINT(edge_plane,point);
|
||||
if(dist-m_margin>0.0f) return false; // outside plane
|
||||
|
||||
this->get_edge_plane(2,tri_normal,edge_plane);
|
||||
dist = DISTANCE_PLANE_POINT(edge_plane,point);
|
||||
if(dist-m_margin>0.0f) return false; // outside plane
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//! Bidireccional ray collision
|
||||
SIMD_FORCE_INLINE bool ray_collision(
|
||||
const btVector3 & vPoint,
|
||||
const btVector3 & vDir, btVector3 & pout, btVector3 & triangle_normal,
|
||||
GREAL & tparam, GREAL tmax = G_REAL_INFINITY)
|
||||
{
|
||||
btVector4 faceplane;
|
||||
{
|
||||
btVector3 dif1 = m_vertices[1] - m_vertices[0];
|
||||
btVector3 dif2 = m_vertices[2] - m_vertices[0];
|
||||
VEC_CROSS(faceplane,dif1,dif2);
|
||||
faceplane[3] = m_vertices[0].dot(faceplane);
|
||||
}
|
||||
|
||||
GUINT res = LINE_PLANE_COLLISION(faceplane,vDir,vPoint,pout,tparam, btScalar(0), tmax);
|
||||
if(res == 0) return false;
|
||||
if(! is_point_inside(pout,faceplane)) return false;
|
||||
|
||||
if(res==2) //invert normal
|
||||
{
|
||||
triangle_normal.setValue(-faceplane[0],-faceplane[1],-faceplane[2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
triangle_normal.setValue(faceplane[0],faceplane[1],faceplane[2]);
|
||||
}
|
||||
|
||||
VEC_NORMALIZE(triangle_normal);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//! one direccion ray collision
|
||||
SIMD_FORCE_INLINE bool ray_collision_front_side(
|
||||
const btVector3 & vPoint,
|
||||
const btVector3 & vDir, btVector3 & pout, btVector3 & triangle_normal,
|
||||
GREAL & tparam, GREAL tmax = G_REAL_INFINITY)
|
||||
{
|
||||
btVector4 faceplane;
|
||||
{
|
||||
btVector3 dif1 = m_vertices[1] - m_vertices[0];
|
||||
btVector3 dif2 = m_vertices[2] - m_vertices[0];
|
||||
VEC_CROSS(faceplane,dif1,dif2);
|
||||
faceplane[3] = m_vertices[0].dot(faceplane);
|
||||
}
|
||||
|
||||
GUINT res = LINE_PLANE_COLLISION(faceplane,vDir,vPoint,pout,tparam, btScalar(0), tmax);
|
||||
if(res != 1) return false;
|
||||
|
||||
if(!is_point_inside(pout,faceplane)) return false;
|
||||
|
||||
triangle_normal.setValue(faceplane[0],faceplane[1],faceplane[2]);
|
||||
|
||||
VEC_NORMALIZE(triangle_normal);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
//! @}
|
||||
|
||||
#endif // GIM_TRI_COLLISION_H_INCLUDED
|
||||
#ifndef GIM_TRI_COLLISION_H_INCLUDED
|
||||
#define GIM_TRI_COLLISION_H_INCLUDED
|
||||
|
||||
/*! \file gim_tri_collision.h
|
||||
\author Francisco Len Nßjera
|
||||
*/
|
||||
/*
|
||||
-----------------------------------------------------------------------------
|
||||
This source file is part of GIMPACT Library.
|
||||
|
||||
For the latest info, see http://gimpact.sourceforge.net/
|
||||
|
||||
Copyright (c) 2006 Francisco Leon Najera. 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.
|
||||
(3) The zlib/libpng license that is included with this library in
|
||||
the file GIMPACT-LICENSE-ZLIB.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, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "gim_box_collision.h"
|
||||
#include "gim_clip_polygon.h"
|
||||
|
||||
/*! \addtogroup GEOMETRIC_OPERATIONS
|
||||
*/
|
||||
//! @{
|
||||
|
||||
|
||||
|
||||
#define MAX_TRI_CLIPPING 16
|
||||
|
||||
//! Structure for collision
|
||||
struct GIM_TRIANGLE_CONTACT_DATA
|
||||
{
|
||||
GREAL m_penetration_depth;
|
||||
GUINT m_point_count;
|
||||
btVector4 m_separating_normal;
|
||||
btVector3 m_points[MAX_TRI_CLIPPING];
|
||||
|
||||
SIMD_FORCE_INLINE void copy_from(const GIM_TRIANGLE_CONTACT_DATA& other)
|
||||
{
|
||||
m_penetration_depth = other.m_penetration_depth;
|
||||
m_separating_normal = other.m_separating_normal;
|
||||
m_point_count = other.m_point_count;
|
||||
GUINT i = m_point_count;
|
||||
while(i--)
|
||||
{
|
||||
m_points[i] = other.m_points[i];
|
||||
}
|
||||
}
|
||||
|
||||
GIM_TRIANGLE_CONTACT_DATA()
|
||||
{
|
||||
}
|
||||
|
||||
GIM_TRIANGLE_CONTACT_DATA(const GIM_TRIANGLE_CONTACT_DATA& other)
|
||||
{
|
||||
copy_from(other);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//! classify points that are closer
|
||||
template<typename DISTANCE_FUNC,typename CLASS_PLANE>
|
||||
SIMD_FORCE_INLINE void mergepoints_generic(const CLASS_PLANE & plane,
|
||||
GREAL margin, const btVector3 * points, GUINT point_count, DISTANCE_FUNC distance_func)
|
||||
{
|
||||
m_point_count = 0;
|
||||
m_penetration_depth= -1000.0f;
|
||||
|
||||
GUINT point_indices[MAX_TRI_CLIPPING];
|
||||
|
||||
GUINT _k;
|
||||
|
||||
for(_k=0;_k<point_count;_k++)
|
||||
{
|
||||
GREAL _dist = -distance_func(plane,points[_k]) + margin;
|
||||
|
||||
if(_dist>=0.0f)
|
||||
{
|
||||
if(_dist>m_penetration_depth)
|
||||
{
|
||||
m_penetration_depth = _dist;
|
||||
point_indices[0] = _k;
|
||||
m_point_count=1;
|
||||
}
|
||||
else if((_dist+G_EPSILON)>=m_penetration_depth)
|
||||
{
|
||||
point_indices[m_point_count] = _k;
|
||||
m_point_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for( _k=0;_k<m_point_count;_k++)
|
||||
{
|
||||
m_points[_k] = points[point_indices[_k]];
|
||||
}
|
||||
}
|
||||
|
||||
//! classify points that are closer
|
||||
SIMD_FORCE_INLINE void merge_points(const btVector4 & plane, GREAL margin,
|
||||
const btVector3 * points, GUINT point_count)
|
||||
{
|
||||
m_separating_normal = plane;
|
||||
mergepoints_generic(plane, margin, points, point_count, DISTANCE_PLANE_3D_FUNC());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//! Class for colliding triangles
|
||||
class GIM_TRIANGLE
|
||||
{
|
||||
public:
|
||||
btScalar m_margin;
|
||||
btVector3 m_vertices[3];
|
||||
|
||||
GIM_TRIANGLE():m_margin(0.1f)
|
||||
{
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE GIM_AABB get_box() const
|
||||
{
|
||||
return GIM_AABB(m_vertices[0],m_vertices[1],m_vertices[2],m_margin);
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE void get_normal(btVector3 &normal) const
|
||||
{
|
||||
TRIANGLE_NORMAL(m_vertices[0],m_vertices[1],m_vertices[2],normal);
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE void get_plane(btVector4 &plane) const
|
||||
{
|
||||
TRIANGLE_PLANE(m_vertices[0],m_vertices[1],m_vertices[2],plane);;
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE void apply_transform(const btTransform & trans)
|
||||
{
|
||||
m_vertices[0] = trans(m_vertices[0]);
|
||||
m_vertices[1] = trans(m_vertices[1]);
|
||||
m_vertices[2] = trans(m_vertices[2]);
|
||||
}
|
||||
|
||||
SIMD_FORCE_INLINE void get_edge_plane(GUINT edge_index,const btVector3 &triangle_normal,btVector4 &plane) const
|
||||
{
|
||||
const btVector3 & e0 = m_vertices[edge_index];
|
||||
const btVector3 & e1 = m_vertices[(edge_index+1)%3];
|
||||
EDGE_PLANE(e0,e1,triangle_normal,plane);
|
||||
}
|
||||
|
||||
//! Gets the relative transformation of this triangle
|
||||
/*!
|
||||
The transformation is oriented to the triangle normal , and aligned to the 1st edge of this triangle. The position corresponds to vertice 0:
|
||||
- triangle normal corresponds to Z axis.
|
||||
- 1st normalized edge corresponds to X axis,
|
||||
|
||||
*/
|
||||
SIMD_FORCE_INLINE void get_triangle_transform(btTransform & triangle_transform) const
|
||||
{
|
||||
btMatrix3x3 & matrix = triangle_transform.getBasis();
|
||||
|
||||
btVector3 zaxis;
|
||||
get_normal(zaxis);
|
||||
MAT_SET_Z(matrix,zaxis);
|
||||
|
||||
btVector3 xaxis = m_vertices[1] - m_vertices[0];
|
||||
VEC_NORMALIZE(xaxis);
|
||||
MAT_SET_X(matrix,xaxis);
|
||||
|
||||
//y axis
|
||||
xaxis = zaxis.cross(xaxis);
|
||||
MAT_SET_Y(matrix,xaxis);
|
||||
|
||||
triangle_transform.setOrigin(m_vertices[0]);
|
||||
}
|
||||
|
||||
|
||||
//! Test triangles by finding separating axis
|
||||
/*!
|
||||
\param other Triangle for collide
|
||||
\param contact_data Structure for holding contact points, normal and penetration depth; The normal is pointing toward this triangle from the other triangle
|
||||
*/
|
||||
bool collide_triangle_hard_test(
|
||||
const GIM_TRIANGLE & other,
|
||||
GIM_TRIANGLE_CONTACT_DATA & contact_data) const;
|
||||
|
||||
//! Test boxes before doing hard test
|
||||
/*!
|
||||
\param other Triangle for collide
|
||||
\param contact_data Structure for holding contact points, normal and penetration depth; The normal is pointing toward this triangle from the other triangle
|
||||
\
|
||||
*/
|
||||
SIMD_FORCE_INLINE bool collide_triangle(
|
||||
const GIM_TRIANGLE & other,
|
||||
GIM_TRIANGLE_CONTACT_DATA & contact_data) const
|
||||
{
|
||||
//test box collisioin
|
||||
GIM_AABB boxu(m_vertices[0],m_vertices[1],m_vertices[2],m_margin);
|
||||
GIM_AABB boxv(other.m_vertices[0],other.m_vertices[1],other.m_vertices[2],other.m_margin);
|
||||
if(!boxu.has_collision(boxv)) return false;
|
||||
|
||||
//do hard test
|
||||
return collide_triangle_hard_test(other,contact_data);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
Solve the System for u,v parameters:
|
||||
|
||||
u*axe1[i1] + v*axe2[i1] = vecproj[i1]
|
||||
u*axe1[i2] + v*axe2[i2] = vecproj[i2]
|
||||
|
||||
sustitute:
|
||||
v = (vecproj[i2] - u*axe1[i2])/axe2[i2]
|
||||
|
||||
then the first equation in terms of 'u':
|
||||
|
||||
--> u*axe1[i1] + ((vecproj[i2] - u*axe1[i2])/axe2[i2])*axe2[i1] = vecproj[i1]
|
||||
|
||||
--> u*axe1[i1] + vecproj[i2]*axe2[i1]/axe2[i2] - u*axe1[i2]*axe2[i1]/axe2[i2] = vecproj[i1]
|
||||
|
||||
--> u*(axe1[i1] - axe1[i2]*axe2[i1]/axe2[i2]) = vecproj[i1] - vecproj[i2]*axe2[i1]/axe2[i2]
|
||||
|
||||
--> u*((axe1[i1]*axe2[i2] - axe1[i2]*axe2[i1])/axe2[i2]) = (vecproj[i1]*axe2[i2] - vecproj[i2]*axe2[i1])/axe2[i2]
|
||||
|
||||
--> u*(axe1[i1]*axe2[i2] - axe1[i2]*axe2[i1]) = vecproj[i1]*axe2[i2] - vecproj[i2]*axe2[i1]
|
||||
|
||||
--> u = (vecproj[i1]*axe2[i2] - vecproj[i2]*axe2[i1]) /(axe1[i1]*axe2[i2] - axe1[i2]*axe2[i1])
|
||||
|
||||
if 0.0<= u+v <=1.0 then they are inside of triangle
|
||||
|
||||
\return false if the point is outside of triangle.This function doesn't take the margin
|
||||
*/
|
||||
SIMD_FORCE_INLINE bool get_uv_parameters(
|
||||
const btVector3 & point,
|
||||
const btVector3 & tri_plane,
|
||||
GREAL & u, GREAL & v) const
|
||||
{
|
||||
btVector3 _axe1 = m_vertices[1]-m_vertices[0];
|
||||
btVector3 _axe2 = m_vertices[2]-m_vertices[0];
|
||||
btVector3 _vecproj = point - m_vertices[0];
|
||||
GUINT _i1 = (tri_plane.closestAxis()+1)%3;
|
||||
GUINT _i2 = (_i1+1)%3;
|
||||
if(btFabs(_axe2[_i2])<G_EPSILON)
|
||||
{
|
||||
u = (_vecproj[_i2]*_axe2[_i1] - _vecproj[_i1]*_axe2[_i2]) /(_axe1[_i2]*_axe2[_i1] - _axe1[_i1]*_axe2[_i2]);
|
||||
v = (_vecproj[_i1] - u*_axe1[_i1])/_axe2[_i1];
|
||||
}
|
||||
else
|
||||
{
|
||||
u = (_vecproj[_i1]*_axe2[_i2] - _vecproj[_i2]*_axe2[_i1]) /(_axe1[_i1]*_axe2[_i2] - _axe1[_i2]*_axe2[_i1]);
|
||||
v = (_vecproj[_i2] - u*_axe1[_i2])/_axe2[_i2];
|
||||
}
|
||||
|
||||
if(u<-G_EPSILON)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if(v<-G_EPSILON)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
float sumuv;
|
||||
sumuv = u+v;
|
||||
if(sumuv<-G_EPSILON)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if(sumuv-1.0f>G_EPSILON)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//! is point in triangle beam?
|
||||
/*!
|
||||
Test if point is in triangle, with m_margin tolerance
|
||||
*/
|
||||
SIMD_FORCE_INLINE bool is_point_inside(const btVector3 & point, const btVector3 & tri_normal) const
|
||||
{
|
||||
//Test with edge 0
|
||||
btVector4 edge_plane;
|
||||
this->get_edge_plane(0,tri_normal,edge_plane);
|
||||
GREAL dist = DISTANCE_PLANE_POINT(edge_plane,point);
|
||||
if(dist-m_margin>0.0f) return false; // outside plane
|
||||
|
||||
this->get_edge_plane(1,tri_normal,edge_plane);
|
||||
dist = DISTANCE_PLANE_POINT(edge_plane,point);
|
||||
if(dist-m_margin>0.0f) return false; // outside plane
|
||||
|
||||
this->get_edge_plane(2,tri_normal,edge_plane);
|
||||
dist = DISTANCE_PLANE_POINT(edge_plane,point);
|
||||
if(dist-m_margin>0.0f) return false; // outside plane
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//! Bidireccional ray collision
|
||||
SIMD_FORCE_INLINE bool ray_collision(
|
||||
const btVector3 & vPoint,
|
||||
const btVector3 & vDir, btVector3 & pout, btVector3 & triangle_normal,
|
||||
GREAL & tparam, GREAL tmax = G_REAL_INFINITY)
|
||||
{
|
||||
btVector4 faceplane;
|
||||
{
|
||||
btVector3 dif1 = m_vertices[1] - m_vertices[0];
|
||||
btVector3 dif2 = m_vertices[2] - m_vertices[0];
|
||||
VEC_CROSS(faceplane,dif1,dif2);
|
||||
faceplane[3] = m_vertices[0].dot(faceplane);
|
||||
}
|
||||
|
||||
GUINT res = LINE_PLANE_COLLISION(faceplane,vDir,vPoint,pout,tparam, btScalar(0), tmax);
|
||||
if(res == 0) return false;
|
||||
if(! is_point_inside(pout,faceplane)) return false;
|
||||
|
||||
if(res==2) //invert normal
|
||||
{
|
||||
triangle_normal.setValue(-faceplane[0],-faceplane[1],-faceplane[2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
triangle_normal.setValue(faceplane[0],faceplane[1],faceplane[2]);
|
||||
}
|
||||
|
||||
VEC_NORMALIZE(triangle_normal);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//! one direccion ray collision
|
||||
SIMD_FORCE_INLINE bool ray_collision_front_side(
|
||||
const btVector3 & vPoint,
|
||||
const btVector3 & vDir, btVector3 & pout, btVector3 & triangle_normal,
|
||||
GREAL & tparam, GREAL tmax = G_REAL_INFINITY)
|
||||
{
|
||||
btVector4 faceplane;
|
||||
{
|
||||
btVector3 dif1 = m_vertices[1] - m_vertices[0];
|
||||
btVector3 dif2 = m_vertices[2] - m_vertices[0];
|
||||
VEC_CROSS(faceplane,dif1,dif2);
|
||||
faceplane[3] = m_vertices[0].dot(faceplane);
|
||||
}
|
||||
|
||||
GUINT res = LINE_PLANE_COLLISION(faceplane,vDir,vPoint,pout,tparam, btScalar(0), tmax);
|
||||
if(res != 1) return false;
|
||||
|
||||
if(!is_point_inside(pout,faceplane)) return false;
|
||||
|
||||
triangle_normal.setValue(faceplane[0],faceplane[1],faceplane[2]);
|
||||
|
||||
VEC_NORMALIZE(triangle_normal);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
//! @}
|
||||
|
||||
#endif // GIM_TRI_COLLISION_H_INCLUDED
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user