moved Extras/Gimpact to src/BulletCollision/Gimpact

moved Extras/BulletMultiThreaded to src/BulletMultiThreaded
(build systems will be updated soon)
This commit is contained in:
erwin.coumans
2008-10-10 19:48:36 +00:00
parent 6f6f88fa08
commit 512c0f167e
111 changed files with 10811 additions and 11799 deletions

View File

@@ -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
)

View File

@@ -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

View File

@@ -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.

View File

@@ -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!

View File

@@ -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.

View File

@@ -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 ;

View File

@@ -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

View File

@@ -1,4 +0,0 @@
SubDir TOP Extras GIMPACT include ;
Recurse InstallHeader : .h ;

View File

@@ -2,7 +2,7 @@
#define BT_BOX_COLLISION_H_INCLUDED #define BT_BOX_COLLISION_H_INCLUDED
/*! \file gim_box_collision.h /*! \file gim_box_collision.h
\author Francisco León Nájera \author Francisco Len Nßjera
*/ */
/* /*
This source file is part of GIMPACT Library. This source file is part of GIMPACT Library.

View File

@@ -2,7 +2,7 @@
#define BT_CLIP_POLYGON_H_INCLUDED #define BT_CLIP_POLYGON_H_INCLUDED
/*! \file btClipPolygon.h /*! \file btClipPolygon.h
\author Francisco León Nájera \author Francisco Len Nßjera
*/ */
/* /*
This source file is part of GIMPACT Library. This source file is part of GIMPACT Library.

View File

@@ -1,181 +1,181 @@
/* /*
This source file is part of GIMPACT Library. This source file is part of GIMPACT Library.
For the latest info, see http://gimpact.sourceforge.net/ For the latest info, see http://gimpact.sourceforge.net/
Copyright (c) 2007 Francisco Leon Najera. C.C. 80087371. Copyright (c) 2007 Francisco Leon Najera. C.C. 80087371.
email: projectileman@yahoo.com email: projectileman@yahoo.com
This software is provided 'as-is', without any express or implied warranty. 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. 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, Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely, including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions: 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. 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. 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. 3. This notice may not be removed or altered from any source distribution.
*/ */
#include "GIMPACT/Bullet/btContactProcessing.h" #include "btContactProcessing.h"
#define MAX_COINCIDENT 8 #define MAX_COINCIDENT 8
struct CONTACT_KEY_TOKEN struct CONTACT_KEY_TOKEN
{ {
unsigned int m_key; unsigned int m_key;
int m_value; int m_value;
CONTACT_KEY_TOKEN() CONTACT_KEY_TOKEN()
{ {
} }
CONTACT_KEY_TOKEN(unsigned int key,int token) CONTACT_KEY_TOKEN(unsigned int key,int token)
{ {
m_key = key; m_key = key;
m_value = token; m_value = token;
} }
CONTACT_KEY_TOKEN(const CONTACT_KEY_TOKEN& rtoken) CONTACT_KEY_TOKEN(const CONTACT_KEY_TOKEN& rtoken)
{ {
m_key = rtoken.m_key; m_key = rtoken.m_key;
m_value = rtoken.m_value; m_value = rtoken.m_value;
} }
inline bool operator <(const CONTACT_KEY_TOKEN& other) const inline bool operator <(const CONTACT_KEY_TOKEN& other) const
{ {
return (m_key < other.m_key); return (m_key < other.m_key);
} }
inline bool operator >(const CONTACT_KEY_TOKEN& other) const inline bool operator >(const CONTACT_KEY_TOKEN& other) const
{ {
return (m_key > other.m_key); return (m_key > other.m_key);
} }
}; };
class CONTACT_KEY_TOKEN_COMP class CONTACT_KEY_TOKEN_COMP
{ {
public: public:
bool operator() ( const CONTACT_KEY_TOKEN& a, const CONTACT_KEY_TOKEN& b ) bool operator() ( const CONTACT_KEY_TOKEN& a, const CONTACT_KEY_TOKEN& b )
{ {
return ( a < b ); return ( a < b );
} }
}; };
void btContactArray::merge_contacts( void btContactArray::merge_contacts(
const btContactArray & contacts, bool normal_contact_average) const btContactArray & contacts, bool normal_contact_average)
{ {
clear(); clear();
int i; int i;
if(contacts.size()==0) return; if(contacts.size()==0) return;
if(contacts.size()==1) if(contacts.size()==1)
{ {
push_back(contacts[0]); push_back(contacts[0]);
return; return;
} }
btAlignedObjectArray<CONTACT_KEY_TOKEN> keycontacts; btAlignedObjectArray<CONTACT_KEY_TOKEN> keycontacts;
keycontacts.reserve(contacts.size()); keycontacts.reserve(contacts.size());
//fill key contacts //fill key contacts
for ( i = 0;i<contacts.size() ;i++ ) for ( i = 0;i<contacts.size() ;i++ )
{ {
keycontacts.push_back(CONTACT_KEY_TOKEN(contacts[i].calc_key_contact(),i)); keycontacts.push_back(CONTACT_KEY_TOKEN(contacts[i].calc_key_contact(),i));
} }
//sort keys //sort keys
keycontacts.quickSort(CONTACT_KEY_TOKEN_COMP()); keycontacts.quickSort(CONTACT_KEY_TOKEN_COMP());
// Merge contacts // Merge contacts
int coincident_count=0; int coincident_count=0;
btVector3 coincident_normals[MAX_COINCIDENT]; btVector3 coincident_normals[MAX_COINCIDENT];
unsigned int last_key = keycontacts[0].m_key; unsigned int last_key = keycontacts[0].m_key;
unsigned int key = 0; unsigned int key = 0;
push_back(contacts[keycontacts[0].m_value]); push_back(contacts[keycontacts[0].m_value]);
BT_CONTACT * pcontact = &(*this)[0]; BT_CONTACT * pcontact = &(*this)[0];
for( i=1;i<keycontacts.size();i++) for( i=1;i<keycontacts.size();i++)
{ {
key = keycontacts[i].m_key; key = keycontacts[i].m_key;
const BT_CONTACT * scontact = &contacts[keycontacts[i].m_value]; const BT_CONTACT * scontact = &contacts[keycontacts[i].m_value];
if(last_key == key)//same points if(last_key == key)//same points
{ {
//merge contact //merge contact
if(pcontact->m_depth - CONTACT_DIFF_EPSILON > scontact->m_depth)//) if(pcontact->m_depth - CONTACT_DIFF_EPSILON > scontact->m_depth)//)
{ {
*pcontact = *scontact; *pcontact = *scontact;
coincident_count = 0; coincident_count = 0;
} }
else if(normal_contact_average) else if(normal_contact_average)
{ {
if(btFabs(pcontact->m_depth - scontact->m_depth)<CONTACT_DIFF_EPSILON) if(btFabs(pcontact->m_depth - scontact->m_depth)<CONTACT_DIFF_EPSILON)
{ {
if(coincident_count<MAX_COINCIDENT) if(coincident_count<MAX_COINCIDENT)
{ {
coincident_normals[coincident_count] = scontact->m_normal; coincident_normals[coincident_count] = scontact->m_normal;
coincident_count++; coincident_count++;
} }
} }
} }
} }
else else
{//add new contact {//add new contact
if(normal_contact_average && coincident_count>0) if(normal_contact_average && coincident_count>0)
{ {
pcontact->interpolate_normals(coincident_normals,coincident_count); pcontact->interpolate_normals(coincident_normals,coincident_count);
coincident_count = 0; coincident_count = 0;
} }
push_back(*scontact); push_back(*scontact);
pcontact = &(*this)[this->size()-1]; pcontact = &(*this)[this->size()-1];
} }
last_key = key; last_key = key;
} }
} }
void btContactArray::merge_contacts_unique(const btContactArray & contacts) void btContactArray::merge_contacts_unique(const btContactArray & contacts)
{ {
clear(); clear();
if(contacts.size()==0) return; if(contacts.size()==0) return;
if(contacts.size()==1) if(contacts.size()==1)
{ {
push_back(contacts[0]); push_back(contacts[0]);
return; return;
} }
BT_CONTACT average_contact = contacts[0]; BT_CONTACT average_contact = contacts[0];
for (int i=1;i<contacts.size() ;i++ ) for (int i=1;i<contacts.size() ;i++ )
{ {
average_contact.m_point += contacts[i].m_point; average_contact.m_point += contacts[i].m_point;
average_contact.m_normal += contacts[i].m_normal * contacts[i].m_depth; average_contact.m_normal += contacts[i].m_normal * contacts[i].m_depth;
} }
//divide //divide
btScalar divide_average = 1.0f/((btScalar)contacts.size()); btScalar divide_average = 1.0f/((btScalar)contacts.size());
average_contact.m_point *= divide_average; average_contact.m_point *= divide_average;
average_contact.m_normal *= divide_average; average_contact.m_normal *= divide_average;
average_contact.m_depth = average_contact.m_normal.length(); average_contact.m_depth = average_contact.m_normal.length();
average_contact.m_normal /= average_contact.m_depth; average_contact.m_normal /= average_contact.m_depth;
} }

View File

@@ -2,7 +2,7 @@
#define BT_CONTACT_H_INCLUDED #define BT_CONTACT_H_INCLUDED
/*! \file gim_contact.h /*! \file gim_contact.h
\author Francisco León Nájera \author Francisco Len Nßjera
*/ */
/* /*
This source file is part of GIMPACT Library. This source file is part of GIMPACT Library.
@@ -26,7 +26,7 @@ subject to the following restrictions:
#include "LinearMath/btTransform.h" #include "LinearMath/btTransform.h"
#include "LinearMath/btAlignedObjectArray.h" #include "LinearMath/btAlignedObjectArray.h"
#include "GIMPACT/Bullet/btTriangleShapeEx.h" #include "btTriangleShapeEx.h"
/*! \defgroup CONTACTS /*! \defgroup CONTACTS

View File

@@ -1,5 +1,5 @@
/*! \file gim_box_set.h /*! \file gim_box_set.h
\author Francisco León Nájera \author Francisco Len Nßjera
*/ */
/* /*
This source file is part of GIMPACT Library. 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. 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. 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" #include "LinearMath/btQuickprof.h"
#ifdef TRI_COLLISION_PROFILING #ifdef TRI_COLLISION_PROFILING

View File

@@ -2,7 +2,7 @@
#define GIM_BOX_SET_H_INCLUDED #define GIM_BOX_SET_H_INCLUDED
/*! \file gim_box_set.h /*! \file gim_box_set.h
\author Francisco León Nájera \author Francisco Len Nßjera
*/ */
/* /*
This source file is part of GIMPACT Library. This source file is part of GIMPACT Library.
@@ -27,8 +27,8 @@ subject to the following restrictions:
#include "LinearMath/btAlignedObjectArray.h" #include "LinearMath/btAlignedObjectArray.h"
#include "GIMPACT/Bullet/btBoxCollision.h" #include "btBoxCollision.h"
#include "GIMPACT/Bullet/btTriangleShapeEx.h" #include "btTriangleShapeEx.h"

View File

@@ -1,306 +1,306 @@
/*! \file btGImpactShape.h /*! \file btGImpactShape.h
\author Francisco León Nájera \author Francisco Len Nßjera
*/ */
/* /*
This source file is part of GIMPACT Library. This source file is part of GIMPACT Library.
For the latest info, see http://gimpact.sourceforge.net/ For the latest info, see http://gimpact.sourceforge.net/
Copyright (c) 2007 Francisco Leon Najera. C.C. 80087371. Copyright (c) 2007 Francisco Leon Najera. C.C. 80087371.
email: projectileman@yahoo.com email: projectileman@yahoo.com
This software is provided 'as-is', without any express or implied warranty. 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. 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, Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely, including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions: 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. 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. 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. 3. This notice may not be removed or altered from any source distribution.
*/ */
#ifndef BVH_CONCAVE_COLLISION_ALGORITHM_H #ifndef BVH_CONCAVE_COLLISION_ALGORITHM_H
#define BVH_CONCAVE_COLLISION_ALGORITHM_H #define BVH_CONCAVE_COLLISION_ALGORITHM_H
#include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h" #include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h"
#include "BulletCollision/BroadphaseCollision/btDispatcher.h" #include "BulletCollision/BroadphaseCollision/btDispatcher.h"
#include "BulletCollision/BroadphaseCollision/btBroadphaseInterface.h" #include "BulletCollision/BroadphaseCollision/btBroadphaseInterface.h"
#include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h" #include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
class btDispatcher; class btDispatcher;
#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
#include "BulletCollision/CollisionDispatch/btCollisionCreateFunc.h" #include "BulletCollision/CollisionDispatch/btCollisionCreateFunc.h"
#include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h" #include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h"
#include "LinearMath/btAlignedObjectArray.h" #include "LinearMath/btAlignedObjectArray.h"
#include "GIMPACT/Bullet/btGImpactShape.h" #include "btGImpactShape.h"
#include "BulletCollision/CollisionShapes/btStaticPlaneShape.h" #include "BulletCollision/CollisionShapes/btStaticPlaneShape.h"
#include "BulletCollision/CollisionShapes/btCompoundShape.h" #include "BulletCollision/CollisionShapes/btCompoundShape.h"
#include "BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h" #include "BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h"
#include "LinearMath/btIDebugDraw.h" #include "LinearMath/btIDebugDraw.h"
//! Collision Algorithm for GImpact Shapes //! Collision Algorithm for GImpact Shapes
/*! /*!
For register this algorithm in Bullet, proceed as following: For register this algorithm in Bullet, proceed as following:
\code \code
btCollisionDispatcher * dispatcher = static_cast<btCollisionDispatcher *>(m_dynamicsWorld ->getDispatcher()); btCollisionDispatcher * dispatcher = static_cast<btCollisionDispatcher *>(m_dynamicsWorld ->getDispatcher());
btGImpactCollisionAlgorithm::registerAlgorithm(dispatcher); btGImpactCollisionAlgorithm::registerAlgorithm(dispatcher);
\endcode \endcode
*/ */
class btGImpactCollisionAlgorithm : public btCollisionAlgorithm class btGImpactCollisionAlgorithm : public btCollisionAlgorithm
{ {
protected: protected:
btCollisionAlgorithm * m_convex_algorithm; btCollisionAlgorithm * m_convex_algorithm;
btPersistentManifold * m_manifoldPtr; btPersistentManifold * m_manifoldPtr;
btManifoldResult* m_resultOut; btManifoldResult* m_resultOut;
const btDispatcherInfo * m_dispatchInfo; const btDispatcherInfo * m_dispatchInfo;
int m_triface0; int m_triface0;
int m_part0; int m_part0;
int m_triface1; int m_triface1;
int m_part1; int m_part1;
//! Creates a new contact point //! Creates a new contact point
SIMD_FORCE_INLINE btPersistentManifold* newContactManifold(btCollisionObject* body0,btCollisionObject* body1) SIMD_FORCE_INLINE btPersistentManifold* newContactManifold(btCollisionObject* body0,btCollisionObject* body1)
{ {
m_manifoldPtr = m_dispatcher->getNewManifold(body0,body1); m_manifoldPtr = m_dispatcher->getNewManifold(body0,body1);
return m_manifoldPtr; return m_manifoldPtr;
} }
SIMD_FORCE_INLINE void destroyConvexAlgorithm() SIMD_FORCE_INLINE void destroyConvexAlgorithm()
{ {
if(m_convex_algorithm) if(m_convex_algorithm)
{ {
m_convex_algorithm->~btCollisionAlgorithm(); m_convex_algorithm->~btCollisionAlgorithm();
m_dispatcher->freeCollisionAlgorithm( m_convex_algorithm); m_dispatcher->freeCollisionAlgorithm( m_convex_algorithm);
m_convex_algorithm = NULL; m_convex_algorithm = NULL;
} }
} }
SIMD_FORCE_INLINE void destroyContactManifolds() SIMD_FORCE_INLINE void destroyContactManifolds()
{ {
if(m_manifoldPtr == NULL) return; if(m_manifoldPtr == NULL) return;
m_dispatcher->releaseManifold(m_manifoldPtr); m_dispatcher->releaseManifold(m_manifoldPtr);
m_manifoldPtr = NULL; m_manifoldPtr = NULL;
} }
SIMD_FORCE_INLINE void clearCache() SIMD_FORCE_INLINE void clearCache()
{ {
destroyContactManifolds(); destroyContactManifolds();
destroyConvexAlgorithm(); destroyConvexAlgorithm();
m_triface0 = -1; m_triface0 = -1;
m_part0 = -1; m_part0 = -1;
m_triface1 = -1; m_triface1 = -1;
m_part1 = -1; m_part1 = -1;
} }
SIMD_FORCE_INLINE btPersistentManifold* getLastManifold() SIMD_FORCE_INLINE btPersistentManifold* getLastManifold()
{ {
return m_manifoldPtr; return m_manifoldPtr;
} }
// Call before process collision // Call before process collision
SIMD_FORCE_INLINE void checkManifold(btCollisionObject* body0,btCollisionObject* body1) SIMD_FORCE_INLINE void checkManifold(btCollisionObject* body0,btCollisionObject* body1)
{ {
if(getLastManifold() == 0) if(getLastManifold() == 0)
{ {
newContactManifold(body0,body1); newContactManifold(body0,body1);
} }
m_resultOut->setPersistentManifold(getLastManifold()); m_resultOut->setPersistentManifold(getLastManifold());
} }
// Call before process collision // Call before process collision
SIMD_FORCE_INLINE btCollisionAlgorithm * newAlgorithm(btCollisionObject* body0,btCollisionObject* body1) SIMD_FORCE_INLINE btCollisionAlgorithm * newAlgorithm(btCollisionObject* body0,btCollisionObject* body1)
{ {
checkManifold(body0,body1); checkManifold(body0,body1);
btCollisionAlgorithm * convex_algorithm = m_dispatcher->findAlgorithm( btCollisionAlgorithm * convex_algorithm = m_dispatcher->findAlgorithm(
body0,body1,getLastManifold()); body0,body1,getLastManifold());
return convex_algorithm ; return convex_algorithm ;
} }
// Call before process collision // Call before process collision
SIMD_FORCE_INLINE void checkConvexAlgorithm(btCollisionObject* body0,btCollisionObject* body1) SIMD_FORCE_INLINE void checkConvexAlgorithm(btCollisionObject* body0,btCollisionObject* body1)
{ {
if(m_convex_algorithm) return; if(m_convex_algorithm) return;
m_convex_algorithm = newAlgorithm(body0,body1); m_convex_algorithm = newAlgorithm(body0,body1);
} }
void addContactPoint(btCollisionObject * body0, void addContactPoint(btCollisionObject * body0,
btCollisionObject * body1, btCollisionObject * body1,
const btVector3 & point, const btVector3 & point,
const btVector3 & normal, const btVector3 & normal,
btScalar distance); btScalar distance);
//! Collision routines //! Collision routines
//!@{ //!@{
void collide_gjk_triangles(btCollisionObject * body0, void collide_gjk_triangles(btCollisionObject * body0,
btCollisionObject * body1, btCollisionObject * body1,
btGImpactMeshShapePart * shape0, btGImpactMeshShapePart * shape0,
btGImpactMeshShapePart * shape1, btGImpactMeshShapePart * shape1,
const int * pairs, int pair_count); const int * pairs, int pair_count);
void collide_sat_triangles(btCollisionObject * body0, void collide_sat_triangles(btCollisionObject * body0,
btCollisionObject * body1, btCollisionObject * body1,
btGImpactMeshShapePart * shape0, btGImpactMeshShapePart * shape0,
btGImpactMeshShapePart * shape1, btGImpactMeshShapePart * shape1,
const int * pairs, int pair_count); const int * pairs, int pair_count);
void shape_vs_shape_collision( void shape_vs_shape_collision(
btCollisionObject * body0, btCollisionObject * body0,
btCollisionObject * body1, btCollisionObject * body1,
btCollisionShape * shape0, btCollisionShape * shape0,
btCollisionShape * shape1); btCollisionShape * shape1);
void convex_vs_convex_collision(btCollisionObject * body0, void convex_vs_convex_collision(btCollisionObject * body0,
btCollisionObject * body1, btCollisionObject * body1,
btCollisionShape * shape0, btCollisionShape * shape0,
btCollisionShape * shape1); btCollisionShape * shape1);
void gimpact_vs_gimpact_find_pairs( void gimpact_vs_gimpact_find_pairs(
const btTransform & trans0, const btTransform & trans0,
const btTransform & trans1, const btTransform & trans1,
btGImpactShapeInterface * shape0, btGImpactShapeInterface * shape0,
btGImpactShapeInterface * shape1,btPairSet & pairset); btGImpactShapeInterface * shape1,btPairSet & pairset);
void gimpact_vs_shape_find_pairs( void gimpact_vs_shape_find_pairs(
const btTransform & trans0, const btTransform & trans0,
const btTransform & trans1, const btTransform & trans1,
btGImpactShapeInterface * shape0, btGImpactShapeInterface * shape0,
btCollisionShape * shape1, btCollisionShape * shape1,
btAlignedObjectArray<int> & collided_primitives); btAlignedObjectArray<int> & collided_primitives);
void gimpacttrimeshpart_vs_plane_collision( void gimpacttrimeshpart_vs_plane_collision(
btCollisionObject * body0, btCollisionObject * body0,
btCollisionObject * body1, btCollisionObject * body1,
btGImpactMeshShapePart * shape0, btGImpactMeshShapePart * shape0,
btStaticPlaneShape * shape1,bool swapped); btStaticPlaneShape * shape1,bool swapped);
public: public:
btGImpactCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1); btGImpactCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1);
virtual ~btGImpactCollisionAlgorithm(); virtual ~btGImpactCollisionAlgorithm();
virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut); virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
btScalar calculateTimeOfImpact(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) virtual void getAllContactManifolds(btManifoldArray& manifoldArray)
{ {
if (m_manifoldPtr) if (m_manifoldPtr)
manifoldArray.push_back(m_manifoldPtr); manifoldArray.push_back(m_manifoldPtr);
} }
struct CreateFunc :public btCollisionAlgorithmCreateFunc struct CreateFunc :public btCollisionAlgorithmCreateFunc
{ {
virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1) virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
{ {
void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btGImpactCollisionAlgorithm)); void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btGImpactCollisionAlgorithm));
return new(mem) btGImpactCollisionAlgorithm(ci,body0,body1); return new(mem) btGImpactCollisionAlgorithm(ci,body0,body1);
} }
}; };
//! Use this function for register the algorithm externally //! Use this function for register the algorithm externally
static void registerAlgorithm(btCollisionDispatcher * dispatcher); static void registerAlgorithm(btCollisionDispatcher * dispatcher);
//! Gets the average time in miliseconds of tree collisions //! Gets the average time in miliseconds of tree collisions
static float getAverageTreeCollisionTime(); static float getAverageTreeCollisionTime();
//! Gets the average time in miliseconds of triangle collisions //! Gets the average time in miliseconds of triangle collisions
static float getAverageTriangleCollisionTime(); static float getAverageTriangleCollisionTime();
//! Collides two gimpact shapes //! Collides two gimpact shapes
/*! /*!
\pre shape0 and shape1 couldn't be btGImpactMeshShape objects \pre shape0 and shape1 couldn't be btGImpactMeshShape objects
*/ */
void gimpact_vs_gimpact(btCollisionObject * body0, void gimpact_vs_gimpact(btCollisionObject * body0,
btCollisionObject * body1, btCollisionObject * body1,
btGImpactShapeInterface * shape0, btGImpactShapeInterface * shape0,
btGImpactShapeInterface * shape1); btGImpactShapeInterface * shape1);
void gimpact_vs_shape(btCollisionObject * body0, void gimpact_vs_shape(btCollisionObject * body0,
btCollisionObject * body1, btCollisionObject * body1,
btGImpactShapeInterface * shape0, btGImpactShapeInterface * shape0,
btCollisionShape * shape1,bool swapped); btCollisionShape * shape1,bool swapped);
void gimpact_vs_compoundshape(btCollisionObject * body0, void gimpact_vs_compoundshape(btCollisionObject * body0,
btCollisionObject * body1, btCollisionObject * body1,
btGImpactShapeInterface * shape0, btGImpactShapeInterface * shape0,
btCompoundShape * shape1,bool swapped); btCompoundShape * shape1,bool swapped);
void gimpact_vs_concave( void gimpact_vs_concave(
btCollisionObject * body0, btCollisionObject * body0,
btCollisionObject * body1, btCollisionObject * body1,
btGImpactShapeInterface * shape0, btGImpactShapeInterface * shape0,
btConcaveShape * shape1,bool swapped); btConcaveShape * shape1,bool swapped);
/// Accessor/Mutator pairs for Part and triangleID /// Accessor/Mutator pairs for Part and triangleID
void setFace0(int value) void setFace0(int value)
{ {
m_triface0 = value; m_triface0 = value;
} }
int getFace0() int getFace0()
{ {
return m_triface0; return m_triface0;
} }
void setFace1(int value) void setFace1(int value)
{ {
m_triface1 = value; m_triface1 = value;
} }
int getFace1() int getFace1()
{ {
return m_triface1; return m_triface1;
} }
void setPart0(int value) void setPart0(int value)
{ {
m_part0 = value; m_part0 = value;
} }
int getPart0() int getPart0()
{ {
return m_part0; return m_part0;
} }
void setPart1(int value) void setPart1(int value)
{ {
m_part1 = value; m_part1 = value;
} }
int getPart1() int getPart1()
{ {
return m_part1; return m_part1;
} }
}; };
//algorithm details //algorithm details
//#define BULLET_TRIANGLE_COLLISION 1 //#define BULLET_TRIANGLE_COLLISION 1
#define GIMPACT_VS_PLANE_COLLISION 1 #define GIMPACT_VS_PLANE_COLLISION 1
#endif //BVH_CONCAVE_COLLISION_ALGORITHM_H #endif //BVH_CONCAVE_COLLISION_ALGORITHM_H

