Skip to content

Commit

Permalink
Move rotation functions to legacy math
Browse files Browse the repository at this point in the history
  • Loading branch information
Eli2 committed Mar 29, 2015
1 parent c9a35c1 commit 5cd7d30
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 19 deletions.
20 changes: 2 additions & 18 deletions src/graphics/particle/ParticleSystem.cpp
Expand Up @@ -183,22 +183,6 @@ void ParticleSystem::SetTexture(const char * _pszTex, int _iNbTex, int _iTime) {
}
}

static void VectorRotateY(Vec3f & _eIn, Vec3f & _eOut, float _fAngle) {
float c = std::cos(_fAngle);
float s = std::sin(_fAngle);
_eOut.x = (_eIn.x * c) + (_eIn.z * s);
_eOut.y = _eIn.y;
_eOut.z = (_eIn.z * c) - (_eIn.x * s);
}

static void VectorRotateZ(Vec3f & _eIn, Vec3f & _eOut, float _fAngle) {
float c = std::cos(_fAngle);
float s = std::sin(_fAngle);
_eOut.x = (_eIn.x * c) + (_eIn.y * s);
_eOut.y = (_eIn.y * c) - (_eIn.x * s);
_eOut.z = _eIn.z;
}

void ParticleSystem::SetParticleParams(Particle * pP) {

pP->p3Pos = Vec3f_ZERO;
Expand Down Expand Up @@ -231,8 +215,8 @@ void ParticleSystem::SetParticleParams(Particle * pP) {

vv1 = -Vec3f_Y_AXIS;

VectorRotateZ(vv1, vvz, fAngleX);
VectorRotateY(vvz, vv1, glm::radians(rnd() * 360.0f));
vvz = VRotateZ(vv1, glm::degrees(fAngleX));
vv1 = VRotateY(vvz, rnd() * 360.0f);

vvz = Vec3f(eMat * Vec4f(vv1, 1.f));

Expand Down
15 changes: 14 additions & 1 deletion tests/math/LegacyMath.h
Expand Up @@ -245,8 +245,21 @@ Vec3f camEE_RT(const Vec3f & in, const EERIE_TRANSFORM & trans) {
return Vec3f(temp2.x, temp2.y, temp3.z);
}

void VectorRotateY(Vec3f & _eIn, Vec3f & _eOut, float _fAngle) {
float c = std::cos(_fAngle);
float s = std::sin(_fAngle);
_eOut.x = (_eIn.x * c) + (_eIn.z * s);
_eOut.y = _eIn.y;
_eOut.z = (_eIn.z * c) - (_eIn.x * s);
}


void VectorRotateZ(Vec3f & _eIn, Vec3f & _eOut, float _fAngle) {
float c = std::cos(_fAngle);
float s = std::sin(_fAngle);
_eOut.x = (_eIn.x * c) + (_eIn.y * s);
_eOut.y = (_eIn.y * c) - (_eIn.x * s);
_eOut.z = _eIn.z;
}


Vec2s inventorySizeFromTextureSize_1(u32 m_dwWidth, u32 m_dwHeight) {
Expand Down
29 changes: 29 additions & 0 deletions tests/math/LegacyMathTest.cpp
Expand Up @@ -293,3 +293,32 @@ void LegacyMathTest::angleToVectorXZ_Test() {
CPPUNIT_ASSERT_EQUAL(expected, result2);
}
}

void LegacyMathTest::vectorRotateTest() {

for(float angle = 0; angle < 720; angle += 10) {

Vec3f foo = Vec3f(0.f, 0.f, 1.f);

Vec3f result;
VectorRotateY(foo, result, glm::radians(angle));

Vec3f result2 = VRotateY(foo, angle);

CPPUNIT_ASSERT_EQUAL(result, result2);
}

for(float angle = 0; angle < 720; angle += 10) {

Vec3f foo = Vec3f(1.f, 0.f, 0.f);

Vec3f result;
VectorRotateZ(foo, result, glm::radians(angle));

Vec3f result2 = VRotateZ(foo, angle);

//std::cout << angle << "; " << glm::to_string(result) << glm::to_string(result2) << "\n";

CPPUNIT_ASSERT_EQUAL(result, result2);
}
}
3 changes: 3 additions & 0 deletions tests/math/LegacyMathTest.h
Expand Up @@ -38,6 +38,7 @@ class LegacyMathTest : public CppUnit::TestFixture {
CPPUNIT_TEST(cameraRotationTest);
CPPUNIT_TEST(inventorySizeTest);
CPPUNIT_TEST(angleToVectorXZ_Test);
CPPUNIT_TEST(vectorRotateTest);
CPPUNIT_TEST_SUITE_END();

public:
Expand All @@ -62,6 +63,8 @@ class LegacyMathTest : public CppUnit::TestFixture {
void inventorySizeTest();

void angleToVectorXZ_Test();

void vectorRotateTest();
};

#endif // ARX_TESTS_GRAPHICS_LEGACYMATHTEST_H

0 comments on commit 5cd7d30

Please sign in to comment.