converted files to UNIX EOL

This commit is contained in:
ejcoumans
2007-08-21 04:06:39 +00:00
parent 4171d02b99
commit dbdc2a812f
78 changed files with 83697 additions and 83697 deletions

View File

@@ -1,31 +1,31 @@
Vector Math library for 3-D linear algebra (vector, matrix, quaternion) Vector Math library for 3-D linear algebra (vector, matrix, quaternion)
SIMD support for SSE, PowerPC (PPU) and the SPU. SIMD support for SSE, PowerPC (PPU) and the SPU.
Also includes generic multi-platform scalar version. Also includes generic multi-platform scalar version.
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc. Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the with or without modification, are permitted provided that the
following conditions are met: following conditions are met:
* Redistributions of source code must retain the above copyright * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright * Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names * Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission. from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.

View File

@@ -1,119 +1,119 @@
# Makefile for vector math library. # Makefile for vector math library.
# #
# Copyright (C) 2006, 2007 Sony Computer Entertainment Inc. # Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, # Redistribution and use in source and binary forms,
# with or without modification, are permitted provided that the # with or without modification, are permitted provided that the
# following conditions are met: # following conditions are met:
# * Redistributions of source code must retain the above copyright # * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer. # notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright # * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the # notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution. # documentation and/or other materials provided with the distribution.
# * Neither the name of the Sony Computer Entertainment Inc nor the names # * Neither the name of the Sony Computer Entertainment Inc nor the names
# of its contributors may be used to endorse or promote products derived # of its contributors may be used to endorse or promote products derived
# from this software without specific prior written permission. # from this software without specific prior written permission.
# #
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # 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 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE. # POSSIBILITY OF SUCH DAMAGE.
# How to build: # How to build:
# #
# Nothing to do (The all of the library is implemented as inline). # Nothing to do (The all of the library is implemented as inline).
# #
# How to install: # How to install:
# #
# To install the library: # To install the library:
# #
# make ARCH=<ARCHITECTURE> install # make ARCH=<ARCHITECTURE> install
# #
# where <ARCHITECTURE> must be one of: # where <ARCHITECTURE> must be one of:
# #
# ppu (PowerPC) # ppu (PowerPC)
# spu # spu
# SSE # SSE
# scalar (generic) # scalar (generic)
# #
# e.g.) make ARCH=cell install # e.g.) make ARCH=cell install
# #
topdir = . topdir = .
ARCH = scalar ARCH = scalar
prefix_spu = /usr/spu prefix_spu = /usr/spu
ARCH_DIRS = $(ARCH) ARCH_DIRS = $(ARCH)
ARCH_INSTALL= $(ARCH_INSTALL_$(ARCH)) ARCH_INSTALL= $(ARCH_INSTALL_$(ARCH))
ARCH_CHECK= $(ARCH_CHECK_$(ARCH)) ARCH_CHECK= $(ARCH_CHECK_$(ARCH))
prefix = $(if $(prefix_$(ARCH)),$(prefix_$(ARCH)),/usr) prefix = $(if $(prefix_$(ARCH)),$(prefix_$(ARCH)),/usr)
DESTDIR = DESTDIR =
COMMON_DIRS = scalar COMMON_DIRS = scalar
INSTALL = install INSTALL = install
LIB_MAJOR_VERSION = 1 LIB_MAJOR_VERSION = 1
LIB_MINOR_VERSION = 0 LIB_MINOR_VERSION = 0
LIB_RELEASE = 1 LIB_RELEASE = 1
LIB_FULL_VERSION = $(LIB_MAJOR_VERSION).$(LIB_MINOR_VERSION).$(LIB_RELEASE) LIB_FULL_VERSION = $(LIB_MAJOR_VERSION).$(LIB_MINOR_VERSION).$(LIB_RELEASE)
LIB_BASE = vectormath LIB_BASE = vectormath
TAR_NAME = $(LIB_BASE)-$(LIB_FULL_VERSION) TAR_NAME = $(LIB_BASE)-$(LIB_FULL_VERSION)
TAR_BALL = $(TAR_NAME).tar.gz TAR_BALL = $(TAR_NAME).tar.gz
all: all:
@true @true
install: install:
$(INSTALL) -m 755 -d $(DESTDIR)$(prefix)/include/vectormath/c $(INSTALL) -m 755 -d $(DESTDIR)$(prefix)/include/vectormath/c
$(INSTALL) -m 755 -d $(DESTDIR)$(prefix)/include/vectormath/cpp $(INSTALL) -m 755 -d $(DESTDIR)$(prefix)/include/vectormath/cpp
$(INSTALL) -m 644 include/vectormath/c/*.h $(DESTDIR)$(prefix)/include/vectormath/c/ $(INSTALL) -m 644 include/vectormath/c/*.h $(DESTDIR)$(prefix)/include/vectormath/c/
$(INSTALL) -m 644 include/vectormath/cpp/*.h $(DESTDIR)$(prefix)/include/vectormath/cpp/ $(INSTALL) -m 644 include/vectormath/cpp/*.h $(DESTDIR)$(prefix)/include/vectormath/cpp/
$(INSTALL) -m 755 -d $(DESTDIR)$(prefix)/include/vectormath/cpp $(INSTALL) -m 755 -d $(DESTDIR)$(prefix)/include/vectormath/cpp
for _d in $(ARCH_DIRS) $(COMMON_DIRS); do \ for _d in $(ARCH_DIRS) $(COMMON_DIRS); do \
if test -d include/vectormath/$$_d/c; then \ if test -d include/vectormath/$$_d/c; then \
$(INSTALL) -m 755 -d $(DESTDIR)$(prefix)/include/vectormath/$$_d/c && \ $(INSTALL) -m 755 -d $(DESTDIR)$(prefix)/include/vectormath/$$_d/c && \
$(INSTALL) -m 644 include/vectormath/$$_d/c/*.h \ $(INSTALL) -m 644 include/vectormath/$$_d/c/*.h \
$(DESTDIR)$(prefix)/include/vectormath/$$_d/c/ || exit 1; \ $(DESTDIR)$(prefix)/include/vectormath/$$_d/c/ || exit 1; \
fi; \ fi; \
if test -d include/vectormath/$$_d/cpp; then \ if test -d include/vectormath/$$_d/cpp; then \
$(INSTALL) -m 755 -d $(DESTDIR)$(prefix)/include/vectormath/$$_d/cpp && \ $(INSTALL) -m 755 -d $(DESTDIR)$(prefix)/include/vectormath/$$_d/cpp && \
$(INSTALL) -m 644 include/vectormath/$$_d/cpp/*.h \ $(INSTALL) -m 644 include/vectormath/$$_d/cpp/*.h \
$(DESTDIR)$(prefix)/include/vectormath/$$_d/cpp/ || exit 1; \ $(DESTDIR)$(prefix)/include/vectormath/$$_d/cpp/ || exit 1; \
fi; \ fi; \
done done
check: check:
$(MAKE) -C tests ARCH=$(ARCH) check $(MAKE) -C tests ARCH=$(ARCH) check
clean: clean:
$(MAKE) -C tests clean $(MAKE) -C tests clean
-rm -f $(TAR_BALL) -rm -f $(TAR_BALL)
distclean: distclean:
$(MAKE) -C tests distclean $(MAKE) -C tests distclean
dist: dist:
-rm -rf .dist -rm -rf .dist
mkdir -p .dist/$(TAR_NAME) mkdir -p .dist/$(TAR_NAME)
find . -name .dist -prune -o \ find . -name .dist -prune -o \
-name .CVS -prune -o -name .svn -prune -o \ -name .CVS -prune -o -name .svn -prune -o \
-name .pc -prune -o -name patches -prune -o \ -name .pc -prune -o -name patches -prune -o \
'(' -name README -o -name LICENSE -o \ '(' -name README -o -name LICENSE -o \
-name Makefile -o -name '*.[ch]' -o -name '*.cpp' -o \ -name Makefile -o -name '*.[ch]' -o -name '*.cpp' -o \
-name '*.pl' -o -name '*.txt' -o -name '*.pdf' -o -name '*.spec' ')' \ -name '*.pl' -o -name '*.txt' -o -name '*.pdf' -o -name '*.spec' ')' \
-print | tar -T - -cf - | tar xf - -C .dist/$(TAR_NAME) -print | tar -T - -cf - | tar xf - -C .dist/$(TAR_NAME)
tar zcf $(TAR_BALL) -C .dist $(TAR_NAME) tar zcf $(TAR_BALL) -C .dist $(TAR_NAME)
-rm -rf .dist -rm -rf .dist

View File

@@ -1,247 +1,247 @@
/* /*
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc. Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the with or without modification, are permitted provided that the
following conditions are met: following conditions are met:
* Redistributions of source code must retain the above copyright * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright * Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names * Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission. from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef _BOOLINVEC_H #ifndef _BOOLINVEC_H
#define _BOOLINVEC_H #define _BOOLINVEC_H
#include <math.h> #include <math.h>
namespace Vectormath { namespace Vectormath {
class floatInVec; class floatInVec;
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// boolInVec class // boolInVec class
// //
class boolInVec class boolInVec
{ {
private: private:
__m128 mData; __m128 mData;
inline boolInVec(__m128 vec); inline boolInVec(__m128 vec);
public: public:
inline boolInVec() {} inline boolInVec() {}
// matches standard type conversions // matches standard type conversions
// //
inline boolInVec(const floatInVec &vec); inline boolInVec(const floatInVec &vec);
// explicit cast from bool // explicit cast from bool
// //
explicit inline boolInVec(bool scalar); explicit inline boolInVec(bool scalar);
#ifdef _VECTORMATH_NO_SCALAR_CAST #ifdef _VECTORMATH_NO_SCALAR_CAST
// explicit cast to bool // explicit cast to bool
// //
inline bool getAsBool() const; inline bool getAsBool() const;
#else #else
// implicit cast to bool // implicit cast to bool
// //
inline operator bool() const; inline operator bool() const;
#endif #endif
// get vector data // get vector data
// bool value is splatted across all word slots of vector as 0 (false) or -1 (true) // bool value is splatted across all word slots of vector as 0 (false) or -1 (true)
// //
inline __m128 get128() const; inline __m128 get128() const;
// operators // operators
// //
inline const boolInVec operator ! () const; inline const boolInVec operator ! () const;
inline boolInVec& operator = (const boolInVec &vec); inline boolInVec& operator = (const boolInVec &vec);
inline boolInVec& operator &= (const boolInVec &vec); inline boolInVec& operator &= (const boolInVec &vec);
inline boolInVec& operator ^= (const boolInVec &vec); inline boolInVec& operator ^= (const boolInVec &vec);
inline boolInVec& operator |= (const boolInVec &vec); inline boolInVec& operator |= (const boolInVec &vec);
// friend functions // friend functions
// //
friend inline const boolInVec operator == (const boolInVec &vec0, const boolInVec &vec1); friend inline const boolInVec operator == (const boolInVec &vec0, const boolInVec &vec1);
friend inline const boolInVec operator != (const boolInVec &vec0, const boolInVec &vec1); friend inline const boolInVec operator != (const boolInVec &vec0, const boolInVec &vec1);
friend inline const boolInVec operator < (const floatInVec &vec0, const floatInVec &vec1); friend inline const boolInVec operator < (const floatInVec &vec0, const floatInVec &vec1);
friend inline const boolInVec operator <= (const floatInVec &vec0, const floatInVec &vec1); friend inline const boolInVec operator <= (const floatInVec &vec0, const floatInVec &vec1);
friend inline const boolInVec operator > (const floatInVec &vec0, const floatInVec &vec1); friend inline const boolInVec operator > (const floatInVec &vec0, const floatInVec &vec1);
friend inline const boolInVec operator >= (const floatInVec &vec0, const floatInVec &vec1); friend inline const boolInVec operator >= (const floatInVec &vec0, const floatInVec &vec1);
friend inline const boolInVec operator == (const floatInVec &vec0, const floatInVec &vec1); friend inline const boolInVec operator == (const floatInVec &vec0, const floatInVec &vec1);
friend inline const boolInVec operator != (const floatInVec &vec0, const floatInVec &vec1); friend inline const boolInVec operator != (const floatInVec &vec0, const floatInVec &vec1);
friend inline const boolInVec operator & (const boolInVec &vec0, const boolInVec &vec1); friend inline const boolInVec operator & (const boolInVec &vec0, const boolInVec &vec1);
friend inline const boolInVec operator ^ (const boolInVec &vec0, const boolInVec &vec1); friend inline const boolInVec operator ^ (const boolInVec &vec0, const boolInVec &vec1);
friend inline const boolInVec operator | (const boolInVec &vec0, const boolInVec &vec1); friend inline const boolInVec operator | (const boolInVec &vec0, const boolInVec &vec1);
friend inline const boolInVec select(const boolInVec &vec0, const boolInVec &vec1, const boolInVec &select_vec1); friend inline const boolInVec select(const boolInVec &vec0, const boolInVec &vec1, const boolInVec &select_vec1);
}; };
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// boolInVec functions // boolInVec functions
// //
// operators // operators
// //
inline const boolInVec operator == (const boolInVec &vec0, const boolInVec &vec1); inline const boolInVec operator == (const boolInVec &vec0, const boolInVec &vec1);
inline const boolInVec operator != (const boolInVec &vec0, const boolInVec &vec1); inline const boolInVec operator != (const boolInVec &vec0, const boolInVec &vec1);
inline const boolInVec operator & (const boolInVec &vec0, const boolInVec &vec1); inline const boolInVec operator & (const boolInVec &vec0, const boolInVec &vec1);
inline const boolInVec operator ^ (const boolInVec &vec0, const boolInVec &vec1); inline const boolInVec operator ^ (const boolInVec &vec0, const boolInVec &vec1);
inline const boolInVec operator | (const boolInVec &vec0, const boolInVec &vec1); inline const boolInVec operator | (const boolInVec &vec0, const boolInVec &vec1);
// select between vec0 and vec1 using boolInVec. // select between vec0 and vec1 using boolInVec.
// false selects vec0, true selects vec1 // false selects vec0, true selects vec1
// //
inline const boolInVec select(const boolInVec &vec0, const boolInVec &vec1, const boolInVec &select_vec1); inline const boolInVec select(const boolInVec &vec0, const boolInVec &vec1, const boolInVec &select_vec1);
} // namespace Vectormath } // namespace Vectormath
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// boolInVec implementation // boolInVec implementation
// //
#include "floatInVec.h" #include "floatInVec.h"
namespace Vectormath { namespace Vectormath {
inline inline
boolInVec::boolInVec(__m128 vec) boolInVec::boolInVec(__m128 vec)
{ {
mData = vec; mData = vec;
} }
inline inline
boolInVec::boolInVec(const floatInVec &vec) boolInVec::boolInVec(const floatInVec &vec)
{ {
*this = (vec != floatInVec(0.0f)); *this = (vec != floatInVec(0.0f));
} }
inline inline
boolInVec::boolInVec(bool scalar) boolInVec::boolInVec(bool scalar)
{ {
unsigned int mask = -(int)scalar; unsigned int mask = -(int)scalar;
mData = _mm_set1_ps(*(float *)&mask); // TODO: Union mData = _mm_set1_ps(*(float *)&mask); // TODO: Union
} }
#ifdef _VECTORMATH_NO_SCALAR_CAST #ifdef _VECTORMATH_NO_SCALAR_CAST
inline inline
bool bool
boolInVec::getAsBool() const boolInVec::getAsBool() const
#else #else
inline inline
boolInVec::operator bool() const boolInVec::operator bool() const
#endif #endif
{ {
return *(bool *)&mData; return *(bool *)&mData;
} }
inline inline
__m128 __m128
boolInVec::get128() const boolInVec::get128() const
{ {
return mData; return mData;
} }
inline inline
const boolInVec const boolInVec
boolInVec::operator ! () const boolInVec::operator ! () const
{ {
return boolInVec(_mm_andnot_ps(mData, _mm_cmpneq_ps(_mm_setzero_ps(),_mm_setzero_ps()))); return boolInVec(_mm_andnot_ps(mData, _mm_cmpneq_ps(_mm_setzero_ps(),_mm_setzero_ps())));
} }
inline inline
boolInVec& boolInVec&
boolInVec::operator = (const boolInVec &vec) boolInVec::operator = (const boolInVec &vec)
{ {
mData = vec.mData; mData = vec.mData;
return *this; return *this;
} }
inline inline
boolInVec& boolInVec&
boolInVec::operator &= (const boolInVec &vec) boolInVec::operator &= (const boolInVec &vec)
{ {
*this = *this & vec; *this = *this & vec;
return *this; return *this;
} }
inline inline
boolInVec& boolInVec&
boolInVec::operator ^= (const boolInVec &vec) boolInVec::operator ^= (const boolInVec &vec)
{ {
*this = *this ^ vec; *this = *this ^ vec;
return *this; return *this;
} }
inline inline
boolInVec& boolInVec&
boolInVec::operator |= (const boolInVec &vec) boolInVec::operator |= (const boolInVec &vec)
{ {
*this = *this | vec; *this = *this | vec;
return *this; return *this;
} }
inline inline
const boolInVec const boolInVec
operator == (const boolInVec &vec0, const boolInVec &vec1) operator == (const boolInVec &vec0, const boolInVec &vec1)
{ {
return boolInVec(_mm_cmpeq_ps(vec0.get128(), vec1.get128())); return boolInVec(_mm_cmpeq_ps(vec0.get128(), vec1.get128()));
} }
inline inline
const boolInVec const boolInVec
operator != (const boolInVec &vec0, const boolInVec &vec1) operator != (const boolInVec &vec0, const boolInVec &vec1)
{ {
return boolInVec(_mm_cmpneq_ps(vec0.get128(), vec1.get128())); return boolInVec(_mm_cmpneq_ps(vec0.get128(), vec1.get128()));
} }
inline inline
const boolInVec const boolInVec
operator & (const boolInVec &vec0, const boolInVec &vec1) operator & (const boolInVec &vec0, const boolInVec &vec1)
{ {
return boolInVec(_mm_and_ps(vec0.get128(), vec1.get128())); return boolInVec(_mm_and_ps(vec0.get128(), vec1.get128()));
} }
inline inline
const boolInVec const boolInVec
operator | (const boolInVec &vec0, const boolInVec &vec1) operator | (const boolInVec &vec0, const boolInVec &vec1)
{ {
return boolInVec(_mm_or_ps(vec0.get128(), vec1.get128())); return boolInVec(_mm_or_ps(vec0.get128(), vec1.get128()));
} }
inline inline
const boolInVec const boolInVec
operator ^ (const boolInVec &vec0, const boolInVec &vec1) operator ^ (const boolInVec &vec0, const boolInVec &vec1)
{ {
return boolInVec(_mm_xor_ps(vec0.get128(), vec1.get128())); return boolInVec(_mm_xor_ps(vec0.get128(), vec1.get128()));
} }
inline inline
const boolInVec const boolInVec
select(const boolInVec &vec0, const boolInVec &vec1, const boolInVec &select_vec1) select(const boolInVec &vec0, const boolInVec &vec1, const boolInVec &select_vec1)
{ {
return boolInVec(vec_sel(vec0.get128(), vec1.get128(), select_vec1.get128())); return boolInVec(vec_sel(vec0.get128(), vec1.get128(), select_vec1.get128()));
} }
} // namespace Vectormath } // namespace Vectormath
#endif // boolInVec_h #endif // boolInVec_h

View File

@@ -1,340 +1,340 @@
/* /*
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc. Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the with or without modification, are permitted provided that the
following conditions are met: following conditions are met:
* Redistributions of source code must retain the above copyright * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright * Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names * Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission. from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef _FLOATINVEC_H #ifndef _FLOATINVEC_H
#define _FLOATINVEC_H #define _FLOATINVEC_H
#include <math.h> #include <math.h>
#include <xmmintrin.h> #include <xmmintrin.h>
namespace Vectormath { namespace Vectormath {
class boolInVec; class boolInVec;
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// floatInVec class // floatInVec class
// //
class floatInVec class floatInVec
{ {
private: private:
__m128 mData; __m128 mData;
public: public:
inline floatInVec(__m128 vec); inline floatInVec(__m128 vec);
inline floatInVec() {} inline floatInVec() {}
// matches standard type conversions // matches standard type conversions
// //
inline floatInVec(const boolInVec &vec); inline floatInVec(const boolInVec &vec);
// construct from a slot of __m128 // construct from a slot of __m128
// //
inline floatInVec(__m128 vec, int slot); inline floatInVec(__m128 vec, int slot);
// explicit cast from float // explicit cast from float
// //
explicit inline floatInVec(float scalar); explicit inline floatInVec(float scalar);
#ifdef _VECTORMATH_NO_SCALAR_CAST #ifdef _VECTORMATH_NO_SCALAR_CAST
// explicit cast to float // explicit cast to float
// //
inline float getAsFloat() const; inline float getAsFloat() const;
#else #else
// implicit cast to float // implicit cast to float
// //
inline operator float() const; inline operator float() const;
#endif #endif
// get vector data // get vector data
// float value is splatted across all word slots of vector // float value is splatted across all word slots of vector
// //
inline __m128 get128() const; inline __m128 get128() const;
// operators // operators
// //
inline const floatInVec operator ++ (int); inline const floatInVec operator ++ (int);
inline const floatInVec operator -- (int); inline const floatInVec operator -- (int);
inline floatInVec& operator ++ (); inline floatInVec& operator ++ ();
inline floatInVec& operator -- (); inline floatInVec& operator -- ();
inline const floatInVec operator - () const; inline const floatInVec operator - () const;
inline floatInVec& operator = (const floatInVec &vec); inline floatInVec& operator = (const floatInVec &vec);
inline floatInVec& operator *= (const floatInVec &vec); inline floatInVec& operator *= (const floatInVec &vec);
inline floatInVec& operator /= (const floatInVec &vec); inline floatInVec& operator /= (const floatInVec &vec);
inline floatInVec& operator += (const floatInVec &vec); inline floatInVec& operator += (const floatInVec &vec);
inline floatInVec& operator -= (const floatInVec &vec); inline floatInVec& operator -= (const floatInVec &vec);
// friend functions // friend functions
// //
friend inline const floatInVec operator * (const floatInVec &vec0, const floatInVec &vec1); friend inline const floatInVec operator * (const floatInVec &vec0, const floatInVec &vec1);
friend inline const floatInVec operator / (const floatInVec &vec0, const floatInVec &vec1); friend inline const floatInVec operator / (const floatInVec &vec0, const floatInVec &vec1);
friend inline const floatInVec operator + (const floatInVec &vec0, const floatInVec &vec1); friend inline const floatInVec operator + (const floatInVec &vec0, const floatInVec &vec1);
friend inline const floatInVec operator - (const floatInVec &vec0, const floatInVec &vec1); friend inline const floatInVec operator - (const floatInVec &vec0, const floatInVec &vec1);
friend inline const floatInVec select(const floatInVec &vec0, const floatInVec &vec1, boolInVec select_vec1); friend inline const floatInVec select(const floatInVec &vec0, const floatInVec &vec1, boolInVec select_vec1);
}; };
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// floatInVec functions // floatInVec functions
// //
// operators // operators
// //
inline const floatInVec operator * (const floatInVec &vec0, const floatInVec &vec1); inline const floatInVec operator * (const floatInVec &vec0, const floatInVec &vec1);
inline const floatInVec operator / (const floatInVec &vec0, const floatInVec &vec1); inline const floatInVec operator / (const floatInVec &vec0, const floatInVec &vec1);
inline const floatInVec operator + (const floatInVec &vec0, const floatInVec &vec1); inline const floatInVec operator + (const floatInVec &vec0, const floatInVec &vec1);
inline const floatInVec operator - (const floatInVec &vec0, const floatInVec &vec1); inline const floatInVec operator - (const floatInVec &vec0, const floatInVec &vec1);
inline const boolInVec operator < (const floatInVec &vec0, const floatInVec &vec1); inline const boolInVec operator < (const floatInVec &vec0, const floatInVec &vec1);
inline const boolInVec operator <= (const floatInVec &vec0, const floatInVec &vec1); inline const boolInVec operator <= (const floatInVec &vec0, const floatInVec &vec1);
inline const boolInVec operator > (const floatInVec &vec0, const floatInVec &vec1); inline const boolInVec operator > (const floatInVec &vec0, const floatInVec &vec1);
inline const boolInVec operator >= (const floatInVec &vec0, const floatInVec &vec1); inline const boolInVec operator >= (const floatInVec &vec0, const floatInVec &vec1);
inline const boolInVec operator == (const floatInVec &vec0, const floatInVec &vec1); inline const boolInVec operator == (const floatInVec &vec0, const floatInVec &vec1);
inline const boolInVec operator != (const floatInVec &vec0, const floatInVec &vec1); inline const boolInVec operator != (const floatInVec &vec0, const floatInVec &vec1);
// select between vec0 and vec1 using boolInVec. // select between vec0 and vec1 using boolInVec.
// false selects vec0, true selects vec1 // false selects vec0, true selects vec1
// //
inline const floatInVec select(const floatInVec &vec0, const floatInVec &vec1, const boolInVec &select_vec1); inline const floatInVec select(const floatInVec &vec0, const floatInVec &vec1, const boolInVec &select_vec1);
} // namespace Vectormath } // namespace Vectormath
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// floatInVec implementation // floatInVec implementation
// //
#include "boolInVec.h" #include "boolInVec.h"
namespace Vectormath { namespace Vectormath {
inline inline
floatInVec::floatInVec(__m128 vec) floatInVec::floatInVec(__m128 vec)
{ {
mData = vec; mData = vec;
} }
inline inline
floatInVec::floatInVec(const boolInVec &vec) floatInVec::floatInVec(const boolInVec &vec)
{ {
mData = vec_sel(_mm_setzero_ps(), _mm_set1_ps(1.0f), vec.get128()); mData = vec_sel(_mm_setzero_ps(), _mm_set1_ps(1.0f), vec.get128());
} }
inline inline
floatInVec::floatInVec(__m128 vec, int slot) floatInVec::floatInVec(__m128 vec, int slot)
{ {
SSEFloat v; SSEFloat v;
v.m128 = vec; v.m128 = vec;
mData = _mm_set1_ps(v.f[slot]); mData = _mm_set1_ps(v.f[slot]);
} }
inline inline
floatInVec::floatInVec(float scalar) floatInVec::floatInVec(float scalar)
{ {
mData = _mm_set1_ps(scalar); mData = _mm_set1_ps(scalar);
} }
#ifdef _VECTORMATH_NO_SCALAR_CAST #ifdef _VECTORMATH_NO_SCALAR_CAST
inline inline
float float
floatInVec::getAsFloat() const floatInVec::getAsFloat() const
#else #else
inline inline
floatInVec::operator float() const floatInVec::operator float() const
#endif #endif
{ {
return *((float *)&mData); return *((float *)&mData);
} }
inline inline
__m128 __m128
floatInVec::get128() const floatInVec::get128() const
{ {
return mData; return mData;
} }
inline inline
const floatInVec const floatInVec
floatInVec::operator ++ (int) floatInVec::operator ++ (int)
{ {
__m128 olddata = mData; __m128 olddata = mData;
operator ++(); operator ++();
return floatInVec(olddata); return floatInVec(olddata);
} }
inline inline
const floatInVec const floatInVec
floatInVec::operator -- (int) floatInVec::operator -- (int)
{ {
__m128 olddata = mData; __m128 olddata = mData;
operator --(); operator --();
return floatInVec(olddata); return floatInVec(olddata);
} }
inline inline
floatInVec& floatInVec&
floatInVec::operator ++ () floatInVec::operator ++ ()
{ {
*this += floatInVec(_mm_set1_ps(1.0f)); *this += floatInVec(_mm_set1_ps(1.0f));
return *this; return *this;
} }
inline inline
floatInVec& floatInVec&
floatInVec::operator -- () floatInVec::operator -- ()
{ {
*this -= floatInVec(_mm_set1_ps(1.0f)); *this -= floatInVec(_mm_set1_ps(1.0f));
return *this; return *this;
} }
inline inline
const floatInVec const floatInVec
floatInVec::operator - () const floatInVec::operator - () const
{ {
return floatInVec(_mm_sub_ps(_mm_setzero_ps(), mData)); return floatInVec(_mm_sub_ps(_mm_setzero_ps(), mData));
} }
inline inline
floatInVec& floatInVec&
floatInVec::operator = (const floatInVec &vec) floatInVec::operator = (const floatInVec &vec)
{ {
mData = vec.mData; mData = vec.mData;
return *this; return *this;
} }
inline inline
floatInVec& floatInVec&
floatInVec::operator *= (const floatInVec &vec) floatInVec::operator *= (const floatInVec &vec)
{ {
*this = *this * vec; *this = *this * vec;
return *this; return *this;
} }
inline inline
floatInVec& floatInVec&
floatInVec::operator /= (const floatInVec &vec) floatInVec::operator /= (const floatInVec &vec)
{ {
*this = *this / vec; *this = *this / vec;
return *this; return *this;
} }
inline inline
floatInVec& floatInVec&
floatInVec::operator += (const floatInVec &vec) floatInVec::operator += (const floatInVec &vec)
{ {
*this = *this + vec; *this = *this + vec;
return *this; return *this;
} }
inline inline
floatInVec& floatInVec&
floatInVec::operator -= (const floatInVec &vec) floatInVec::operator -= (const floatInVec &vec)
{ {
*this = *this - vec; *this = *this - vec;
return *this; return *this;
} }
inline inline
const floatInVec const floatInVec
operator * (const floatInVec &vec0, const floatInVec &vec1) operator * (const floatInVec &vec0, const floatInVec &vec1)
{ {
return floatInVec(_mm_mul_ps(vec0.get128(), vec1.get128())); return floatInVec(_mm_mul_ps(vec0.get128(), vec1.get128()));
} }
inline inline
const floatInVec const floatInVec
operator / (const floatInVec &num, const floatInVec &den) operator / (const floatInVec &num, const floatInVec &den)
{ {
return floatInVec(_mm_div_ps(num.get128(), den.get128())); return floatInVec(_mm_div_ps(num.get128(), den.get128()));
} }
inline inline
const floatInVec const floatInVec
operator + (const floatInVec &vec0, const floatInVec &vec1) operator + (const floatInVec &vec0, const floatInVec &vec1)
{ {
return floatInVec(_mm_add_ps(vec0.get128(), vec1.get128())); return floatInVec(_mm_add_ps(vec0.get128(), vec1.get128()));
} }
inline inline
const floatInVec const floatInVec
operator - (const floatInVec &vec0, const floatInVec &vec1) operator - (const floatInVec &vec0, const floatInVec &vec1)
{ {
return floatInVec(_mm_sub_ps(vec0.get128(), vec1.get128())); return floatInVec(_mm_sub_ps(vec0.get128(), vec1.get128()));
} }
inline inline
const boolInVec const boolInVec
operator < (const floatInVec &vec0, const floatInVec &vec1) operator < (const floatInVec &vec0, const floatInVec &vec1)
{ {
return boolInVec(_mm_cmpgt_ps(vec1.get128(), vec0.get128())); return boolInVec(_mm_cmpgt_ps(vec1.get128(), vec0.get128()));
} }
inline inline
const boolInVec const boolInVec
operator <= (const floatInVec &vec0, const floatInVec &vec1) operator <= (const floatInVec &vec0, const floatInVec &vec1)
{ {
return boolInVec(_mm_cmpge_ps(vec1.get128(), vec0.get128())); return boolInVec(_mm_cmpge_ps(vec1.get128(), vec0.get128()));
} }
inline inline
const boolInVec const boolInVec
operator > (const floatInVec &vec0, const floatInVec &vec1) operator > (const floatInVec &vec0, const floatInVec &vec1)
{ {
return boolInVec(_mm_cmpgt_ps(vec0.get128(), vec1.get128())); return boolInVec(_mm_cmpgt_ps(vec0.get128(), vec1.get128()));
} }
inline inline
const boolInVec const boolInVec
operator >= (const floatInVec &vec0, const floatInVec &vec1) operator >= (const floatInVec &vec0, const floatInVec &vec1)
{ {
return boolInVec(_mm_cmpge_ps(vec0.get128(), vec1.get128())); return boolInVec(_mm_cmpge_ps(vec0.get128(), vec1.get128()));
} }
inline inline
const boolInVec const boolInVec
operator == (const floatInVec &vec0, const floatInVec &vec1) operator == (const floatInVec &vec0, const floatInVec &vec1)
{ {
return boolInVec(_mm_cmpeq_ps(vec0.get128(), vec1.get128())); return boolInVec(_mm_cmpeq_ps(vec0.get128(), vec1.get128()));
} }
inline inline
const boolInVec const boolInVec
operator != (const floatInVec &vec0, const floatInVec &vec1) operator != (const floatInVec &vec0, const floatInVec &vec1)
{ {
return boolInVec(_mm_cmpneq_ps(vec0.get128(), vec1.get128())); return boolInVec(_mm_cmpneq_ps(vec0.get128(), vec1.get128()));
} }
inline inline
const floatInVec const floatInVec
select(const floatInVec &vec0, const floatInVec &vec1, const boolInVec &select_vec1) select(const floatInVec &vec0, const floatInVec &vec1, const boolInVec &select_vec1)
{ {
return floatInVec(vec_sel(vec0.get128(), vec1.get128(), select_vec1.get128())); return floatInVec(vec_sel(vec0.get128(), vec1.get128(), select_vec1.get128()));
} }
} // namespace Vectormath } // namespace Vectormath
#endif // floatInVec_h #endif // floatInVec_h

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,80 +1,80 @@
/* /*
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc. Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the with or without modification, are permitted provided that the
following conditions are met: following conditions are met:
* Redistributions of source code must retain the above copyright * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright * Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names * Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission. from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef _VECTORMATH_VECIDX_AOS_H #ifndef _VECTORMATH_VECIDX_AOS_H
#define _VECTORMATH_VECIDX_AOS_H #define _VECTORMATH_VECIDX_AOS_H
#include "floatInVec.h" #include "floatInVec.h"
namespace Vectormath { namespace Vectormath {
namespace Aos { namespace Aos {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// VecIdx // VecIdx
// Used in setting elements of Vector3, Vector4, Point3, or Quat with the // Used in setting elements of Vector3, Vector4, Point3, or Quat with the
// subscripting operator. // subscripting operator.
// //
__declspec(align(16)) class VecIdx __declspec(align(16)) class VecIdx
{ {
private: private:
__m128 &ref; __m128 &ref;
int i; int i;
public: public:
inline VecIdx( __m128& vec, int idx ): ref(vec) { i = idx; } inline VecIdx( __m128& vec, int idx ): ref(vec) { i = idx; }
// implicitly casts to float unless _VECTORMATH_NO_SCALAR_CAST defined // implicitly casts to float unless _VECTORMATH_NO_SCALAR_CAST defined
// in which case, implicitly casts to floatInVec, and one must call // in which case, implicitly casts to floatInVec, and one must call
// getAsFloat to convert to float. // getAsFloat to convert to float.
// //
#ifdef _VECTORMATH_NO_SCALAR_CAST #ifdef _VECTORMATH_NO_SCALAR_CAST
inline operator floatInVec() const; inline operator floatInVec() const;
inline float getAsFloat() const; inline float getAsFloat() const;
#else #else
inline operator float() const; inline operator float() const;
#endif #endif
inline float operator =( float scalar ); inline float operator =( float scalar );
inline floatInVec operator =( const floatInVec &scalar ); inline floatInVec operator =( const floatInVec &scalar );
inline floatInVec operator =( const VecIdx& scalar ); inline floatInVec operator =( const VecIdx& scalar );
inline floatInVec operator *=( float scalar ); inline floatInVec operator *=( float scalar );
inline floatInVec operator *=( const floatInVec &scalar ); inline floatInVec operator *=( const floatInVec &scalar );
inline floatInVec operator /=( float scalar ); inline floatInVec operator /=( float scalar );
inline floatInVec operator /=( const floatInVec &scalar ); inline floatInVec operator /=( const floatInVec &scalar );
inline floatInVec operator +=( float scalar ); inline floatInVec operator +=( float scalar );
inline floatInVec operator +=( const floatInVec &scalar ); inline floatInVec operator +=( const floatInVec &scalar );
inline floatInVec operator -=( float scalar ); inline floatInVec operator -=( float scalar );
inline floatInVec operator -=( const floatInVec &scalar ); inline floatInVec operator -=( const floatInVec &scalar );
}; };
} // namespace Aos } // namespace Aos
} // namespace Vectormath } // namespace Vectormath
#endif #endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,379 +1,379 @@
/* /*
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc. Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the with or without modification, are permitted provided that the
following conditions are met: following conditions are met:
* Redistributions of source code must retain the above copyright * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright * Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names * Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission. from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef _VECTORMATH_QUAT_AOS_C_H #ifndef _VECTORMATH_QUAT_AOS_C_H
#define _VECTORMATH_QUAT_AOS_C_H #define _VECTORMATH_QUAT_AOS_C_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
/*----------------------------------------------------------------------------- /*-----------------------------------------------------------------------------
* Definitions * Definitions
*/ */
#ifndef _VECTORMATH_INTERNAL_FUNCTIONS #ifndef _VECTORMATH_INTERNAL_FUNCTIONS
#define _VECTORMATH_INTERNAL_FUNCTIONS #define _VECTORMATH_INTERNAL_FUNCTIONS
#endif #endif
static inline void vmathQCopy( VmathQuat *result, const VmathQuat *quat ) static inline void vmathQCopy( VmathQuat *result, const VmathQuat *quat )
{ {
result->vec128 = quat->vec128; result->vec128 = quat->vec128;
} }
static inline void vmathQMakeFromElems( VmathQuat *result, float _x, float _y, float _z, float _w ) static inline void vmathQMakeFromElems( VmathQuat *result, float _x, float _y, float _z, float _w )
{ {
if (__builtin_constant_p(_x) & __builtin_constant_p(_y) & if (__builtin_constant_p(_x) & __builtin_constant_p(_y) &
__builtin_constant_p(_z) & __builtin_constant_p(_w)) { __builtin_constant_p(_z) & __builtin_constant_p(_w)) {
result->vec128 = (vec_float4){_x, _y, _z, _w}; result->vec128 = (vec_float4){_x, _y, _z, _w};
} else { } else {
float *pf = (float *)&result->vec128; float *pf = (float *)&result->vec128;
pf[0] = _x; pf[0] = _x;
pf[1] = _y; pf[1] = _y;
pf[2] = _z; pf[2] = _z;
pf[3] = _w; pf[3] = _w;
} }
} }
static inline void vmathQMakeFromV3Scalar( VmathQuat *result, const VmathVector3 *xyz, float _w ) static inline void vmathQMakeFromV3Scalar( VmathQuat *result, const VmathVector3 *xyz, float _w )
{ {
result->vec128 = xyz->vec128; result->vec128 = xyz->vec128;
_vmathVfSetElement(result->vec128, _w, 3); _vmathVfSetElement(result->vec128, _w, 3);
} }
static inline void vmathQMakeFromV4( VmathQuat *result, const VmathVector4 *vec ) static inline void vmathQMakeFromV4( VmathQuat *result, const VmathVector4 *vec )
{ {
result->vec128 = vec->vec128; result->vec128 = vec->vec128;
} }
static inline void vmathQMakeFromScalar( VmathQuat *result, float scalar ) static inline void vmathQMakeFromScalar( VmathQuat *result, float scalar )
{ {
result->vec128 = _vmathVfSplatScalar(scalar); result->vec128 = _vmathVfSplatScalar(scalar);
} }
static inline void vmathQMakeFrom128( VmathQuat *result, vec_float4 vf4 ) static inline void vmathQMakeFrom128( VmathQuat *result, vec_float4 vf4 )
{ {
result->vec128 = vf4; result->vec128 = vf4;
} }
static inline void vmathQMakeIdentity( VmathQuat *result ) static inline void vmathQMakeIdentity( VmathQuat *result )
{ {
result->vec128 = _VECTORMATH_UNIT_0001; result->vec128 = _VECTORMATH_UNIT_0001;
} }
static inline void vmathQLerp( VmathQuat *result, float t, const VmathQuat *quat0, const VmathQuat *quat1 ) static inline void vmathQLerp( VmathQuat *result, float t, const VmathQuat *quat0, const VmathQuat *quat1 )
{ {
VmathQuat tmpQ_0, tmpQ_1; VmathQuat tmpQ_0, tmpQ_1;
vmathQSub( &tmpQ_0, quat1, quat0 ); vmathQSub( &tmpQ_0, quat1, quat0 );
vmathQScalarMul( &tmpQ_1, &tmpQ_0, t ); vmathQScalarMul( &tmpQ_1, &tmpQ_0, t );
vmathQAdd( result, quat0, &tmpQ_1 ); vmathQAdd( result, quat0, &tmpQ_1 );
} }
static inline void vmathQSlerp( VmathQuat *result, float t, const VmathQuat *unitQuat0, const VmathQuat *unitQuat1 ) static inline void vmathQSlerp( VmathQuat *result, float t, const VmathQuat *unitQuat0, const VmathQuat *unitQuat1 )
{ {
VmathQuat start; VmathQuat start;
vec_float4 scales, scale0, scale1, cosAngle, angle, tttt, oneMinusT, angles, sines; vec_float4 scales, scale0, scale1, cosAngle, angle, tttt, oneMinusT, angles, sines;
vec_uint4 selectMask; vec_uint4 selectMask;
cosAngle = _vmathVfDot4( unitQuat0->vec128, unitQuat1->vec128 ); cosAngle = _vmathVfDot4( unitQuat0->vec128, unitQuat1->vec128 );
cosAngle = vec_splat( cosAngle, 0 ); cosAngle = vec_splat( cosAngle, 0 );
selectMask = (vec_uint4)vec_cmpgt( ((vec_float4){0.0f,0.0f,0.0f,0.0f}), cosAngle ); selectMask = (vec_uint4)vec_cmpgt( ((vec_float4){0.0f,0.0f,0.0f,0.0f}), cosAngle );
cosAngle = vec_sel( cosAngle, negatef4( cosAngle ), selectMask ); cosAngle = vec_sel( cosAngle, negatef4( cosAngle ), selectMask );
start.vec128 = vec_sel( unitQuat0->vec128, negatef4( unitQuat0->vec128 ), selectMask ); start.vec128 = vec_sel( unitQuat0->vec128, negatef4( unitQuat0->vec128 ), selectMask );
selectMask = (vec_uint4)vec_cmpgt( ((vec_float4){_VECTORMATH_SLERP_TOL,_VECTORMATH_SLERP_TOL,_VECTORMATH_SLERP_TOL,_VECTORMATH_SLERP_TOL}), cosAngle ); selectMask = (vec_uint4)vec_cmpgt( ((vec_float4){_VECTORMATH_SLERP_TOL,_VECTORMATH_SLERP_TOL,_VECTORMATH_SLERP_TOL,_VECTORMATH_SLERP_TOL}), cosAngle );
angle = acosf4( cosAngle ); angle = acosf4( cosAngle );
tttt = _vmathVfSplatScalar(t); tttt = _vmathVfSplatScalar(t);
oneMinusT = vec_sub( ((vec_float4){1.0f,1.0f,1.0f,1.0f}), tttt ); oneMinusT = vec_sub( ((vec_float4){1.0f,1.0f,1.0f,1.0f}), tttt );
angles = vec_mergeh( ((vec_float4){1.0f,1.0f,1.0f,1.0f}), tttt ); angles = vec_mergeh( ((vec_float4){1.0f,1.0f,1.0f,1.0f}), tttt );
angles = vec_mergeh( angles, oneMinusT ); angles = vec_mergeh( angles, oneMinusT );
angles = vec_madd( angles, angle, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ); angles = vec_madd( angles, angle, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) );
sines = sinf4( angles ); sines = sinf4( angles );
scales = divf4( sines, vec_splat( sines, 0 ) ); scales = divf4( sines, vec_splat( sines, 0 ) );
scale0 = vec_sel( oneMinusT, vec_splat( scales, 1 ), selectMask ); scale0 = vec_sel( oneMinusT, vec_splat( scales, 1 ), selectMask );
scale1 = vec_sel( tttt, vec_splat( scales, 2 ), selectMask ); scale1 = vec_sel( tttt, vec_splat( scales, 2 ), selectMask );
result->vec128 = vec_madd( start.vec128, scale0, vec_madd( unitQuat1->vec128, scale1, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ); result->vec128 = vec_madd( start.vec128, scale0, vec_madd( unitQuat1->vec128, scale1, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) );
} }
static inline void vmathQSquad( VmathQuat *result, float t, const VmathQuat *unitQuat0, const VmathQuat *unitQuat1, const VmathQuat *unitQuat2, const VmathQuat *unitQuat3 ) static inline void vmathQSquad( VmathQuat *result, float t, const VmathQuat *unitQuat0, const VmathQuat *unitQuat1, const VmathQuat *unitQuat2, const VmathQuat *unitQuat3 )
{ {
VmathQuat tmp0, tmp1; VmathQuat tmp0, tmp1;
vmathQSlerp( &tmp0, t, unitQuat0, unitQuat3 ); vmathQSlerp( &tmp0, t, unitQuat0, unitQuat3 );
vmathQSlerp( &tmp1, t, unitQuat1, unitQuat2 ); vmathQSlerp( &tmp1, t, unitQuat1, unitQuat2 );
vmathQSlerp( result, ( ( 2.0f * t ) * ( 1.0f - t ) ), &tmp0, &tmp1 ); vmathQSlerp( result, ( ( 2.0f * t ) * ( 1.0f - t ) ), &tmp0, &tmp1 );
} }
static inline vec_float4 vmathQGet128( const VmathQuat *quat ) static inline vec_float4 vmathQGet128( const VmathQuat *quat )
{ {
return quat->vec128; return quat->vec128;
} }
static inline void vmathQSetXYZ( VmathQuat *result, const VmathVector3 *vec ) static inline void vmathQSetXYZ( VmathQuat *result, const VmathVector3 *vec )
{ {
result->vec128 = vec_sel( vec->vec128, result->vec128, _VECTORMATH_MASK_0x000F ); result->vec128 = vec_sel( vec->vec128, result->vec128, _VECTORMATH_MASK_0x000F );
} }
static inline void vmathQGetXYZ( VmathVector3 *result, const VmathQuat *quat ) static inline void vmathQGetXYZ( VmathVector3 *result, const VmathQuat *quat )
{ {
result->vec128 = quat->vec128; result->vec128 = quat->vec128;
} }
static inline void vmathQSetX( VmathQuat *result, float _x ) static inline void vmathQSetX( VmathQuat *result, float _x )
{ {
_vmathVfSetElement(result->vec128, _x, 0); _vmathVfSetElement(result->vec128, _x, 0);
} }
static inline float vmathQGetX( const VmathQuat *quat ) static inline float vmathQGetX( const VmathQuat *quat )
{ {
return _vmathVfGetElement(quat->vec128, 0); return _vmathVfGetElement(quat->vec128, 0);
} }
static inline void vmathQSetY( VmathQuat *result, float _y ) static inline void vmathQSetY( VmathQuat *result, float _y )
{ {
_vmathVfSetElement(result->vec128, _y, 1); _vmathVfSetElement(result->vec128, _y, 1);
} }
static inline float vmathQGetY( const VmathQuat *quat ) static inline float vmathQGetY( const VmathQuat *quat )
{ {
return _vmathVfGetElement(quat->vec128, 1); return _vmathVfGetElement(quat->vec128, 1);
} }
static inline void vmathQSetZ( VmathQuat *result, float _z ) static inline void vmathQSetZ( VmathQuat *result, float _z )
{ {
_vmathVfSetElement(result->vec128, _z, 2); _vmathVfSetElement(result->vec128, _z, 2);
} }
static inline float vmathQGetZ( const VmathQuat *quat ) static inline float vmathQGetZ( const VmathQuat *quat )
{ {
return _vmathVfGetElement(quat->vec128, 2); return _vmathVfGetElement(quat->vec128, 2);
} }
static inline void vmathQSetW( VmathQuat *result, float _w ) static inline void vmathQSetW( VmathQuat *result, float _w )
{ {
_vmathVfSetElement(result->vec128, _w, 3); _vmathVfSetElement(result->vec128, _w, 3);
} }
static inline float vmathQGetW( const VmathQuat *quat ) static inline float vmathQGetW( const VmathQuat *quat )
{ {
return _vmathVfGetElement(quat->vec128, 3); return _vmathVfGetElement(quat->vec128, 3);
} }
static inline void vmathQSetElem( VmathQuat *result, int idx, float value ) static inline void vmathQSetElem( VmathQuat *result, int idx, float value )
{ {
_vmathVfSetElement(result->vec128, value, idx); _vmathVfSetElement(result->vec128, value, idx);
} }
static inline float vmathQGetElem( const VmathQuat *quat, int idx ) static inline float vmathQGetElem( const VmathQuat *quat, int idx )
{ {
return _vmathVfGetElement(quat->vec128, idx); return _vmathVfGetElement(quat->vec128, idx);
} }
static inline void vmathQAdd( VmathQuat *result, const VmathQuat *quat0, const VmathQuat *quat1 ) static inline void vmathQAdd( VmathQuat *result, const VmathQuat *quat0, const VmathQuat *quat1 )
{ {
result->vec128 = vec_add( quat0->vec128, quat1->vec128 ); result->vec128 = vec_add( quat0->vec128, quat1->vec128 );
} }
static inline void vmathQSub( VmathQuat *result, const VmathQuat *quat0, const VmathQuat *quat1 ) static inline void vmathQSub( VmathQuat *result, const VmathQuat *quat0, const VmathQuat *quat1 )
{ {
result->vec128 = vec_sub( quat0->vec128, quat1->vec128 ); result->vec128 = vec_sub( quat0->vec128, quat1->vec128 );
} }
static inline void vmathQScalarMul( VmathQuat *result, const VmathQuat *quat, float scalar ) static inline void vmathQScalarMul( VmathQuat *result, const VmathQuat *quat, float scalar )
{ {
result->vec128 = vec_madd( quat->vec128, _vmathVfSplatScalar(scalar), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ); result->vec128 = vec_madd( quat->vec128, _vmathVfSplatScalar(scalar), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) );
} }
static inline void vmathQScalarDiv( VmathQuat *result, const VmathQuat *quat, float scalar ) static inline void vmathQScalarDiv( VmathQuat *result, const VmathQuat *quat, float scalar )
{ {
result->vec128 = divf4( quat->vec128, _vmathVfSplatScalar(scalar) ); result->vec128 = divf4( quat->vec128, _vmathVfSplatScalar(scalar) );
} }
static inline void vmathQNeg( VmathQuat *result, const VmathQuat *quat ) static inline void vmathQNeg( VmathQuat *result, const VmathQuat *quat )
{ {
result->vec128 = negatef4( quat->vec128 ); result->vec128 = negatef4( quat->vec128 );
} }
static inline float vmathQDot( const VmathQuat *quat0, const VmathQuat *quat1 ) static inline float vmathQDot( const VmathQuat *quat0, const VmathQuat *quat1 )
{ {
vec_float4 result = _vmathVfDot4( quat0->vec128, quat1->vec128 ); vec_float4 result = _vmathVfDot4( quat0->vec128, quat1->vec128 );
return _vmathVfGetElement(result, 0); return _vmathVfGetElement(result, 0);
} }
static inline float vmathQNorm( const VmathQuat *quat ) static inline float vmathQNorm( const VmathQuat *quat )
{ {
vec_float4 result = _vmathVfDot4( quat->vec128, quat->vec128 ); vec_float4 result = _vmathVfDot4( quat->vec128, quat->vec128 );
return _vmathVfGetElement(result, 0); return _vmathVfGetElement(result, 0);
} }
static inline float vmathQLength( const VmathQuat *quat ) static inline float vmathQLength( const VmathQuat *quat )
{ {
return sqrtf( vmathQNorm( quat ) ); return sqrtf( vmathQNorm( quat ) );
} }
static inline void vmathQNormalize( VmathQuat *result, const VmathQuat *quat ) static inline void vmathQNormalize( VmathQuat *result, const VmathQuat *quat )
{ {
vec_float4 dot = _vmathVfDot4( quat->vec128, quat->vec128 ); vec_float4 dot = _vmathVfDot4( quat->vec128, quat->vec128 );
result->vec128 = vec_madd( quat->vec128, rsqrtf4( dot ), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ); result->vec128 = vec_madd( quat->vec128, rsqrtf4( dot ), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) );
} }
static inline void vmathQMakeRotationArc( VmathQuat *result, const VmathVector3 *unitVec0, const VmathVector3 *unitVec1 ) static inline void vmathQMakeRotationArc( VmathQuat *result, const VmathVector3 *unitVec0, const VmathVector3 *unitVec1 )
{ {
VmathVector3 crossVec, tmpV3_0; VmathVector3 crossVec, tmpV3_0;
vec_float4 cosAngle, cosAngleX2Plus2, recipCosHalfAngleX2, cosHalfAngleX2, res; vec_float4 cosAngle, cosAngleX2Plus2, recipCosHalfAngleX2, cosHalfAngleX2, res;
cosAngle = _vmathVfDot3( unitVec0->vec128, unitVec1->vec128 ); cosAngle = _vmathVfDot3( unitVec0->vec128, unitVec1->vec128 );
cosAngle = vec_splat( cosAngle, 0 ); cosAngle = vec_splat( cosAngle, 0 );
cosAngleX2Plus2 = vec_madd( cosAngle, ((vec_float4){2.0f,2.0f,2.0f,2.0f}), ((vec_float4){2.0f,2.0f,2.0f,2.0f}) ); cosAngleX2Plus2 = vec_madd( cosAngle, ((vec_float4){2.0f,2.0f,2.0f,2.0f}), ((vec_float4){2.0f,2.0f,2.0f,2.0f}) );
recipCosHalfAngleX2 = rsqrtf4( cosAngleX2Plus2 ); recipCosHalfAngleX2 = rsqrtf4( cosAngleX2Plus2 );
cosHalfAngleX2 = vec_madd( recipCosHalfAngleX2, cosAngleX2Plus2, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ); cosHalfAngleX2 = vec_madd( recipCosHalfAngleX2, cosAngleX2Plus2, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) );
vmathV3Cross( &tmpV3_0, unitVec0, unitVec1 ); vmathV3Cross( &tmpV3_0, unitVec0, unitVec1 );
crossVec = tmpV3_0; crossVec = tmpV3_0;
res = vec_madd( crossVec.vec128, recipCosHalfAngleX2, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ); res = vec_madd( crossVec.vec128, recipCosHalfAngleX2, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) );
res = vec_sel( res, vec_madd( cosHalfAngleX2, ((vec_float4){0.5f,0.5f,0.5f,0.5f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), _VECTORMATH_MASK_0x000F ); res = vec_sel( res, vec_madd( cosHalfAngleX2, ((vec_float4){0.5f,0.5f,0.5f,0.5f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), _VECTORMATH_MASK_0x000F );
result->vec128 = res; result->vec128 = res;
} }
static inline void vmathQMakeRotationAxis( VmathQuat *result, float radians, const VmathVector3 *unitVec ) static inline void vmathQMakeRotationAxis( VmathQuat *result, float radians, const VmathVector3 *unitVec )
{ {
vec_float4 s, c, angle, res; vec_float4 s, c, angle, res;
angle = vec_madd( _vmathVfSplatScalar(radians), ((vec_float4){0.5f,0.5f,0.5f,0.5f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ); angle = vec_madd( _vmathVfSplatScalar(radians), ((vec_float4){0.5f,0.5f,0.5f,0.5f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) );
sincosf4( angle, &s, &c ); sincosf4( angle, &s, &c );
res = vec_sel( vec_madd( unitVec->vec128, s, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), c, _VECTORMATH_MASK_0x000F ); res = vec_sel( vec_madd( unitVec->vec128, s, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), c, _VECTORMATH_MASK_0x000F );
result->vec128 = res; result->vec128 = res;
} }
static inline void vmathQMakeRotationX( VmathQuat *result, float radians ) static inline void vmathQMakeRotationX( VmathQuat *result, float radians )
{ {
vec_float4 s, c, angle, res; vec_float4 s, c, angle, res;
angle = vec_madd( _vmathVfSplatScalar(radians), ((vec_float4){0.5f,0.5f,0.5f,0.5f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ); angle = vec_madd( _vmathVfSplatScalar(radians), ((vec_float4){0.5f,0.5f,0.5f,0.5f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) );
sincosf4( angle, &s, &c ); sincosf4( angle, &s, &c );
res = vec_sel( ((vec_float4){0.0f,0.0f,0.0f,0.0f}), s, _VECTORMATH_MASK_0xF000 ); res = vec_sel( ((vec_float4){0.0f,0.0f,0.0f,0.0f}), s, _VECTORMATH_MASK_0xF000 );
res = vec_sel( res, c, _VECTORMATH_MASK_0x000F ); res = vec_sel( res, c, _VECTORMATH_MASK_0x000F );
result->vec128 = res; result->vec128 = res;
} }
static inline void vmathQMakeRotationY( VmathQuat *result, float radians ) static inline void vmathQMakeRotationY( VmathQuat *result, float radians )
{ {
vec_float4 s, c, angle, res; vec_float4 s, c, angle, res;
angle = vec_madd( _vmathVfSplatScalar(radians), ((vec_float4){0.5f,0.5f,0.5f,0.5f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ); angle = vec_madd( _vmathVfSplatScalar(radians), ((vec_float4){0.5f,0.5f,0.5f,0.5f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) );
sincosf4( angle, &s, &c ); sincosf4( angle, &s, &c );
res = vec_sel( ((vec_float4){0.0f,0.0f,0.0f,0.0f}), s, _VECTORMATH_MASK_0x0F00 ); res = vec_sel( ((vec_float4){0.0f,0.0f,0.0f,0.0f}), s, _VECTORMATH_MASK_0x0F00 );
res = vec_sel( res, c, _VECTORMATH_MASK_0x000F ); res = vec_sel( res, c, _VECTORMATH_MASK_0x000F );
result->vec128 = res; result->vec128 = res;
} }
static inline void vmathQMakeRotationZ( VmathQuat *result, float radians ) static inline void vmathQMakeRotationZ( VmathQuat *result, float radians )
{ {
vec_float4 s, c, angle, res; vec_float4 s, c, angle, res;
angle = vec_madd( _vmathVfSplatScalar(radians), ((vec_float4){0.5f,0.5f,0.5f,0.5f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ); angle = vec_madd( _vmathVfSplatScalar(radians), ((vec_float4){0.5f,0.5f,0.5f,0.5f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) );
sincosf4( angle, &s, &c ); sincosf4( angle, &s, &c );
res = vec_sel( ((vec_float4){0.0f,0.0f,0.0f,0.0f}), s, _VECTORMATH_MASK_0x00F0 ); res = vec_sel( ((vec_float4){0.0f,0.0f,0.0f,0.0f}), s, _VECTORMATH_MASK_0x00F0 );
res = vec_sel( res, c, _VECTORMATH_MASK_0x000F ); res = vec_sel( res, c, _VECTORMATH_MASK_0x000F );
result->vec128 = res; result->vec128 = res;
} }
static inline void vmathQMul( VmathQuat *result, const VmathQuat *quat0, const VmathQuat *quat1 ) static inline void vmathQMul( VmathQuat *result, const VmathQuat *quat0, const VmathQuat *quat1 )
{ {
vec_float4 ldata, rdata, qv, tmp0, tmp1, tmp2, tmp3; vec_float4 ldata, rdata, qv, tmp0, tmp1, tmp2, tmp3;
vec_float4 product, l_wxyz, r_wxyz, xy, qw; vec_float4 product, l_wxyz, r_wxyz, xy, qw;
ldata = quat0->vec128; ldata = quat0->vec128;
rdata = quat1->vec128; rdata = quat1->vec128;
tmp0 = vec_perm( ldata, ldata, _VECTORMATH_PERM_YZXW ); tmp0 = vec_perm( ldata, ldata, _VECTORMATH_PERM_YZXW );
tmp1 = vec_perm( rdata, rdata, _VECTORMATH_PERM_ZXYW ); tmp1 = vec_perm( rdata, rdata, _VECTORMATH_PERM_ZXYW );
tmp2 = vec_perm( ldata, ldata, _VECTORMATH_PERM_ZXYW ); tmp2 = vec_perm( ldata, ldata, _VECTORMATH_PERM_ZXYW );
tmp3 = vec_perm( rdata, rdata, _VECTORMATH_PERM_YZXW ); tmp3 = vec_perm( rdata, rdata, _VECTORMATH_PERM_YZXW );
qv = vec_madd( vec_splat( ldata, 3 ), rdata, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ); qv = vec_madd( vec_splat( ldata, 3 ), rdata, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) );
qv = vec_madd( vec_splat( rdata, 3 ), ldata, qv ); qv = vec_madd( vec_splat( rdata, 3 ), ldata, qv );
qv = vec_madd( tmp0, tmp1, qv ); qv = vec_madd( tmp0, tmp1, qv );
qv = vec_nmsub( tmp2, tmp3, qv ); qv = vec_nmsub( tmp2, tmp3, qv );
product = vec_madd( ldata, rdata, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ); product = vec_madd( ldata, rdata, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) );
l_wxyz = vec_sld( ldata, ldata, 12 ); l_wxyz = vec_sld( ldata, ldata, 12 );
r_wxyz = vec_sld( rdata, rdata, 12 ); r_wxyz = vec_sld( rdata, rdata, 12 );
qw = vec_nmsub( l_wxyz, r_wxyz, product ); qw = vec_nmsub( l_wxyz, r_wxyz, product );
xy = vec_madd( l_wxyz, r_wxyz, product ); xy = vec_madd( l_wxyz, r_wxyz, product );
qw = vec_sub( qw, vec_sld( xy, xy, 8 ) ); qw = vec_sub( qw, vec_sld( xy, xy, 8 ) );
result->vec128 = vec_sel( qv, qw, _VECTORMATH_MASK_0x000F ); result->vec128 = vec_sel( qv, qw, _VECTORMATH_MASK_0x000F );
} }
static inline void vmathQRotate( VmathVector3 *result, const VmathQuat *quat, const VmathVector3 *vec ) static inline void vmathQRotate( VmathVector3 *result, const VmathQuat *quat, const VmathVector3 *vec )
{ {
vec_float4 qdata, vdata, product, tmp0, tmp1, tmp2, tmp3, wwww, qv, qw, res; vec_float4 qdata, vdata, product, tmp0, tmp1, tmp2, tmp3, wwww, qv, qw, res;
qdata = quat->vec128; qdata = quat->vec128;
vdata = vec->vec128; vdata = vec->vec128;
tmp0 = vec_perm( qdata, qdata, _VECTORMATH_PERM_YZXW ); tmp0 = vec_perm( qdata, qdata, _VECTORMATH_PERM_YZXW );
tmp1 = vec_perm( vdata, vdata, _VECTORMATH_PERM_ZXYW ); tmp1 = vec_perm( vdata, vdata, _VECTORMATH_PERM_ZXYW );
tmp2 = vec_perm( qdata, qdata, _VECTORMATH_PERM_ZXYW ); tmp2 = vec_perm( qdata, qdata, _VECTORMATH_PERM_ZXYW );
tmp3 = vec_perm( vdata, vdata, _VECTORMATH_PERM_YZXW ); tmp3 = vec_perm( vdata, vdata, _VECTORMATH_PERM_YZXW );
wwww = vec_splat( qdata, 3 ); wwww = vec_splat( qdata, 3 );
qv = vec_madd( wwww, vdata, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ); qv = vec_madd( wwww, vdata, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) );
qv = vec_madd( tmp0, tmp1, qv ); qv = vec_madd( tmp0, tmp1, qv );
qv = vec_nmsub( tmp2, tmp3, qv ); qv = vec_nmsub( tmp2, tmp3, qv );
product = vec_madd( qdata, vdata, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ); product = vec_madd( qdata, vdata, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) );
qw = vec_madd( vec_sld( qdata, qdata, 4 ), vec_sld( vdata, vdata, 4 ), product ); qw = vec_madd( vec_sld( qdata, qdata, 4 ), vec_sld( vdata, vdata, 4 ), product );
qw = vec_add( vec_sld( product, product, 8 ), qw ); qw = vec_add( vec_sld( product, product, 8 ), qw );
tmp1 = vec_perm( qv, qv, _VECTORMATH_PERM_ZXYW ); tmp1 = vec_perm( qv, qv, _VECTORMATH_PERM_ZXYW );
tmp3 = vec_perm( qv, qv, _VECTORMATH_PERM_YZXW ); tmp3 = vec_perm( qv, qv, _VECTORMATH_PERM_YZXW );
res = vec_madd( vec_splat( qw, 0 ), qdata, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ); res = vec_madd( vec_splat( qw, 0 ), qdata, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) );
res = vec_madd( wwww, qv, res ); res = vec_madd( wwww, qv, res );
res = vec_madd( tmp0, tmp1, res ); res = vec_madd( tmp0, tmp1, res );
res = vec_nmsub( tmp2, tmp3, res ); res = vec_nmsub( tmp2, tmp3, res );
result->vec128 = res; result->vec128 = res;
} }
static inline void vmathQConj( VmathQuat *result, const VmathQuat *quat ) static inline void vmathQConj( VmathQuat *result, const VmathQuat *quat )
{ {
result->vec128 = vec_xor( quat->vec128, ((vec_float4)(vec_int4){0x80000000,0x80000000,0x80000000,0}) ); result->vec128 = vec_xor( quat->vec128, ((vec_float4)(vec_int4){0x80000000,0x80000000,0x80000000,0}) );
} }
static inline void vmathQSelect( VmathQuat *result, const VmathQuat *quat0, const VmathQuat *quat1, unsigned int select1 ) static inline void vmathQSelect( VmathQuat *result, const VmathQuat *quat0, const VmathQuat *quat1, unsigned int select1 )
{ {
unsigned int tmp; unsigned int tmp;
tmp = (unsigned int)-(select1 > 0); tmp = (unsigned int)-(select1 > 0);
result->vec128 = vec_sel( quat0->vec128, quat1->vec128, _vmathVuiSplatScalar(tmp) ); result->vec128 = vec_sel( quat0->vec128, quat1->vec128, _vmathVuiSplatScalar(tmp) );
} }
#ifdef _VECTORMATH_DEBUG #ifdef _VECTORMATH_DEBUG
static inline void vmathQPrint( const VmathQuat *quat ) static inline void vmathQPrint( const VmathQuat *quat )
{ {
union { vec_float4 v; float s[4]; } tmp; union { vec_float4 v; float s[4]; } tmp;
tmp.v = quat->vec128; tmp.v = quat->vec128;
printf( "( %f %f %f %f )\n", tmp.s[0], tmp.s[1], tmp.s[2], tmp.s[3] ); printf( "( %f %f %f %f )\n", tmp.s[0], tmp.s[1], tmp.s[2], tmp.s[3] );
} }
static inline void vmathQPrints( const VmathQuat *quat, const char *name ) static inline void vmathQPrints( const VmathQuat *quat, const char *name )
{ {
union { vec_float4 v; float s[4]; } tmp; union { vec_float4 v; float s[4]; } tmp;
tmp.v = quat->vec128; tmp.v = quat->vec128;
printf( "%s: ( %f %f %f %f )\n", name, tmp.s[0], tmp.s[1], tmp.s[2], tmp.s[3] ); printf( "%s: ( %f %f %f %f )\n", name, tmp.s[0], tmp.s[1], tmp.s[2], tmp.s[3] );
} }
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif #endif

View File

@@ -1,312 +1,312 @@
/* /*
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc. Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the with or without modification, are permitted provided that the
following conditions are met: following conditions are met:
* Redistributions of source code must retain the above copyright * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright * Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names * Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission. from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef _VECTORMATH_QUAT_AOS_V_C_H #ifndef _VECTORMATH_QUAT_AOS_V_C_H
#define _VECTORMATH_QUAT_AOS_V_C_H #define _VECTORMATH_QUAT_AOS_V_C_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
/*----------------------------------------------------------------------------- /*-----------------------------------------------------------------------------
* Definitions * Definitions
*/ */
#ifndef _VECTORMATH_INTERNAL_FUNCTIONS #ifndef _VECTORMATH_INTERNAL_FUNCTIONS
#define _VECTORMATH_INTERNAL_FUNCTIONS #define _VECTORMATH_INTERNAL_FUNCTIONS
#endif #endif
static inline VmathQuat vmathQMakeFromElems_V( float _x, float _y, float _z, float _w ) static inline VmathQuat vmathQMakeFromElems_V( float _x, float _y, float _z, float _w )
{ {
VmathQuat result; VmathQuat result;
vmathQMakeFromElems(&result, _x, _y, _z, _w); vmathQMakeFromElems(&result, _x, _y, _z, _w);
return result; return result;
} }
static inline VmathQuat vmathQMakeFromV3Scalar_V( VmathVector3 xyz, float _w ) static inline VmathQuat vmathQMakeFromV3Scalar_V( VmathVector3 xyz, float _w )
{ {
VmathQuat result; VmathQuat result;
vmathQMakeFromV3Scalar(&result, &xyz, _w); vmathQMakeFromV3Scalar(&result, &xyz, _w);
return result; return result;
} }
static inline VmathQuat vmathQMakeFromV4_V( VmathVector4 vec ) static inline VmathQuat vmathQMakeFromV4_V( VmathVector4 vec )
{ {
VmathQuat result; VmathQuat result;
vmathQMakeFromV4(&result, &vec); vmathQMakeFromV4(&result, &vec);
return result; return result;
} }
static inline VmathQuat vmathQMakeFromScalar_V( float scalar ) static inline VmathQuat vmathQMakeFromScalar_V( float scalar )
{ {
VmathQuat result; VmathQuat result;
vmathQMakeFromScalar(&result, scalar); vmathQMakeFromScalar(&result, scalar);
return result; return result;
} }
static inline VmathQuat vmathQMakeFrom128_V( vec_float4 vf4 ) static inline VmathQuat vmathQMakeFrom128_V( vec_float4 vf4 )
{ {
VmathQuat result; VmathQuat result;
vmathQMakeFrom128(&result, vf4); vmathQMakeFrom128(&result, vf4);
return result; return result;
} }
static inline VmathQuat vmathQMakeIdentity_V( ) static inline VmathQuat vmathQMakeIdentity_V( )
{ {
VmathQuat result; VmathQuat result;
vmathQMakeIdentity(&result); vmathQMakeIdentity(&result);
return result; return result;
} }
static inline VmathQuat vmathQLerp_V( float t, VmathQuat quat0, VmathQuat quat1 ) static inline VmathQuat vmathQLerp_V( float t, VmathQuat quat0, VmathQuat quat1 )
{ {
VmathQuat result; VmathQuat result;
vmathQLerp(&result, t, &quat0, &quat1); vmathQLerp(&result, t, &quat0, &quat1);
return result; return result;
} }
static inline VmathQuat vmathQSlerp_V( float t, VmathQuat unitQuat0, VmathQuat unitQuat1 ) static inline VmathQuat vmathQSlerp_V( float t, VmathQuat unitQuat0, VmathQuat unitQuat1 )
{ {
VmathQuat result; VmathQuat result;
vmathQSlerp(&result, t, &unitQuat0, &unitQuat1); vmathQSlerp(&result, t, &unitQuat0, &unitQuat1);
return result; return result;
} }
static inline VmathQuat vmathQSquad_V( float t, VmathQuat unitQuat0, VmathQuat unitQuat1, VmathQuat unitQuat2, VmathQuat unitQuat3 ) static inline VmathQuat vmathQSquad_V( float t, VmathQuat unitQuat0, VmathQuat unitQuat1, VmathQuat unitQuat2, VmathQuat unitQuat3 )
{ {
VmathQuat result; VmathQuat result;
vmathQSquad(&result, t, &unitQuat0, &unitQuat1, &unitQuat2, &unitQuat3); vmathQSquad(&result, t, &unitQuat0, &unitQuat1, &unitQuat2, &unitQuat3);
return result; return result;
} }
static inline vec_float4 vmathQGet128_V( VmathQuat quat ) static inline vec_float4 vmathQGet128_V( VmathQuat quat )
{ {
return vmathQGet128(&quat); return vmathQGet128(&quat);
} }
static inline void vmathQSetXYZ_V( VmathQuat *result, VmathVector3 vec ) static inline void vmathQSetXYZ_V( VmathQuat *result, VmathVector3 vec )
{ {
vmathQSetXYZ(result, &vec); vmathQSetXYZ(result, &vec);
} }
static inline VmathVector3 vmathQGetXYZ_V( VmathQuat quat ) static inline VmathVector3 vmathQGetXYZ_V( VmathQuat quat )
{ {
VmathVector3 result; VmathVector3 result;
vmathQGetXYZ(&result, &quat); vmathQGetXYZ(&result, &quat);
return result; return result;
} }
static inline void vmathQSetX_V( VmathQuat *result, float _x ) static inline void vmathQSetX_V( VmathQuat *result, float _x )
{ {
vmathQSetX(result, _x); vmathQSetX(result, _x);
} }
static inline float vmathQGetX_V( VmathQuat quat ) static inline float vmathQGetX_V( VmathQuat quat )
{ {
return vmathQGetX(&quat); return vmathQGetX(&quat);
} }
static inline void vmathQSetY_V( VmathQuat *result, float _y ) static inline void vmathQSetY_V( VmathQuat *result, float _y )
{ {
vmathQSetY(result, _y); vmathQSetY(result, _y);
} }
static inline float vmathQGetY_V( VmathQuat quat ) static inline float vmathQGetY_V( VmathQuat quat )
{ {
return vmathQGetY(&quat); return vmathQGetY(&quat);
} }
static inline void vmathQSetZ_V( VmathQuat *result, float _z ) static inline void vmathQSetZ_V( VmathQuat *result, float _z )
{ {
vmathQSetZ(result, _z); vmathQSetZ(result, _z);
} }
static inline float vmathQGetZ_V( VmathQuat quat ) static inline float vmathQGetZ_V( VmathQuat quat )
{ {
return vmathQGetZ(&quat); return vmathQGetZ(&quat);
} }
static inline void vmathQSetW_V( VmathQuat *result, float _w ) static inline void vmathQSetW_V( VmathQuat *result, float _w )
{ {
vmathQSetW(result, _w); vmathQSetW(result, _w);
} }
static inline float vmathQGetW_V( VmathQuat quat ) static inline float vmathQGetW_V( VmathQuat quat )
{ {
return vmathQGetW(&quat); return vmathQGetW(&quat);
} }
static inline void vmathQSetElem_V( VmathQuat *result, int idx, float value ) static inline void vmathQSetElem_V( VmathQuat *result, int idx, float value )
{ {
vmathQSetElem(result, idx, value); vmathQSetElem(result, idx, value);
} }
static inline float vmathQGetElem_V( VmathQuat quat, int idx ) static inline float vmathQGetElem_V( VmathQuat quat, int idx )
{ {
return vmathQGetElem(&quat, idx); return vmathQGetElem(&quat, idx);
} }
static inline VmathQuat vmathQAdd_V( VmathQuat quat0, VmathQuat quat1 ) static inline VmathQuat vmathQAdd_V( VmathQuat quat0, VmathQuat quat1 )
{ {
VmathQuat result; VmathQuat result;
vmathQAdd(&result, &quat0, &quat1); vmathQAdd(&result, &quat0, &quat1);
return result; return result;
} }
static inline VmathQuat vmathQSub_V( VmathQuat quat0, VmathQuat quat1 ) static inline VmathQuat vmathQSub_V( VmathQuat quat0, VmathQuat quat1 )
{ {
VmathQuat result; VmathQuat result;
vmathQSub(&result, &quat0, &quat1); vmathQSub(&result, &quat0, &quat1);
return result; return result;
} }
static inline VmathQuat vmathQScalarMul_V( VmathQuat quat, float scalar ) static inline VmathQuat vmathQScalarMul_V( VmathQuat quat, float scalar )
{ {
VmathQuat result; VmathQuat result;
vmathQScalarMul(&result, &quat, scalar); vmathQScalarMul(&result, &quat, scalar);
return result; return result;
} }
static inline VmathQuat vmathQScalarDiv_V( VmathQuat quat, float scalar ) static inline VmathQuat vmathQScalarDiv_V( VmathQuat quat, float scalar )
{ {
VmathQuat result; VmathQuat result;
vmathQScalarDiv(&result, &quat, scalar); vmathQScalarDiv(&result, &quat, scalar);
return result; return result;
} }
static inline VmathQuat vmathQNeg_V( VmathQuat quat ) static inline VmathQuat vmathQNeg_V( VmathQuat quat )
{ {
VmathQuat result; VmathQuat result;
vmathQNeg(&result, &quat); vmathQNeg(&result, &quat);
return result; return result;
} }
static inline float vmathQDot_V( VmathQuat quat0, VmathQuat quat1 ) static inline float vmathQDot_V( VmathQuat quat0, VmathQuat quat1 )
{ {
return vmathQDot(&quat0, &quat1); return vmathQDot(&quat0, &quat1);
} }
static inline float vmathQNorm_V( VmathQuat quat ) static inline float vmathQNorm_V( VmathQuat quat )
{ {
return vmathQNorm(&quat); return vmathQNorm(&quat);
} }
static inline float vmathQLength_V( VmathQuat quat ) static inline float vmathQLength_V( VmathQuat quat )
{ {
return vmathQLength(&quat); return vmathQLength(&quat);
} }
static inline VmathQuat vmathQNormalize_V( VmathQuat quat ) static inline VmathQuat vmathQNormalize_V( VmathQuat quat )
{ {
VmathQuat result; VmathQuat result;
vmathQNormalize(&result, &quat); vmathQNormalize(&result, &quat);
return result; return result;
} }
static inline VmathQuat vmathQMakeRotationArc_V( VmathVector3 unitVec0, VmathVector3 unitVec1 ) static inline VmathQuat vmathQMakeRotationArc_V( VmathVector3 unitVec0, VmathVector3 unitVec1 )
{ {
VmathQuat result; VmathQuat result;
vmathQMakeRotationArc(&result, &unitVec0, &unitVec1); vmathQMakeRotationArc(&result, &unitVec0, &unitVec1);
return result; return result;
} }
static inline VmathQuat vmathQMakeRotationAxis_V( float radians, VmathVector3 unitVec ) static inline VmathQuat vmathQMakeRotationAxis_V( float radians, VmathVector3 unitVec )
{ {
VmathQuat result; VmathQuat result;
vmathQMakeRotationAxis(&result, radians, &unitVec); vmathQMakeRotationAxis(&result, radians, &unitVec);
return result; return result;
} }
static inline VmathQuat vmathQMakeRotationX_V( float radians ) static inline VmathQuat vmathQMakeRotationX_V( float radians )
{ {
VmathQuat result; VmathQuat result;
vmathQMakeRotationX(&result, radians); vmathQMakeRotationX(&result, radians);
return result; return result;
} }
static inline VmathQuat vmathQMakeRotationY_V( float radians ) static inline VmathQuat vmathQMakeRotationY_V( float radians )
{ {
VmathQuat result; VmathQuat result;
vmathQMakeRotationY(&result, radians); vmathQMakeRotationY(&result, radians);
return result; return result;
} }
static inline VmathQuat vmathQMakeRotationZ_V( float radians ) static inline VmathQuat vmathQMakeRotationZ_V( float radians )
{ {
VmathQuat result; VmathQuat result;
vmathQMakeRotationZ(&result, radians); vmathQMakeRotationZ(&result, radians);
return result; return result;
} }
static inline VmathQuat vmathQMul_V( VmathQuat quat0, VmathQuat quat1 ) static inline VmathQuat vmathQMul_V( VmathQuat quat0, VmathQuat quat1 )
{ {
VmathQuat result; VmathQuat result;
vmathQMul(&result, &quat0, &quat1); vmathQMul(&result, &quat0, &quat1);
return result; return result;
} }
static inline VmathVector3 vmathQRotate_V( VmathQuat quat, VmathVector3 vec ) static inline VmathVector3 vmathQRotate_V( VmathQuat quat, VmathVector3 vec )
{ {
VmathVector3 result; VmathVector3 result;
vmathQRotate(&result, &quat, &vec); vmathQRotate(&result, &quat, &vec);
return result; return result;
} }
static inline VmathQuat vmathQConj_V( VmathQuat quat ) static inline VmathQuat vmathQConj_V( VmathQuat quat )
{ {
VmathQuat result; VmathQuat result;
vmathQConj(&result, &quat); vmathQConj(&result, &quat);
return result; return result;
} }
static inline VmathQuat vmathQSelect_V( VmathQuat quat0, VmathQuat quat1, unsigned int select1 ) static inline VmathQuat vmathQSelect_V( VmathQuat quat0, VmathQuat quat1, unsigned int select1 )
{ {
VmathQuat result; VmathQuat result;
vmathQSelect(&result, &quat0, &quat1, select1); vmathQSelect(&result, &quat0, &quat1, select1);
return result; return result;
} }
#ifdef _VECTORMATH_DEBUG #ifdef _VECTORMATH_DEBUG
static inline void vmathQPrint_V( VmathQuat quat ) static inline void vmathQPrint_V( VmathQuat quat )
{ {
vmathQPrint(&quat); vmathQPrint(&quat);
} }
static inline void vmathQPrints_V( VmathQuat quat, const char *name ) static inline void vmathQPrints_V( VmathQuat quat, const char *name )
{ {
vmathQPrints(&quat, name); vmathQPrints(&quat, name);
} }
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif #endif

View File

@@ -1,415 +1,415 @@
/* /*
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc. Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the with or without modification, are permitted provided that the
following conditions are met: following conditions are met:
* Redistributions of source code must retain the above copyright * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright * Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names * Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission. from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef _VECTORMATH_QUAT_SOA_C_H #ifndef _VECTORMATH_QUAT_SOA_C_H
#define _VECTORMATH_QUAT_SOA_C_H #define _VECTORMATH_QUAT_SOA_C_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
/*----------------------------------------------------------------------------- /*-----------------------------------------------------------------------------
* Definitions * Definitions
*/ */
#ifndef _VECTORMATH_INTERNAL_FUNCTIONS #ifndef _VECTORMATH_INTERNAL_FUNCTIONS
#define _VECTORMATH_INTERNAL_FUNCTIONS #define _VECTORMATH_INTERNAL_FUNCTIONS
#endif #endif
static inline void vmathSoaQCopy( VmathSoaQuat *result, const VmathSoaQuat *quat ) static inline void vmathSoaQCopy( VmathSoaQuat *result, const VmathSoaQuat *quat )
{ {
result->x = quat->x; result->x = quat->x;
result->y = quat->y; result->y = quat->y;
result->z = quat->z; result->z = quat->z;
result->w = quat->w; result->w = quat->w;
} }
static inline void vmathSoaQMakeFromElems( VmathSoaQuat *result, vec_float4 _x, vec_float4 _y, vec_float4 _z, vec_float4 _w ) static inline void vmathSoaQMakeFromElems( VmathSoaQuat *result, vec_float4 _x, vec_float4 _y, vec_float4 _z, vec_float4 _w )
{ {
result->x = _x; result->x = _x;
result->y = _y; result->y = _y;
result->z = _z; result->z = _z;
result->w = _w; result->w = _w;
} }
static inline void vmathSoaQMakeFromV3Scalar( VmathSoaQuat *result, const VmathSoaVector3 *xyz, vec_float4 _w ) static inline void vmathSoaQMakeFromV3Scalar( VmathSoaQuat *result, const VmathSoaVector3 *xyz, vec_float4 _w )
{ {
vmathSoaQSetXYZ( result, xyz ); vmathSoaQSetXYZ( result, xyz );
vmathSoaQSetW( result, _w ); vmathSoaQSetW( result, _w );
} }
static inline void vmathSoaQMakeFromV4( VmathSoaQuat *result, const VmathSoaVector4 *vec ) static inline void vmathSoaQMakeFromV4( VmathSoaQuat *result, const VmathSoaVector4 *vec )
{ {
result->x = vec->x; result->x = vec->x;
result->y = vec->y; result->y = vec->y;
result->z = vec->z; result->z = vec->z;
result->w = vec->w; result->w = vec->w;
} }
static inline void vmathSoaQMakeFromScalar( VmathSoaQuat *result, vec_float4 scalar ) static inline void vmathSoaQMakeFromScalar( VmathSoaQuat *result, vec_float4 scalar )
{ {
result->x = scalar; result->x = scalar;
result->y = scalar; result->y = scalar;
result->z = scalar; result->z = scalar;
result->w = scalar; result->w = scalar;
} }
static inline void vmathSoaQMakeFromAos( VmathSoaQuat *result, const VmathQuat *quat ) static inline void vmathSoaQMakeFromAos( VmathSoaQuat *result, const VmathQuat *quat )
{ {
vec_float4 vec128 = quat->vec128; vec_float4 vec128 = quat->vec128;
result->x = vec_splat( vec128, 0 ); result->x = vec_splat( vec128, 0 );
result->y = vec_splat( vec128, 1 ); result->y = vec_splat( vec128, 1 );
result->z = vec_splat( vec128, 2 ); result->z = vec_splat( vec128, 2 );
result->w = vec_splat( vec128, 3 ); result->w = vec_splat( vec128, 3 );
} }
static inline void vmathSoaQMakeFrom4Aos( VmathSoaQuat *result, const VmathQuat *quat0, const VmathQuat *quat1, const VmathQuat *quat2, const VmathQuat *quat3 ) static inline void vmathSoaQMakeFrom4Aos( VmathSoaQuat *result, const VmathQuat *quat0, const VmathQuat *quat1, const VmathQuat *quat2, const VmathQuat *quat3 )
{ {
vec_float4 tmp0, tmp1, tmp2, tmp3; vec_float4 tmp0, tmp1, tmp2, tmp3;
tmp0 = vec_mergeh( quat0->vec128, quat2->vec128 ); tmp0 = vec_mergeh( quat0->vec128, quat2->vec128 );
tmp1 = vec_mergeh( quat1->vec128, quat3->vec128 ); tmp1 = vec_mergeh( quat1->vec128, quat3->vec128 );
tmp2 = vec_mergel( quat0->vec128, quat2->vec128 ); tmp2 = vec_mergel( quat0->vec128, quat2->vec128 );
tmp3 = vec_mergel( quat1->vec128, quat3->vec128 ); tmp3 = vec_mergel( quat1->vec128, quat3->vec128 );
result->x = vec_mergeh( tmp0, tmp1 ); result->x = vec_mergeh( tmp0, tmp1 );
result->y = vec_mergel( tmp0, tmp1 ); result->y = vec_mergel( tmp0, tmp1 );
result->z = vec_mergeh( tmp2, tmp3 ); result->z = vec_mergeh( tmp2, tmp3 );
result->w = vec_mergel( tmp2, tmp3 ); result->w = vec_mergel( tmp2, tmp3 );
} }
static inline void vmathSoaQMakeIdentity( VmathSoaQuat *result ) static inline void vmathSoaQMakeIdentity( VmathSoaQuat *result )
{ {
vmathSoaQMakeFromElems( result, ((vec_float4){0.0f,0.0f,0.0f,0.0f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}), ((vec_float4){1.0f,1.0f,1.0f,1.0f}) ); vmathSoaQMakeFromElems( result, ((vec_float4){0.0f,0.0f,0.0f,0.0f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}), ((vec_float4){1.0f,1.0f,1.0f,1.0f}) );
} }
static inline void vmathSoaQLerp( VmathSoaQuat *result, vec_float4 t, const VmathSoaQuat *quat0, const VmathSoaQuat *quat1 ) static inline void vmathSoaQLerp( VmathSoaQuat *result, vec_float4 t, const VmathSoaQuat *quat0, const VmathSoaQuat *quat1 )
{ {
VmathSoaQuat tmpQ_0, tmpQ_1; VmathSoaQuat tmpQ_0, tmpQ_1;
vmathSoaQSub( &tmpQ_0, quat1, quat0 ); vmathSoaQSub( &tmpQ_0, quat1, quat0 );
vmathSoaQScalarMul( &tmpQ_1, &tmpQ_0, t ); vmathSoaQScalarMul( &tmpQ_1, &tmpQ_0, t );
vmathSoaQAdd( result, quat0, &tmpQ_1 ); vmathSoaQAdd( result, quat0, &tmpQ_1 );
} }
static inline void vmathSoaQSlerp( VmathSoaQuat *result, vec_float4 t, const VmathSoaQuat *unitQuat0, const VmathSoaQuat *unitQuat1 ) static inline void vmathSoaQSlerp( VmathSoaQuat *result, vec_float4 t, const VmathSoaQuat *unitQuat0, const VmathSoaQuat *unitQuat1 )
{ {
VmathSoaQuat start, tmpQ_0, tmpQ_1; VmathSoaQuat start, tmpQ_0, tmpQ_1;
vec_float4 recipSinAngle, scale0, scale1, cosAngle, angle; vec_float4 recipSinAngle, scale0, scale1, cosAngle, angle;
vec_uint4 selectMask; vec_uint4 selectMask;
cosAngle = vmathSoaQDot( unitQuat0, unitQuat1 ); cosAngle = vmathSoaQDot( unitQuat0, unitQuat1 );
selectMask = (vec_uint4)vec_cmpgt( (vec_float4){0.0f,0.0f,0.0f,0.0f}, cosAngle ); selectMask = (vec_uint4)vec_cmpgt( (vec_float4){0.0f,0.0f,0.0f,0.0f}, cosAngle );
cosAngle = vec_sel( cosAngle, negatef4( cosAngle ), selectMask ); cosAngle = vec_sel( cosAngle, negatef4( cosAngle ), selectMask );
vmathSoaQSetX( &start, vec_sel( unitQuat0->x, negatef4( unitQuat0->x ), selectMask ) ); vmathSoaQSetX( &start, vec_sel( unitQuat0->x, negatef4( unitQuat0->x ), selectMask ) );
vmathSoaQSetY( &start, vec_sel( unitQuat0->y, negatef4( unitQuat0->y ), selectMask ) ); vmathSoaQSetY( &start, vec_sel( unitQuat0->y, negatef4( unitQuat0->y ), selectMask ) );
vmathSoaQSetZ( &start, vec_sel( unitQuat0->z, negatef4( unitQuat0->z ), selectMask ) ); vmathSoaQSetZ( &start, vec_sel( unitQuat0->z, negatef4( unitQuat0->z ), selectMask ) );
vmathSoaQSetW( &start, vec_sel( unitQuat0->w, negatef4( unitQuat0->w ), selectMask ) ); vmathSoaQSetW( &start, vec_sel( unitQuat0->w, negatef4( unitQuat0->w ), selectMask ) );
selectMask = (vec_uint4)vec_cmpgt( (vec_float4){_VECTORMATH_SLERP_TOL,_VECTORMATH_SLERP_TOL,_VECTORMATH_SLERP_TOL,_VECTORMATH_SLERP_TOL}, cosAngle ); selectMask = (vec_uint4)vec_cmpgt( (vec_float4){_VECTORMATH_SLERP_TOL,_VECTORMATH_SLERP_TOL,_VECTORMATH_SLERP_TOL,_VECTORMATH_SLERP_TOL}, cosAngle );
angle = acosf4( cosAngle ); angle = acosf4( cosAngle );
recipSinAngle = divf4( ((vec_float4){1.0f,1.0f,1.0f,1.0f}), sinf4( angle ) ); recipSinAngle = divf4( ((vec_float4){1.0f,1.0f,1.0f,1.0f}), sinf4( angle ) );
scale0 = vec_sel( vec_sub( ((vec_float4){1.0f,1.0f,1.0f,1.0f}), t ), vec_madd( sinf4( vec_madd( vec_sub( ((vec_float4){1.0f,1.0f,1.0f,1.0f}), t ), angle, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), recipSinAngle, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), selectMask ); scale0 = vec_sel( vec_sub( ((vec_float4){1.0f,1.0f,1.0f,1.0f}), t ), vec_madd( sinf4( vec_madd( vec_sub( ((vec_float4){1.0f,1.0f,1.0f,1.0f}), t ), angle, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), recipSinAngle, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), selectMask );
scale1 = vec_sel( t, vec_madd( sinf4( vec_madd( t, angle, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), recipSinAngle, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), selectMask ); scale1 = vec_sel( t, vec_madd( sinf4( vec_madd( t, angle, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), recipSinAngle, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), selectMask );
vmathSoaQScalarMul( &tmpQ_0, &start, scale0 ); vmathSoaQScalarMul( &tmpQ_0, &start, scale0 );
vmathSoaQScalarMul( &tmpQ_1, unitQuat1, scale1 ); vmathSoaQScalarMul( &tmpQ_1, unitQuat1, scale1 );
vmathSoaQAdd( result, &tmpQ_0, &tmpQ_1 ); vmathSoaQAdd( result, &tmpQ_0, &tmpQ_1 );
} }
static inline void vmathSoaQSquad( VmathSoaQuat *result, vec_float4 t, const VmathSoaQuat *unitQuat0, const VmathSoaQuat *unitQuat1, const VmathSoaQuat *unitQuat2, const VmathSoaQuat *unitQuat3 ) static inline void vmathSoaQSquad( VmathSoaQuat *result, vec_float4 t, const VmathSoaQuat *unitQuat0, const VmathSoaQuat *unitQuat1, const VmathSoaQuat *unitQuat2, const VmathSoaQuat *unitQuat3 )
{ {
VmathSoaQuat tmp0, tmp1; VmathSoaQuat tmp0, tmp1;
vmathSoaQSlerp( &tmp0, t, unitQuat0, unitQuat3 ); vmathSoaQSlerp( &tmp0, t, unitQuat0, unitQuat3 );
vmathSoaQSlerp( &tmp1, t, unitQuat1, unitQuat2 ); vmathSoaQSlerp( &tmp1, t, unitQuat1, unitQuat2 );
vmathSoaQSlerp( result, vec_madd( vec_madd( ((vec_float4){2.0f,2.0f,2.0f,2.0f}), t, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_sub( ((vec_float4){1.0f,1.0f,1.0f,1.0f}), t ), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), &tmp0, &tmp1 ); vmathSoaQSlerp( result, vec_madd( vec_madd( ((vec_float4){2.0f,2.0f,2.0f,2.0f}), t, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_sub( ((vec_float4){1.0f,1.0f,1.0f,1.0f}), t ), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), &tmp0, &tmp1 );
} }
static inline void vmathSoaQGet4Aos( const VmathSoaQuat *quat, VmathQuat *result0, VmathQuat *result1, VmathQuat *result2, VmathQuat *result3 ) static inline void vmathSoaQGet4Aos( const VmathSoaQuat *quat, VmathQuat *result0, VmathQuat *result1, VmathQuat *result2, VmathQuat *result3 )
{ {
vec_float4 tmp0, tmp1, tmp2, tmp3; vec_float4 tmp0, tmp1, tmp2, tmp3;
tmp0 = vec_mergeh( quat->x, quat->z ); tmp0 = vec_mergeh( quat->x, quat->z );
tmp1 = vec_mergeh( quat->y, quat->w ); tmp1 = vec_mergeh( quat->y, quat->w );
tmp2 = vec_mergel( quat->x, quat->z ); tmp2 = vec_mergel( quat->x, quat->z );
tmp3 = vec_mergel( quat->y, quat->w ); tmp3 = vec_mergel( quat->y, quat->w );
vmathQMakeFrom128( result0, vec_mergeh( tmp0, tmp1 ) ); vmathQMakeFrom128( result0, vec_mergeh( tmp0, tmp1 ) );
vmathQMakeFrom128( result1, vec_mergel( tmp0, tmp1 ) ); vmathQMakeFrom128( result1, vec_mergel( tmp0, tmp1 ) );
vmathQMakeFrom128( result2, vec_mergeh( tmp2, tmp3 ) ); vmathQMakeFrom128( result2, vec_mergeh( tmp2, tmp3 ) );
vmathQMakeFrom128( result3, vec_mergel( tmp2, tmp3 ) ); vmathQMakeFrom128( result3, vec_mergel( tmp2, tmp3 ) );
} }
static inline void vmathSoaQSetXYZ( VmathSoaQuat *result, const VmathSoaVector3 *vec ) static inline void vmathSoaQSetXYZ( VmathSoaQuat *result, const VmathSoaVector3 *vec )
{ {
result->x = vec->x; result->x = vec->x;
result->y = vec->y; result->y = vec->y;
result->z = vec->z; result->z = vec->z;
} }
static inline void vmathSoaQGetXYZ( VmathSoaVector3 *result, const VmathSoaQuat *quat ) static inline void vmathSoaQGetXYZ( VmathSoaVector3 *result, const VmathSoaQuat *quat )
{ {
vmathSoaV3MakeFromElems( result, quat->x, quat->y, quat->z ); vmathSoaV3MakeFromElems( result, quat->x, quat->y, quat->z );
} }
static inline void vmathSoaQSetX( VmathSoaQuat *result, vec_float4 _x ) static inline void vmathSoaQSetX( VmathSoaQuat *result, vec_float4 _x )
{ {
result->x = _x; result->x = _x;
} }
static inline vec_float4 vmathSoaQGetX( const VmathSoaQuat *quat ) static inline vec_float4 vmathSoaQGetX( const VmathSoaQuat *quat )
{ {
return quat->x; return quat->x;
} }
static inline void vmathSoaQSetY( VmathSoaQuat *result, vec_float4 _y ) static inline void vmathSoaQSetY( VmathSoaQuat *result, vec_float4 _y )
{ {
result->y = _y; result->y = _y;
} }
static inline vec_float4 vmathSoaQGetY( const VmathSoaQuat *quat ) static inline vec_float4 vmathSoaQGetY( const VmathSoaQuat *quat )
{ {
return quat->y; return quat->y;
} }
static inline void vmathSoaQSetZ( VmathSoaQuat *result, vec_float4 _z ) static inline void vmathSoaQSetZ( VmathSoaQuat *result, vec_float4 _z )
{ {
result->z = _z; result->z = _z;
} }
static inline vec_float4 vmathSoaQGetZ( const VmathSoaQuat *quat ) static inline vec_float4 vmathSoaQGetZ( const VmathSoaQuat *quat )
{ {
return quat->z; return quat->z;
} }
static inline void vmathSoaQSetW( VmathSoaQuat *result, vec_float4 _w ) static inline void vmathSoaQSetW( VmathSoaQuat *result, vec_float4 _w )
{ {
result->w = _w; result->w = _w;
} }
static inline vec_float4 vmathSoaQGetW( const VmathSoaQuat *quat ) static inline vec_float4 vmathSoaQGetW( const VmathSoaQuat *quat )
{ {
return quat->w; return quat->w;
} }
static inline void vmathSoaQSetElem( VmathSoaQuat *result, int idx, vec_float4 value ) static inline void vmathSoaQSetElem( VmathSoaQuat *result, int idx, vec_float4 value )
{ {
*(&result->x + idx) = value; *(&result->x + idx) = value;
} }
static inline vec_float4 vmathSoaQGetElem( const VmathSoaQuat *quat, int idx ) static inline vec_float4 vmathSoaQGetElem( const VmathSoaQuat *quat, int idx )
{ {
return *(&quat->x + idx); return *(&quat->x + idx);
} }
static inline void vmathSoaQAdd( VmathSoaQuat *result, const VmathSoaQuat *quat0, const VmathSoaQuat *quat1 ) static inline void vmathSoaQAdd( VmathSoaQuat *result, const VmathSoaQuat *quat0, const VmathSoaQuat *quat1 )
{ {
result->x = vec_add( quat0->x, quat1->x ); result->x = vec_add( quat0->x, quat1->x );
result->y = vec_add( quat0->y, quat1->y ); result->y = vec_add( quat0->y, quat1->y );
result->z = vec_add( quat0->z, quat1->z ); result->z = vec_add( quat0->z, quat1->z );
result->w = vec_add( quat0->w, quat1->w ); result->w = vec_add( quat0->w, quat1->w );
} }
static inline void vmathSoaQSub( VmathSoaQuat *result, const VmathSoaQuat *quat0, const VmathSoaQuat *quat1 ) static inline void vmathSoaQSub( VmathSoaQuat *result, const VmathSoaQuat *quat0, const VmathSoaQuat *quat1 )
{ {
result->x = vec_sub( quat0->x, quat1->x ); result->x = vec_sub( quat0->x, quat1->x );
result->y = vec_sub( quat0->y, quat1->y ); result->y = vec_sub( quat0->y, quat1->y );
result->z = vec_sub( quat0->z, quat1->z ); result->z = vec_sub( quat0->z, quat1->z );
result->w = vec_sub( quat0->w, quat1->w ); result->w = vec_sub( quat0->w, quat1->w );
} }
static inline void vmathSoaQScalarMul( VmathSoaQuat *result, const VmathSoaQuat *quat, vec_float4 scalar ) static inline void vmathSoaQScalarMul( VmathSoaQuat *result, const VmathSoaQuat *quat, vec_float4 scalar )
{ {
result->x = vec_madd( quat->x, scalar, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ); result->x = vec_madd( quat->x, scalar, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) );
result->y = vec_madd( quat->y, scalar, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ); result->y = vec_madd( quat->y, scalar, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) );
result->z = vec_madd( quat->z, scalar, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ); result->z = vec_madd( quat->z, scalar, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) );
result->w = vec_madd( quat->w, scalar, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ); result->w = vec_madd( quat->w, scalar, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) );
} }
static inline void vmathSoaQScalarDiv( VmathSoaQuat *result, const VmathSoaQuat *quat, vec_float4 scalar ) static inline void vmathSoaQScalarDiv( VmathSoaQuat *result, const VmathSoaQuat *quat, vec_float4 scalar )
{ {
result->x = divf4( quat->x, scalar ); result->x = divf4( quat->x, scalar );
result->y = divf4( quat->y, scalar ); result->y = divf4( quat->y, scalar );
result->z = divf4( quat->z, scalar ); result->z = divf4( quat->z, scalar );
result->w = divf4( quat->w, scalar ); result->w = divf4( quat->w, scalar );
} }
static inline void vmathSoaQNeg( VmathSoaQuat *result, const VmathSoaQuat *quat ) static inline void vmathSoaQNeg( VmathSoaQuat *result, const VmathSoaQuat *quat )
{ {
result->x = negatef4( quat->x ); result->x = negatef4( quat->x );
result->y = negatef4( quat->y ); result->y = negatef4( quat->y );
result->z = negatef4( quat->z ); result->z = negatef4( quat->z );
result->w = negatef4( quat->w ); result->w = negatef4( quat->w );
} }
static inline vec_float4 vmathSoaQDot( const VmathSoaQuat *quat0, const VmathSoaQuat *quat1 ) static inline vec_float4 vmathSoaQDot( const VmathSoaQuat *quat0, const VmathSoaQuat *quat1 )
{ {
vec_float4 result; vec_float4 result;
result = vec_madd( quat0->x, quat1->x, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ); result = vec_madd( quat0->x, quat1->x, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) );
result = vec_add( result, vec_madd( quat0->y, quat1->y, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ); result = vec_add( result, vec_madd( quat0->y, quat1->y, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) );
result = vec_add( result, vec_madd( quat0->z, quat1->z, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ); result = vec_add( result, vec_madd( quat0->z, quat1->z, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) );
result = vec_add( result, vec_madd( quat0->w, quat1->w, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ); result = vec_add( result, vec_madd( quat0->w, quat1->w, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) );
return result; return result;
} }
static inline vec_float4 vmathSoaQNorm( const VmathSoaQuat *quat ) static inline vec_float4 vmathSoaQNorm( const VmathSoaQuat *quat )
{ {
vec_float4 result; vec_float4 result;
result = vec_madd( quat->x, quat->x, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ); result = vec_madd( quat->x, quat->x, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) );
result = vec_add( result, vec_madd( quat->y, quat->y, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ); result = vec_add( result, vec_madd( quat->y, quat->y, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) );
result = vec_add( result, vec_madd( quat->z, quat->z, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ); result = vec_add( result, vec_madd( quat->z, quat->z, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) );
result = vec_add( result, vec_madd( quat->w, quat->w, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ); result = vec_add( result, vec_madd( quat->w, quat->w, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) );
return result; return result;
} }
static inline vec_float4 vmathSoaQLength( const VmathSoaQuat *quat ) static inline vec_float4 vmathSoaQLength( const VmathSoaQuat *quat )
{ {
return sqrtf4( vmathSoaQNorm( quat ) ); return sqrtf4( vmathSoaQNorm( quat ) );
} }
static inline void vmathSoaQNormalize( VmathSoaQuat *result, const VmathSoaQuat *quat ) static inline void vmathSoaQNormalize( VmathSoaQuat *result, const VmathSoaQuat *quat )
{ {
vec_float4 lenSqr, lenInv; vec_float4 lenSqr, lenInv;
lenSqr = vmathSoaQNorm( quat ); lenSqr = vmathSoaQNorm( quat );
lenInv = divf4( ((vec_float4){1.0f,1.0f,1.0f,1.0f}), sqrtf4( lenSqr ) ); lenInv = divf4( ((vec_float4){1.0f,1.0f,1.0f,1.0f}), sqrtf4( lenSqr ) );
result->x = vec_madd( quat->x, lenInv, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ); result->x = vec_madd( quat->x, lenInv, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) );
result->y = vec_madd( quat->y, lenInv, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ); result->y = vec_madd( quat->y, lenInv, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) );
result->z = vec_madd( quat->z, lenInv, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ); result->z = vec_madd( quat->z, lenInv, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) );
result->w = vec_madd( quat->w, lenInv, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ); result->w = vec_madd( quat->w, lenInv, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) );
} }
static inline void vmathSoaQMakeRotationArc( VmathSoaQuat *result, const VmathSoaVector3 *unitVec0, const VmathSoaVector3 *unitVec1 ) static inline void vmathSoaQMakeRotationArc( VmathSoaQuat *result, const VmathSoaVector3 *unitVec0, const VmathSoaVector3 *unitVec1 )
{ {
VmathSoaVector3 tmpV3_0, tmpV3_1; VmathSoaVector3 tmpV3_0, tmpV3_1;
vec_float4 cosHalfAngleX2, recipCosHalfAngleX2; vec_float4 cosHalfAngleX2, recipCosHalfAngleX2;
cosHalfAngleX2 = sqrtf4( vec_madd( ((vec_float4){2.0f,2.0f,2.0f,2.0f}), vec_add( ((vec_float4){1.0f,1.0f,1.0f,1.0f}), vmathSoaV3Dot( unitVec0, unitVec1 ) ), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ); cosHalfAngleX2 = sqrtf4( vec_madd( ((vec_float4){2.0f,2.0f,2.0f,2.0f}), vec_add( ((vec_float4){1.0f,1.0f,1.0f,1.0f}), vmathSoaV3Dot( unitVec0, unitVec1 ) ), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) );
recipCosHalfAngleX2 = divf4( ((vec_float4){1.0f,1.0f,1.0f,1.0f}), cosHalfAngleX2 ); recipCosHalfAngleX2 = divf4( ((vec_float4){1.0f,1.0f,1.0f,1.0f}), cosHalfAngleX2 );
vmathSoaV3Cross( &tmpV3_0, unitVec0, unitVec1 ); vmathSoaV3Cross( &tmpV3_0, unitVec0, unitVec1 );
vmathSoaV3ScalarMul( &tmpV3_1, &tmpV3_0, recipCosHalfAngleX2 ); vmathSoaV3ScalarMul( &tmpV3_1, &tmpV3_0, recipCosHalfAngleX2 );
vmathSoaQMakeFromV3Scalar( result, &tmpV3_1, vec_madd( cosHalfAngleX2, ((vec_float4){0.5f,0.5f,0.5f,0.5f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ); vmathSoaQMakeFromV3Scalar( result, &tmpV3_1, vec_madd( cosHalfAngleX2, ((vec_float4){0.5f,0.5f,0.5f,0.5f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) );
} }
static inline void vmathSoaQMakeRotationAxis( VmathSoaQuat *result, vec_float4 radians, const VmathSoaVector3 *unitVec ) static inline void vmathSoaQMakeRotationAxis( VmathSoaQuat *result, vec_float4 radians, const VmathSoaVector3 *unitVec )
{ {
VmathSoaVector3 tmpV3_0; VmathSoaVector3 tmpV3_0;
vec_float4 s, c, angle; vec_float4 s, c, angle;
angle = vec_madd( radians, ((vec_float4){0.5f,0.5f,0.5f,0.5f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ); angle = vec_madd( radians, ((vec_float4){0.5f,0.5f,0.5f,0.5f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) );
sincosf4( angle, &s, &c ); sincosf4( angle, &s, &c );
vmathSoaV3ScalarMul( &tmpV3_0, unitVec, s ); vmathSoaV3ScalarMul( &tmpV3_0, unitVec, s );
vmathSoaQMakeFromV3Scalar( result, &tmpV3_0, c ); vmathSoaQMakeFromV3Scalar( result, &tmpV3_0, c );
} }
static inline void vmathSoaQMakeRotationX( VmathSoaQuat *result, vec_float4 radians ) static inline void vmathSoaQMakeRotationX( VmathSoaQuat *result, vec_float4 radians )
{ {
vec_float4 s, c, angle; vec_float4 s, c, angle;
angle = vec_madd( radians, ((vec_float4){0.5f,0.5f,0.5f,0.5f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ); angle = vec_madd( radians, ((vec_float4){0.5f,0.5f,0.5f,0.5f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) );
sincosf4( angle, &s, &c ); sincosf4( angle, &s, &c );
vmathSoaQMakeFromElems( result, s, ((vec_float4){0.0f,0.0f,0.0f,0.0f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}), c ); vmathSoaQMakeFromElems( result, s, ((vec_float4){0.0f,0.0f,0.0f,0.0f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}), c );
} }
static inline void vmathSoaQMakeRotationY( VmathSoaQuat *result, vec_float4 radians ) static inline void vmathSoaQMakeRotationY( VmathSoaQuat *result, vec_float4 radians )
{ {
vec_float4 s, c, angle; vec_float4 s, c, angle;
angle = vec_madd( radians, ((vec_float4){0.5f,0.5f,0.5f,0.5f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ); angle = vec_madd( radians, ((vec_float4){0.5f,0.5f,0.5f,0.5f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) );
sincosf4( angle, &s, &c ); sincosf4( angle, &s, &c );
vmathSoaQMakeFromElems( result, ((vec_float4){0.0f,0.0f,0.0f,0.0f}), s, ((vec_float4){0.0f,0.0f,0.0f,0.0f}), c ); vmathSoaQMakeFromElems( result, ((vec_float4){0.0f,0.0f,0.0f,0.0f}), s, ((vec_float4){0.0f,0.0f,0.0f,0.0f}), c );
} }
static inline void vmathSoaQMakeRotationZ( VmathSoaQuat *result, vec_float4 radians ) static inline void vmathSoaQMakeRotationZ( VmathSoaQuat *result, vec_float4 radians )
{ {
vec_float4 s, c, angle; vec_float4 s, c, angle;
angle = vec_madd( radians, ((vec_float4){0.5f,0.5f,0.5f,0.5f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ); angle = vec_madd( radians, ((vec_float4){0.5f,0.5f,0.5f,0.5f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) );
sincosf4( angle, &s, &c ); sincosf4( angle, &s, &c );
vmathSoaQMakeFromElems( result, ((vec_float4){0.0f,0.0f,0.0f,0.0f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}), s, c ); vmathSoaQMakeFromElems( result, ((vec_float4){0.0f,0.0f,0.0f,0.0f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}), s, c );
} }
static inline void vmathSoaQMul( VmathSoaQuat *result, const VmathSoaQuat *quat0, const VmathSoaQuat *quat1 ) static inline void vmathSoaQMul( VmathSoaQuat *result, const VmathSoaQuat *quat0, const VmathSoaQuat *quat1 )
{ {
vec_float4 tmpX, tmpY, tmpZ, tmpW; vec_float4 tmpX, tmpY, tmpZ, tmpW;
tmpX = vec_sub( vec_add( vec_add( vec_madd( quat0->w, quat1->x, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( quat0->x, quat1->w, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( quat0->y, quat1->z, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( quat0->z, quat1->y, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ); tmpX = vec_sub( vec_add( vec_add( vec_madd( quat0->w, quat1->x, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( quat0->x, quat1->w, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( quat0->y, quat1->z, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( quat0->z, quat1->y, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) );
tmpY = vec_sub( vec_add( vec_add( vec_madd( quat0->w, quat1->y, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( quat0->y, quat1->w, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( quat0->z, quat1->x, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( quat0->x, quat1->z, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ); tmpY = vec_sub( vec_add( vec_add( vec_madd( quat0->w, quat1->y, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( quat0->y, quat1->w, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( quat0->z, quat1->x, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( quat0->x, quat1->z, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) );
tmpZ = vec_sub( vec_add( vec_add( vec_madd( quat0->w, quat1->z, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( quat0->z, quat1->w, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( quat0->x, quat1->y, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( quat0->y, quat1->x, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ); tmpZ = vec_sub( vec_add( vec_add( vec_madd( quat0->w, quat1->z, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( quat0->z, quat1->w, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( quat0->x, quat1->y, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( quat0->y, quat1->x, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) );
tmpW = vec_sub( vec_sub( vec_sub( vec_madd( quat0->w, quat1->w, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( quat0->x, quat1->x, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( quat0->y, quat1->y, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( quat0->z, quat1->z, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ); tmpW = vec_sub( vec_sub( vec_sub( vec_madd( quat0->w, quat1->w, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( quat0->x, quat1->x, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( quat0->y, quat1->y, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( quat0->z, quat1->z, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) );
vmathSoaQMakeFromElems( result, tmpX, tmpY, tmpZ, tmpW ); vmathSoaQMakeFromElems( result, tmpX, tmpY, tmpZ, tmpW );
} }
static inline void vmathSoaQRotate( VmathSoaVector3 *result, const VmathSoaQuat *quat, const VmathSoaVector3 *vec ) static inline void vmathSoaQRotate( VmathSoaVector3 *result, const VmathSoaQuat *quat, const VmathSoaVector3 *vec )
{ {
vec_float4 tmpX, tmpY, tmpZ, tmpW; vec_float4 tmpX, tmpY, tmpZ, tmpW;
tmpX = vec_sub( vec_add( vec_madd( quat->w, vec->x, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( quat->y, vec->z, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( quat->z, vec->y, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ); tmpX = vec_sub( vec_add( vec_madd( quat->w, vec->x, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( quat->y, vec->z, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( quat->z, vec->y, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) );
tmpY = vec_sub( vec_add( vec_madd( quat->w, vec->y, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( quat->z, vec->x, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( quat->x, vec->z, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ); tmpY = vec_sub( vec_add( vec_madd( quat->w, vec->y, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( quat->z, vec->x, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( quat->x, vec->z, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) );
tmpZ = vec_sub( vec_add( vec_madd( quat->w, vec->z, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( quat->x, vec->y, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( quat->y, vec->x, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ); tmpZ = vec_sub( vec_add( vec_madd( quat->w, vec->z, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( quat->x, vec->y, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( quat->y, vec->x, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) );
tmpW = vec_add( vec_add( vec_madd( quat->x, vec->x, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( quat->y, vec->y, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( quat->z, vec->z, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ); tmpW = vec_add( vec_add( vec_madd( quat->x, vec->x, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( quat->y, vec->y, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( quat->z, vec->z, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) );
result->x = vec_add( vec_sub( vec_add( vec_madd( tmpW, quat->x, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( tmpX, quat->w, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( tmpY, quat->z, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( tmpZ, quat->y, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ); result->x = vec_add( vec_sub( vec_add( vec_madd( tmpW, quat->x, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( tmpX, quat->w, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( tmpY, quat->z, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( tmpZ, quat->y, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) );
result->y = vec_add( vec_sub( vec_add( vec_madd( tmpW, quat->y, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( tmpY, quat->w, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( tmpZ, quat->x, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( tmpX, quat->z, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ); result->y = vec_add( vec_sub( vec_add( vec_madd( tmpW, quat->y, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( tmpY, quat->w, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( tmpZ, quat->x, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( tmpX, quat->z, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) );
result->z = vec_add( vec_sub( vec_add( vec_madd( tmpW, quat->z, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( tmpZ, quat->w, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( tmpX, quat->y, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( tmpY, quat->x, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ); result->z = vec_add( vec_sub( vec_add( vec_madd( tmpW, quat->z, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( tmpZ, quat->w, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( tmpX, quat->y, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( tmpY, quat->x, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) );
} }
static inline void vmathSoaQConj( VmathSoaQuat *result, const VmathSoaQuat *quat ) static inline void vmathSoaQConj( VmathSoaQuat *result, const VmathSoaQuat *quat )
{ {
vmathSoaQMakeFromElems( result, negatef4( quat->x ), negatef4( quat->y ), negatef4( quat->z ), quat->w ); vmathSoaQMakeFromElems( result, negatef4( quat->x ), negatef4( quat->y ), negatef4( quat->z ), quat->w );
} }
static inline void vmathSoaQSelect( VmathSoaQuat *result, const VmathSoaQuat *quat0, const VmathSoaQuat *quat1, vec_uint4 select1 ) static inline void vmathSoaQSelect( VmathSoaQuat *result, const VmathSoaQuat *quat0, const VmathSoaQuat *quat1, vec_uint4 select1 )
{ {
result->x = vec_sel( quat0->x, quat1->x, select1 ); result->x = vec_sel( quat0->x, quat1->x, select1 );
result->y = vec_sel( quat0->y, quat1->y, select1 ); result->y = vec_sel( quat0->y, quat1->y, select1 );
result->z = vec_sel( quat0->z, quat1->z, select1 ); result->z = vec_sel( quat0->z, quat1->z, select1 );
result->w = vec_sel( quat0->w, quat1->w, select1 ); result->w = vec_sel( quat0->w, quat1->w, select1 );
} }
#ifdef _VECTORMATH_DEBUG #ifdef _VECTORMATH_DEBUG
static inline void vmathSoaQPrint( const VmathSoaQuat *quat ) static inline void vmathSoaQPrint( const VmathSoaQuat *quat )
{ {
VmathQuat vec0, vec1, vec2, vec3; VmathQuat vec0, vec1, vec2, vec3;
vmathSoaQGet4Aos( quat, &vec0, &vec1, &vec2, &vec3 ); vmathSoaQGet4Aos( quat, &vec0, &vec1, &vec2, &vec3 );
printf("slot 0:\n"); printf("slot 0:\n");
vmathQPrint( &vec0 ); vmathQPrint( &vec0 );
printf("slot 1:\n"); printf("slot 1:\n");
vmathQPrint( &vec1 ); vmathQPrint( &vec1 );
printf("slot 2:\n"); printf("slot 2:\n");
vmathQPrint( &vec2 ); vmathQPrint( &vec2 );
printf("slot 3:\n"); printf("slot 3:\n");
vmathQPrint( &vec3 ); vmathQPrint( &vec3 );
} }
static inline void vmathSoaQPrints( const VmathSoaQuat *quat, const char *name ) static inline void vmathSoaQPrints( const VmathSoaQuat *quat, const char *name )
{ {
VmathQuat vec0, vec1, vec2, vec3; VmathQuat vec0, vec1, vec2, vec3;
printf( "%s:\n", name ); printf( "%s:\n", name );
vmathSoaQGet4Aos( quat, &vec0, &vec1, &vec2, &vec3 ); vmathSoaQGet4Aos( quat, &vec0, &vec1, &vec2, &vec3 );
printf("slot 0:\n"); printf("slot 0:\n");
vmathQPrint( &vec0 ); vmathQPrint( &vec0 );
printf("slot 1:\n"); printf("slot 1:\n");
vmathQPrint( &vec1 ); vmathQPrint( &vec1 );
printf("slot 2:\n"); printf("slot 2:\n");
vmathQPrint( &vec2 ); vmathQPrint( &vec2 );
printf("slot 3:\n"); printf("slot 3:\n");
vmathQPrint( &vec3 ); vmathQPrint( &vec3 );
} }
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif #endif

View File

@@ -1,319 +1,319 @@
/* /*
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc. Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the with or without modification, are permitted provided that the
following conditions are met: following conditions are met:
* Redistributions of source code must retain the above copyright * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright * Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names * Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission. from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef _VECTORMATH_QUAT_SOA_V_C_H #ifndef _VECTORMATH_QUAT_SOA_V_C_H
#define _VECTORMATH_QUAT_SOA_V_C_H #define _VECTORMATH_QUAT_SOA_V_C_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
/*----------------------------------------------------------------------------- /*-----------------------------------------------------------------------------
* Definitions * Definitions
*/ */
#ifndef _VECTORMATH_INTERNAL_FUNCTIONS #ifndef _VECTORMATH_INTERNAL_FUNCTIONS
#define _VECTORMATH_INTERNAL_FUNCTIONS #define _VECTORMATH_INTERNAL_FUNCTIONS
#endif #endif
static inline VmathSoaQuat vmathSoaQMakeFromElems_V( vec_float4 _x, vec_float4 _y, vec_float4 _z, vec_float4 _w ) static inline VmathSoaQuat vmathSoaQMakeFromElems_V( vec_float4 _x, vec_float4 _y, vec_float4 _z, vec_float4 _w )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQMakeFromElems(&result, _x, _y, _z, _w); vmathSoaQMakeFromElems(&result, _x, _y, _z, _w);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQMakeFromV3Scalar_V( VmathSoaVector3 xyz, vec_float4 _w ) static inline VmathSoaQuat vmathSoaQMakeFromV3Scalar_V( VmathSoaVector3 xyz, vec_float4 _w )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQMakeFromV3Scalar(&result, &xyz, _w); vmathSoaQMakeFromV3Scalar(&result, &xyz, _w);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQMakeFromV4_V( VmathSoaVector4 vec ) static inline VmathSoaQuat vmathSoaQMakeFromV4_V( VmathSoaVector4 vec )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQMakeFromV4(&result, &vec); vmathSoaQMakeFromV4(&result, &vec);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQMakeFromScalar_V( vec_float4 scalar ) static inline VmathSoaQuat vmathSoaQMakeFromScalar_V( vec_float4 scalar )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQMakeFromScalar(&result, scalar); vmathSoaQMakeFromScalar(&result, scalar);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQMakeFromAos_V( VmathQuat quat ) static inline VmathSoaQuat vmathSoaQMakeFromAos_V( VmathQuat quat )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQMakeFromAos(&result, &quat); vmathSoaQMakeFromAos(&result, &quat);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQMakeFrom4Aos_V( VmathQuat quat0, VmathQuat quat1, VmathQuat quat2, VmathQuat quat3 ) static inline VmathSoaQuat vmathSoaQMakeFrom4Aos_V( VmathQuat quat0, VmathQuat quat1, VmathQuat quat2, VmathQuat quat3 )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQMakeFrom4Aos(&result, &quat0, &quat1, &quat2, &quat3); vmathSoaQMakeFrom4Aos(&result, &quat0, &quat1, &quat2, &quat3);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQMakeIdentity_V( ) static inline VmathSoaQuat vmathSoaQMakeIdentity_V( )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQMakeIdentity(&result); vmathSoaQMakeIdentity(&result);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQLerp_V( vec_float4 t, VmathSoaQuat quat0, VmathSoaQuat quat1 ) static inline VmathSoaQuat vmathSoaQLerp_V( vec_float4 t, VmathSoaQuat quat0, VmathSoaQuat quat1 )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQLerp(&result, t, &quat0, &quat1); vmathSoaQLerp(&result, t, &quat0, &quat1);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQSlerp_V( vec_float4 t, VmathSoaQuat unitQuat0, VmathSoaQuat unitQuat1 ) static inline VmathSoaQuat vmathSoaQSlerp_V( vec_float4 t, VmathSoaQuat unitQuat0, VmathSoaQuat unitQuat1 )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQSlerp(&result, t, &unitQuat0, &unitQuat1); vmathSoaQSlerp(&result, t, &unitQuat0, &unitQuat1);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQSquad_V( vec_float4 t, VmathSoaQuat unitQuat0, VmathSoaQuat unitQuat1, VmathSoaQuat unitQuat2, VmathSoaQuat unitQuat3 ) static inline VmathSoaQuat vmathSoaQSquad_V( vec_float4 t, VmathSoaQuat unitQuat0, VmathSoaQuat unitQuat1, VmathSoaQuat unitQuat2, VmathSoaQuat unitQuat3 )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQSquad(&result, t, &unitQuat0, &unitQuat1, &unitQuat2, &unitQuat3); vmathSoaQSquad(&result, t, &unitQuat0, &unitQuat1, &unitQuat2, &unitQuat3);
return result; return result;
} }
static inline void vmathSoaQGet4Aos_V( VmathSoaQuat quat, VmathQuat *result0, VmathQuat *result1, VmathQuat *result2, VmathQuat *result3 ) static inline void vmathSoaQGet4Aos_V( VmathSoaQuat quat, VmathQuat *result0, VmathQuat *result1, VmathQuat *result2, VmathQuat *result3 )
{ {
vmathSoaQGet4Aos(&quat, result0, result1, result2, result3); vmathSoaQGet4Aos(&quat, result0, result1, result2, result3);
} }
static inline void vmathSoaQSetXYZ_V( VmathSoaQuat *result, VmathSoaVector3 vec ) static inline void vmathSoaQSetXYZ_V( VmathSoaQuat *result, VmathSoaVector3 vec )
{ {
vmathSoaQSetXYZ(result, &vec); vmathSoaQSetXYZ(result, &vec);
} }
static inline VmathSoaVector3 vmathSoaQGetXYZ_V( VmathSoaQuat quat ) static inline VmathSoaVector3 vmathSoaQGetXYZ_V( VmathSoaQuat quat )
{ {
VmathSoaVector3 result; VmathSoaVector3 result;
vmathSoaQGetXYZ(&result, &quat); vmathSoaQGetXYZ(&result, &quat);
return result; return result;
} }
static inline void vmathSoaQSetX_V( VmathSoaQuat *result, vec_float4 _x ) static inline void vmathSoaQSetX_V( VmathSoaQuat *result, vec_float4 _x )
{ {
vmathSoaQSetX(result, _x); vmathSoaQSetX(result, _x);
} }
static inline vec_float4 vmathSoaQGetX_V( VmathSoaQuat quat ) static inline vec_float4 vmathSoaQGetX_V( VmathSoaQuat quat )
{ {
return vmathSoaQGetX(&quat); return vmathSoaQGetX(&quat);
} }
static inline void vmathSoaQSetY_V( VmathSoaQuat *result, vec_float4 _y ) static inline void vmathSoaQSetY_V( VmathSoaQuat *result, vec_float4 _y )
{ {
vmathSoaQSetY(result, _y); vmathSoaQSetY(result, _y);
} }
static inline vec_float4 vmathSoaQGetY_V( VmathSoaQuat quat ) static inline vec_float4 vmathSoaQGetY_V( VmathSoaQuat quat )
{ {
return vmathSoaQGetY(&quat); return vmathSoaQGetY(&quat);
} }
static inline void vmathSoaQSetZ_V( VmathSoaQuat *result, vec_float4 _z ) static inline void vmathSoaQSetZ_V( VmathSoaQuat *result, vec_float4 _z )
{ {
vmathSoaQSetZ(result, _z); vmathSoaQSetZ(result, _z);
} }
static inline vec_float4 vmathSoaQGetZ_V( VmathSoaQuat quat ) static inline vec_float4 vmathSoaQGetZ_V( VmathSoaQuat quat )
{ {
return vmathSoaQGetZ(&quat); return vmathSoaQGetZ(&quat);
} }
static inline void vmathSoaQSetW_V( VmathSoaQuat *result, vec_float4 _w ) static inline void vmathSoaQSetW_V( VmathSoaQuat *result, vec_float4 _w )
{ {
vmathSoaQSetW(result, _w); vmathSoaQSetW(result, _w);
} }
static inline vec_float4 vmathSoaQGetW_V( VmathSoaQuat quat ) static inline vec_float4 vmathSoaQGetW_V( VmathSoaQuat quat )
{ {
return vmathSoaQGetW(&quat); return vmathSoaQGetW(&quat);
} }
static inline void vmathSoaQSetElem_V( VmathSoaQuat *result, int idx, vec_float4 value ) static inline void vmathSoaQSetElem_V( VmathSoaQuat *result, int idx, vec_float4 value )
{ {
vmathSoaQSetElem(result, idx, value); vmathSoaQSetElem(result, idx, value);
} }
static inline vec_float4 vmathSoaQGetElem_V( VmathSoaQuat quat, int idx ) static inline vec_float4 vmathSoaQGetElem_V( VmathSoaQuat quat, int idx )
{ {
return vmathSoaQGetElem(&quat, idx); return vmathSoaQGetElem(&quat, idx);
} }
static inline VmathSoaQuat vmathSoaQAdd_V( VmathSoaQuat quat0, VmathSoaQuat quat1 ) static inline VmathSoaQuat vmathSoaQAdd_V( VmathSoaQuat quat0, VmathSoaQuat quat1 )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQAdd(&result, &quat0, &quat1); vmathSoaQAdd(&result, &quat0, &quat1);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQSub_V( VmathSoaQuat quat0, VmathSoaQuat quat1 ) static inline VmathSoaQuat vmathSoaQSub_V( VmathSoaQuat quat0, VmathSoaQuat quat1 )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQSub(&result, &quat0, &quat1); vmathSoaQSub(&result, &quat0, &quat1);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQScalarMul_V( VmathSoaQuat quat, vec_float4 scalar ) static inline VmathSoaQuat vmathSoaQScalarMul_V( VmathSoaQuat quat, vec_float4 scalar )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQScalarMul(&result, &quat, scalar); vmathSoaQScalarMul(&result, &quat, scalar);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQScalarDiv_V( VmathSoaQuat quat, vec_float4 scalar ) static inline VmathSoaQuat vmathSoaQScalarDiv_V( VmathSoaQuat quat, vec_float4 scalar )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQScalarDiv(&result, &quat, scalar); vmathSoaQScalarDiv(&result, &quat, scalar);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQNeg_V( VmathSoaQuat quat ) static inline VmathSoaQuat vmathSoaQNeg_V( VmathSoaQuat quat )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQNeg(&result, &quat); vmathSoaQNeg(&result, &quat);
return result; return result;
} }
static inline vec_float4 vmathSoaQDot_V( VmathSoaQuat quat0, VmathSoaQuat quat1 ) static inline vec_float4 vmathSoaQDot_V( VmathSoaQuat quat0, VmathSoaQuat quat1 )
{ {
return vmathSoaQDot(&quat0, &quat1); return vmathSoaQDot(&quat0, &quat1);
} }
static inline vec_float4 vmathSoaQNorm_V( VmathSoaQuat quat ) static inline vec_float4 vmathSoaQNorm_V( VmathSoaQuat quat )
{ {
return vmathSoaQNorm(&quat); return vmathSoaQNorm(&quat);
} }
static inline vec_float4 vmathSoaQLength_V( VmathSoaQuat quat ) static inline vec_float4 vmathSoaQLength_V( VmathSoaQuat quat )
{ {
return vmathSoaQLength(&quat); return vmathSoaQLength(&quat);
} }
static inline VmathSoaQuat vmathSoaQNormalize_V( VmathSoaQuat quat ) static inline VmathSoaQuat vmathSoaQNormalize_V( VmathSoaQuat quat )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQNormalize(&result, &quat); vmathSoaQNormalize(&result, &quat);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQMakeRotationArc_V( VmathSoaVector3 unitVec0, VmathSoaVector3 unitVec1 ) static inline VmathSoaQuat vmathSoaQMakeRotationArc_V( VmathSoaVector3 unitVec0, VmathSoaVector3 unitVec1 )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQMakeRotationArc(&result, &unitVec0, &unitVec1); vmathSoaQMakeRotationArc(&result, &unitVec0, &unitVec1);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQMakeRotationAxis_V( vec_float4 radians, VmathSoaVector3 unitVec ) static inline VmathSoaQuat vmathSoaQMakeRotationAxis_V( vec_float4 radians, VmathSoaVector3 unitVec )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQMakeRotationAxis(&result, radians, &unitVec); vmathSoaQMakeRotationAxis(&result, radians, &unitVec);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQMakeRotationX_V( vec_float4 radians ) static inline VmathSoaQuat vmathSoaQMakeRotationX_V( vec_float4 radians )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQMakeRotationX(&result, radians); vmathSoaQMakeRotationX(&result, radians);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQMakeRotationY_V( vec_float4 radians ) static inline VmathSoaQuat vmathSoaQMakeRotationY_V( vec_float4 radians )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQMakeRotationY(&result, radians); vmathSoaQMakeRotationY(&result, radians);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQMakeRotationZ_V( vec_float4 radians ) static inline VmathSoaQuat vmathSoaQMakeRotationZ_V( vec_float4 radians )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQMakeRotationZ(&result, radians); vmathSoaQMakeRotationZ(&result, radians);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQMul_V( VmathSoaQuat quat0, VmathSoaQuat quat1 ) static inline VmathSoaQuat vmathSoaQMul_V( VmathSoaQuat quat0, VmathSoaQuat quat1 )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQMul(&result, &quat0, &quat1); vmathSoaQMul(&result, &quat0, &quat1);
return result; return result;
} }
static inline VmathSoaVector3 vmathSoaQRotate_V( VmathSoaQuat quat, VmathSoaVector3 vec ) static inline VmathSoaVector3 vmathSoaQRotate_V( VmathSoaQuat quat, VmathSoaVector3 vec )
{ {
VmathSoaVector3 result; VmathSoaVector3 result;
vmathSoaQRotate(&result, &quat, &vec); vmathSoaQRotate(&result, &quat, &vec);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQConj_V( VmathSoaQuat quat ) static inline VmathSoaQuat vmathSoaQConj_V( VmathSoaQuat quat )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQConj(&result, &quat); vmathSoaQConj(&result, &quat);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQSelect_V( VmathSoaQuat quat0, VmathSoaQuat quat1, vec_uint4 select1 ) static inline VmathSoaQuat vmathSoaQSelect_V( VmathSoaQuat quat0, VmathSoaQuat quat1, vec_uint4 select1 )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQSelect(&result, &quat0, &quat1, select1); vmathSoaQSelect(&result, &quat0, &quat1, select1);
return result; return result;
} }
#ifdef _VECTORMATH_DEBUG #ifdef _VECTORMATH_DEBUG
static inline void vmathSoaQPrint_V( VmathSoaQuat quat ) static inline void vmathSoaQPrint_V( VmathSoaQuat quat )
{ {
vmathSoaQPrint(&quat); vmathSoaQPrint(&quat);
} }
static inline void vmathSoaQPrints_V( VmathSoaQuat quat, const char *name ) static inline void vmathSoaQPrints_V( VmathSoaQuat quat, const char *name )
{ {
vmathSoaQPrints(&quat, name); vmathSoaQPrints(&quat, name);
} }
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif #endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,261 +1,261 @@
/* /*
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc. Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the with or without modification, are permitted provided that the
following conditions are met: following conditions are met:
* Redistributions of source code must retain the above copyright * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright * Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names * Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission. from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef _BOOLINVEC_H #ifndef _BOOLINVEC_H
#define _BOOLINVEC_H #define _BOOLINVEC_H
#include <math.h> #include <math.h>
#include <altivec.h> #include <altivec.h>
#include "../c/vec_types.h" #include "../c/vec_types.h"
#undef bool #undef bool
namespace Vectormath { namespace Vectormath {
class floatInVec; class floatInVec;
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// boolInVec class // boolInVec class
// //
class boolInVec class boolInVec
{ {
private: private:
vec_uint4 mData; vec_uint4 mData;
inline boolInVec(vec_uint4 vec); inline boolInVec(vec_uint4 vec);
public: public:
inline boolInVec() {} inline boolInVec() {}
// matches standard type conversions // matches standard type conversions
// //
inline boolInVec(floatInVec vec); inline boolInVec(floatInVec vec);
// explicit cast from bool // explicit cast from bool
// //
explicit inline boolInVec(bool scalar); explicit inline boolInVec(bool scalar);
#ifdef _VECTORMATH_NO_SCALAR_CAST #ifdef _VECTORMATH_NO_SCALAR_CAST
// explicit cast to bool // explicit cast to bool
// //
inline bool getAsBool() const; inline bool getAsBool() const;
#else #else
// implicit cast to bool // implicit cast to bool
// //
inline operator bool() const; inline operator bool() const;
#endif #endif
// get vector data // get vector data
// bool value is splatted across all word slots of vector as 0 (false) or -1 (true) // bool value is splatted across all word slots of vector as 0 (false) or -1 (true)
// //
inline vec_uint4 get128() const; inline vec_uint4 get128() const;
// operators // operators
// //
inline const boolInVec operator ! () const; inline const boolInVec operator ! () const;
inline boolInVec& operator = (boolInVec vec); inline boolInVec& operator = (boolInVec vec);
inline boolInVec& operator &= (boolInVec vec); inline boolInVec& operator &= (boolInVec vec);
inline boolInVec& operator ^= (boolInVec vec); inline boolInVec& operator ^= (boolInVec vec);
inline boolInVec& operator |= (boolInVec vec); inline boolInVec& operator |= (boolInVec vec);
// friend functions // friend functions
// //
friend inline const boolInVec operator == (boolInVec vec0, boolInVec vec1); friend inline const boolInVec operator == (boolInVec vec0, boolInVec vec1);
friend inline const boolInVec operator != (boolInVec vec0, boolInVec vec1); friend inline const boolInVec operator != (boolInVec vec0, boolInVec vec1);
friend inline const boolInVec operator < (floatInVec vec0, floatInVec vec1); friend inline const boolInVec operator < (floatInVec vec0, floatInVec vec1);
friend inline const boolInVec operator <= (floatInVec vec0, floatInVec vec1); friend inline const boolInVec operator <= (floatInVec vec0, floatInVec vec1);
friend inline const boolInVec operator > (floatInVec vec0, floatInVec vec1); friend inline const boolInVec operator > (floatInVec vec0, floatInVec vec1);
friend inline const boolInVec operator >= (floatInVec vec0, floatInVec vec1); friend inline const boolInVec operator >= (floatInVec vec0, floatInVec vec1);
friend inline const boolInVec operator == (floatInVec vec0, floatInVec vec1); friend inline const boolInVec operator == (floatInVec vec0, floatInVec vec1);
friend inline const boolInVec operator != (floatInVec vec0, floatInVec vec1); friend inline const boolInVec operator != (floatInVec vec0, floatInVec vec1);
friend inline const boolInVec operator & (boolInVec vec0, boolInVec vec1); friend inline const boolInVec operator & (boolInVec vec0, boolInVec vec1);
friend inline const boolInVec operator ^ (boolInVec vec0, boolInVec vec1); friend inline const boolInVec operator ^ (boolInVec vec0, boolInVec vec1);
friend inline const boolInVec operator | (boolInVec vec0, boolInVec vec1); friend inline const boolInVec operator | (boolInVec vec0, boolInVec vec1);
friend inline const boolInVec select(boolInVec vec0, boolInVec vec1, boolInVec select_vec1); friend inline const boolInVec select(boolInVec vec0, boolInVec vec1, boolInVec select_vec1);
}; };
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// boolInVec functions // boolInVec functions
// //
// operators // operators
// //
inline const boolInVec operator == (boolInVec vec0, boolInVec vec1); inline const boolInVec operator == (boolInVec vec0, boolInVec vec1);
inline const boolInVec operator != (boolInVec vec0, boolInVec vec1); inline const boolInVec operator != (boolInVec vec0, boolInVec vec1);
inline const boolInVec operator & (boolInVec vec0, boolInVec vec1); inline const boolInVec operator & (boolInVec vec0, boolInVec vec1);
inline const boolInVec operator ^ (boolInVec vec0, boolInVec vec1); inline const boolInVec operator ^ (boolInVec vec0, boolInVec vec1);
inline const boolInVec operator | (boolInVec vec0, boolInVec vec1); inline const boolInVec operator | (boolInVec vec0, boolInVec vec1);
// select between vec0 and vec1 using boolInVec. // select between vec0 and vec1 using boolInVec.
// false selects vec0, true selects vec1 // false selects vec0, true selects vec1
// //
inline const boolInVec select(boolInVec vec0, boolInVec vec1, boolInVec select_vec1); inline const boolInVec select(boolInVec vec0, boolInVec vec1, boolInVec select_vec1);
} // namespace Vectormath } // namespace Vectormath
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// boolInVec implementation // boolInVec implementation
// //
#include "floatInVec.h" #include "floatInVec.h"
namespace Vectormath { namespace Vectormath {
inline inline
boolInVec::boolInVec(vec_uint4 vec) boolInVec::boolInVec(vec_uint4 vec)
{ {
mData = vec; mData = vec;
} }
inline inline
boolInVec::boolInVec(floatInVec vec) boolInVec::boolInVec(floatInVec vec)
{ {
*this = (vec != floatInVec(0.0f)); *this = (vec != floatInVec(0.0f));
} }
inline inline
boolInVec::boolInVec(bool scalar) boolInVec::boolInVec(bool scalar)
{ {
#ifdef __GNUC__ #ifdef __GNUC__
if (__builtin_constant_p(scalar)) if (__builtin_constant_p(scalar))
{ {
const unsigned int mask = -(int)scalar; const unsigned int mask = -(int)scalar;
mData = (vec_uint4){mask, mask, mask, mask}; mData = (vec_uint4){mask, mask, mask, mask};
} }
else else
#endif #endif
{ {
unsigned int mask = -(int)scalar; unsigned int mask = -(int)scalar;
vec_uint4 vec = vec_ld(0, &mask); vec_uint4 vec = vec_ld(0, &mask);
mData = vec_splat(vec_perm(vec, vec, vec_lvsl(0, &mask)), 0); mData = vec_splat(vec_perm(vec, vec, vec_lvsl(0, &mask)), 0);
} }
} }
#ifdef _VECTORMATH_NO_SCALAR_CAST #ifdef _VECTORMATH_NO_SCALAR_CAST
inline inline
bool bool
boolInVec::getAsBool() const boolInVec::getAsBool() const
#else #else
inline inline
boolInVec::operator bool() const boolInVec::operator bool() const
#endif #endif
{ {
return vec_all_gt(mData, ((vec_uint4){0,0,0,0})); return vec_all_gt(mData, ((vec_uint4){0,0,0,0}));
} }
inline inline
vec_uint4 vec_uint4
boolInVec::get128() const boolInVec::get128() const
{ {
return mData; return mData;
} }
inline inline
const boolInVec const boolInVec
boolInVec::operator ! () const boolInVec::operator ! () const
{ {
return boolInVec(vec_nor(mData, mData)); return boolInVec(vec_nor(mData, mData));
} }
inline inline
boolInVec& boolInVec&
boolInVec::operator = (boolInVec vec) boolInVec::operator = (boolInVec vec)
{ {
mData = vec.mData; mData = vec.mData;
return *this; return *this;
} }
inline inline
boolInVec& boolInVec&
boolInVec::operator &= (boolInVec vec) boolInVec::operator &= (boolInVec vec)
{ {
*this = *this & vec; *this = *this & vec;
return *this; return *this;
} }
inline inline
boolInVec& boolInVec&
boolInVec::operator ^= (boolInVec vec) boolInVec::operator ^= (boolInVec vec)
{ {
*this = *this ^ vec; *this = *this ^ vec;
return *this; return *this;
} }
inline inline
boolInVec& boolInVec&
boolInVec::operator |= (boolInVec vec) boolInVec::operator |= (boolInVec vec)
{ {
*this = *this | vec; *this = *this | vec;
return *this; return *this;
} }
inline inline
const boolInVec const boolInVec
operator == (boolInVec vec0, boolInVec vec1) operator == (boolInVec vec0, boolInVec vec1)
{ {
return boolInVec((vec_uint4)vec_cmpeq(vec0.get128(), vec1.get128())); return boolInVec((vec_uint4)vec_cmpeq(vec0.get128(), vec1.get128()));
} }
inline inline
const boolInVec const boolInVec
operator != (boolInVec vec0, boolInVec vec1) operator != (boolInVec vec0, boolInVec vec1)
{ {
return !(vec0 == vec1); return !(vec0 == vec1);
} }
inline inline
const boolInVec const boolInVec
operator & (boolInVec vec0, boolInVec vec1) operator & (boolInVec vec0, boolInVec vec1)
{ {
return boolInVec(vec_and(vec0.get128(), vec1.get128())); return boolInVec(vec_and(vec0.get128(), vec1.get128()));
} }
inline inline
const boolInVec const boolInVec
operator | (boolInVec vec0, boolInVec vec1) operator | (boolInVec vec0, boolInVec vec1)
{ {
return boolInVec(vec_or(vec0.get128(), vec1.get128())); return boolInVec(vec_or(vec0.get128(), vec1.get128()));
} }
inline inline
const boolInVec const boolInVec
operator ^ (boolInVec vec0, boolInVec vec1) operator ^ (boolInVec vec0, boolInVec vec1)
{ {
return boolInVec(vec_xor(vec0.get128(), vec1.get128())); return boolInVec(vec_xor(vec0.get128(), vec1.get128()));
} }
inline inline
const boolInVec const boolInVec
select(boolInVec vec0, boolInVec vec1, boolInVec select_vec1) select(boolInVec vec0, boolInVec vec1, boolInVec select_vec1)
{ {
return boolInVec(vec_sel(vec0.get128(), vec1.get128(), select_vec1.get128())); return boolInVec(vec_sel(vec0.get128(), vec1.get128(), select_vec1.get128()));
} }
} // namespace Vectormath } // namespace Vectormath
#endif // boolInVec_h #endif // boolInVec_h

View File

@@ -1,361 +1,361 @@
/* /*
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc. Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the with or without modification, are permitted provided that the
following conditions are met: following conditions are met:
* Redistributions of source code must retain the above copyright * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright * Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names * Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission. from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef _FLOATINVEC_H #ifndef _FLOATINVEC_H
#define _FLOATINVEC_H #define _FLOATINVEC_H
#include <math.h> #include <math.h>
#include <altivec.h> #include <altivec.h>
#include <stddef.h> #include <stddef.h>
#include <simdmath.h> #include <simdmath.h>
#include "../c/vec_types.h" #include "../c/vec_types.h"
#undef bool #undef bool
namespace Vectormath { namespace Vectormath {
class boolInVec; class boolInVec;
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// floatInVec class // floatInVec class
// //
class floatInVec class floatInVec
{ {
private: private:
vec_float4 mData; vec_float4 mData;
inline floatInVec(vec_float4 vec); inline floatInVec(vec_float4 vec);
public: public:
inline floatInVec() {} inline floatInVec() {}
// matches standard type conversions // matches standard type conversions
// //
inline floatInVec(boolInVec vec); inline floatInVec(boolInVec vec);
// construct from a slot of vec_float4 // construct from a slot of vec_float4
// //
inline floatInVec(vec_float4 vec, int slot); inline floatInVec(vec_float4 vec, int slot);
// explicit cast from float // explicit cast from float
// //
explicit inline floatInVec(float scalar); explicit inline floatInVec(float scalar);
#ifdef _VECTORMATH_NO_SCALAR_CAST #ifdef _VECTORMATH_NO_SCALAR_CAST
// explicit cast to float // explicit cast to float
// //
inline float getAsFloat() const; inline float getAsFloat() const;
#else #else
// implicit cast to float // implicit cast to float
// //
inline operator float() const; inline operator float() const;
#endif #endif
// get vector data // get vector data
// float value is splatted across all word slots of vector // float value is splatted across all word slots of vector
// //
inline vec_float4 get128() const; inline vec_float4 get128() const;
// operators // operators
// //
inline const floatInVec operator ++ (int); inline const floatInVec operator ++ (int);
inline const floatInVec operator -- (int); inline const floatInVec operator -- (int);
inline floatInVec& operator ++ (); inline floatInVec& operator ++ ();
inline floatInVec& operator -- (); inline floatInVec& operator -- ();
inline const floatInVec operator - () const; inline const floatInVec operator - () const;
inline floatInVec& operator = (floatInVec vec); inline floatInVec& operator = (floatInVec vec);
inline floatInVec& operator *= (floatInVec vec); inline floatInVec& operator *= (floatInVec vec);
inline floatInVec& operator /= (floatInVec vec); inline floatInVec& operator /= (floatInVec vec);
inline floatInVec& operator += (floatInVec vec); inline floatInVec& operator += (floatInVec vec);
inline floatInVec& operator -= (floatInVec vec); inline floatInVec& operator -= (floatInVec vec);
// friend functions // friend functions
// //
friend inline const floatInVec operator * (floatInVec vec0, floatInVec vec1); friend inline const floatInVec operator * (floatInVec vec0, floatInVec vec1);
friend inline const floatInVec operator / (floatInVec vec0, floatInVec vec1); friend inline const floatInVec operator / (floatInVec vec0, floatInVec vec1);
friend inline const floatInVec operator + (floatInVec vec0, floatInVec vec1); friend inline const floatInVec operator + (floatInVec vec0, floatInVec vec1);
friend inline const floatInVec operator - (floatInVec vec0, floatInVec vec1); friend inline const floatInVec operator - (floatInVec vec0, floatInVec vec1);
friend inline const floatInVec select(floatInVec vec0, floatInVec vec1, boolInVec select_vec1); friend inline const floatInVec select(floatInVec vec0, floatInVec vec1, boolInVec select_vec1);
}; };
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// floatInVec functions // floatInVec functions
// //
// operators // operators
// //
inline const floatInVec operator * (floatInVec vec0, floatInVec vec1); inline const floatInVec operator * (floatInVec vec0, floatInVec vec1);
inline const floatInVec operator / (floatInVec vec0, floatInVec vec1); inline const floatInVec operator / (floatInVec vec0, floatInVec vec1);
inline const floatInVec operator + (floatInVec vec0, floatInVec vec1); inline const floatInVec operator + (floatInVec vec0, floatInVec vec1);
inline const floatInVec operator - (floatInVec vec0, floatInVec vec1); inline const floatInVec operator - (floatInVec vec0, floatInVec vec1);
inline const boolInVec operator < (floatInVec vec0, floatInVec vec1); inline const boolInVec operator < (floatInVec vec0, floatInVec vec1);
inline const boolInVec operator <= (floatInVec vec0, floatInVec vec1); inline const boolInVec operator <= (floatInVec vec0, floatInVec vec1);
inline const boolInVec operator > (floatInVec vec0, floatInVec vec1); inline const boolInVec operator > (floatInVec vec0, floatInVec vec1);
inline const boolInVec operator >= (floatInVec vec0, floatInVec vec1); inline const boolInVec operator >= (floatInVec vec0, floatInVec vec1);
inline const boolInVec operator == (floatInVec vec0, floatInVec vec1); inline const boolInVec operator == (floatInVec vec0, floatInVec vec1);
inline const boolInVec operator != (floatInVec vec0, floatInVec vec1); inline const boolInVec operator != (floatInVec vec0, floatInVec vec1);
// select between vec0 and vec1 using boolInVec. // select between vec0 and vec1 using boolInVec.
// false selects vec0, true selects vec1 // false selects vec0, true selects vec1
// //
inline const floatInVec select(floatInVec vec0, floatInVec vec1, boolInVec select_vec1); inline const floatInVec select(floatInVec vec0, floatInVec vec1, boolInVec select_vec1);
} // namespace Vectormath } // namespace Vectormath
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// floatInVec implementation // floatInVec implementation
// //
#include "boolInVec.h" #include "boolInVec.h"
namespace Vectormath { namespace Vectormath {
inline inline
floatInVec::floatInVec(vec_float4 vec) floatInVec::floatInVec(vec_float4 vec)
{ {
mData = vec; mData = vec;
} }
inline inline
floatInVec::floatInVec(boolInVec vec) floatInVec::floatInVec(boolInVec vec)
{ {
mData = vec_ctf(vec_sub((vec_uint4){0,0,0,0}, vec.get128()), 0); mData = vec_ctf(vec_sub((vec_uint4){0,0,0,0}, vec.get128()), 0);
} }
inline inline
floatInVec::floatInVec(vec_float4 vec, int slot) floatInVec::floatInVec(vec_float4 vec, int slot)
{ {
#ifdef __GNUC__ #ifdef __GNUC__
if (__builtin_constant_p(slot)) if (__builtin_constant_p(slot))
{ {
mData = vec_splat(vec, slot); mData = vec_splat(vec, slot);
} }
else else
#endif #endif
{ {
const vec_uchar16 shiftpattern = vec_lvsl(0, (float *)(size_t)(slot << 2)); const vec_uchar16 shiftpattern = vec_lvsl(0, (float *)(size_t)(slot << 2));
mData = vec_splat(vec_perm(vec, vec, shiftpattern), 0); mData = vec_splat(vec_perm(vec, vec, shiftpattern), 0);
} }
} }
inline inline
floatInVec::floatInVec(float scalar) floatInVec::floatInVec(float scalar)
{ {
#ifdef __GNUC__ #ifdef __GNUC__
if (__builtin_constant_p(scalar)) if (__builtin_constant_p(scalar))
{ {
mData = (vec_float4){scalar, scalar, scalar, scalar}; mData = (vec_float4){scalar, scalar, scalar, scalar};
} }
else else
#endif #endif
{ {
vec_float4 vec = vec_ld(0, &scalar); vec_float4 vec = vec_ld(0, &scalar);
mData = vec_splat(vec_perm(vec, vec, vec_lvsl(0, &scalar)), 0); mData = vec_splat(vec_perm(vec, vec, vec_lvsl(0, &scalar)), 0);
} }
} }
#ifdef _VECTORMATH_NO_SCALAR_CAST #ifdef _VECTORMATH_NO_SCALAR_CAST
inline inline
float float
floatInVec::getAsFloat() const floatInVec::getAsFloat() const
#else #else
inline inline
floatInVec::operator float() const floatInVec::operator float() const
#endif #endif
{ {
return *((float *)&mData); return *((float *)&mData);
} }
inline inline
vec_float4 vec_float4
floatInVec::get128() const floatInVec::get128() const
{ {
return mData; return mData;
} }
inline inline
const floatInVec const floatInVec
floatInVec::operator ++ (int) floatInVec::operator ++ (int)
{ {
vec_float4 olddata = mData; vec_float4 olddata = mData;
operator ++(); operator ++();
return floatInVec(olddata); return floatInVec(olddata);
} }
inline inline
const floatInVec const floatInVec
floatInVec::operator -- (int) floatInVec::operator -- (int)
{ {
vec_float4 olddata = mData; vec_float4 olddata = mData;
operator --(); operator --();
return floatInVec(olddata); return floatInVec(olddata);
} }
inline inline
floatInVec& floatInVec&
floatInVec::operator ++ () floatInVec::operator ++ ()
{ {
*this += floatInVec((vec_float4){1.0f,1.0f,1.0f,1.0f}); *this += floatInVec((vec_float4){1.0f,1.0f,1.0f,1.0f});
return *this; return *this;
} }
inline inline
floatInVec& floatInVec&
floatInVec::operator -- () floatInVec::operator -- ()
{ {
*this -= floatInVec((vec_float4){1.0f,1.0f,1.0f,1.0f}); *this -= floatInVec((vec_float4){1.0f,1.0f,1.0f,1.0f});
return *this; return *this;
} }
inline inline
const floatInVec const floatInVec
floatInVec::operator - () const floatInVec::operator - () const
{ {
return floatInVec((vec_float4)vec_xor((vec_uint4)mData, (vec_uint4){0x80000000,0x80000000,0x80000000,0x80000000})); return floatInVec((vec_float4)vec_xor((vec_uint4)mData, (vec_uint4){0x80000000,0x80000000,0x80000000,0x80000000}));
} }
inline inline
floatInVec& floatInVec&
floatInVec::operator = (floatInVec vec) floatInVec::operator = (floatInVec vec)
{ {
mData = vec.mData; mData = vec.mData;
return *this; return *this;
} }
inline inline
floatInVec& floatInVec&
floatInVec::operator *= (floatInVec vec) floatInVec::operator *= (floatInVec vec)
{ {
*this = *this * vec; *this = *this * vec;
return *this; return *this;
} }
inline inline
floatInVec& floatInVec&
floatInVec::operator /= (floatInVec vec) floatInVec::operator /= (floatInVec vec)
{ {
*this = *this / vec; *this = *this / vec;
return *this; return *this;
} }
inline inline
floatInVec& floatInVec&
floatInVec::operator += (floatInVec vec) floatInVec::operator += (floatInVec vec)
{ {
*this = *this + vec; *this = *this + vec;
return *this; return *this;
} }
inline inline
floatInVec& floatInVec&
floatInVec::operator -= (floatInVec vec) floatInVec::operator -= (floatInVec vec)
{ {
*this = *this - vec; *this = *this - vec;
return *this; return *this;
} }
inline inline
const floatInVec const floatInVec
operator * (floatInVec vec0, floatInVec vec1) operator * (floatInVec vec0, floatInVec vec1)
{ {
return floatInVec(vec_madd(vec0.get128(), vec1.get128(), (vec_float4){0,0,0,0})); return floatInVec(vec_madd(vec0.get128(), vec1.get128(), (vec_float4){0,0,0,0}));
} }
inline inline
const floatInVec const floatInVec
operator / (floatInVec num, floatInVec den) operator / (floatInVec num, floatInVec den)
{ {
return floatInVec(divf4(num.get128(), den.get128())); return floatInVec(divf4(num.get128(), den.get128()));
} }
inline inline
const floatInVec const floatInVec
operator + (floatInVec vec0, floatInVec vec1) operator + (floatInVec vec0, floatInVec vec1)
{ {
return floatInVec(vec_add(vec0.get128(), vec1.get128())); return floatInVec(vec_add(vec0.get128(), vec1.get128()));
} }
inline inline
const floatInVec const floatInVec
operator - (floatInVec vec0, floatInVec vec1) operator - (floatInVec vec0, floatInVec vec1)
{ {
return floatInVec(vec_sub(vec0.get128(), vec1.get128())); return floatInVec(vec_sub(vec0.get128(), vec1.get128()));
} }
inline inline
const boolInVec const boolInVec
operator < (floatInVec vec0, floatInVec vec1) operator < (floatInVec vec0, floatInVec vec1)
{ {
return boolInVec((vec_uint4)vec_cmpgt(vec1.get128(), vec0.get128())); return boolInVec((vec_uint4)vec_cmpgt(vec1.get128(), vec0.get128()));
} }
inline inline
const boolInVec const boolInVec
operator <= (floatInVec vec0, floatInVec vec1) operator <= (floatInVec vec0, floatInVec vec1)
{ {
return !(vec0 > vec1); return !(vec0 > vec1);
} }
inline inline
const boolInVec const boolInVec
operator > (floatInVec vec0, floatInVec vec1) operator > (floatInVec vec0, floatInVec vec1)
{ {
return boolInVec((vec_uint4)vec_cmpgt(vec0.get128(), vec1.get128())); return boolInVec((vec_uint4)vec_cmpgt(vec0.get128(), vec1.get128()));
} }
inline inline
const boolInVec const boolInVec
operator >= (floatInVec vec0, floatInVec vec1) operator >= (floatInVec vec0, floatInVec vec1)
{ {
return !(vec0 < vec1); return !(vec0 < vec1);
} }
inline inline
const boolInVec const boolInVec
operator == (floatInVec vec0, floatInVec vec1) operator == (floatInVec vec0, floatInVec vec1)
{ {
return boolInVec((vec_uint4)vec_cmpeq(vec0.get128(), vec1.get128())); return boolInVec((vec_uint4)vec_cmpeq(vec0.get128(), vec1.get128()));
} }
inline inline
const boolInVec const boolInVec
operator != (floatInVec vec0, floatInVec vec1) operator != (floatInVec vec0, floatInVec vec1)
{ {
return !(vec0 == vec1); return !(vec0 == vec1);
} }
inline inline
const floatInVec const floatInVec
select(floatInVec vec0, floatInVec vec1, boolInVec select_vec1) select(floatInVec vec0, floatInVec vec1, boolInVec select_vec1)
{ {
return floatInVec(vec_sel(vec0.get128(), vec1.get128(), select_vec1.get128())); return floatInVec(vec_sel(vec0.get128(), vec1.get128(), select_vec1.get128()));
} }
} // namespace Vectormath } // namespace Vectormath
#endif // floatInVec_h #endif // floatInVec_h

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,479 +1,479 @@
/* /*
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc. Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the with or without modification, are permitted provided that the
following conditions are met: following conditions are met:
* Redistributions of source code must retain the above copyright * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright * Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names * Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission. from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef _VECTORMATH_QUAT_SOA_CPP_H #ifndef _VECTORMATH_QUAT_SOA_CPP_H
#define _VECTORMATH_QUAT_SOA_CPP_H #define _VECTORMATH_QUAT_SOA_CPP_H
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Definitions // Definitions
#ifndef _VECTORMATH_INTERNAL_FUNCTIONS #ifndef _VECTORMATH_INTERNAL_FUNCTIONS
#define _VECTORMATH_INTERNAL_FUNCTIONS #define _VECTORMATH_INTERNAL_FUNCTIONS
#endif #endif
namespace Vectormath { namespace Vectormath {
namespace Soa { namespace Soa {
inline Quat::Quat( const Quat & quat ) inline Quat::Quat( const Quat & quat )
{ {
mX = quat.mX; mX = quat.mX;
mY = quat.mY; mY = quat.mY;
mZ = quat.mZ; mZ = quat.mZ;
mW = quat.mW; mW = quat.mW;
} }
inline Quat::Quat( vec_float4 _x, vec_float4 _y, vec_float4 _z, vec_float4 _w ) inline Quat::Quat( vec_float4 _x, vec_float4 _y, vec_float4 _z, vec_float4 _w )
{ {
mX = _x; mX = _x;
mY = _y; mY = _y;
mZ = _z; mZ = _z;
mW = _w; mW = _w;
} }
inline Quat::Quat( const Vector3 & xyz, vec_float4 _w ) inline Quat::Quat( const Vector3 & xyz, vec_float4 _w )
{ {
this->setXYZ( xyz ); this->setXYZ( xyz );
this->setW( _w ); this->setW( _w );
} }
inline Quat::Quat( const Vector4 & vec ) inline Quat::Quat( const Vector4 & vec )
{ {
mX = vec.getX(); mX = vec.getX();
mY = vec.getY(); mY = vec.getY();
mZ = vec.getZ(); mZ = vec.getZ();
mW = vec.getW(); mW = vec.getW();
} }
inline Quat::Quat( vec_float4 scalar ) inline Quat::Quat( vec_float4 scalar )
{ {
mX = scalar; mX = scalar;
mY = scalar; mY = scalar;
mZ = scalar; mZ = scalar;
mW = scalar; mW = scalar;
} }
inline Quat::Quat( Aos::Quat quat ) inline Quat::Quat( Aos::Quat quat )
{ {
vec_float4 vec128 = quat.get128(); vec_float4 vec128 = quat.get128();
mX = vec_splat( vec128, 0 ); mX = vec_splat( vec128, 0 );
mY = vec_splat( vec128, 1 ); mY = vec_splat( vec128, 1 );
mZ = vec_splat( vec128, 2 ); mZ = vec_splat( vec128, 2 );
mW = vec_splat( vec128, 3 ); mW = vec_splat( vec128, 3 );
} }
inline Quat::Quat( Aos::Quat quat0, Aos::Quat quat1, Aos::Quat quat2, Aos::Quat quat3 ) inline Quat::Quat( Aos::Quat quat0, Aos::Quat quat1, Aos::Quat quat2, Aos::Quat quat3 )
{ {
vec_float4 tmp0, tmp1, tmp2, tmp3; vec_float4 tmp0, tmp1, tmp2, tmp3;
tmp0 = vec_mergeh( quat0.get128(), quat2.get128() ); tmp0 = vec_mergeh( quat0.get128(), quat2.get128() );
tmp1 = vec_mergeh( quat1.get128(), quat3.get128() ); tmp1 = vec_mergeh( quat1.get128(), quat3.get128() );
tmp2 = vec_mergel( quat0.get128(), quat2.get128() ); tmp2 = vec_mergel( quat0.get128(), quat2.get128() );
tmp3 = vec_mergel( quat1.get128(), quat3.get128() ); tmp3 = vec_mergel( quat1.get128(), quat3.get128() );
mX = vec_mergeh( tmp0, tmp1 ); mX = vec_mergeh( tmp0, tmp1 );
mY = vec_mergel( tmp0, tmp1 ); mY = vec_mergel( tmp0, tmp1 );
mZ = vec_mergeh( tmp2, tmp3 ); mZ = vec_mergeh( tmp2, tmp3 );
mW = vec_mergel( tmp2, tmp3 ); mW = vec_mergel( tmp2, tmp3 );
} }
inline const Quat Quat::identity( ) inline const Quat Quat::identity( )
{ {
return Quat( ((vec_float4){0.0f,0.0f,0.0f,0.0f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}), ((vec_float4){1.0f,1.0f,1.0f,1.0f}) ); return Quat( ((vec_float4){0.0f,0.0f,0.0f,0.0f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}), ((vec_float4){1.0f,1.0f,1.0f,1.0f}) );
} }
inline const Quat lerp( vec_float4 t, const Quat & quat0, const Quat & quat1 ) inline const Quat lerp( vec_float4 t, const Quat & quat0, const Quat & quat1 )
{ {
return ( quat0 + ( ( quat1 - quat0 ) * t ) ); return ( quat0 + ( ( quat1 - quat0 ) * t ) );
} }
inline const Quat slerp( vec_float4 t, const Quat & unitQuat0, const Quat & unitQuat1 ) inline const Quat slerp( vec_float4 t, const Quat & unitQuat0, const Quat & unitQuat1 )
{ {
Quat start; Quat start;
vec_float4 recipSinAngle, scale0, scale1, cosAngle, angle; vec_float4 recipSinAngle, scale0, scale1, cosAngle, angle;
vec_uint4 selectMask; vec_uint4 selectMask;
cosAngle = dot( unitQuat0, unitQuat1 ); cosAngle = dot( unitQuat0, unitQuat1 );
selectMask = (vec_uint4)vec_cmpgt( (vec_float4){0.0f,0.0f,0.0f,0.0f}, cosAngle ); selectMask = (vec_uint4)vec_cmpgt( (vec_float4){0.0f,0.0f,0.0f,0.0f}, cosAngle );
cosAngle = vec_sel( cosAngle, negatef4( cosAngle ), selectMask ); cosAngle = vec_sel( cosAngle, negatef4( cosAngle ), selectMask );
start.setX( vec_sel( unitQuat0.getX(), negatef4( unitQuat0.getX() ), selectMask ) ); start.setX( vec_sel( unitQuat0.getX(), negatef4( unitQuat0.getX() ), selectMask ) );
start.setY( vec_sel( unitQuat0.getY(), negatef4( unitQuat0.getY() ), selectMask ) ); start.setY( vec_sel( unitQuat0.getY(), negatef4( unitQuat0.getY() ), selectMask ) );
start.setZ( vec_sel( unitQuat0.getZ(), negatef4( unitQuat0.getZ() ), selectMask ) ); start.setZ( vec_sel( unitQuat0.getZ(), negatef4( unitQuat0.getZ() ), selectMask ) );
start.setW( vec_sel( unitQuat0.getW(), negatef4( unitQuat0.getW() ), selectMask ) ); start.setW( vec_sel( unitQuat0.getW(), negatef4( unitQuat0.getW() ), selectMask ) );
selectMask = (vec_uint4)vec_cmpgt( (vec_float4){_VECTORMATH_SLERP_TOL,_VECTORMATH_SLERP_TOL,_VECTORMATH_SLERP_TOL,_VECTORMATH_SLERP_TOL}, cosAngle ); selectMask = (vec_uint4)vec_cmpgt( (vec_float4){_VECTORMATH_SLERP_TOL,_VECTORMATH_SLERP_TOL,_VECTORMATH_SLERP_TOL,_VECTORMATH_SLERP_TOL}, cosAngle );
angle = acosf4( cosAngle ); angle = acosf4( cosAngle );
recipSinAngle = divf4( ((vec_float4){1.0f,1.0f,1.0f,1.0f}), sinf4( angle ) ); recipSinAngle = divf4( ((vec_float4){1.0f,1.0f,1.0f,1.0f}), sinf4( angle ) );
scale0 = vec_sel( vec_sub( ((vec_float4){1.0f,1.0f,1.0f,1.0f}), t ), vec_madd( sinf4( vec_madd( vec_sub( ((vec_float4){1.0f,1.0f,1.0f,1.0f}), t ), angle, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), recipSinAngle, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), selectMask ); scale0 = vec_sel( vec_sub( ((vec_float4){1.0f,1.0f,1.0f,1.0f}), t ), vec_madd( sinf4( vec_madd( vec_sub( ((vec_float4){1.0f,1.0f,1.0f,1.0f}), t ), angle, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), recipSinAngle, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), selectMask );
scale1 = vec_sel( t, vec_madd( sinf4( vec_madd( t, angle, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), recipSinAngle, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), selectMask ); scale1 = vec_sel( t, vec_madd( sinf4( vec_madd( t, angle, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), recipSinAngle, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), selectMask );
return ( ( start * scale0 ) + ( unitQuat1 * scale1 ) ); return ( ( start * scale0 ) + ( unitQuat1 * scale1 ) );
} }
inline const Quat squad( vec_float4 t, const Quat & unitQuat0, const Quat & unitQuat1, const Quat & unitQuat2, const Quat & unitQuat3 ) inline const Quat squad( vec_float4 t, const Quat & unitQuat0, const Quat & unitQuat1, const Quat & unitQuat2, const Quat & unitQuat3 )
{ {
Quat tmp0, tmp1; Quat tmp0, tmp1;
tmp0 = slerp( t, unitQuat0, unitQuat3 ); tmp0 = slerp( t, unitQuat0, unitQuat3 );
tmp1 = slerp( t, unitQuat1, unitQuat2 ); tmp1 = slerp( t, unitQuat1, unitQuat2 );
return slerp( vec_madd( vec_madd( ((vec_float4){2.0f,2.0f,2.0f,2.0f}), t, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_sub( ((vec_float4){1.0f,1.0f,1.0f,1.0f}), t ), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), tmp0, tmp1 ); return slerp( vec_madd( vec_madd( ((vec_float4){2.0f,2.0f,2.0f,2.0f}), t, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_sub( ((vec_float4){1.0f,1.0f,1.0f,1.0f}), t ), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), tmp0, tmp1 );
} }
inline void Quat::get4Aos( Aos::Quat & result0, Aos::Quat & result1, Aos::Quat & result2, Aos::Quat & result3 ) const inline void Quat::get4Aos( Aos::Quat & result0, Aos::Quat & result1, Aos::Quat & result2, Aos::Quat & result3 ) const
{ {
vec_float4 tmp0, tmp1, tmp2, tmp3; vec_float4 tmp0, tmp1, tmp2, tmp3;
tmp0 = vec_mergeh( mX, mZ ); tmp0 = vec_mergeh( mX, mZ );
tmp1 = vec_mergeh( mY, mW ); tmp1 = vec_mergeh( mY, mW );
tmp2 = vec_mergel( mX, mZ ); tmp2 = vec_mergel( mX, mZ );
tmp3 = vec_mergel( mY, mW ); tmp3 = vec_mergel( mY, mW );
result0 = Aos::Quat( vec_mergeh( tmp0, tmp1 ) ); result0 = Aos::Quat( vec_mergeh( tmp0, tmp1 ) );
result1 = Aos::Quat( vec_mergel( tmp0, tmp1 ) ); result1 = Aos::Quat( vec_mergel( tmp0, tmp1 ) );
result2 = Aos::Quat( vec_mergeh( tmp2, tmp3 ) ); result2 = Aos::Quat( vec_mergeh( tmp2, tmp3 ) );
result3 = Aos::Quat( vec_mergel( tmp2, tmp3 ) ); result3 = Aos::Quat( vec_mergel( tmp2, tmp3 ) );
} }
inline Quat & Quat::operator =( const Quat & quat ) inline Quat & Quat::operator =( const Quat & quat )
{ {
mX = quat.mX; mX = quat.mX;
mY = quat.mY; mY = quat.mY;
mZ = quat.mZ; mZ = quat.mZ;
mW = quat.mW; mW = quat.mW;
return *this; return *this;
} }
inline Quat & Quat::setXYZ( const Vector3 & vec ) inline Quat & Quat::setXYZ( const Vector3 & vec )
{ {
mX = vec.getX(); mX = vec.getX();
mY = vec.getY(); mY = vec.getY();
mZ = vec.getZ(); mZ = vec.getZ();
return *this; return *this;
} }
inline const Vector3 Quat::getXYZ( ) const inline const Vector3 Quat::getXYZ( ) const
{ {
return Vector3( mX, mY, mZ ); return Vector3( mX, mY, mZ );
} }
inline Quat & Quat::setX( vec_float4 _x ) inline Quat & Quat::setX( vec_float4 _x )
{ {
mX = _x; mX = _x;
return *this; return *this;
} }
inline vec_float4 Quat::getX( ) const inline vec_float4 Quat::getX( ) const
{ {
return mX; return mX;
} }
inline Quat & Quat::setY( vec_float4 _y ) inline Quat & Quat::setY( vec_float4 _y )
{ {
mY = _y; mY = _y;
return *this; return *this;
} }
inline vec_float4 Quat::getY( ) const inline vec_float4 Quat::getY( ) const
{ {
return mY; return mY;
} }
inline Quat & Quat::setZ( vec_float4 _z ) inline Quat & Quat::setZ( vec_float4 _z )
{ {
mZ = _z; mZ = _z;
return *this; return *this;
} }
inline vec_float4 Quat::getZ( ) const inline vec_float4 Quat::getZ( ) const
{ {
return mZ; return mZ;
} }
inline Quat & Quat::setW( vec_float4 _w ) inline Quat & Quat::setW( vec_float4 _w )
{ {
mW = _w; mW = _w;
return *this; return *this;
} }
inline vec_float4 Quat::getW( ) const inline vec_float4 Quat::getW( ) const
{ {
return mW; return mW;
} }
inline Quat & Quat::setElem( int idx, vec_float4 value ) inline Quat & Quat::setElem( int idx, vec_float4 value )
{ {
*(&mX + idx) = value; *(&mX + idx) = value;
return *this; return *this;
} }
inline vec_float4 Quat::getElem( int idx ) const inline vec_float4 Quat::getElem( int idx ) const
{ {
return *(&mX + idx); return *(&mX + idx);
} }
inline Quat::vec_float4_t & Quat::operator []( int idx ) inline Quat::vec_float4_t & Quat::operator []( int idx )
{ {
return *(&mX + idx); return *(&mX + idx);
} }
inline vec_float4 Quat::operator []( int idx ) const inline vec_float4 Quat::operator []( int idx ) const
{ {
return *(&mX + idx); return *(&mX + idx);
} }
inline const Quat Quat::operator +( const Quat & quat ) const inline const Quat Quat::operator +( const Quat & quat ) const
{ {
return Quat( return Quat(
vec_add( mX, quat.mX ), vec_add( mX, quat.mX ),
vec_add( mY, quat.mY ), vec_add( mY, quat.mY ),
vec_add( mZ, quat.mZ ), vec_add( mZ, quat.mZ ),
vec_add( mW, quat.mW ) vec_add( mW, quat.mW )
); );
} }
inline const Quat Quat::operator -( const Quat & quat ) const inline const Quat Quat::operator -( const Quat & quat ) const
{ {
return Quat( return Quat(
vec_sub( mX, quat.mX ), vec_sub( mX, quat.mX ),
vec_sub( mY, quat.mY ), vec_sub( mY, quat.mY ),
vec_sub( mZ, quat.mZ ), vec_sub( mZ, quat.mZ ),
vec_sub( mW, quat.mW ) vec_sub( mW, quat.mW )
); );
} }
inline const Quat Quat::operator *( vec_float4 scalar ) const inline const Quat Quat::operator *( vec_float4 scalar ) const
{ {
return Quat( return Quat(
vec_madd( mX, scalar, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( mX, scalar, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ),
vec_madd( mY, scalar, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( mY, scalar, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ),
vec_madd( mZ, scalar, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( mZ, scalar, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ),
vec_madd( mW, scalar, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) vec_madd( mW, scalar, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) )
); );
} }
inline Quat & Quat::operator +=( const Quat & quat ) inline Quat & Quat::operator +=( const Quat & quat )
{ {
*this = *this + quat; *this = *this + quat;
return *this; return *this;
} }
inline Quat & Quat::operator -=( const Quat & quat ) inline Quat & Quat::operator -=( const Quat & quat )
{ {
*this = *this - quat; *this = *this - quat;
return *this; return *this;
} }
inline Quat & Quat::operator *=( vec_float4 scalar ) inline Quat & Quat::operator *=( vec_float4 scalar )
{ {
*this = *this * scalar; *this = *this * scalar;
return *this; return *this;
} }
inline const Quat Quat::operator /( vec_float4 scalar ) const inline const Quat Quat::operator /( vec_float4 scalar ) const
{ {
return Quat( return Quat(
divf4( mX, scalar ), divf4( mX, scalar ),
divf4( mY, scalar ), divf4( mY, scalar ),
divf4( mZ, scalar ), divf4( mZ, scalar ),
divf4( mW, scalar ) divf4( mW, scalar )
); );
} }
inline Quat & Quat::operator /=( vec_float4 scalar ) inline Quat & Quat::operator /=( vec_float4 scalar )
{ {
*this = *this / scalar; *this = *this / scalar;
return *this; return *this;
} }
inline const Quat Quat::operator -( ) const inline const Quat Quat::operator -( ) const
{ {
return Quat( return Quat(
negatef4( mX ), negatef4( mX ),
negatef4( mY ), negatef4( mY ),
negatef4( mZ ), negatef4( mZ ),
negatef4( mW ) negatef4( mW )
); );
} }
inline const Quat operator *( vec_float4 scalar, const Quat & quat ) inline const Quat operator *( vec_float4 scalar, const Quat & quat )
{ {
return quat * scalar; return quat * scalar;
} }
inline vec_float4 dot( const Quat & quat0, const Quat & quat1 ) inline vec_float4 dot( const Quat & quat0, const Quat & quat1 )
{ {
vec_float4 result; vec_float4 result;
result = vec_madd( quat0.getX(), quat1.getX(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ); result = vec_madd( quat0.getX(), quat1.getX(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) );
result = vec_add( result, vec_madd( quat0.getY(), quat1.getY(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ); result = vec_add( result, vec_madd( quat0.getY(), quat1.getY(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) );
result = vec_add( result, vec_madd( quat0.getZ(), quat1.getZ(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ); result = vec_add( result, vec_madd( quat0.getZ(), quat1.getZ(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) );
result = vec_add( result, vec_madd( quat0.getW(), quat1.getW(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ); result = vec_add( result, vec_madd( quat0.getW(), quat1.getW(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) );
return result; return result;
} }
inline vec_float4 norm( const Quat & quat ) inline vec_float4 norm( const Quat & quat )
{ {
vec_float4 result; vec_float4 result;
result = vec_madd( quat.getX(), quat.getX(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ); result = vec_madd( quat.getX(), quat.getX(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) );
result = vec_add( result, vec_madd( quat.getY(), quat.getY(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ); result = vec_add( result, vec_madd( quat.getY(), quat.getY(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) );
result = vec_add( result, vec_madd( quat.getZ(), quat.getZ(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ); result = vec_add( result, vec_madd( quat.getZ(), quat.getZ(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) );
result = vec_add( result, vec_madd( quat.getW(), quat.getW(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ); result = vec_add( result, vec_madd( quat.getW(), quat.getW(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) );
return result; return result;
} }
inline vec_float4 length( const Quat & quat ) inline vec_float4 length( const Quat & quat )
{ {
return sqrtf4( norm( quat ) ); return sqrtf4( norm( quat ) );
} }
inline const Quat normalize( const Quat & quat ) inline const Quat normalize( const Quat & quat )
{ {
vec_float4 lenSqr, lenInv; vec_float4 lenSqr, lenInv;
lenSqr = norm( quat ); lenSqr = norm( quat );
lenInv = divf4( ((vec_float4){1.0f,1.0f,1.0f,1.0f}), sqrtf4( lenSqr ) ); lenInv = divf4( ((vec_float4){1.0f,1.0f,1.0f,1.0f}), sqrtf4( lenSqr ) );
return Quat( return Quat(
vec_madd( quat.getX(), lenInv, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( quat.getX(), lenInv, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ),
vec_madd( quat.getY(), lenInv, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( quat.getY(), lenInv, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ),
vec_madd( quat.getZ(), lenInv, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( quat.getZ(), lenInv, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ),
vec_madd( quat.getW(), lenInv, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) vec_madd( quat.getW(), lenInv, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) )
); );
} }
inline const Quat Quat::rotation( const Vector3 & unitVec0, const Vector3 & unitVec1 ) inline const Quat Quat::rotation( const Vector3 & unitVec0, const Vector3 & unitVec1 )
{ {
vec_float4 cosHalfAngleX2, recipCosHalfAngleX2; vec_float4 cosHalfAngleX2, recipCosHalfAngleX2;
cosHalfAngleX2 = sqrtf4( vec_madd( ((vec_float4){2.0f,2.0f,2.0f,2.0f}), vec_add( ((vec_float4){1.0f,1.0f,1.0f,1.0f}), dot( unitVec0, unitVec1 ) ), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ); cosHalfAngleX2 = sqrtf4( vec_madd( ((vec_float4){2.0f,2.0f,2.0f,2.0f}), vec_add( ((vec_float4){1.0f,1.0f,1.0f,1.0f}), dot( unitVec0, unitVec1 ) ), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) );
recipCosHalfAngleX2 = divf4( ((vec_float4){1.0f,1.0f,1.0f,1.0f}), cosHalfAngleX2 ); recipCosHalfAngleX2 = divf4( ((vec_float4){1.0f,1.0f,1.0f,1.0f}), cosHalfAngleX2 );
return Quat( ( cross( unitVec0, unitVec1 ) * recipCosHalfAngleX2 ), vec_madd( cosHalfAngleX2, ((vec_float4){0.5f,0.5f,0.5f,0.5f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ); return Quat( ( cross( unitVec0, unitVec1 ) * recipCosHalfAngleX2 ), vec_madd( cosHalfAngleX2, ((vec_float4){0.5f,0.5f,0.5f,0.5f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) );
} }
inline const Quat Quat::rotation( vec_float4 radians, const Vector3 & unitVec ) inline const Quat Quat::rotation( vec_float4 radians, const Vector3 & unitVec )
{ {
vec_float4 s, c, angle; vec_float4 s, c, angle;
angle = vec_madd( radians, ((vec_float4){0.5f,0.5f,0.5f,0.5f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ); angle = vec_madd( radians, ((vec_float4){0.5f,0.5f,0.5f,0.5f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) );
sincosf4( angle, &s, &c ); sincosf4( angle, &s, &c );
return Quat( ( unitVec * s ), c ); return Quat( ( unitVec * s ), c );
} }
inline const Quat Quat::rotationX( vec_float4 radians ) inline const Quat Quat::rotationX( vec_float4 radians )
{ {
vec_float4 s, c, angle; vec_float4 s, c, angle;
angle = vec_madd( radians, ((vec_float4){0.5f,0.5f,0.5f,0.5f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ); angle = vec_madd( radians, ((vec_float4){0.5f,0.5f,0.5f,0.5f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) );
sincosf4( angle, &s, &c ); sincosf4( angle, &s, &c );
return Quat( s, ((vec_float4){0.0f,0.0f,0.0f,0.0f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}), c ); return Quat( s, ((vec_float4){0.0f,0.0f,0.0f,0.0f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}), c );
} }
inline const Quat Quat::rotationY( vec_float4 radians ) inline const Quat Quat::rotationY( vec_float4 radians )
{ {
vec_float4 s, c, angle; vec_float4 s, c, angle;
angle = vec_madd( radians, ((vec_float4){0.5f,0.5f,0.5f,0.5f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ); angle = vec_madd( radians, ((vec_float4){0.5f,0.5f,0.5f,0.5f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) );
sincosf4( angle, &s, &c ); sincosf4( angle, &s, &c );
return Quat( ((vec_float4){0.0f,0.0f,0.0f,0.0f}), s, ((vec_float4){0.0f,0.0f,0.0f,0.0f}), c ); return Quat( ((vec_float4){0.0f,0.0f,0.0f,0.0f}), s, ((vec_float4){0.0f,0.0f,0.0f,0.0f}), c );
} }
inline const Quat Quat::rotationZ( vec_float4 radians ) inline const Quat Quat::rotationZ( vec_float4 radians )
{ {
vec_float4 s, c, angle; vec_float4 s, c, angle;
angle = vec_madd( radians, ((vec_float4){0.5f,0.5f,0.5f,0.5f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ); angle = vec_madd( radians, ((vec_float4){0.5f,0.5f,0.5f,0.5f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) );
sincosf4( angle, &s, &c ); sincosf4( angle, &s, &c );
return Quat( ((vec_float4){0.0f,0.0f,0.0f,0.0f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}), s, c ); return Quat( ((vec_float4){0.0f,0.0f,0.0f,0.0f}), ((vec_float4){0.0f,0.0f,0.0f,0.0f}), s, c );
} }
inline const Quat Quat::operator *( const Quat & quat ) const inline const Quat Quat::operator *( const Quat & quat ) const
{ {
return Quat( return Quat(
vec_sub( vec_add( vec_add( vec_madd( mW, quat.mX, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( mX, quat.mW, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( mY, quat.mZ, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( mZ, quat.mY, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_sub( vec_add( vec_add( vec_madd( mW, quat.mX, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( mX, quat.mW, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( mY, quat.mZ, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( mZ, quat.mY, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ),
vec_sub( vec_add( vec_add( vec_madd( mW, quat.mY, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( mY, quat.mW, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( mZ, quat.mX, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( mX, quat.mZ, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_sub( vec_add( vec_add( vec_madd( mW, quat.mY, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( mY, quat.mW, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( mZ, quat.mX, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( mX, quat.mZ, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ),
vec_sub( vec_add( vec_add( vec_madd( mW, quat.mZ, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( mZ, quat.mW, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( mX, quat.mY, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( mY, quat.mX, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_sub( vec_add( vec_add( vec_madd( mW, quat.mZ, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( mZ, quat.mW, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( mX, quat.mY, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( mY, quat.mX, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ),
vec_sub( vec_sub( vec_sub( vec_madd( mW, quat.mW, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( mX, quat.mX, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( mY, quat.mY, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( mZ, quat.mZ, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ) vec_sub( vec_sub( vec_sub( vec_madd( mW, quat.mW, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( mX, quat.mX, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( mY, quat.mY, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( mZ, quat.mZ, ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) )
); );
} }
inline Quat & Quat::operator *=( const Quat & quat ) inline Quat & Quat::operator *=( const Quat & quat )
{ {
*this = *this * quat; *this = *this * quat;
return *this; return *this;
} }
inline const Vector3 rotate( const Quat & quat, const Vector3 & vec ) inline const Vector3 rotate( const Quat & quat, const Vector3 & vec )
{ {
vec_float4 tmpX, tmpY, tmpZ, tmpW; vec_float4 tmpX, tmpY, tmpZ, tmpW;
tmpX = vec_sub( vec_add( vec_madd( quat.getW(), vec.getX(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( quat.getY(), vec.getZ(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( quat.getZ(), vec.getY(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ); tmpX = vec_sub( vec_add( vec_madd( quat.getW(), vec.getX(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( quat.getY(), vec.getZ(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( quat.getZ(), vec.getY(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) );
tmpY = vec_sub( vec_add( vec_madd( quat.getW(), vec.getY(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( quat.getZ(), vec.getX(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( quat.getX(), vec.getZ(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ); tmpY = vec_sub( vec_add( vec_madd( quat.getW(), vec.getY(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( quat.getZ(), vec.getX(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( quat.getX(), vec.getZ(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) );
tmpZ = vec_sub( vec_add( vec_madd( quat.getW(), vec.getZ(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( quat.getX(), vec.getY(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( quat.getY(), vec.getX(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ); tmpZ = vec_sub( vec_add( vec_madd( quat.getW(), vec.getZ(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( quat.getX(), vec.getY(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( quat.getY(), vec.getX(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) );
tmpW = vec_add( vec_add( vec_madd( quat.getX(), vec.getX(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( quat.getY(), vec.getY(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( quat.getZ(), vec.getZ(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ); tmpW = vec_add( vec_add( vec_madd( quat.getX(), vec.getX(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( quat.getY(), vec.getY(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( quat.getZ(), vec.getZ(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) );
return Vector3( return Vector3(
vec_add( vec_sub( vec_add( vec_madd( tmpW, quat.getX(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( tmpX, quat.getW(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( tmpY, quat.getZ(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( tmpZ, quat.getY(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_add( vec_sub( vec_add( vec_madd( tmpW, quat.getX(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( tmpX, quat.getW(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( tmpY, quat.getZ(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( tmpZ, quat.getY(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ),
vec_add( vec_sub( vec_add( vec_madd( tmpW, quat.getY(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( tmpY, quat.getW(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( tmpZ, quat.getX(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( tmpX, quat.getZ(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_add( vec_sub( vec_add( vec_madd( tmpW, quat.getY(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( tmpY, quat.getW(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( tmpZ, quat.getX(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( tmpX, quat.getZ(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ),
vec_add( vec_sub( vec_add( vec_madd( tmpW, quat.getZ(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( tmpZ, quat.getW(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( tmpX, quat.getY(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( tmpY, quat.getX(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ) vec_add( vec_sub( vec_add( vec_madd( tmpW, quat.getZ(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ), vec_madd( tmpZ, quat.getW(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( tmpX, quat.getY(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) ), vec_madd( tmpY, quat.getX(), ((vec_float4){0.0f,0.0f,0.0f,0.0f}) ) )
); );
} }
inline const Quat conj( const Quat & quat ) inline const Quat conj( const Quat & quat )
{ {
return Quat( negatef4( quat.getX() ), negatef4( quat.getY() ), negatef4( quat.getZ() ), quat.getW() ); return Quat( negatef4( quat.getX() ), negatef4( quat.getY() ), negatef4( quat.getZ() ), quat.getW() );
} }
inline const Quat select( const Quat & quat0, const Quat & quat1, vec_uint4 select1 ) inline const Quat select( const Quat & quat0, const Quat & quat1, vec_uint4 select1 )
{ {
return Quat( return Quat(
vec_sel( quat0.getX(), quat1.getX(), select1 ), vec_sel( quat0.getX(), quat1.getX(), select1 ),
vec_sel( quat0.getY(), quat1.getY(), select1 ), vec_sel( quat0.getY(), quat1.getY(), select1 ),
vec_sel( quat0.getZ(), quat1.getZ(), select1 ), vec_sel( quat0.getZ(), quat1.getZ(), select1 ),
vec_sel( quat0.getW(), quat1.getW(), select1 ) vec_sel( quat0.getW(), quat1.getW(), select1 )
); );
} }
#ifdef _VECTORMATH_DEBUG #ifdef _VECTORMATH_DEBUG
inline void print( const Quat & quat ) inline void print( const Quat & quat )
{ {
Aos::Quat vec0, vec1, vec2, vec3; Aos::Quat vec0, vec1, vec2, vec3;
quat.get4Aos( vec0, vec1, vec2, vec3 ); quat.get4Aos( vec0, vec1, vec2, vec3 );
printf("slot 0:\n"); printf("slot 0:\n");
print( vec0 ); print( vec0 );
printf("slot 1:\n"); printf("slot 1:\n");
print( vec1 ); print( vec1 );
printf("slot 2:\n"); printf("slot 2:\n");
print( vec2 ); print( vec2 );
printf("slot 3:\n"); printf("slot 3:\n");
print( vec3 ); print( vec3 );
} }
inline void print( const Quat & quat, const char * name ) inline void print( const Quat & quat, const char * name )
{ {
Aos::Quat vec0, vec1, vec2, vec3; Aos::Quat vec0, vec1, vec2, vec3;
printf( "%s:\n", name ); printf( "%s:\n", name );
quat.get4Aos( vec0, vec1, vec2, vec3 ); quat.get4Aos( vec0, vec1, vec2, vec3 );
printf("slot 0:\n"); printf("slot 0:\n");
print( vec0 ); print( vec0 );
printf("slot 1:\n"); printf("slot 1:\n");
print( vec1 ); print( vec1 );
printf("slot 2:\n"); printf("slot 2:\n");
print( vec2 ); print( vec2 );
printf("slot 3:\n"); printf("slot 3:\n");
print( vec3 ); print( vec3 );
} }
#endif #endif
} // namespace Soa } // namespace Soa
} // namespace Vectormath } // namespace Vectormath
#endif #endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,80 +1,80 @@
/* /*
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc. Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the with or without modification, are permitted provided that the
following conditions are met: following conditions are met:
* Redistributions of source code must retain the above copyright * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright * Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names * Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission. from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef _VECTORMATH_VECIDX_AOS_H #ifndef _VECTORMATH_VECIDX_AOS_H
#define _VECTORMATH_VECIDX_AOS_H #define _VECTORMATH_VECIDX_AOS_H
#include "floatInVec.h" #include "floatInVec.h"
namespace Vectormath { namespace Vectormath {
namespace Aos { namespace Aos {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// VecIdx // VecIdx
// Used in setting elements of Vector3, Vector4, Point3, or Quat with the // Used in setting elements of Vector3, Vector4, Point3, or Quat with the
// subscripting operator. // subscripting operator.
// //
class VecIdx class VecIdx
{ {
private: private:
typedef vec_float4 vec_float4_t; typedef vec_float4 vec_float4_t;
vec_float4_t &ref __attribute__ ((aligned(16))); vec_float4_t &ref __attribute__ ((aligned(16)));
int i __attribute__ ((aligned(16))); int i __attribute__ ((aligned(16)));
public: public:
inline VecIdx( vec_float4_t& vec, int idx ): ref(vec) { i = idx; } inline VecIdx( vec_float4_t& vec, int idx ): ref(vec) { i = idx; }
// implicitly casts to float unless _VECTORMATH_NO_SCALAR_CAST defined // implicitly casts to float unless _VECTORMATH_NO_SCALAR_CAST defined
// in which case, implicitly casts to floatInVec, and one must call // in which case, implicitly casts to floatInVec, and one must call
// getAsFloat to convert to float. // getAsFloat to convert to float.
// //
#ifdef _VECTORMATH_NO_SCALAR_CAST #ifdef _VECTORMATH_NO_SCALAR_CAST
inline operator floatInVec() const; inline operator floatInVec() const;
inline float getAsFloat() const; inline float getAsFloat() const;
#else #else
inline operator float() const; inline operator float() const;
#endif #endif
inline float operator =( float scalar ); inline float operator =( float scalar );
inline floatInVec operator =( floatInVec scalar ); inline floatInVec operator =( floatInVec scalar );
inline floatInVec operator =( const VecIdx& scalar ); inline floatInVec operator =( const VecIdx& scalar );
inline floatInVec operator *=( float scalar ); inline floatInVec operator *=( float scalar );
inline floatInVec operator *=( floatInVec scalar ); inline floatInVec operator *=( floatInVec scalar );
inline floatInVec operator /=( float scalar ); inline floatInVec operator /=( float scalar );
inline floatInVec operator /=( floatInVec scalar ); inline floatInVec operator /=( floatInVec scalar );
inline floatInVec operator +=( float scalar ); inline floatInVec operator +=( float scalar );
inline floatInVec operator +=( floatInVec scalar ); inline floatInVec operator +=( floatInVec scalar );
inline floatInVec operator -=( float scalar ); inline floatInVec operator -=( float scalar );
inline floatInVec operator -=( floatInVec scalar ); inline floatInVec operator -=( floatInVec scalar );
}; };
} // namespace Aos } // namespace Aos
} // namespace Vectormath } // namespace Vectormath
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,368 +1,368 @@
/* /*
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc. Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the with or without modification, are permitted provided that the
following conditions are met: following conditions are met:
* Redistributions of source code must retain the above copyright * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright * Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names * Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission. from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef _VECTORMATH_QUAT_AOS_C_H #ifndef _VECTORMATH_QUAT_AOS_C_H
#define _VECTORMATH_QUAT_AOS_C_H #define _VECTORMATH_QUAT_AOS_C_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
/*----------------------------------------------------------------------------- /*-----------------------------------------------------------------------------
* Definitions * Definitions
*/ */
#ifndef _VECTORMATH_INTERNAL_FUNCTIONS #ifndef _VECTORMATH_INTERNAL_FUNCTIONS
#define _VECTORMATH_INTERNAL_FUNCTIONS #define _VECTORMATH_INTERNAL_FUNCTIONS
#endif #endif
static inline void vmathQCopy( VmathQuat *result, const VmathQuat *quat ) static inline void vmathQCopy( VmathQuat *result, const VmathQuat *quat )
{ {
result->x = quat->x; result->x = quat->x;
result->y = quat->y; result->y = quat->y;
result->z = quat->z; result->z = quat->z;
result->w = quat->w; result->w = quat->w;
} }
static inline void vmathQMakeFromElems( VmathQuat *result, float _x, float _y, float _z, float _w ) static inline void vmathQMakeFromElems( VmathQuat *result, float _x, float _y, float _z, float _w )
{ {
result->x = _x; result->x = _x;
result->y = _y; result->y = _y;
result->z = _z; result->z = _z;
result->w = _w; result->w = _w;
} }
static inline void vmathQMakeFromV3Scalar( VmathQuat *result, const VmathVector3 *xyz, float _w ) static inline void vmathQMakeFromV3Scalar( VmathQuat *result, const VmathVector3 *xyz, float _w )
{ {
vmathQSetXYZ( result, xyz ); vmathQSetXYZ( result, xyz );
vmathQSetW( result, _w ); vmathQSetW( result, _w );
} }
static inline void vmathQMakeFromV4( VmathQuat *result, const VmathVector4 *vec ) static inline void vmathQMakeFromV4( VmathQuat *result, const VmathVector4 *vec )
{ {
result->x = vec->x; result->x = vec->x;
result->y = vec->y; result->y = vec->y;
result->z = vec->z; result->z = vec->z;
result->w = vec->w; result->w = vec->w;
} }
static inline void vmathQMakeFromScalar( VmathQuat *result, float scalar ) static inline void vmathQMakeFromScalar( VmathQuat *result, float scalar )
{ {
result->x = scalar; result->x = scalar;
result->y = scalar; result->y = scalar;
result->z = scalar; result->z = scalar;
result->w = scalar; result->w = scalar;
} }
static inline void vmathQMakeIdentity( VmathQuat *result ) static inline void vmathQMakeIdentity( VmathQuat *result )
{ {
vmathQMakeFromElems( result, 0.0f, 0.0f, 0.0f, 1.0f ); vmathQMakeFromElems( result, 0.0f, 0.0f, 0.0f, 1.0f );
} }
static inline void vmathQLerp( VmathQuat *result, float t, const VmathQuat *quat0, const VmathQuat *quat1 ) static inline void vmathQLerp( VmathQuat *result, float t, const VmathQuat *quat0, const VmathQuat *quat1 )
{ {
VmathQuat tmpQ_0, tmpQ_1; VmathQuat tmpQ_0, tmpQ_1;
vmathQSub( &tmpQ_0, quat1, quat0 ); vmathQSub( &tmpQ_0, quat1, quat0 );
vmathQScalarMul( &tmpQ_1, &tmpQ_0, t ); vmathQScalarMul( &tmpQ_1, &tmpQ_0, t );
vmathQAdd( result, quat0, &tmpQ_1 ); vmathQAdd( result, quat0, &tmpQ_1 );
} }
static inline void vmathQSlerp( VmathQuat *result, float t, const VmathQuat *unitQuat0, const VmathQuat *unitQuat1 ) static inline void vmathQSlerp( VmathQuat *result, float t, const VmathQuat *unitQuat0, const VmathQuat *unitQuat1 )
{ {
VmathQuat start, tmpQ_0, tmpQ_1; VmathQuat start, tmpQ_0, tmpQ_1;
float recipSinAngle, scale0, scale1, cosAngle, angle; float recipSinAngle, scale0, scale1, cosAngle, angle;
cosAngle = vmathQDot( unitQuat0, unitQuat1 ); cosAngle = vmathQDot( unitQuat0, unitQuat1 );
if ( cosAngle < 0.0f ) { if ( cosAngle < 0.0f ) {
cosAngle = -cosAngle; cosAngle = -cosAngle;
vmathQNeg( &start, unitQuat0 ); vmathQNeg( &start, unitQuat0 );
} else { } else {
vmathQCopy( &start, unitQuat0 ); vmathQCopy( &start, unitQuat0 );
} }
if ( cosAngle < _VECTORMATH_SLERP_TOL ) { if ( cosAngle < _VECTORMATH_SLERP_TOL ) {
angle = acosf( cosAngle ); angle = acosf( cosAngle );
recipSinAngle = ( 1.0f / sinf( angle ) ); recipSinAngle = ( 1.0f / sinf( angle ) );
scale0 = ( sinf( ( ( 1.0f - t ) * angle ) ) * recipSinAngle ); scale0 = ( sinf( ( ( 1.0f - t ) * angle ) ) * recipSinAngle );
scale1 = ( sinf( ( t * angle ) ) * recipSinAngle ); scale1 = ( sinf( ( t * angle ) ) * recipSinAngle );
} else { } else {
scale0 = ( 1.0f - t ); scale0 = ( 1.0f - t );
scale1 = t; scale1 = t;
} }
vmathQScalarMul( &tmpQ_0, &start, scale0 ); vmathQScalarMul( &tmpQ_0, &start, scale0 );
vmathQScalarMul( &tmpQ_1, unitQuat1, scale1 ); vmathQScalarMul( &tmpQ_1, unitQuat1, scale1 );
vmathQAdd( result, &tmpQ_0, &tmpQ_1 ); vmathQAdd( result, &tmpQ_0, &tmpQ_1 );
} }
static inline void vmathQSquad( VmathQuat *result, float t, const VmathQuat *unitQuat0, const VmathQuat *unitQuat1, const VmathQuat *unitQuat2, const VmathQuat *unitQuat3 ) static inline void vmathQSquad( VmathQuat *result, float t, const VmathQuat *unitQuat0, const VmathQuat *unitQuat1, const VmathQuat *unitQuat2, const VmathQuat *unitQuat3 )
{ {
VmathQuat tmp0, tmp1; VmathQuat tmp0, tmp1;
vmathQSlerp( &tmp0, t, unitQuat0, unitQuat3 ); vmathQSlerp( &tmp0, t, unitQuat0, unitQuat3 );
vmathQSlerp( &tmp1, t, unitQuat1, unitQuat2 ); vmathQSlerp( &tmp1, t, unitQuat1, unitQuat2 );
vmathQSlerp( result, ( ( 2.0f * t ) * ( 1.0f - t ) ), &tmp0, &tmp1 ); vmathQSlerp( result, ( ( 2.0f * t ) * ( 1.0f - t ) ), &tmp0, &tmp1 );
} }
static inline void vmathQSetXYZ( VmathQuat *result, const VmathVector3 *vec ) static inline void vmathQSetXYZ( VmathQuat *result, const VmathVector3 *vec )
{ {
result->x = vec->x; result->x = vec->x;
result->y = vec->y; result->y = vec->y;
result->z = vec->z; result->z = vec->z;
} }
static inline void vmathQGetXYZ( VmathVector3 *result, const VmathQuat *quat ) static inline void vmathQGetXYZ( VmathVector3 *result, const VmathQuat *quat )
{ {
vmathV3MakeFromElems( result, quat->x, quat->y, quat->z ); vmathV3MakeFromElems( result, quat->x, quat->y, quat->z );
} }
static inline void vmathQSetX( VmathQuat *result, float _x ) static inline void vmathQSetX( VmathQuat *result, float _x )
{ {
result->x = _x; result->x = _x;
} }
static inline float vmathQGetX( const VmathQuat *quat ) static inline float vmathQGetX( const VmathQuat *quat )
{ {
return quat->x; return quat->x;
} }
static inline void vmathQSetY( VmathQuat *result, float _y ) static inline void vmathQSetY( VmathQuat *result, float _y )
{ {
result->y = _y; result->y = _y;
} }
static inline float vmathQGetY( const VmathQuat *quat ) static inline float vmathQGetY( const VmathQuat *quat )
{ {
return quat->y; return quat->y;
} }
static inline void vmathQSetZ( VmathQuat *result, float _z ) static inline void vmathQSetZ( VmathQuat *result, float _z )
{ {
result->z = _z; result->z = _z;
} }
static inline float vmathQGetZ( const VmathQuat *quat ) static inline float vmathQGetZ( const VmathQuat *quat )
{ {
return quat->z; return quat->z;
} }
static inline void vmathQSetW( VmathQuat *result, float _w ) static inline void vmathQSetW( VmathQuat *result, float _w )
{ {
result->w = _w; result->w = _w;
} }
static inline float vmathQGetW( const VmathQuat *quat ) static inline float vmathQGetW( const VmathQuat *quat )
{ {
return quat->w; return quat->w;
} }
static inline void vmathQSetElem( VmathQuat *result, int idx, float value ) static inline void vmathQSetElem( VmathQuat *result, int idx, float value )
{ {
*(&result->x + idx) = value; *(&result->x + idx) = value;
} }
static inline float vmathQGetElem( const VmathQuat *quat, int idx ) static inline float vmathQGetElem( const VmathQuat *quat, int idx )
{ {
return *(&quat->x + idx); return *(&quat->x + idx);
} }
static inline void vmathQAdd( VmathQuat *result, const VmathQuat *quat0, const VmathQuat *quat1 ) static inline void vmathQAdd( VmathQuat *result, const VmathQuat *quat0, const VmathQuat *quat1 )
{ {
result->x = ( quat0->x + quat1->x ); result->x = ( quat0->x + quat1->x );
result->y = ( quat0->y + quat1->y ); result->y = ( quat0->y + quat1->y );
result->z = ( quat0->z + quat1->z ); result->z = ( quat0->z + quat1->z );
result->w = ( quat0->w + quat1->w ); result->w = ( quat0->w + quat1->w );
} }
static inline void vmathQSub( VmathQuat *result, const VmathQuat *quat0, const VmathQuat *quat1 ) static inline void vmathQSub( VmathQuat *result, const VmathQuat *quat0, const VmathQuat *quat1 )
{ {
result->x = ( quat0->x - quat1->x ); result->x = ( quat0->x - quat1->x );
result->y = ( quat0->y - quat1->y ); result->y = ( quat0->y - quat1->y );
result->z = ( quat0->z - quat1->z ); result->z = ( quat0->z - quat1->z );
result->w = ( quat0->w - quat1->w ); result->w = ( quat0->w - quat1->w );
} }
static inline void vmathQScalarMul( VmathQuat *result, const VmathQuat *quat, float scalar ) static inline void vmathQScalarMul( VmathQuat *result, const VmathQuat *quat, float scalar )
{ {
result->x = ( quat->x * scalar ); result->x = ( quat->x * scalar );
result->y = ( quat->y * scalar ); result->y = ( quat->y * scalar );
result->z = ( quat->z * scalar ); result->z = ( quat->z * scalar );
result->w = ( quat->w * scalar ); result->w = ( quat->w * scalar );
} }
static inline void vmathQScalarDiv( VmathQuat *result, const VmathQuat *quat, float scalar ) static inline void vmathQScalarDiv( VmathQuat *result, const VmathQuat *quat, float scalar )
{ {
result->x = ( quat->x / scalar ); result->x = ( quat->x / scalar );
result->y = ( quat->y / scalar ); result->y = ( quat->y / scalar );
result->z = ( quat->z / scalar ); result->z = ( quat->z / scalar );
result->w = ( quat->w / scalar ); result->w = ( quat->w / scalar );
} }
static inline void vmathQNeg( VmathQuat *result, const VmathQuat *quat ) static inline void vmathQNeg( VmathQuat *result, const VmathQuat *quat )
{ {
result->x = -quat->x; result->x = -quat->x;
result->y = -quat->y; result->y = -quat->y;
result->z = -quat->z; result->z = -quat->z;
result->w = -quat->w; result->w = -quat->w;
} }
static inline float vmathQDot( const VmathQuat *quat0, const VmathQuat *quat1 ) static inline float vmathQDot( const VmathQuat *quat0, const VmathQuat *quat1 )
{ {
float result; float result;
result = ( quat0->x * quat1->x ); result = ( quat0->x * quat1->x );
result = ( result + ( quat0->y * quat1->y ) ); result = ( result + ( quat0->y * quat1->y ) );
result = ( result + ( quat0->z * quat1->z ) ); result = ( result + ( quat0->z * quat1->z ) );
result = ( result + ( quat0->w * quat1->w ) ); result = ( result + ( quat0->w * quat1->w ) );
return result; return result;
} }
static inline float vmathQNorm( const VmathQuat *quat ) static inline float vmathQNorm( const VmathQuat *quat )
{ {
float result; float result;
result = ( quat->x * quat->x ); result = ( quat->x * quat->x );
result = ( result + ( quat->y * quat->y ) ); result = ( result + ( quat->y * quat->y ) );
result = ( result + ( quat->z * quat->z ) ); result = ( result + ( quat->z * quat->z ) );
result = ( result + ( quat->w * quat->w ) ); result = ( result + ( quat->w * quat->w ) );
return result; return result;
} }
static inline float vmathQLength( const VmathQuat *quat ) static inline float vmathQLength( const VmathQuat *quat )
{ {
return sqrtf( vmathQNorm( quat ) ); return sqrtf( vmathQNorm( quat ) );
} }
static inline void vmathQNormalize( VmathQuat *result, const VmathQuat *quat ) static inline void vmathQNormalize( VmathQuat *result, const VmathQuat *quat )
{ {
float lenSqr, lenInv; float lenSqr, lenInv;
lenSqr = vmathQNorm( quat ); lenSqr = vmathQNorm( quat );
lenInv = ( 1.0f / sqrtf( lenSqr ) ); lenInv = ( 1.0f / sqrtf( lenSqr ) );
result->x = ( quat->x * lenInv ); result->x = ( quat->x * lenInv );
result->y = ( quat->y * lenInv ); result->y = ( quat->y * lenInv );
result->z = ( quat->z * lenInv ); result->z = ( quat->z * lenInv );
result->w = ( quat->w * lenInv ); result->w = ( quat->w * lenInv );
} }
static inline void vmathQMakeRotationArc( VmathQuat *result, const VmathVector3 *unitVec0, const VmathVector3 *unitVec1 ) static inline void vmathQMakeRotationArc( VmathQuat *result, const VmathVector3 *unitVec0, const VmathVector3 *unitVec1 )
{ {
VmathVector3 tmpV3_0, tmpV3_1; VmathVector3 tmpV3_0, tmpV3_1;
float cosHalfAngleX2, recipCosHalfAngleX2; float cosHalfAngleX2, recipCosHalfAngleX2;
cosHalfAngleX2 = sqrtf( ( 2.0f * ( 1.0f + vmathV3Dot( unitVec0, unitVec1 ) ) ) ); cosHalfAngleX2 = sqrtf( ( 2.0f * ( 1.0f + vmathV3Dot( unitVec0, unitVec1 ) ) ) );
recipCosHalfAngleX2 = ( 1.0f / cosHalfAngleX2 ); recipCosHalfAngleX2 = ( 1.0f / cosHalfAngleX2 );
vmathV3Cross( &tmpV3_0, unitVec0, unitVec1 ); vmathV3Cross( &tmpV3_0, unitVec0, unitVec1 );
vmathV3ScalarMul( &tmpV3_1, &tmpV3_0, recipCosHalfAngleX2 ); vmathV3ScalarMul( &tmpV3_1, &tmpV3_0, recipCosHalfAngleX2 );
vmathQMakeFromV3Scalar( result, &tmpV3_1, ( cosHalfAngleX2 * 0.5f ) ); vmathQMakeFromV3Scalar( result, &tmpV3_1, ( cosHalfAngleX2 * 0.5f ) );
} }
static inline void vmathQMakeRotationAxis( VmathQuat *result, float radians, const VmathVector3 *unitVec ) static inline void vmathQMakeRotationAxis( VmathQuat *result, float radians, const VmathVector3 *unitVec )
{ {
VmathVector3 tmpV3_0; VmathVector3 tmpV3_0;
float s, c, angle; float s, c, angle;
angle = ( radians * 0.5f ); angle = ( radians * 0.5f );
s = sinf( angle ); s = sinf( angle );
c = cosf( angle ); c = cosf( angle );
vmathV3ScalarMul( &tmpV3_0, unitVec, s ); vmathV3ScalarMul( &tmpV3_0, unitVec, s );
vmathQMakeFromV3Scalar( result, &tmpV3_0, c ); vmathQMakeFromV3Scalar( result, &tmpV3_0, c );
} }
static inline void vmathQMakeRotationX( VmathQuat *result, float radians ) static inline void vmathQMakeRotationX( VmathQuat *result, float radians )
{ {
float s, c, angle; float s, c, angle;
angle = ( radians * 0.5f ); angle = ( radians * 0.5f );
s = sinf( angle ); s = sinf( angle );
c = cosf( angle ); c = cosf( angle );
vmathQMakeFromElems( result, s, 0.0f, 0.0f, c ); vmathQMakeFromElems( result, s, 0.0f, 0.0f, c );
} }
static inline void vmathQMakeRotationY( VmathQuat *result, float radians ) static inline void vmathQMakeRotationY( VmathQuat *result, float radians )
{ {
float s, c, angle; float s, c, angle;
angle = ( radians * 0.5f ); angle = ( radians * 0.5f );
s = sinf( angle ); s = sinf( angle );
c = cosf( angle ); c = cosf( angle );
vmathQMakeFromElems( result, 0.0f, s, 0.0f, c ); vmathQMakeFromElems( result, 0.0f, s, 0.0f, c );
} }
static inline void vmathQMakeRotationZ( VmathQuat *result, float radians ) static inline void vmathQMakeRotationZ( VmathQuat *result, float radians )
{ {
float s, c, angle; float s, c, angle;
angle = ( radians * 0.5f ); angle = ( radians * 0.5f );
s = sinf( angle ); s = sinf( angle );
c = cosf( angle ); c = cosf( angle );
vmathQMakeFromElems( result, 0.0f, 0.0f, s, c ); vmathQMakeFromElems( result, 0.0f, 0.0f, s, c );
} }
static inline void vmathQMul( VmathQuat *result, const VmathQuat *quat0, const VmathQuat *quat1 ) static inline void vmathQMul( VmathQuat *result, const VmathQuat *quat0, const VmathQuat *quat1 )
{ {
float tmpX, tmpY, tmpZ, tmpW; float tmpX, tmpY, tmpZ, tmpW;
tmpX = ( ( ( ( quat0->w * quat1->x ) + ( quat0->x * quat1->w ) ) + ( quat0->y * quat1->z ) ) - ( quat0->z * quat1->y ) ); tmpX = ( ( ( ( quat0->w * quat1->x ) + ( quat0->x * quat1->w ) ) + ( quat0->y * quat1->z ) ) - ( quat0->z * quat1->y ) );
tmpY = ( ( ( ( quat0->w * quat1->y ) + ( quat0->y * quat1->w ) ) + ( quat0->z * quat1->x ) ) - ( quat0->x * quat1->z ) ); tmpY = ( ( ( ( quat0->w * quat1->y ) + ( quat0->y * quat1->w ) ) + ( quat0->z * quat1->x ) ) - ( quat0->x * quat1->z ) );
tmpZ = ( ( ( ( quat0->w * quat1->z ) + ( quat0->z * quat1->w ) ) + ( quat0->x * quat1->y ) ) - ( quat0->y * quat1->x ) ); tmpZ = ( ( ( ( quat0->w * quat1->z ) + ( quat0->z * quat1->w ) ) + ( quat0->x * quat1->y ) ) - ( quat0->y * quat1->x ) );
tmpW = ( ( ( ( quat0->w * quat1->w ) - ( quat0->x * quat1->x ) ) - ( quat0->y * quat1->y ) ) - ( quat0->z * quat1->z ) ); tmpW = ( ( ( ( quat0->w * quat1->w ) - ( quat0->x * quat1->x ) ) - ( quat0->y * quat1->y ) ) - ( quat0->z * quat1->z ) );
vmathQMakeFromElems( result, tmpX, tmpY, tmpZ, tmpW ); vmathQMakeFromElems( result, tmpX, tmpY, tmpZ, tmpW );
} }
static inline void vmathQRotate( VmathVector3 *result, const VmathQuat *quat, const VmathVector3 *vec ) static inline void vmathQRotate( VmathVector3 *result, const VmathQuat *quat, const VmathVector3 *vec )
{ {
float tmpX, tmpY, tmpZ, tmpW; float tmpX, tmpY, tmpZ, tmpW;
tmpX = ( ( ( quat->w * vec->x ) + ( quat->y * vec->z ) ) - ( quat->z * vec->y ) ); tmpX = ( ( ( quat->w * vec->x ) + ( quat->y * vec->z ) ) - ( quat->z * vec->y ) );
tmpY = ( ( ( quat->w * vec->y ) + ( quat->z * vec->x ) ) - ( quat->x * vec->z ) ); tmpY = ( ( ( quat->w * vec->y ) + ( quat->z * vec->x ) ) - ( quat->x * vec->z ) );
tmpZ = ( ( ( quat->w * vec->z ) + ( quat->x * vec->y ) ) - ( quat->y * vec->x ) ); tmpZ = ( ( ( quat->w * vec->z ) + ( quat->x * vec->y ) ) - ( quat->y * vec->x ) );
tmpW = ( ( ( quat->x * vec->x ) + ( quat->y * vec->y ) ) + ( quat->z * vec->z ) ); tmpW = ( ( ( quat->x * vec->x ) + ( quat->y * vec->y ) ) + ( quat->z * vec->z ) );
result->x = ( ( ( ( tmpW * quat->x ) + ( tmpX * quat->w ) ) - ( tmpY * quat->z ) ) + ( tmpZ * quat->y ) ); result->x = ( ( ( ( tmpW * quat->x ) + ( tmpX * quat->w ) ) - ( tmpY * quat->z ) ) + ( tmpZ * quat->y ) );
result->y = ( ( ( ( tmpW * quat->y ) + ( tmpY * quat->w ) ) - ( tmpZ * quat->x ) ) + ( tmpX * quat->z ) ); result->y = ( ( ( ( tmpW * quat->y ) + ( tmpY * quat->w ) ) - ( tmpZ * quat->x ) ) + ( tmpX * quat->z ) );
result->z = ( ( ( ( tmpW * quat->z ) + ( tmpZ * quat->w ) ) - ( tmpX * quat->y ) ) + ( tmpY * quat->x ) ); result->z = ( ( ( ( tmpW * quat->z ) + ( tmpZ * quat->w ) ) - ( tmpX * quat->y ) ) + ( tmpY * quat->x ) );
} }
static inline void vmathQConj( VmathQuat *result, const VmathQuat *quat ) static inline void vmathQConj( VmathQuat *result, const VmathQuat *quat )
{ {
vmathQMakeFromElems( result, -quat->x, -quat->y, -quat->z, quat->w ); vmathQMakeFromElems( result, -quat->x, -quat->y, -quat->z, quat->w );
} }
static inline void vmathQSelect( VmathQuat *result, const VmathQuat *quat0, const VmathQuat *quat1, unsigned int select1 ) static inline void vmathQSelect( VmathQuat *result, const VmathQuat *quat0, const VmathQuat *quat1, unsigned int select1 )
{ {
result->x = ( select1 )? quat1->x : quat0->x; result->x = ( select1 )? quat1->x : quat0->x;
result->y = ( select1 )? quat1->y : quat0->y; result->y = ( select1 )? quat1->y : quat0->y;
result->z = ( select1 )? quat1->z : quat0->z; result->z = ( select1 )? quat1->z : quat0->z;
result->w = ( select1 )? quat1->w : quat0->w; result->w = ( select1 )? quat1->w : quat0->w;
} }
#ifdef _VECTORMATH_DEBUG #ifdef _VECTORMATH_DEBUG
static inline void vmathQPrint( const VmathQuat *quat ) static inline void vmathQPrint( const VmathQuat *quat )
{ {
printf( "( %f %f %f %f )\n", quat->x, quat->y, quat->z, quat->w ); printf( "( %f %f %f %f )\n", quat->x, quat->y, quat->z, quat->w );
} }
static inline void vmathQPrints( const VmathQuat *quat, const char *name ) static inline void vmathQPrints( const VmathQuat *quat, const char *name )
{ {
printf( "%s: ( %f %f %f %f )\n", name, quat->x, quat->y, quat->z, quat->w ); printf( "%s: ( %f %f %f %f )\n", name, quat->x, quat->y, quat->z, quat->w );
} }
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif #endif

View File

@@ -1,300 +1,300 @@
/* /*
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc. Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the with or without modification, are permitted provided that the
following conditions are met: following conditions are met:
* Redistributions of source code must retain the above copyright * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright * Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names * Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission. from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef _VECTORMATH_QUAT_AOS_V_C_H #ifndef _VECTORMATH_QUAT_AOS_V_C_H
#define _VECTORMATH_QUAT_AOS_V_C_H #define _VECTORMATH_QUAT_AOS_V_C_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
/*----------------------------------------------------------------------------- /*-----------------------------------------------------------------------------
* Definitions * Definitions
*/ */
#ifndef _VECTORMATH_INTERNAL_FUNCTIONS #ifndef _VECTORMATH_INTERNAL_FUNCTIONS
#define _VECTORMATH_INTERNAL_FUNCTIONS #define _VECTORMATH_INTERNAL_FUNCTIONS
#endif #endif
static inline VmathQuat vmathQMakeFromElems_V( float _x, float _y, float _z, float _w ) static inline VmathQuat vmathQMakeFromElems_V( float _x, float _y, float _z, float _w )
{ {
VmathQuat result; VmathQuat result;
vmathQMakeFromElems(&result, _x, _y, _z, _w); vmathQMakeFromElems(&result, _x, _y, _z, _w);
return result; return result;
} }
static inline VmathQuat vmathQMakeFromV3Scalar_V( VmathVector3 xyz, float _w ) static inline VmathQuat vmathQMakeFromV3Scalar_V( VmathVector3 xyz, float _w )
{ {
VmathQuat result; VmathQuat result;
vmathQMakeFromV3Scalar(&result, &xyz, _w); vmathQMakeFromV3Scalar(&result, &xyz, _w);
return result; return result;
} }
static inline VmathQuat vmathQMakeFromV4_V( VmathVector4 vec ) static inline VmathQuat vmathQMakeFromV4_V( VmathVector4 vec )
{ {
VmathQuat result; VmathQuat result;
vmathQMakeFromV4(&result, &vec); vmathQMakeFromV4(&result, &vec);
return result; return result;
} }
static inline VmathQuat vmathQMakeFromScalar_V( float scalar ) static inline VmathQuat vmathQMakeFromScalar_V( float scalar )
{ {
VmathQuat result; VmathQuat result;
vmathQMakeFromScalar(&result, scalar); vmathQMakeFromScalar(&result, scalar);
return result; return result;
} }
static inline VmathQuat vmathQMakeIdentity_V( ) static inline VmathQuat vmathQMakeIdentity_V( )
{ {
VmathQuat result; VmathQuat result;
vmathQMakeIdentity(&result); vmathQMakeIdentity(&result);
return result; return result;
} }
static inline VmathQuat vmathQLerp_V( float t, VmathQuat quat0, VmathQuat quat1 ) static inline VmathQuat vmathQLerp_V( float t, VmathQuat quat0, VmathQuat quat1 )
{ {
VmathQuat result; VmathQuat result;
vmathQLerp(&result, t, &quat0, &quat1); vmathQLerp(&result, t, &quat0, &quat1);
return result; return result;
} }
static inline VmathQuat vmathQSlerp_V( float t, VmathQuat unitQuat0, VmathQuat unitQuat1 ) static inline VmathQuat vmathQSlerp_V( float t, VmathQuat unitQuat0, VmathQuat unitQuat1 )
{ {
VmathQuat result; VmathQuat result;
vmathQSlerp(&result, t, &unitQuat0, &unitQuat1); vmathQSlerp(&result, t, &unitQuat0, &unitQuat1);
return result; return result;
} }
static inline VmathQuat vmathQSquad_V( float t, VmathQuat unitQuat0, VmathQuat unitQuat1, VmathQuat unitQuat2, VmathQuat unitQuat3 ) static inline VmathQuat vmathQSquad_V( float t, VmathQuat unitQuat0, VmathQuat unitQuat1, VmathQuat unitQuat2, VmathQuat unitQuat3 )
{ {
VmathQuat result; VmathQuat result;
vmathQSquad(&result, t, &unitQuat0, &unitQuat1, &unitQuat2, &unitQuat3); vmathQSquad(&result, t, &unitQuat0, &unitQuat1, &unitQuat2, &unitQuat3);
return result; return result;
} }
static inline void vmathQSetXYZ_V( VmathQuat *result, VmathVector3 vec ) static inline void vmathQSetXYZ_V( VmathQuat *result, VmathVector3 vec )
{ {
vmathQSetXYZ(result, &vec); vmathQSetXYZ(result, &vec);
} }
static inline VmathVector3 vmathQGetXYZ_V( VmathQuat quat ) static inline VmathVector3 vmathQGetXYZ_V( VmathQuat quat )
{ {
VmathVector3 result; VmathVector3 result;
vmathQGetXYZ(&result, &quat); vmathQGetXYZ(&result, &quat);
return result; return result;
} }
static inline void vmathQSetX_V( VmathQuat *result, float _x ) static inline void vmathQSetX_V( VmathQuat *result, float _x )
{ {
vmathQSetX(result, _x); vmathQSetX(result, _x);
} }
static inline float vmathQGetX_V( VmathQuat quat ) static inline float vmathQGetX_V( VmathQuat quat )
{ {
return vmathQGetX(&quat); return vmathQGetX(&quat);
} }
static inline void vmathQSetY_V( VmathQuat *result, float _y ) static inline void vmathQSetY_V( VmathQuat *result, float _y )
{ {
vmathQSetY(result, _y); vmathQSetY(result, _y);
} }
static inline float vmathQGetY_V( VmathQuat quat ) static inline float vmathQGetY_V( VmathQuat quat )
{ {
return vmathQGetY(&quat); return vmathQGetY(&quat);
} }
static inline void vmathQSetZ_V( VmathQuat *result, float _z ) static inline void vmathQSetZ_V( VmathQuat *result, float _z )
{ {
vmathQSetZ(result, _z); vmathQSetZ(result, _z);
} }
static inline float vmathQGetZ_V( VmathQuat quat ) static inline float vmathQGetZ_V( VmathQuat quat )
{ {
return vmathQGetZ(&quat); return vmathQGetZ(&quat);
} }
static inline void vmathQSetW_V( VmathQuat *result, float _w ) static inline void vmathQSetW_V( VmathQuat *result, float _w )
{ {
vmathQSetW(result, _w); vmathQSetW(result, _w);
} }
static inline float vmathQGetW_V( VmathQuat quat ) static inline float vmathQGetW_V( VmathQuat quat )
{ {
return vmathQGetW(&quat); return vmathQGetW(&quat);
} }
static inline void vmathQSetElem_V( VmathQuat *result, int idx, float value ) static inline void vmathQSetElem_V( VmathQuat *result, int idx, float value )
{ {
vmathQSetElem(result, idx, value); vmathQSetElem(result, idx, value);
} }
static inline float vmathQGetElem_V( VmathQuat quat, int idx ) static inline float vmathQGetElem_V( VmathQuat quat, int idx )
{ {
return vmathQGetElem(&quat, idx); return vmathQGetElem(&quat, idx);
} }
static inline VmathQuat vmathQAdd_V( VmathQuat quat0, VmathQuat quat1 ) static inline VmathQuat vmathQAdd_V( VmathQuat quat0, VmathQuat quat1 )
{ {
VmathQuat result; VmathQuat result;
vmathQAdd(&result, &quat0, &quat1); vmathQAdd(&result, &quat0, &quat1);
return result; return result;
} }
static inline VmathQuat vmathQSub_V( VmathQuat quat0, VmathQuat quat1 ) static inline VmathQuat vmathQSub_V( VmathQuat quat0, VmathQuat quat1 )
{ {
VmathQuat result; VmathQuat result;
vmathQSub(&result, &quat0, &quat1); vmathQSub(&result, &quat0, &quat1);
return result; return result;
} }
static inline VmathQuat vmathQScalarMul_V( VmathQuat quat, float scalar ) static inline VmathQuat vmathQScalarMul_V( VmathQuat quat, float scalar )
{ {
VmathQuat result; VmathQuat result;
vmathQScalarMul(&result, &quat, scalar); vmathQScalarMul(&result, &quat, scalar);
return result; return result;
} }
static inline VmathQuat vmathQScalarDiv_V( VmathQuat quat, float scalar ) static inline VmathQuat vmathQScalarDiv_V( VmathQuat quat, float scalar )
{ {
VmathQuat result; VmathQuat result;
vmathQScalarDiv(&result, &quat, scalar); vmathQScalarDiv(&result, &quat, scalar);
return result; return result;
} }
static inline VmathQuat vmathQNeg_V( VmathQuat quat ) static inline VmathQuat vmathQNeg_V( VmathQuat quat )
{ {
VmathQuat result; VmathQuat result;
vmathQNeg(&result, &quat); vmathQNeg(&result, &quat);
return result; return result;
} }
static inline float vmathQDot_V( VmathQuat quat0, VmathQuat quat1 ) static inline float vmathQDot_V( VmathQuat quat0, VmathQuat quat1 )
{ {
return vmathQDot(&quat0, &quat1); return vmathQDot(&quat0, &quat1);
} }
static inline float vmathQNorm_V( VmathQuat quat ) static inline float vmathQNorm_V( VmathQuat quat )
{ {
return vmathQNorm(&quat); return vmathQNorm(&quat);
} }
static inline float vmathQLength_V( VmathQuat quat ) static inline float vmathQLength_V( VmathQuat quat )
{ {
return vmathQLength(&quat); return vmathQLength(&quat);
} }
static inline VmathQuat vmathQNormalize_V( VmathQuat quat ) static inline VmathQuat vmathQNormalize_V( VmathQuat quat )
{ {
VmathQuat result; VmathQuat result;
vmathQNormalize(&result, &quat); vmathQNormalize(&result, &quat);
return result; return result;
} }
static inline VmathQuat vmathQMakeRotationArc_V( VmathVector3 unitVec0, VmathVector3 unitVec1 ) static inline VmathQuat vmathQMakeRotationArc_V( VmathVector3 unitVec0, VmathVector3 unitVec1 )
{ {
VmathQuat result; VmathQuat result;
vmathQMakeRotationArc(&result, &unitVec0, &unitVec1); vmathQMakeRotationArc(&result, &unitVec0, &unitVec1);
return result; return result;
} }
static inline VmathQuat vmathQMakeRotationAxis_V( float radians, VmathVector3 unitVec ) static inline VmathQuat vmathQMakeRotationAxis_V( float radians, VmathVector3 unitVec )
{ {
VmathQuat result; VmathQuat result;
vmathQMakeRotationAxis(&result, radians, &unitVec); vmathQMakeRotationAxis(&result, radians, &unitVec);
return result; return result;
} }
static inline VmathQuat vmathQMakeRotationX_V( float radians ) static inline VmathQuat vmathQMakeRotationX_V( float radians )
{ {
VmathQuat result; VmathQuat result;
vmathQMakeRotationX(&result, radians); vmathQMakeRotationX(&result, radians);
return result; return result;
} }
static inline VmathQuat vmathQMakeRotationY_V( float radians ) static inline VmathQuat vmathQMakeRotationY_V( float radians )
{ {
VmathQuat result; VmathQuat result;
vmathQMakeRotationY(&result, radians); vmathQMakeRotationY(&result, radians);
return result; return result;
} }
static inline VmathQuat vmathQMakeRotationZ_V( float radians ) static inline VmathQuat vmathQMakeRotationZ_V( float radians )
{ {
VmathQuat result; VmathQuat result;
vmathQMakeRotationZ(&result, radians); vmathQMakeRotationZ(&result, radians);
return result; return result;
} }
static inline VmathQuat vmathQMul_V( VmathQuat quat0, VmathQuat quat1 ) static inline VmathQuat vmathQMul_V( VmathQuat quat0, VmathQuat quat1 )
{ {
VmathQuat result; VmathQuat result;
vmathQMul(&result, &quat0, &quat1); vmathQMul(&result, &quat0, &quat1);
return result; return result;
} }
static inline VmathVector3 vmathQRotate_V( VmathQuat quat, VmathVector3 vec ) static inline VmathVector3 vmathQRotate_V( VmathQuat quat, VmathVector3 vec )
{ {
VmathVector3 result; VmathVector3 result;
vmathQRotate(&result, &quat, &vec); vmathQRotate(&result, &quat, &vec);
return result; return result;
} }
static inline VmathQuat vmathQConj_V( VmathQuat quat ) static inline VmathQuat vmathQConj_V( VmathQuat quat )
{ {
VmathQuat result; VmathQuat result;
vmathQConj(&result, &quat); vmathQConj(&result, &quat);
return result; return result;
} }
static inline VmathQuat vmathQSelect_V( VmathQuat quat0, VmathQuat quat1, unsigned int select1 ) static inline VmathQuat vmathQSelect_V( VmathQuat quat0, VmathQuat quat1, unsigned int select1 )
{ {
VmathQuat result; VmathQuat result;
vmathQSelect(&result, &quat0, &quat1, select1); vmathQSelect(&result, &quat0, &quat1, select1);
return result; return result;
} }
#ifdef _VECTORMATH_DEBUG #ifdef _VECTORMATH_DEBUG
static inline void vmathQPrint_V( VmathQuat quat ) static inline void vmathQPrint_V( VmathQuat quat )
{ {
vmathQPrint(&quat); vmathQPrint(&quat);
} }
static inline void vmathQPrints_V( VmathQuat quat, const char *name ) static inline void vmathQPrints_V( VmathQuat quat, const char *name )
{ {
vmathQPrints(&quat, name); vmathQPrints(&quat, name);
} }
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,432 +1,432 @@
/* /*
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc. Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the with or without modification, are permitted provided that the
following conditions are met: following conditions are met:
* Redistributions of source code must retain the above copyright * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright * Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names * Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission. from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef _VECTORMATH_QUAT_AOS_CPP_H #ifndef _VECTORMATH_QUAT_AOS_CPP_H
#define _VECTORMATH_QUAT_AOS_CPP_H #define _VECTORMATH_QUAT_AOS_CPP_H
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Definitions // Definitions
#ifndef _VECTORMATH_INTERNAL_FUNCTIONS #ifndef _VECTORMATH_INTERNAL_FUNCTIONS
#define _VECTORMATH_INTERNAL_FUNCTIONS #define _VECTORMATH_INTERNAL_FUNCTIONS
#endif #endif
namespace Vectormath { namespace Vectormath {
namespace Aos { namespace Aos {
inline Quat::Quat( const Quat & quat ) inline Quat::Quat( const Quat & quat )
{ {
mX = quat.mX; mX = quat.mX;
mY = quat.mY; mY = quat.mY;
mZ = quat.mZ; mZ = quat.mZ;
mW = quat.mW; mW = quat.mW;
} }
inline Quat::Quat( float _x, float _y, float _z, float _w ) inline Quat::Quat( float _x, float _y, float _z, float _w )
{ {
mX = _x; mX = _x;
mY = _y; mY = _y;
mZ = _z; mZ = _z;
mW = _w; mW = _w;
} }
inline Quat::Quat( const Vector3 & xyz, float _w ) inline Quat::Quat( const Vector3 & xyz, float _w )
{ {
this->setXYZ( xyz ); this->setXYZ( xyz );
this->setW( _w ); this->setW( _w );
} }
inline Quat::Quat( const Vector4 & vec ) inline Quat::Quat( const Vector4 & vec )
{ {
mX = vec.getX(); mX = vec.getX();
mY = vec.getY(); mY = vec.getY();
mZ = vec.getZ(); mZ = vec.getZ();
mW = vec.getW(); mW = vec.getW();
} }
inline Quat::Quat( float scalar ) inline Quat::Quat( float scalar )
{ {
mX = scalar; mX = scalar;
mY = scalar; mY = scalar;
mZ = scalar; mZ = scalar;
mW = scalar; mW = scalar;
} }
inline const Quat Quat::identity( ) inline const Quat Quat::identity( )
{ {
return Quat( 0.0f, 0.0f, 0.0f, 1.0f ); return Quat( 0.0f, 0.0f, 0.0f, 1.0f );
} }
inline const Quat lerp( float t, const Quat & quat0, const Quat & quat1 ) inline const Quat lerp( float t, const Quat & quat0, const Quat & quat1 )
{ {
return ( quat0 + ( ( quat1 - quat0 ) * t ) ); return ( quat0 + ( ( quat1 - quat0 ) * t ) );
} }
inline const Quat slerp( float t, const Quat & unitQuat0, const Quat & unitQuat1 ) inline const Quat slerp( float t, const Quat & unitQuat0, const Quat & unitQuat1 )
{ {
Quat start; Quat start;
float recipSinAngle, scale0, scale1, cosAngle, angle; float recipSinAngle, scale0, scale1, cosAngle, angle;
cosAngle = dot( unitQuat0, unitQuat1 ); cosAngle = dot( unitQuat0, unitQuat1 );
if ( cosAngle < 0.0f ) { if ( cosAngle < 0.0f ) {
cosAngle = -cosAngle; cosAngle = -cosAngle;
start = ( -unitQuat0 ); start = ( -unitQuat0 );
} else { } else {
start = unitQuat0; start = unitQuat0;
} }
if ( cosAngle < _VECTORMATH_SLERP_TOL ) { if ( cosAngle < _VECTORMATH_SLERP_TOL ) {
angle = acosf( cosAngle ); angle = acosf( cosAngle );
recipSinAngle = ( 1.0f / sinf( angle ) ); recipSinAngle = ( 1.0f / sinf( angle ) );
scale0 = ( sinf( ( ( 1.0f - t ) * angle ) ) * recipSinAngle ); scale0 = ( sinf( ( ( 1.0f - t ) * angle ) ) * recipSinAngle );
scale1 = ( sinf( ( t * angle ) ) * recipSinAngle ); scale1 = ( sinf( ( t * angle ) ) * recipSinAngle );
} else { } else {
scale0 = ( 1.0f - t ); scale0 = ( 1.0f - t );
scale1 = t; scale1 = t;
} }
return ( ( start * scale0 ) + ( unitQuat1 * scale1 ) ); return ( ( start * scale0 ) + ( unitQuat1 * scale1 ) );
} }
inline const Quat squad( float t, const Quat & unitQuat0, const Quat & unitQuat1, const Quat & unitQuat2, const Quat & unitQuat3 ) inline const Quat squad( float t, const Quat & unitQuat0, const Quat & unitQuat1, const Quat & unitQuat2, const Quat & unitQuat3 )
{ {
Quat tmp0, tmp1; Quat tmp0, tmp1;
tmp0 = slerp( t, unitQuat0, unitQuat3 ); tmp0 = slerp( t, unitQuat0, unitQuat3 );
tmp1 = slerp( t, unitQuat1, unitQuat2 ); tmp1 = slerp( t, unitQuat1, unitQuat2 );
return slerp( ( ( 2.0f * t ) * ( 1.0f - t ) ), tmp0, tmp1 ); return slerp( ( ( 2.0f * t ) * ( 1.0f - t ) ), tmp0, tmp1 );
} }
inline Quat & Quat::operator =( const Quat & quat ) inline Quat & Quat::operator =( const Quat & quat )
{ {
mX = quat.mX; mX = quat.mX;
mY = quat.mY; mY = quat.mY;
mZ = quat.mZ; mZ = quat.mZ;
mW = quat.mW; mW = quat.mW;
return *this; return *this;
} }
inline Quat & Quat::setXYZ( const Vector3 & vec ) inline Quat & Quat::setXYZ( const Vector3 & vec )
{ {
mX = vec.getX(); mX = vec.getX();
mY = vec.getY(); mY = vec.getY();
mZ = vec.getZ(); mZ = vec.getZ();
return *this; return *this;
} }
inline const Vector3 Quat::getXYZ( ) const inline const Vector3 Quat::getXYZ( ) const
{ {
return Vector3( mX, mY, mZ ); return Vector3( mX, mY, mZ );
} }
inline Quat & Quat::setX( float _x ) inline Quat & Quat::setX( float _x )
{ {
mX = _x; mX = _x;
return *this; return *this;
} }
inline float Quat::getX( ) const inline float Quat::getX( ) const
{ {
return mX; return mX;
} }
inline Quat & Quat::setY( float _y ) inline Quat & Quat::setY( float _y )
{ {
mY = _y; mY = _y;
return *this; return *this;
} }
inline float Quat::getY( ) const inline float Quat::getY( ) const
{ {
return mY; return mY;
} }
inline Quat & Quat::setZ( float _z ) inline Quat & Quat::setZ( float _z )
{ {
mZ = _z; mZ = _z;
return *this; return *this;
} }
inline float Quat::getZ( ) const inline float Quat::getZ( ) const
{ {
return mZ; return mZ;
} }
inline Quat & Quat::setW( float _w ) inline Quat & Quat::setW( float _w )
{ {
mW = _w; mW = _w;
return *this; return *this;
} }
inline float Quat::getW( ) const inline float Quat::getW( ) const
{ {
return mW; return mW;
} }
inline Quat & Quat::setElem( int idx, float value ) inline Quat & Quat::setElem( int idx, float value )
{ {
*(&mX + idx) = value; *(&mX + idx) = value;
return *this; return *this;
} }
inline float Quat::getElem( int idx ) const inline float Quat::getElem( int idx ) const
{ {
return *(&mX + idx); return *(&mX + idx);
} }
inline float & Quat::operator []( int idx ) inline float & Quat::operator []( int idx )
{ {
return *(&mX + idx); return *(&mX + idx);
} }
inline float Quat::operator []( int idx ) const inline float Quat::operator []( int idx ) const
{ {
return *(&mX + idx); return *(&mX + idx);
} }
inline const Quat Quat::operator +( const Quat & quat ) const inline const Quat Quat::operator +( const Quat & quat ) const
{ {
return Quat( return Quat(
( mX + quat.mX ), ( mX + quat.mX ),
( mY + quat.mY ), ( mY + quat.mY ),
( mZ + quat.mZ ), ( mZ + quat.mZ ),
( mW + quat.mW ) ( mW + quat.mW )
); );
} }
inline const Quat Quat::operator -( const Quat & quat ) const inline const Quat Quat::operator -( const Quat & quat ) const
{ {
return Quat( return Quat(
( mX - quat.mX ), ( mX - quat.mX ),
( mY - quat.mY ), ( mY - quat.mY ),
( mZ - quat.mZ ), ( mZ - quat.mZ ),
( mW - quat.mW ) ( mW - quat.mW )
); );
} }
inline const Quat Quat::operator *( float scalar ) const inline const Quat Quat::operator *( float scalar ) const
{ {
return Quat( return Quat(
( mX * scalar ), ( mX * scalar ),
( mY * scalar ), ( mY * scalar ),
( mZ * scalar ), ( mZ * scalar ),
( mW * scalar ) ( mW * scalar )
); );
} }
inline Quat & Quat::operator +=( const Quat & quat ) inline Quat & Quat::operator +=( const Quat & quat )
{ {
*this = *this + quat; *this = *this + quat;
return *this; return *this;
} }
inline Quat & Quat::operator -=( const Quat & quat ) inline Quat & Quat::operator -=( const Quat & quat )
{ {
*this = *this - quat; *this = *this - quat;
return *this; return *this;
} }
inline Quat & Quat::operator *=( float scalar ) inline Quat & Quat::operator *=( float scalar )
{ {
*this = *this * scalar; *this = *this * scalar;
return *this; return *this;
} }
inline const Quat Quat::operator /( float scalar ) const inline const Quat Quat::operator /( float scalar ) const
{ {
return Quat( return Quat(
( mX / scalar ), ( mX / scalar ),
( mY / scalar ), ( mY / scalar ),
( mZ / scalar ), ( mZ / scalar ),
( mW / scalar ) ( mW / scalar )
); );
} }
inline Quat & Quat::operator /=( float scalar ) inline Quat & Quat::operator /=( float scalar )
{ {
*this = *this / scalar; *this = *this / scalar;
return *this; return *this;
} }
inline const Quat Quat::operator -( ) const inline const Quat Quat::operator -( ) const
{ {
return Quat( return Quat(
-mX, -mX,
-mY, -mY,
-mZ, -mZ,
-mW -mW
); );
} }
inline const Quat operator *( float scalar, const Quat & quat ) inline const Quat operator *( float scalar, const Quat & quat )
{ {
return quat * scalar; return quat * scalar;
} }
inline float dot( const Quat & quat0, const Quat & quat1 ) inline float dot( const Quat & quat0, const Quat & quat1 )
{ {
float result; float result;
result = ( quat0.getX() * quat1.getX() ); result = ( quat0.getX() * quat1.getX() );
result = ( result + ( quat0.getY() * quat1.getY() ) ); result = ( result + ( quat0.getY() * quat1.getY() ) );
result = ( result + ( quat0.getZ() * quat1.getZ() ) ); result = ( result + ( quat0.getZ() * quat1.getZ() ) );
result = ( result + ( quat0.getW() * quat1.getW() ) ); result = ( result + ( quat0.getW() * quat1.getW() ) );
return result; return result;
} }
inline float norm( const Quat & quat ) inline float norm( const Quat & quat )
{ {
float result; float result;
result = ( quat.getX() * quat.getX() ); result = ( quat.getX() * quat.getX() );
result = ( result + ( quat.getY() * quat.getY() ) ); result = ( result + ( quat.getY() * quat.getY() ) );
result = ( result + ( quat.getZ() * quat.getZ() ) ); result = ( result + ( quat.getZ() * quat.getZ() ) );
result = ( result + ( quat.getW() * quat.getW() ) ); result = ( result + ( quat.getW() * quat.getW() ) );
return result; return result;
} }
inline float length( const Quat & quat ) inline float length( const Quat & quat )
{ {
return sqrtf( norm( quat ) ); return sqrtf( norm( quat ) );
} }
inline const Quat normalize( const Quat & quat ) inline const Quat normalize( const Quat & quat )
{ {
float lenSqr, lenInv; float lenSqr, lenInv;
lenSqr = norm( quat ); lenSqr = norm( quat );
lenInv = ( 1.0f / sqrtf( lenSqr ) ); lenInv = ( 1.0f / sqrtf( lenSqr ) );
return Quat( return Quat(
( quat.getX() * lenInv ), ( quat.getX() * lenInv ),
( quat.getY() * lenInv ), ( quat.getY() * lenInv ),
( quat.getZ() * lenInv ), ( quat.getZ() * lenInv ),
( quat.getW() * lenInv ) ( quat.getW() * lenInv )
); );
} }
inline const Quat Quat::rotation( const Vector3 & unitVec0, const Vector3 & unitVec1 ) inline const Quat Quat::rotation( const Vector3 & unitVec0, const Vector3 & unitVec1 )
{ {
float cosHalfAngleX2, recipCosHalfAngleX2; float cosHalfAngleX2, recipCosHalfAngleX2;
cosHalfAngleX2 = sqrtf( ( 2.0f * ( 1.0f + dot( unitVec0, unitVec1 ) ) ) ); cosHalfAngleX2 = sqrtf( ( 2.0f * ( 1.0f + dot( unitVec0, unitVec1 ) ) ) );
recipCosHalfAngleX2 = ( 1.0f / cosHalfAngleX2 ); recipCosHalfAngleX2 = ( 1.0f / cosHalfAngleX2 );
return Quat( ( cross( unitVec0, unitVec1 ) * recipCosHalfAngleX2 ), ( cosHalfAngleX2 * 0.5f ) ); return Quat( ( cross( unitVec0, unitVec1 ) * recipCosHalfAngleX2 ), ( cosHalfAngleX2 * 0.5f ) );
} }
inline const Quat Quat::rotation( float radians, const Vector3 & unitVec ) inline const Quat Quat::rotation( float radians, const Vector3 & unitVec )
{ {
float s, c, angle; float s, c, angle;
angle = ( radians * 0.5f ); angle = ( radians * 0.5f );
s = sinf( angle ); s = sinf( angle );
c = cosf( angle ); c = cosf( angle );
return Quat( ( unitVec * s ), c ); return Quat( ( unitVec * s ), c );
} }
inline const Quat Quat::rotationX( float radians ) inline const Quat Quat::rotationX( float radians )
{ {
float s, c, angle; float s, c, angle;
angle = ( radians * 0.5f ); angle = ( radians * 0.5f );
s = sinf( angle ); s = sinf( angle );
c = cosf( angle ); c = cosf( angle );
return Quat( s, 0.0f, 0.0f, c ); return Quat( s, 0.0f, 0.0f, c );
} }
inline const Quat Quat::rotationY( float radians ) inline const Quat Quat::rotationY( float radians )
{ {
float s, c, angle; float s, c, angle;
angle = ( radians * 0.5f ); angle = ( radians * 0.5f );
s = sinf( angle ); s = sinf( angle );
c = cosf( angle ); c = cosf( angle );
return Quat( 0.0f, s, 0.0f, c ); return Quat( 0.0f, s, 0.0f, c );
} }
inline const Quat Quat::rotationZ( float radians ) inline const Quat Quat::rotationZ( float radians )
{ {
float s, c, angle; float s, c, angle;
angle = ( radians * 0.5f ); angle = ( radians * 0.5f );
s = sinf( angle ); s = sinf( angle );
c = cosf( angle ); c = cosf( angle );
return Quat( 0.0f, 0.0f, s, c ); return Quat( 0.0f, 0.0f, s, c );
} }
inline const Quat Quat::operator *( const Quat & quat ) const inline const Quat Quat::operator *( const Quat & quat ) const
{ {
return Quat( return Quat(
( ( ( ( mW * quat.mX ) + ( mX * quat.mW ) ) + ( mY * quat.mZ ) ) - ( mZ * quat.mY ) ), ( ( ( ( mW * quat.mX ) + ( mX * quat.mW ) ) + ( mY * quat.mZ ) ) - ( mZ * quat.mY ) ),
( ( ( ( mW * quat.mY ) + ( mY * quat.mW ) ) + ( mZ * quat.mX ) ) - ( mX * quat.mZ ) ), ( ( ( ( mW * quat.mY ) + ( mY * quat.mW ) ) + ( mZ * quat.mX ) ) - ( mX * quat.mZ ) ),
( ( ( ( mW * quat.mZ ) + ( mZ * quat.mW ) ) + ( mX * quat.mY ) ) - ( mY * quat.mX ) ), ( ( ( ( mW * quat.mZ ) + ( mZ * quat.mW ) ) + ( mX * quat.mY ) ) - ( mY * quat.mX ) ),
( ( ( ( mW * quat.mW ) - ( mX * quat.mX ) ) - ( mY * quat.mY ) ) - ( mZ * quat.mZ ) ) ( ( ( ( mW * quat.mW ) - ( mX * quat.mX ) ) - ( mY * quat.mY ) ) - ( mZ * quat.mZ ) )
); );
} }
inline Quat & Quat::operator *=( const Quat & quat ) inline Quat & Quat::operator *=( const Quat & quat )
{ {
*this = *this * quat; *this = *this * quat;
return *this; return *this;
} }
inline const Vector3 rotate( const Quat & quat, const Vector3 & vec ) inline const Vector3 rotate( const Quat & quat, const Vector3 & vec )
{ {
float tmpX, tmpY, tmpZ, tmpW; float tmpX, tmpY, tmpZ, tmpW;
tmpX = ( ( ( quat.getW() * vec.getX() ) + ( quat.getY() * vec.getZ() ) ) - ( quat.getZ() * vec.getY() ) ); tmpX = ( ( ( quat.getW() * vec.getX() ) + ( quat.getY() * vec.getZ() ) ) - ( quat.getZ() * vec.getY() ) );
tmpY = ( ( ( quat.getW() * vec.getY() ) + ( quat.getZ() * vec.getX() ) ) - ( quat.getX() * vec.getZ() ) ); tmpY = ( ( ( quat.getW() * vec.getY() ) + ( quat.getZ() * vec.getX() ) ) - ( quat.getX() * vec.getZ() ) );
tmpZ = ( ( ( quat.getW() * vec.getZ() ) + ( quat.getX() * vec.getY() ) ) - ( quat.getY() * vec.getX() ) ); tmpZ = ( ( ( quat.getW() * vec.getZ() ) + ( quat.getX() * vec.getY() ) ) - ( quat.getY() * vec.getX() ) );
tmpW = ( ( ( quat.getX() * vec.getX() ) + ( quat.getY() * vec.getY() ) ) + ( quat.getZ() * vec.getZ() ) ); tmpW = ( ( ( quat.getX() * vec.getX() ) + ( quat.getY() * vec.getY() ) ) + ( quat.getZ() * vec.getZ() ) );
return Vector3( return Vector3(
( ( ( ( tmpW * quat.getX() ) + ( tmpX * quat.getW() ) ) - ( tmpY * quat.getZ() ) ) + ( tmpZ * quat.getY() ) ), ( ( ( ( tmpW * quat.getX() ) + ( tmpX * quat.getW() ) ) - ( tmpY * quat.getZ() ) ) + ( tmpZ * quat.getY() ) ),
( ( ( ( tmpW * quat.getY() ) + ( tmpY * quat.getW() ) ) - ( tmpZ * quat.getX() ) ) + ( tmpX * quat.getZ() ) ), ( ( ( ( tmpW * quat.getY() ) + ( tmpY * quat.getW() ) ) - ( tmpZ * quat.getX() ) ) + ( tmpX * quat.getZ() ) ),
( ( ( ( tmpW * quat.getZ() ) + ( tmpZ * quat.getW() ) ) - ( tmpX * quat.getY() ) ) + ( tmpY * quat.getX() ) ) ( ( ( ( tmpW * quat.getZ() ) + ( tmpZ * quat.getW() ) ) - ( tmpX * quat.getY() ) ) + ( tmpY * quat.getX() ) )
); );
} }
inline const Quat conj( const Quat & quat ) inline const Quat conj( const Quat & quat )
{ {
return Quat( -quat.getX(), -quat.getY(), -quat.getZ(), quat.getW() ); return Quat( -quat.getX(), -quat.getY(), -quat.getZ(), quat.getW() );
} }
inline const Quat select( const Quat & quat0, const Quat & quat1, bool select1 ) inline const Quat select( const Quat & quat0, const Quat & quat1, bool select1 )
{ {
return Quat( return Quat(
( select1 )? quat1.getX() : quat0.getX(), ( select1 )? quat1.getX() : quat0.getX(),
( select1 )? quat1.getY() : quat0.getY(), ( select1 )? quat1.getY() : quat0.getY(),
( select1 )? quat1.getZ() : quat0.getZ(), ( select1 )? quat1.getZ() : quat0.getZ(),
( select1 )? quat1.getW() : quat0.getW() ( select1 )? quat1.getW() : quat0.getW()
); );
} }
#ifdef _VECTORMATH_DEBUG #ifdef _VECTORMATH_DEBUG
inline void print( const Quat & quat ) inline void print( const Quat & quat )
{ {
printf( "( %f %f %f %f )\n", quat.getX(), quat.getY(), quat.getZ(), quat.getW() ); printf( "( %f %f %f %f )\n", quat.getX(), quat.getY(), quat.getZ(), quat.getW() );
} }
inline void print( const Quat & quat, const char * name ) inline void print( const Quat & quat, const char * name )
{ {
printf( "%s: ( %f %f %f %f )\n", name, quat.getX(), quat.getY(), quat.getZ(), quat.getW() ); printf( "%s: ( %f %f %f %f )\n", name, quat.getX(), quat.getY(), quat.getZ(), quat.getW() );
} }
#endif #endif
} // namespace Aos } // namespace Aos
} // namespace Vectormath } // namespace Vectormath
#endif #endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,371 +1,371 @@
/* /*
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc. Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the with or without modification, are permitted provided that the
following conditions are met: following conditions are met:
* Redistributions of source code must retain the above copyright * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright * Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names * Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission. from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef _VECTORMATH_QUAT_AOS_C_H #ifndef _VECTORMATH_QUAT_AOS_C_H
#define _VECTORMATH_QUAT_AOS_C_H #define _VECTORMATH_QUAT_AOS_C_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
/*----------------------------------------------------------------------------- /*-----------------------------------------------------------------------------
* Definitions * Definitions
*/ */
#ifndef _VECTORMATH_INTERNAL_FUNCTIONS #ifndef _VECTORMATH_INTERNAL_FUNCTIONS
#define _VECTORMATH_INTERNAL_FUNCTIONS #define _VECTORMATH_INTERNAL_FUNCTIONS
#endif #endif
static inline void vmathQCopy( VmathQuat *result, const VmathQuat *quat ) static inline void vmathQCopy( VmathQuat *result, const VmathQuat *quat )
{ {
result->vec128 = quat->vec128; result->vec128 = quat->vec128;
} }
static inline void vmathQMakeFromElems( VmathQuat *result, float _x, float _y, float _z, float _w ) static inline void vmathQMakeFromElems( VmathQuat *result, float _x, float _y, float _z, float _w )
{ {
result->vec128 = (vec_float4){ _x, _y, _z, _w }; result->vec128 = (vec_float4){ _x, _y, _z, _w };
} }
static inline void vmathQMakeFromV3Scalar( VmathQuat *result, const VmathVector3 *xyz, float _w ) static inline void vmathQMakeFromV3Scalar( VmathQuat *result, const VmathVector3 *xyz, float _w )
{ {
result->vec128 = spu_shuffle( xyz->vec128, spu_promote( _w, 0 ), _VECTORMATH_SHUF_XYZA ); result->vec128 = spu_shuffle( xyz->vec128, spu_promote( _w, 0 ), _VECTORMATH_SHUF_XYZA );
} }
static inline void vmathQMakeFromV4( VmathQuat *result, const VmathVector4 *vec ) static inline void vmathQMakeFromV4( VmathQuat *result, const VmathVector4 *vec )
{ {
result->vec128 = vec->vec128; result->vec128 = vec->vec128;
} }
static inline void vmathQMakeFromScalar( VmathQuat *result, float scalar ) static inline void vmathQMakeFromScalar( VmathQuat *result, float scalar )
{ {
result->vec128 = spu_splats( scalar ); result->vec128 = spu_splats( scalar );
} }
static inline void vmathQMakeFrom128( VmathQuat *result, vec_float4 vf4 ) static inline void vmathQMakeFrom128( VmathQuat *result, vec_float4 vf4 )
{ {
result->vec128 = vf4; result->vec128 = vf4;
} }
static inline void vmathQMakeIdentity( VmathQuat *result ) static inline void vmathQMakeIdentity( VmathQuat *result )
{ {
result->vec128 = _VECTORMATH_UNIT_0001; result->vec128 = _VECTORMATH_UNIT_0001;
} }
static inline void vmathQLerp( VmathQuat *result, float t, const VmathQuat *quat0, const VmathQuat *quat1 ) static inline void vmathQLerp( VmathQuat *result, float t, const VmathQuat *quat0, const VmathQuat *quat1 )
{ {
VmathQuat tmpQ_0, tmpQ_1; VmathQuat tmpQ_0, tmpQ_1;
vmathQSub( &tmpQ_0, quat1, quat0 ); vmathQSub( &tmpQ_0, quat1, quat0 );
vmathQScalarMul( &tmpQ_1, &tmpQ_0, t ); vmathQScalarMul( &tmpQ_1, &tmpQ_0, t );
vmathQAdd( result, quat0, &tmpQ_1 ); vmathQAdd( result, quat0, &tmpQ_1 );
} }
static inline void vmathQSlerp( VmathQuat *result, float t, const VmathQuat *unitQuat0, const VmathQuat *unitQuat1 ) static inline void vmathQSlerp( VmathQuat *result, float t, const VmathQuat *unitQuat0, const VmathQuat *unitQuat1 )
{ {
VmathQuat start; VmathQuat start;
vec_float4 scales, scale0, scale1, cosAngle, angle, tttt, oneMinusT, angles, sines; vec_float4 scales, scale0, scale1, cosAngle, angle, tttt, oneMinusT, angles, sines;
vec_uint4 selectMask; vec_uint4 selectMask;
vec_uchar16 shuffle_xxxx = (vec_uchar16)spu_splats((int)0x00010203); vec_uchar16 shuffle_xxxx = (vec_uchar16)spu_splats((int)0x00010203);
vec_uchar16 shuffle_yyyy = (vec_uchar16)spu_splats((int)0x04050607); vec_uchar16 shuffle_yyyy = (vec_uchar16)spu_splats((int)0x04050607);
vec_uchar16 shuffle_zzzz = (vec_uchar16)spu_splats((int)0x08090a0b); vec_uchar16 shuffle_zzzz = (vec_uchar16)spu_splats((int)0x08090a0b);
cosAngle = _vmathVfDot4( unitQuat0->vec128, unitQuat1->vec128 ); cosAngle = _vmathVfDot4( unitQuat0->vec128, unitQuat1->vec128 );
cosAngle = spu_shuffle( cosAngle, cosAngle, shuffle_xxxx ); cosAngle = spu_shuffle( cosAngle, cosAngle, shuffle_xxxx );
selectMask = (vec_uint4)spu_cmpgt( spu_splats(0.0f), cosAngle ); selectMask = (vec_uint4)spu_cmpgt( spu_splats(0.0f), cosAngle );
cosAngle = spu_sel( cosAngle, negatef4( cosAngle ), selectMask ); cosAngle = spu_sel( cosAngle, negatef4( cosAngle ), selectMask );
start.vec128 = spu_sel( unitQuat0->vec128, negatef4( unitQuat0->vec128 ), selectMask ); start.vec128 = spu_sel( unitQuat0->vec128, negatef4( unitQuat0->vec128 ), selectMask );
selectMask = (vec_uint4)spu_cmpgt( spu_splats(_VECTORMATH_SLERP_TOL), cosAngle ); selectMask = (vec_uint4)spu_cmpgt( spu_splats(_VECTORMATH_SLERP_TOL), cosAngle );
angle = acosf4( cosAngle ); angle = acosf4( cosAngle );
tttt = spu_splats(t); tttt = spu_splats(t);
oneMinusT = spu_sub( spu_splats(1.0f), tttt ); oneMinusT = spu_sub( spu_splats(1.0f), tttt );
angles = spu_sel( spu_splats(1.0f), oneMinusT, (vec_uint4)spu_maskb(0x0f00) ); angles = spu_sel( spu_splats(1.0f), oneMinusT, (vec_uint4)spu_maskb(0x0f00) );
angles = spu_sel( angles, tttt, (vec_uint4)spu_maskb(0x00f0) ); angles = spu_sel( angles, tttt, (vec_uint4)spu_maskb(0x00f0) );
angles = spu_mul( angles, angle ); angles = spu_mul( angles, angle );
sines = sinf4( angles ); sines = sinf4( angles );
scales = divf4( sines, spu_shuffle( sines, sines, shuffle_xxxx ) ); scales = divf4( sines, spu_shuffle( sines, sines, shuffle_xxxx ) );
scale0 = spu_sel( oneMinusT, spu_shuffle( scales, scales, shuffle_yyyy ), selectMask ); scale0 = spu_sel( oneMinusT, spu_shuffle( scales, scales, shuffle_yyyy ), selectMask );
scale1 = spu_sel( tttt, spu_shuffle( scales, scales, shuffle_zzzz ), selectMask ); scale1 = spu_sel( tttt, spu_shuffle( scales, scales, shuffle_zzzz ), selectMask );
result->vec128 = spu_madd( start.vec128, scale0, spu_mul( unitQuat1->vec128, scale1 ) ); result->vec128 = spu_madd( start.vec128, scale0, spu_mul( unitQuat1->vec128, scale1 ) );
} }
static inline void vmathQSquad( VmathQuat *result, float t, const VmathQuat *unitQuat0, const VmathQuat *unitQuat1, const VmathQuat *unitQuat2, const VmathQuat *unitQuat3 ) static inline void vmathQSquad( VmathQuat *result, float t, const VmathQuat *unitQuat0, const VmathQuat *unitQuat1, const VmathQuat *unitQuat2, const VmathQuat *unitQuat3 )
{ {
VmathQuat tmp0, tmp1; VmathQuat tmp0, tmp1;
vmathQSlerp( &tmp0, t, unitQuat0, unitQuat3 ); vmathQSlerp( &tmp0, t, unitQuat0, unitQuat3 );
vmathQSlerp( &tmp1, t, unitQuat1, unitQuat2 ); vmathQSlerp( &tmp1, t, unitQuat1, unitQuat2 );
vmathQSlerp( result, ( ( 2.0f * t ) * ( 1.0f - t ) ), &tmp0, &tmp1 ); vmathQSlerp( result, ( ( 2.0f * t ) * ( 1.0f - t ) ), &tmp0, &tmp1 );
} }
static inline vec_float4 vmathQGet128( const VmathQuat *quat ) static inline vec_float4 vmathQGet128( const VmathQuat *quat )
{ {
return quat->vec128; return quat->vec128;
} }
static inline void vmathQSetXYZ( VmathQuat *result, const VmathVector3 *vec ) static inline void vmathQSetXYZ( VmathQuat *result, const VmathVector3 *vec )
{ {
result->vec128 = spu_sel( vec->vec128, result->vec128, (vec_uint4)spu_maskb(0x000f) ); result->vec128 = spu_sel( vec->vec128, result->vec128, (vec_uint4)spu_maskb(0x000f) );
} }
static inline void vmathQGetXYZ( VmathVector3 *result, const VmathQuat *quat ) static inline void vmathQGetXYZ( VmathVector3 *result, const VmathQuat *quat )
{ {
result->vec128 = quat->vec128; result->vec128 = quat->vec128;
} }
static inline void vmathQSetX( VmathQuat *result, float _x ) static inline void vmathQSetX( VmathQuat *result, float _x )
{ {
result->vec128 = spu_insert( _x, result->vec128, 0 ); result->vec128 = spu_insert( _x, result->vec128, 0 );
} }
static inline float vmathQGetX( const VmathQuat *quat ) static inline float vmathQGetX( const VmathQuat *quat )
{ {
return spu_extract( quat->vec128, 0 ); return spu_extract( quat->vec128, 0 );
} }
static inline void vmathQSetY( VmathQuat *result, float _y ) static inline void vmathQSetY( VmathQuat *result, float _y )
{ {
result->vec128 = spu_insert( _y, result->vec128, 1 ); result->vec128 = spu_insert( _y, result->vec128, 1 );
} }
static inline float vmathQGetY( const VmathQuat *quat ) static inline float vmathQGetY( const VmathQuat *quat )
{ {
return spu_extract( quat->vec128, 1 ); return spu_extract( quat->vec128, 1 );
} }
static inline void vmathQSetZ( VmathQuat *result, float _z ) static inline void vmathQSetZ( VmathQuat *result, float _z )
{ {
result->vec128 = spu_insert( _z, result->vec128, 2 ); result->vec128 = spu_insert( _z, result->vec128, 2 );
} }
static inline float vmathQGetZ( const VmathQuat *quat ) static inline float vmathQGetZ( const VmathQuat *quat )
{ {
return spu_extract( quat->vec128, 2 ); return spu_extract( quat->vec128, 2 );
} }
static inline void vmathQSetW( VmathQuat *result, float _w ) static inline void vmathQSetW( VmathQuat *result, float _w )
{ {
result->vec128 = spu_insert( _w, result->vec128, 3 ); result->vec128 = spu_insert( _w, result->vec128, 3 );
} }
static inline float vmathQGetW( const VmathQuat *quat ) static inline float vmathQGetW( const VmathQuat *quat )
{ {
return spu_extract( quat->vec128, 3 ); return spu_extract( quat->vec128, 3 );
} }
static inline void vmathQSetElem( VmathQuat *result, int idx, float value ) static inline void vmathQSetElem( VmathQuat *result, int idx, float value )
{ {
result->vec128 = spu_insert( value, result->vec128, idx ); result->vec128 = spu_insert( value, result->vec128, idx );
} }
static inline float vmathQGetElem( const VmathQuat *quat, int idx ) static inline float vmathQGetElem( const VmathQuat *quat, int idx )
{ {
return spu_extract( quat->vec128, idx ); return spu_extract( quat->vec128, idx );
} }
static inline void vmathQAdd( VmathQuat *result, const VmathQuat *quat0, const VmathQuat *quat1 ) static inline void vmathQAdd( VmathQuat *result, const VmathQuat *quat0, const VmathQuat *quat1 )
{ {
result->vec128 = spu_add( quat0->vec128, quat1->vec128 ); result->vec128 = spu_add( quat0->vec128, quat1->vec128 );
} }
static inline void vmathQSub( VmathQuat *result, const VmathQuat *quat0, const VmathQuat *quat1 ) static inline void vmathQSub( VmathQuat *result, const VmathQuat *quat0, const VmathQuat *quat1 )
{ {
result->vec128 = spu_sub( quat0->vec128, quat1->vec128 ); result->vec128 = spu_sub( quat0->vec128, quat1->vec128 );
} }
static inline void vmathQScalarMul( VmathQuat *result, const VmathQuat *quat, float scalar ) static inline void vmathQScalarMul( VmathQuat *result, const VmathQuat *quat, float scalar )
{ {
result->vec128 = spu_mul( quat->vec128, spu_splats(scalar) ); result->vec128 = spu_mul( quat->vec128, spu_splats(scalar) );
} }
static inline void vmathQScalarDiv( VmathQuat *result, const VmathQuat *quat, float scalar ) static inline void vmathQScalarDiv( VmathQuat *result, const VmathQuat *quat, float scalar )
{ {
result->vec128 = divf4( quat->vec128, spu_splats(scalar) ); result->vec128 = divf4( quat->vec128, spu_splats(scalar) );
} }
static inline void vmathQNeg( VmathQuat *result, const VmathQuat *quat ) static inline void vmathQNeg( VmathQuat *result, const VmathQuat *quat )
{ {
result->vec128 = negatef4( quat->vec128 ); result->vec128 = negatef4( quat->vec128 );
} }
static inline float vmathQDot( const VmathQuat *quat0, const VmathQuat *quat1 ) static inline float vmathQDot( const VmathQuat *quat0, const VmathQuat *quat1 )
{ {
return spu_extract( _vmathVfDot4( quat0->vec128, quat1->vec128 ), 0 ); return spu_extract( _vmathVfDot4( quat0->vec128, quat1->vec128 ), 0 );
} }
static inline float vmathQNorm( const VmathQuat *quat ) static inline float vmathQNorm( const VmathQuat *quat )
{ {
return spu_extract( _vmathVfDot4( quat->vec128, quat->vec128 ), 0 ); return spu_extract( _vmathVfDot4( quat->vec128, quat->vec128 ), 0 );
} }
static inline float vmathQLength( const VmathQuat *quat ) static inline float vmathQLength( const VmathQuat *quat )
{ {
return sqrtf( vmathQNorm( quat ) ); return sqrtf( vmathQNorm( quat ) );
} }
static inline void vmathQNormalize( VmathQuat *result, const VmathQuat *quat ) static inline void vmathQNormalize( VmathQuat *result, const VmathQuat *quat )
{ {
vec_float4 dot = _vmathVfDot4( quat->vec128, quat->vec128 ); vec_float4 dot = _vmathVfDot4( quat->vec128, quat->vec128 );
result->vec128 = spu_mul( quat->vec128, rsqrtf4( dot ) ); result->vec128 = spu_mul( quat->vec128, rsqrtf4( dot ) );
} }
static inline void vmathQMakeRotationArc( VmathQuat *result, const VmathVector3 *unitVec0, const VmathVector3 *unitVec1 ) static inline void vmathQMakeRotationArc( VmathQuat *result, const VmathVector3 *unitVec0, const VmathVector3 *unitVec1 )
{ {
VmathVector3 crossVec, tmpV3_0; VmathVector3 crossVec, tmpV3_0;
vec_float4 cosAngle, cosAngleX2Plus2, recipCosHalfAngleX2, cosHalfAngleX2, res; vec_float4 cosAngle, cosAngleX2Plus2, recipCosHalfAngleX2, cosHalfAngleX2, res;
cosAngle = _vmathVfDot3( unitVec0->vec128, unitVec1->vec128 ); cosAngle = _vmathVfDot3( unitVec0->vec128, unitVec1->vec128 );
cosAngle = spu_shuffle( cosAngle, cosAngle, (vec_uchar16)spu_splats(0x00010203) ); cosAngle = spu_shuffle( cosAngle, cosAngle, (vec_uchar16)spu_splats(0x00010203) );
cosAngleX2Plus2 = spu_madd( cosAngle, spu_splats(2.0f), spu_splats(2.0f) ); cosAngleX2Plus2 = spu_madd( cosAngle, spu_splats(2.0f), spu_splats(2.0f) );
recipCosHalfAngleX2 = rsqrtf4( cosAngleX2Plus2 ); recipCosHalfAngleX2 = rsqrtf4( cosAngleX2Plus2 );
cosHalfAngleX2 = spu_mul( recipCosHalfAngleX2, cosAngleX2Plus2 ); cosHalfAngleX2 = spu_mul( recipCosHalfAngleX2, cosAngleX2Plus2 );
vmathV3Cross( &tmpV3_0, unitVec0, unitVec1 ); vmathV3Cross( &tmpV3_0, unitVec0, unitVec1 );
crossVec = tmpV3_0; crossVec = tmpV3_0;
res = spu_mul( crossVec.vec128, recipCosHalfAngleX2 ); res = spu_mul( crossVec.vec128, recipCosHalfAngleX2 );
res = spu_sel( res, spu_mul( cosHalfAngleX2, spu_splats(0.5f) ), (vec_uint4)spu_maskb(0x000f) ); res = spu_sel( res, spu_mul( cosHalfAngleX2, spu_splats(0.5f) ), (vec_uint4)spu_maskb(0x000f) );
result->vec128 = res; result->vec128 = res;
} }
static inline void vmathQMakeRotationAxis( VmathQuat *result, float radians, const VmathVector3 *unitVec ) static inline void vmathQMakeRotationAxis( VmathQuat *result, float radians, const VmathVector3 *unitVec )
{ {
vec_float4 s, c, angle, res; vec_float4 s, c, angle, res;
angle = spu_mul( spu_splats(radians), spu_splats(0.5f) ); angle = spu_mul( spu_splats(radians), spu_splats(0.5f) );
sincosf4( angle, &s, &c ); sincosf4( angle, &s, &c );
res = spu_sel( spu_mul( unitVec->vec128, s ), c, (vec_uint4)spu_maskb(0x000f) ); res = spu_sel( spu_mul( unitVec->vec128, s ), c, (vec_uint4)spu_maskb(0x000f) );
result->vec128 = res; result->vec128 = res;
} }
static inline void vmathQMakeRotationX( VmathQuat *result, float radians ) static inline void vmathQMakeRotationX( VmathQuat *result, float radians )
{ {
vec_float4 s, c, angle, res; vec_float4 s, c, angle, res;
angle = spu_mul( spu_splats(radians), spu_splats(0.5f) ); angle = spu_mul( spu_splats(radians), spu_splats(0.5f) );
sincosf4( angle, &s, &c ); sincosf4( angle, &s, &c );
res = spu_sel( spu_splats(0.0f), s, (vec_uint4)spu_maskb(0xf000) ); res = spu_sel( spu_splats(0.0f), s, (vec_uint4)spu_maskb(0xf000) );
res = spu_sel( res, c, (vec_uint4)spu_maskb(0x000f) ); res = spu_sel( res, c, (vec_uint4)spu_maskb(0x000f) );
result->vec128 = res; result->vec128 = res;
} }
static inline void vmathQMakeRotationY( VmathQuat *result, float radians ) static inline void vmathQMakeRotationY( VmathQuat *result, float radians )
{ {
vec_float4 s, c, angle, res; vec_float4 s, c, angle, res;
angle = spu_mul( spu_splats(radians), spu_splats(0.5f) ); angle = spu_mul( spu_splats(radians), spu_splats(0.5f) );
sincosf4( angle, &s, &c ); sincosf4( angle, &s, &c );
res = spu_sel( spu_splats(0.0f), s, (vec_uint4)spu_maskb(0x0f00) ); res = spu_sel( spu_splats(0.0f), s, (vec_uint4)spu_maskb(0x0f00) );
res = spu_sel( res, c, (vec_uint4)spu_maskb(0x000f) ); res = spu_sel( res, c, (vec_uint4)spu_maskb(0x000f) );
result->vec128 = res; result->vec128 = res;
} }
static inline void vmathQMakeRotationZ( VmathQuat *result, float radians ) static inline void vmathQMakeRotationZ( VmathQuat *result, float radians )
{ {
vec_float4 s, c, angle, res; vec_float4 s, c, angle, res;
angle = spu_mul( spu_splats(radians), spu_splats(0.5f) ); angle = spu_mul( spu_splats(radians), spu_splats(0.5f) );
sincosf4( angle, &s, &c ); sincosf4( angle, &s, &c );
res = spu_sel( spu_splats(0.0f), s, (vec_uint4)spu_maskb(0x00f0) ); res = spu_sel( spu_splats(0.0f), s, (vec_uint4)spu_maskb(0x00f0) );
res = spu_sel( res, c, (vec_uint4)spu_maskb(0x000f) ); res = spu_sel( res, c, (vec_uint4)spu_maskb(0x000f) );
result->vec128 = res; result->vec128 = res;
} }
static inline void vmathQMul( VmathQuat *result, const VmathQuat *quat0, const VmathQuat *quat1 ) static inline void vmathQMul( VmathQuat *result, const VmathQuat *quat0, const VmathQuat *quat1 )
{ {
vec_float4 ldata, rdata, qv, tmp0, tmp1, tmp2, tmp3; vec_float4 ldata, rdata, qv, tmp0, tmp1, tmp2, tmp3;
vec_float4 product, l_wxyz, r_wxyz, xy, qw; vec_float4 product, l_wxyz, r_wxyz, xy, qw;
ldata = quat0->vec128; ldata = quat0->vec128;
rdata = quat1->vec128; rdata = quat1->vec128;
vec_uchar16 shuffle_wwww = (vec_uchar16)spu_splats((int)0x0c0d0e0f); vec_uchar16 shuffle_wwww = (vec_uchar16)spu_splats((int)0x0c0d0e0f);
tmp0 = spu_shuffle( ldata, ldata, _VECTORMATH_SHUF_YZXW ); tmp0 = spu_shuffle( ldata, ldata, _VECTORMATH_SHUF_YZXW );
tmp1 = spu_shuffle( rdata, rdata, _VECTORMATH_SHUF_ZXYW ); tmp1 = spu_shuffle( rdata, rdata, _VECTORMATH_SHUF_ZXYW );
tmp2 = spu_shuffle( ldata, ldata, _VECTORMATH_SHUF_ZXYW ); tmp2 = spu_shuffle( ldata, ldata, _VECTORMATH_SHUF_ZXYW );
tmp3 = spu_shuffle( rdata, rdata, _VECTORMATH_SHUF_YZXW ); tmp3 = spu_shuffle( rdata, rdata, _VECTORMATH_SHUF_YZXW );
qv = spu_mul( spu_shuffle( ldata, ldata, shuffle_wwww ), rdata ); qv = spu_mul( spu_shuffle( ldata, ldata, shuffle_wwww ), rdata );
qv = spu_madd( spu_shuffle( rdata, rdata, shuffle_wwww ), ldata, qv ); qv = spu_madd( spu_shuffle( rdata, rdata, shuffle_wwww ), ldata, qv );
qv = spu_madd( tmp0, tmp1, qv ); qv = spu_madd( tmp0, tmp1, qv );
qv = spu_nmsub( tmp2, tmp3, qv ); qv = spu_nmsub( tmp2, tmp3, qv );
product = spu_mul( ldata, rdata ); product = spu_mul( ldata, rdata );
l_wxyz = spu_rlqwbyte( ldata, 12 ); l_wxyz = spu_rlqwbyte( ldata, 12 );
r_wxyz = spu_rlqwbyte( rdata, 12 ); r_wxyz = spu_rlqwbyte( rdata, 12 );
qw = spu_nmsub( l_wxyz, r_wxyz, product ); qw = spu_nmsub( l_wxyz, r_wxyz, product );
xy = spu_madd( l_wxyz, r_wxyz, product ); xy = spu_madd( l_wxyz, r_wxyz, product );
qw = spu_sub( qw, spu_rlqwbyte( xy, 8 ) ); qw = spu_sub( qw, spu_rlqwbyte( xy, 8 ) );
result->vec128 = spu_sel( qv, qw, (vec_uint4)spu_maskb( 0x000f ) ); result->vec128 = spu_sel( qv, qw, (vec_uint4)spu_maskb( 0x000f ) );
} }
static inline void vmathQRotate( VmathVector3 *result, const VmathQuat *quat, const VmathVector3 *vec ) static inline void vmathQRotate( VmathVector3 *result, const VmathQuat *quat, const VmathVector3 *vec )
{ {
vec_float4 qdata, vdata, product, tmp0, tmp1, tmp2, tmp3, wwww, qv, qw, res; vec_float4 qdata, vdata, product, tmp0, tmp1, tmp2, tmp3, wwww, qv, qw, res;
qdata = quat->vec128; qdata = quat->vec128;
vdata = vec->vec128; vdata = vec->vec128;
vec_uchar16 shuffle_xxxx = (vec_uchar16)spu_splats((int)0x00010203); vec_uchar16 shuffle_xxxx = (vec_uchar16)spu_splats((int)0x00010203);
vec_uchar16 shuffle_wwww = (vec_uchar16)spu_splats((int)0x0c0d0e0f); vec_uchar16 shuffle_wwww = (vec_uchar16)spu_splats((int)0x0c0d0e0f);
tmp0 = spu_shuffle( qdata, qdata, _VECTORMATH_SHUF_YZXW ); tmp0 = spu_shuffle( qdata, qdata, _VECTORMATH_SHUF_YZXW );
tmp1 = spu_shuffle( vdata, vdata, _VECTORMATH_SHUF_ZXYW ); tmp1 = spu_shuffle( vdata, vdata, _VECTORMATH_SHUF_ZXYW );
tmp2 = spu_shuffle( qdata, qdata, _VECTORMATH_SHUF_ZXYW ); tmp2 = spu_shuffle( qdata, qdata, _VECTORMATH_SHUF_ZXYW );
tmp3 = spu_shuffle( vdata, vdata, _VECTORMATH_SHUF_YZXW ); tmp3 = spu_shuffle( vdata, vdata, _VECTORMATH_SHUF_YZXW );
wwww = spu_shuffle( qdata, qdata, shuffle_wwww ); wwww = spu_shuffle( qdata, qdata, shuffle_wwww );
qv = spu_mul( wwww, vdata ); qv = spu_mul( wwww, vdata );
qv = spu_madd( tmp0, tmp1, qv ); qv = spu_madd( tmp0, tmp1, qv );
qv = spu_nmsub( tmp2, tmp3, qv ); qv = spu_nmsub( tmp2, tmp3, qv );
product = spu_mul( qdata, vdata ); product = spu_mul( qdata, vdata );
qw = spu_madd( spu_rlqwbyte( qdata, 4 ), spu_rlqwbyte( vdata, 4 ), product ); qw = spu_madd( spu_rlqwbyte( qdata, 4 ), spu_rlqwbyte( vdata, 4 ), product );
qw = spu_add( spu_rlqwbyte( product, 8 ), qw ); qw = spu_add( spu_rlqwbyte( product, 8 ), qw );
tmp1 = spu_shuffle( qv, qv, _VECTORMATH_SHUF_ZXYW ); tmp1 = spu_shuffle( qv, qv, _VECTORMATH_SHUF_ZXYW );
tmp3 = spu_shuffle( qv, qv, _VECTORMATH_SHUF_YZXW ); tmp3 = spu_shuffle( qv, qv, _VECTORMATH_SHUF_YZXW );
res = spu_mul( spu_shuffle( qw, qw, shuffle_xxxx ), qdata ); res = spu_mul( spu_shuffle( qw, qw, shuffle_xxxx ), qdata );
res = spu_madd( wwww, qv, res ); res = spu_madd( wwww, qv, res );
res = spu_madd( tmp0, tmp1, res ); res = spu_madd( tmp0, tmp1, res );
res = spu_nmsub( tmp2, tmp3, res ); res = spu_nmsub( tmp2, tmp3, res );
result->vec128 = res; result->vec128 = res;
} }
static inline void vmathQConj( VmathQuat *result, const VmathQuat *quat ) static inline void vmathQConj( VmathQuat *result, const VmathQuat *quat )
{ {
result->vec128 = spu_xor( quat->vec128, ((vec_float4)(vec_int4){0x80000000,0x80000000,0x80000000,0}) ); result->vec128 = spu_xor( quat->vec128, ((vec_float4)(vec_int4){0x80000000,0x80000000,0x80000000,0}) );
} }
static inline void vmathQSelect( VmathQuat *result, const VmathQuat *quat0, const VmathQuat *quat1, unsigned int select1 ) static inline void vmathQSelect( VmathQuat *result, const VmathQuat *quat0, const VmathQuat *quat1, unsigned int select1 )
{ {
result->vec128 = spu_sel( quat0->vec128, quat1->vec128, spu_splats( (unsigned int)-(select1 > 0) ) ); result->vec128 = spu_sel( quat0->vec128, quat1->vec128, spu_splats( (unsigned int)-(select1 > 0) ) );
} }
#ifdef _VECTORMATH_DEBUG #ifdef _VECTORMATH_DEBUG
static inline void vmathQPrint( const VmathQuat *quat ) static inline void vmathQPrint( const VmathQuat *quat )
{ {
union { vec_float4 v; float s[4]; } tmp; union { vec_float4 v; float s[4]; } tmp;
tmp.v = quat->vec128; tmp.v = quat->vec128;
printf( "( %f %f %f %f )\n", tmp.s[0], tmp.s[1], tmp.s[2], tmp.s[3] ); printf( "( %f %f %f %f )\n", tmp.s[0], tmp.s[1], tmp.s[2], tmp.s[3] );
} }
static inline void vmathQPrints( const VmathQuat *quat, const char *name ) static inline void vmathQPrints( const VmathQuat *quat, const char *name )
{ {
union { vec_float4 v; float s[4]; } tmp; union { vec_float4 v; float s[4]; } tmp;
tmp.v = quat->vec128; tmp.v = quat->vec128;
printf( "%s: ( %f %f %f %f )\n", name, tmp.s[0], tmp.s[1], tmp.s[2], tmp.s[3] ); printf( "%s: ( %f %f %f %f )\n", name, tmp.s[0], tmp.s[1], tmp.s[2], tmp.s[3] );
} }
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif #endif

View File

@@ -1,312 +1,312 @@
/* /*
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc. Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the with or without modification, are permitted provided that the
following conditions are met: following conditions are met:
* Redistributions of source code must retain the above copyright * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright * Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names * Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission. from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef _VECTORMATH_QUAT_AOS_V_C_H #ifndef _VECTORMATH_QUAT_AOS_V_C_H
#define _VECTORMATH_QUAT_AOS_V_C_H #define _VECTORMATH_QUAT_AOS_V_C_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
/*----------------------------------------------------------------------------- /*-----------------------------------------------------------------------------
* Definitions * Definitions
*/ */
#ifndef _VECTORMATH_INTERNAL_FUNCTIONS #ifndef _VECTORMATH_INTERNAL_FUNCTIONS
#define _VECTORMATH_INTERNAL_FUNCTIONS #define _VECTORMATH_INTERNAL_FUNCTIONS
#endif #endif
static inline VmathQuat vmathQMakeFromElems_V( float _x, float _y, float _z, float _w ) static inline VmathQuat vmathQMakeFromElems_V( float _x, float _y, float _z, float _w )
{ {
VmathQuat result; VmathQuat result;
vmathQMakeFromElems(&result, _x, _y, _z, _w); vmathQMakeFromElems(&result, _x, _y, _z, _w);
return result; return result;
} }
static inline VmathQuat vmathQMakeFromV3Scalar_V( VmathVector3 xyz, float _w ) static inline VmathQuat vmathQMakeFromV3Scalar_V( VmathVector3 xyz, float _w )
{ {
VmathQuat result; VmathQuat result;
vmathQMakeFromV3Scalar(&result, &xyz, _w); vmathQMakeFromV3Scalar(&result, &xyz, _w);
return result; return result;
} }
static inline VmathQuat vmathQMakeFromV4_V( VmathVector4 vec ) static inline VmathQuat vmathQMakeFromV4_V( VmathVector4 vec )
{ {
VmathQuat result; VmathQuat result;
vmathQMakeFromV4(&result, &vec); vmathQMakeFromV4(&result, &vec);
return result; return result;
} }
static inline VmathQuat vmathQMakeFromScalar_V( float scalar ) static inline VmathQuat vmathQMakeFromScalar_V( float scalar )
{ {
VmathQuat result; VmathQuat result;
vmathQMakeFromScalar(&result, scalar); vmathQMakeFromScalar(&result, scalar);
return result; return result;
} }
static inline VmathQuat vmathQMakeFrom128_V( vec_float4 vf4 ) static inline VmathQuat vmathQMakeFrom128_V( vec_float4 vf4 )
{ {
VmathQuat result; VmathQuat result;
vmathQMakeFrom128(&result, vf4); vmathQMakeFrom128(&result, vf4);
return result; return result;
} }
static inline VmathQuat vmathQMakeIdentity_V( ) static inline VmathQuat vmathQMakeIdentity_V( )
{ {
VmathQuat result; VmathQuat result;
vmathQMakeIdentity(&result); vmathQMakeIdentity(&result);
return result; return result;
} }
static inline VmathQuat vmathQLerp_V( float t, VmathQuat quat0, VmathQuat quat1 ) static inline VmathQuat vmathQLerp_V( float t, VmathQuat quat0, VmathQuat quat1 )
{ {
VmathQuat result; VmathQuat result;
vmathQLerp(&result, t, &quat0, &quat1); vmathQLerp(&result, t, &quat0, &quat1);
return result; return result;
} }
static inline VmathQuat vmathQSlerp_V( float t, VmathQuat unitQuat0, VmathQuat unitQuat1 ) static inline VmathQuat vmathQSlerp_V( float t, VmathQuat unitQuat0, VmathQuat unitQuat1 )
{ {
VmathQuat result; VmathQuat result;
vmathQSlerp(&result, t, &unitQuat0, &unitQuat1); vmathQSlerp(&result, t, &unitQuat0, &unitQuat1);
return result; return result;
} }
static inline VmathQuat vmathQSquad_V( float t, VmathQuat unitQuat0, VmathQuat unitQuat1, VmathQuat unitQuat2, VmathQuat unitQuat3 ) static inline VmathQuat vmathQSquad_V( float t, VmathQuat unitQuat0, VmathQuat unitQuat1, VmathQuat unitQuat2, VmathQuat unitQuat3 )
{ {
VmathQuat result; VmathQuat result;
vmathQSquad(&result, t, &unitQuat0, &unitQuat1, &unitQuat2, &unitQuat3); vmathQSquad(&result, t, &unitQuat0, &unitQuat1, &unitQuat2, &unitQuat3);
return result; return result;
} }
static inline vec_float4 vmathQGet128_V( VmathQuat quat ) static inline vec_float4 vmathQGet128_V( VmathQuat quat )
{ {
return vmathQGet128(&quat); return vmathQGet128(&quat);
} }
static inline void vmathQSetXYZ_V( VmathQuat *result, VmathVector3 vec ) static inline void vmathQSetXYZ_V( VmathQuat *result, VmathVector3 vec )
{ {
vmathQSetXYZ(result, &vec); vmathQSetXYZ(result, &vec);
} }
static inline VmathVector3 vmathQGetXYZ_V( VmathQuat quat ) static inline VmathVector3 vmathQGetXYZ_V( VmathQuat quat )
{ {
VmathVector3 result; VmathVector3 result;
vmathQGetXYZ(&result, &quat); vmathQGetXYZ(&result, &quat);
return result; return result;
} }
static inline void vmathQSetX_V( VmathQuat *result, float _x ) static inline void vmathQSetX_V( VmathQuat *result, float _x )
{ {
vmathQSetX(result, _x); vmathQSetX(result, _x);
} }
static inline float vmathQGetX_V( VmathQuat quat ) static inline float vmathQGetX_V( VmathQuat quat )
{ {
return vmathQGetX(&quat); return vmathQGetX(&quat);
} }
static inline void vmathQSetY_V( VmathQuat *result, float _y ) static inline void vmathQSetY_V( VmathQuat *result, float _y )
{ {
vmathQSetY(result, _y); vmathQSetY(result, _y);
} }
static inline float vmathQGetY_V( VmathQuat quat ) static inline float vmathQGetY_V( VmathQuat quat )
{ {
return vmathQGetY(&quat); return vmathQGetY(&quat);
} }
static inline void vmathQSetZ_V( VmathQuat *result, float _z ) static inline void vmathQSetZ_V( VmathQuat *result, float _z )
{ {
vmathQSetZ(result, _z); vmathQSetZ(result, _z);
} }
static inline float vmathQGetZ_V( VmathQuat quat ) static inline float vmathQGetZ_V( VmathQuat quat )
{ {
return vmathQGetZ(&quat); return vmathQGetZ(&quat);
} }
static inline void vmathQSetW_V( VmathQuat *result, float _w ) static inline void vmathQSetW_V( VmathQuat *result, float _w )
{ {
vmathQSetW(result, _w); vmathQSetW(result, _w);
} }
static inline float vmathQGetW_V( VmathQuat quat ) static inline float vmathQGetW_V( VmathQuat quat )
{ {
return vmathQGetW(&quat); return vmathQGetW(&quat);
} }
static inline void vmathQSetElem_V( VmathQuat *result, int idx, float value ) static inline void vmathQSetElem_V( VmathQuat *result, int idx, float value )
{ {
vmathQSetElem(result, idx, value); vmathQSetElem(result, idx, value);
} }
static inline float vmathQGetElem_V( VmathQuat quat, int idx ) static inline float vmathQGetElem_V( VmathQuat quat, int idx )
{ {
return vmathQGetElem(&quat, idx); return vmathQGetElem(&quat, idx);
} }
static inline VmathQuat vmathQAdd_V( VmathQuat quat0, VmathQuat quat1 ) static inline VmathQuat vmathQAdd_V( VmathQuat quat0, VmathQuat quat1 )
{ {
VmathQuat result; VmathQuat result;
vmathQAdd(&result, &quat0, &quat1); vmathQAdd(&result, &quat0, &quat1);
return result; return result;
} }
static inline VmathQuat vmathQSub_V( VmathQuat quat0, VmathQuat quat1 ) static inline VmathQuat vmathQSub_V( VmathQuat quat0, VmathQuat quat1 )
{ {
VmathQuat result; VmathQuat result;
vmathQSub(&result, &quat0, &quat1); vmathQSub(&result, &quat0, &quat1);
return result; return result;
} }
static inline VmathQuat vmathQScalarMul_V( VmathQuat quat, float scalar ) static inline VmathQuat vmathQScalarMul_V( VmathQuat quat, float scalar )
{ {
VmathQuat result; VmathQuat result;
vmathQScalarMul(&result, &quat, scalar); vmathQScalarMul(&result, &quat, scalar);
return result; return result;
} }
static inline VmathQuat vmathQScalarDiv_V( VmathQuat quat, float scalar ) static inline VmathQuat vmathQScalarDiv_V( VmathQuat quat, float scalar )
{ {
VmathQuat result; VmathQuat result;
vmathQScalarDiv(&result, &quat, scalar); vmathQScalarDiv(&result, &quat, scalar);
return result; return result;
} }
static inline VmathQuat vmathQNeg_V( VmathQuat quat ) static inline VmathQuat vmathQNeg_V( VmathQuat quat )
{ {
VmathQuat result; VmathQuat result;
vmathQNeg(&result, &quat); vmathQNeg(&result, &quat);
return result; return result;
} }
static inline float vmathQDot_V( VmathQuat quat0, VmathQuat quat1 ) static inline float vmathQDot_V( VmathQuat quat0, VmathQuat quat1 )
{ {
return vmathQDot(&quat0, &quat1); return vmathQDot(&quat0, &quat1);
} }
static inline float vmathQNorm_V( VmathQuat quat ) static inline float vmathQNorm_V( VmathQuat quat )
{ {
return vmathQNorm(&quat); return vmathQNorm(&quat);
} }
static inline float vmathQLength_V( VmathQuat quat ) static inline float vmathQLength_V( VmathQuat quat )
{ {
return vmathQLength(&quat); return vmathQLength(&quat);
} }
static inline VmathQuat vmathQNormalize_V( VmathQuat quat ) static inline VmathQuat vmathQNormalize_V( VmathQuat quat )
{ {
VmathQuat result; VmathQuat result;
vmathQNormalize(&result, &quat); vmathQNormalize(&result, &quat);
return result; return result;
} }
static inline VmathQuat vmathQMakeRotationArc_V( VmathVector3 unitVec0, VmathVector3 unitVec1 ) static inline VmathQuat vmathQMakeRotationArc_V( VmathVector3 unitVec0, VmathVector3 unitVec1 )
{ {
VmathQuat result; VmathQuat result;
vmathQMakeRotationArc(&result, &unitVec0, &unitVec1); vmathQMakeRotationArc(&result, &unitVec0, &unitVec1);
return result; return result;
} }
static inline VmathQuat vmathQMakeRotationAxis_V( float radians, VmathVector3 unitVec ) static inline VmathQuat vmathQMakeRotationAxis_V( float radians, VmathVector3 unitVec )
{ {
VmathQuat result; VmathQuat result;
vmathQMakeRotationAxis(&result, radians, &unitVec); vmathQMakeRotationAxis(&result, radians, &unitVec);
return result; return result;
} }
static inline VmathQuat vmathQMakeRotationX_V( float radians ) static inline VmathQuat vmathQMakeRotationX_V( float radians )
{ {
VmathQuat result; VmathQuat result;
vmathQMakeRotationX(&result, radians); vmathQMakeRotationX(&result, radians);
return result; return result;
} }
static inline VmathQuat vmathQMakeRotationY_V( float radians ) static inline VmathQuat vmathQMakeRotationY_V( float radians )
{ {
VmathQuat result; VmathQuat result;
vmathQMakeRotationY(&result, radians); vmathQMakeRotationY(&result, radians);
return result; return result;
} }
static inline VmathQuat vmathQMakeRotationZ_V( float radians ) static inline VmathQuat vmathQMakeRotationZ_V( float radians )
{ {
VmathQuat result; VmathQuat result;
vmathQMakeRotationZ(&result, radians); vmathQMakeRotationZ(&result, radians);
return result; return result;
} }
static inline VmathQuat vmathQMul_V( VmathQuat quat0, VmathQuat quat1 ) static inline VmathQuat vmathQMul_V( VmathQuat quat0, VmathQuat quat1 )
{ {
VmathQuat result; VmathQuat result;
vmathQMul(&result, &quat0, &quat1); vmathQMul(&result, &quat0, &quat1);
return result; return result;
} }
static inline VmathVector3 vmathQRotate_V( VmathQuat quat, VmathVector3 vec ) static inline VmathVector3 vmathQRotate_V( VmathQuat quat, VmathVector3 vec )
{ {
VmathVector3 result; VmathVector3 result;
vmathQRotate(&result, &quat, &vec); vmathQRotate(&result, &quat, &vec);
return result; return result;
} }
static inline VmathQuat vmathQConj_V( VmathQuat quat ) static inline VmathQuat vmathQConj_V( VmathQuat quat )
{ {
VmathQuat result; VmathQuat result;
vmathQConj(&result, &quat); vmathQConj(&result, &quat);
return result; return result;
} }
static inline VmathQuat vmathQSelect_V( VmathQuat quat0, VmathQuat quat1, unsigned int select1 ) static inline VmathQuat vmathQSelect_V( VmathQuat quat0, VmathQuat quat1, unsigned int select1 )
{ {
VmathQuat result; VmathQuat result;
vmathQSelect(&result, &quat0, &quat1, select1); vmathQSelect(&result, &quat0, &quat1, select1);
return result; return result;
} }
#ifdef _VECTORMATH_DEBUG #ifdef _VECTORMATH_DEBUG
static inline void vmathQPrint_V( VmathQuat quat ) static inline void vmathQPrint_V( VmathQuat quat )
{ {
vmathQPrint(&quat); vmathQPrint(&quat);
} }
static inline void vmathQPrints_V( VmathQuat quat, const char *name ) static inline void vmathQPrints_V( VmathQuat quat, const char *name )
{ {
vmathQPrints(&quat, name); vmathQPrints(&quat, name);
} }
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif #endif

View File

@@ -1,419 +1,419 @@
/* /*
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc. Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the with or without modification, are permitted provided that the
following conditions are met: following conditions are met:
* Redistributions of source code must retain the above copyright * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright * Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names * Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission. from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef _VECTORMATH_QUAT_SOA_C_H #ifndef _VECTORMATH_QUAT_SOA_C_H
#define _VECTORMATH_QUAT_SOA_C_H #define _VECTORMATH_QUAT_SOA_C_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
/*----------------------------------------------------------------------------- /*-----------------------------------------------------------------------------
* Definitions * Definitions
*/ */
#ifndef _VECTORMATH_INTERNAL_FUNCTIONS #ifndef _VECTORMATH_INTERNAL_FUNCTIONS
#define _VECTORMATH_INTERNAL_FUNCTIONS #define _VECTORMATH_INTERNAL_FUNCTIONS
#endif #endif
static inline void vmathSoaQCopy( VmathSoaQuat *result, const VmathSoaQuat *quat ) static inline void vmathSoaQCopy( VmathSoaQuat *result, const VmathSoaQuat *quat )
{ {
result->x = quat->x; result->x = quat->x;
result->y = quat->y; result->y = quat->y;
result->z = quat->z; result->z = quat->z;
result->w = quat->w; result->w = quat->w;
} }
static inline void vmathSoaQMakeFromElems( VmathSoaQuat *result, vec_float4 _x, vec_float4 _y, vec_float4 _z, vec_float4 _w ) static inline void vmathSoaQMakeFromElems( VmathSoaQuat *result, vec_float4 _x, vec_float4 _y, vec_float4 _z, vec_float4 _w )
{ {
result->x = _x; result->x = _x;
result->y = _y; result->y = _y;
result->z = _z; result->z = _z;
result->w = _w; result->w = _w;
} }
static inline void vmathSoaQMakeFromV3Scalar( VmathSoaQuat *result, const VmathSoaVector3 *xyz, vec_float4 _w ) static inline void vmathSoaQMakeFromV3Scalar( VmathSoaQuat *result, const VmathSoaVector3 *xyz, vec_float4 _w )
{ {
vmathSoaQSetXYZ( result, xyz ); vmathSoaQSetXYZ( result, xyz );
vmathSoaQSetW( result, _w ); vmathSoaQSetW( result, _w );
} }
static inline void vmathSoaQMakeFromV4( VmathSoaQuat *result, const VmathSoaVector4 *vec ) static inline void vmathSoaQMakeFromV4( VmathSoaQuat *result, const VmathSoaVector4 *vec )
{ {
result->x = vec->x; result->x = vec->x;
result->y = vec->y; result->y = vec->y;
result->z = vec->z; result->z = vec->z;
result->w = vec->w; result->w = vec->w;
} }
static inline void vmathSoaQMakeFromScalar( VmathSoaQuat *result, vec_float4 scalar ) static inline void vmathSoaQMakeFromScalar( VmathSoaQuat *result, vec_float4 scalar )
{ {
result->x = scalar; result->x = scalar;
result->y = scalar; result->y = scalar;
result->z = scalar; result->z = scalar;
result->w = scalar; result->w = scalar;
} }
static inline void vmathSoaQMakeFromAos( VmathSoaQuat *result, const VmathQuat *quat ) static inline void vmathSoaQMakeFromAos( VmathSoaQuat *result, const VmathQuat *quat )
{ {
vec_uchar16 shuffle_xxxx = (vec_uchar16)spu_splats((int)0x00010203); vec_uchar16 shuffle_xxxx = (vec_uchar16)spu_splats((int)0x00010203);
vec_uchar16 shuffle_yyyy = (vec_uchar16)spu_splats((int)0x04050607); vec_uchar16 shuffle_yyyy = (vec_uchar16)spu_splats((int)0x04050607);
vec_uchar16 shuffle_zzzz = (vec_uchar16)spu_splats((int)0x08090a0b); vec_uchar16 shuffle_zzzz = (vec_uchar16)spu_splats((int)0x08090a0b);
vec_uchar16 shuffle_wwww = (vec_uchar16)spu_splats((int)0x0c0d0e0f); vec_uchar16 shuffle_wwww = (vec_uchar16)spu_splats((int)0x0c0d0e0f);
vec_float4 vec128 = quat->vec128; vec_float4 vec128 = quat->vec128;
result->x = spu_shuffle( vec128, vec128, shuffle_xxxx ); result->x = spu_shuffle( vec128, vec128, shuffle_xxxx );
result->y = spu_shuffle( vec128, vec128, shuffle_yyyy ); result->y = spu_shuffle( vec128, vec128, shuffle_yyyy );
result->z = spu_shuffle( vec128, vec128, shuffle_zzzz ); result->z = spu_shuffle( vec128, vec128, shuffle_zzzz );
result->w = spu_shuffle( vec128, vec128, shuffle_wwww ); result->w = spu_shuffle( vec128, vec128, shuffle_wwww );
} }
static inline void vmathSoaQMakeFrom4Aos( VmathSoaQuat *result, const VmathQuat *quat0, const VmathQuat *quat1, const VmathQuat *quat2, const VmathQuat *quat3 ) static inline void vmathSoaQMakeFrom4Aos( VmathSoaQuat *result, const VmathQuat *quat0, const VmathQuat *quat1, const VmathQuat *quat2, const VmathQuat *quat3 )
{ {
vec_float4 tmp0, tmp1, tmp2, tmp3; vec_float4 tmp0, tmp1, tmp2, tmp3;
tmp0 = spu_shuffle( quat0->vec128, quat2->vec128, _VECTORMATH_SHUF_XAYB ); tmp0 = spu_shuffle( quat0->vec128, quat2->vec128, _VECTORMATH_SHUF_XAYB );
tmp1 = spu_shuffle( quat1->vec128, quat3->vec128, _VECTORMATH_SHUF_XAYB ); tmp1 = spu_shuffle( quat1->vec128, quat3->vec128, _VECTORMATH_SHUF_XAYB );
tmp2 = spu_shuffle( quat0->vec128, quat2->vec128, _VECTORMATH_SHUF_ZCWD ); tmp2 = spu_shuffle( quat0->vec128, quat2->vec128, _VECTORMATH_SHUF_ZCWD );
tmp3 = spu_shuffle( quat1->vec128, quat3->vec128, _VECTORMATH_SHUF_ZCWD ); tmp3 = spu_shuffle( quat1->vec128, quat3->vec128, _VECTORMATH_SHUF_ZCWD );
result->x = spu_shuffle( tmp0, tmp1, _VECTORMATH_SHUF_XAYB ); result->x = spu_shuffle( tmp0, tmp1, _VECTORMATH_SHUF_XAYB );
result->y = spu_shuffle( tmp0, tmp1, _VECTORMATH_SHUF_ZCWD ); result->y = spu_shuffle( tmp0, tmp1, _VECTORMATH_SHUF_ZCWD );
result->z = spu_shuffle( tmp2, tmp3, _VECTORMATH_SHUF_XAYB ); result->z = spu_shuffle( tmp2, tmp3, _VECTORMATH_SHUF_XAYB );
result->w = spu_shuffle( tmp2, tmp3, _VECTORMATH_SHUF_ZCWD ); result->w = spu_shuffle( tmp2, tmp3, _VECTORMATH_SHUF_ZCWD );
} }
static inline void vmathSoaQMakeIdentity( VmathSoaQuat *result ) static inline void vmathSoaQMakeIdentity( VmathSoaQuat *result )
{ {
vmathSoaQMakeFromElems( result, spu_splats(0.0f), spu_splats(0.0f), spu_splats(0.0f), spu_splats(1.0f) ); vmathSoaQMakeFromElems( result, spu_splats(0.0f), spu_splats(0.0f), spu_splats(0.0f), spu_splats(1.0f) );
} }
static inline void vmathSoaQLerp( VmathSoaQuat *result, vec_float4 t, const VmathSoaQuat *quat0, const VmathSoaQuat *quat1 ) static inline void vmathSoaQLerp( VmathSoaQuat *result, vec_float4 t, const VmathSoaQuat *quat0, const VmathSoaQuat *quat1 )
{ {
VmathSoaQuat tmpQ_0, tmpQ_1; VmathSoaQuat tmpQ_0, tmpQ_1;
vmathSoaQSub( &tmpQ_0, quat1, quat0 ); vmathSoaQSub( &tmpQ_0, quat1, quat0 );
vmathSoaQScalarMul( &tmpQ_1, &tmpQ_0, t ); vmathSoaQScalarMul( &tmpQ_1, &tmpQ_0, t );
vmathSoaQAdd( result, quat0, &tmpQ_1 ); vmathSoaQAdd( result, quat0, &tmpQ_1 );
} }
static inline void vmathSoaQSlerp( VmathSoaQuat *result, vec_float4 t, const VmathSoaQuat *unitQuat0, const VmathSoaQuat *unitQuat1 ) static inline void vmathSoaQSlerp( VmathSoaQuat *result, vec_float4 t, const VmathSoaQuat *unitQuat0, const VmathSoaQuat *unitQuat1 )
{ {
VmathSoaQuat start, tmpQ_0, tmpQ_1; VmathSoaQuat start, tmpQ_0, tmpQ_1;
vec_float4 recipSinAngle, scale0, scale1, cosAngle, angle; vec_float4 recipSinAngle, scale0, scale1, cosAngle, angle;
vec_uint4 selectMask; vec_uint4 selectMask;
cosAngle = vmathSoaQDot( unitQuat0, unitQuat1 ); cosAngle = vmathSoaQDot( unitQuat0, unitQuat1 );
selectMask = (vec_uint4)spu_cmpgt( spu_splats(0.0f), cosAngle ); selectMask = (vec_uint4)spu_cmpgt( spu_splats(0.0f), cosAngle );
cosAngle = spu_sel( cosAngle, negatef4( cosAngle ), selectMask ); cosAngle = spu_sel( cosAngle, negatef4( cosAngle ), selectMask );
vmathSoaQSetX( &start, spu_sel( unitQuat0->x, negatef4( unitQuat0->x ), selectMask ) ); vmathSoaQSetX( &start, spu_sel( unitQuat0->x, negatef4( unitQuat0->x ), selectMask ) );
vmathSoaQSetY( &start, spu_sel( unitQuat0->y, negatef4( unitQuat0->y ), selectMask ) ); vmathSoaQSetY( &start, spu_sel( unitQuat0->y, negatef4( unitQuat0->y ), selectMask ) );
vmathSoaQSetZ( &start, spu_sel( unitQuat0->z, negatef4( unitQuat0->z ), selectMask ) ); vmathSoaQSetZ( &start, spu_sel( unitQuat0->z, negatef4( unitQuat0->z ), selectMask ) );
vmathSoaQSetW( &start, spu_sel( unitQuat0->w, negatef4( unitQuat0->w ), selectMask ) ); vmathSoaQSetW( &start, spu_sel( unitQuat0->w, negatef4( unitQuat0->w ), selectMask ) );
selectMask = (vec_uint4)spu_cmpgt( spu_splats(_VECTORMATH_SLERP_TOL), cosAngle ); selectMask = (vec_uint4)spu_cmpgt( spu_splats(_VECTORMATH_SLERP_TOL), cosAngle );
angle = acosf4( cosAngle ); angle = acosf4( cosAngle );
recipSinAngle = recipf4( sinf4( angle ) ); recipSinAngle = recipf4( sinf4( angle ) );
scale0 = spu_sel( spu_sub( spu_splats(1.0f), t ), spu_mul( sinf4( spu_mul( spu_sub( spu_splats(1.0f), t ), angle ) ), recipSinAngle ), selectMask ); scale0 = spu_sel( spu_sub( spu_splats(1.0f), t ), spu_mul( sinf4( spu_mul( spu_sub( spu_splats(1.0f), t ), angle ) ), recipSinAngle ), selectMask );
scale1 = spu_sel( t, spu_mul( sinf4( spu_mul( t, angle ) ), recipSinAngle ), selectMask ); scale1 = spu_sel( t, spu_mul( sinf4( spu_mul( t, angle ) ), recipSinAngle ), selectMask );
vmathSoaQScalarMul( &tmpQ_0, &start, scale0 ); vmathSoaQScalarMul( &tmpQ_0, &start, scale0 );
vmathSoaQScalarMul( &tmpQ_1, unitQuat1, scale1 ); vmathSoaQScalarMul( &tmpQ_1, unitQuat1, scale1 );
vmathSoaQAdd( result, &tmpQ_0, &tmpQ_1 ); vmathSoaQAdd( result, &tmpQ_0, &tmpQ_1 );
} }
static inline void vmathSoaQSquad( VmathSoaQuat *result, vec_float4 t, const VmathSoaQuat *unitQuat0, const VmathSoaQuat *unitQuat1, const VmathSoaQuat *unitQuat2, const VmathSoaQuat *unitQuat3 ) static inline void vmathSoaQSquad( VmathSoaQuat *result, vec_float4 t, const VmathSoaQuat *unitQuat0, const VmathSoaQuat *unitQuat1, const VmathSoaQuat *unitQuat2, const VmathSoaQuat *unitQuat3 )
{ {
VmathSoaQuat tmp0, tmp1; VmathSoaQuat tmp0, tmp1;
vmathSoaQSlerp( &tmp0, t, unitQuat0, unitQuat3 ); vmathSoaQSlerp( &tmp0, t, unitQuat0, unitQuat3 );
vmathSoaQSlerp( &tmp1, t, unitQuat1, unitQuat2 ); vmathSoaQSlerp( &tmp1, t, unitQuat1, unitQuat2 );
vmathSoaQSlerp( result, spu_mul( spu_mul( spu_splats(2.0f), t ), spu_sub( spu_splats(1.0f), t ) ), &tmp0, &tmp1 ); vmathSoaQSlerp( result, spu_mul( spu_mul( spu_splats(2.0f), t ), spu_sub( spu_splats(1.0f), t ) ), &tmp0, &tmp1 );
} }
static inline void vmathSoaQGet4Aos( const VmathSoaQuat *quat, VmathQuat *result0, VmathQuat *result1, VmathQuat *result2, VmathQuat *result3 ) static inline void vmathSoaQGet4Aos( const VmathSoaQuat *quat, VmathQuat *result0, VmathQuat *result1, VmathQuat *result2, VmathQuat *result3 )
{ {
vec_float4 tmp0, tmp1, tmp2, tmp3; vec_float4 tmp0, tmp1, tmp2, tmp3;
tmp0 = spu_shuffle( quat->x, quat->z, _VECTORMATH_SHUF_XAYB ); tmp0 = spu_shuffle( quat->x, quat->z, _VECTORMATH_SHUF_XAYB );
tmp1 = spu_shuffle( quat->y, quat->w, _VECTORMATH_SHUF_XAYB ); tmp1 = spu_shuffle( quat->y, quat->w, _VECTORMATH_SHUF_XAYB );
tmp2 = spu_shuffle( quat->x, quat->z, _VECTORMATH_SHUF_ZCWD ); tmp2 = spu_shuffle( quat->x, quat->z, _VECTORMATH_SHUF_ZCWD );
tmp3 = spu_shuffle( quat->y, quat->w, _VECTORMATH_SHUF_ZCWD ); tmp3 = spu_shuffle( quat->y, quat->w, _VECTORMATH_SHUF_ZCWD );
vmathQMakeFrom128( result0, spu_shuffle( tmp0, tmp1, _VECTORMATH_SHUF_XAYB ) ); vmathQMakeFrom128( result0, spu_shuffle( tmp0, tmp1, _VECTORMATH_SHUF_XAYB ) );
vmathQMakeFrom128( result1, spu_shuffle( tmp0, tmp1, _VECTORMATH_SHUF_ZCWD ) ); vmathQMakeFrom128( result1, spu_shuffle( tmp0, tmp1, _VECTORMATH_SHUF_ZCWD ) );
vmathQMakeFrom128( result2, spu_shuffle( tmp2, tmp3, _VECTORMATH_SHUF_XAYB ) ); vmathQMakeFrom128( result2, spu_shuffle( tmp2, tmp3, _VECTORMATH_SHUF_XAYB ) );
vmathQMakeFrom128( result3, spu_shuffle( tmp2, tmp3, _VECTORMATH_SHUF_ZCWD ) ); vmathQMakeFrom128( result3, spu_shuffle( tmp2, tmp3, _VECTORMATH_SHUF_ZCWD ) );
} }
static inline void vmathSoaQSetXYZ( VmathSoaQuat *result, const VmathSoaVector3 *vec ) static inline void vmathSoaQSetXYZ( VmathSoaQuat *result, const VmathSoaVector3 *vec )
{ {
result->x = vec->x; result->x = vec->x;
result->y = vec->y; result->y = vec->y;
result->z = vec->z; result->z = vec->z;
} }
static inline void vmathSoaQGetXYZ( VmathSoaVector3 *result, const VmathSoaQuat *quat ) static inline void vmathSoaQGetXYZ( VmathSoaVector3 *result, const VmathSoaQuat *quat )
{ {
vmathSoaV3MakeFromElems( result, quat->x, quat->y, quat->z ); vmathSoaV3MakeFromElems( result, quat->x, quat->y, quat->z );
} }
static inline void vmathSoaQSetX( VmathSoaQuat *result, vec_float4 _x ) static inline void vmathSoaQSetX( VmathSoaQuat *result, vec_float4 _x )
{ {
result->x = _x; result->x = _x;
} }
static inline vec_float4 vmathSoaQGetX( const VmathSoaQuat *quat ) static inline vec_float4 vmathSoaQGetX( const VmathSoaQuat *quat )
{ {
return quat->x; return quat->x;
} }
static inline void vmathSoaQSetY( VmathSoaQuat *result, vec_float4 _y ) static inline void vmathSoaQSetY( VmathSoaQuat *result, vec_float4 _y )
{ {
result->y = _y; result->y = _y;
} }
static inline vec_float4 vmathSoaQGetY( const VmathSoaQuat *quat ) static inline vec_float4 vmathSoaQGetY( const VmathSoaQuat *quat )
{ {
return quat->y; return quat->y;
} }
static inline void vmathSoaQSetZ( VmathSoaQuat *result, vec_float4 _z ) static inline void vmathSoaQSetZ( VmathSoaQuat *result, vec_float4 _z )
{ {
result->z = _z; result->z = _z;
} }
static inline vec_float4 vmathSoaQGetZ( const VmathSoaQuat *quat ) static inline vec_float4 vmathSoaQGetZ( const VmathSoaQuat *quat )
{ {
return quat->z; return quat->z;
} }
static inline void vmathSoaQSetW( VmathSoaQuat *result, vec_float4 _w ) static inline void vmathSoaQSetW( VmathSoaQuat *result, vec_float4 _w )
{ {
result->w = _w; result->w = _w;
} }
static inline vec_float4 vmathSoaQGetW( const VmathSoaQuat *quat ) static inline vec_float4 vmathSoaQGetW( const VmathSoaQuat *quat )
{ {
return quat->w; return quat->w;
} }
static inline void vmathSoaQSetElem( VmathSoaQuat *result, int idx, vec_float4 value ) static inline void vmathSoaQSetElem( VmathSoaQuat *result, int idx, vec_float4 value )
{ {
*(&result->x + idx) = value; *(&result->x + idx) = value;
} }
static inline vec_float4 vmathSoaQGetElem( const VmathSoaQuat *quat, int idx ) static inline vec_float4 vmathSoaQGetElem( const VmathSoaQuat *quat, int idx )
{ {
return *(&quat->x + idx); return *(&quat->x + idx);
} }
static inline void vmathSoaQAdd( VmathSoaQuat *result, const VmathSoaQuat *quat0, const VmathSoaQuat *quat1 ) static inline void vmathSoaQAdd( VmathSoaQuat *result, const VmathSoaQuat *quat0, const VmathSoaQuat *quat1 )
{ {
result->x = spu_add( quat0->x, quat1->x ); result->x = spu_add( quat0->x, quat1->x );
result->y = spu_add( quat0->y, quat1->y ); result->y = spu_add( quat0->y, quat1->y );
result->z = spu_add( quat0->z, quat1->z ); result->z = spu_add( quat0->z, quat1->z );
result->w = spu_add( quat0->w, quat1->w ); result->w = spu_add( quat0->w, quat1->w );
} }
static inline void vmathSoaQSub( VmathSoaQuat *result, const VmathSoaQuat *quat0, const VmathSoaQuat *quat1 ) static inline void vmathSoaQSub( VmathSoaQuat *result, const VmathSoaQuat *quat0, const VmathSoaQuat *quat1 )
{ {
result->x = spu_sub( quat0->x, quat1->x ); result->x = spu_sub( quat0->x, quat1->x );
result->y = spu_sub( quat0->y, quat1->y ); result->y = spu_sub( quat0->y, quat1->y );
result->z = spu_sub( quat0->z, quat1->z ); result->z = spu_sub( quat0->z, quat1->z );
result->w = spu_sub( quat0->w, quat1->w ); result->w = spu_sub( quat0->w, quat1->w );
} }
static inline void vmathSoaQScalarMul( VmathSoaQuat *result, const VmathSoaQuat *quat, vec_float4 scalar ) static inline void vmathSoaQScalarMul( VmathSoaQuat *result, const VmathSoaQuat *quat, vec_float4 scalar )
{ {
result->x = spu_mul( quat->x, scalar ); result->x = spu_mul( quat->x, scalar );
result->y = spu_mul( quat->y, scalar ); result->y = spu_mul( quat->y, scalar );
result->z = spu_mul( quat->z, scalar ); result->z = spu_mul( quat->z, scalar );
result->w = spu_mul( quat->w, scalar ); result->w = spu_mul( quat->w, scalar );
} }
static inline void vmathSoaQScalarDiv( VmathSoaQuat *result, const VmathSoaQuat *quat, vec_float4 scalar ) static inline void vmathSoaQScalarDiv( VmathSoaQuat *result, const VmathSoaQuat *quat, vec_float4 scalar )
{ {
result->x = divf4( quat->x, scalar ); result->x = divf4( quat->x, scalar );
result->y = divf4( quat->y, scalar ); result->y = divf4( quat->y, scalar );
result->z = divf4( quat->z, scalar ); result->z = divf4( quat->z, scalar );
result->w = divf4( quat->w, scalar ); result->w = divf4( quat->w, scalar );
} }
static inline void vmathSoaQNeg( VmathSoaQuat *result, const VmathSoaQuat *quat ) static inline void vmathSoaQNeg( VmathSoaQuat *result, const VmathSoaQuat *quat )
{ {
result->x = negatef4( quat->x ); result->x = negatef4( quat->x );
result->y = negatef4( quat->y ); result->y = negatef4( quat->y );
result->z = negatef4( quat->z ); result->z = negatef4( quat->z );
result->w = negatef4( quat->w ); result->w = negatef4( quat->w );
} }
static inline vec_float4 vmathSoaQDot( const VmathSoaQuat *quat0, const VmathSoaQuat *quat1 ) static inline vec_float4 vmathSoaQDot( const VmathSoaQuat *quat0, const VmathSoaQuat *quat1 )
{ {
vec_float4 result; vec_float4 result;
result = spu_mul( quat0->x, quat1->x ); result = spu_mul( quat0->x, quat1->x );
result = spu_add( result, spu_mul( quat0->y, quat1->y ) ); result = spu_add( result, spu_mul( quat0->y, quat1->y ) );
result = spu_add( result, spu_mul( quat0->z, quat1->z ) ); result = spu_add( result, spu_mul( quat0->z, quat1->z ) );
result = spu_add( result, spu_mul( quat0->w, quat1->w ) ); result = spu_add( result, spu_mul( quat0->w, quat1->w ) );
return result; return result;
} }
static inline vec_float4 vmathSoaQNorm( const VmathSoaQuat *quat ) static inline vec_float4 vmathSoaQNorm( const VmathSoaQuat *quat )
{ {
vec_float4 result; vec_float4 result;
result = spu_mul( quat->x, quat->x ); result = spu_mul( quat->x, quat->x );
result = spu_add( result, spu_mul( quat->y, quat->y ) ); result = spu_add( result, spu_mul( quat->y, quat->y ) );
result = spu_add( result, spu_mul( quat->z, quat->z ) ); result = spu_add( result, spu_mul( quat->z, quat->z ) );
result = spu_add( result, spu_mul( quat->w, quat->w ) ); result = spu_add( result, spu_mul( quat->w, quat->w ) );
return result; return result;
} }
static inline vec_float4 vmathSoaQLength( const VmathSoaQuat *quat ) static inline vec_float4 vmathSoaQLength( const VmathSoaQuat *quat )
{ {
return sqrtf4( vmathSoaQNorm( quat ) ); return sqrtf4( vmathSoaQNorm( quat ) );
} }
static inline void vmathSoaQNormalize( VmathSoaQuat *result, const VmathSoaQuat *quat ) static inline void vmathSoaQNormalize( VmathSoaQuat *result, const VmathSoaQuat *quat )
{ {
vec_float4 lenSqr, lenInv; vec_float4 lenSqr, lenInv;
lenSqr = vmathSoaQNorm( quat ); lenSqr = vmathSoaQNorm( quat );
lenInv = rsqrtf4( lenSqr ); lenInv = rsqrtf4( lenSqr );
result->x = spu_mul( quat->x, lenInv ); result->x = spu_mul( quat->x, lenInv );
result->y = spu_mul( quat->y, lenInv ); result->y = spu_mul( quat->y, lenInv );
result->z = spu_mul( quat->z, lenInv ); result->z = spu_mul( quat->z, lenInv );
result->w = spu_mul( quat->w, lenInv ); result->w = spu_mul( quat->w, lenInv );
} }
static inline void vmathSoaQMakeRotationArc( VmathSoaQuat *result, const VmathSoaVector3 *unitVec0, const VmathSoaVector3 *unitVec1 ) static inline void vmathSoaQMakeRotationArc( VmathSoaQuat *result, const VmathSoaVector3 *unitVec0, const VmathSoaVector3 *unitVec1 )
{ {
VmathSoaVector3 tmpV3_0, tmpV3_1; VmathSoaVector3 tmpV3_0, tmpV3_1;
vec_float4 cosHalfAngleX2, recipCosHalfAngleX2; vec_float4 cosHalfAngleX2, recipCosHalfAngleX2;
cosHalfAngleX2 = sqrtf4( spu_mul( spu_splats(2.0f), spu_add( spu_splats(1.0f), vmathSoaV3Dot( unitVec0, unitVec1 ) ) ) ); cosHalfAngleX2 = sqrtf4( spu_mul( spu_splats(2.0f), spu_add( spu_splats(1.0f), vmathSoaV3Dot( unitVec0, unitVec1 ) ) ) );
recipCosHalfAngleX2 = recipf4( cosHalfAngleX2 ); recipCosHalfAngleX2 = recipf4( cosHalfAngleX2 );
vmathSoaV3Cross( &tmpV3_0, unitVec0, unitVec1 ); vmathSoaV3Cross( &tmpV3_0, unitVec0, unitVec1 );
vmathSoaV3ScalarMul( &tmpV3_1, &tmpV3_0, recipCosHalfAngleX2 ); vmathSoaV3ScalarMul( &tmpV3_1, &tmpV3_0, recipCosHalfAngleX2 );
vmathSoaQMakeFromV3Scalar( result, &tmpV3_1, spu_mul( cosHalfAngleX2, spu_splats(0.5f) ) ); vmathSoaQMakeFromV3Scalar( result, &tmpV3_1, spu_mul( cosHalfAngleX2, spu_splats(0.5f) ) );
} }
static inline void vmathSoaQMakeRotationAxis( VmathSoaQuat *result, vec_float4 radians, const VmathSoaVector3 *unitVec ) static inline void vmathSoaQMakeRotationAxis( VmathSoaQuat *result, vec_float4 radians, const VmathSoaVector3 *unitVec )
{ {
VmathSoaVector3 tmpV3_0; VmathSoaVector3 tmpV3_0;
vec_float4 s, c, angle; vec_float4 s, c, angle;
angle = spu_mul( radians, spu_splats(0.5f) ); angle = spu_mul( radians, spu_splats(0.5f) );
sincosf4( angle, &s, &c ); sincosf4( angle, &s, &c );
vmathSoaV3ScalarMul( &tmpV3_0, unitVec, s ); vmathSoaV3ScalarMul( &tmpV3_0, unitVec, s );
vmathSoaQMakeFromV3Scalar( result, &tmpV3_0, c ); vmathSoaQMakeFromV3Scalar( result, &tmpV3_0, c );
} }
static inline void vmathSoaQMakeRotationX( VmathSoaQuat *result, vec_float4 radians ) static inline void vmathSoaQMakeRotationX( VmathSoaQuat *result, vec_float4 radians )
{ {
vec_float4 s, c, angle; vec_float4 s, c, angle;
angle = spu_mul( radians, spu_splats(0.5f) ); angle = spu_mul( radians, spu_splats(0.5f) );
sincosf4( angle, &s, &c ); sincosf4( angle, &s, &c );
vmathSoaQMakeFromElems( result, s, spu_splats(0.0f), spu_splats(0.0f), c ); vmathSoaQMakeFromElems( result, s, spu_splats(0.0f), spu_splats(0.0f), c );
} }
static inline void vmathSoaQMakeRotationY( VmathSoaQuat *result, vec_float4 radians ) static inline void vmathSoaQMakeRotationY( VmathSoaQuat *result, vec_float4 radians )
{ {
vec_float4 s, c, angle; vec_float4 s, c, angle;
angle = spu_mul( radians, spu_splats(0.5f) ); angle = spu_mul( radians, spu_splats(0.5f) );
sincosf4( angle, &s, &c ); sincosf4( angle, &s, &c );
vmathSoaQMakeFromElems( result, spu_splats(0.0f), s, spu_splats(0.0f), c ); vmathSoaQMakeFromElems( result, spu_splats(0.0f), s, spu_splats(0.0f), c );
} }
static inline void vmathSoaQMakeRotationZ( VmathSoaQuat *result, vec_float4 radians ) static inline void vmathSoaQMakeRotationZ( VmathSoaQuat *result, vec_float4 radians )
{ {
vec_float4 s, c, angle; vec_float4 s, c, angle;
angle = spu_mul( radians, spu_splats(0.5f) ); angle = spu_mul( radians, spu_splats(0.5f) );
sincosf4( angle, &s, &c ); sincosf4( angle, &s, &c );
vmathSoaQMakeFromElems( result, spu_splats(0.0f), spu_splats(0.0f), s, c ); vmathSoaQMakeFromElems( result, spu_splats(0.0f), spu_splats(0.0f), s, c );
} }
static inline void vmathSoaQMul( VmathSoaQuat *result, const VmathSoaQuat *quat0, const VmathSoaQuat *quat1 ) static inline void vmathSoaQMul( VmathSoaQuat *result, const VmathSoaQuat *quat0, const VmathSoaQuat *quat1 )
{ {
vec_float4 tmpX, tmpY, tmpZ, tmpW; vec_float4 tmpX, tmpY, tmpZ, tmpW;
tmpX = spu_sub( spu_add( spu_add( spu_mul( quat0->w, quat1->x ), spu_mul( quat0->x, quat1->w ) ), spu_mul( quat0->y, quat1->z ) ), spu_mul( quat0->z, quat1->y ) ); tmpX = spu_sub( spu_add( spu_add( spu_mul( quat0->w, quat1->x ), spu_mul( quat0->x, quat1->w ) ), spu_mul( quat0->y, quat1->z ) ), spu_mul( quat0->z, quat1->y ) );
tmpY = spu_sub( spu_add( spu_add( spu_mul( quat0->w, quat1->y ), spu_mul( quat0->y, quat1->w ) ), spu_mul( quat0->z, quat1->x ) ), spu_mul( quat0->x, quat1->z ) ); tmpY = spu_sub( spu_add( spu_add( spu_mul( quat0->w, quat1->y ), spu_mul( quat0->y, quat1->w ) ), spu_mul( quat0->z, quat1->x ) ), spu_mul( quat0->x, quat1->z ) );
tmpZ = spu_sub( spu_add( spu_add( spu_mul( quat0->w, quat1->z ), spu_mul( quat0->z, quat1->w ) ), spu_mul( quat0->x, quat1->y ) ), spu_mul( quat0->y, quat1->x ) ); tmpZ = spu_sub( spu_add( spu_add( spu_mul( quat0->w, quat1->z ), spu_mul( quat0->z, quat1->w ) ), spu_mul( quat0->x, quat1->y ) ), spu_mul( quat0->y, quat1->x ) );
tmpW = spu_sub( spu_sub( spu_sub( spu_mul( quat0->w, quat1->w ), spu_mul( quat0->x, quat1->x ) ), spu_mul( quat0->y, quat1->y ) ), spu_mul( quat0->z, quat1->z ) ); tmpW = spu_sub( spu_sub( spu_sub( spu_mul( quat0->w, quat1->w ), spu_mul( quat0->x, quat1->x ) ), spu_mul( quat0->y, quat1->y ) ), spu_mul( quat0->z, quat1->z ) );
vmathSoaQMakeFromElems( result, tmpX, tmpY, tmpZ, tmpW ); vmathSoaQMakeFromElems( result, tmpX, tmpY, tmpZ, tmpW );
} }
static inline void vmathSoaQRotate( VmathSoaVector3 *result, const VmathSoaQuat *quat, const VmathSoaVector3 *vec ) static inline void vmathSoaQRotate( VmathSoaVector3 *result, const VmathSoaQuat *quat, const VmathSoaVector3 *vec )
{ {
vec_float4 tmpX, tmpY, tmpZ, tmpW; vec_float4 tmpX, tmpY, tmpZ, tmpW;
tmpX = spu_sub( spu_add( spu_mul( quat->w, vec->x ), spu_mul( quat->y, vec->z ) ), spu_mul( quat->z, vec->y ) ); tmpX = spu_sub( spu_add( spu_mul( quat->w, vec->x ), spu_mul( quat->y, vec->z ) ), spu_mul( quat->z, vec->y ) );
tmpY = spu_sub( spu_add( spu_mul( quat->w, vec->y ), spu_mul( quat->z, vec->x ) ), spu_mul( quat->x, vec->z ) ); tmpY = spu_sub( spu_add( spu_mul( quat->w, vec->y ), spu_mul( quat->z, vec->x ) ), spu_mul( quat->x, vec->z ) );
tmpZ = spu_sub( spu_add( spu_mul( quat->w, vec->z ), spu_mul( quat->x, vec->y ) ), spu_mul( quat->y, vec->x ) ); tmpZ = spu_sub( spu_add( spu_mul( quat->w, vec->z ), spu_mul( quat->x, vec->y ) ), spu_mul( quat->y, vec->x ) );
tmpW = spu_add( spu_add( spu_mul( quat->x, vec->x ), spu_mul( quat->y, vec->y ) ), spu_mul( quat->z, vec->z ) ); tmpW = spu_add( spu_add( spu_mul( quat->x, vec->x ), spu_mul( quat->y, vec->y ) ), spu_mul( quat->z, vec->z ) );
result->x = spu_add( spu_sub( spu_add( spu_mul( tmpW, quat->x ), spu_mul( tmpX, quat->w ) ), spu_mul( tmpY, quat->z ) ), spu_mul( tmpZ, quat->y ) ); result->x = spu_add( spu_sub( spu_add( spu_mul( tmpW, quat->x ), spu_mul( tmpX, quat->w ) ), spu_mul( tmpY, quat->z ) ), spu_mul( tmpZ, quat->y ) );
result->y = spu_add( spu_sub( spu_add( spu_mul( tmpW, quat->y ), spu_mul( tmpY, quat->w ) ), spu_mul( tmpZ, quat->x ) ), spu_mul( tmpX, quat->z ) ); result->y = spu_add( spu_sub( spu_add( spu_mul( tmpW, quat->y ), spu_mul( tmpY, quat->w ) ), spu_mul( tmpZ, quat->x ) ), spu_mul( tmpX, quat->z ) );
result->z = spu_add( spu_sub( spu_add( spu_mul( tmpW, quat->z ), spu_mul( tmpZ, quat->w ) ), spu_mul( tmpX, quat->y ) ), spu_mul( tmpY, quat->x ) ); result->z = spu_add( spu_sub( spu_add( spu_mul( tmpW, quat->z ), spu_mul( tmpZ, quat->w ) ), spu_mul( tmpX, quat->y ) ), spu_mul( tmpY, quat->x ) );
} }
static inline void vmathSoaQConj( VmathSoaQuat *result, const VmathSoaQuat *quat ) static inline void vmathSoaQConj( VmathSoaQuat *result, const VmathSoaQuat *quat )
{ {
vmathSoaQMakeFromElems( result, negatef4( quat->x ), negatef4( quat->y ), negatef4( quat->z ), quat->w ); vmathSoaQMakeFromElems( result, negatef4( quat->x ), negatef4( quat->y ), negatef4( quat->z ), quat->w );
} }
static inline void vmathSoaQSelect( VmathSoaQuat *result, const VmathSoaQuat *quat0, const VmathSoaQuat *quat1, vec_uint4 select1 ) static inline void vmathSoaQSelect( VmathSoaQuat *result, const VmathSoaQuat *quat0, const VmathSoaQuat *quat1, vec_uint4 select1 )
{ {
result->x = spu_sel( quat0->x, quat1->x, select1 ); result->x = spu_sel( quat0->x, quat1->x, select1 );
result->y = spu_sel( quat0->y, quat1->y, select1 ); result->y = spu_sel( quat0->y, quat1->y, select1 );
result->z = spu_sel( quat0->z, quat1->z, select1 ); result->z = spu_sel( quat0->z, quat1->z, select1 );
result->w = spu_sel( quat0->w, quat1->w, select1 ); result->w = spu_sel( quat0->w, quat1->w, select1 );
} }
#ifdef _VECTORMATH_DEBUG #ifdef _VECTORMATH_DEBUG
static inline void vmathSoaQPrint( const VmathSoaQuat *quat ) static inline void vmathSoaQPrint( const VmathSoaQuat *quat )
{ {
VmathQuat vec0, vec1, vec2, vec3; VmathQuat vec0, vec1, vec2, vec3;
vmathSoaQGet4Aos( quat, &vec0, &vec1, &vec2, &vec3 ); vmathSoaQGet4Aos( quat, &vec0, &vec1, &vec2, &vec3 );
printf("slot 0:\n"); printf("slot 0:\n");
vmathQPrint( &vec0 ); vmathQPrint( &vec0 );
printf("slot 1:\n"); printf("slot 1:\n");
vmathQPrint( &vec1 ); vmathQPrint( &vec1 );
printf("slot 2:\n"); printf("slot 2:\n");
vmathQPrint( &vec2 ); vmathQPrint( &vec2 );
printf("slot 3:\n"); printf("slot 3:\n");
vmathQPrint( &vec3 ); vmathQPrint( &vec3 );
} }
static inline void vmathSoaQPrints( const VmathSoaQuat *quat, const char *name ) static inline void vmathSoaQPrints( const VmathSoaQuat *quat, const char *name )
{ {
VmathQuat vec0, vec1, vec2, vec3; VmathQuat vec0, vec1, vec2, vec3;
printf( "%s:\n", name ); printf( "%s:\n", name );
vmathSoaQGet4Aos( quat, &vec0, &vec1, &vec2, &vec3 ); vmathSoaQGet4Aos( quat, &vec0, &vec1, &vec2, &vec3 );
printf("slot 0:\n"); printf("slot 0:\n");
vmathQPrint( &vec0 ); vmathQPrint( &vec0 );
printf("slot 1:\n"); printf("slot 1:\n");
vmathQPrint( &vec1 ); vmathQPrint( &vec1 );
printf("slot 2:\n"); printf("slot 2:\n");
vmathQPrint( &vec2 ); vmathQPrint( &vec2 );
printf("slot 3:\n"); printf("slot 3:\n");
vmathQPrint( &vec3 ); vmathQPrint( &vec3 );
} }
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif #endif

View File

@@ -1,319 +1,319 @@
/* /*
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc. Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the with or without modification, are permitted provided that the
following conditions are met: following conditions are met:
* Redistributions of source code must retain the above copyright * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright * Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names * Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission. from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef _VECTORMATH_QUAT_SOA_V_C_H #ifndef _VECTORMATH_QUAT_SOA_V_C_H
#define _VECTORMATH_QUAT_SOA_V_C_H #define _VECTORMATH_QUAT_SOA_V_C_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
/*----------------------------------------------------------------------------- /*-----------------------------------------------------------------------------
* Definitions * Definitions
*/ */
#ifndef _VECTORMATH_INTERNAL_FUNCTIONS #ifndef _VECTORMATH_INTERNAL_FUNCTIONS
#define _VECTORMATH_INTERNAL_FUNCTIONS #define _VECTORMATH_INTERNAL_FUNCTIONS
#endif #endif
static inline VmathSoaQuat vmathSoaQMakeFromElems_V( vec_float4 _x, vec_float4 _y, vec_float4 _z, vec_float4 _w ) static inline VmathSoaQuat vmathSoaQMakeFromElems_V( vec_float4 _x, vec_float4 _y, vec_float4 _z, vec_float4 _w )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQMakeFromElems(&result, _x, _y, _z, _w); vmathSoaQMakeFromElems(&result, _x, _y, _z, _w);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQMakeFromV3Scalar_V( VmathSoaVector3 xyz, vec_float4 _w ) static inline VmathSoaQuat vmathSoaQMakeFromV3Scalar_V( VmathSoaVector3 xyz, vec_float4 _w )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQMakeFromV3Scalar(&result, &xyz, _w); vmathSoaQMakeFromV3Scalar(&result, &xyz, _w);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQMakeFromV4_V( VmathSoaVector4 vec ) static inline VmathSoaQuat vmathSoaQMakeFromV4_V( VmathSoaVector4 vec )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQMakeFromV4(&result, &vec); vmathSoaQMakeFromV4(&result, &vec);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQMakeFromScalar_V( vec_float4 scalar ) static inline VmathSoaQuat vmathSoaQMakeFromScalar_V( vec_float4 scalar )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQMakeFromScalar(&result, scalar); vmathSoaQMakeFromScalar(&result, scalar);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQMakeFromAos_V( VmathQuat quat ) static inline VmathSoaQuat vmathSoaQMakeFromAos_V( VmathQuat quat )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQMakeFromAos(&result, &quat); vmathSoaQMakeFromAos(&result, &quat);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQMakeFrom4Aos_V( VmathQuat quat0, VmathQuat quat1, VmathQuat quat2, VmathQuat quat3 ) static inline VmathSoaQuat vmathSoaQMakeFrom4Aos_V( VmathQuat quat0, VmathQuat quat1, VmathQuat quat2, VmathQuat quat3 )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQMakeFrom4Aos(&result, &quat0, &quat1, &quat2, &quat3); vmathSoaQMakeFrom4Aos(&result, &quat0, &quat1, &quat2, &quat3);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQMakeIdentity_V( ) static inline VmathSoaQuat vmathSoaQMakeIdentity_V( )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQMakeIdentity(&result); vmathSoaQMakeIdentity(&result);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQLerp_V( vec_float4 t, VmathSoaQuat quat0, VmathSoaQuat quat1 ) static inline VmathSoaQuat vmathSoaQLerp_V( vec_float4 t, VmathSoaQuat quat0, VmathSoaQuat quat1 )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQLerp(&result, t, &quat0, &quat1); vmathSoaQLerp(&result, t, &quat0, &quat1);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQSlerp_V( vec_float4 t, VmathSoaQuat unitQuat0, VmathSoaQuat unitQuat1 ) static inline VmathSoaQuat vmathSoaQSlerp_V( vec_float4 t, VmathSoaQuat unitQuat0, VmathSoaQuat unitQuat1 )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQSlerp(&result, t, &unitQuat0, &unitQuat1); vmathSoaQSlerp(&result, t, &unitQuat0, &unitQuat1);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQSquad_V( vec_float4 t, VmathSoaQuat unitQuat0, VmathSoaQuat unitQuat1, VmathSoaQuat unitQuat2, VmathSoaQuat unitQuat3 ) static inline VmathSoaQuat vmathSoaQSquad_V( vec_float4 t, VmathSoaQuat unitQuat0, VmathSoaQuat unitQuat1, VmathSoaQuat unitQuat2, VmathSoaQuat unitQuat3 )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQSquad(&result, t, &unitQuat0, &unitQuat1, &unitQuat2, &unitQuat3); vmathSoaQSquad(&result, t, &unitQuat0, &unitQuat1, &unitQuat2, &unitQuat3);
return result; return result;
} }
static inline void vmathSoaQGet4Aos_V( VmathSoaQuat quat, VmathQuat *result0, VmathQuat *result1, VmathQuat *result2, VmathQuat *result3 ) static inline void vmathSoaQGet4Aos_V( VmathSoaQuat quat, VmathQuat *result0, VmathQuat *result1, VmathQuat *result2, VmathQuat *result3 )
{ {
vmathSoaQGet4Aos(&quat, result0, result1, result2, result3); vmathSoaQGet4Aos(&quat, result0, result1, result2, result3);
} }
static inline void vmathSoaQSetXYZ_V( VmathSoaQuat *result, VmathSoaVector3 vec ) static inline void vmathSoaQSetXYZ_V( VmathSoaQuat *result, VmathSoaVector3 vec )
{ {
vmathSoaQSetXYZ(result, &vec); vmathSoaQSetXYZ(result, &vec);
} }
static inline VmathSoaVector3 vmathSoaQGetXYZ_V( VmathSoaQuat quat ) static inline VmathSoaVector3 vmathSoaQGetXYZ_V( VmathSoaQuat quat )
{ {
VmathSoaVector3 result; VmathSoaVector3 result;
vmathSoaQGetXYZ(&result, &quat); vmathSoaQGetXYZ(&result, &quat);
return result; return result;
} }
static inline void vmathSoaQSetX_V( VmathSoaQuat *result, vec_float4 _x ) static inline void vmathSoaQSetX_V( VmathSoaQuat *result, vec_float4 _x )
{ {
vmathSoaQSetX(result, _x); vmathSoaQSetX(result, _x);
} }
static inline vec_float4 vmathSoaQGetX_V( VmathSoaQuat quat ) static inline vec_float4 vmathSoaQGetX_V( VmathSoaQuat quat )
{ {
return vmathSoaQGetX(&quat); return vmathSoaQGetX(&quat);
} }
static inline void vmathSoaQSetY_V( VmathSoaQuat *result, vec_float4 _y ) static inline void vmathSoaQSetY_V( VmathSoaQuat *result, vec_float4 _y )
{ {
vmathSoaQSetY(result, _y); vmathSoaQSetY(result, _y);
} }
static inline vec_float4 vmathSoaQGetY_V( VmathSoaQuat quat ) static inline vec_float4 vmathSoaQGetY_V( VmathSoaQuat quat )
{ {
return vmathSoaQGetY(&quat); return vmathSoaQGetY(&quat);
} }
static inline void vmathSoaQSetZ_V( VmathSoaQuat *result, vec_float4 _z ) static inline void vmathSoaQSetZ_V( VmathSoaQuat *result, vec_float4 _z )
{ {
vmathSoaQSetZ(result, _z); vmathSoaQSetZ(result, _z);
} }
static inline vec_float4 vmathSoaQGetZ_V( VmathSoaQuat quat ) static inline vec_float4 vmathSoaQGetZ_V( VmathSoaQuat quat )
{ {
return vmathSoaQGetZ(&quat); return vmathSoaQGetZ(&quat);
} }
static inline void vmathSoaQSetW_V( VmathSoaQuat *result, vec_float4 _w ) static inline void vmathSoaQSetW_V( VmathSoaQuat *result, vec_float4 _w )
{ {
vmathSoaQSetW(result, _w); vmathSoaQSetW(result, _w);
} }
static inline vec_float4 vmathSoaQGetW_V( VmathSoaQuat quat ) static inline vec_float4 vmathSoaQGetW_V( VmathSoaQuat quat )
{ {
return vmathSoaQGetW(&quat); return vmathSoaQGetW(&quat);
} }
static inline void vmathSoaQSetElem_V( VmathSoaQuat *result, int idx, vec_float4 value ) static inline void vmathSoaQSetElem_V( VmathSoaQuat *result, int idx, vec_float4 value )
{ {
vmathSoaQSetElem(result, idx, value); vmathSoaQSetElem(result, idx, value);
} }
static inline vec_float4 vmathSoaQGetElem_V( VmathSoaQuat quat, int idx ) static inline vec_float4 vmathSoaQGetElem_V( VmathSoaQuat quat, int idx )
{ {
return vmathSoaQGetElem(&quat, idx); return vmathSoaQGetElem(&quat, idx);
} }
static inline VmathSoaQuat vmathSoaQAdd_V( VmathSoaQuat quat0, VmathSoaQuat quat1 ) static inline VmathSoaQuat vmathSoaQAdd_V( VmathSoaQuat quat0, VmathSoaQuat quat1 )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQAdd(&result, &quat0, &quat1); vmathSoaQAdd(&result, &quat0, &quat1);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQSub_V( VmathSoaQuat quat0, VmathSoaQuat quat1 ) static inline VmathSoaQuat vmathSoaQSub_V( VmathSoaQuat quat0, VmathSoaQuat quat1 )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQSub(&result, &quat0, &quat1); vmathSoaQSub(&result, &quat0, &quat1);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQScalarMul_V( VmathSoaQuat quat, vec_float4 scalar ) static inline VmathSoaQuat vmathSoaQScalarMul_V( VmathSoaQuat quat, vec_float4 scalar )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQScalarMul(&result, &quat, scalar); vmathSoaQScalarMul(&result, &quat, scalar);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQScalarDiv_V( VmathSoaQuat quat, vec_float4 scalar ) static inline VmathSoaQuat vmathSoaQScalarDiv_V( VmathSoaQuat quat, vec_float4 scalar )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQScalarDiv(&result, &quat, scalar); vmathSoaQScalarDiv(&result, &quat, scalar);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQNeg_V( VmathSoaQuat quat ) static inline VmathSoaQuat vmathSoaQNeg_V( VmathSoaQuat quat )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQNeg(&result, &quat); vmathSoaQNeg(&result, &quat);
return result; return result;
} }
static inline vec_float4 vmathSoaQDot_V( VmathSoaQuat quat0, VmathSoaQuat quat1 ) static inline vec_float4 vmathSoaQDot_V( VmathSoaQuat quat0, VmathSoaQuat quat1 )
{ {
return vmathSoaQDot(&quat0, &quat1); return vmathSoaQDot(&quat0, &quat1);
} }
static inline vec_float4 vmathSoaQNorm_V( VmathSoaQuat quat ) static inline vec_float4 vmathSoaQNorm_V( VmathSoaQuat quat )
{ {
return vmathSoaQNorm(&quat); return vmathSoaQNorm(&quat);
} }
static inline vec_float4 vmathSoaQLength_V( VmathSoaQuat quat ) static inline vec_float4 vmathSoaQLength_V( VmathSoaQuat quat )
{ {
return vmathSoaQLength(&quat); return vmathSoaQLength(&quat);
} }
static inline VmathSoaQuat vmathSoaQNormalize_V( VmathSoaQuat quat ) static inline VmathSoaQuat vmathSoaQNormalize_V( VmathSoaQuat quat )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQNormalize(&result, &quat); vmathSoaQNormalize(&result, &quat);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQMakeRotationArc_V( VmathSoaVector3 unitVec0, VmathSoaVector3 unitVec1 ) static inline VmathSoaQuat vmathSoaQMakeRotationArc_V( VmathSoaVector3 unitVec0, VmathSoaVector3 unitVec1 )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQMakeRotationArc(&result, &unitVec0, &unitVec1); vmathSoaQMakeRotationArc(&result, &unitVec0, &unitVec1);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQMakeRotationAxis_V( vec_float4 radians, VmathSoaVector3 unitVec ) static inline VmathSoaQuat vmathSoaQMakeRotationAxis_V( vec_float4 radians, VmathSoaVector3 unitVec )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQMakeRotationAxis(&result, radians, &unitVec); vmathSoaQMakeRotationAxis(&result, radians, &unitVec);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQMakeRotationX_V( vec_float4 radians ) static inline VmathSoaQuat vmathSoaQMakeRotationX_V( vec_float4 radians )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQMakeRotationX(&result, radians); vmathSoaQMakeRotationX(&result, radians);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQMakeRotationY_V( vec_float4 radians ) static inline VmathSoaQuat vmathSoaQMakeRotationY_V( vec_float4 radians )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQMakeRotationY(&result, radians); vmathSoaQMakeRotationY(&result, radians);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQMakeRotationZ_V( vec_float4 radians ) static inline VmathSoaQuat vmathSoaQMakeRotationZ_V( vec_float4 radians )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQMakeRotationZ(&result, radians); vmathSoaQMakeRotationZ(&result, radians);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQMul_V( VmathSoaQuat quat0, VmathSoaQuat quat1 ) static inline VmathSoaQuat vmathSoaQMul_V( VmathSoaQuat quat0, VmathSoaQuat quat1 )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQMul(&result, &quat0, &quat1); vmathSoaQMul(&result, &quat0, &quat1);
return result; return result;
} }
static inline VmathSoaVector3 vmathSoaQRotate_V( VmathSoaQuat quat, VmathSoaVector3 vec ) static inline VmathSoaVector3 vmathSoaQRotate_V( VmathSoaQuat quat, VmathSoaVector3 vec )
{ {
VmathSoaVector3 result; VmathSoaVector3 result;
vmathSoaQRotate(&result, &quat, &vec); vmathSoaQRotate(&result, &quat, &vec);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQConj_V( VmathSoaQuat quat ) static inline VmathSoaQuat vmathSoaQConj_V( VmathSoaQuat quat )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQConj(&result, &quat); vmathSoaQConj(&result, &quat);
return result; return result;
} }
static inline VmathSoaQuat vmathSoaQSelect_V( VmathSoaQuat quat0, VmathSoaQuat quat1, vec_uint4 select1 ) static inline VmathSoaQuat vmathSoaQSelect_V( VmathSoaQuat quat0, VmathSoaQuat quat1, vec_uint4 select1 )
{ {
VmathSoaQuat result; VmathSoaQuat result;
vmathSoaQSelect(&result, &quat0, &quat1, select1); vmathSoaQSelect(&result, &quat0, &quat1, select1);
return result; return result;
} }
#ifdef _VECTORMATH_DEBUG #ifdef _VECTORMATH_DEBUG
static inline void vmathSoaQPrint_V( VmathSoaQuat quat ) static inline void vmathSoaQPrint_V( VmathSoaQuat quat )
{ {
vmathSoaQPrint(&quat); vmathSoaQPrint(&quat);
} }
static inline void vmathSoaQPrints_V( VmathSoaQuat quat, const char *name ) static inline void vmathSoaQPrints_V( VmathSoaQuat quat, const char *name )
{ {
vmathSoaQPrints(&quat, name); vmathSoaQPrints(&quat, name);
} }
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif #endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,246 +1,246 @@
/* /*
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc. Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the with or without modification, are permitted provided that the
following conditions are met: following conditions are met:
* Redistributions of source code must retain the above copyright * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright * Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names * Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission. from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef _BOOLINVEC_H #ifndef _BOOLINVEC_H
#define _BOOLINVEC_H #define _BOOLINVEC_H
#include <spu_intrinsics.h> #include <spu_intrinsics.h>
namespace Vectormath { namespace Vectormath {
class floatInVec; class floatInVec;
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// boolInVec class // boolInVec class
// //
class boolInVec class boolInVec
{ {
private: private:
vec_uint4 mData; vec_uint4 mData;
inline boolInVec(vec_uint4 vec); inline boolInVec(vec_uint4 vec);
public: public:
inline boolInVec() {} inline boolInVec() {}
// matches standard type conversions // matches standard type conversions
// //
inline boolInVec(floatInVec vec); inline boolInVec(floatInVec vec);
// explicit cast from bool // explicit cast from bool
// //
explicit inline boolInVec(bool scalar); explicit inline boolInVec(bool scalar);
#ifdef _VECTORMATH_NO_SCALAR_CAST #ifdef _VECTORMATH_NO_SCALAR_CAST
// explicit cast to bool // explicit cast to bool
// //
inline bool getAsBool() const; inline bool getAsBool() const;
#else #else
// implicit cast to bool // implicit cast to bool
// //
inline operator bool() const; inline operator bool() const;
#endif #endif
// get vector data // get vector data
// bool value is in the 0 word slot of vector as 0 (false) or -1 (true) // bool value is in the 0 word slot of vector as 0 (false) or -1 (true)
// //
inline vec_uint4 get128() const; inline vec_uint4 get128() const;
// operators // operators
// //
inline const boolInVec operator ! () const; inline const boolInVec operator ! () const;
inline boolInVec& operator = (boolInVec vec); inline boolInVec& operator = (boolInVec vec);
inline boolInVec& operator &= (boolInVec vec); inline boolInVec& operator &= (boolInVec vec);
inline boolInVec& operator ^= (boolInVec vec); inline boolInVec& operator ^= (boolInVec vec);
inline boolInVec& operator |= (boolInVec vec); inline boolInVec& operator |= (boolInVec vec);
// friend functions // friend functions
// //
friend inline const boolInVec operator == (boolInVec vec0, boolInVec vec1); friend inline const boolInVec operator == (boolInVec vec0, boolInVec vec1);
friend inline const boolInVec operator != (boolInVec vec0, boolInVec vec1); friend inline const boolInVec operator != (boolInVec vec0, boolInVec vec1);
friend inline const boolInVec operator < (floatInVec vec0, floatInVec vec1); friend inline const boolInVec operator < (floatInVec vec0, floatInVec vec1);
friend inline const boolInVec operator <= (floatInVec vec0, floatInVec vec1); friend inline const boolInVec operator <= (floatInVec vec0, floatInVec vec1);
friend inline const boolInVec operator > (floatInVec vec0, floatInVec vec1); friend inline const boolInVec operator > (floatInVec vec0, floatInVec vec1);
friend inline const boolInVec operator >= (floatInVec vec0, floatInVec vec1); friend inline const boolInVec operator >= (floatInVec vec0, floatInVec vec1);
friend inline const boolInVec operator == (floatInVec vec0, floatInVec vec1); friend inline const boolInVec operator == (floatInVec vec0, floatInVec vec1);
friend inline const boolInVec operator != (floatInVec vec0, floatInVec vec1); friend inline const boolInVec operator != (floatInVec vec0, floatInVec vec1);
friend inline const boolInVec operator & (boolInVec vec0, boolInVec vec1); friend inline const boolInVec operator & (boolInVec vec0, boolInVec vec1);
friend inline const boolInVec operator ^ (boolInVec vec0, boolInVec vec1); friend inline const boolInVec operator ^ (boolInVec vec0, boolInVec vec1);
friend inline const boolInVec operator | (boolInVec vec0, boolInVec vec1); friend inline const boolInVec operator | (boolInVec vec0, boolInVec vec1);
friend inline const boolInVec select(boolInVec vec0, boolInVec vec1, boolInVec select_vec1); friend inline const boolInVec select(boolInVec vec0, boolInVec vec1, boolInVec select_vec1);
}; };
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// boolInVec functions // boolInVec functions
// //
// operators // operators
// //
inline const boolInVec operator == (boolInVec vec0, boolInVec vec1); inline const boolInVec operator == (boolInVec vec0, boolInVec vec1);
inline const boolInVec operator != (boolInVec vec0, boolInVec vec1); inline const boolInVec operator != (boolInVec vec0, boolInVec vec1);
inline const boolInVec operator & (boolInVec vec0, boolInVec vec1); inline const boolInVec operator & (boolInVec vec0, boolInVec vec1);
inline const boolInVec operator ^ (boolInVec vec0, boolInVec vec1); inline const boolInVec operator ^ (boolInVec vec0, boolInVec vec1);
inline const boolInVec operator | (boolInVec vec0, boolInVec vec1); inline const boolInVec operator | (boolInVec vec0, boolInVec vec1);
// select between vec0 and vec1 using boolInVec. // select between vec0 and vec1 using boolInVec.
// false selects vec0, true selects vec1 // false selects vec0, true selects vec1
// //
inline const boolInVec select(boolInVec vec0, boolInVec vec1, boolInVec select_vec1); inline const boolInVec select(boolInVec vec0, boolInVec vec1, boolInVec select_vec1);
} // namespace Vectormath } // namespace Vectormath
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// boolInVec implementation // boolInVec implementation
// //
#include "floatInVec.h" #include "floatInVec.h"
namespace Vectormath { namespace Vectormath {
inline inline
boolInVec::boolInVec(vec_uint4 vec) boolInVec::boolInVec(vec_uint4 vec)
{ {
mData = vec; mData = vec;
} }
inline inline
boolInVec::boolInVec(floatInVec vec) boolInVec::boolInVec(floatInVec vec)
{ {
*this = (vec != floatInVec(0.0f)); *this = (vec != floatInVec(0.0f));
} }
inline inline
boolInVec::boolInVec(bool scalar) boolInVec::boolInVec(bool scalar)
{ {
mData = spu_promote((unsigned int)-scalar, 0); mData = spu_promote((unsigned int)-scalar, 0);
} }
#ifdef _VECTORMATH_NO_SCALAR_CAST #ifdef _VECTORMATH_NO_SCALAR_CAST
inline inline
bool bool
boolInVec::getAsBool() const boolInVec::getAsBool() const
#else #else
inline inline
boolInVec::operator bool() const boolInVec::operator bool() const
#endif #endif
{ {
return (bool)spu_extract(mData, 0); return (bool)spu_extract(mData, 0);
} }
inline inline
vec_uint4 vec_uint4
boolInVec::get128() const boolInVec::get128() const
{ {
return mData; return mData;
} }
inline inline
const boolInVec const boolInVec
boolInVec::operator ! () const boolInVec::operator ! () const
{ {
return boolInVec(spu_nor(mData, mData)); return boolInVec(spu_nor(mData, mData));
} }
inline inline
boolInVec& boolInVec&
boolInVec::operator = (boolInVec vec) boolInVec::operator = (boolInVec vec)
{ {
mData = vec.mData; mData = vec.mData;
return *this; return *this;
} }
inline inline
boolInVec& boolInVec&
boolInVec::operator &= (boolInVec vec) boolInVec::operator &= (boolInVec vec)
{ {
*this = *this & vec; *this = *this & vec;
return *this; return *this;
} }
inline inline
boolInVec& boolInVec&
boolInVec::operator ^= (boolInVec vec) boolInVec::operator ^= (boolInVec vec)
{ {
*this = *this ^ vec; *this = *this ^ vec;
return *this; return *this;
} }
inline inline
boolInVec& boolInVec&
boolInVec::operator |= (boolInVec vec) boolInVec::operator |= (boolInVec vec)
{ {
*this = *this | vec; *this = *this | vec;
return *this; return *this;
} }
inline inline
const boolInVec const boolInVec
operator == (boolInVec vec0, boolInVec vec1) operator == (boolInVec vec0, boolInVec vec1)
{ {
return boolInVec(spu_cmpeq(vec0.get128(), vec1.get128())); return boolInVec(spu_cmpeq(vec0.get128(), vec1.get128()));
} }
inline inline
const boolInVec const boolInVec
operator != (boolInVec vec0, boolInVec vec1) operator != (boolInVec vec0, boolInVec vec1)
{ {
return !(vec0 == vec1); return !(vec0 == vec1);
} }
inline inline
const boolInVec const boolInVec
operator & (boolInVec vec0, boolInVec vec1) operator & (boolInVec vec0, boolInVec vec1)
{ {
return boolInVec(spu_and(vec0.get128(), vec1.get128())); return boolInVec(spu_and(vec0.get128(), vec1.get128()));
} }
inline inline
const boolInVec const boolInVec
operator | (boolInVec vec0, boolInVec vec1) operator | (boolInVec vec0, boolInVec vec1)
{ {
return boolInVec(spu_or(vec0.get128(), vec1.get128())); return boolInVec(spu_or(vec0.get128(), vec1.get128()));
} }
inline inline
const boolInVec const boolInVec
operator ^ (boolInVec vec0, boolInVec vec1) operator ^ (boolInVec vec0, boolInVec vec1)
{ {
return boolInVec(spu_xor(vec0.get128(), vec1.get128())); return boolInVec(spu_xor(vec0.get128(), vec1.get128()));
} }
inline inline
const boolInVec const boolInVec
select(boolInVec vec0, boolInVec vec1, boolInVec select_vec1) select(boolInVec vec0, boolInVec vec1, boolInVec select_vec1)
{ {
return boolInVec(spu_sel(vec0.get128(), vec1.get128(), select_vec1.get128())); return boolInVec(spu_sel(vec0.get128(), vec1.get128(), select_vec1.get128()));
} }
} // namespace Vectormath } // namespace Vectormath
#endif // boolInVec_h #endif // boolInVec_h

View File

@@ -1,339 +1,339 @@
/* /*
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc. Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the with or without modification, are permitted provided that the
following conditions are met: following conditions are met:
* Redistributions of source code must retain the above copyright * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright * Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names * Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission. from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef _FLOATINVEC_H #ifndef _FLOATINVEC_H
#define _FLOATINVEC_H #define _FLOATINVEC_H
#include <math.h> #include <math.h>
#include <spu_intrinsics.h> #include <spu_intrinsics.h>
#include <simdmath.h> #include <simdmath.h>
#undef bool #undef bool
namespace Vectormath { namespace Vectormath {
class boolInVec; class boolInVec;
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// floatInVec class // floatInVec class
// //
class floatInVec class floatInVec
{ {
private: private:
vec_float4 mData; vec_float4 mData;
inline floatInVec(vec_float4 vec); inline floatInVec(vec_float4 vec);
public: public:
inline floatInVec() {} inline floatInVec() {}
// matches standard type conversions // matches standard type conversions
// //
inline floatInVec(boolInVec vec); inline floatInVec(boolInVec vec);
// construct from a slot of vec_float4 // construct from a slot of vec_float4
// //
inline floatInVec(vec_float4 vec, int slot); inline floatInVec(vec_float4 vec, int slot);
// explicit cast from float // explicit cast from float
// //
explicit inline floatInVec(float scalar); explicit inline floatInVec(float scalar);
#ifdef _VECTORMATH_NO_SCALAR_CAST #ifdef _VECTORMATH_NO_SCALAR_CAST
// explicit cast to float // explicit cast to float
// //
inline float getAsFloat() const; inline float getAsFloat() const;
#else #else
// implicit cast to float // implicit cast to float
// //
inline operator float() const; inline operator float() const;
#endif #endif
// get vector data // get vector data
// float value is in 0 word slot of vector // float value is in 0 word slot of vector
// //
inline vec_float4 get128() const; inline vec_float4 get128() const;
// operators // operators
// //
inline const floatInVec operator ++ (int); inline const floatInVec operator ++ (int);
inline const floatInVec operator -- (int); inline const floatInVec operator -- (int);
inline floatInVec& operator ++ (); inline floatInVec& operator ++ ();
inline floatInVec& operator -- (); inline floatInVec& operator -- ();
inline const floatInVec operator - () const; inline const floatInVec operator - () const;
inline floatInVec& operator = (floatInVec vec); inline floatInVec& operator = (floatInVec vec);
inline floatInVec& operator *= (floatInVec vec); inline floatInVec& operator *= (floatInVec vec);
inline floatInVec& operator /= (floatInVec vec); inline floatInVec& operator /= (floatInVec vec);
inline floatInVec& operator += (floatInVec vec); inline floatInVec& operator += (floatInVec vec);
inline floatInVec& operator -= (floatInVec vec); inline floatInVec& operator -= (floatInVec vec);
// friend functions // friend functions
// //
friend inline const floatInVec operator * (floatInVec vec0, floatInVec vec1); friend inline const floatInVec operator * (floatInVec vec0, floatInVec vec1);
friend inline const floatInVec operator / (floatInVec vec0, floatInVec vec1); friend inline const floatInVec operator / (floatInVec vec0, floatInVec vec1);
friend inline const floatInVec operator + (floatInVec vec0, floatInVec vec1); friend inline const floatInVec operator + (floatInVec vec0, floatInVec vec1);
friend inline const floatInVec operator - (floatInVec vec0, floatInVec vec1); friend inline const floatInVec operator - (floatInVec vec0, floatInVec vec1);
friend inline const floatInVec select(floatInVec vec0, floatInVec vec1, boolInVec select_vec1); friend inline const floatInVec select(floatInVec vec0, floatInVec vec1, boolInVec select_vec1);
}; };
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// floatInVec functions // floatInVec functions
// //
// operators // operators
// //
inline const floatInVec operator * (floatInVec vec0, floatInVec vec1); inline const floatInVec operator * (floatInVec vec0, floatInVec vec1);
inline const floatInVec operator / (floatInVec vec0, floatInVec vec1); inline const floatInVec operator / (floatInVec vec0, floatInVec vec1);
inline const floatInVec operator + (floatInVec vec0, floatInVec vec1); inline const floatInVec operator + (floatInVec vec0, floatInVec vec1);
inline const floatInVec operator - (floatInVec vec0, floatInVec vec1); inline const floatInVec operator - (floatInVec vec0, floatInVec vec1);
inline const boolInVec operator < (floatInVec vec0, floatInVec vec1); inline const boolInVec operator < (floatInVec vec0, floatInVec vec1);
inline const boolInVec operator <= (floatInVec vec0, floatInVec vec1); inline const boolInVec operator <= (floatInVec vec0, floatInVec vec1);
inline const boolInVec operator > (floatInVec vec0, floatInVec vec1); inline const boolInVec operator > (floatInVec vec0, floatInVec vec1);
inline const boolInVec operator >= (floatInVec vec0, floatInVec vec1); inline const boolInVec operator >= (floatInVec vec0, floatInVec vec1);
inline const boolInVec operator == (floatInVec vec0, floatInVec vec1); inline const boolInVec operator == (floatInVec vec0, floatInVec vec1);
inline const boolInVec operator != (floatInVec vec0, floatInVec vec1); inline const boolInVec operator != (floatInVec vec0, floatInVec vec1);
// select between vec0 and vec1 using boolInVec. // select between vec0 and vec1 using boolInVec.
// false selects vec0, true selects vec1 // false selects vec0, true selects vec1
// //
inline const floatInVec select(floatInVec vec0, floatInVec vec1, boolInVec select_vec1); inline const floatInVec select(floatInVec vec0, floatInVec vec1, boolInVec select_vec1);
} // namespace Vectormath } // namespace Vectormath
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// floatInVec implementation // floatInVec implementation
// //
#include "boolInVec.h" #include "boolInVec.h"
namespace Vectormath { namespace Vectormath {
inline inline
floatInVec::floatInVec(vec_float4 vec) floatInVec::floatInVec(vec_float4 vec)
{ {
mData = vec; mData = vec;
} }
inline inline
floatInVec::floatInVec(boolInVec vec) floatInVec::floatInVec(boolInVec vec)
{ {
mData = spu_sel(spu_splats(0.0f), spu_splats(1.0f), vec.get128()); mData = spu_sel(spu_splats(0.0f), spu_splats(1.0f), vec.get128());
} }
inline inline
floatInVec::floatInVec(vec_float4 vec, int slot) floatInVec::floatInVec(vec_float4 vec, int slot)
{ {
mData = spu_promote(spu_extract(vec, slot), 0); mData = spu_promote(spu_extract(vec, slot), 0);
} }
inline inline
floatInVec::floatInVec(float scalar) floatInVec::floatInVec(float scalar)
{ {
mData = spu_promote(scalar, 0); mData = spu_promote(scalar, 0);
} }
#ifdef _VECTORMATH_NO_SCALAR_CAST #ifdef _VECTORMATH_NO_SCALAR_CAST
inline inline
float float
floatInVec::getAsFloat() const floatInVec::getAsFloat() const
#else #else
inline inline
floatInVec::operator float() const floatInVec::operator float() const
#endif #endif
{ {
return spu_extract(mData,0); return spu_extract(mData,0);
} }
inline inline
vec_float4 vec_float4
floatInVec::get128() const floatInVec::get128() const
{ {
return mData; return mData;
} }
inline inline
const floatInVec const floatInVec
floatInVec::operator ++ (int) floatInVec::operator ++ (int)
{ {
vec_float4 olddata = mData; vec_float4 olddata = mData;
operator ++(); operator ++();
return floatInVec(olddata); return floatInVec(olddata);
} }
inline inline
const floatInVec const floatInVec
floatInVec::operator -- (int) floatInVec::operator -- (int)
{ {
vec_float4 olddata = mData; vec_float4 olddata = mData;
operator --(); operator --();
return floatInVec(olddata); return floatInVec(olddata);
} }
inline inline
floatInVec& floatInVec&
floatInVec::operator ++ () floatInVec::operator ++ ()
{ {
*this += floatInVec(1.0f); *this += floatInVec(1.0f);
return *this; return *this;
} }
inline inline
floatInVec& floatInVec&
floatInVec::operator -- () floatInVec::operator -- ()
{ {
*this -= floatInVec(1.0f); *this -= floatInVec(1.0f);
return *this; return *this;
} }
inline inline
const floatInVec const floatInVec
floatInVec::operator - () const floatInVec::operator - () const
{ {
return floatInVec((vec_float4)spu_xor((vec_uint4)mData, spu_splats(0x80000000))); return floatInVec((vec_float4)spu_xor((vec_uint4)mData, spu_splats(0x80000000)));
} }
inline inline
floatInVec& floatInVec&
floatInVec::operator = (floatInVec vec) floatInVec::operator = (floatInVec vec)
{ {
mData = vec.mData; mData = vec.mData;
return *this; return *this;
} }
inline inline
floatInVec& floatInVec&
floatInVec::operator *= (floatInVec vec) floatInVec::operator *= (floatInVec vec)
{ {
*this = *this * vec; *this = *this * vec;
return *this; return *this;
} }
inline inline
floatInVec& floatInVec&
floatInVec::operator /= (floatInVec vec) floatInVec::operator /= (floatInVec vec)
{ {
*this = *this / vec; *this = *this / vec;
return *this; return *this;
} }
inline inline
floatInVec& floatInVec&
floatInVec::operator += (floatInVec vec) floatInVec::operator += (floatInVec vec)
{ {
*this = *this + vec; *this = *this + vec;
return *this; return *this;
} }
inline inline
floatInVec& floatInVec&
floatInVec::operator -= (floatInVec vec) floatInVec::operator -= (floatInVec vec)
{ {
*this = *this - vec; *this = *this - vec;
return *this; return *this;
} }
inline inline
const floatInVec const floatInVec
operator * (floatInVec vec0, floatInVec vec1) operator * (floatInVec vec0, floatInVec vec1)
{ {
return floatInVec(spu_mul(vec0.get128(), vec1.get128())); return floatInVec(spu_mul(vec0.get128(), vec1.get128()));
} }
inline inline
const floatInVec const floatInVec
operator / (floatInVec num, floatInVec den) operator / (floatInVec num, floatInVec den)
{ {
return floatInVec(divf4(num.get128(), den.get128())); return floatInVec(divf4(num.get128(), den.get128()));
} }
inline inline
const floatInVec const floatInVec
operator + (floatInVec vec0, floatInVec vec1) operator + (floatInVec vec0, floatInVec vec1)
{ {
return floatInVec(spu_add(vec0.get128(), vec1.get128())); return floatInVec(spu_add(vec0.get128(), vec1.get128()));
} }
inline inline
const floatInVec const floatInVec
operator - (floatInVec vec0, floatInVec vec1) operator - (floatInVec vec0, floatInVec vec1)
{ {
return floatInVec(spu_sub(vec0.get128(), vec1.get128())); return floatInVec(spu_sub(vec0.get128(), vec1.get128()));
} }
inline inline
const boolInVec const boolInVec
operator < (floatInVec vec0, floatInVec vec1) operator < (floatInVec vec0, floatInVec vec1)
{ {
return boolInVec(spu_cmpgt(vec1.get128(), vec0.get128())); return boolInVec(spu_cmpgt(vec1.get128(), vec0.get128()));
} }
inline inline
const boolInVec const boolInVec
operator <= (floatInVec vec0, floatInVec vec1) operator <= (floatInVec vec0, floatInVec vec1)
{ {
return !(vec0 > vec1); return !(vec0 > vec1);
} }
inline inline
const boolInVec const boolInVec
operator > (floatInVec vec0, floatInVec vec1) operator > (floatInVec vec0, floatInVec vec1)
{ {
return boolInVec(spu_cmpgt(vec0.get128(), vec1.get128())); return boolInVec(spu_cmpgt(vec0.get128(), vec1.get128()));
} }
inline inline
const boolInVec const boolInVec
operator >= (floatInVec vec0, floatInVec vec1) operator >= (floatInVec vec0, floatInVec vec1)
{ {
return !(vec0 < vec1); return !(vec0 < vec1);
} }
inline inline
const boolInVec const boolInVec
operator == (floatInVec vec0, floatInVec vec1) operator == (floatInVec vec0, floatInVec vec1)
{ {
return boolInVec(spu_cmpeq(vec0.get128(), vec1.get128())); return boolInVec(spu_cmpeq(vec0.get128(), vec1.get128()));
} }
inline inline
const boolInVec const boolInVec
operator != (floatInVec vec0, floatInVec vec1) operator != (floatInVec vec0, floatInVec vec1)
{ {
return !(vec0 == vec1); return !(vec0 == vec1);
} }
inline inline
const floatInVec const floatInVec
select(floatInVec vec0, floatInVec vec1, boolInVec select_vec1) select(floatInVec vec0, floatInVec vec1, boolInVec select_vec1)
{ {
return floatInVec(spu_sel(vec0.get128(), vec1.get128(), select_vec1.get128())); return floatInVec(spu_sel(vec0.get128(), vec1.get128(), select_vec1.get128()));
} }
} // namespace Vectormath } // namespace Vectormath
#endif // floatInVec_h #endif // floatInVec_h

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,417 +1,417 @@
/* /*
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc. Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the with or without modification, are permitted provided that the
following conditions are met: following conditions are met:
* Redistributions of source code must retain the above copyright * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright * Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names * Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission. from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef _VECTORMATH_QUAT_AOS_CPP_H #ifndef _VECTORMATH_QUAT_AOS_CPP_H
#define _VECTORMATH_QUAT_AOS_CPP_H #define _VECTORMATH_QUAT_AOS_CPP_H
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Definitions // Definitions
#ifndef _VECTORMATH_INTERNAL_FUNCTIONS #ifndef _VECTORMATH_INTERNAL_FUNCTIONS
#define _VECTORMATH_INTERNAL_FUNCTIONS #define _VECTORMATH_INTERNAL_FUNCTIONS
#endif #endif
namespace Vectormath { namespace Vectormath {
namespace Aos { namespace Aos {
inline Quat::Quat( float _x, float _y, float _z, float _w ) inline Quat::Quat( float _x, float _y, float _z, float _w )
{ {
mVec128 = (vec_float4){ _x, _y, _z, _w }; mVec128 = (vec_float4){ _x, _y, _z, _w };
} }
inline Quat::Quat( Vector3 xyz, float _w ) inline Quat::Quat( Vector3 xyz, float _w )
{ {
mVec128 = spu_shuffle( xyz.get128(), spu_promote( _w, 0 ), _VECTORMATH_SHUF_XYZA ); mVec128 = spu_shuffle( xyz.get128(), spu_promote( _w, 0 ), _VECTORMATH_SHUF_XYZA );
} }
inline Quat::Quat( Vector4 vec ) inline Quat::Quat( Vector4 vec )
{ {
mVec128 = vec.get128(); mVec128 = vec.get128();
} }
inline Quat::Quat( float scalar ) inline Quat::Quat( float scalar )
{ {
mVec128 = spu_splats( scalar ); mVec128 = spu_splats( scalar );
} }
inline Quat::Quat( vec_float4 vf4 ) inline Quat::Quat( vec_float4 vf4 )
{ {
mVec128 = vf4; mVec128 = vf4;
} }
inline const Quat Quat::identity( ) inline const Quat Quat::identity( )
{ {
return Quat( _VECTORMATH_UNIT_0001 ); return Quat( _VECTORMATH_UNIT_0001 );
} }
inline const Quat lerp( float t, Quat quat0, Quat quat1 ) inline const Quat lerp( float t, Quat quat0, Quat quat1 )
{ {
return ( quat0 + ( ( quat1 - quat0 ) * t ) ); return ( quat0 + ( ( quat1 - quat0 ) * t ) );
} }
inline const Quat slerp( float t, Quat unitQuat0, Quat unitQuat1 ) inline const Quat slerp( float t, Quat unitQuat0, Quat unitQuat1 )
{ {
Quat start; Quat start;
vec_float4 scales, scale0, scale1, cosAngle, angle, tttt, oneMinusT, angles, sines; vec_float4 scales, scale0, scale1, cosAngle, angle, tttt, oneMinusT, angles, sines;
vec_uint4 selectMask; vec_uint4 selectMask;
vec_uchar16 shuffle_xxxx = (vec_uchar16)spu_splats((int)0x00010203); vec_uchar16 shuffle_xxxx = (vec_uchar16)spu_splats((int)0x00010203);
vec_uchar16 shuffle_yyyy = (vec_uchar16)spu_splats((int)0x04050607); vec_uchar16 shuffle_yyyy = (vec_uchar16)spu_splats((int)0x04050607);
vec_uchar16 shuffle_zzzz = (vec_uchar16)spu_splats((int)0x08090a0b); vec_uchar16 shuffle_zzzz = (vec_uchar16)spu_splats((int)0x08090a0b);
cosAngle = _vmathVfDot4( unitQuat0.get128(), unitQuat1.get128() ); cosAngle = _vmathVfDot4( unitQuat0.get128(), unitQuat1.get128() );
cosAngle = spu_shuffle( cosAngle, cosAngle, shuffle_xxxx ); cosAngle = spu_shuffle( cosAngle, cosAngle, shuffle_xxxx );
selectMask = (vec_uint4)spu_cmpgt( spu_splats(0.0f), cosAngle ); selectMask = (vec_uint4)spu_cmpgt( spu_splats(0.0f), cosAngle );
cosAngle = spu_sel( cosAngle, negatef4( cosAngle ), selectMask ); cosAngle = spu_sel( cosAngle, negatef4( cosAngle ), selectMask );
start = Quat( spu_sel( unitQuat0.get128(), negatef4( unitQuat0.get128() ), selectMask ) ); start = Quat( spu_sel( unitQuat0.get128(), negatef4( unitQuat0.get128() ), selectMask ) );
selectMask = (vec_uint4)spu_cmpgt( spu_splats(_VECTORMATH_SLERP_TOL), cosAngle ); selectMask = (vec_uint4)spu_cmpgt( spu_splats(_VECTORMATH_SLERP_TOL), cosAngle );
angle = acosf4( cosAngle ); angle = acosf4( cosAngle );
tttt = spu_splats(t); tttt = spu_splats(t);
oneMinusT = spu_sub( spu_splats(1.0f), tttt ); oneMinusT = spu_sub( spu_splats(1.0f), tttt );
angles = spu_sel( spu_splats(1.0f), oneMinusT, (vec_uint4)spu_maskb(0x0f00) ); angles = spu_sel( spu_splats(1.0f), oneMinusT, (vec_uint4)spu_maskb(0x0f00) );
angles = spu_sel( angles, tttt, (vec_uint4)spu_maskb(0x00f0) ); angles = spu_sel( angles, tttt, (vec_uint4)spu_maskb(0x00f0) );
angles = spu_mul( angles, angle ); angles = spu_mul( angles, angle );
sines = sinf4( angles ); sines = sinf4( angles );
scales = divf4( sines, spu_shuffle( sines, sines, shuffle_xxxx ) ); scales = divf4( sines, spu_shuffle( sines, sines, shuffle_xxxx ) );
scale0 = spu_sel( oneMinusT, spu_shuffle( scales, scales, shuffle_yyyy ), selectMask ); scale0 = spu_sel( oneMinusT, spu_shuffle( scales, scales, shuffle_yyyy ), selectMask );
scale1 = spu_sel( tttt, spu_shuffle( scales, scales, shuffle_zzzz ), selectMask ); scale1 = spu_sel( tttt, spu_shuffle( scales, scales, shuffle_zzzz ), selectMask );
return Quat( spu_madd( start.get128(), scale0, spu_mul( unitQuat1.get128(), scale1 ) ) ); return Quat( spu_madd( start.get128(), scale0, spu_mul( unitQuat1.get128(), scale1 ) ) );
} }
inline const Quat squad( float t, Quat unitQuat0, Quat unitQuat1, Quat unitQuat2, Quat unitQuat3 ) inline const Quat squad( float t, Quat unitQuat0, Quat unitQuat1, Quat unitQuat2, Quat unitQuat3 )
{ {
Quat tmp0, tmp1; Quat tmp0, tmp1;
tmp0 = slerp( t, unitQuat0, unitQuat3 ); tmp0 = slerp( t, unitQuat0, unitQuat3 );
tmp1 = slerp( t, unitQuat1, unitQuat2 ); tmp1 = slerp( t, unitQuat1, unitQuat2 );
return slerp( ( ( 2.0f * t ) * ( 1.0f - t ) ), tmp0, tmp1 ); return slerp( ( ( 2.0f * t ) * ( 1.0f - t ) ), tmp0, tmp1 );
} }
inline vec_float4 Quat::get128( ) const inline vec_float4 Quat::get128( ) const
{ {
return mVec128; return mVec128;
} }
inline Quat & Quat::operator =( Quat quat ) inline Quat & Quat::operator =( Quat quat )
{ {
mVec128 = quat.mVec128; mVec128 = quat.mVec128;
return *this; return *this;
} }
inline Quat & Quat::setXYZ( Vector3 vec ) inline Quat & Quat::setXYZ( Vector3 vec )
{ {
mVec128 = spu_sel( vec.get128(), mVec128, (vec_uint4)spu_maskb(0x000f) ); mVec128 = spu_sel( vec.get128(), mVec128, (vec_uint4)spu_maskb(0x000f) );
return *this; return *this;
} }
inline const Vector3 Quat::getXYZ( ) const inline const Vector3 Quat::getXYZ( ) const
{ {
return Vector3( mVec128 ); return Vector3( mVec128 );
} }
inline Quat & Quat::setX( float _x ) inline Quat & Quat::setX( float _x )
{ {
mVec128 = spu_insert( _x, mVec128, 0 ); mVec128 = spu_insert( _x, mVec128, 0 );
return *this; return *this;
} }
inline float Quat::getX( ) const inline float Quat::getX( ) const
{ {
return spu_extract( mVec128, 0 ); return spu_extract( mVec128, 0 );
} }
inline Quat & Quat::setY( float _y ) inline Quat & Quat::setY( float _y )
{ {
mVec128 = spu_insert( _y, mVec128, 1 ); mVec128 = spu_insert( _y, mVec128, 1 );
return *this; return *this;
} }
inline float Quat::getY( ) const inline float Quat::getY( ) const
{ {
return spu_extract( mVec128, 1 ); return spu_extract( mVec128, 1 );
} }
inline Quat & Quat::setZ( float _z ) inline Quat & Quat::setZ( float _z )
{ {
mVec128 = spu_insert( _z, mVec128, 2 ); mVec128 = spu_insert( _z, mVec128, 2 );
return *this; return *this;
} }
inline float Quat::getZ( ) const inline float Quat::getZ( ) const
{ {
return spu_extract( mVec128, 2 ); return spu_extract( mVec128, 2 );
} }
inline Quat & Quat::setW( float _w ) inline Quat & Quat::setW( float _w )
{ {
mVec128 = spu_insert( _w, mVec128, 3 ); mVec128 = spu_insert( _w, mVec128, 3 );
return *this; return *this;
} }
inline float Quat::getW( ) const inline float Quat::getW( ) const
{ {
return spu_extract( mVec128, 3 ); return spu_extract( mVec128, 3 );
} }
inline Quat & Quat::setElem( int idx, float value ) inline Quat & Quat::setElem( int idx, float value )
{ {
mVec128 = spu_insert( value, mVec128, idx ); mVec128 = spu_insert( value, mVec128, idx );
return *this; return *this;
} }
inline float Quat::getElem( int idx ) const inline float Quat::getElem( int idx ) const
{ {
return spu_extract( mVec128, idx ); return spu_extract( mVec128, idx );
} }
inline VecIdx Quat::operator []( int idx ) inline VecIdx Quat::operator []( int idx )
{ {
return VecIdx( mVec128, idx ); return VecIdx( mVec128, idx );
} }
inline float Quat::operator []( int idx ) const inline float Quat::operator []( int idx ) const
{ {
return spu_extract( mVec128, idx ); return spu_extract( mVec128, idx );
} }
inline const Quat Quat::operator +( Quat quat ) const inline const Quat Quat::operator +( Quat quat ) const
{ {
return Quat( spu_add( mVec128, quat.mVec128 ) ); return Quat( spu_add( mVec128, quat.mVec128 ) );
} }
inline const Quat Quat::operator -( Quat quat ) const inline const Quat Quat::operator -( Quat quat ) const
{ {
return Quat( spu_sub( mVec128, quat.mVec128 ) ); return Quat( spu_sub( mVec128, quat.mVec128 ) );
} }
inline const Quat Quat::operator *( float scalar ) const inline const Quat Quat::operator *( float scalar ) const
{ {
return Quat( spu_mul( mVec128, spu_splats(scalar) ) ); return Quat( spu_mul( mVec128, spu_splats(scalar) ) );
} }
inline Quat & Quat::operator +=( Quat quat ) inline Quat & Quat::operator +=( Quat quat )
{ {
*this = *this + quat; *this = *this + quat;
return *this; return *this;
} }
inline Quat & Quat::operator -=( Quat quat ) inline Quat & Quat::operator -=( Quat quat )
{ {
*this = *this - quat; *this = *this - quat;
return *this; return *this;
} }
inline Quat & Quat::operator *=( float scalar ) inline Quat & Quat::operator *=( float scalar )
{ {
*this = *this * scalar; *this = *this * scalar;
return *this; return *this;
} }
inline const Quat Quat::operator /( float scalar ) const inline const Quat Quat::operator /( float scalar ) const
{ {
return Quat( divf4( mVec128, spu_splats(scalar) ) ); return Quat( divf4( mVec128, spu_splats(scalar) ) );
} }
inline Quat & Quat::operator /=( float scalar ) inline Quat & Quat::operator /=( float scalar )
{ {
*this = *this / scalar; *this = *this / scalar;
return *this; return *this;
} }
inline const Quat Quat::operator -( ) const inline const Quat Quat::operator -( ) const
{ {
return Quat( negatef4( mVec128 ) ); return Quat( negatef4( mVec128 ) );
} }
inline const Quat operator *( float scalar, Quat quat ) inline const Quat operator *( float scalar, Quat quat )
{ {
return quat * scalar; return quat * scalar;
} }
inline float dot( Quat quat0, Quat quat1 ) inline float dot( Quat quat0, Quat quat1 )
{ {
return spu_extract( _vmathVfDot4( quat0.get128(), quat1.get128() ), 0 ); return spu_extract( _vmathVfDot4( quat0.get128(), quat1.get128() ), 0 );
} }
inline float norm( Quat quat ) inline float norm( Quat quat )
{ {
return spu_extract( _vmathVfDot4( quat.get128(), quat.get128() ), 0 ); return spu_extract( _vmathVfDot4( quat.get128(), quat.get128() ), 0 );
} }
inline float length( Quat quat ) inline float length( Quat quat )
{ {
return sqrtf( norm( quat ) ); return sqrtf( norm( quat ) );
} }
inline const Quat normalize( Quat quat ) inline const Quat normalize( Quat quat )
{ {
vec_float4 dot = _vmathVfDot4( quat.get128(), quat.get128() ); vec_float4 dot = _vmathVfDot4( quat.get128(), quat.get128() );
return Quat( spu_mul( quat.get128(), rsqrtf4( dot ) ) ); return Quat( spu_mul( quat.get128(), rsqrtf4( dot ) ) );
} }
inline const Quat Quat::rotation( Vector3 unitVec0, Vector3 unitVec1 ) inline const Quat Quat::rotation( Vector3 unitVec0, Vector3 unitVec1 )
{ {
Vector3 crossVec; Vector3 crossVec;
vec_float4 cosAngle, cosAngleX2Plus2, recipCosHalfAngleX2, cosHalfAngleX2, res; vec_float4 cosAngle, cosAngleX2Plus2, recipCosHalfAngleX2, cosHalfAngleX2, res;
cosAngle = _vmathVfDot3( unitVec0.get128(), unitVec1.get128() ); cosAngle = _vmathVfDot3( unitVec0.get128(), unitVec1.get128() );
cosAngle = spu_shuffle( cosAngle, cosAngle, (vec_uchar16)spu_splats(0x00010203) ); cosAngle = spu_shuffle( cosAngle, cosAngle, (vec_uchar16)spu_splats(0x00010203) );
cosAngleX2Plus2 = spu_madd( cosAngle, spu_splats(2.0f), spu_splats(2.0f) ); cosAngleX2Plus2 = spu_madd( cosAngle, spu_splats(2.0f), spu_splats(2.0f) );
recipCosHalfAngleX2 = rsqrtf4( cosAngleX2Plus2 ); recipCosHalfAngleX2 = rsqrtf4( cosAngleX2Plus2 );
cosHalfAngleX2 = spu_mul( recipCosHalfAngleX2, cosAngleX2Plus2 ); cosHalfAngleX2 = spu_mul( recipCosHalfAngleX2, cosAngleX2Plus2 );
crossVec = cross( unitVec0, unitVec1 ); crossVec = cross( unitVec0, unitVec1 );
res = spu_mul( crossVec.get128(), recipCosHalfAngleX2 ); res = spu_mul( crossVec.get128(), recipCosHalfAngleX2 );
res = spu_sel( res, spu_mul( cosHalfAngleX2, spu_splats(0.5f) ), (vec_uint4)spu_maskb(0x000f) ); res = spu_sel( res, spu_mul( cosHalfAngleX2, spu_splats(0.5f) ), (vec_uint4)spu_maskb(0x000f) );
return Quat( res ); return Quat( res );
} }
inline const Quat Quat::rotation( float radians, Vector3 unitVec ) inline const Quat Quat::rotation( float radians, Vector3 unitVec )
{ {
vec_float4 s, c, angle, res; vec_float4 s, c, angle, res;
angle = spu_mul( spu_splats(radians), spu_splats(0.5f) ); angle = spu_mul( spu_splats(radians), spu_splats(0.5f) );
sincosf4( angle, &s, &c ); sincosf4( angle, &s, &c );
res = spu_sel( spu_mul( unitVec.get128(), s ), c, (vec_uint4)spu_maskb(0x000f) ); res = spu_sel( spu_mul( unitVec.get128(), s ), c, (vec_uint4)spu_maskb(0x000f) );
return Quat( res ); return Quat( res );
} }
inline const Quat Quat::rotationX( float radians ) inline const Quat Quat::rotationX( float radians )
{ {
vec_float4 s, c, angle, res; vec_float4 s, c, angle, res;
angle = spu_mul( spu_splats(radians), spu_splats(0.5f) ); angle = spu_mul( spu_splats(radians), spu_splats(0.5f) );
sincosf4( angle, &s, &c ); sincosf4( angle, &s, &c );
res = spu_sel( spu_splats(0.0f), s, (vec_uint4)spu_maskb(0xf000) ); res = spu_sel( spu_splats(0.0f), s, (vec_uint4)spu_maskb(0xf000) );
res = spu_sel( res, c, (vec_uint4)spu_maskb(0x000f) ); res = spu_sel( res, c, (vec_uint4)spu_maskb(0x000f) );
return Quat( res ); return Quat( res );
} }
inline const Quat Quat::rotationY( float radians ) inline const Quat Quat::rotationY( float radians )
{ {
vec_float4 s, c, angle, res; vec_float4 s, c, angle, res;
angle = spu_mul( spu_splats(radians), spu_splats(0.5f) ); angle = spu_mul( spu_splats(radians), spu_splats(0.5f) );
sincosf4( angle, &s, &c ); sincosf4( angle, &s, &c );
res = spu_sel( spu_splats(0.0f), s, (vec_uint4)spu_maskb(0x0f00) ); res = spu_sel( spu_splats(0.0f), s, (vec_uint4)spu_maskb(0x0f00) );
res = spu_sel( res, c, (vec_uint4)spu_maskb(0x000f) ); res = spu_sel( res, c, (vec_uint4)spu_maskb(0x000f) );
return Quat( res ); return Quat( res );
} }
inline const Quat Quat::rotationZ( float radians ) inline const Quat Quat::rotationZ( float radians )
{ {
vec_float4 s, c, angle, res; vec_float4 s, c, angle, res;
angle = spu_mul( spu_splats(radians), spu_splats(0.5f) ); angle = spu_mul( spu_splats(radians), spu_splats(0.5f) );
sincosf4( angle, &s, &c ); sincosf4( angle, &s, &c );
res = spu_sel( spu_splats(0.0f), s, (vec_uint4)spu_maskb(0x00f0) ); res = spu_sel( spu_splats(0.0f), s, (vec_uint4)spu_maskb(0x00f0) );
res = spu_sel( res, c, (vec_uint4)spu_maskb(0x000f) ); res = spu_sel( res, c, (vec_uint4)spu_maskb(0x000f) );
return Quat( res ); return Quat( res );
} }
inline const Quat Quat::operator *( Quat quat ) const inline const Quat Quat::operator *( Quat quat ) const
{ {
vec_float4 ldata, rdata, qv, tmp0, tmp1, tmp2, tmp3; vec_float4 ldata, rdata, qv, tmp0, tmp1, tmp2, tmp3;
vec_float4 product, l_wxyz, r_wxyz, xy, qw; vec_float4 product, l_wxyz, r_wxyz, xy, qw;
ldata = mVec128; ldata = mVec128;
rdata = quat.mVec128; rdata = quat.mVec128;
vec_uchar16 shuffle_wwww = (vec_uchar16)spu_splats((int)0x0c0d0e0f); vec_uchar16 shuffle_wwww = (vec_uchar16)spu_splats((int)0x0c0d0e0f);
tmp0 = spu_shuffle( ldata, ldata, _VECTORMATH_SHUF_YZXW ); tmp0 = spu_shuffle( ldata, ldata, _VECTORMATH_SHUF_YZXW );
tmp1 = spu_shuffle( rdata, rdata, _VECTORMATH_SHUF_ZXYW ); tmp1 = spu_shuffle( rdata, rdata, _VECTORMATH_SHUF_ZXYW );
tmp2 = spu_shuffle( ldata, ldata, _VECTORMATH_SHUF_ZXYW ); tmp2 = spu_shuffle( ldata, ldata, _VECTORMATH_SHUF_ZXYW );
tmp3 = spu_shuffle( rdata, rdata, _VECTORMATH_SHUF_YZXW ); tmp3 = spu_shuffle( rdata, rdata, _VECTORMATH_SHUF_YZXW );
qv = spu_mul( spu_shuffle( ldata, ldata, shuffle_wwww ), rdata ); qv = spu_mul( spu_shuffle( ldata, ldata, shuffle_wwww ), rdata );
qv = spu_madd( spu_shuffle( rdata, rdata, shuffle_wwww ), ldata, qv ); qv = spu_madd( spu_shuffle( rdata, rdata, shuffle_wwww ), ldata, qv );
qv = spu_madd( tmp0, tmp1, qv ); qv = spu_madd( tmp0, tmp1, qv );
qv = spu_nmsub( tmp2, tmp3, qv ); qv = spu_nmsub( tmp2, tmp3, qv );
product = spu_mul( ldata, rdata ); product = spu_mul( ldata, rdata );
l_wxyz = spu_rlqwbyte( ldata, 12 ); l_wxyz = spu_rlqwbyte( ldata, 12 );
r_wxyz = spu_rlqwbyte( rdata, 12 ); r_wxyz = spu_rlqwbyte( rdata, 12 );
qw = spu_nmsub( l_wxyz, r_wxyz, product ); qw = spu_nmsub( l_wxyz, r_wxyz, product );
xy = spu_madd( l_wxyz, r_wxyz, product ); xy = spu_madd( l_wxyz, r_wxyz, product );
qw = spu_sub( qw, spu_rlqwbyte( xy, 8 ) ); qw = spu_sub( qw, spu_rlqwbyte( xy, 8 ) );
return Quat( spu_sel( qv, qw, (vec_uint4)spu_maskb( 0x000f ) ) ); return Quat( spu_sel( qv, qw, (vec_uint4)spu_maskb( 0x000f ) ) );
} }
inline Quat & Quat::operator *=( Quat quat ) inline Quat & Quat::operator *=( Quat quat )
{ {
*this = *this * quat; *this = *this * quat;
return *this; return *this;
} }
inline const Vector3 rotate( Quat quat, Vector3 vec ) inline const Vector3 rotate( Quat quat, Vector3 vec )
{ {
vec_float4 qdata, vdata, product, tmp0, tmp1, tmp2, tmp3, wwww, qv, qw, res; vec_float4 qdata, vdata, product, tmp0, tmp1, tmp2, tmp3, wwww, qv, qw, res;
qdata = quat.get128(); qdata = quat.get128();
vdata = vec.get128(); vdata = vec.get128();
vec_uchar16 shuffle_xxxx = (vec_uchar16)spu_splats((int)0x00010203); vec_uchar16 shuffle_xxxx = (vec_uchar16)spu_splats((int)0x00010203);
vec_uchar16 shuffle_wwww = (vec_uchar16)spu_splats((int)0x0c0d0e0f); vec_uchar16 shuffle_wwww = (vec_uchar16)spu_splats((int)0x0c0d0e0f);
tmp0 = spu_shuffle( qdata, qdata, _VECTORMATH_SHUF_YZXW ); tmp0 = spu_shuffle( qdata, qdata, _VECTORMATH_SHUF_YZXW );
tmp1 = spu_shuffle( vdata, vdata, _VECTORMATH_SHUF_ZXYW ); tmp1 = spu_shuffle( vdata, vdata, _VECTORMATH_SHUF_ZXYW );
tmp2 = spu_shuffle( qdata, qdata, _VECTORMATH_SHUF_ZXYW ); tmp2 = spu_shuffle( qdata, qdata, _VECTORMATH_SHUF_ZXYW );
tmp3 = spu_shuffle( vdata, vdata, _VECTORMATH_SHUF_YZXW ); tmp3 = spu_shuffle( vdata, vdata, _VECTORMATH_SHUF_YZXW );
wwww = spu_shuffle( qdata, qdata, shuffle_wwww ); wwww = spu_shuffle( qdata, qdata, shuffle_wwww );
qv = spu_mul( wwww, vdata ); qv = spu_mul( wwww, vdata );
qv = spu_madd( tmp0, tmp1, qv ); qv = spu_madd( tmp0, tmp1, qv );
qv = spu_nmsub( tmp2, tmp3, qv ); qv = spu_nmsub( tmp2, tmp3, qv );
product = spu_mul( qdata, vdata ); product = spu_mul( qdata, vdata );
qw = spu_madd( spu_rlqwbyte( qdata, 4 ), spu_rlqwbyte( vdata, 4 ), product ); qw = spu_madd( spu_rlqwbyte( qdata, 4 ), spu_rlqwbyte( vdata, 4 ), product );
qw = spu_add( spu_rlqwbyte( product, 8 ), qw ); qw = spu_add( spu_rlqwbyte( product, 8 ), qw );
tmp1 = spu_shuffle( qv, qv, _VECTORMATH_SHUF_ZXYW ); tmp1 = spu_shuffle( qv, qv, _VECTORMATH_SHUF_ZXYW );
tmp3 = spu_shuffle( qv, qv, _VECTORMATH_SHUF_YZXW ); tmp3 = spu_shuffle( qv, qv, _VECTORMATH_SHUF_YZXW );
res = spu_mul( spu_shuffle( qw, qw, shuffle_xxxx ), qdata ); res = spu_mul( spu_shuffle( qw, qw, shuffle_xxxx ), qdata );
res = spu_madd( wwww, qv, res ); res = spu_madd( wwww, qv, res );
res = spu_madd( tmp0, tmp1, res ); res = spu_madd( tmp0, tmp1, res );
res = spu_nmsub( tmp2, tmp3, res ); res = spu_nmsub( tmp2, tmp3, res );
return Vector3( res ); return Vector3( res );
} }
inline const Quat conj( Quat quat ) inline const Quat conj( Quat quat )
{ {
return Quat( spu_xor( quat.get128(), ((vec_float4)(vec_int4){0x80000000,0x80000000,0x80000000,0}) ) ); return Quat( spu_xor( quat.get128(), ((vec_float4)(vec_int4){0x80000000,0x80000000,0x80000000,0}) ) );
} }
inline const Quat select( Quat quat0, Quat quat1, bool select1 ) inline const Quat select( Quat quat0, Quat quat1, bool select1 )
{ {
return Quat( spu_sel( quat0.get128(), quat1.get128(), spu_splats( (unsigned int)-(select1 > 0) ) ) ); return Quat( spu_sel( quat0.get128(), quat1.get128(), spu_splats( (unsigned int)-(select1 > 0) ) ) );
} }
#ifdef _VECTORMATH_DEBUG #ifdef _VECTORMATH_DEBUG
inline void print( Quat quat ) inline void print( Quat quat )
{ {
union { vec_float4 v; float s[4]; } tmp; union { vec_float4 v; float s[4]; } tmp;
tmp.v = quat.get128(); tmp.v = quat.get128();
printf( "( %f %f %f %f )\n", tmp.s[0], tmp.s[1], tmp.s[2], tmp.s[3] ); printf( "( %f %f %f %f )\n", tmp.s[0], tmp.s[1], tmp.s[2], tmp.s[3] );
} }
inline void print( Quat quat, const char * name ) inline void print( Quat quat, const char * name )
{ {
union { vec_float4 v; float s[4]; } tmp; union { vec_float4 v; float s[4]; } tmp;
tmp.v = quat.get128(); tmp.v = quat.get128();
printf( "%s: ( %f %f %f %f )\n", name, tmp.s[0], tmp.s[1], tmp.s[2], tmp.s[3] ); printf( "%s: ( %f %f %f %f )\n", name, tmp.s[0], tmp.s[1], tmp.s[2], tmp.s[3] );
} }
#endif #endif
} // namespace Aos } // namespace Aos
} // namespace Vectormath } // namespace Vectormath
#endif #endif

View File

@@ -1,483 +1,483 @@
/* /*
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc. Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the with or without modification, are permitted provided that the
following conditions are met: following conditions are met:
* Redistributions of source code must retain the above copyright * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright * Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names * Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission. from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef _VECTORMATH_QUAT_SOA_CPP_H #ifndef _VECTORMATH_QUAT_SOA_CPP_H
#define _VECTORMATH_QUAT_SOA_CPP_H #define _VECTORMATH_QUAT_SOA_CPP_H
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Definitions // Definitions
#ifndef _VECTORMATH_INTERNAL_FUNCTIONS #ifndef _VECTORMATH_INTERNAL_FUNCTIONS
#define _VECTORMATH_INTERNAL_FUNCTIONS #define _VECTORMATH_INTERNAL_FUNCTIONS
#endif #endif
namespace Vectormath { namespace Vectormath {
namespace Soa { namespace Soa {
inline Quat::Quat( const Quat & quat ) inline Quat::Quat( const Quat & quat )
{ {
mX = quat.mX; mX = quat.mX;
mY = quat.mY; mY = quat.mY;
mZ = quat.mZ; mZ = quat.mZ;
mW = quat.mW; mW = quat.mW;
} }
inline Quat::Quat( vec_float4 _x, vec_float4 _y, vec_float4 _z, vec_float4 _w ) inline Quat::Quat( vec_float4 _x, vec_float4 _y, vec_float4 _z, vec_float4 _w )
{ {
mX = _x; mX = _x;
mY = _y; mY = _y;
mZ = _z; mZ = _z;
mW = _w; mW = _w;
} }
inline Quat::Quat( const Vector3 & xyz, vec_float4 _w ) inline Quat::Quat( const Vector3 & xyz, vec_float4 _w )
{ {
this->setXYZ( xyz ); this->setXYZ( xyz );
this->setW( _w ); this->setW( _w );
} }
inline Quat::Quat( const Vector4 & vec ) inline Quat::Quat( const Vector4 & vec )
{ {
mX = vec.getX(); mX = vec.getX();
mY = vec.getY(); mY = vec.getY();
mZ = vec.getZ(); mZ = vec.getZ();
mW = vec.getW(); mW = vec.getW();
} }
inline Quat::Quat( vec_float4 scalar ) inline Quat::Quat( vec_float4 scalar )
{ {
mX = scalar; mX = scalar;
mY = scalar; mY = scalar;
mZ = scalar; mZ = scalar;
mW = scalar; mW = scalar;
} }
inline Quat::Quat( Aos::Quat quat ) inline Quat::Quat( Aos::Quat quat )
{ {
vec_uchar16 shuffle_xxxx = (vec_uchar16)spu_splats((int)0x00010203); vec_uchar16 shuffle_xxxx = (vec_uchar16)spu_splats((int)0x00010203);
vec_uchar16 shuffle_yyyy = (vec_uchar16)spu_splats((int)0x04050607); vec_uchar16 shuffle_yyyy = (vec_uchar16)spu_splats((int)0x04050607);
vec_uchar16 shuffle_zzzz = (vec_uchar16)spu_splats((int)0x08090a0b); vec_uchar16 shuffle_zzzz = (vec_uchar16)spu_splats((int)0x08090a0b);
vec_uchar16 shuffle_wwww = (vec_uchar16)spu_splats((int)0x0c0d0e0f); vec_uchar16 shuffle_wwww = (vec_uchar16)spu_splats((int)0x0c0d0e0f);
vec_float4 vec128 = quat.get128(); vec_float4 vec128 = quat.get128();
mX = spu_shuffle( vec128, vec128, shuffle_xxxx ); mX = spu_shuffle( vec128, vec128, shuffle_xxxx );
mY = spu_shuffle( vec128, vec128, shuffle_yyyy ); mY = spu_shuffle( vec128, vec128, shuffle_yyyy );
mZ = spu_shuffle( vec128, vec128, shuffle_zzzz ); mZ = spu_shuffle( vec128, vec128, shuffle_zzzz );
mW = spu_shuffle( vec128, vec128, shuffle_wwww ); mW = spu_shuffle( vec128, vec128, shuffle_wwww );
} }
inline Quat::Quat( Aos::Quat quat0, Aos::Quat quat1, Aos::Quat quat2, Aos::Quat quat3 ) inline Quat::Quat( Aos::Quat quat0, Aos::Quat quat1, Aos::Quat quat2, Aos::Quat quat3 )
{ {
vec_float4 tmp0, tmp1, tmp2, tmp3; vec_float4 tmp0, tmp1, tmp2, tmp3;
tmp0 = spu_shuffle( quat0.get128(), quat2.get128(), _VECTORMATH_SHUF_XAYB ); tmp0 = spu_shuffle( quat0.get128(), quat2.get128(), _VECTORMATH_SHUF_XAYB );
tmp1 = spu_shuffle( quat1.get128(), quat3.get128(), _VECTORMATH_SHUF_XAYB ); tmp1 = spu_shuffle( quat1.get128(), quat3.get128(), _VECTORMATH_SHUF_XAYB );
tmp2 = spu_shuffle( quat0.get128(), quat2.get128(), _VECTORMATH_SHUF_ZCWD ); tmp2 = spu_shuffle( quat0.get128(), quat2.get128(), _VECTORMATH_SHUF_ZCWD );
tmp3 = spu_shuffle( quat1.get128(), quat3.get128(), _VECTORMATH_SHUF_ZCWD ); tmp3 = spu_shuffle( quat1.get128(), quat3.get128(), _VECTORMATH_SHUF_ZCWD );
mX = spu_shuffle( tmp0, tmp1, _VECTORMATH_SHUF_XAYB ); mX = spu_shuffle( tmp0, tmp1, _VECTORMATH_SHUF_XAYB );
mY = spu_shuffle( tmp0, tmp1, _VECTORMATH_SHUF_ZCWD ); mY = spu_shuffle( tmp0, tmp1, _VECTORMATH_SHUF_ZCWD );
mZ = spu_shuffle( tmp2, tmp3, _VECTORMATH_SHUF_XAYB ); mZ = spu_shuffle( tmp2, tmp3, _VECTORMATH_SHUF_XAYB );
mW = spu_shuffle( tmp2, tmp3, _VECTORMATH_SHUF_ZCWD ); mW = spu_shuffle( tmp2, tmp3, _VECTORMATH_SHUF_ZCWD );
} }
inline const Quat Quat::identity( ) inline const Quat Quat::identity( )
{ {
return Quat( spu_splats(0.0f), spu_splats(0.0f), spu_splats(0.0f), spu_splats(1.0f) ); return Quat( spu_splats(0.0f), spu_splats(0.0f), spu_splats(0.0f), spu_splats(1.0f) );
} }
inline const Quat lerp( vec_float4 t, const Quat & quat0, const Quat & quat1 ) inline const Quat lerp( vec_float4 t, const Quat & quat0, const Quat & quat1 )
{ {
return ( quat0 + ( ( quat1 - quat0 ) * t ) ); return ( quat0 + ( ( quat1 - quat0 ) * t ) );
} }
inline const Quat slerp( vec_float4 t, const Quat & unitQuat0, const Quat & unitQuat1 ) inline const Quat slerp( vec_float4 t, const Quat & unitQuat0, const Quat & unitQuat1 )
{ {
Quat start; Quat start;
vec_float4 recipSinAngle, scale0, scale1, cosAngle, angle; vec_float4 recipSinAngle, scale0, scale1, cosAngle, angle;
vec_uint4 selectMask; vec_uint4 selectMask;
cosAngle = dot( unitQuat0, unitQuat1 ); cosAngle = dot( unitQuat0, unitQuat1 );
selectMask = (vec_uint4)spu_cmpgt( spu_splats(0.0f), cosAngle ); selectMask = (vec_uint4)spu_cmpgt( spu_splats(0.0f), cosAngle );
cosAngle = spu_sel( cosAngle, negatef4( cosAngle ), selectMask ); cosAngle = spu_sel( cosAngle, negatef4( cosAngle ), selectMask );
start.setX( spu_sel( unitQuat0.getX(), negatef4( unitQuat0.getX() ), selectMask ) ); start.setX( spu_sel( unitQuat0.getX(), negatef4( unitQuat0.getX() ), selectMask ) );
start.setY( spu_sel( unitQuat0.getY(), negatef4( unitQuat0.getY() ), selectMask ) ); start.setY( spu_sel( unitQuat0.getY(), negatef4( unitQuat0.getY() ), selectMask ) );
start.setZ( spu_sel( unitQuat0.getZ(), negatef4( unitQuat0.getZ() ), selectMask ) ); start.setZ( spu_sel( unitQuat0.getZ(), negatef4( unitQuat0.getZ() ), selectMask ) );
start.setW( spu_sel( unitQuat0.getW(), negatef4( unitQuat0.getW() ), selectMask ) ); start.setW( spu_sel( unitQuat0.getW(), negatef4( unitQuat0.getW() ), selectMask ) );
selectMask = (vec_uint4)spu_cmpgt( spu_splats(_VECTORMATH_SLERP_TOL), cosAngle ); selectMask = (vec_uint4)spu_cmpgt( spu_splats(_VECTORMATH_SLERP_TOL), cosAngle );
angle = acosf4( cosAngle ); angle = acosf4( cosAngle );
recipSinAngle = recipf4( sinf4( angle ) ); recipSinAngle = recipf4( sinf4( angle ) );
scale0 = spu_sel( spu_sub( spu_splats(1.0f), t ), spu_mul( sinf4( spu_mul( spu_sub( spu_splats(1.0f), t ), angle ) ), recipSinAngle ), selectMask ); scale0 = spu_sel( spu_sub( spu_splats(1.0f), t ), spu_mul( sinf4( spu_mul( spu_sub( spu_splats(1.0f), t ), angle ) ), recipSinAngle ), selectMask );
scale1 = spu_sel( t, spu_mul( sinf4( spu_mul( t, angle ) ), recipSinAngle ), selectMask ); scale1 = spu_sel( t, spu_mul( sinf4( spu_mul( t, angle ) ), recipSinAngle ), selectMask );
return ( ( start * scale0 ) + ( unitQuat1 * scale1 ) ); return ( ( start * scale0 ) + ( unitQuat1 * scale1 ) );
} }
inline const Quat squad( vec_float4 t, const Quat & unitQuat0, const Quat & unitQuat1, const Quat & unitQuat2, const Quat & unitQuat3 ) inline const Quat squad( vec_float4 t, const Quat & unitQuat0, const Quat & unitQuat1, const Quat & unitQuat2, const Quat & unitQuat3 )
{ {
Quat tmp0, tmp1; Quat tmp0, tmp1;
tmp0 = slerp( t, unitQuat0, unitQuat3 ); tmp0 = slerp( t, unitQuat0, unitQuat3 );
tmp1 = slerp( t, unitQuat1, unitQuat2 ); tmp1 = slerp( t, unitQuat1, unitQuat2 );
return slerp( spu_mul( spu_mul( spu_splats(2.0f), t ), spu_sub( spu_splats(1.0f), t ) ), tmp0, tmp1 ); return slerp( spu_mul( spu_mul( spu_splats(2.0f), t ), spu_sub( spu_splats(1.0f), t ) ), tmp0, tmp1 );
} }
inline void Quat::get4Aos( Aos::Quat & result0, Aos::Quat & result1, Aos::Quat & result2, Aos::Quat & result3 ) const inline void Quat::get4Aos( Aos::Quat & result0, Aos::Quat & result1, Aos::Quat & result2, Aos::Quat & result3 ) const
{ {
vec_float4 tmp0, tmp1, tmp2, tmp3; vec_float4 tmp0, tmp1, tmp2, tmp3;
tmp0 = spu_shuffle( mX, mZ, _VECTORMATH_SHUF_XAYB ); tmp0 = spu_shuffle( mX, mZ, _VECTORMATH_SHUF_XAYB );
tmp1 = spu_shuffle( mY, mW, _VECTORMATH_SHUF_XAYB ); tmp1 = spu_shuffle( mY, mW, _VECTORMATH_SHUF_XAYB );
tmp2 = spu_shuffle( mX, mZ, _VECTORMATH_SHUF_ZCWD ); tmp2 = spu_shuffle( mX, mZ, _VECTORMATH_SHUF_ZCWD );
tmp3 = spu_shuffle( mY, mW, _VECTORMATH_SHUF_ZCWD ); tmp3 = spu_shuffle( mY, mW, _VECTORMATH_SHUF_ZCWD );
result0 = Aos::Quat( spu_shuffle( tmp0, tmp1, _VECTORMATH_SHUF_XAYB ) ); result0 = Aos::Quat( spu_shuffle( tmp0, tmp1, _VECTORMATH_SHUF_XAYB ) );
result1 = Aos::Quat( spu_shuffle( tmp0, tmp1, _VECTORMATH_SHUF_ZCWD ) ); result1 = Aos::Quat( spu_shuffle( tmp0, tmp1, _VECTORMATH_SHUF_ZCWD ) );
result2 = Aos::Quat( spu_shuffle( tmp2, tmp3, _VECTORMATH_SHUF_XAYB ) ); result2 = Aos::Quat( spu_shuffle( tmp2, tmp3, _VECTORMATH_SHUF_XAYB ) );
result3 = Aos::Quat( spu_shuffle( tmp2, tmp3, _VECTORMATH_SHUF_ZCWD ) ); result3 = Aos::Quat( spu_shuffle( tmp2, tmp3, _VECTORMATH_SHUF_ZCWD ) );
} }
inline Quat & Quat::operator =( const Quat & quat ) inline Quat & Quat::operator =( const Quat & quat )
{ {
mX = quat.mX; mX = quat.mX;
mY = quat.mY; mY = quat.mY;
mZ = quat.mZ; mZ = quat.mZ;
mW = quat.mW; mW = quat.mW;
return *this; return *this;
} }
inline Quat & Quat::setXYZ( const Vector3 & vec ) inline Quat & Quat::setXYZ( const Vector3 & vec )
{ {
mX = vec.getX(); mX = vec.getX();
mY = vec.getY(); mY = vec.getY();
mZ = vec.getZ(); mZ = vec.getZ();
return *this; return *this;
} }
inline const Vector3 Quat::getXYZ( ) const inline const Vector3 Quat::getXYZ( ) const
{ {
return Vector3( mX, mY, mZ ); return Vector3( mX, mY, mZ );
} }
inline Quat & Quat::setX( vec_float4 _x ) inline Quat & Quat::setX( vec_float4 _x )
{ {
mX = _x; mX = _x;
return *this; return *this;
} }
inline vec_float4 Quat::getX( ) const inline vec_float4 Quat::getX( ) const
{ {
return mX; return mX;
} }
inline Quat & Quat::setY( vec_float4 _y ) inline Quat & Quat::setY( vec_float4 _y )
{ {
mY = _y; mY = _y;
return *this; return *this;
} }
inline vec_float4 Quat::getY( ) const inline vec_float4 Quat::getY( ) const
{ {
return mY; return mY;
} }
inline Quat & Quat::setZ( vec_float4 _z ) inline Quat & Quat::setZ( vec_float4 _z )
{ {
mZ = _z; mZ = _z;
return *this; return *this;
} }
inline vec_float4 Quat::getZ( ) const inline vec_float4 Quat::getZ( ) const
{ {
return mZ; return mZ;
} }
inline Quat & Quat::setW( vec_float4 _w ) inline Quat & Quat::setW( vec_float4 _w )
{ {
mW = _w; mW = _w;
return *this; return *this;
} }
inline vec_float4 Quat::getW( ) const inline vec_float4 Quat::getW( ) const
{ {
return mW; return mW;
} }
inline Quat & Quat::setElem( int idx, vec_float4 value ) inline Quat & Quat::setElem( int idx, vec_float4 value )
{ {
*(&mX + idx) = value; *(&mX + idx) = value;
return *this; return *this;
} }
inline vec_float4 Quat::getElem( int idx ) const inline vec_float4 Quat::getElem( int idx ) const
{ {
return *(&mX + idx); return *(&mX + idx);
} }
inline Quat::vec_float4_t & Quat::operator []( int idx ) inline Quat::vec_float4_t & Quat::operator []( int idx )
{ {
return *(&mX + idx); return *(&mX + idx);
} }
inline vec_float4 Quat::operator []( int idx ) const inline vec_float4 Quat::operator []( int idx ) const
{ {
return *(&mX + idx); return *(&mX + idx);
} }
inline const Quat Quat::operator +( const Quat & quat ) const inline const Quat Quat::operator +( const Quat & quat ) const
{ {
return Quat( return Quat(
spu_add( mX, quat.mX ), spu_add( mX, quat.mX ),
spu_add( mY, quat.mY ), spu_add( mY, quat.mY ),
spu_add( mZ, quat.mZ ), spu_add( mZ, quat.mZ ),
spu_add( mW, quat.mW ) spu_add( mW, quat.mW )
); );
} }
inline const Quat Quat::operator -( const Quat & quat ) const inline const Quat Quat::operator -( const Quat & quat ) const
{ {
return Quat( return Quat(
spu_sub( mX, quat.mX ), spu_sub( mX, quat.mX ),
spu_sub( mY, quat.mY ), spu_sub( mY, quat.mY ),
spu_sub( mZ, quat.mZ ), spu_sub( mZ, quat.mZ ),
spu_sub( mW, quat.mW ) spu_sub( mW, quat.mW )
); );
} }
inline const Quat Quat::operator *( vec_float4 scalar ) const inline const Quat Quat::operator *( vec_float4 scalar ) const
{ {
return Quat( return Quat(
spu_mul( mX, scalar ), spu_mul( mX, scalar ),
spu_mul( mY, scalar ), spu_mul( mY, scalar ),
spu_mul( mZ, scalar ), spu_mul( mZ, scalar ),
spu_mul( mW, scalar ) spu_mul( mW, scalar )
); );
} }
inline Quat & Quat::operator +=( const Quat & quat ) inline Quat & Quat::operator +=( const Quat & quat )
{ {
*this = *this + quat; *this = *this + quat;
return *this; return *this;
} }
inline Quat & Quat::operator -=( const Quat & quat ) inline Quat & Quat::operator -=( const Quat & quat )
{ {
*this = *this - quat; *this = *this - quat;
return *this; return *this;
} }
inline Quat & Quat::operator *=( vec_float4 scalar ) inline Quat & Quat::operator *=( vec_float4 scalar )
{ {
*this = *this * scalar; *this = *this * scalar;
return *this; return *this;
} }
inline const Quat Quat::operator /( vec_float4 scalar ) const inline const Quat Quat::operator /( vec_float4 scalar ) const
{ {
return Quat( return Quat(
divf4( mX, scalar ), divf4( mX, scalar ),
divf4( mY, scalar ), divf4( mY, scalar ),
divf4( mZ, scalar ), divf4( mZ, scalar ),
divf4( mW, scalar ) divf4( mW, scalar )
); );
} }
inline Quat & Quat::operator /=( vec_float4 scalar ) inline Quat & Quat::operator /=( vec_float4 scalar )
{ {
*this = *this / scalar; *this = *this / scalar;
return *this; return *this;
} }
inline const Quat Quat::operator -( ) const inline const Quat Quat::operator -( ) const
{ {
return Quat( return Quat(
negatef4( mX ), negatef4( mX ),
negatef4( mY ), negatef4( mY ),
negatef4( mZ ), negatef4( mZ ),
negatef4( mW ) negatef4( mW )
); );
} }
inline const Quat operator *( vec_float4 scalar, const Quat & quat ) inline const Quat operator *( vec_float4 scalar, const Quat & quat )
{ {
return quat * scalar; return quat * scalar;
} }
inline vec_float4 dot( const Quat & quat0, const Quat & quat1 ) inline vec_float4 dot( const Quat & quat0, const Quat & quat1 )
{ {
vec_float4 result; vec_float4 result;
result = spu_mul( quat0.getX(), quat1.getX() ); result = spu_mul( quat0.getX(), quat1.getX() );
result = spu_add( result, spu_mul( quat0.getY(), quat1.getY() ) ); result = spu_add( result, spu_mul( quat0.getY(), quat1.getY() ) );
result = spu_add( result, spu_mul( quat0.getZ(), quat1.getZ() ) ); result = spu_add( result, spu_mul( quat0.getZ(), quat1.getZ() ) );
result = spu_add( result, spu_mul( quat0.getW(), quat1.getW() ) ); result = spu_add( result, spu_mul( quat0.getW(), quat1.getW() ) );
return result; return result;
} }
inline vec_float4 norm( const Quat & quat ) inline vec_float4 norm( const Quat & quat )
{ {
vec_float4 result; vec_float4 result;
result = spu_mul( quat.getX(), quat.getX() ); result = spu_mul( quat.getX(), quat.getX() );
result = spu_add( result, spu_mul( quat.getY(), quat.getY() ) ); result = spu_add( result, spu_mul( quat.getY(), quat.getY() ) );
result = spu_add( result, spu_mul( quat.getZ(), quat.getZ() ) ); result = spu_add( result, spu_mul( quat.getZ(), quat.getZ() ) );
result = spu_add( result, spu_mul( quat.getW(), quat.getW() ) ); result = spu_add( result, spu_mul( quat.getW(), quat.getW() ) );
return result; return result;
} }
inline vec_float4 length( const Quat & quat ) inline vec_float4 length( const Quat & quat )
{ {
return sqrtf4( norm( quat ) ); return sqrtf4( norm( quat ) );
} }
inline const Quat normalize( const Quat & quat ) inline const Quat normalize( const Quat & quat )
{ {
vec_float4 lenSqr, lenInv; vec_float4 lenSqr, lenInv;
lenSqr = norm( quat ); lenSqr = norm( quat );
lenInv = rsqrtf4( lenSqr ); lenInv = rsqrtf4( lenSqr );
return Quat( return Quat(
spu_mul( quat.getX(), lenInv ), spu_mul( quat.getX(), lenInv ),
spu_mul( quat.getY(), lenInv ), spu_mul( quat.getY(), lenInv ),
spu_mul( quat.getZ(), lenInv ), spu_mul( quat.getZ(), lenInv ),
spu_mul( quat.getW(), lenInv ) spu_mul( quat.getW(), lenInv )
); );
} }
inline const Quat Quat::rotation( const Vector3 & unitVec0, const Vector3 & unitVec1 ) inline const Quat Quat::rotation( const Vector3 & unitVec0, const Vector3 & unitVec1 )
{ {
vec_float4 cosHalfAngleX2, recipCosHalfAngleX2; vec_float4 cosHalfAngleX2, recipCosHalfAngleX2;
cosHalfAngleX2 = sqrtf4( spu_mul( spu_splats(2.0f), spu_add( spu_splats(1.0f), dot( unitVec0, unitVec1 ) ) ) ); cosHalfAngleX2 = sqrtf4( spu_mul( spu_splats(2.0f), spu_add( spu_splats(1.0f), dot( unitVec0, unitVec1 ) ) ) );
recipCosHalfAngleX2 = recipf4( cosHalfAngleX2 ); recipCosHalfAngleX2 = recipf4( cosHalfAngleX2 );
return Quat( ( cross( unitVec0, unitVec1 ) * recipCosHalfAngleX2 ), spu_mul( cosHalfAngleX2, spu_splats(0.5f) ) ); return Quat( ( cross( unitVec0, unitVec1 ) * recipCosHalfAngleX2 ), spu_mul( cosHalfAngleX2, spu_splats(0.5f) ) );
} }
inline const Quat Quat::rotation( vec_float4 radians, const Vector3 & unitVec ) inline const Quat Quat::rotation( vec_float4 radians, const Vector3 & unitVec )
{ {
vec_float4 s, c, angle; vec_float4 s, c, angle;
angle = spu_mul( radians, spu_splats(0.5f) ); angle = spu_mul( radians, spu_splats(0.5f) );
sincosf4( angle, &s, &c ); sincosf4( angle, &s, &c );
return Quat( ( unitVec * s ), c ); return Quat( ( unitVec * s ), c );
} }
inline const Quat Quat::rotationX( vec_float4 radians ) inline const Quat Quat::rotationX( vec_float4 radians )
{ {
vec_float4 s, c, angle; vec_float4 s, c, angle;
angle = spu_mul( radians, spu_splats(0.5f) ); angle = spu_mul( radians, spu_splats(0.5f) );
sincosf4( angle, &s, &c ); sincosf4( angle, &s, &c );
return Quat( s, spu_splats(0.0f), spu_splats(0.0f), c ); return Quat( s, spu_splats(0.0f), spu_splats(0.0f), c );
} }
inline const Quat Quat::rotationY( vec_float4 radians ) inline const Quat Quat::rotationY( vec_float4 radians )
{ {
vec_float4 s, c, angle; vec_float4 s, c, angle;
angle = spu_mul( radians, spu_splats(0.5f) ); angle = spu_mul( radians, spu_splats(0.5f) );
sincosf4( angle, &s, &c ); sincosf4( angle, &s, &c );
return Quat( spu_splats(0.0f), s, spu_splats(0.0f), c ); return Quat( spu_splats(0.0f), s, spu_splats(0.0f), c );
} }
inline const Quat Quat::rotationZ( vec_float4 radians ) inline const Quat Quat::rotationZ( vec_float4 radians )
{ {
vec_float4 s, c, angle; vec_float4 s, c, angle;
angle = spu_mul( radians, spu_splats(0.5f) ); angle = spu_mul( radians, spu_splats(0.5f) );
sincosf4( angle, &s, &c ); sincosf4( angle, &s, &c );
return Quat( spu_splats(0.0f), spu_splats(0.0f), s, c ); return Quat( spu_splats(0.0f), spu_splats(0.0f), s, c );
} }
inline const Quat Quat::operator *( const Quat & quat ) const inline const Quat Quat::operator *( const Quat & quat ) const
{ {
return Quat( return Quat(
spu_sub( spu_add( spu_add( spu_mul( mW, quat.mX ), spu_mul( mX, quat.mW ) ), spu_mul( mY, quat.mZ ) ), spu_mul( mZ, quat.mY ) ), spu_sub( spu_add( spu_add( spu_mul( mW, quat.mX ), spu_mul( mX, quat.mW ) ), spu_mul( mY, quat.mZ ) ), spu_mul( mZ, quat.mY ) ),
spu_sub( spu_add( spu_add( spu_mul( mW, quat.mY ), spu_mul( mY, quat.mW ) ), spu_mul( mZ, quat.mX ) ), spu_mul( mX, quat.mZ ) ), spu_sub( spu_add( spu_add( spu_mul( mW, quat.mY ), spu_mul( mY, quat.mW ) ), spu_mul( mZ, quat.mX ) ), spu_mul( mX, quat.mZ ) ),
spu_sub( spu_add( spu_add( spu_mul( mW, quat.mZ ), spu_mul( mZ, quat.mW ) ), spu_mul( mX, quat.mY ) ), spu_mul( mY, quat.mX ) ), spu_sub( spu_add( spu_add( spu_mul( mW, quat.mZ ), spu_mul( mZ, quat.mW ) ), spu_mul( mX, quat.mY ) ), spu_mul( mY, quat.mX ) ),
spu_sub( spu_sub( spu_sub( spu_mul( mW, quat.mW ), spu_mul( mX, quat.mX ) ), spu_mul( mY, quat.mY ) ), spu_mul( mZ, quat.mZ ) ) spu_sub( spu_sub( spu_sub( spu_mul( mW, quat.mW ), spu_mul( mX, quat.mX ) ), spu_mul( mY, quat.mY ) ), spu_mul( mZ, quat.mZ ) )
); );
} }
inline Quat & Quat::operator *=( const Quat & quat ) inline Quat & Quat::operator *=( const Quat & quat )
{ {
*this = *this * quat; *this = *this * quat;
return *this; return *this;
} }
inline const Vector3 rotate( const Quat & quat, const Vector3 & vec ) inline const Vector3 rotate( const Quat & quat, const Vector3 & vec )
{ {
vec_float4 tmpX, tmpY, tmpZ, tmpW; vec_float4 tmpX, tmpY, tmpZ, tmpW;
tmpX = spu_sub( spu_add( spu_mul( quat.getW(), vec.getX() ), spu_mul( quat.getY(), vec.getZ() ) ), spu_mul( quat.getZ(), vec.getY() ) ); tmpX = spu_sub( spu_add( spu_mul( quat.getW(), vec.getX() ), spu_mul( quat.getY(), vec.getZ() ) ), spu_mul( quat.getZ(), vec.getY() ) );
tmpY = spu_sub( spu_add( spu_mul( quat.getW(), vec.getY() ), spu_mul( quat.getZ(), vec.getX() ) ), spu_mul( quat.getX(), vec.getZ() ) ); tmpY = spu_sub( spu_add( spu_mul( quat.getW(), vec.getY() ), spu_mul( quat.getZ(), vec.getX() ) ), spu_mul( quat.getX(), vec.getZ() ) );
tmpZ = spu_sub( spu_add( spu_mul( quat.getW(), vec.getZ() ), spu_mul( quat.getX(), vec.getY() ) ), spu_mul( quat.getY(), vec.getX() ) ); tmpZ = spu_sub( spu_add( spu_mul( quat.getW(), vec.getZ() ), spu_mul( quat.getX(), vec.getY() ) ), spu_mul( quat.getY(), vec.getX() ) );
tmpW = spu_add( spu_add( spu_mul( quat.getX(), vec.getX() ), spu_mul( quat.getY(), vec.getY() ) ), spu_mul( quat.getZ(), vec.getZ() ) ); tmpW = spu_add( spu_add( spu_mul( quat.getX(), vec.getX() ), spu_mul( quat.getY(), vec.getY() ) ), spu_mul( quat.getZ(), vec.getZ() ) );
return Vector3( return Vector3(
spu_add( spu_sub( spu_add( spu_mul( tmpW, quat.getX() ), spu_mul( tmpX, quat.getW() ) ), spu_mul( tmpY, quat.getZ() ) ), spu_mul( tmpZ, quat.getY() ) ), spu_add( spu_sub( spu_add( spu_mul( tmpW, quat.getX() ), spu_mul( tmpX, quat.getW() ) ), spu_mul( tmpY, quat.getZ() ) ), spu_mul( tmpZ, quat.getY() ) ),
spu_add( spu_sub( spu_add( spu_mul( tmpW, quat.getY() ), spu_mul( tmpY, quat.getW() ) ), spu_mul( tmpZ, quat.getX() ) ), spu_mul( tmpX, quat.getZ() ) ), spu_add( spu_sub( spu_add( spu_mul( tmpW, quat.getY() ), spu_mul( tmpY, quat.getW() ) ), spu_mul( tmpZ, quat.getX() ) ), spu_mul( tmpX, quat.getZ() ) ),
spu_add( spu_sub( spu_add( spu_mul( tmpW, quat.getZ() ), spu_mul( tmpZ, quat.getW() ) ), spu_mul( tmpX, quat.getY() ) ), spu_mul( tmpY, quat.getX() ) ) spu_add( spu_sub( spu_add( spu_mul( tmpW, quat.getZ() ), spu_mul( tmpZ, quat.getW() ) ), spu_mul( tmpX, quat.getY() ) ), spu_mul( tmpY, quat.getX() ) )
); );
} }
inline const Quat conj( const Quat & quat ) inline const Quat conj( const Quat & quat )
{ {
return Quat( negatef4( quat.getX() ), negatef4( quat.getY() ), negatef4( quat.getZ() ), quat.getW() ); return Quat( negatef4( quat.getX() ), negatef4( quat.getY() ), negatef4( quat.getZ() ), quat.getW() );
} }
inline const Quat select( const Quat & quat0, const Quat & quat1, vec_uint4 select1 ) inline const Quat select( const Quat & quat0, const Quat & quat1, vec_uint4 select1 )
{ {
return Quat( return Quat(
spu_sel( quat0.getX(), quat1.getX(), select1 ), spu_sel( quat0.getX(), quat1.getX(), select1 ),
spu_sel( quat0.getY(), quat1.getY(), select1 ), spu_sel( quat0.getY(), quat1.getY(), select1 ),
spu_sel( quat0.getZ(), quat1.getZ(), select1 ), spu_sel( quat0.getZ(), quat1.getZ(), select1 ),
spu_sel( quat0.getW(), quat1.getW(), select1 ) spu_sel( quat0.getW(), quat1.getW(), select1 )
); );
} }
#ifdef _VECTORMATH_DEBUG #ifdef _VECTORMATH_DEBUG
inline void print( const Quat & quat ) inline void print( const Quat & quat )
{ {
Aos::Quat vec0, vec1, vec2, vec3; Aos::Quat vec0, vec1, vec2, vec3;
quat.get4Aos( vec0, vec1, vec2, vec3 ); quat.get4Aos( vec0, vec1, vec2, vec3 );
printf("slot 0:\n"); printf("slot 0:\n");
print( vec0 ); print( vec0 );
printf("slot 1:\n"); printf("slot 1:\n");
print( vec1 ); print( vec1 );
printf("slot 2:\n"); printf("slot 2:\n");
print( vec2 ); print( vec2 );
printf("slot 3:\n"); printf("slot 3:\n");
print( vec3 ); print( vec3 );
} }
inline void print( const Quat & quat, const char * name ) inline void print( const Quat & quat, const char * name )
{ {
Aos::Quat vec0, vec1, vec2, vec3; Aos::Quat vec0, vec1, vec2, vec3;
printf( "%s:\n", name ); printf( "%s:\n", name );
quat.get4Aos( vec0, vec1, vec2, vec3 ); quat.get4Aos( vec0, vec1, vec2, vec3 );
printf("slot 0:\n"); printf("slot 0:\n");
print( vec0 ); print( vec0 );
printf("slot 1:\n"); printf("slot 1:\n");
print( vec1 ); print( vec1 );
printf("slot 2:\n"); printf("slot 2:\n");
print( vec2 ); print( vec2 );
printf("slot 3:\n"); printf("slot 3:\n");
print( vec3 ); print( vec3 );
} }
#endif #endif
} // namespace Soa } // namespace Soa
} // namespace Vectormath } // namespace Vectormath
#endif #endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,64 +1,64 @@
/* /*
Copyright (C) 2006, 2007 Sony Computer Entertainment Inc. Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the with or without modification, are permitted provided that the
following conditions are met: following conditions are met:
* Redistributions of source code must retain the above copyright * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright * Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
* Neither the name of the Sony Computer Entertainment Inc nor the names * Neither the name of the Sony Computer Entertainment Inc nor the names
of its contributors may be used to endorse or promote products derived of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission. from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef _VECTORMATH_VECIDX_AOS_H #ifndef _VECTORMATH_VECIDX_AOS_H
#define _VECTORMATH_VECIDX_AOS_H #define _VECTORMATH_VECIDX_AOS_H
#include <spu_intrinsics.h> #include <spu_intrinsics.h>
namespace Vectormath { namespace Vectormath {
namespace Aos { namespace Aos {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// VecIdx // VecIdx
// Used in setting elements of Vector3, Vector4, Point3, or Quat with the // Used in setting elements of Vector3, Vector4, Point3, or Quat with the
// subscripting operator. // subscripting operator.
// //
class VecIdx class VecIdx
{ {
private: private:
typedef vec_float4 vec_float4_t; typedef vec_float4 vec_float4_t;
vec_float4_t &ref __attribute__ ((aligned(16))); vec_float4_t &ref __attribute__ ((aligned(16)));
int i __attribute__ ((aligned(16))); int i __attribute__ ((aligned(16)));
public: public:
inline VecIdx( vec_float4& vec, int idx ): ref(vec) { i = idx; } inline VecIdx( vec_float4& vec, int idx ): ref(vec) { i = idx; }
inline operator float() const; inline operator float() const;
inline float operator =( float scalar ); inline float operator =( float scalar );
inline float operator =( const VecIdx& scalar ); inline float operator =( const VecIdx& scalar );
inline float operator *=( float scalar ); inline float operator *=( float scalar );
inline float operator /=( float scalar ); inline float operator /=( float scalar );
inline float operator +=( float scalar ); inline float operator +=( float scalar );
inline float operator -=( float scalar ); inline float operator -=( float scalar );
}; };
} // namespace Aos } // namespace Aos
} // namespace Vectormath } // namespace Vectormath
#endif #endif

View File

@@ -1,109 +1,109 @@
#!/usr/bin/perl #!/usr/bin/perl
# #
# Copyright (C) 2006, 2007 Sony Computer Entertainment Inc. # Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, # Redistribution and use in source and binary forms,
# with or without modification, are permitted provided that the # with or without modification, are permitted provided that the
# following conditions are met: # following conditions are met:
# * Redistributions of source code must retain the above copyright # * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer. # notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright # * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the # notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution. # documentation and/or other materials provided with the distribution.
# * Neither the name of the Sony Computer Entertainment Inc nor the names # * Neither the name of the Sony Computer Entertainment Inc nor the names
# of its contributors may be used to endorse or promote products derived # of its contributors may be used to endorse or promote products derived
# from this software without specific prior written permission. # from this software without specific prior written permission.
# #
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # 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 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE. # POSSIBILITY OF SUCH DAMAGE.
# #
$lineno = 0; $lineno = 0;
sub getLine sub getLine
{ {
local( $line ); local( $line );
$line = <STDIN>; $line = <STDIN>;
while( $line =~ m/^lv2\([^\)]*\)\:$/ ) while( $line =~ m/^lv2\([^\)]*\)\:$/ )
{ {
$line = <STDIN>; $line = <STDIN>;
} }
$line =~ s/^lv2\([^\)]*\)\: //; $line =~ s/^lv2\([^\)]*\)\: //;
return $line; return $line;
} }
while(($line = <STDIN>) !~ m/__begin__/) while(($line = <STDIN>) !~ m/__begin__/)
{ {
} }
$countSlotLines = 0; $countSlotLines = 0;
while( $line = &getLine ) while( $line = &getLine )
{ {
$lineno++; $lineno++;
if ( $line =~ m/__end__/ ) if ( $line =~ m/__end__/ )
{ {
exit; exit;
} }
# if soa print, only save first slot # if soa print, only save first slot
if ( $line =~ m/^slot ([1-3])/ ) if ( $line =~ m/^slot ([1-3])/ )
{ {
while ( $line =~ m/^slot [1-3]/ ) while ( $line =~ m/^slot [1-3]/ )
{ {
# skip all lines for this slot # skip all lines for this slot
for ( $i = 0; $i < $slotLines; $i++ ) for ( $i = 0; $i < $slotLines; $i++ )
{ {
$line = &getLine; $line = &getLine;
} }
# get next line # get next line
$line = &getLine; $line = &getLine;
} }
# stop counting slot lines # stop counting slot lines
$countSlotLines = 0; $countSlotLines = 0;
} }
elsif ( $countSlotLines ) elsif ( $countSlotLines )
{ {
$slotLines++; $slotLines++;
} }
if ( $line =~ m/^slot 0\:(.?)/ ) if ( $line =~ m/^slot 0\:(.?)/ )
{ {
$countSlotLines = 1; $countSlotLines = 1;
if ( $1 eq ' ' ) if ( $1 eq ' ' )
{ {
$line =~ s/^slot 0\: //; $line =~ s/^slot 0\: //;
$slotLines = 0; $slotLines = 0;
} }
else else
{ {
$line = &getLine; $line = &getLine;
$slotLines = 1; $slotLines = 1;
} }
} }
print $line; print $line;
} }

View File

@@ -1,95 +1,95 @@
#!/usr/bin/perl #!/usr/bin/perl
# #
# Copyright (C) 2006, 2007 Sony Computer Entertainment Inc. # Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, # Redistribution and use in source and binary forms,
# with or without modification, are permitted provided that the # with or without modification, are permitted provided that the
# following conditions are met: # following conditions are met:
# * Redistributions of source code must retain the above copyright # * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer. # notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright # * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the # notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution. # documentation and/or other materials provided with the distribution.
# * Neither the name of the Sony Computer Entertainment Inc nor the names # * Neither the name of the Sony Computer Entertainment Inc nor the names
# of its contributors may be used to endorse or promote products derived # of its contributors may be used to endorse or promote products derived
# from this software without specific prior written permission. # from this software without specific prior written permission.
# #
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # 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 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE. # POSSIBILITY OF SUCH DAMAGE.
# #
$file1 = $ARGV[0]; $file1 = $ARGV[0];
$file2 = $ARGV[1]; $file2 = $ARGV[1];
if (!open(FILE1, "<$file1")) if (!open(FILE1, "<$file1"))
{ {
print "Couldn't open $file1\n"; print "Couldn't open $file1\n";
exit; exit;
} }
if (!open(FILE2, "<$file2")) if (!open(FILE2, "<$file2"))
{ {
print "Couldn't open $file2\n"; print "Couldn't open $file2\n";
exit; exit;
} }
print "Comparing $file1 $file2\n"; print "Comparing $file1 $file2\n";
$lineno1 = 0; $lineno1 = 0;
$lineno2 = 0; $lineno2 = 0;
while(($line1 = <FILE1>) && ($line2 = <FILE2>)) while(($line1 = <FILE1>) && ($line2 = <FILE2>))
{ {
$lineno1++; $lineno1++;
$lineno2++; $lineno2++;
if ( $line1 =~ m/\:$/ ) if ( $line1 =~ m/\:$/ )
{ {
$line1 = <FILE1>; $line1 = <FILE1>;
$lineno1++; $lineno1++;
} }
if ( $line2 =~ m/\:$/ ) if ( $line2 =~ m/\:$/ )
{ {
$line2 = <FILE2>; $line2 = <FILE2>;
$lineno2++; $lineno2++;
} }
$line1 =~ s/^.*\: //g; $line1 =~ s/^.*\: //g;
$line2 =~ s/^.*\: //g; $line2 =~ s/^.*\: //g;
@words1 = split(/ /,$line1); @words1 = split(/ /,$line1);
@words2 = split(/ /,$line2); @words2 = split(/ /,$line2);
for ($i = 0; $i < @words1; $i++) for ($i = 0; $i < @words1; $i++)
{ {
$word1 = $words1[$i]; $word1 = $words1[$i];
$word2 = $words2[$i]; $word2 = $words2[$i];
$word1 =~ s/\s//g; $word1 =~ s/\s//g;
$word2 =~ s/\s//g; $word2 =~ s/\s//g;
if ( $word1 ne $word2 ) if ( $word1 ne $word2 )
{ {
$error = abs($word1 - $word2); $error = abs($word1 - $word2);
$limit = abs(1e-4 * $word1); $limit = abs(1e-4 * $word1);
if ( $error > $limit && !( abs($word1) < 1e-4 && $error < 1e-4 ) ) if ( $error > $limit && !( abs($word1) < 1e-4 && $error < 1e-4 ) )
{ {
print "$lineno1: $word1 $lineno2: $word2\n"; print "$lineno1: $word1 $lineno2: $word2\n";
} }
} }
} }
} }

View File

@@ -1,81 +1,81 @@
%define lib_version 1.0.1 %define lib_version 1.0.1
Summary: Vector math library Summary: Vector math library
Name: vectormath Name: vectormath
Version: %{lib_version} Version: %{lib_version}
Release: 1 Release: 1
License: BSD License: BSD
Group: Development/Libraries Group: Development/Libraries
Source0: %{name}-%{version}.tar.gz Source0: %{name}-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
%description %description
Vector math library. Vector math library.
%ifarch ppc ppc64 %ifarch ppc ppc64
%define _lib_arch ppu %define _lib_arch ppu
%endif %endif
%ifarch i386 x86_64 %ifarch i386 x86_64
%define _lib_arch SSE %define _lib_arch SSE
%endif %endif
%if %{undefined _lib_arch} %if %{undefined _lib_arch}
%define _lib_arch scalar %define _lib_arch scalar
%endif %endif
%package -n %{name}-devel %package -n %{name}-devel
Summary: Vector math library. Summary: Vector math library.
Group: Development/Libraries Group: Development/Libraries
%ifarch ppc ppc64 %ifarch ppc ppc64
Requires: simdmath-devel Requires: simdmath-devel
%endif %endif
%description -n %{name}-devel %description -n %{name}-devel
Vector math library. Vector math library.
%ifarch ppc ppc64 %ifarch ppc ppc64
%package -n spu-%{name}-devel %package -n spu-%{name}-devel
Summary: Vector math library. Summary: Vector math library.
Group: Development/Libraries Group: Development/Libraries
Requires: spu-simdmath-devel Requires: spu-simdmath-devel
%description -n spu-%{name}-devel %description -n spu-%{name}-devel
Vector math library. Vector math library.
%endif %endif
%prep %prep
%setup -q %setup -q
%build %build
%install %install
rm -rf %{buildroot} rm -rf %{buildroot}
make ARCH=%{_lib_arch} DESTDIR=%{buildroot} install make ARCH=%{_lib_arch} DESTDIR=%{buildroot} install
%ifarch ppc ppc64 %ifarch ppc ppc64
make ARCH=spu DESTDIR=%{buildroot} install make ARCH=spu DESTDIR=%{buildroot} install
%endif %endif
mkdir -p %{buildroot}/%{_docdir}/%{name}-%{version} mkdir -p %{buildroot}/%{_docdir}/%{name}-%{version}
cp README LICENSE doc/*.pdf %{buildroot}/%{_docdir}/%{name}-%{version}/ cp README LICENSE doc/*.pdf %{buildroot}/%{_docdir}/%{name}-%{version}/
%clean %clean
rm -rf %{buildroot} rm -rf %{buildroot}
%files -n %{name}-devel %files -n %{name}-devel
%defattr(-,root,root,-) %defattr(-,root,root,-)
%{_includedir}/* %{_includedir}/*
%{_docdir}/* %{_docdir}/*
%ifarch ppc ppc64 %ifarch ppc ppc64
%files -n spu-%{name}-devel %files -n spu-%{name}-devel
%defattr(-,root,root,-) %defattr(-,root,root,-)
%{_prefix}/spu/include/* %{_prefix}/spu/include/*
%endif %endif
%changelog %changelog
* Wed Aug 8 2007 Kazunori Asayama <asayama@sm.sony.co.jp> - 1.0.1-1 * Wed Aug 8 2007 Kazunori Asayama <asayama@sm.sony.co.jp> - 1.0.1-1
- Initial build. - Initial build.