View File

@@ -1,60 +1,60 @@
/*! \file btGImpactMassUtil.h /*! \file btGImpactMassUtil.h
\author Francisco León Nájera \author Francisco Len Nßjera
*/ */
/* /*
This source file is part of GIMPACT Library. This source file is part of GIMPACT Library.
For the latest info, see http://gimpact.sourceforge.net/ For the latest info, see http://gimpact.sourceforge.net/
Copyright (c) 2007 Francisco Leon Najera. C.C. 80087371. Copyright (c) 2007 Francisco Leon Najera. C.C. 80087371.
email: projectileman@yahoo.com email: projectileman@yahoo.com
This software is provided 'as-is', without any express or implied warranty. 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. 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, Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely, including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions: 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. 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. 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. 3. This notice may not be removed or altered from any source distribution.
*/ */
#ifndef GIMPACT_MASS_UTIL_H #ifndef GIMPACT_MASS_UTIL_H
#define GIMPACT_MASS_UTIL_H #define GIMPACT_MASS_UTIL_H
#include "LinearMath/btTransform.h" #include "LinearMath/btTransform.h"
SIMD_FORCE_INLINE btVector3 gim_inertia_add_transformed( SIMD_FORCE_INLINE btVector3 gim_inertia_add_transformed(
const btVector3 & source_inertia, const btVector3 & added_inertia, const btTransform & transform) const btVector3 & source_inertia, const btVector3 & added_inertia, const btTransform & transform)
{ {
btMatrix3x3 rotatedTensor = transform.getBasis().scaled(added_inertia) * transform.getBasis().transpose(); btMatrix3x3 rotatedTensor = transform.getBasis().scaled(added_inertia) * transform.getBasis().transpose();
btScalar x2 = transform.getOrigin()[0]; btScalar x2 = transform.getOrigin()[0];
x2*= x2; x2*= x2;
btScalar y2 = transform.getOrigin()[1]; btScalar y2 = transform.getOrigin()[1];
y2*= y2; y2*= y2;
btScalar z2 = transform.getOrigin()[2]; btScalar z2 = transform.getOrigin()[2];
z2*= z2; z2*= z2;
btScalar ix = rotatedTensor[0][0]*(y2+z2); btScalar ix = rotatedTensor[0][0]*(y2+z2);
btScalar iy = rotatedTensor[1][1]*(x2+z2); btScalar iy = rotatedTensor[1][1]*(x2+z2);
btScalar iz = rotatedTensor[2][2]*(x2+y2); btScalar iz = rotatedTensor[2][2]*(x2+y2);
return btVector3(source_inertia[0]+ix,source_inertia[1]+iy,source_inertia[2] + iz); 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) SIMD_FORCE_INLINE btVector3 gim_get_point_inertia(const btVector3 & point, btScalar mass)
{ {
btScalar x2 = point[0]*point[0]; btScalar x2 = point[0]*point[0];
btScalar y2 = point[1]*point[1]; btScalar y2 = point[1]*point[1];
btScalar z2 = point[2]*point[2]; btScalar z2 = point[2]*point[2];
return btVector3(mass*(y2+z2),mass*(x2+z2),mass*(x2+y2)); return btVector3(mass*(y2+z2),mass*(x2+z2),mass*(x2+y2));
} }
#endif //GIMPACT_MESH_SHAPE_H #endif //GIMPACT_MESH_SHAPE_H

View File

@@ -1,5 +1,5 @@
/*! \file gim_box_set.h /*! \file gim_box_set.h
\author Francisco León Nájera \author Francisco Len Nßjera
*/ */
/* /*
This source file is part of GIMPACT Library. 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. 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" #include "LinearMath/btQuickprof.h"
#ifdef TRI_COLLISION_PROFILING #ifdef TRI_COLLISION_PROFILING

View File

@@ -2,7 +2,7 @@
#define GIM_QUANTIZED_SET_H_INCLUDED #define GIM_QUANTIZED_SET_H_INCLUDED
/*! \file btGImpactQuantizedBvh.h /*! \file btGImpactQuantizedBvh.h
\author Francisco León Nájera \author Francisco Len Nßjera
*/ */
/* /*
This source file is part of GIMPACT Library. 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. 3. This notice may not be removed or altered from any source distribution.
*/ */
#include "GIMPACT/Bullet/btGImpactBvh.h" #include "btGImpactBvh.h"
#include "GIMPACT/Bullet/btQuantization.h" #include "btQuantization.h"

View File

@@ -1,183 +1,183 @@
/* /*
This source file is part of GIMPACT Library. This source file is part of GIMPACT Library.
For the latest info, see http://gimpact.sourceforge.net/ For the latest info, see http://gimpact.sourceforge.net/
Copyright (c) 2007 Francisco Leon Najera. C.C. 80087371. Copyright (c) 2007 Francisco Leon Najera. C.C. 80087371.
email: projectileman@yahoo.com email: projectileman@yahoo.com
This software is provided 'as-is', without any express or implied warranty. 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. 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, Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely, including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions: 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. 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. 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. 3. This notice may not be removed or altered from any source distribution.
*/ */
#include "GIMPACT/Bullet/btGImpactShape.h" #include "btGImpactShape.h"
#include "GIMPACT/Bullet/btGImpactMassUtil.h" #include "btGImpactMassUtil.h"
#define CALC_EXACT_INERTIA 1 #define CALC_EXACT_INERTIA 1
void btGImpactCompoundShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const void btGImpactCompoundShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
{ {
lockChildShapes(); lockChildShapes();
#ifdef CALC_EXACT_INERTIA #ifdef CALC_EXACT_INERTIA
inertia.setValue(0.f,0.f,0.f); inertia.setValue(0.f,0.f,0.f);
int i = this->getNumChildShapes(); int i = this->getNumChildShapes();
btScalar shapemass = mass/btScalar(i); btScalar shapemass = mass/btScalar(i);
while(i--) while(i--)
{ {
btVector3 temp_inertia; btVector3 temp_inertia;
m_childShapes[i]->calculateLocalInertia(shapemass,temp_inertia); m_childShapes[i]->calculateLocalInertia(shapemass,temp_inertia);
if(childrenHasTransform()) if(childrenHasTransform())
{ {
inertia = gim_inertia_add_transformed( inertia,temp_inertia,m_childTransforms[i]); inertia = gim_inertia_add_transformed( inertia,temp_inertia,m_childTransforms[i]);
} }
else else
{ {
inertia = gim_inertia_add_transformed( inertia,temp_inertia,btTransform::getIdentity()); inertia = gim_inertia_add_transformed( inertia,temp_inertia,btTransform::getIdentity());
} }
} }
#else #else
// Calc box inertia // Calc box inertia
btScalar lx= m_localAABB.m_max[0] - m_localAABB.m_min[0]; 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 ly= m_localAABB.m_max[1] - m_localAABB.m_min[1];
btScalar lz= m_localAABB.m_max[2] - m_localAABB.m_min[2]; btScalar lz= m_localAABB.m_max[2] - m_localAABB.m_min[2];
const btScalar x2 = lx*lx; const btScalar x2 = lx*lx;
const btScalar y2 = ly*ly; const btScalar y2 = ly*ly;
const btScalar z2 = lz*lz; const btScalar z2 = lz*lz;
const btScalar scaledmass = mass * btScalar(0.08333333); const btScalar scaledmass = mass * btScalar(0.08333333);
inertia = scaledmass * (btVector3(y2+z2,x2+z2,x2+y2)); inertia = scaledmass * (btVector3(y2+z2,x2+z2,x2+y2));
#endif #endif
unlockChildShapes(); unlockChildShapes();
} }
void btGImpactMeshShapePart::calculateLocalInertia(btScalar mass,btVector3& inertia) const void btGImpactMeshShapePart::calculateLocalInertia(btScalar mass,btVector3& inertia) const
{ {
lockChildShapes(); lockChildShapes();
#ifdef CALC_EXACT_INERTIA #ifdef CALC_EXACT_INERTIA
inertia.setValue(0.f,0.f,0.f); inertia.setValue(0.f,0.f,0.f);
int i = this->getVertexCount(); int i = this->getVertexCount();
btScalar pointmass = mass/btScalar(i); btScalar pointmass = mass/btScalar(i);
while(i--) while(i--)
{ {
btVector3 pointintertia; btVector3 pointintertia;
this->getVertex(i,pointintertia); this->getVertex(i,pointintertia);
pointintertia = gim_get_point_inertia(pointintertia,pointmass); pointintertia = gim_get_point_inertia(pointintertia,pointmass);
inertia+=pointintertia; inertia+=pointintertia;
} }
#else #else
// Calc box inertia // Calc box inertia
btScalar lx= m_localAABB.m_max[0] - m_localAABB.m_min[0]; 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 ly= m_localAABB.m_max[1] - m_localAABB.m_min[1];
btScalar lz= m_localAABB.m_max[2] - m_localAABB.m_min[2]; btScalar lz= m_localAABB.m_max[2] - m_localAABB.m_min[2];
const btScalar x2 = lx*lx; const btScalar x2 = lx*lx;
const btScalar y2 = ly*ly; const btScalar y2 = ly*ly;
const btScalar z2 = lz*lz; const btScalar z2 = lz*lz;
const btScalar scaledmass = mass * btScalar(0.08333333); const btScalar scaledmass = mass * btScalar(0.08333333);
inertia = scaledmass * (btVector3(y2+z2,x2+z2,x2+y2)); inertia = scaledmass * (btVector3(y2+z2,x2+z2,x2+y2));
#endif #endif
unlockChildShapes(); unlockChildShapes();
} }
void btGImpactMeshShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const void btGImpactMeshShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
{ {
#ifdef CALC_EXACT_INERTIA #ifdef CALC_EXACT_INERTIA
inertia.setValue(0.f,0.f,0.f); inertia.setValue(0.f,0.f,0.f);
int i = this->getMeshPartCount(); int i = this->getMeshPartCount();
btScalar partmass = mass/btScalar(i); btScalar partmass = mass/btScalar(i);
while(i--) while(i--)
{ {
btVector3 partinertia; btVector3 partinertia;
getMeshPart(i)->calculateLocalInertia(partmass,partinertia); getMeshPart(i)->calculateLocalInertia(partmass,partinertia);
inertia+=partinertia; inertia+=partinertia;
} }
#else #else
// Calc box inertia // Calc box inertia
btScalar lx= m_localAABB.m_max[0] - m_localAABB.m_min[0]; 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 ly= m_localAABB.m_max[1] - m_localAABB.m_min[1];
btScalar lz= m_localAABB.m_max[2] - m_localAABB.m_min[2]; btScalar lz= m_localAABB.m_max[2] - m_localAABB.m_min[2];
const btScalar x2 = lx*lx; const btScalar x2 = lx*lx;
const btScalar y2 = ly*ly; const btScalar y2 = ly*ly;
const btScalar z2 = lz*lz; const btScalar z2 = lz*lz;
const btScalar scaledmass = mass * btScalar(0.08333333); const btScalar scaledmass = mass * btScalar(0.08333333);
inertia = scaledmass * (btVector3(y2+z2,x2+z2,x2+y2)); inertia = scaledmass * (btVector3(y2+z2,x2+z2,x2+y2));
#endif #endif
} }
void btGImpactMeshShape::rayTest(const btVector3& rayFrom, const btVector3& rayTo, btCollisionWorld::RayResultCallback& resultCallback) const 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 void btGImpactMeshShapePart::processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const
{ {
lockChildShapes(); lockChildShapes();
btAABB box; btAABB box;
box.m_min = aabbMin; box.m_min = aabbMin;
box.m_max = aabbMax; box.m_max = aabbMax;
btAlignedObjectArray<int> collided; btAlignedObjectArray<int> collided;
m_box_set.boxQuery(box,collided); m_box_set.boxQuery(box,collided);
if(collided.size()==0) if(collided.size()==0)
{ {
unlockChildShapes(); unlockChildShapes();
return; return;
} }
int part = (int)getPart(); int part = (int)getPart();
btPrimitiveTriangle triangle; btPrimitiveTriangle triangle;
int i = collided.size(); int i = collided.size();
while(i--) while(i--)
{ {
this->getPrimitiveTriangle(collided[i],triangle); this->getPrimitiveTriangle(collided[i],triangle);
callback->processTriangle(triangle.m_vertices,part,collided[i]); callback->processTriangle(triangle.m_vertices,part,collided[i]);
} }
unlockChildShapes(); unlockChildShapes();
} }
void btGImpactMeshShape::processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const void btGImpactMeshShape::processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const
{ {
int i = m_mesh_parts.size(); int i = m_mesh_parts.size();
while(i--) while(i--)
{ {
m_mesh_parts[i]->processAllTriangles(callback,aabbMin,aabbMax); m_mesh_parts[i]->processAllTriangles(callback,aabbMin,aabbMax);
} }
} }

File diff suppressed because it is too large Load Diff

View File

@@ -1,283 +1,283 @@
/*! \file btGenericPoolAllocator.cpp /*! \file btGenericPoolAllocator.cpp
\author Francisco León Nájera. email projectileman@yahoo.com \author Francisco Len Nßjera. email projectileman@yahoo.com
General purpose allocator class General purpose allocator class
*/ */
/* /*
Bullet Continuous Collision Detection and Physics Library Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty. 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. 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, Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely, including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions: 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. 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. 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. 3. This notice may not be removed or altered from any source distribution.
*/ */
#include "GIMPACT/Bullet/btGenericPoolAllocator.h" #include "btGenericPoolAllocator.h"
/// *************** btGenericMemoryPool ******************/////////// /// *************** btGenericMemoryPool ******************///////////
size_t btGenericMemoryPool::allocate_from_free_nodes(size_t num_elements) size_t btGenericMemoryPool::allocate_from_free_nodes(size_t num_elements)
{ {
size_t ptr = BT_UINT_MAX; size_t ptr = BT_UINT_MAX;
if(m_free_nodes_count == 0) return BT_UINT_MAX; if(m_free_nodes_count == 0) return BT_UINT_MAX;
// find an avaliable free node with the correct size // find an avaliable free node with the correct size
size_t revindex = m_free_nodes_count; size_t revindex = m_free_nodes_count;
while(revindex-- && ptr == BT_UINT_MAX) while(revindex-- && ptr == BT_UINT_MAX)
{ {
if(m_allocated_sizes[m_free_nodes[revindex]]>=num_elements) if(m_allocated_sizes[m_free_nodes[revindex]]>=num_elements)
{ {
ptr = revindex; ptr = revindex;
} }
} }
if(ptr == BT_UINT_MAX) return BT_UINT_MAX; // not found if(ptr == BT_UINT_MAX) return BT_UINT_MAX; // not found
revindex = ptr; revindex = ptr;
ptr = m_free_nodes[revindex]; ptr = m_free_nodes[revindex];
// post: ptr contains the node index, and revindex the index in m_free_nodes // post: ptr contains the node index, and revindex the index in m_free_nodes
size_t finalsize = m_allocated_sizes[ptr]; size_t finalsize = m_allocated_sizes[ptr];
finalsize -= num_elements; finalsize -= num_elements;
m_allocated_sizes[ptr] = num_elements; m_allocated_sizes[ptr] = num_elements;
// post: finalsize>=0, m_allocated_sizes[ptr] has the requested size // post: finalsize>=0, m_allocated_sizes[ptr] has the requested size
if(finalsize>0) // preserve free node, there are some free memory if(finalsize>0) // preserve free node, there are some free memory
{ {
m_free_nodes[revindex] = ptr + num_elements; m_free_nodes[revindex] = ptr + num_elements;
m_allocated_sizes[ptr + num_elements] = finalsize; m_allocated_sizes[ptr + num_elements] = finalsize;
} }
else // delete free node else // delete free node
{ {
// swap with end // swap with end
m_free_nodes[revindex] = m_free_nodes[m_free_nodes_count-1]; m_free_nodes[revindex] = m_free_nodes[m_free_nodes_count-1];
m_free_nodes_count--; m_free_nodes_count--;
} }
return ptr; return ptr;
} }
size_t btGenericMemoryPool::allocate_from_pool(size_t num_elements) size_t btGenericMemoryPool::allocate_from_pool(size_t num_elements)
{ {
if(m_allocated_count+num_elements>m_max_element_count) return BT_UINT_MAX; if(m_allocated_count+num_elements>m_max_element_count) return BT_UINT_MAX;
size_t ptr = m_allocated_count; size_t ptr = m_allocated_count;
m_allocated_sizes[m_allocated_count] = num_elements; m_allocated_sizes[m_allocated_count] = num_elements;
m_allocated_count+=num_elements; m_allocated_count+=num_elements;
return ptr; return ptr;
} }
void btGenericMemoryPool::init_pool(size_t element_size, size_t element_count) void btGenericMemoryPool::init_pool(size_t element_size, size_t element_count)
{ {
m_allocated_count = 0; m_allocated_count = 0;
m_free_nodes_count = 0; m_free_nodes_count = 0;
m_element_size = element_size; m_element_size = element_size;
m_max_element_count = element_count; m_max_element_count = element_count;
m_pool = (unsigned char *) btAlignedAlloc(m_element_size*m_max_element_count,16); 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_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); 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++ ) for (size_t i = 0;i< m_max_element_count;i++ )
{ {
m_allocated_sizes[i] = 0; m_allocated_sizes[i] = 0;
} }
} }
void btGenericMemoryPool::end_pool() void btGenericMemoryPool::end_pool()
{ {
btAlignedFree(m_pool); btAlignedFree(m_pool);
btAlignedFree(m_free_nodes); btAlignedFree(m_free_nodes);
btAlignedFree(m_allocated_sizes); btAlignedFree(m_allocated_sizes);
m_allocated_count = 0; m_allocated_count = 0;
m_free_nodes_count = 0; m_free_nodes_count = 0;
} }
//! Allocates memory in pool //! Allocates memory in pool
/*! /*!
\param size_bytes size in bytes of the buffer \param size_bytes size in bytes of the buffer
*/ */
void * btGenericMemoryPool::allocate(size_t size_bytes) void * btGenericMemoryPool::allocate(size_t size_bytes)
{ {
size_t module = size_bytes%m_element_size; size_t module = size_bytes%m_element_size;
size_t element_count = size_bytes/m_element_size; size_t element_count = size_bytes/m_element_size;
if(module>0) element_count++; if(module>0) element_count++;
size_t alloc_pos = allocate_from_free_nodes(element_count); size_t alloc_pos = allocate_from_free_nodes(element_count);
// a free node is found // a free node is found
if(alloc_pos != BT_UINT_MAX) if(alloc_pos != BT_UINT_MAX)
{ {
return get_element_data(alloc_pos); return get_element_data(alloc_pos);
} }
// allocate directly on pool // allocate directly on pool
alloc_pos = allocate_from_pool(element_count); alloc_pos = allocate_from_pool(element_count);
if(alloc_pos == BT_UINT_MAX) return NULL; // not space if(alloc_pos == BT_UINT_MAX) return NULL; // not space
return get_element_data(alloc_pos); return get_element_data(alloc_pos);
} }
bool btGenericMemoryPool::freeMemory(void * pointer) bool btGenericMemoryPool::freeMemory(void * pointer)
{ {
unsigned char * pointer_pos = (unsigned char *)pointer; unsigned char * pointer_pos = (unsigned char *)pointer;
unsigned char * pool_pos = (unsigned char *)m_pool; unsigned char * pool_pos = (unsigned char *)m_pool;
// calc offset // calc offset
if(pointer_pos<pool_pos) return false;//other pool if(pointer_pos<pool_pos) return false;//other pool
size_t offset = size_t(pointer_pos - pool_pos); size_t offset = size_t(pointer_pos - pool_pos);
if(offset>=get_pool_capacity()) return false;// far away if(offset>=get_pool_capacity()) return false;// far away
// find free position // find free position
m_free_nodes[m_free_nodes_count] = offset/m_element_size; m_free_nodes[m_free_nodes_count] = offset/m_element_size;
m_free_nodes_count++; m_free_nodes_count++;
return true; return true;
} }
/// *******************! btGenericPoolAllocator *******************!/// /// *******************! btGenericPoolAllocator *******************!///
btGenericPoolAllocator::~btGenericPoolAllocator() btGenericPoolAllocator::~btGenericPoolAllocator()
{ {
// destroy pools // destroy pools
size_t i; size_t i;
for (i=0;i<m_pool_count;i++) for (i=0;i<m_pool_count;i++)
{ {
m_pools[i]->end_pool(); m_pools[i]->end_pool();
btAlignedFree(m_pools[i]); btAlignedFree(m_pools[i]);
} }
} }
// creates a pool // creates a pool
btGenericMemoryPool * btGenericPoolAllocator::push_new_pool() btGenericMemoryPool * btGenericPoolAllocator::push_new_pool()
{ {
if(m_pool_count >= BT_DEFAULT_MAX_POOLS) return NULL; if(m_pool_count >= BT_DEFAULT_MAX_POOLS) return NULL;
btGenericMemoryPool * newptr = (btGenericMemoryPool *)btAlignedAlloc(sizeof(btGenericMemoryPool),16); btGenericMemoryPool * newptr = (btGenericMemoryPool *)btAlignedAlloc(sizeof(btGenericMemoryPool),16);
m_pools[m_pool_count] = newptr; m_pools[m_pool_count] = newptr;
m_pools[m_pool_count]->init_pool(m_pool_element_size,m_pool_element_count); m_pools[m_pool_count]->init_pool(m_pool_element_size,m_pool_element_count);
m_pool_count++; m_pool_count++;
return newptr; return newptr;
} }
void * btGenericPoolAllocator::failback_alloc(size_t size_bytes) void * btGenericPoolAllocator::failback_alloc(size_t size_bytes)
{ {
btGenericMemoryPool * pool = NULL; btGenericMemoryPool * pool = NULL;
if(size_bytes<=get_pool_capacity()) if(size_bytes<=get_pool_capacity())
{ {
pool = push_new_pool(); pool = push_new_pool();
} }
if(pool==NULL) // failback if(pool==NULL) // failback
{ {
return btAlignedAlloc(size_bytes,16); return btAlignedAlloc(size_bytes,16);
} }
return pool->allocate(size_bytes); return pool->allocate(size_bytes);
} }
bool btGenericPoolAllocator::failback_free(void * pointer) bool btGenericPoolAllocator::failback_free(void * pointer)
{ {
btAlignedFree(pointer); btAlignedFree(pointer);
return true; return true;
} }
//! Allocates memory in pool //! Allocates memory in pool
/*! /*!
\param size_bytes size in bytes of the buffer \param size_bytes size in bytes of the buffer
*/ */
void * btGenericPoolAllocator::allocate(size_t size_bytes) void * btGenericPoolAllocator::allocate(size_t size_bytes)
{ {
void * ptr = NULL; void * ptr = NULL;
size_t i = 0; size_t i = 0;
while(i<m_pool_count && ptr == NULL) while(i<m_pool_count && ptr == NULL)
{ {
ptr = m_pools[i]->allocate(size_bytes); ptr = m_pools[i]->allocate(size_bytes);
++i; ++i;
} }
if(ptr) return ptr; if(ptr) return ptr;
return failback_alloc(size_bytes); return failback_alloc(size_bytes);
} }
bool btGenericPoolAllocator::freeMemory(void * pointer) bool btGenericPoolAllocator::freeMemory(void * pointer)
{ {
bool result = false; bool result = false;
size_t i = 0; size_t i = 0;
while(i<m_pool_count && result == false) while(i<m_pool_count && result == false)
{ {
result = m_pools[i]->freeMemory(pointer); result = m_pools[i]->freeMemory(pointer);
++i; ++i;
} }
if(result) return true; if(result) return true;
return failback_free(pointer); return failback_free(pointer);
} }
/// ************** STANDARD ALLOCATOR ***************************/// /// ************** STANDARD ALLOCATOR ***************************///
#define BT_DEFAULT_POOL_SIZE 32768 #define BT_DEFAULT_POOL_SIZE 32768
#define BT_DEFAULT_POOL_ELEMENT_SIZE 8 #define BT_DEFAULT_POOL_ELEMENT_SIZE 8
// main allocator // main allocator
class BT_STANDARD_ALLOCATOR: public btGenericPoolAllocator class BT_STANDARD_ALLOCATOR: public btGenericPoolAllocator
{ {
public: public:
BT_STANDARD_ALLOCATOR():btGenericPoolAllocator(BT_DEFAULT_POOL_ELEMENT_SIZE,BT_DEFAULT_POOL_SIZE) BT_STANDARD_ALLOCATOR():btGenericPoolAllocator(BT_DEFAULT_POOL_ELEMENT_SIZE,BT_DEFAULT_POOL_SIZE)
{ {
} }
}; };
// global allocator // global allocator
BT_STANDARD_ALLOCATOR g_main_allocator; BT_STANDARD_ALLOCATOR g_main_allocator;
void * btPoolAlloc(size_t size) void * btPoolAlloc(size_t size)
{ {
return g_main_allocator.allocate(size); return g_main_allocator.allocate(size);
} }
void * btPoolRealloc(void *ptr, size_t oldsize, size_t newsize) void * btPoolRealloc(void *ptr, size_t oldsize, size_t newsize)
{ {
void * newptr = btPoolAlloc(newsize); void * newptr = btPoolAlloc(newsize);
size_t copysize = oldsize<newsize?oldsize:newsize; size_t copysize = oldsize<newsize?oldsize:newsize;
memcpy(newptr,ptr,copysize); memcpy(newptr,ptr,copysize);
btPoolFree(ptr); btPoolFree(ptr);
return newptr; return newptr;
} }
void btPoolFree(void *ptr) void btPoolFree(void *ptr)
{ {
g_main_allocator.freeMemory(ptr); g_main_allocator.freeMemory(ptr);
} }

