* Fix CVector3f SSE4.1

* Add CColor
This commit is contained in:
Phillip Stephens 2015-04-30 23:31:59 -07:00
parent 5df0bae045
commit 17956988dd
4 changed files with 73 additions and 1 deletions

70
CColor.hpp Normal file
View File

@ -0,0 +1,70 @@
#ifndef CCOLOR_HPP
#define CCOLOR_HPP
#include "MathLib.hpp"
#include <iostream>
class CColor
{
public:
ZE_DECLARE_ALIGNED_ALLOCATOR();
CColor() : r(1.0f), g(1.0f), b(1.0f), a(1.0f) {}
CColor(float r, float g, float b, float a = 1.0f)
: r(r), g(g), b(b), a(a)
{
}
CColor(Athena::io::IStreamReader& reader) {readRGBA(reader);}
inline void readRGBA(Athena::io::IStreamReader& reader)
{
r = reader.readFloat();
g = reader.readFloat();
b = reader.readFloat();
a = reader.readFloat();
}
inline void readBGRA(Athena::io::IStreamReader& reader)
{
b = reader.readFloat();
g = reader.readFloat();
r = reader.readFloat();
a = reader.readFloat();
}
inline float operator[](const int& idx) { return (&r)[idx]; }
union
{
struct
{
float r, g, b, a;
};
#if __SSE__
__m128 mVec128;
#endif
};
void fromRGBA32(unsigned int rgba)
{
union
{
struct
{
unsigned char r, g, b, a;
};
unsigned int rgba;
} tmp =
{
.rgba = rgba
};
r = tmp.r / 255.f;
g = tmp.g / 255.f;
b = tmp.b / 255.f;
a = tmp.a / 255.f;
}
};
#endif // CCOLOR_HPP

View File

@ -185,7 +185,7 @@ public:
{
#if __SSE4_1__
TVectorUnion result;
result.mVec128 = _mm_dp_ps(mVec128, rhs.mVec128, 0x71);
result.mVec128 = _mm_dp_ps(mVec128, mVec128, 0x71);
return result.v[0];
#elif __SSE__
TVectorUnion result;

View File

@ -9,6 +9,7 @@
#include "CVector3d.hpp"
#include "CVector3f.hpp"
#include "CPlane.hpp"
#include "CColor.hpp"
#include "Global.hpp"
#include "Math.hpp"

View File

@ -18,6 +18,7 @@ HEADERS += \
$$PWD/CAxisAngle.hpp \
$$PWD/CPlane.hpp \
$$PWD/CTransform.hpp \
$$PWD/CColor.hpp \
$$PWD/Global.hpp \
$$PWD/MathLib.hpp