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

View File

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

View File

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