View File

@@ -1,168 +1,168 @@
/*! \file btGenericPoolAllocator.h /*! \file btGenericPoolAllocator.h
\author Francisco León Nájera. email projectileman@yahoo.com \author Francisco Len Nßjera. email projectileman@yahoo.com
General purpose allocator class General purpose allocator class
*/ */
/* /*
Bullet Continuous Collision Detection and Physics Library Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty. 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. 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, Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely, including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions: 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. 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. 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. 3. This notice may not be removed or altered from any source distribution.
*/ */
#ifndef BT_GENERIC_POOL_ALLOCATOR_H #ifndef BT_GENERIC_POOL_ALLOCATOR_H
#define BT_GENERIC_POOL_ALLOCATOR_H #define BT_GENERIC_POOL_ALLOCATOR_H
#include <limits.h> #include <limits.h>
#include <stdio.h> #include <stdio.h>
#include <memory.h> #include <memory.h>
#include "LinearMath/btAlignedAllocator.h" #include "LinearMath/btAlignedAllocator.h"
#define BT_UINT_MAX UINT_MAX #define BT_UINT_MAX UINT_MAX
#define BT_DEFAULT_MAX_POOLS 16 #define BT_DEFAULT_MAX_POOLS 16
//! Generic Pool class //! Generic Pool class
class btGenericMemoryPool class btGenericMemoryPool
{ {
public: public:
unsigned char * m_pool; //[m_element_size*m_max_element_count]; 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_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_sizes;//[m_max_element_count];//! Number of elements allocated per node
size_t m_allocated_count; size_t m_allocated_count;
size_t m_free_nodes_count; size_t m_free_nodes_count;
protected: protected:
size_t m_element_size; size_t m_element_size;
size_t m_max_element_count; size_t m_max_element_count;
size_t allocate_from_free_nodes(size_t num_elements); size_t allocate_from_free_nodes(size_t num_elements);
size_t allocate_from_pool(size_t num_elements); size_t allocate_from_pool(size_t num_elements);
public: public:
void init_pool(size_t element_size, size_t element_count); void init_pool(size_t element_size, size_t element_count);
void end_pool(); void end_pool();
btGenericMemoryPool(size_t element_size, size_t element_count) btGenericMemoryPool(size_t element_size, size_t element_count)
{ {
init_pool(element_size, element_count); init_pool(element_size, element_count);
} }
~btGenericMemoryPool() ~btGenericMemoryPool()
{ {
end_pool(); end_pool();
} }
inline size_t get_pool_capacity() inline size_t get_pool_capacity()
{ {
return m_element_size*m_max_element_count; return m_element_size*m_max_element_count;
} }
inline size_t gem_element_size() inline size_t gem_element_size()
{ {
return m_element_size; return m_element_size;
} }
inline size_t get_max_element_count() inline size_t get_max_element_count()
{ {
return m_max_element_count; return m_max_element_count;
} }
inline size_t get_allocated_count() inline size_t get_allocated_count()
{ {
return m_allocated_count; return m_allocated_count;
} }
inline size_t get_free_positions_count() inline size_t get_free_positions_count()
{ {
return m_free_nodes_count; return m_free_nodes_count;
} }
inline void * get_element_data(size_t element_index) inline void * get_element_data(size_t element_index)
{ {
return &m_pool[element_index*m_element_size]; return &m_pool[element_index*m_element_size];
} }
//! Allocates memory in pool //! Allocates memory in pool
/*! /*!
\param size_bytes size in bytes of the buffer \param size_bytes size in bytes of the buffer
*/ */
void * allocate(size_t size_bytes); void * allocate(size_t size_bytes);
bool freeMemory(void * pointer); bool freeMemory(void * pointer);
}; };
//! Generic Allocator with pools //! Generic Allocator with pools
/*! /*!
General purpose Allocator which can create Memory Pools dynamiacally as needed. General purpose Allocator which can create Memory Pools dynamiacally as needed.
*/ */
class btGenericPoolAllocator class btGenericPoolAllocator
{ {
protected: protected:
size_t m_pool_element_size; size_t m_pool_element_size;
size_t m_pool_element_count; size_t m_pool_element_count;
public: public:
btGenericMemoryPool * m_pools[BT_DEFAULT_MAX_POOLS]; btGenericMemoryPool * m_pools[BT_DEFAULT_MAX_POOLS];
size_t m_pool_count; size_t m_pool_count;
inline size_t get_pool_capacity() inline size_t get_pool_capacity()
{ {
return m_pool_element_size*m_pool_element_count; return m_pool_element_size*m_pool_element_count;
} }
protected: protected:
// creates a pool // creates a pool
btGenericMemoryPool * push_new_pool(); btGenericMemoryPool * push_new_pool();
void * failback_alloc(size_t size_bytes); void * failback_alloc(size_t size_bytes);
bool failback_free(void * pointer); bool failback_free(void * pointer);
public: public:
btGenericPoolAllocator(size_t pool_element_size, size_t pool_element_count) btGenericPoolAllocator(size_t pool_element_size, size_t pool_element_count)
{ {
m_pool_count = 0; m_pool_count = 0;
m_pool_element_size = pool_element_size; m_pool_element_size = pool_element_size;
m_pool_element_count = pool_element_count; m_pool_element_count = pool_element_count;
} }
virtual ~btGenericPoolAllocator(); virtual ~btGenericPoolAllocator();
//! Allocates memory in pool //! Allocates memory in pool
/*! /*!
\param size_bytes size in bytes of the buffer \param size_bytes size in bytes of the buffer
*/ */
void * allocate(size_t size_bytes); void * allocate(size_t size_bytes);
bool freeMemory(void * pointer); bool freeMemory(void * pointer);
}; };
/*! \defgroup POOL_MEMORY_FUNCTIONS /*! \defgroup POOL_MEMORY_FUNCTIONS
standar managed Memory functions. Memory pools are used. standar managed Memory functions. Memory pools are used.
*/ */
//! @{ //! @{
void * btPoolAlloc(size_t size); void * btPoolAlloc(size_t size);
void * btPoolRealloc(void *ptr, size_t oldsize, size_t newsize); void * btPoolRealloc(void *ptr, size_t oldsize, size_t newsize);
void btPoolFree(void *ptr); void btPoolFree(void *ptr);
//! @} //! @}
#endif #endif

View File

@@ -2,7 +2,7 @@
#define BT_BASIC_GEOMETRY_OPERATIONS_H_INCLUDED #define BT_BASIC_GEOMETRY_OPERATIONS_H_INCLUDED
/*! \file btGeometryOperations.h /*! \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. 3. This notice may not be removed or altered from any source distribution.
*/ */
#include "GIMPACT/Bullet/btBoxCollision.h" #include "btBoxCollision.h"

View File

@@ -2,7 +2,7 @@
#define BT_QUANTIZATION_H_INCLUDED #define BT_QUANTIZATION_H_INCLUDED
/*! \file btQuantization.h /*! \file btQuantization.h
*\author Francisco León Nájera *\author Francisco Len Nßjera
*/ */
/* /*

View File

@@ -1,5 +1,5 @@
/*! \file btGImpactTriangleShape.h /*! \file btGImpactTriangleShape.h
\author Francisco León Nájera \author Francisco Len Nßjera
*/ */
/* /*
This source file is part of GIMPACT Library. 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. 3. This notice may not be removed or altered from any source distribution.
*/ */
#include "GIMPACT/Bullet/btTriangleShapeEx.h" #include "btTriangleShapeEx.h"

View File

@@ -1,5 +1,5 @@
/*! \file btGImpactShape.h /*! \file btGImpactShape.h
\author Francisco León Nájera \author Francisco Len Nßjera
*/ */
/* /*
This source file is part of GIMPACT Library. 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/btCollisionShape.h"
#include "BulletCollision/CollisionShapes/btTriangleShape.h" #include "BulletCollision/CollisionShapes/btTriangleShape.h"
#include "GIMPACT/Bullet/btBoxCollision.h" #include "btBoxCollision.h"
#include "GIMPACT/Bullet/btClipPolygon.h" #include "btClipPolygon.h"
#include "GIMPACT/Bullet/btGeometryOperations.h" #include "btGeometryOperations.h"
#define MAX_TRI_CLIPPING 16 #define MAX_TRI_CLIPPING 16

View File

@@ -1,332 +1,332 @@
#ifndef GIM_ARRAY_H_INCLUDED #ifndef GIM_ARRAY_H_INCLUDED
#define GIM_ARRAY_H_INCLUDED #define GIM_ARRAY_H_INCLUDED
/*! \file gim_array.h /*! \file gim_array.h
\author Francisco León Nájera \author Francisco Len Nßjera
*/ */
/* /*
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
This source file is part of GIMPACT Library. This source file is part of GIMPACT Library.
For the latest info, see http://gimpact.sourceforge.net/ For the latest info, see http://gimpact.sourceforge.net/
Copyright (c) 2006 Francisco Leon Najera. C.C. 80087371. Copyright (c) 2006 Francisco Leon Najera. C.C. 80087371.
email: projectileman@yahoo.com email: projectileman@yahoo.com
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of EITHER: modify it under the terms of EITHER:
(1) The GNU Lesser General Public License as published by the Free (1) The GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at Software Foundation; either version 2.1 of the License, or (at
your option) any later version. The text of the GNU Lesser your option) any later version. The text of the GNU Lesser
General Public License is included with this library in the General Public License is included with this library in the
file GIMPACT-LICENSE-LGPL.TXT. file GIMPACT-LICENSE-LGPL.TXT.
(2) The BSD-style license that is included with this library in (2) The BSD-style license that is included with this library in
the file GIMPACT-LICENSE-BSD.TXT. the file GIMPACT-LICENSE-BSD.TXT.
(3) The zlib/libpng license that is included with this library in (3) The zlib/libpng license that is included with this library in
the file GIMPACT-LICENSE-ZLIB.TXT. the file GIMPACT-LICENSE-ZLIB.TXT.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files 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. GIMPACT-LICENSE-LGPL.TXT, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
*/ */
#include "GIMPACT/core/gim_memory.h" #include "gim_memory.h"
/*! \addtogroup CONTAINERS /*! \addtogroup CONTAINERS
\brief \brief
Abstract class for template containers Abstract class for template containers
*/ */
//! @{ //! @{
#define GIM_ARRAY_GROW_INCREMENT 2 #define GIM_ARRAY_GROW_INCREMENT 2
#define GIM_ARRAY_GROW_FACTOR 2 #define GIM_ARRAY_GROW_FACTOR 2
//! Very simple array container with fast access and simd memory //! Very simple array container with fast access and simd memory
template<typename T> template<typename T>
class gim_array class gim_array
{ {
public: public:
//! properties //! properties
//!@{ //!@{
T *m_data; T *m_data;
GUINT m_size; GUINT m_size;
GUINT m_allocated_size; GUINT m_allocated_size;
//!@} //!@}
//! protected operations //! protected operations
//!@{ //!@{
inline void destroyData() inline void destroyData()
{ {
m_allocated_size = 0; m_allocated_size = 0;
if(m_data==NULL) return; if(m_data==NULL) return;
gim_free(m_data); gim_free(m_data);
m_data = NULL; m_data = NULL;
} }
inline bool resizeData(GUINT newsize) inline bool resizeData(GUINT newsize)
{ {
if(newsize==0) if(newsize==0)
{ {
destroyData(); destroyData();
return true; return true;
} }
if(m_size>0) if(m_size>0)
{ {
m_data = (T*)gim_realloc(m_data,m_size*sizeof(T),newsize*sizeof(T)); m_data = (T*)gim_realloc(m_data,m_size*sizeof(T),newsize*sizeof(T));
} }
else else
{ {
m_data = (T*)gim_alloc(newsize*sizeof(T)); m_data = (T*)gim_alloc(newsize*sizeof(T));
} }
m_allocated_size = newsize; m_allocated_size = newsize;
return true; return true;
} }
inline bool growingCheck() inline bool growingCheck()
{ {
if(m_allocated_size<=m_size) if(m_allocated_size<=m_size)
{ {
GUINT requestsize = m_size; GUINT requestsize = m_size;
m_size = m_allocated_size; m_size = m_allocated_size;
if(resizeData((requestsize+GIM_ARRAY_GROW_INCREMENT)*GIM_ARRAY_GROW_FACTOR)==false) return false; if(resizeData((requestsize+GIM_ARRAY_GROW_INCREMENT)*GIM_ARRAY_GROW_FACTOR)==false) return false;
} }
return true; return true;
} }
//!@} //!@}
//! public operations //! public operations
//!@{ //!@{
inline bool reserve(GUINT size) inline bool reserve(GUINT size)
{ {
if(m_allocated_size>=size) return false; if(m_allocated_size>=size) return false;
return resizeData(size); return resizeData(size);
} }
inline void clear_range(GUINT start_range) inline void clear_range(GUINT start_range)
{ {
while(m_size>start_range) while(m_size>start_range)
{ {
m_data[--m_size].~T(); m_data[--m_size].~T();
} }
} }
inline void clear() inline void clear()
{ {
if(m_size==0)return; if(m_size==0)return;
clear_range(0); clear_range(0);
} }
inline void clear_memory() inline void clear_memory()
{ {
clear(); clear();
destroyData(); destroyData();
} }
gim_array() gim_array()
{ {
m_data = 0; m_data = 0;
m_size = 0; m_size = 0;
m_allocated_size = 0; m_allocated_size = 0;
} }
gim_array(GUINT reservesize) gim_array(GUINT reservesize)
{ {
m_data = 0; m_data = 0;
m_size = 0; m_size = 0;
m_allocated_size = 0; m_allocated_size = 0;
reserve(reservesize); reserve(reservesize);
} }
~gim_array() ~gim_array()
{ {
clear_memory(); clear_memory();
} }
inline GUINT size() const inline GUINT size() const
{ {
return m_size; return m_size;
} }
inline GUINT max_size() const inline GUINT max_size() const
{ {
return m_allocated_size; return m_allocated_size;
} }
inline T & operator[](size_t i) inline T & operator[](size_t i)
{ {
return m_data[i]; return m_data[i];
} }
inline const T & operator[](size_t i) const inline const T & operator[](size_t i) const
{ {
return m_data[i]; return m_data[i];
} }
inline T * pointer(){ return m_data;} inline T * pointer(){ return m_data;}
inline const T * pointer() const inline const T * pointer() const
{ return m_data;} { return m_data;}
inline T * get_pointer_at(GUINT i) inline T * get_pointer_at(GUINT i)
{ {
return m_data + i; return m_data + i;
} }
inline const T * get_pointer_at(GUINT i) const inline const T * get_pointer_at(GUINT i) const
{ {
return m_data + i; return m_data + i;
} }
inline T & at(GUINT i) inline T & at(GUINT i)
{ {
return m_data[i]; return m_data[i];
} }
inline const T & at(GUINT i) const inline const T & at(GUINT i) const
{ {
return m_data[i]; return m_data[i];
} }
inline T & front() inline T & front()
{ {
return *m_data; return *m_data;
} }
inline const T & front() const inline const T & front() const
{ {
return *m_data; return *m_data;
} }
inline T & back() inline T & back()
{ {
return m_data[m_size-1]; return m_data[m_size-1];
} }
inline const T & back() const inline const T & back() const
{ {
return m_data[m_size-1]; return m_data[m_size-1];
} }
inline void swap(GUINT i, GUINT j) inline void swap(GUINT i, GUINT j)
{ {
gim_swap_elements(m_data,i,j); gim_swap_elements(m_data,i,j);
} }
inline void push_back(const T & obj) inline void push_back(const T & obj)
{ {
this->growingCheck(); this->growingCheck();
m_data[m_size] = obj; m_data[m_size] = obj;
m_size++; m_size++;
} }
//!Simply increase the m_size, doesn't call the new element constructor //!Simply increase the m_size, doesn't call the new element constructor
inline void push_back_mem() inline void push_back_mem()
{ {
this->growingCheck(); this->growingCheck();
m_size++; m_size++;
} }
inline void push_back_memcpy(const T & obj) inline void push_back_memcpy(const T & obj)
{ {
this->growingCheck(); this->growingCheck();
irr_simd_memcpy(&m_data[m_size],&obj,sizeof(T)); irr_simd_memcpy(&m_data[m_size],&obj,sizeof(T));
m_size++; m_size++;
} }
inline void pop_back() inline void pop_back()
{ {
m_size--; m_size--;
m_data[m_size].~T(); m_data[m_size].~T();
} }
//!Simply decrease the m_size, doesn't call the deleted element destructor //!Simply decrease the m_size, doesn't call the deleted element destructor
inline void pop_back_mem() inline void pop_back_mem()
{ {
m_size--; m_size--;
} }
//! fast erase //! fast erase
inline void erase(GUINT index) inline void erase(GUINT index)
{ {
if(index<m_size-1) if(index<m_size-1)
{ {
swap(index,m_size-1); swap(index,m_size-1);
} }
pop_back(); pop_back();
} }
inline void erase_sorted_mem(GUINT index) inline void erase_sorted_mem(GUINT index)
{ {
m_size--; m_size--;
for(GUINT i = index;i<m_size;i++) for(GUINT i = index;i<m_size;i++)
{ {
gim_simd_memcpy(m_data+i,m_data+i+1,sizeof(T)); gim_simd_memcpy(m_data+i,m_data+i+1,sizeof(T));
} }
} }
inline void erase_sorted(GUINT index) inline void erase_sorted(GUINT index)
{ {
m_data[index].~T(); m_data[index].~T();
erase_sorted_mem(index); erase_sorted_mem(index);
} }
inline void insert_mem(GUINT index) inline void insert_mem(GUINT index)
{ {
this->growingCheck(); this->growingCheck();
for(GUINT i = m_size;i>index;i--) for(GUINT i = m_size;i>index;i--)
{ {
gim_simd_memcpy(m_data+i,m_data+i-1,sizeof(T)); gim_simd_memcpy(m_data+i,m_data+i-1,sizeof(T));
} }
m_size++; m_size++;
} }
inline void insert(const T & obj,GUINT index) inline void insert(const T & obj,GUINT index)
{ {
insert_mem(index); insert_mem(index);
m_data[index] = obj; m_data[index] = obj;
} }
inline void resize(GUINT size, bool call_constructor = true) inline void resize(GUINT size, bool call_constructor = true)
{ {
if(size>m_size) if(size>m_size)
{ {
reserve(size); reserve(size);
if(call_constructor) if(call_constructor)
{ {
T obj; T obj;
while(m_size<size) while(m_size<size)
{ {
m_data[m_size] = obj; m_data[m_size] = obj;
m_size++; m_size++;
} }
} }
else else
{ {
m_size = size; m_size = size;
} }
} }
else if(size<m_size) else if(size<m_size)
{ {
if(call_constructor) clear_range(size); if(call_constructor) clear_range(size);
m_size = size; m_size = size;
} }
} }
inline void refit() inline void refit()
{ {
resizeData(m_size); resizeData(m_size);
} }
//!@} //!@}
}; };
//! @} //! @}
#endif // GIM_CONTAINERS_H_INCLUDED #endif // GIM_CONTAINERS_H_INCLUDED

View File

@@ -1,129 +1,129 @@
#ifndef GIM_BITSET_H_INCLUDED #ifndef GIM_BITSET_H_INCLUDED
#define GIM_BITSET_H_INCLUDED #define GIM_BITSET_H_INCLUDED
/*! \file gim_bitset.h /*! \file gim_bitset.h
\author Francisco León Nájera \author Francisco Len Nßjera
*/ */
/* /*
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
This source file is part of GIMPACT Library. This source file is part of GIMPACT Library.
For the latest info, see http://gimpact.sourceforge.net/ For the latest info, see http://gimpact.sourceforge.net/
Copyright (c) 2006 Francisco Leon Najera. C.C. 80087371. Copyright (c) 2006 Francisco Leon Najera. C.C. 80087371.
email: projectileman@yahoo.com email: projectileman@yahoo.com
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of EITHER: modify it under the terms of EITHER:
(1) The GNU Lesser General Public License as published by the Free (1) The GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at Software Foundation; either version 2.1 of the License, or (at
your option) any later version. The text of the GNU Lesser your option) any later version. The text of the GNU Lesser
General Public License is included with this library in the General Public License is included with this library in the
file GIMPACT-LICENSE-LGPL.TXT. file GIMPACT-LICENSE-LGPL.TXT.
(2) The BSD-style license that is included with this library in (2) The BSD-style license that is included with this library in
the file GIMPACT-LICENSE-BSD.TXT. the file GIMPACT-LICENSE-BSD.TXT.
(3) The zlib/libpng license that is included with this library in (3) The zlib/libpng license that is included with this library in
the file GIMPACT-LICENSE-ZLIB.TXT. the file GIMPACT-LICENSE-ZLIB.TXT.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files 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. GIMPACT-LICENSE-LGPL.TXT, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
*/ */
#include "GIMPACT/core/gim_array.h" #include "gim_array.h"
/*! \addtogroup CONTAINERS /*! \addtogroup CONTAINERS
\brief \brief
Abstract class for template containers Abstract class for template containers
*/ */
//! @{ //! @{
#define GUINT_BIT_COUNT 32 #define GUINT_BIT_COUNT 32
#define GUINT_EXPONENT 5 #define GUINT_EXPONENT 5
class gim_bitset class gim_bitset
{ {
public: public:
gim_array<GUINT> m_container; gim_array<GUINT> m_container;
gim_bitset() gim_bitset()
{ {
} }
gim_bitset(GUINT bits_count) gim_bitset(GUINT bits_count)
{ {
resize(bits_count); resize(bits_count);
} }
~gim_bitset() ~gim_bitset()
{ {
} }
inline bool resize(GUINT newsize) inline bool resize(GUINT newsize)
{ {
GUINT oldsize = m_container.size(); GUINT oldsize = m_container.size();
m_container.resize(newsize/GUINT_BIT_COUNT + 1,false); m_container.resize(newsize/GUINT_BIT_COUNT + 1,false);
while(oldsize<m_container.size()) while(oldsize<m_container.size())
{ {
m_container[oldsize] = 0; m_container[oldsize] = 0;
} }
return true; return true;
} }
inline GUINT size() inline GUINT size()
{ {
return m_container.size()*GUINT_BIT_COUNT; return m_container.size()*GUINT_BIT_COUNT;
} }
inline void set_all() inline void set_all()
{ {
for(GUINT i = 0;i<m_container.size();++i) for(GUINT i = 0;i<m_container.size();++i)
{ {
m_container[i] = 0xffffffff; m_container[i] = 0xffffffff;
} }
} }
inline void clear_all() inline void clear_all()
{ {
for(GUINT i = 0;i<m_container.size();++i) for(GUINT i = 0;i<m_container.size();++i)
{ {
m_container[i] = 0; m_container[i] = 0;
} }
} }
inline void set(GUINT bit_index) inline void set(GUINT bit_index)
{ {
if(bit_index>=size()) if(bit_index>=size())
{ {
resize(bit_index); resize(bit_index);
} }
m_container[bit_index >> GUINT_EXPONENT] |= (1 << (bit_index & (GUINT_BIT_COUNT-1))); m_container[bit_index >> GUINT_EXPONENT] |= (1 << (bit_index & (GUINT_BIT_COUNT-1)));
} }
///Return 0 or 1 ///Return 0 or 1
inline char get(GUINT bit_index) inline char get(GUINT bit_index)
{ {
if(bit_index>=size()) if(bit_index>=size())
{ {
return 0; return 0;
} }
char value = m_container[bit_index >> GUINT_EXPONENT] & char value = m_container[bit_index >> GUINT_EXPONENT] &
(1 << (bit_index & (GUINT_BIT_COUNT-1))); (1 << (bit_index & (GUINT_BIT_COUNT-1)));
return value; return value;
} }
inline void clear(GUINT bit_index) inline void clear(GUINT bit_index)
{ {
m_container[bit_index >> GUINT_EXPONENT] &= ~(1 << (bit_index & (GUINT_BIT_COUNT-1))); m_container[bit_index >> GUINT_EXPONENT] &= ~(1 << (bit_index & (GUINT_BIT_COUNT-1)));
} }
}; };
//! @} //! @}
#endif // GIM_CONTAINERS_H_INCLUDED #endif // GIM_CONTAINERS_H_INCLUDED

File diff suppressed because it is too large Load Diff

View File

@@ -1,182 +1,182 @@
/* /*
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
This source file is part of GIMPACT Library. This source file is part of GIMPACT Library.
For the latest info, see http://gimpact.sourceforge.net/ For the latest info, see http://gimpact.sourceforge.net/
Copyright (c) 2006 Francisco Leon Najera. C.C. 80087371. Copyright (c) 2006 Francisco Leon Najera. C.C. 80087371.
email: projectileman@yahoo.com email: projectileman@yahoo.com
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of EITHER: modify it under the terms of EITHER:
(1) The GNU Lesser General Public License as published by the Free (1) The GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at Software Foundation; either version 2.1 of the License, or (at
your option) any later version. The text of the GNU Lesser your option) any later version. The text of the GNU Lesser
General Public License is included with this library in the General Public License is included with this library in the
file GIMPACT-LICENSE-LGPL.TXT. file GIMPACT-LICENSE-LGPL.TXT.
(2) The BSD-style license that is included with this library in (2) The BSD-style license that is included with this library in
the file GIMPACT-LICENSE-BSD.TXT. the file GIMPACT-LICENSE-BSD.TXT.
(3) The zlib/libpng license that is included with this library in (3) The zlib/libpng license that is included with this library in
the file GIMPACT-LICENSE-ZLIB.TXT. the file GIMPACT-LICENSE-ZLIB.TXT.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files 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. GIMPACT-LICENSE-LGPL.TXT, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
*/ */
#include "GIMPACT/core/gim_box_set.h" #include "gim_box_set.h"
GUINT GIM_BOX_TREE::_calc_splitting_axis( GUINT GIM_BOX_TREE::_calc_splitting_axis(
gim_array<GIM_AABB_DATA> & primitive_boxes, GUINT startIndex, GUINT endIndex) gim_array<GIM_AABB_DATA> & primitive_boxes, GUINT startIndex, GUINT endIndex)
{ {
GUINT i; GUINT i;
btVector3 means(btScalar(0.),btScalar(0.),btScalar(0.)); btVector3 means(btScalar(0.),btScalar(0.),btScalar(0.));
btVector3 variance(btScalar(0.),btScalar(0.),btScalar(0.)); btVector3 variance(btScalar(0.),btScalar(0.),btScalar(0.));
GUINT numIndices = endIndex-startIndex; GUINT numIndices = endIndex-startIndex;
for (i=startIndex;i<endIndex;i++) for (i=startIndex;i<endIndex;i++)
{ {
btVector3 center = btScalar(0.5)*(primitive_boxes[i].m_bound.m_max + btVector3 center = btScalar(0.5)*(primitive_boxes[i].m_bound.m_max +
primitive_boxes[i].m_bound.m_min); primitive_boxes[i].m_bound.m_min);
means+=center; means+=center;
} }
means *= (btScalar(1.)/(btScalar)numIndices); means *= (btScalar(1.)/(btScalar)numIndices);
for (i=startIndex;i<endIndex;i++) for (i=startIndex;i<endIndex;i++)
{ {
btVector3 center = btScalar(0.5)*(primitive_boxes[i].m_bound.m_max + btVector3 center = btScalar(0.5)*(primitive_boxes[i].m_bound.m_max +
primitive_boxes[i].m_bound.m_min); primitive_boxes[i].m_bound.m_min);
btVector3 diff2 = center-means; btVector3 diff2 = center-means;
diff2 = diff2 * diff2; diff2 = diff2 * diff2;
variance += diff2; variance += diff2;
} }
variance *= (btScalar(1.)/ ((btScalar)numIndices-1) ); variance *= (btScalar(1.)/ ((btScalar)numIndices-1) );
return variance.maxAxis(); return variance.maxAxis();
} }
GUINT GIM_BOX_TREE::_sort_and_calc_splitting_index( GUINT GIM_BOX_TREE::_sort_and_calc_splitting_index(
gim_array<GIM_AABB_DATA> & primitive_boxes, GUINT startIndex, gim_array<GIM_AABB_DATA> & primitive_boxes, GUINT startIndex,
GUINT endIndex, GUINT splitAxis) GUINT endIndex, GUINT splitAxis)
{ {
GUINT i; GUINT i;
GUINT splitIndex =startIndex; GUINT splitIndex =startIndex;
GUINT numIndices = endIndex - startIndex; GUINT numIndices = endIndex - startIndex;
// average of centers // average of centers
btScalar splitValue = 0.0f; btScalar splitValue = 0.0f;
for (i=startIndex;i<endIndex;i++) for (i=startIndex;i<endIndex;i++)
{ {
splitValue+= 0.5f*(primitive_boxes[i].m_bound.m_max[splitAxis] + splitValue+= 0.5f*(primitive_boxes[i].m_bound.m_max[splitAxis] +
primitive_boxes[i].m_bound.m_min[splitAxis]); primitive_boxes[i].m_bound.m_min[splitAxis]);
} }
splitValue /= (btScalar)numIndices; splitValue /= (btScalar)numIndices;
//sort leafNodes so all values larger then splitValue comes first, and smaller values start from 'splitIndex'. //sort leafNodes so all values larger then splitValue comes first, and smaller values start from 'splitIndex'.
for (i=startIndex;i<endIndex;i++) for (i=startIndex;i<endIndex;i++)
{ {
btScalar center = 0.5f*(primitive_boxes[i].m_bound.m_max[splitAxis] + btScalar center = 0.5f*(primitive_boxes[i].m_bound.m_max[splitAxis] +
primitive_boxes[i].m_bound.m_min[splitAxis]); primitive_boxes[i].m_bound.m_min[splitAxis]);
if (center > splitValue) if (center > splitValue)
{ {
//swap //swap
primitive_boxes.swap(i,splitIndex); primitive_boxes.swap(i,splitIndex);
splitIndex++; splitIndex++;
} }
} }
//if the splitIndex causes unbalanced trees, fix this by using the center in between startIndex and endIndex //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. //otherwise the tree-building might fail due to stack-overflows in certain cases.
//unbalanced1 is unsafe: it can cause stack overflows //unbalanced1 is unsafe: it can cause stack overflows
//bool unbalanced1 = ((splitIndex==startIndex) || (splitIndex == (endIndex-1))); //bool unbalanced1 = ((splitIndex==startIndex) || (splitIndex == (endIndex-1)));
//unbalanced2 should work too: always use center (perfect balanced trees) //unbalanced2 should work too: always use center (perfect balanced trees)
//bool unbalanced2 = true; //bool unbalanced2 = true;
//this should be safe too: //this should be safe too:
GUINT rangeBalancedIndices = numIndices/3; GUINT rangeBalancedIndices = numIndices/3;
bool unbalanced = ((splitIndex<=(startIndex+rangeBalancedIndices)) || (splitIndex >=(endIndex-1-rangeBalancedIndices))); bool unbalanced = ((splitIndex<=(startIndex+rangeBalancedIndices)) || (splitIndex >=(endIndex-1-rangeBalancedIndices)));
if (unbalanced) if (unbalanced)
{ {
splitIndex = startIndex+ (numIndices>>1); splitIndex = startIndex+ (numIndices>>1);
} }
bool unbal = (splitIndex==startIndex) || (splitIndex == (endIndex)); bool unbal = (splitIndex==startIndex) || (splitIndex == (endIndex));
btAssert(!unbal); btAssert(!unbal);
return splitIndex; return splitIndex;
} }
void GIM_BOX_TREE::_build_sub_tree(gim_array<GIM_AABB_DATA> & primitive_boxes, GUINT startIndex, GUINT endIndex) void GIM_BOX_TREE::_build_sub_tree(gim_array<GIM_AABB_DATA> & primitive_boxes, GUINT startIndex, GUINT endIndex)
{ {
GUINT current_index = m_num_nodes++; GUINT current_index = m_num_nodes++;
btAssert((endIndex-startIndex)>0); btAssert((endIndex-startIndex)>0);
if((endIndex-startIndex) == 1) //we got a leaf if((endIndex-startIndex) == 1) //we got a leaf
{ {
m_node_array[current_index].m_left = 0; m_node_array[current_index].m_left = 0;
m_node_array[current_index].m_right = 0; m_node_array[current_index].m_right = 0;
m_node_array[current_index].m_escapeIndex = 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_bound = primitive_boxes[startIndex].m_bound;
m_node_array[current_index].m_data = primitive_boxes[startIndex].m_data; m_node_array[current_index].m_data = primitive_boxes[startIndex].m_data;
return; return;
} }
//configure inner node //configure inner node
GUINT splitIndex; GUINT splitIndex;
//calc this node bounding box //calc this node bounding box
m_node_array[current_index].m_bound.invalidate(); m_node_array[current_index].m_bound.invalidate();
for (splitIndex=startIndex;splitIndex<endIndex;splitIndex++) for (splitIndex=startIndex;splitIndex<endIndex;splitIndex++)
{ {
m_node_array[current_index].m_bound.merge(primitive_boxes[splitIndex].m_bound); 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'. //calculate Best Splitting Axis and where to split it. Sort the incoming 'leafNodes' array within range 'startIndex/endIndex'.
//split axis //split axis
splitIndex = _calc_splitting_axis(primitive_boxes,startIndex,endIndex); splitIndex = _calc_splitting_axis(primitive_boxes,startIndex,endIndex);
splitIndex = _sort_and_calc_splitting_index( splitIndex = _sort_and_calc_splitting_index(
primitive_boxes,startIndex,endIndex,splitIndex); primitive_boxes,startIndex,endIndex,splitIndex);
//configure this inner node : the left node index //configure this inner node : the left node index
m_node_array[current_index].m_left = m_num_nodes; m_node_array[current_index].m_left = m_num_nodes;
//build left child tree //build left child tree
_build_sub_tree(primitive_boxes, startIndex, splitIndex ); _build_sub_tree(primitive_boxes, startIndex, splitIndex );
//configure this inner node : the right node index //configure this inner node : the right node index
m_node_array[current_index].m_right = m_num_nodes; m_node_array[current_index].m_right = m_num_nodes;
//build right child tree //build right child tree
_build_sub_tree(primitive_boxes, splitIndex ,endIndex); _build_sub_tree(primitive_boxes, splitIndex ,endIndex);
//configure this inner node : the escape index //configure this inner node : the escape index
m_node_array[current_index].m_escapeIndex = m_num_nodes - current_index; m_node_array[current_index].m_escapeIndex = m_num_nodes - current_index;
} }
//! stackless build tree //! stackless build tree
void GIM_BOX_TREE::build_tree( void GIM_BOX_TREE::build_tree(
gim_array<GIM_AABB_DATA> & primitive_boxes) gim_array<GIM_AABB_DATA> & primitive_boxes)
{ {
// initialize node count to 0 // initialize node count to 0
m_num_nodes = 0; m_num_nodes = 0;
// allocate nodes // allocate nodes
m_node_array.resize(primitive_boxes.size()*2); m_node_array.resize(primitive_boxes.size()*2);
_build_sub_tree(primitive_boxes, 0, primitive_boxes.size()); _build_sub_tree(primitive_boxes, 0, primitive_boxes.size());
} }

File diff suppressed because it is too large Load Diff

View File

@@ -1,214 +1,214 @@
#ifndef GIM_CLIP_POLYGON_H_INCLUDED #ifndef GIM_CLIP_POLYGON_H_INCLUDED
#define GIM_CLIP_POLYGON_H_INCLUDED #define GIM_CLIP_POLYGON_H_INCLUDED
/*! \file gim_tri_collision.h /*! \file gim_tri_collision.h
\author Francisco León Nájera \author Francisco Len Nßjera
*/ */
/* /*
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
This source file is part of GIMPACT Library. This source file is part of GIMPACT Library.
For the latest info, see http://gimpact.sourceforge.net/ For the latest info, see http://gimpact.sourceforge.net/
Copyright (c) 2006 Francisco Leon Najera. C.C. 80087371. Copyright (c) 2006 Francisco Leon Najera. C.C. 80087371.
email: projectileman@yahoo.com email: projectileman@yahoo.com
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of EITHER: modify it under the terms of EITHER:
(1) The GNU Lesser General Public License as published by the Free (1) The GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at Software Foundation; either version 2.1 of the License, or (at
your option) any later version. The text of the GNU Lesser your option) any later version. The text of the GNU Lesser
General Public License is included with this library in the General Public License is included with this library in the
file GIMPACT-LICENSE-LGPL.TXT. file GIMPACT-LICENSE-LGPL.TXT.
(2) The BSD-style license that is included with this library in (2) The BSD-style license that is included with this library in
the file GIMPACT-LICENSE-BSD.TXT. the file GIMPACT-LICENSE-BSD.TXT.
(3) The zlib/libpng license that is included with this library in (3) The zlib/libpng license that is included with this library in
the file GIMPACT-LICENSE-ZLIB.TXT. the file GIMPACT-LICENSE-ZLIB.TXT.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files 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. GIMPACT-LICENSE-LGPL.TXT, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
*/ */
/*! \addtogroup GEOMETRIC_OPERATIONS /*! \addtogroup GEOMETRIC_OPERATIONS
*/ */
//! @{ //! @{
//! This function calcs the distance from a 3D plane //! This function calcs the distance from a 3D plane
class DISTANCE_PLANE_3D_FUNC class DISTANCE_PLANE_3D_FUNC
{ {
public: public:
template<typename CLASS_POINT,typename CLASS_PLANE> template<typename CLASS_POINT,typename CLASS_PLANE>
inline GREAL operator()(const CLASS_PLANE & plane, const CLASS_POINT & point) inline GREAL operator()(const CLASS_PLANE & plane, const CLASS_POINT & point)
{ {
return DISTANCE_PLANE_POINT(plane, point); return DISTANCE_PLANE_POINT(plane, point);
} }
}; };
template<typename CLASS_POINT> template<typename CLASS_POINT>
SIMD_FORCE_INLINE void PLANE_CLIP_POLYGON_COLLECT( SIMD_FORCE_INLINE void PLANE_CLIP_POLYGON_COLLECT(
const CLASS_POINT & point0, const CLASS_POINT & point0,
const CLASS_POINT & point1, const CLASS_POINT & point1,
GREAL dist0, GREAL dist0,
GREAL dist1, GREAL dist1,
CLASS_POINT * clipped, CLASS_POINT * clipped,
GUINT & clipped_count) GUINT & clipped_count)
{ {
GUINT _prevclassif = (dist0>G_EPSILON); GUINT _prevclassif = (dist0>G_EPSILON);
GUINT _classif = (dist1>G_EPSILON); GUINT _classif = (dist1>G_EPSILON);
if(_classif!=_prevclassif) if(_classif!=_prevclassif)
{ {
GREAL blendfactor = -dist0/(dist1-dist0); GREAL blendfactor = -dist0/(dist1-dist0);
VEC_BLEND(clipped[clipped_count],point0,point1,blendfactor); VEC_BLEND(clipped[clipped_count],point0,point1,blendfactor);
clipped_count++; clipped_count++;
} }
if(!_classif) if(!_classif)
{ {
VEC_COPY(clipped[clipped_count],point1); VEC_COPY(clipped[clipped_count],point1);
clipped_count++; clipped_count++;
} }
} }
//! Clips a polygon by a plane //! Clips a polygon by a plane
/*! /*!
*\return The count of the clipped counts *\return The count of the clipped counts
*/ */
template<typename CLASS_POINT,typename CLASS_PLANE, typename DISTANCE_PLANE_FUNC> template<typename CLASS_POINT,typename CLASS_PLANE, typename DISTANCE_PLANE_FUNC>
SIMD_FORCE_INLINE GUINT PLANE_CLIP_POLYGON_GENERIC( SIMD_FORCE_INLINE GUINT PLANE_CLIP_POLYGON_GENERIC(
const CLASS_PLANE & plane, const CLASS_PLANE & plane,
const CLASS_POINT * polygon_points, const CLASS_POINT * polygon_points,
GUINT polygon_point_count, GUINT polygon_point_count,
CLASS_POINT * clipped,DISTANCE_PLANE_FUNC distance_func) CLASS_POINT * clipped,DISTANCE_PLANE_FUNC distance_func)
{ {
GUINT clipped_count = 0; GUINT clipped_count = 0;
//clip first point //clip first point
GREAL firstdist = distance_func(plane,polygon_points[0]);; GREAL firstdist = distance_func(plane,polygon_points[0]);;
if(!(firstdist>G_EPSILON)) if(!(firstdist>G_EPSILON))
{ {
VEC_COPY(clipped[clipped_count],polygon_points[0]); VEC_COPY(clipped[clipped_count],polygon_points[0]);
clipped_count++; clipped_count++;
} }
GREAL olddist = firstdist; GREAL olddist = firstdist;
for(GUINT _i=1;_i<polygon_point_count;_i++) for(GUINT _i=1;_i<polygon_point_count;_i++)
{ {
GREAL dist = distance_func(plane,polygon_points[_i]); GREAL dist = distance_func(plane,polygon_points[_i]);
PLANE_CLIP_POLYGON_COLLECT( PLANE_CLIP_POLYGON_COLLECT(
polygon_points[_i-1],polygon_points[_i], polygon_points[_i-1],polygon_points[_i],
olddist, olddist,
dist, dist,
clipped, clipped,
clipped_count); clipped_count);
olddist = dist; olddist = dist;
} }
//RETURN TO FIRST point //RETURN TO FIRST point
PLANE_CLIP_POLYGON_COLLECT( PLANE_CLIP_POLYGON_COLLECT(
polygon_points[polygon_point_count-1],polygon_points[0], polygon_points[polygon_point_count-1],polygon_points[0],
olddist, olddist,
firstdist, firstdist,
clipped, clipped,
clipped_count); clipped_count);
return clipped_count; return clipped_count;
} }
//! Clips a polygon by a plane //! Clips a polygon by a plane
/*! /*!
*\return The count of the clipped counts *\return The count of the clipped counts
*/ */
template<typename CLASS_POINT,typename CLASS_PLANE, typename DISTANCE_PLANE_FUNC> template<typename CLASS_POINT,typename CLASS_PLANE, typename DISTANCE_PLANE_FUNC>
SIMD_FORCE_INLINE GUINT PLANE_CLIP_TRIANGLE_GENERIC( SIMD_FORCE_INLINE GUINT PLANE_CLIP_TRIANGLE_GENERIC(
const CLASS_PLANE & plane, const CLASS_PLANE & plane,
const CLASS_POINT & point0, const CLASS_POINT & point0,
const CLASS_POINT & point1, const CLASS_POINT & point1,
const CLASS_POINT & point2, const CLASS_POINT & point2,
CLASS_POINT * clipped,DISTANCE_PLANE_FUNC distance_func) CLASS_POINT * clipped,DISTANCE_PLANE_FUNC distance_func)
{ {
GUINT clipped_count = 0; GUINT clipped_count = 0;
//clip first point //clip first point
GREAL firstdist = distance_func(plane,point0);; GREAL firstdist = distance_func(plane,point0);;
if(!(firstdist>G_EPSILON)) if(!(firstdist>G_EPSILON))
{ {
VEC_COPY(clipped[clipped_count],point0); VEC_COPY(clipped[clipped_count],point0);
clipped_count++; clipped_count++;
} }
// point 1 // point 1
GREAL olddist = firstdist; GREAL olddist = firstdist;
GREAL dist = distance_func(plane,point1); GREAL dist = distance_func(plane,point1);
PLANE_CLIP_POLYGON_COLLECT( PLANE_CLIP_POLYGON_COLLECT(
point0,point1, point0,point1,
olddist, olddist,
dist, dist,
clipped, clipped,
clipped_count); clipped_count);
olddist = dist; olddist = dist;
// point 2 // point 2
dist = distance_func(plane,point2); dist = distance_func(plane,point2);
PLANE_CLIP_POLYGON_COLLECT( PLANE_CLIP_POLYGON_COLLECT(
point1,point2, point1,point2,
olddist, olddist,
dist, dist,
clipped, clipped,
clipped_count); clipped_count);
olddist = dist; olddist = dist;
//RETURN TO FIRST point //RETURN TO FIRST point
PLANE_CLIP_POLYGON_COLLECT( PLANE_CLIP_POLYGON_COLLECT(
point2,point0, point2,point0,
olddist, olddist,
firstdist, firstdist,
clipped, clipped,
clipped_count); clipped_count);
return clipped_count; return clipped_count;
} }
template<typename CLASS_POINT,typename CLASS_PLANE> template<typename CLASS_POINT,typename CLASS_PLANE>
SIMD_FORCE_INLINE GUINT PLANE_CLIP_POLYGON3D( SIMD_FORCE_INLINE GUINT PLANE_CLIP_POLYGON3D(
const CLASS_PLANE & plane, const CLASS_PLANE & plane,
const CLASS_POINT * polygon_points, const CLASS_POINT * polygon_points,
GUINT polygon_point_count, GUINT polygon_point_count,
CLASS_POINT * clipped) CLASS_POINT * clipped)
{ {
return PLANE_CLIP_POLYGON_GENERIC<CLASS_POINT,CLASS_PLANE>(plane,polygon_points,polygon_point_count,clipped,DISTANCE_PLANE_3D_FUNC()); 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> template<typename CLASS_POINT,typename CLASS_PLANE>
SIMD_FORCE_INLINE GUINT PLANE_CLIP_TRIANGLE3D( SIMD_FORCE_INLINE GUINT PLANE_CLIP_TRIANGLE3D(
const CLASS_PLANE & plane, const CLASS_PLANE & plane,
const CLASS_POINT & point0, const CLASS_POINT & point0,
const CLASS_POINT & point1, const CLASS_POINT & point1,
const CLASS_POINT & point2, const CLASS_POINT & point2,
CLASS_POINT * clipped) CLASS_POINT * clipped)
{ {
return PLANE_CLIP_TRIANGLE_GENERIC<CLASS_POINT,CLASS_PLANE>(plane,point0,point1,point2,clipped,DISTANCE_PLANE_3D_FUNC()); return PLANE_CLIP_TRIANGLE_GENERIC<CLASS_POINT,CLASS_PLANE>(plane,point0,point1,point2,clipped,DISTANCE_PLANE_3D_FUNC());
} }
//! @} //! @}
#endif // GIM_TRI_COLLISION_H_INCLUDED #endif // GIM_TRI_COLLISION_H_INCLUDED

View File

@@ -1,146 +1,146 @@
/* /*
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
This source file is part of GIMPACT Library. This source file is part of GIMPACT Library.
For the latest info, see http://gimpact.sourceforge.net/ For the latest info, see http://gimpact.sourceforge.net/
Copyright (c) 2006 Francisco Leon Najera. C.C. 80087371. Copyright (c) 2006 Francisco Leon Najera. C.C. 80087371.
email: projectileman@yahoo.com email: projectileman@yahoo.com
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of EITHER: modify it under the terms of EITHER:
(1) The GNU Lesser General Public License as published by the Free (1) The GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at Software Foundation; either version 2.1 of the License, or (at
your option) any later version. The text of the GNU Lesser your option) any later version. The text of the GNU Lesser
General Public License is included with this library in the General Public License is included with this library in the
file GIMPACT-LICENSE-LGPL.TXT. file GIMPACT-LICENSE-LGPL.TXT.
(2) The BSD-style license that is included with this library in (2) The BSD-style license that is included with this library in
the file GIMPACT-LICENSE-BSD.TXT. the file GIMPACT-LICENSE-BSD.TXT.
(3) The zlib/libpng license that is included with this library in (3) The zlib/libpng license that is included with this library in
the file GIMPACT-LICENSE-ZLIB.TXT. the file GIMPACT-LICENSE-ZLIB.TXT.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files 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. GIMPACT-LICENSE-LGPL.TXT, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
*/ */
#include "GIMPACT/core/gim_contact.h" #include "gim_contact.h"
#define MAX_COINCIDENT 8 #define MAX_COINCIDENT 8
void gim_contact_array::merge_contacts( void gim_contact_array::merge_contacts(
const gim_contact_array & contacts, bool normal_contact_average) const gim_contact_array & contacts, bool normal_contact_average)
{ {
clear(); clear();
if(contacts.size()==1) if(contacts.size()==1)
{ {
push_back(contacts.back()); push_back(contacts.back());
return; return;
} }
gim_array<GIM_RSORT_TOKEN> keycontacts(contacts.size()); gim_array<GIM_RSORT_TOKEN> keycontacts(contacts.size());
keycontacts.resize(contacts.size(),false); keycontacts.resize(contacts.size(),false);
//fill key contacts //fill key contacts
GUINT i; GUINT i;
for (i = 0;i<contacts.size() ;i++ ) for (i = 0;i<contacts.size() ;i++ )
{ {
keycontacts[i].m_key = contacts[i].calc_key_contact(); keycontacts[i].m_key = contacts[i].calc_key_contact();
keycontacts[i].m_value = i; keycontacts[i].m_value = i;
} }
//sort keys //sort keys
gim_heap_sort(keycontacts.pointer(),keycontacts.size(),GIM_RSORT_TOKEN_COMPARATOR()); gim_heap_sort(keycontacts.pointer(),keycontacts.size(),GIM_RSORT_TOKEN_COMPARATOR());
// Merge contacts // Merge contacts
GUINT coincident_count=0; GUINT coincident_count=0;
btVector3 coincident_normals[MAX_COINCIDENT]; btVector3 coincident_normals[MAX_COINCIDENT];
GUINT last_key = keycontacts[0].m_key; GUINT last_key = keycontacts[0].m_key;
GUINT key = 0; GUINT key = 0;
push_back(contacts[keycontacts[0].m_value]); push_back(contacts[keycontacts[0].m_value]);
GIM_CONTACT * pcontact = &back(); GIM_CONTACT * pcontact = &back();
for( i=1;i<keycontacts.size();i++) for( i=1;i<keycontacts.size();i++)
{ {
key = keycontacts[i].m_key; key = keycontacts[i].m_key;
const GIM_CONTACT * scontact = &contacts[keycontacts[i].m_value]; const GIM_CONTACT * scontact = &contacts[keycontacts[i].m_value];
if(last_key == key)//same points if(last_key == key)//same points
{ {
//merge contact //merge contact
if(pcontact->m_depth - CONTACT_DIFF_EPSILON > scontact->m_depth)//) if(pcontact->m_depth - CONTACT_DIFF_EPSILON > scontact->m_depth)//)
{ {
*pcontact = *scontact; *pcontact = *scontact;
coincident_count = 0; coincident_count = 0;
} }
else if(normal_contact_average) else if(normal_contact_average)
{ {
if(btFabs(pcontact->m_depth - scontact->m_depth)<CONTACT_DIFF_EPSILON) if(btFabs(pcontact->m_depth - scontact->m_depth)<CONTACT_DIFF_EPSILON)
{ {
if(coincident_count<MAX_COINCIDENT) if(coincident_count<MAX_COINCIDENT)
{ {
coincident_normals[coincident_count] = scontact->m_normal; coincident_normals[coincident_count] = scontact->m_normal;
coincident_count++; coincident_count++;
} }
} }
} }
} }
else else
{//add new contact {//add new contact
if(normal_contact_average && coincident_count>0) if(normal_contact_average && coincident_count>0)
{ {
pcontact->interpolate_normals(coincident_normals,coincident_count); pcontact->interpolate_normals(coincident_normals,coincident_count);
coincident_count = 0; coincident_count = 0;
} }
push_back(*scontact); push_back(*scontact);
pcontact = &back(); pcontact = &back();
} }
last_key = key; last_key = key;
} }
} }
void gim_contact_array::merge_contacts_unique(const gim_contact_array & contacts) void gim_contact_array::merge_contacts_unique(const gim_contact_array & contacts)
{ {
clear(); clear();
if(contacts.size()==1) if(contacts.size()==1)
{ {
push_back(contacts.back()); push_back(contacts.back());
return; return;
} }
GIM_CONTACT average_contact = contacts.back(); GIM_CONTACT average_contact = contacts.back();
for (GUINT i=1;i<contacts.size() ;i++ ) for (GUINT i=1;i<contacts.size() ;i++ )
{ {
average_contact.m_point += contacts[i].m_point; average_contact.m_point += contacts[i].m_point;
average_contact.m_normal += contacts[i].m_normal * contacts[i].m_depth; average_contact.m_normal += contacts[i].m_normal * contacts[i].m_depth;
} }
//divide //divide
GREAL divide_average = 1.0f/((GREAL)contacts.size()); GREAL divide_average = 1.0f/((GREAL)contacts.size());
average_contact.m_point *= divide_average; average_contact.m_point *= divide_average;
average_contact.m_normal *= divide_average; average_contact.m_normal *= divide_average;
average_contact.m_depth = average_contact.m_normal.length(); average_contact.m_depth = average_contact.m_normal.length();
average_contact.m_normal /= average_contact.m_depth; average_contact.m_normal /= average_contact.m_depth;
} }

View File

@@ -1,172 +1,172 @@
#ifndef GIM_CONTACT_H_INCLUDED #ifndef GIM_CONTACT_H_INCLUDED
#define GIM_CONTACT_H_INCLUDED #define GIM_CONTACT_H_INCLUDED
/*! \file gim_contact.h /*! \file gim_contact.h
\author Francisco León Nájera \author Francisco Len Nßjera
*/ */
/* /*
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
This source file is part of GIMPACT Library. This source file is part of GIMPACT Library.
For the latest info, see http://gimpact.sourceforge.net/ For the latest info, see http://gimpact.sourceforge.net/
Copyright (c) 2006 Francisco Leon Najera. C.C. 80087371. Copyright (c) 2006 Francisco Leon Najera. C.C. 80087371.
email: projectileman@yahoo.com email: projectileman@yahoo.com
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of EITHER: modify it under the terms of EITHER:
(1) The GNU Lesser General Public License as published by the Free (1) The GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at Software Foundation; either version 2.1 of the License, or (at
your option) any later version. The text of the GNU Lesser your option) any later version. The text of the GNU Lesser
General Public License is included with this library in the General Public License is included with this library in the
file GIMPACT-LICENSE-LGPL.TXT. file GIMPACT-LICENSE-LGPL.TXT.
(2) The BSD-style license that is included with this library in (2) The BSD-style license that is included with this library in
the file GIMPACT-LICENSE-BSD.TXT. the file GIMPACT-LICENSE-BSD.TXT.
(3) The zlib/libpng license that is included with this library in (3) The zlib/libpng license that is included with this library in
the file GIMPACT-LICENSE-ZLIB.TXT. the file GIMPACT-LICENSE-ZLIB.TXT.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files 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. GIMPACT-LICENSE-LGPL.TXT, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
*/ */
#include "GIMPACT/core/gim_geometry.h" #include "gim_geometry.h"
#include "GIMPACT/core/gim_radixsort.h" #include "gim_radixsort.h"
#include "GIMPACT/core/gim_array.h" #include "gim_array.h"
/*! \defgroup CONTACTS /*! \defgroup CONTACTS
\brief \brief
Functions for managing and sorting contacts resulting from a collision query. Functions for managing and sorting contacts resulting from a collision query.
<ul> <ul>
<li> Contact lists must be create by calling \ref GIM_CREATE_CONTACT_LIST <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> 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 <li> Contacts can be merge for avoid duplicate results by calling \ref gim_merge_contacts
</ul> </ul>
*/ */
//! @{ //! @{
/** /**
Configuration var for applying interpolation of contact normals Configuration var for applying interpolation of contact normals
*/ */
#define NORMAL_CONTACT_AVERAGE 1 #define NORMAL_CONTACT_AVERAGE 1
#define CONTACT_DIFF_EPSILON 0.00001f #define CONTACT_DIFF_EPSILON 0.00001f
/// Structure for collision results /// Structure for collision results
class GIM_CONTACT class GIM_CONTACT
{ {
public: public:
btVector3 m_point; btVector3 m_point;
btVector3 m_normal; btVector3 m_normal;
GREAL m_depth;//Positive value indicates interpenetration GREAL m_depth;//Positive value indicates interpenetration
GREAL m_distance;//Padding not for use GREAL m_distance;//Padding not for use
GUINT m_feature1;//Face number GUINT m_feature1;//Face number
GUINT m_feature2;//Face number GUINT m_feature2;//Face number
public: public:
GIM_CONTACT() GIM_CONTACT()
{ {
} }
GIM_CONTACT(const GIM_CONTACT & contact): GIM_CONTACT(const GIM_CONTACT & contact):
m_point(contact.m_point), m_point(contact.m_point),
m_normal(contact.m_normal), m_normal(contact.m_normal),
m_depth(contact.m_depth), m_depth(contact.m_depth),
m_feature1(contact.m_feature1), m_feature1(contact.m_feature1),
m_feature2(contact.m_feature2) m_feature2(contact.m_feature2)
{ {
m_point = contact.m_point; m_point = contact.m_point;
m_normal = contact.m_normal; m_normal = contact.m_normal;
m_depth = contact.m_depth; m_depth = contact.m_depth;
m_feature1 = contact.m_feature1; m_feature1 = contact.m_feature1;
m_feature2 = contact.m_feature2; m_feature2 = contact.m_feature2;
} }
GIM_CONTACT(const btVector3 &point,const btVector3 & normal, GIM_CONTACT(const btVector3 &point,const btVector3 & normal,
GREAL depth, GUINT feature1, GUINT feature2): GREAL depth, GUINT feature1, GUINT feature2):
m_point(point), m_point(point),
m_normal(normal), m_normal(normal),
m_depth(depth), m_depth(depth),
m_feature1(feature1), m_feature1(feature1),
m_feature2(feature2) m_feature2(feature2)
{ {
} }
//! Calcs key for coord classification //! Calcs key for coord classification
SIMD_FORCE_INLINE GUINT calc_key_contact() const SIMD_FORCE_INLINE GUINT calc_key_contact() const
{ {
GINT _coords[] = { GINT _coords[] = {
(GINT)(m_point[0]*1000.0f+1.0f), (GINT)(m_point[0]*1000.0f+1.0f),
(GINT)(m_point[1]*1333.0f), (GINT)(m_point[1]*1333.0f),
(GINT)(m_point[2]*2133.0f+3.0f)}; (GINT)(m_point[2]*2133.0f+3.0f)};
GUINT _hash=0; GUINT _hash=0;
GUINT *_uitmp = (GUINT *)(&_coords[0]); GUINT *_uitmp = (GUINT *)(&_coords[0]);
_hash = *_uitmp; _hash = *_uitmp;
_uitmp++; _uitmp++;
_hash += (*_uitmp)<<4; _hash += (*_uitmp)<<4;
_uitmp++; _uitmp++;
_hash += (*_uitmp)<<8; _hash += (*_uitmp)<<8;
return _hash; return _hash;
} }
SIMD_FORCE_INLINE void interpolate_normals( btVector3 * normals,GUINT normal_count) SIMD_FORCE_INLINE void interpolate_normals( btVector3 * normals,GUINT normal_count)
{ {
btVector3 vec_sum(m_normal); btVector3 vec_sum(m_normal);
for(GUINT i=0;i<normal_count;i++) for(GUINT i=0;i<normal_count;i++)
{ {
vec_sum += normals[i]; vec_sum += normals[i];
} }
GREAL vec_sum_len = vec_sum.length2(); GREAL vec_sum_len = vec_sum.length2();
if(vec_sum_len <CONTACT_DIFF_EPSILON) return; if(vec_sum_len <CONTACT_DIFF_EPSILON) return;
GIM_INV_SQRT(vec_sum_len,vec_sum_len); // 1/sqrt(vec_sum_len) GIM_INV_SQRT(vec_sum_len,vec_sum_len); // 1/sqrt(vec_sum_len)
m_normal = vec_sum*vec_sum_len; m_normal = vec_sum*vec_sum_len;
} }
}; };
class gim_contact_array:public gim_array<GIM_CONTACT> class gim_contact_array:public gim_array<GIM_CONTACT>
{ {
public: public:
gim_contact_array():gim_array<GIM_CONTACT>(64) gim_contact_array():gim_array<GIM_CONTACT>(64)
{ {
} }
SIMD_FORCE_INLINE void push_contact(const btVector3 &point,const btVector3 & normal, SIMD_FORCE_INLINE void push_contact(const btVector3 &point,const btVector3 & normal,
GREAL depth, GUINT feature1, GUINT feature2) GREAL depth, GUINT feature1, GUINT feature2)
{ {
push_back_mem(); push_back_mem();
GIM_CONTACT & newele = back(); GIM_CONTACT & newele = back();
newele.m_point = point; newele.m_point = point;
newele.m_normal = normal; newele.m_normal = normal;
newele.m_depth = depth; newele.m_depth = depth;
newele.m_feature1 = feature1; newele.m_feature1 = feature1;
newele.m_feature2 = feature2; newele.m_feature2 = feature2;
} }
SIMD_FORCE_INLINE void push_triangle_contacts( SIMD_FORCE_INLINE void push_triangle_contacts(
const GIM_TRIANGLE_CONTACT_DATA & tricontact, const GIM_TRIANGLE_CONTACT_DATA & tricontact,
GUINT feature1,GUINT feature2) GUINT feature1,GUINT feature2)
{ {
for(GUINT i = 0;i<tricontact.m_point_count ;i++ ) for(GUINT i = 0;i<tricontact.m_point_count ;i++ )
{ {
push_back_mem(); push_back_mem();
GIM_CONTACT & newele = back(); GIM_CONTACT & newele = back();
newele.m_point = tricontact.m_points[i]; newele.m_point = tricontact.m_points[i];
newele.m_normal = tricontact.m_separating_normal; newele.m_normal = tricontact.m_separating_normal;
newele.m_depth = tricontact.m_penetration_depth; newele.m_depth = tricontact.m_penetration_depth;
newele.m_feature1 = feature1; newele.m_feature1 = feature1;
newele.m_feature2 = feature2; newele.m_feature2 = feature2;
} }
} }
void merge_contacts(const gim_contact_array & contacts, bool normal_contact_average = true); void merge_contacts(const gim_contact_array & contacts, bool normal_contact_average = true);
void merge_contacts_unique(const gim_contact_array & contacts); void merge_contacts_unique(const gim_contact_array & contacts);
}; };
//! @} //! @}
#endif // GIM_CONTACT_H_INCLUDED #endif // GIM_CONTACT_H_INCLUDED

View File

@@ -1,102 +1,102 @@
#ifndef GIM_GEOM_TYPES_H_INCLUDED #ifndef GIM_GEOM_TYPES_H_INCLUDED
#define GIM_GEOM_TYPES_H_INCLUDED #define GIM_GEOM_TYPES_H_INCLUDED
/*! \file gim_geom_types.h /*! \file gim_geom_types.h
\author Francisco León Nájera \author Francisco Len Nßjera
*/ */
/* /*
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
This source file is part of GIMPACT Library. This source file is part of GIMPACT Library.
For the latest info, see http://gimpact.sourceforge.net/ For the latest info, see http://gimpact.sourceforge.net/
Copyright (c) 2006 Francisco Leon Najera. C.C. 80087371. Copyright (c) 2006 Francisco Leon Najera. C.C. 80087371.
email: projectileman@yahoo.com email: projectileman@yahoo.com
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of EITHER: modify it under the terms of EITHER:
(1) The GNU Lesser General Public License as published by the Free (1) The GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at Software Foundation; either version 2.1 of the License, or (at
your option) any later version. The text of the GNU Lesser your option) any later version. The text of the GNU Lesser
General Public License is included with this library in the General Public License is included with this library in the
file GIMPACT-LICENSE-LGPL.TXT. file GIMPACT-LICENSE-LGPL.TXT.
(2) The BSD-style license that is included with this library in (2) The BSD-style license that is included with this library in
the file GIMPACT-LICENSE-BSD.TXT. the file GIMPACT-LICENSE-BSD.TXT.
(3) The zlib/libpng license that is included with this library in (3) The zlib/libpng license that is included with this library in
the file GIMPACT-LICENSE-ZLIB.TXT. the file GIMPACT-LICENSE-ZLIB.TXT.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files 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. GIMPACT-LICENSE-LGPL.TXT, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
*/ */
#include "GIMPACT/core/gim_math.h" #include "gim_math.h"
/*! \defgroup GEOMETRIC_TYPES /*! \defgroup GEOMETRIC_TYPES
\brief \brief
Basic types and constants for geometry Basic types and constants for geometry
*/ */
//! @{ //! @{
//! Short Integer vector 2D //! Short Integer vector 2D
typedef GSHORT vec2s[2]; typedef GSHORT vec2s[2];
//! Integer vector 3D //! Integer vector 3D
typedef GSHORT vec3s[3]; typedef GSHORT vec3s[3];
//! Integer vector 4D //! Integer vector 4D
typedef GSHORT vec4s[4]; typedef GSHORT vec4s[4];
//! Short Integer vector 2D //! Short Integer vector 2D
typedef GUSHORT vec2us[2]; typedef GUSHORT vec2us[2];
//! Integer vector 3D //! Integer vector 3D
typedef GUSHORT vec3us[3]; typedef GUSHORT vec3us[3];
//! Integer vector 4D //! Integer vector 4D
typedef GUSHORT vec4us[4]; typedef GUSHORT vec4us[4];
//! Integer vector 2D //! Integer vector 2D
typedef GINT vec2i[2]; typedef GINT vec2i[2];
//! Integer vector 3D //! Integer vector 3D
typedef GINT vec3i[3]; typedef GINT vec3i[3];
//! Integer vector 4D //! Integer vector 4D
typedef GINT vec4i[4]; typedef GINT vec4i[4];
//! Unsigned Integer vector 2D //! Unsigned Integer vector 2D
typedef GUINT vec2ui[2]; typedef GUINT vec2ui[2];
//! Unsigned Integer vector 3D //! Unsigned Integer vector 3D
typedef GUINT vec3ui[3]; typedef GUINT vec3ui[3];
//! Unsigned Integer vector 4D //! Unsigned Integer vector 4D
typedef GUINT vec4ui[4]; typedef GUINT vec4ui[4];
//! Float vector 2D //! Float vector 2D
typedef GREAL vec2f[2]; typedef GREAL vec2f[2];
//! Float vector 3D //! Float vector 3D
typedef GREAL vec3f[3]; typedef GREAL vec3f[3];
//! Float vector 4D //! Float vector 4D
typedef GREAL vec4f[4]; typedef GREAL vec4f[4];
//! Double vector 2D //! Double vector 2D
typedef GREAL2 vec2d[2]; typedef GREAL2 vec2d[2];
//! Float vector 3D //! Float vector 3D
typedef GREAL2 vec3d[3]; typedef GREAL2 vec3d[3];
//! Float vector 4D //! Float vector 4D
typedef GREAL2 vec4d[4]; typedef GREAL2 vec4d[4];
//! Matrix 2D, row ordered //! Matrix 2D, row ordered
typedef GREAL mat2f[2][2]; typedef GREAL mat2f[2][2];
//! Matrix 3D, row ordered //! Matrix 3D, row ordered
typedef GREAL mat3f[3][3]; typedef GREAL mat3f[3][3];
//! Matrix 4D, row ordered //! Matrix 4D, row ordered
typedef GREAL mat4f[4][4]; typedef GREAL mat4f[4][4];
//! Quaternion //! Quaternion
typedef GREAL quatf[4]; typedef GREAL quatf[4];
//typedef struct _aabb3f aabb3f; //typedef struct _aabb3f aabb3f;
//! @} //! @}
#endif // GIM_GEOM_TYPES_H_INCLUDED #endif // GIM_GEOM_TYPES_H_INCLUDED

View File

@@ -1,44 +1,42 @@
#ifndef GIM_GEOMETRY_H_INCLUDED #ifndef GIM_GEOMETRY_H_INCLUDED
#define GIM_GEOMETRY_H_INCLUDED #define GIM_GEOMETRY_H_INCLUDED
/*! \file gim_geometry.h /*! \file gim_geometry.h
\author Francisco León Nájera \author Francisco Len Nßjera
*/ */
/* /*
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
This source file is part of GIMPACT Library. This source file is part of GIMPACT Library.
For the latest info, see http://gimpact.sourceforge.net/ For the latest info, see http://gimpact.sourceforge.net/
Copyright (c) 2006 Francisco Leon Najera. C.C. 80087371. Copyright (c) 2006 Francisco Leon Najera. C.C. 80087371.
email: projectileman@yahoo.com email: projectileman@yahoo.com
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of EITHER: modify it under the terms of EITHER:
(1) The GNU Lesser General Public License as published by the Free (1) The GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at Software Foundation; either version 2.1 of the License, or (at
your option) any later version. The text of the GNU Lesser your option) any later version. The text of the GNU Lesser
General Public License is included with this library in the General Public License is included with this library in the
file GIMPACT-LICENSE-LGPL.TXT. file GIMPACT-LICENSE-LGPL.TXT.
(2) The BSD-style license that is included with this library in (2) The BSD-style license that is included with this library in
the file GIMPACT-LICENSE-BSD.TXT. the file GIMPACT-LICENSE-BSD.TXT.
(3) The zlib/libpng license that is included with this library in (3) The zlib/libpng license that is included with this library in
the file GIMPACT-LICENSE-ZLIB.TXT. the file GIMPACT-LICENSE-ZLIB.TXT.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files 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. GIMPACT-LICENSE-LGPL.TXT, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
*/ */
///Additional Headers for Collision ///Additional Headers for Collision
#include "GIMPACT/core/gim_basic_geometry_operations.h" #include "gim_basic_geometry_operations.h"
#include "GIMPACT/core/gim_clip_polygon.h" #include "gim_clip_polygon.h"
#include "GIMPACT/core/gim_box_collision.h" #include "gim_box_collision.h"
#include "GIMPACT/core/gim_tri_collision.h" #include "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
#endif // GIM_VECTOR_H_INCLUDED

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,181 +1,181 @@
#ifndef GIM_MATH_H_INCLUDED #ifndef GIM_MATH_H_INCLUDED
#define GIM_MATH_H_INCLUDED #define GIM_MATH_H_INCLUDED
/*! \file gim_math.h /*! \file gim_math.h
\author Francisco León Nájera \author Francisco Len Nßjera
*/ */
/* /*
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
This source file is part of GIMPACT Library. This source file is part of GIMPACT Library.
For the latest info, see http://gimpact.sourceforge.net/ For the latest info, see http://gimpact.sourceforge.net/
Copyright (c) 2006 Francisco Leon Najera. C.C. 80087371. Copyright (c) 2006 Francisco Leon Najera. C.C. 80087371.
email: projectileman@yahoo.com email: projectileman@yahoo.com
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of EITHER: modify it under the terms of EITHER:
(1) The GNU Lesser General Public License as published by the Free (1) The GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at Software Foundation; either version 2.1 of the License, or (at
your option) any later version. The text of the GNU Lesser your option) any later version. The text of the GNU Lesser
General Public License is included with this library in the General Public License is included with this library in the
file GIMPACT-LICENSE-LGPL.TXT. file GIMPACT-LICENSE-LGPL.TXT.
(2) The BSD-style license that is included with this library in (2) The BSD-style license that is included with this library in
the file GIMPACT-LICENSE-BSD.TXT. the file GIMPACT-LICENSE-BSD.TXT.
(3) The zlib/libpng license that is included with this library in (3) The zlib/libpng license that is included with this library in
the file GIMPACT-LICENSE-ZLIB.TXT. the file GIMPACT-LICENSE-ZLIB.TXT.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files 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. GIMPACT-LICENSE-LGPL.TXT, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
*/ */
#include "LinearMath/btScalar.h" #include "LinearMath/btScalar.h"
/*! \defgroup BASIC_TYPES /*! \defgroup BASIC_TYPES
Basic types and constants Basic types and constants
Conventions: Conventions:
Types starting with G Types starting with G
Constants starting with G_ Constants starting with G_
*/ */
//! @{ //! @{
#define GREAL btScalar #define GREAL btScalar
#define GREAL2 double #define GREAL2 double
#define GINT int #define GINT int
#define GUINT unsigned int #define GUINT unsigned int
#define GSHORT short #define GSHORT short
#define GUSHORT unsigned short #define GUSHORT unsigned short
#define GINT64 long long #define GINT64 long long
#define GUINT64 unsigned long long #define GUINT64 unsigned long long
//! @} //! @}
/*! \defgroup BASIC_CONSTANTS /*! \defgroup BASIC_CONSTANTS
Basic constants Basic constants
Conventions: Conventions:
Types starting with G Types starting with G
Constants starting with G_ Constants starting with G_
*/ */
//! @{ //! @{
#define G_PI 3.14159265358979f #define G_PI 3.14159265358979f
#define G_HALF_PI 1.5707963f #define G_HALF_PI 1.5707963f
//267948966 //267948966
#define G_TWO_PI 6.28318530f #define G_TWO_PI 6.28318530f
//71795864 //71795864
#define G_ROOT3 1.73205f #define G_ROOT3 1.73205f
#define G_ROOT2 1.41421f #define G_ROOT2 1.41421f
#define G_UINT_INFINITY 0xffffffff //!< A very very high value #define G_UINT_INFINITY 0xffffffff //!< A very very high value
#define G_REAL_INFINITY FLT_MAX #define G_REAL_INFINITY FLT_MAX
#define G_SIGN_BITMASK 0x80000000 #define G_SIGN_BITMASK 0x80000000
#define G_EPSILON SIMD_EPSILON #define G_EPSILON SIMD_EPSILON
//! @} //! @}
/*! \defgroup SCALAR_TYPES /*! \defgroup SCALAR_TYPES
\brief \brief
Precision type constants Precision type constants
*/ */
//! @{ //! @{
enum GIM_SCALAR_TYPES enum GIM_SCALAR_TYPES
{ {
G_STYPE_REAL =0, G_STYPE_REAL =0,
G_STYPE_REAL2, G_STYPE_REAL2,
G_STYPE_SHORT, G_STYPE_SHORT,
G_STYPE_USHORT, G_STYPE_USHORT,
G_STYPE_INT, G_STYPE_INT,
G_STYPE_UINT, G_STYPE_UINT,
G_STYPE_INT64, G_STYPE_INT64,
G_STYPE_UINT64 G_STYPE_UINT64
}; };
//! @} //! @}
/*! \defgroup MATH_FUNCTIONS /*! \defgroup MATH_FUNCTIONS
mathematical functions mathematical functions
*/ */
//! @{ //! @{
#define G_DEGTORAD(X) ((X)*3.1415926f/180.0f) #define G_DEGTORAD(X) ((X)*3.1415926f/180.0f)
#define G_RADTODEG(X) ((X)*180.0f/3.1415926f) #define G_RADTODEG(X) ((X)*180.0f/3.1415926f)
//! Integer representation of a floating-point value. //! Integer representation of a floating-point value.
#define GIM_IR(x) ((GUINT&)(x)) #define GIM_IR(x) ((GUINT&)(x))
//! Signed integer representation of a floating-point value. //! Signed integer representation of a floating-point value.
#define GIM_SIR(x) ((GINT&)(x)) #define GIM_SIR(x) ((GINT&)(x))
//! Absolute integer representation of a floating-point value //! Absolute integer representation of a floating-point value
#define GIM_AIR(x) (GIM_IR(x)&0x7fffffff) #define GIM_AIR(x) (GIM_IR(x)&0x7fffffff)
//! Floating-point representation of an integer value. //! Floating-point representation of an integer value.
#define GIM_FR(x) ((GREAL&)(x)) #define GIM_FR(x) ((GREAL&)(x))
#define GIM_MAX(a,b) (a<b?b:a) #define GIM_MAX(a,b) (a<b?b:a)
#define GIM_MIN(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_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_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_ZERO(value) (value < G_EPSILON && value > -G_EPSILON)
#define GIM_IS_NEGATIVE(value) (value <= -G_EPSILON) #define GIM_IS_NEGATIVE(value) (value <= -G_EPSILON)
#define GIM_IS_POSISITVE(value) (value >= G_EPSILON) #define GIM_IS_POSISITVE(value) (value >= G_EPSILON)
#define GIM_NEAR_EQUAL(v1,v2) GIM_IS_ZERO((v1-v2)) #define GIM_NEAR_EQUAL(v1,v2) GIM_IS_ZERO((v1-v2))
///returns a clamped number ///returns a clamped number
#define GIM_CLAMP(number,minval,maxval) (number<minval?minval:(number>maxval?maxval:number)) #define GIM_CLAMP(number,minval,maxval) (number<minval?minval:(number>maxval?maxval:number))
#define GIM_GREATER(x, y) fabsf(x) > (y) #define GIM_GREATER(x, y) fabsf(x) > (y)
///Swap numbers ///Swap numbers
#define GIM_SWAP_NUMBERS(a,b){ \ #define GIM_SWAP_NUMBERS(a,b){ \
a = a+b; \ a = a+b; \
b = a-b; \ b = a-b; \
a = a-b; \ a = a-b; \
}\ }\
#define GIM_INV_SQRT(va,isva)\ #define GIM_INV_SQRT(va,isva)\
{\ {\
if(va<=0.0000001f)\ if(va<=0.0000001f)\
{\ {\
isva = G_REAL_INFINITY;\ isva = G_REAL_INFINITY;\
}\ }\
else\ else\
{\ {\
GREAL _x = va * 0.5f;\ GREAL _x = va * 0.5f;\
GUINT _y = 0x5f3759df - ( GIM_IR(va) >> 1);\ GUINT _y = 0x5f3759df - ( GIM_IR(va) >> 1);\
isva = GIM_FR(_y);\ isva = GIM_FR(_y);\
isva = isva * ( 1.5f - ( _x * isva * isva ) );\ isva = isva * ( 1.5f - ( _x * isva * isva ) );\
}\ }\
}\ }\
#define GIM_SQRT(va,sva)\ #define GIM_SQRT(va,sva)\
{\ {\
GIM_INV_SQRT(va,sva);\ GIM_INV_SQRT(va,sva);\
sva = 1.0f/sva;\ sva = 1.0f/sva;\
}\ }\
//! Computes 1.0f / sqrtf(x). Comes from Quake3. See http://www.magic-software.com/3DGEDInvSqrt.html //! Computes 1.0f / sqrtf(x). Comes from Quake3. See http://www.magic-software.com/3DGEDInvSqrt.html
inline GREAL gim_inv_sqrt(GREAL f) inline GREAL gim_inv_sqrt(GREAL f)
{ {
GREAL r; GREAL r;
GIM_INV_SQRT(f,r); GIM_INV_SQRT(f,r);
return r; return r;
} }
inline GREAL gim_sqrt(GREAL f) inline GREAL gim_sqrt(GREAL f)
{ {
GREAL r; GREAL r;
GIM_SQRT(f,r); GIM_SQRT(f,r);
return r; return r;
} }
//! @} //! @}
#endif // GIM_MATH_H_INCLUDED #endif // GIM_MATH_H_INCLUDED

View File

@@ -1,135 +1,135 @@
/* /*
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
This source file is part of GIMPACT Library. This source file is part of GIMPACT Library.
For the latest info, see http://gimpact.sourceforge.net/ For the latest info, see http://gimpact.sourceforge.net/
Copyright (c) 2006 Francisco Leon Najera. C.C. 80087371. Copyright (c) 2006 Francisco Leon Najera. C.C. 80087371.
email: projectileman@yahoo.com email: projectileman@yahoo.com
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of EITHER: modify it under the terms of EITHER:
(1) The GNU Lesser General Public License as published by the Free (1) The GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at Software Foundation; either version 2.1 of the License, or (at
your option) any later version. The text of the GNU Lesser your option) any later version. The text of the GNU Lesser
General Public License is included with this library in the General Public License is included with this library in the
file GIMPACT-LICENSE-LGPL.TXT. file GIMPACT-LICENSE-LGPL.TXT.
(2) The BSD-style license that is included with this library in (2) The BSD-style license that is included with this library in
the file GIMPACT-LICENSE-BSD.TXT. the file GIMPACT-LICENSE-BSD.TXT.
(3) The zlib/libpng license that is included with this library in (3) The zlib/libpng license that is included with this library in
the file GIMPACT-LICENSE-ZLIB.TXT. the file GIMPACT-LICENSE-ZLIB.TXT.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files 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. GIMPACT-LICENSE-LGPL.TXT, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
*/ */
#include "GIMPACT/core/gim_memory.h" #include "gim_memory.h"
#include "stdlib.h" #include "stdlib.h"
#ifdef GIM_SIMD_MEMORY #ifdef GIM_SIMD_MEMORY
#include "LinearMath/btAlignedAllocator.h" #include "LinearMath/btAlignedAllocator.h"
#endif #endif
static gim_alloc_function *g_allocfn = 0; static gim_alloc_function *g_allocfn = 0;
static gim_alloca_function *g_allocafn = 0; static gim_alloca_function *g_allocafn = 0;
static gim_realloc_function *g_reallocfn = 0; static gim_realloc_function *g_reallocfn = 0;
static gim_free_function *g_freefn = 0; static gim_free_function *g_freefn = 0;
void gim_set_alloc_handler (gim_alloc_function *fn) void gim_set_alloc_handler (gim_alloc_function *fn)
{ {
g_allocfn = fn; g_allocfn = fn;
} }
void gim_set_alloca_handler (gim_alloca_function *fn) void gim_set_alloca_handler (gim_alloca_function *fn)
{ {
g_allocafn = fn; g_allocafn = fn;
} }
void gim_set_realloc_handler (gim_realloc_function *fn) void gim_set_realloc_handler (gim_realloc_function *fn)
{ {
g_reallocfn = fn; g_reallocfn = fn;
} }
void gim_set_free_handler (gim_free_function *fn) void gim_set_free_handler (gim_free_function *fn)
{ {
g_freefn = fn; g_freefn = fn;
} }
gim_alloc_function *gim_get_alloc_handler() gim_alloc_function *gim_get_alloc_handler()
{ {
return g_allocfn; return g_allocfn;
} }
gim_alloca_function *gim_get_alloca_handler() gim_alloca_function *gim_get_alloca_handler()
{ {
return g_allocafn; return g_allocafn;
} }
gim_realloc_function *gim_get_realloc_handler () gim_realloc_function *gim_get_realloc_handler ()
{ {
return g_reallocfn; return g_reallocfn;
} }
gim_free_function *gim_get_free_handler () gim_free_function *gim_get_free_handler ()
{ {
return g_freefn; return g_freefn;
} }
void * gim_alloc(size_t size) void * gim_alloc(size_t size)
{ {
void * ptr; void * ptr;
if (g_allocfn) if (g_allocfn)
{ {
ptr = g_allocfn(size); ptr = g_allocfn(size);
} }
else else
{ {
#ifdef GIM_SIMD_MEMORY #ifdef GIM_SIMD_MEMORY
ptr = btAlignedAlloc(size,16); ptr = btAlignedAlloc(size,16);
#else #else
ptr = malloc(size); ptr = malloc(size);
#endif #endif
} }
return ptr; return ptr;
} }
void * gim_alloca(size_t size) void * gim_alloca(size_t size)
{ {
if (g_allocafn) return g_allocafn(size); else return gim_alloc(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 * gim_realloc(void *ptr, size_t oldsize, size_t newsize)
{ {
void * newptr = gim_alloc(newsize); void * newptr = gim_alloc(newsize);
size_t copysize = oldsize<newsize?oldsize:newsize; size_t copysize = oldsize<newsize?oldsize:newsize;
gim_simd_memcpy(newptr,ptr,copysize); gim_simd_memcpy(newptr,ptr,copysize);
gim_free(ptr); gim_free(ptr);
return newptr; return newptr;
} }
void gim_free(void *ptr) void gim_free(void *ptr)
{ {
if (!ptr) return; if (!ptr) return;
if (g_freefn) if (g_freefn)
{ {
g_freefn(ptr); g_freefn(ptr);
} }
else else
{ {
#ifdef GIM_SIMD_MEMORY #ifdef GIM_SIMD_MEMORY
btAlignedFree(ptr); btAlignedFree(ptr);
#else #else
free(ptr); free(ptr);
#endif #endif
} }
} }

View File

@@ -1,211 +1,211 @@
#ifndef GIM_MEMORY_H_INCLUDED #ifndef GIM_MEMORY_H_INCLUDED
#define GIM_MEMORY_H_INCLUDED #define GIM_MEMORY_H_INCLUDED
/*! \file gim_memory.h /*! \file gim_memory.h
\author Francisco León Nájera \author Francisco Len Nßjera
*/ */
/* /*
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
This source file is part of GIMPACT Library. This source file is part of GIMPACT Library.
For the latest info, see http://gimpact.sourceforge.net/ For the latest info, see http://gimpact.sourceforge.net/
Copyright (c) 2006 Francisco Leon Najera. C.C. 80087371. Copyright (c) 2006 Francisco Leon Najera. C.C. 80087371.
email: projectileman@yahoo.com email: projectileman@yahoo.com
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of EITHER: modify it under the terms of EITHER:
(1) The GNU Lesser General Public License as published by the Free (1) The GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at Software Foundation; either version 2.1 of the License, or (at
your option) any later version. The text of the GNU Lesser your option) any later version. The text of the GNU Lesser
General Public License is included with this library in the General Public License is included with this library in the
file GIMPACT-LICENSE-LGPL.TXT. file GIMPACT-LICENSE-LGPL.TXT.
(2) The BSD-style license that is included with this library in (2) The BSD-style license that is included with this library in
the file GIMPACT-LICENSE-BSD.TXT. the file GIMPACT-LICENSE-BSD.TXT.
(3) The zlib/libpng license that is included with this library in (3) The zlib/libpng license that is included with this library in
the file GIMPACT-LICENSE-ZLIB.TXT. the file GIMPACT-LICENSE-ZLIB.TXT.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files 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. GIMPACT-LICENSE-LGPL.TXT, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
*/ */
#include "GIMPACT/core/gim_math.h" #include "gim_math.h"
#include <memory.h> #include <memory.h>
//#define PREFETCH 1 //#define PREFETCH 1
//! \defgroup PREFETCH //! \defgroup PREFETCH
//! @{ //! @{
#ifdef PREFETCH #ifdef PREFETCH
#include <xmmintrin.h> // for prefetch #include <xmmintrin.h> // for prefetch
#define pfval 64 #define pfval 64
#define pfval2 128 #define pfval2 128
//! Prefetch 64 //! Prefetch 64
#define pf(_x,_i) _mm_prefetch((void *)(_x + _i + pfval), 0) #define pf(_x,_i) _mm_prefetch((void *)(_x + _i + pfval), 0)
//! Prefetch 128 //! Prefetch 128
#define pf2(_x,_i) _mm_prefetch((void *)(_x + _i + pfval2), 0) #define pf2(_x,_i) _mm_prefetch((void *)(_x + _i + pfval2), 0)
#else #else
//! Prefetch 64 //! Prefetch 64
#define pf(_x,_i) #define pf(_x,_i)
//! Prefetch 128 //! Prefetch 128
#define pf2(_x,_i) #define pf2(_x,_i)
#endif #endif
//! @} //! @}
/*! \defgroup ARRAY_UTILITIES /*! \defgroup ARRAY_UTILITIES
\brief \brief
Functions for manip packed arrays of numbers Functions for manip packed arrays of numbers
*/ */
//! @{ //! @{
#define GIM_COPY_ARRAYS(dest_array,source_array,element_count)\ #define GIM_COPY_ARRAYS(dest_array,source_array,element_count)\
{\ {\
for (GUINT _i_=0;_i_<element_count ;++_i_)\ for (GUINT _i_=0;_i_<element_count ;++_i_)\
{\ {\
dest_array[_i_] = source_array[_i_];\ dest_array[_i_] = source_array[_i_];\
}\ }\
}\ }\
#define GIM_COPY_ARRAYS_1(dest_array,source_array,element_count,copy_macro)\ #define GIM_COPY_ARRAYS_1(dest_array,source_array,element_count,copy_macro)\
{\ {\
for (GUINT _i_=0;_i_<element_count ;++_i_)\ for (GUINT _i_=0;_i_<element_count ;++_i_)\
{\ {\
copy_macro(dest_array[_i_],source_array[_i_]);\ copy_macro(dest_array[_i_],source_array[_i_]);\
}\ }\
}\ }\
#define GIM_ZERO_ARRAY(array,element_count)\ #define GIM_ZERO_ARRAY(array,element_count)\
{\ {\
for (GUINT _i_=0;_i_<element_count ;++_i_)\ for (GUINT _i_=0;_i_<element_count ;++_i_)\
{\ {\
array[_i_] = 0;\ array[_i_] = 0;\
}\ }\
}\ }\
#define GIM_CONSTANT_ARRAY(array,element_count,constant)\ #define GIM_CONSTANT_ARRAY(array,element_count,constant)\
{\ {\
for (GUINT _i_=0;_i_<element_count ;++_i_)\ for (GUINT _i_=0;_i_<element_count ;++_i_)\
{\ {\
array[_i_] = constant;\ array[_i_] = constant;\
}\ }\
}\ }\
//! @} //! @}
/*! \defgroup MEMORY_FUNCTION_PROTOTYPES /*! \defgroup MEMORY_FUNCTION_PROTOTYPES
Function prototypes to allocate and free memory. Function prototypes to allocate and free memory.
*/ */
//! @{ //! @{
typedef void * gim_alloc_function (size_t size); typedef void * gim_alloc_function (size_t size);
typedef void * gim_alloca_function (size_t size);//Allocs on the heap 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_realloc_function (void *ptr, size_t oldsize, size_t newsize);
typedef void gim_free_function (void *ptr); typedef void gim_free_function (void *ptr);
//! @} //! @}
/*! \defgroup MEMORY_FUNCTION_HANDLERS /*! \defgroup MEMORY_FUNCTION_HANDLERS
\brief \brief
Memory Function Handlers Memory Function Handlers
set new memory management functions. if fn is 0, the default handlers are set new memory management functions. if fn is 0, the default handlers are
used. */ used. */
//! @{ //! @{
void gim_set_alloc_handler (gim_alloc_function *fn); void gim_set_alloc_handler (gim_alloc_function *fn);
void gim_set_alloca_handler (gim_alloca_function *fn); void gim_set_alloca_handler (gim_alloca_function *fn);
void gim_set_realloc_handler (gim_realloc_function *fn); void gim_set_realloc_handler (gim_realloc_function *fn);
void gim_set_free_handler (gim_free_function *fn); void gim_set_free_handler (gim_free_function *fn);
//! @} //! @}
/*! \defgroup MEMORY_FUNCTION_GET_HANDLERS /*! \defgroup MEMORY_FUNCTION_GET_HANDLERS
\brief \brief
get current memory management functions. get current memory management functions.
*/ */
//! @{ //! @{
gim_alloc_function *gim_get_alloc_handler (void); gim_alloc_function *gim_get_alloc_handler (void);
gim_alloca_function *gim_get_alloca_handler(void); gim_alloca_function *gim_get_alloca_handler(void);
gim_realloc_function *gim_get_realloc_handler (void); gim_realloc_function *gim_get_realloc_handler (void);
gim_free_function *gim_get_free_handler (void); gim_free_function *gim_get_free_handler (void);
//! @} //! @}
/*! \defgroup MEMORY_FUNCTIONS /*! \defgroup MEMORY_FUNCTIONS
Standar Memory functions Standar Memory functions
*/ */
//! @{ //! @{
void * gim_alloc(size_t size); void * gim_alloc(size_t size);
void * gim_alloca(size_t size); void * gim_alloca(size_t size);
void * gim_realloc(void *ptr, size_t oldsize, size_t newsize); void * gim_realloc(void *ptr, size_t oldsize, size_t newsize);
void gim_free(void *ptr); void gim_free(void *ptr);
//! @} //! @}
#if defined (WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) #if defined (WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__)
#define GIM_SIMD_MEMORY 1 #define GIM_SIMD_MEMORY 1
#endif #endif
//! SIMD POINTER INTEGER //! SIMD POINTER INTEGER
#define SIMD_T GUINT64 #define SIMD_T GUINT64
//! SIMD INTEGER SIZE //! SIMD INTEGER SIZE
#define SIMD_T_SIZE sizeof(SIMD_T) #define SIMD_T_SIZE sizeof(SIMD_T)
inline void gim_simd_memcpy(void * dst, const void * src, size_t copysize) inline void gim_simd_memcpy(void * dst, const void * src, size_t copysize)
{ {
#ifdef GIM_SIMD_MEMORY #ifdef GIM_SIMD_MEMORY
/* /*
//'long long int' is incompatible with visual studio 6... //'long long int' is incompatible with visual studio 6...
//copy words //copy words
SIMD_T * ui_src_ptr = (SIMD_T *)src; SIMD_T * ui_src_ptr = (SIMD_T *)src;
SIMD_T * ui_dst_ptr = (SIMD_T *)dst; SIMD_T * ui_dst_ptr = (SIMD_T *)dst;
while(copysize>=SIMD_T_SIZE) while(copysize>=SIMD_T_SIZE)
{ {
*(ui_dst_ptr++) = *(ui_src_ptr++); *(ui_dst_ptr++) = *(ui_src_ptr++);
copysize-=SIMD_T_SIZE; copysize-=SIMD_T_SIZE;
} }
if(copysize==0) return; if(copysize==0) return;
*/ */
char * c_src_ptr = (char *)src; char * c_src_ptr = (char *)src;
char * c_dst_ptr = (char *)dst; char * c_dst_ptr = (char *)dst;
while(copysize>0) while(copysize>0)
{ {
*(c_dst_ptr++) = *(c_src_ptr++); *(c_dst_ptr++) = *(c_src_ptr++);
copysize--; copysize--;
} }
return; return;
#else #else
memcpy(dst,src,copysize); memcpy(dst,src,copysize);
#endif #endif
} }
template<class T> template<class T>
inline void gim_swap_elements(T* _array,size_t _i,size_t _j) inline void gim_swap_elements(T* _array,size_t _i,size_t _j)
{ {
T _e_tmp_ = _array[_i]; T _e_tmp_ = _array[_i];
_array[_i] = _array[_j]; _array[_i] = _array[_j];
_array[_j] = _e_tmp_; _array[_j] = _e_tmp_;
} }
template<class T> template<class T>
inline void gim_swap_elements_memcpy(T* _array,size_t _i,size_t _j) inline void gim_swap_elements_memcpy(T* _array,size_t _i,size_t _j)
{ {
char _e_tmp_[sizeof(T)]; char _e_tmp_[sizeof(T)];
gim_simd_memcpy(_e_tmp_,&_array[_i],sizeof(T)); gim_simd_memcpy(_e_tmp_,&_array[_i],sizeof(T));
gim_simd_memcpy(&_array[_i],&_array[_j],sizeof(T)); gim_simd_memcpy(&_array[_i],&_array[_j],sizeof(T));
gim_simd_memcpy(&_array[_j],_e_tmp_,sizeof(T)); gim_simd_memcpy(&_array[_j],_e_tmp_,sizeof(T));
} }
template <int SIZE> template <int SIZE>
inline void gim_swap_elements_ptr(char * _array,size_t _i,size_t _j) inline void gim_swap_elements_ptr(char * _array,size_t _i,size_t _j)
{ {
char _e_tmp_[SIZE]; char _e_tmp_[SIZE];
_i*=SIZE; _i*=SIZE;
_j*=SIZE; _j*=SIZE;
gim_simd_memcpy(_e_tmp_,_array+_i,SIZE); gim_simd_memcpy(_e_tmp_,_array+_i,SIZE);
gim_simd_memcpy(_array+_i,_array+_j,SIZE); gim_simd_memcpy(_array+_i,_array+_j,SIZE);
gim_simd_memcpy(_array+_j,_e_tmp_,SIZE); gim_simd_memcpy(_array+_j,_e_tmp_,SIZE);
} }
#endif // GIM_MEMORY_H_INCLUDED #endif // GIM_MEMORY_H_INCLUDED

View File

@@ -1,410 +1,410 @@
#ifndef GIM_RADIXSORT_H_INCLUDED #ifndef GIM_RADIXSORT_H_INCLUDED
#define GIM_RADIXSORT_H_INCLUDED #define GIM_RADIXSORT_H_INCLUDED
/*! \file gim_radixsort.h /*! \file gim_radixsort.h
\author Francisco León Nájera. \author Francisco Len Nßjera.
Based on the work of Michael Herf : "fast floating-point radix sort" Based on the work of Michael Herf : "fast floating-point radix sort"
Avaliable on http://www.stereopsis.com/radix.html Avaliable on http://www.stereopsis.com/radix.html
*/ */
/* /*
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
This source file is part of GIMPACT Library. This source file is part of GIMPACT Library.
For the latest info, see http://gimpact.sourceforge.net/ For the latest info, see http://gimpact.sourceforge.net/
Copyright (c) 2006 Francisco Leon Najera. C.C. 80087371. Copyright (c) 2006 Francisco Leon Najera. C.C. 80087371.
email: projectileman@yahoo.com email: projectileman@yahoo.com
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of EITHER: modify it under the terms of EITHER:
(1) The GNU Lesser General Public License as published by the Free (1) The GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at Software Foundation; either version 2.1 of the License, or (at
your option) any later version. The text of the GNU Lesser your option) any later version. The text of the GNU Lesser
General Public License is included with this library in the General Public License is included with this library in the
file GIMPACT-LICENSE-LGPL.TXT. file GIMPACT-LICENSE-LGPL.TXT.
(2) The BSD-style license that is included with this library in (2) The BSD-style license that is included with this library in
the file GIMPACT-LICENSE-BSD.TXT. the file GIMPACT-LICENSE-BSD.TXT.
(3) The zlib/libpng license that is included with this library in (3) The zlib/libpng license that is included with this library in
the file GIMPACT-LICENSE-ZLIB.TXT. the file GIMPACT-LICENSE-ZLIB.TXT.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files 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. GIMPACT-LICENSE-LGPL.TXT, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
*/ */
#include "GIMPACT/core/gim_memory.h" #include "gim_memory.h"
/*! \defgroup SORTING /*! \defgroup SORTING
\brief \brief
Macros for sorting. Macros for sorting.
*/ */
//! Prototype for comparators //! Prototype for comparators
class less_comparator class less_comparator
{ {
public: public:
template<class T,class Z> template<class T,class Z>
inline int operator() ( const T& a, const Z& b ) inline int operator() ( const T& a, const Z& b )
{ {
return ( a<b?-1:(a>b?1:0)); return ( a<b?-1:(a>b?1:0));
} }
}; };
//! Prototype for comparators //! Prototype for comparators
class integer_comparator class integer_comparator
{ {
public: public:
template<class T> template<class T>
inline int operator() ( const T& a, const T& b ) inline int operator() ( const T& a, const T& b )
{ {
return (int)(a-b); return (int)(a-b);
} }
}; };
//!Prototype for getting the integer representation of an object //!Prototype for getting the integer representation of an object
class uint_key_func class uint_key_func
{ {
public: public:
template<class T> template<class T>
inline GUINT operator()( const T& a) inline GUINT operator()( const T& a)
{ {
return (GUINT)a; return (GUINT)a;
} }
}; };
//!Prototype for copying elements //!Prototype for copying elements
class copy_elements_func class copy_elements_func
{ {
public: public:
template<class T> template<class T>
inline void operator()(T& a,T& b) inline void operator()(T& a,T& b)
{ {
a = b; a = b;
} }
}; };
//!Prototype for copying elements //!Prototype for copying elements
class memcopy_elements_func class memcopy_elements_func
{ {
public: public:
template<class T> template<class T>
inline void operator()(T& a,T& b) inline void operator()(T& a,T& b)
{ {
gim_simd_memcpy(&a,&b,sizeof(T)); gim_simd_memcpy(&a,&b,sizeof(T));
} }
}; };
//! @{ //! @{
struct GIM_RSORT_TOKEN struct GIM_RSORT_TOKEN
{ {
GUINT m_key; GUINT m_key;
GUINT m_value; GUINT m_value;
GIM_RSORT_TOKEN() GIM_RSORT_TOKEN()
{ {
} }
GIM_RSORT_TOKEN(const GIM_RSORT_TOKEN& rtoken) GIM_RSORT_TOKEN(const GIM_RSORT_TOKEN& rtoken)
{ {
m_key = rtoken.m_key; m_key = rtoken.m_key;
m_value = rtoken.m_value; m_value = rtoken.m_value;
} }
inline bool operator <(const GIM_RSORT_TOKEN& other) const inline bool operator <(const GIM_RSORT_TOKEN& other) const
{ {
return (m_key < other.m_key); return (m_key < other.m_key);
} }
inline bool operator >(const GIM_RSORT_TOKEN& other) const inline bool operator >(const GIM_RSORT_TOKEN& other) const
{ {
return (m_key > other.m_key); return (m_key > other.m_key);
} }
}; };
//! Prototype for comparators //! Prototype for comparators
class GIM_RSORT_TOKEN_COMPARATOR class GIM_RSORT_TOKEN_COMPARATOR
{ {
public: public:
inline int operator()( const GIM_RSORT_TOKEN& a, const GIM_RSORT_TOKEN& b ) inline int operator()( const GIM_RSORT_TOKEN& a, const GIM_RSORT_TOKEN& b )
{ {
return (int)((a.m_key) - (b.m_key)); return (int)((a.m_key) - (b.m_key));
} }
}; };
#define kHist 2048 #define kHist 2048
// ---- utils for accessing 11-bit quantities // ---- utils for accessing 11-bit quantities
#define D11_0(x) (x & 0x7FF) #define D11_0(x) (x & 0x7FF)
#define D11_1(x) (x >> 11 & 0x7FF) #define D11_1(x) (x >> 11 & 0x7FF)
#define D11_2(x) (x >> 22 ) #define D11_2(x) (x >> 22 )
///Radix sort for unsigned integer keys ///Radix sort for unsigned integer keys
inline void gim_radix_sort_rtokens( inline void gim_radix_sort_rtokens(
GIM_RSORT_TOKEN * array, GIM_RSORT_TOKEN * array,
GIM_RSORT_TOKEN * sorted, GUINT element_count) GIM_RSORT_TOKEN * sorted, GUINT element_count)
{ {
GUINT i; GUINT i;
GUINT b0[kHist * 3]; GUINT b0[kHist * 3];
GUINT *b1 = b0 + kHist; GUINT *b1 = b0 + kHist;
GUINT *b2 = b1 + kHist; GUINT *b2 = b1 + kHist;
for (i = 0; i < kHist * 3; ++i) for (i = 0; i < kHist * 3; ++i)
{ {
b0[i] = 0; b0[i] = 0;
} }
GUINT fi; GUINT fi;
GUINT pos; GUINT pos;
for (i = 0; i < element_count; ++i) for (i = 0; i < element_count; ++i)
{ {
fi = array[i].m_key; fi = array[i].m_key;
b0[D11_0(fi)] ++; b0[D11_0(fi)] ++;
b1[D11_1(fi)] ++; b1[D11_1(fi)] ++;
b2[D11_2(fi)] ++; b2[D11_2(fi)] ++;
} }
{ {
GUINT sum0 = 0, sum1 = 0, sum2 = 0; GUINT sum0 = 0, sum1 = 0, sum2 = 0;
GUINT tsum; GUINT tsum;
for (i = 0; i < kHist; ++i) for (i = 0; i < kHist; ++i)
{ {
tsum = b0[i] + sum0; tsum = b0[i] + sum0;
b0[i] = sum0 - 1; b0[i] = sum0 - 1;
sum0 = tsum; sum0 = tsum;
tsum = b1[i] + sum1; tsum = b1[i] + sum1;
b1[i] = sum1 - 1; b1[i] = sum1 - 1;
sum1 = tsum; sum1 = tsum;
tsum = b2[i] + sum2; tsum = b2[i] + sum2;
b2[i] = sum2 - 1; b2[i] = sum2 - 1;
sum2 = tsum; sum2 = tsum;
} }
} }
for (i = 0; i < element_count; ++i) for (i = 0; i < element_count; ++i)
{ {
fi = array[i].m_key; fi = array[i].m_key;
pos = D11_0(fi); pos = D11_0(fi);
pos = ++b0[pos]; pos = ++b0[pos];
sorted[pos].m_key = array[i].m_key; sorted[pos].m_key = array[i].m_key;
sorted[pos].m_value = array[i].m_value; sorted[pos].m_value = array[i].m_value;
} }
for (i = 0; i < element_count; ++i) for (i = 0; i < element_count; ++i)
{ {
fi = sorted[i].m_key; fi = sorted[i].m_key;
pos = D11_1(fi); pos = D11_1(fi);
pos = ++b1[pos]; pos = ++b1[pos];
array[pos].m_key = sorted[i].m_key; array[pos].m_key = sorted[i].m_key;
array[pos].m_value = sorted[i].m_value; array[pos].m_value = sorted[i].m_value;
} }
for (i = 0; i < element_count; ++i) for (i = 0; i < element_count; ++i)
{ {
fi = array[i].m_key; fi = array[i].m_key;
pos = D11_2(fi); pos = D11_2(fi);
pos = ++b2[pos]; pos = ++b2[pos];
sorted[pos].m_key = array[i].m_key; sorted[pos].m_key = array[i].m_key;
sorted[pos].m_value = array[i].m_value; sorted[pos].m_value = array[i].m_value;
} }
} }
/// Get the sorted tokens from an array. For generic use. Tokens are IRR_RSORT_TOKEN /// Get the sorted tokens from an array. For generic use. Tokens are IRR_RSORT_TOKEN
/*! /*!
*\param array Array of elements to sort *\param array Array of elements to sort
*\param sorted_tokens Tokens of sorted elements *\param sorted_tokens Tokens of sorted elements
*\param element_count element count *\param element_count element count
*\param uintkey_macro Functor which retrieves the integer representation of an array element *\param uintkey_macro Functor which retrieves the integer representation of an array element
*/ */
template<typename T, class GETKEY_CLASS> template<typename T, class GETKEY_CLASS>
void gim_radix_sort_array_tokens( void gim_radix_sort_array_tokens(
T* array , T* array ,
GIM_RSORT_TOKEN * sorted_tokens, GIM_RSORT_TOKEN * sorted_tokens,
GUINT element_count,GETKEY_CLASS uintkey_macro) GUINT element_count,GETKEY_CLASS uintkey_macro)
{ {
GIM_RSORT_TOKEN * _unsorted = (GIM_RSORT_TOKEN *) gim_alloc(sizeof(GIM_RSORT_TOKEN)*element_count); GIM_RSORT_TOKEN * _unsorted = (GIM_RSORT_TOKEN *) gim_alloc(sizeof(GIM_RSORT_TOKEN)*element_count);
for (GUINT _i=0;_i<element_count;++_i) for (GUINT _i=0;_i<element_count;++_i)
{ {
_unsorted[_i].m_key = uintkey_macro(array[_i]); _unsorted[_i].m_key = uintkey_macro(array[_i]);
_unsorted[_i].m_value = _i; _unsorted[_i].m_value = _i;
} }
gim_radix_sort_rtokens(_unsorted,sorted_tokens,element_count); gim_radix_sort_rtokens(_unsorted,sorted_tokens,element_count);
gim_free(_unsorted); gim_free(_unsorted);
gim_free(_unsorted); gim_free(_unsorted);
} }
/// Sorts array in place. For generic use /// Sorts array in place. For generic use
/*! /*!
\param type Type of the array \param type Type of the array
\param array \param array
\param element_count \param element_count
\param get_uintkey_macro Macro for extract the Integer value of the element. Similar to SIMPLE_GET_UINTKEY \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 \param copy_elements_macro Macro for copy elements, similar to SIMPLE_COPY_ELEMENTS
*/ */
template<typename T, class GETKEY_CLASS, class COPY_CLASS> template<typename T, class GETKEY_CLASS, class COPY_CLASS>
void gim_radix_sort( void gim_radix_sort(
T * array, GUINT element_count, T * array, GUINT element_count,
GETKEY_CLASS get_uintkey_macro, COPY_CLASS copy_elements_macro) 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_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); gim_radix_sort_array_tokens(array,_sorted,element_count,get_uintkey_macro);
T * _original_array = (T *) gim_alloc(sizeof(T)*element_count); T * _original_array = (T *) gim_alloc(sizeof(T)*element_count);
gim_simd_memcpy(_original_array,array,sizeof(T)*element_count); gim_simd_memcpy(_original_array,array,sizeof(T)*element_count);
for (GUINT _i=0;_i<element_count;++_i) for (GUINT _i=0;_i<element_count;++_i)
{ {
copy_elements_macro(array[_i],_original_array[_sorted[_i].m_value]); copy_elements_macro(array[_i],_original_array[_sorted[_i].m_value]);
} }
gim_free(_original_array); gim_free(_original_array);
gim_free(_sorted); gim_free(_sorted);
} }
//! Failsafe Iterative binary search, //! 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. 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 _array
\param _start_i the beginning of the array \param _start_i the beginning of the array
\param _end_i the ending index of the array \param _end_i the ending index of the array
\param _search_key Value to find \param _search_key Value to find
\param _comp_macro macro for comparing elements \param _comp_macro macro for comparing elements
\param _found If true the value has found. Boolean \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 \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> template<class T, typename KEYCLASS, typename COMP_CLASS>
bool gim_binary_search_ex( bool gim_binary_search_ex(
const T* _array, GUINT _start_i, const T* _array, GUINT _start_i,
GUINT _end_i,GUINT & _result_index, GUINT _end_i,GUINT & _result_index,
const KEYCLASS & _search_key, const KEYCLASS & _search_key,
COMP_CLASS _comp_macro) COMP_CLASS _comp_macro)
{ {
GUINT _k; GUINT _k;
int _comp_result; int _comp_result;
GUINT _i = _start_i; GUINT _i = _start_i;
GUINT _j = _end_i+1; GUINT _j = _end_i+1;
while (_i < _j) while (_i < _j)
{ {
_k = (_j+_i-1)/2; _k = (_j+_i-1)/2;
_comp_result = _comp_macro(_array[_k], _search_key); _comp_result = _comp_macro(_array[_k], _search_key);
if (_comp_result == 0) if (_comp_result == 0)
{ {
_result_index = _k; _result_index = _k;
return true; return true;
} }
else if (_comp_result < 0) else if (_comp_result < 0)
{ {
_i = _k+1; _i = _k+1;
} }
else else
{ {
_j = _k; _j = _k;
} }
} }
_result_index = _i; _result_index = _i;
return false; return false;
} }
//! Failsafe Iterative binary search,Template version //! 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. 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 _array
\param _start_i the beginning of the array \param _start_i the beginning of the array
\param _end_i the ending index of the array \param _end_i the ending index of the array
\param _search_key Value to find \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 \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 \return true if found, else false
*/ */
template<class T> template<class T>
bool gim_binary_search( bool gim_binary_search(
const T*_array,GUINT _start_i, const T*_array,GUINT _start_i,
GUINT _end_i,const T & _search_key, GUINT _end_i,const T & _search_key,
GUINT & _result_index) GUINT & _result_index)
{ {
GUINT _i = _start_i; GUINT _i = _start_i;
GUINT _j = _end_i+1; GUINT _j = _end_i+1;
GUINT _k; GUINT _k;
while(_i < _j) while(_i < _j)
{ {
_k = (_j+_i-1)/2; _k = (_j+_i-1)/2;
if(_array[_k]==_search_key) if(_array[_k]==_search_key)
{ {
_result_index = _k; _result_index = _k;
return true; return true;
} }
else if (_array[_k]<_search_key) else if (_array[_k]<_search_key)
{ {
_i = _k+1; _i = _k+1;
} }
else else
{ {
_j = _k; _j = _k;
} }
} }
_result_index = _i; _result_index = _i;
return false; return false;
} }
///heap sort from http://www.csse.monash.edu.au/~lloyd/tildeAlgDS/Sort/Heap/ ///heap sort from http://www.csse.monash.edu.au/~lloyd/tildeAlgDS/Sort/Heap/
template <typename T, typename COMP_CLASS> template <typename T, typename COMP_CLASS>
void gim_down_heap(T *pArr, GUINT k, GUINT n,COMP_CLASS CompareFunc) void gim_down_heap(T *pArr, GUINT k, GUINT n,COMP_CLASS CompareFunc)
{ {
/* PRE: a[k+1..N] is a heap */ /* PRE: a[k+1..N] is a heap */
/* POST: a[k..N] is a heap */ /* POST: a[k..N] is a heap */
T temp = pArr[k - 1]; T temp = pArr[k - 1];
/* k has child(s) */ /* k has child(s) */
while (k <= n/2) while (k <= n/2)
{ {
int child = 2*k; int child = 2*k;
if ((child < (int)n) && CompareFunc(pArr[child - 1] , pArr[child])<0) if ((child < (int)n) && CompareFunc(pArr[child - 1] , pArr[child])<0)
{ {
child++; child++;
} }
/* pick larger child */ /* pick larger child */
if (CompareFunc(temp , pArr[child - 1])<0) if (CompareFunc(temp , pArr[child - 1])<0)
{ {
/* move child up */ /* move child up */
pArr[k - 1] = pArr[child - 1]; pArr[k - 1] = pArr[child - 1];
k = child; k = child;
} }
else else
{ {
break; break;
} }
} }
pArr[k - 1] = temp; pArr[k - 1] = temp;
} /*downHeap*/ } /*downHeap*/
template <typename T, typename COMP_CLASS> template <typename T, typename COMP_CLASS>
void gim_heap_sort(T *pArr, GUINT element_count, COMP_CLASS CompareFunc) void gim_heap_sort(T *pArr, GUINT element_count, COMP_CLASS CompareFunc)
{ {
/* sort a[0..N-1], N.B. 0 to N-1 */ /* sort a[0..N-1], N.B. 0 to N-1 */
GUINT k; GUINT k;
GUINT n = element_count; GUINT n = element_count;
for (k = n/2; k > 0; k--) for (k = n/2; k > 0; k--)
{ {
gim_down_heap(pArr, k, n, CompareFunc); gim_down_heap(pArr, k, n, CompareFunc);
} }
/* a[1..N] is now a heap */ /* a[1..N] is now a heap */
while ( n>=2 ) while ( n>=2 )
{ {
gim_swap_elements(pArr,0,n-1); /* largest of a[0..n-1] */ gim_swap_elements(pArr,0,n-1); /* largest of a[0..n-1] */
--n; --n;
/* restore a[1..i-1] heap */ /* restore a[1..i-1] heap */
gim_down_heap(pArr, 1, n, CompareFunc); gim_down_heap(pArr, 1, n, CompareFunc);
} }
} }
//! @} //! @}
#endif // GIM_RADIXSORT_H_INCLUDED #endif // GIM_RADIXSORT_H_INCLUDED

File diff suppressed because it is too large Load Diff

View File

@@ -1,383 +1,383 @@
#ifndef GIM_TRI_COLLISION_H_INCLUDED #ifndef GIM_TRI_COLLISION_H_INCLUDED
#define GIM_TRI_COLLISION_H_INCLUDED #define GIM_TRI_COLLISION_H_INCLUDED
/*! \file gim_tri_collision.h /*! \file gim_tri_collision.h
\author Francisco León Nájera \author Francisco Len Nßjera
*/ */
/* /*
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
This source file is part of GIMPACT Library. This source file is part of GIMPACT Library.
For the latest info, see http://gimpact.sourceforge.net/ For the latest info, see http://gimpact.sourceforge.net/
Copyright (c) 2006 Francisco Leon Najera. C.C. 80087371. Copyright (c) 2006 Francisco Leon Najera. C.C. 80087371.
email: projectileman@yahoo.com email: projectileman@yahoo.com
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of EITHER: modify it under the terms of EITHER:
(1) The GNU Lesser General Public License as published by the Free (1) The GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at Software Foundation; either version 2.1 of the License, or (at
your option) any later version. The text of the GNU Lesser your option) any later version. The text of the GNU Lesser
General Public License is included with this library in the General Public License is included with this library in the
file GIMPACT-LICENSE-LGPL.TXT. file GIMPACT-LICENSE-LGPL.TXT.
(2) The BSD-style license that is included with this library in (2) The BSD-style license that is included with this library in
the file GIMPACT-LICENSE-BSD.TXT. the file GIMPACT-LICENSE-BSD.TXT.
(3) The zlib/libpng license that is included with this library in (3) The zlib/libpng license that is included with this library in
the file GIMPACT-LICENSE-ZLIB.TXT. the file GIMPACT-LICENSE-ZLIB.TXT.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files 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. GIMPACT-LICENSE-LGPL.TXT, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
*/ */
#include "GIMPACT/core/gim_box_collision.h" #include "gim_box_collision.h"
#include "GIMPACT/core/gim_clip_polygon.h" #include "gim_clip_polygon.h"
/*! \addtogroup GEOMETRIC_OPERATIONS /*! \addtogroup GEOMETRIC_OPERATIONS
*/ */
//! @{ //! @{
#define MAX_TRI_CLIPPING 16 #define MAX_TRI_CLIPPING 16
//! Structure for collision //! Structure for collision
struct GIM_TRIANGLE_CONTACT_DATA struct GIM_TRIANGLE_CONTACT_DATA
{ {
GREAL m_penetration_depth; GREAL m_penetration_depth;
GUINT m_point_count; GUINT m_point_count;
btVector4 m_separating_normal; btVector4 m_separating_normal;
btVector3 m_points[MAX_TRI_CLIPPING]; btVector3 m_points[MAX_TRI_CLIPPING];
SIMD_FORCE_INLINE void copy_from(const GIM_TRIANGLE_CONTACT_DATA& other) SIMD_FORCE_INLINE void copy_from(const GIM_TRIANGLE_CONTACT_DATA& other)
{ {
m_penetration_depth = other.m_penetration_depth; m_penetration_depth = other.m_penetration_depth;
m_separating_normal = other.m_separating_normal; m_separating_normal = other.m_separating_normal;
m_point_count = other.m_point_count; m_point_count = other.m_point_count;
GUINT i = m_point_count; GUINT i = m_point_count;
while(i--) while(i--)
{ {
m_points[i] = other.m_points[i]; m_points[i] = other.m_points[i];
} }
} }
GIM_TRIANGLE_CONTACT_DATA() GIM_TRIANGLE_CONTACT_DATA()
{ {
} }
GIM_TRIANGLE_CONTACT_DATA(const GIM_TRIANGLE_CONTACT_DATA& other) GIM_TRIANGLE_CONTACT_DATA(const GIM_TRIANGLE_CONTACT_DATA& other)
{ {
copy_from(other); copy_from(other);
} }
//! classify points that are closer //! classify points that are closer
template<typename DISTANCE_FUNC,typename CLASS_PLANE> template<typename DISTANCE_FUNC,typename CLASS_PLANE>
SIMD_FORCE_INLINE void mergepoints_generic(const CLASS_PLANE & plane, SIMD_FORCE_INLINE void mergepoints_generic(const CLASS_PLANE & plane,
GREAL margin, const btVector3 * points, GUINT point_count, DISTANCE_FUNC distance_func) GREAL margin, const btVector3 * points, GUINT point_count, DISTANCE_FUNC distance_func)
{ {
m_point_count = 0; m_point_count = 0;
m_penetration_depth= -1000.0f; m_penetration_depth= -1000.0f;
GUINT point_indices[MAX_TRI_CLIPPING]; GUINT point_indices[MAX_TRI_CLIPPING];
GUINT _k; GUINT _k;
for(_k=0;_k<point_count;_k++) for(_k=0;_k<point_count;_k++)
{ {
GREAL _dist = -distance_func(plane,points[_k]) + margin; GREAL _dist = -distance_func(plane,points[_k]) + margin;
if(_dist>=0.0f) if(_dist>=0.0f)
{ {
if(_dist>m_penetration_depth) if(_dist>m_penetration_depth)
{ {
m_penetration_depth = _dist; m_penetration_depth = _dist;
point_indices[0] = _k; point_indices[0] = _k;
m_point_count=1; m_point_count=1;
} }
else if((_dist+G_EPSILON)>=m_penetration_depth) else if((_dist+G_EPSILON)>=m_penetration_depth)
{ {
point_indices[m_point_count] = _k; point_indices[m_point_count] = _k;
m_point_count++; m_point_count++;
} }
} }
} }
for( _k=0;_k<m_point_count;_k++) for( _k=0;_k<m_point_count;_k++)
{ {
m_points[_k] = points[point_indices[_k]]; m_points[_k] = points[point_indices[_k]];
} }
} }
//! classify points that are closer //! classify points that are closer
SIMD_FORCE_INLINE void merge_points(const btVector4 & plane, GREAL margin, SIMD_FORCE_INLINE void merge_points(const btVector4 & plane, GREAL margin,
const btVector3 * points, GUINT point_count) const btVector3 * points, GUINT point_count)
{ {
m_separating_normal = plane; m_separating_normal = plane;
mergepoints_generic(plane, margin, points, point_count, DISTANCE_PLANE_3D_FUNC()); mergepoints_generic(plane, margin, points, point_count, DISTANCE_PLANE_3D_FUNC());
} }
}; };
//! Class for colliding triangles //! Class for colliding triangles
class GIM_TRIANGLE class GIM_TRIANGLE
{ {
public: public:
btScalar m_margin; btScalar m_margin;
btVector3 m_vertices[3]; btVector3 m_vertices[3];
GIM_TRIANGLE():m_margin(0.1f) GIM_TRIANGLE():m_margin(0.1f)
{ {
} }
SIMD_FORCE_INLINE GIM_AABB get_box() const SIMD_FORCE_INLINE GIM_AABB get_box() const
{ {
return GIM_AABB(m_vertices[0],m_vertices[1],m_vertices[2],m_margin); return GIM_AABB(m_vertices[0],m_vertices[1],m_vertices[2],m_margin);
} }
SIMD_FORCE_INLINE void get_normal(btVector3 &normal) const SIMD_FORCE_INLINE void get_normal(btVector3 &normal) const
{ {
TRIANGLE_NORMAL(m_vertices[0],m_vertices[1],m_vertices[2],normal); TRIANGLE_NORMAL(m_vertices[0],m_vertices[1],m_vertices[2],normal);
} }
SIMD_FORCE_INLINE void get_plane(btVector4 &plane) const SIMD_FORCE_INLINE void get_plane(btVector4 &plane) const
{ {
TRIANGLE_PLANE(m_vertices[0],m_vertices[1],m_vertices[2],plane);; TRIANGLE_PLANE(m_vertices[0],m_vertices[1],m_vertices[2],plane);;
} }
SIMD_FORCE_INLINE void apply_transform(const btTransform & trans) SIMD_FORCE_INLINE void apply_transform(const btTransform & trans)
{ {
m_vertices[0] = trans(m_vertices[0]); m_vertices[0] = trans(m_vertices[0]);
m_vertices[1] = trans(m_vertices[1]); m_vertices[1] = trans(m_vertices[1]);
m_vertices[2] = trans(m_vertices[2]); m_vertices[2] = trans(m_vertices[2]);
} }
SIMD_FORCE_INLINE void get_edge_plane(GUINT edge_index,const btVector3 &triangle_normal,btVector4 &plane) const 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 & e0 = m_vertices[edge_index];
const btVector3 & e1 = m_vertices[(edge_index+1)%3]; const btVector3 & e1 = m_vertices[(edge_index+1)%3];
EDGE_PLANE(e0,e1,triangle_normal,plane); EDGE_PLANE(e0,e1,triangle_normal,plane);
} }
//! Gets the relative transformation of this triangle //! 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: 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. - triangle normal corresponds to Z axis.
- 1st normalized edge corresponds to X axis, - 1st normalized edge corresponds to X axis,
*/ */
SIMD_FORCE_INLINE void get_triangle_transform(btTransform & triangle_transform) const SIMD_FORCE_INLINE void get_triangle_transform(btTransform & triangle_transform) const
{ {
btMatrix3x3 & matrix = triangle_transform.getBasis(); btMatrix3x3 & matrix = triangle_transform.getBasis();
btVector3 zaxis; btVector3 zaxis;
get_normal(zaxis); get_normal(zaxis);
MAT_SET_Z(matrix,zaxis); MAT_SET_Z(matrix,zaxis);
btVector3 xaxis = m_vertices[1] - m_vertices[0]; btVector3 xaxis = m_vertices[1] - m_vertices[0];
VEC_NORMALIZE(xaxis); VEC_NORMALIZE(xaxis);
MAT_SET_X(matrix,xaxis); MAT_SET_X(matrix,xaxis);
//y axis //y axis
xaxis = zaxis.cross(xaxis); xaxis = zaxis.cross(xaxis);
MAT_SET_Y(matrix,xaxis); MAT_SET_Y(matrix,xaxis);
triangle_transform.setOrigin(m_vertices[0]); triangle_transform.setOrigin(m_vertices[0]);
} }
//! Test triangles by finding separating axis //! Test triangles by finding separating axis
/*! /*!
\param other Triangle for collide \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 \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( bool collide_triangle_hard_test(
const GIM_TRIANGLE & other, const GIM_TRIANGLE & other,
GIM_TRIANGLE_CONTACT_DATA & contact_data) const; GIM_TRIANGLE_CONTACT_DATA & contact_data) const;
//! Test boxes before doing hard test //! Test boxes before doing hard test
/*! /*!
\param other Triangle for collide \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 \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( SIMD_FORCE_INLINE bool collide_triangle(
const GIM_TRIANGLE & other, const GIM_TRIANGLE & other,
GIM_TRIANGLE_CONTACT_DATA & contact_data) const GIM_TRIANGLE_CONTACT_DATA & contact_data) const
{ {
//test box collisioin //test box collisioin
GIM_AABB boxu(m_vertices[0],m_vertices[1],m_vertices[2],m_margin); 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); 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; if(!boxu.has_collision(boxv)) return false;
//do hard test //do hard test
return collide_triangle_hard_test(other,contact_data); return collide_triangle_hard_test(other,contact_data);
} }
/*! /*!
Solve the System for u,v parameters: Solve the System for u,v parameters:
u*axe1[i1] + v*axe2[i1] = vecproj[i1] u*axe1[i1] + v*axe2[i1] = vecproj[i1]
u*axe1[i2] + v*axe2[i2] = vecproj[i2] u*axe1[i2] + v*axe2[i2] = vecproj[i2]
sustitute: sustitute:
v = (vecproj[i2] - u*axe1[i2])/axe2[i2] v = (vecproj[i2] - u*axe1[i2])/axe2[i2]
then the first equation in terms of 'u': 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] - 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] + 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] - 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])/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*(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]) --> 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 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 \return false if the point is outside of triangle.This function doesn't take the margin
*/ */
SIMD_FORCE_INLINE bool get_uv_parameters( SIMD_FORCE_INLINE bool get_uv_parameters(
const btVector3 & point, const btVector3 & point,
const btVector3 & tri_plane, const btVector3 & tri_plane,
GREAL & u, GREAL & v) const GREAL & u, GREAL & v) const
{ {
btVector3 _axe1 = m_vertices[1]-m_vertices[0]; btVector3 _axe1 = m_vertices[1]-m_vertices[0];
btVector3 _axe2 = m_vertices[2]-m_vertices[0]; btVector3 _axe2 = m_vertices[2]-m_vertices[0];
btVector3 _vecproj = point - m_vertices[0]; btVector3 _vecproj = point - m_vertices[0];
GUINT _i1 = (tri_plane.closestAxis()+1)%3; GUINT _i1 = (tri_plane.closestAxis()+1)%3;
GUINT _i2 = (_i1+1)%3; GUINT _i2 = (_i1+1)%3;
if(btFabs(_axe2[_i2])<G_EPSILON) if(btFabs(_axe2[_i2])<G_EPSILON)
{ {
u = (_vecproj[_i2]*_axe2[_i1] - _vecproj[_i1]*_axe2[_i2]) /(_axe1[_i2]*_axe2[_i1] - _axe1[_i1]*_axe2[_i2]); 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]; v = (_vecproj[_i1] - u*_axe1[_i1])/_axe2[_i1];
} }
else else
{ {
u = (_vecproj[_i1]*_axe2[_i2] - _vecproj[_i2]*_axe2[_i1]) /(_axe1[_i1]*_axe2[_i2] - _axe1[_i2]*_axe2[_i1]); 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]; v = (_vecproj[_i2] - u*_axe1[_i2])/_axe2[_i2];
} }
if(u<-G_EPSILON) if(u<-G_EPSILON)
{ {
return false; return false;
} }
else if(v<-G_EPSILON) else if(v<-G_EPSILON)
{ {
return false; return false;
} }
else else
{ {
float sumuv; float sumuv;
sumuv = u+v; sumuv = u+v;
if(sumuv<-G_EPSILON) if(sumuv<-G_EPSILON)
{ {
return false; return false;
} }
else if(sumuv-1.0f>G_EPSILON) else if(sumuv-1.0f>G_EPSILON)
{ {
return false; return false;
} }
} }
return true; return true;
} }
//! is point in triangle beam? //! is point in triangle beam?
/*! /*!
Test if point is in triangle, with m_margin tolerance 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 SIMD_FORCE_INLINE bool is_point_inside(const btVector3 & point, const btVector3 & tri_normal) const
{ {
//Test with edge 0 //Test with edge 0
btVector4 edge_plane; btVector4 edge_plane;
this->get_edge_plane(0,tri_normal,edge_plane); this->get_edge_plane(0,tri_normal,edge_plane);
GREAL dist = DISTANCE_PLANE_POINT(edge_plane,point); GREAL dist = DISTANCE_PLANE_POINT(edge_plane,point);
if(dist-m_margin>0.0f) return false; // outside plane if(dist-m_margin>0.0f) return false; // outside plane
this->get_edge_plane(1,tri_normal,edge_plane); this->get_edge_plane(1,tri_normal,edge_plane);
dist = DISTANCE_PLANE_POINT(edge_plane,point); dist = DISTANCE_PLANE_POINT(edge_plane,point);
if(dist-m_margin>0.0f) return false; // outside plane if(dist-m_margin>0.0f) return false; // outside plane
this->get_edge_plane(2,tri_normal,edge_plane); this->get_edge_plane(2,tri_normal,edge_plane);
dist = DISTANCE_PLANE_POINT(edge_plane,point); dist = DISTANCE_PLANE_POINT(edge_plane,point);
if(dist-m_margin>0.0f) return false; // outside plane if(dist-m_margin>0.0f) return false; // outside plane
return true; return true;
} }
//! Bidireccional ray collision //! Bidireccional ray collision
SIMD_FORCE_INLINE bool ray_collision( SIMD_FORCE_INLINE bool ray_collision(
const btVector3 & vPoint, const btVector3 & vPoint,
const btVector3 & vDir, btVector3 & pout, btVector3 & triangle_normal, const btVector3 & vDir, btVector3 & pout, btVector3 & triangle_normal,
GREAL & tparam, GREAL tmax = G_REAL_INFINITY) GREAL & tparam, GREAL tmax = G_REAL_INFINITY)
{ {
btVector4 faceplane; btVector4 faceplane;
{ {
btVector3 dif1 = m_vertices[1] - m_vertices[0]; btVector3 dif1 = m_vertices[1] - m_vertices[0];
btVector3 dif2 = m_vertices[2] - m_vertices[0]; btVector3 dif2 = m_vertices[2] - m_vertices[0];
VEC_CROSS(faceplane,dif1,dif2); VEC_CROSS(faceplane,dif1,dif2);
faceplane[3] = m_vertices[0].dot(faceplane); faceplane[3] = m_vertices[0].dot(faceplane);
} }
GUINT res = LINE_PLANE_COLLISION(faceplane,vDir,vPoint,pout,tparam, btScalar(0), tmax); GUINT res = LINE_PLANE_COLLISION(faceplane,vDir,vPoint,pout,tparam, btScalar(0), tmax);
if(res == 0) return false; if(res == 0) return false;
if(! is_point_inside(pout,faceplane)) return false; if(! is_point_inside(pout,faceplane)) return false;
if(res==2) //invert normal if(res==2) //invert normal
{ {
triangle_normal.setValue(-faceplane[0],-faceplane[1],-faceplane[2]); triangle_normal.setValue(-faceplane[0],-faceplane[1],-faceplane[2]);
} }
else else
{ {
triangle_normal.setValue(faceplane[0],faceplane[1],faceplane[2]); triangle_normal.setValue(faceplane[0],faceplane[1],faceplane[2]);
} }
VEC_NORMALIZE(triangle_normal); VEC_NORMALIZE(triangle_normal);
return true; return true;
} }
//! one direccion ray collision //! one direccion ray collision
SIMD_FORCE_INLINE bool ray_collision_front_side( SIMD_FORCE_INLINE bool ray_collision_front_side(
const btVector3 & vPoint, const btVector3 & vPoint,
const btVector3 & vDir, btVector3 & pout, btVector3 & triangle_normal, const btVector3 & vDir, btVector3 & pout, btVector3 & triangle_normal,
GREAL & tparam, GREAL tmax = G_REAL_INFINITY) GREAL & tparam, GREAL tmax = G_REAL_INFINITY)
{ {
btVector4 faceplane; btVector4 faceplane;
{ {
btVector3 dif1 = m_vertices[1] - m_vertices[0]; btVector3 dif1 = m_vertices[1] - m_vertices[0];
btVector3 dif2 = m_vertices[2] - m_vertices[0]; btVector3 dif2 = m_vertices[2] - m_vertices[0];
VEC_CROSS(faceplane,dif1,dif2); VEC_CROSS(faceplane,dif1,dif2);
faceplane[3] = m_vertices[0].dot(faceplane); faceplane[3] = m_vertices[0].dot(faceplane);
} }
GUINT res = LINE_PLANE_COLLISION(faceplane,vDir,vPoint,pout,tparam, btScalar(0), tmax); GUINT res = LINE_PLANE_COLLISION(faceplane,vDir,vPoint,pout,tparam, btScalar(0), tmax);
if(res != 1) return false; if(res != 1) return false;
if(!is_point_inside(pout,faceplane)) return false; if(!is_point_inside(pout,faceplane)) return false;
triangle_normal.setValue(faceplane[0],faceplane[1],faceplane[2]); triangle_normal.setValue(faceplane[0],faceplane[1],faceplane[2]);
VEC_NORMALIZE(triangle_normal); VEC_NORMALIZE(triangle_normal);
return true; return true;
} }
}; };
//! @} //! @}
#endif // GIM_TRI_COLLISION_H_INCLUDED #endif // GIM_TRI_COLLISION_H_INCLUDED

Some files were not shown because too many files have changed in this diff Show More