From 078751a820bd7b46a820a0c08100454d019477c6 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Sun, 31 May 2015 19:52:12 +0000 Subject: [PATCH] math: all API functions dealing with angles now use radians. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We already have the convenient degrees() and radians() functions to convert between angle formats. This commit involves a lot of refactoring here and there and I may have missed some places where conversions were needed. But hopefully there aren’t may such places. --- doc/samples/btphystest.cpp | 24 ++++---- doc/samples/meshviewer/meshviewer.cpp | 35 +++++------ doc/samples/meshviewer/meshviewer.h | 8 ++- doc/samples/nacl_phystest.cpp | 14 +++-- doc/samples/simplex.cpp | 20 ++++--- doc/tutorial/02_cube.cpp | 4 +- doc/tutorial/05_easymesh.cpp | 18 +++--- doc/tutorial/07_input.cpp | 2 +- src/camera.cpp | 8 +-- src/easymesh/easymeshprimitive.cpp | 40 +++++++------ src/easymesh/easymeshtransform.cpp | 26 +++++---- src/lol/math/matrix.h | 30 +++++----- src/lol/math/transform.h | 8 +-- src/math/matrix.cpp | 34 ++++++----- src/math/transform.cpp | 19 +++--- src/scene.cpp | 4 +- src/t/entity/camera.cpp | 4 +- src/t/math/quat.cpp | 20 +++---- src/t/math/rotation.cpp | 84 +++++++++++++-------------- src/t/math/sqt.cpp | 2 +- 20 files changed, 212 insertions(+), 192 deletions(-) diff --git a/doc/samples/btphystest.cpp b/doc/samples/btphystest.cpp index 1593441a..0f5ce39b 100644 --- a/doc/samples/btphystest.cpp +++ b/doc/samples/btphystest.cpp @@ -1,10 +1,10 @@ // -// BtPhysTest +// Lol Engine — BtPhys tutorial // // Copyright © 2009—2015 Benjamin “Touky” Huet // © 2012—2015 Sam Hocevar // -// This program is free software. It comes without any warranty, to +// Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it // and/or modify it under the terms of the Do What the Fuck You Want // to Public License, Version 2, as published by the WTFPL Task Force. @@ -105,14 +105,14 @@ void BtPhysTest::InitApp() m_camera->SetView(vec3(70.f, 50.f, 0.f), vec3(0.f, 0.f, 0.f), vec3(0, 1, 0)); - m_camera->SetProjection(60.f, .1f, 1000.f, (float)Video::GetSize().x, (float)Video::GetSize().y / (float)Video::GetSize().x); + m_camera->SetProjection(radians(60.f), .1f, 1000.f, (float)Video::GetSize().x, (float)Video::GetSize().y / (float)Video::GetSize().x); m_target_timer = TARGET_TIMER; m_cam_target = -1; #else m_camera->SetView(vec3(50.f, 50.f, 0.f), vec3(0.f, 0.f, 0.f), vec3(0, 1, 0)); - m_camera->SetProjection(45.f, .1f, 1000.f, (float)Video::GetSize().x, (float)Video::GetSize().y / (float)Video::GetSize().x); + m_camera->SetProjection(radians(45.f), .1f, 1000.f, (float)Video::GetSize().x, (float)Video::GetSize().y / (float)Video::GetSize().x); #endif Scene& scene = Scene::GetScene(); scene.PushCamera(m_camera); @@ -150,7 +150,7 @@ void BtPhysTest::InitApp() quat NewRotation = quat::fromeuler_xyz(0.f, 0.f, 0.f); vec3 NewPosition = pos_offset + vec3(5.0f, -29.f, 15.0f); { - NewRotation = quat::fromeuler_xyz(0.f, 0.f, 30.f); + NewRotation = quat::fromeuler_xyz(0.f, 0.f, radians(30.f)); NewPosition += vec3(4.0f, .0f, -4.0f); PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 3); @@ -158,7 +158,7 @@ void BtPhysTest::InitApp() m_stairs_list << NewPhyobj; } { - NewRotation = quat::fromeuler_xyz(0.f, 0.f, 40.f); + NewRotation = quat::fromeuler_xyz(0.f, 0.f, radians(40.f)); NewPosition += vec3(4.0f, .0f, -4.0f); PhysicsObject* NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 3); @@ -196,7 +196,7 @@ void BtPhysTest::InitApp() { vec3 NewAxis = vec3(.0f); NewAxis[2 - idx] = 1; - NewRotation = quat::rotate(90.f, NewAxis); + NewRotation = quat::rotate(radians(90.f), NewAxis); } NewPhyobj->SetTransform(NewPosition, NewRotation); @@ -225,7 +225,7 @@ void BtPhysTest::InitApp() m_platform_list << NewPhyobj; Ticker::Ref(NewPhyobj); - NewRotation = quat::fromeuler_xyz(0.f, 0.f, 90.f); + NewRotation = quat::fromeuler_xyz(0.f, 0.f, radians(90.f)); NewPosition = pos_offset + vec3(-20.0f, -25.0f, 5.0f); NewPhyobj = new PhysicsObject(m_simulation, NewPosition, NewRotation, 1); @@ -517,7 +517,7 @@ void BtPhysTest::TickGame(float seconds) m_loc_dp = damp(m_loc_dp, loc_dp, 0.08f, seconds); m_camera->SetFov(damp(m_camera->GetFov(), m_camera->GetFov() * fov_ratio * 1.1f, m_fov_dp, seconds)); vec3 tmp = damp(m_camera->GetTarget(), new_target, m_loc_dp, seconds); - m_camera->SetView((mat4::rotate(10.f * seconds, vec3(.0f, 1.f, .0f)) * vec4(m_camera->GetPosition(), 1.0f)).xyz, + m_camera->SetView((mat4::rotate(radians(10.f) * seconds, vec3(.0f, 1.f, .0f)) * vec4(m_camera->GetPosition(), 1.0f)).xyz, tmp, vec3(0, 1, 0)); #endif //USE_BODIES #endif //CAT_MODE @@ -562,7 +562,7 @@ void BtPhysTest::TickGame(float seconds) mat4 CenterMx = mat4::translate(GroundBarycenter); GroundMat = inverse(CenterMx) * GroundMat; GroundMat = CenterMx * - mat4(quat::fromeuler_xyz(vec3(.0f, 20.f, 20.0f) * seconds)) + mat4(quat::fromeuler_xyz(vec3(.0f, radians(20.f), radians(20.0f)) * seconds)) * GroundMat; PhysObj->SetTransform(GroundMat[3].xyz, quat(mat3(GroundMat))); } @@ -578,14 +578,14 @@ void BtPhysTest::TickGame(float seconds) mat4 GroundMat = PhysObj->GetTransform(); if (i == 0) { - GroundMat = GroundMat * mat4(quat::fromeuler_xyz(vec3(20.f, .0f, .0f) * seconds)); + GroundMat = GroundMat * mat4(quat::fromeuler_xyz(vec3(radians(20.f), .0f, .0f) * seconds)); PhysObj->SetTransform(GroundMat[3].xyz, quat(mat3(GroundMat))); } else if (i == 1) { GroundMat = mat4::translate(vec3(-15.0f, 5.0f, lol::cos(m_loop_value) * 8.f)) * - mat4(quat::fromeuler_xyz(vec3(.0f, lol::cos(m_loop_value) * 20.f, .0f))); + mat4(quat::fromeuler_xyz(vec3(.0f, lol::cos(m_loop_value) * radians(20.f), .0f))); PhysObj->SetTransform(GroundMat[3].xyz, quat(mat3(GroundMat))); } } diff --git a/doc/samples/meshviewer/meshviewer.cpp b/doc/samples/meshviewer/meshviewer.cpp index 3c1e57d0..f90cba87 100644 --- a/doc/samples/meshviewer/meshviewer.cpp +++ b/doc/samples/meshviewer/meshviewer.cpp @@ -1,13 +1,14 @@ - // -// Lol Engine - EasyMesh tutorial +// Lol Engine — EasyMesh tutorial +// +// Copyright © 2011—2015 Sam Hocevar +// © 2012—2015 Benjamin “Touky” Huet // -// Copyright: (c) 2011-2014 Sam Hocevar -// (c) 2012-2013 Benjamin "Touky" Huet -// This program is free software; you can redistribute it and/or -// modify it under the terms of the Do What The Fuck You Want To -// Public License, Version 2, as published by Sam Hocevar. See -// http://www.wtfpl.net/ for more details. +// Lol Engine is free software. It comes without any warranty, to +// the extent permitted by applicable law. You can redistribute it +// and/or modify it under the terms of the Do What the Fuck You Want +// to Public License, Version 2, as published by the WTFPL Task Force. +// See http://www.wtfpl.net/ for more details. // #if HAVE_CONFIG_H @@ -44,12 +45,12 @@ static int const TEXTURE_WIDTH = 256; #define SCREEN_LIMIT 1.4f #define RESET_TIMER .2f -#define ROT_SPEED vec2(50.f) -#define ROT_CLAMP 89.f +#define ROT_SPEED vec2(radians(50.f)) +#define ROT_CLAMP radians(89.f) #define POS_SPEED vec2(1.2f) #define POS_CLAMP 1.f -#define FOV_SPEED 20.f -#define FOV_CLAMP 120.f +#define FOV_SPEED radians(20.f) +#define FOV_CLAMP radians(120.f) #define ZOM_SPEED 3.f #define ZOM_CLAMP 20.f #define HST_SPEED .5f @@ -172,8 +173,8 @@ void MeshViewer::Start() //Camera setup m_camera = new Camera(); m_camera->SetView(vec3(10.f, 10.f, 10.f), vec3::zero, vec3::axis_y); - m_camera->SetProjection(40.f, .0001f, 200.f); - //m_camera->SetProjection(90.f, .0001f, 2000.f, WIDTH * SCREEN_W, RATIO_HW); + m_camera->SetProjection(radians(40.f), .0001f, 200.f); + //m_camera->SetProjection(radians(90.f), .0001f, 2000.f, WIDTH * SCREEN_W, RATIO_HW); //m_camera->UseShift(true); Scene& scene = Scene::GetScene(); scene.PushCamera(m_camera); @@ -294,7 +295,7 @@ void MeshViewer::TickGame(float seconds) #endif //HAS_INPUT static bool default_open = true; - //static float fov = 40.f; + //static float fov = radians(40.f); //static vec3 sphere_pos = vec3(20.f, 45.f, 45.f); //static bool use_custom_cam = true; //static float f; @@ -335,7 +336,7 @@ void MeshViewer::TickGame(float seconds) vec3 sphere_pos_rad = m_menu_cam_pos; sphere_pos_rad.z = (sphere_pos_rad.z > 0.f) ? (90.f - sphere_pos_rad.z) : (sphere_pos_rad.z - 90.f); sphere_pos_rad = vec3(sphere_pos_rad.x, radians(sphere_pos_rad.y), radians(sphere_pos_rad.z)); - m_camera->SetFov(m_menu_cam_fov); + m_camera->SetFov(radians(m_menu_cam_fov)); m_camera->SetPosition(cartesian(sphere_pos_rad)); m_camera->SetTarget(vec3::zero, vec3::axis_y); } @@ -449,7 +450,7 @@ void MeshViewer::Prepare() //Camera Setup m_reset_timer = -1.f; - m_fov = -100.f; + m_fov = radians(-100.f); m_fov_mesh = 0.f; m_fov_speed = 0.f; m_zoom = 0.f; diff --git a/doc/samples/meshviewer/meshviewer.h b/doc/samples/meshviewer/meshviewer.h index 0312d7bb..1b1f1a4f 100644 --- a/doc/samples/meshviewer/meshviewer.h +++ b/doc/samples/meshviewer/meshviewer.h @@ -1,7 +1,9 @@ // -// Copyright 2009-2015 Benjamin "Touky" Huet +// Lol Engine — EasyMesh tutorial // -// This program is free software. It comes without any warranty, to +// Copyright © 2009—2015 Benjamin “Touky” Huet +// +// Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it // and/or modify it under the terms of the Do What the Fuck You Want // to Public License, Version 2, as published by the WTFPL Task Force. @@ -255,7 +257,7 @@ private: //ImGui stuff bool m_menu_cam_useage = true; - float m_menu_cam_fov = 40.f; + float m_menu_cam_fov = radians(40.f); vec3 m_menu_cam_pos = vec3(20.f, 45.f, 45.f); int m_menu_mesh_idx = 0; array m_menu_mesh_names_char; diff --git a/doc/samples/nacl_phystest.cpp b/doc/samples/nacl_phystest.cpp index d16a92ba..946b74f3 100644 --- a/doc/samples/nacl_phystest.cpp +++ b/doc/samples/nacl_phystest.cpp @@ -1,8 +1,14 @@ // -// BtPhysTest +// Lol Engine — BtPhys tutorial // -// Copyright: (c) 2009-2013 Benjamin "Touky" Huet -// (c) 2012-2013 Sam Hocevar +// Copyright © 2009—2015 Benjamin “Touky” Huet +// © 2012—2015 Sam Hocevar +// +// Lol Engine is free software. It comes without any warranty, to +// the extent permitted by applicable law. You can redistribute it +// and/or modify it under the terms of the Do What the Fuck You Want +// to Public License, Version 2, as published by the WTFPL Task Force. +// See http://www.wtfpl.net/ for more details. // #if HAVE_CONFIG_H @@ -41,7 +47,7 @@ Nacl_PhysTest::Nacl_PhysTest(bool editor) m_camera->SetView(vec3(50.f, 50.f, 0.f), vec3(0.f, 0.f, 0.f), vec3(0, 1, 0)); - m_camera->SetProjection(45.f, .1f, 1000.f, (float)Video::GetSize().x, (float)Video::GetSize().y / (float)Video::GetSize().x); + m_camera->SetProjection(radians(45.f), .1f, 1000.f, (float)Video::GetSize().x, (float)Video::GetSize().y / (float)Video::GetSize().x); Scene::GetScene().PushCamera(m_camera); m_ready = false; diff --git a/doc/samples/simplex.cpp b/doc/samples/simplex.cpp index cb0be2e6..1b7404fe 100644 --- a/doc/samples/simplex.cpp +++ b/doc/samples/simplex.cpp @@ -1,12 +1,14 @@ // -// Simplex Noise Test Program +// Lol Engine — Simplex Noise tutorial // -// Copyright (c) 2010-2014 Sam Hocevar -// (c) 2013-2014 Guillaume Bittoun -// This program is free software; you can redistribute it and/or -// modify it under the terms of the Do What The Fuck You Want To -// Public License, Version 2, as published by Sam Hocevar. See -// http://www.wtfpl.net/ for more details. +// Copyright © 2010—2015 Sam Hocevar +// © 2013-2014 Guillaume Bittoun +// +// Lol Engine is free software. It comes without any warranty, to +// the extent permitted by applicable law. You can redistribute it +// and/or modify it under the terms of the Do What the Fuck You Want +// to Public License, Version 2, as published by the WTFPL Task Force. +// See http://www.wtfpl.net/ for more details. // #if HAVE_CONFIG_H @@ -114,8 +116,8 @@ int main(int argc, char **argv) #if 0 /* Mark simplex vertices */ vec2 diagonal = normalize(vec2(1.f)); - vec2 dx = mat2::rotate(60.f) * diagonal; - vec2 dy = mat2::rotate(-60.f) * diagonal; + vec2 dx = mat2::rotate(radians(60.f)) * diagonal; + vec2 dy = mat2::rotate(radians(-60.f)) * diagonal; for (int j = -100; j < 100; ++j) for (int i = -100; i < 100; ++i) { diff --git a/doc/tutorial/02_cube.cpp b/doc/tutorial/02_cube.cpp index bb06270d..347adedb 100644 --- a/doc/tutorial/02_cube.cpp +++ b/doc/tutorial/02_cube.cpp @@ -50,12 +50,12 @@ public: { WorldEntity::TickGame(seconds); - m_angle += seconds * 45.0f; + m_angle += seconds * radians(45.0f); mat4 anim = mat4::rotate(m_angle, vec3(0, 1, 0)); mat4 model = mat4::translate(vec3(0, 0, -4.5)); mat4 view = mat4::lookat(vec3(0, 2, 0), vec3(0, 0, -4), vec3(0, 1, 0)); - mat4 proj = mat4::perspective(45.0f, 640.0f, 480.0f, 0.1f, 10.0f); + mat4 proj = mat4::perspective(radians(45.0f), 640.0f, 480.0f, 0.1f, 10.0f); m_matrix = proj * view * model * anim; } diff --git a/doc/tutorial/05_easymesh.cpp b/doc/tutorial/05_easymesh.cpp index 19547318..44986f7b 100644 --- a/doc/tutorial/05_easymesh.cpp +++ b/doc/tutorial/05_easymesh.cpp @@ -60,7 +60,7 @@ public: m_angle = 0; m_camera = new Camera(); - m_camera->SetProjection(mat4::perspective(30.f, 960.f, 600.f, .1f, 1000.f)); + m_camera->SetProjection(mat4::perspective(radians(30.f), 960.f, 600.f, .1f, 1000.f)); m_camera->SetView(mat4::lookat(vec3(-15.f, 5.f, 0.f), vec3(0.f, -1.f, 0.f), vec3(0.f, 1.f, 0.f))); @@ -96,16 +96,16 @@ public: { WorldEntity::TickGame(seconds); - m_angle += seconds * 70.0f; - m_mat = mat4::rotate(10.0f, vec3(0, 0, 1)) - * mat4::rotate(100, vec3(0, 1, 0)); + m_angle += seconds * radians(70.0f); + m_mat = mat4::rotate(radians(10.0f), vec3(0, 0, 1)) + * mat4::rotate(radians(100.f), vec3(0, 1, 0)); // * mat4::rotate(m_angle, vec3(0, 1, 0)); - m_gears[0].m3 += seconds * 20.0f; - m_gears[1].m3 += seconds * 20.0f * -2 / 9; - m_gears[2].m3 += seconds * 20.0f * -2 / 3; - m_gears[3].m3 += seconds * 20.0f * -2 / 3; - m_gears[4].m3 += seconds * 20.0f * -2 / 3; + m_gears[0].m3 += seconds * radians(20.0f); + m_gears[1].m3 += seconds * radians(20.0f) * -2 / 9; + m_gears[2].m3 += seconds * radians(20.0f) * -2 / 3; + m_gears[3].m3 += seconds * radians(20.0f) * -2 / 3; + m_gears[4].m3 += seconds * radians(20.0f) * -2 / 3; m_gears[0].m2 = mat4::translate(vec3(0, -1, 0)) * mat4::rotate(m_gears[0].m3 - 130.0f, vec3(0, 1, 0)) diff --git a/doc/tutorial/07_input.cpp b/doc/tutorial/07_input.cpp index 2f8c8c05..5e810a45 100644 --- a/doc/tutorial/07_input.cpp +++ b/doc/tutorial/07_input.cpp @@ -151,7 +151,7 @@ public: mat4 anim = mat4::fromeuler_yxz(m_yaw_angle, m_pitch_angle, 0.f); mat4 model = mat4::translate(vec3(0, 0, -4.5)); mat4 view = mat4::lookat(vec3(0, 2, 0), vec3(0, 0, -4), vec3(0, 1, 0)); - mat4 proj = mat4::perspective(45.0f, 640.0f, 480.0f, 0.1f, 10.0f); + mat4 proj = mat4::perspective(radians(45.0f), 640.0f, 480.0f, 0.1f, 10.0f); m_matrix = proj * view * model * anim; } diff --git a/src/camera.cpp b/src/camera.cpp index 36dc0017..69e489c1 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -32,7 +32,7 @@ Camera::Camera() //Arbitrary values when g_renderer is not ready. ivec2 screen_size = (Renderer::GetCount()) ? (Video::GetSize()) : (ivec2(800, 600)); - m_fov = 45.f; + m_fov = radians(45.f); m_near = -1000.f; m_far = 1000.f; m_screen_size = (float)screen_size.x; @@ -106,7 +106,7 @@ void Camera::SetProjection(float fov, float near, float far, float screen_size, m_screen_size = screen_size; m_screen_ratio = screen_ratio; mat4 screen_scale = mat4::scale(vec3(m_screen_scale.xy, 1.f)); - if (m_fov > .001f) + if (m_fov > .00001f) { if (m_is_shifted) SetProjection(screen_scale * mat4::shifted_perspective(m_fov, screen_size, screen_ratio, m_near, m_far)); @@ -223,13 +223,13 @@ quat Camera::GetRotation() const // Calculate the frustum height at a given distance from the camera. float Camera::GetFrustumHeightAtDistance(float distance, float fov) const { - return 2.f * distance * lol::tan(radians(fov * .5f)); + return 2.f * distance * lol::tan(fov * .5f); } // Calculate the FOV needed to get a given frustum height at a given distance. float Camera::GetFOVForHeightAndDistance(float distance, float height) const { - return 2.f * radians(lol::atan(height * .5f / distance)); + return 2.f * lol::atan(height * .5f / distance); } void Camera::TickGame(float seconds) diff --git a/src/easymesh/easymeshprimitive.cpp b/src/easymesh/easymeshprimitive.cpp index 89a48292..ac1b25f0 100644 --- a/src/easymesh/easymeshprimitive.cpp +++ b/src/easymesh/easymeshprimitive.cpp @@ -1,17 +1,21 @@ // -// EasyMesh-Primitive: The code belonging to primitive operations +// Lol Engine // -// Copyright: (c) 2010-2015 Sam Hocevar -// (c) 2009-2015 Cédric Lecacheur -// (c) 2009-2015 Benjamin "Touky" Huet -// This program is free software; you can redistribute it and/or -// modify it under the terms of the Do What The Fuck You Want To -// Public License, Version 2, as published by Sam Hocevar. See -// http://www.wtfpl.net/ for more details. +// Copyright © 2010—2015 Sam Hocevar +// © 2009—2015 Cédric Lecacheur +// © 2009—2015 Benjamin “Touky” Huet +// +// Lol Engine is free software. It comes without any warranty, to +// the extent permitted by applicable law. You can redistribute it +// and/or modify it under the terms of the Do What the Fuck You Want +// to Public License, Version 2, as published by the WTFPL Task Force. +// See http://www.wtfpl.net/ for more details. // #include +// EasyMesh-Primitive — The code belonging to primitive operations + namespace lol { @@ -38,7 +42,7 @@ void EasyMesh::AppendCylinder(int nsides, float h, float d1, float d2, int vbase = m_vert.count(); - mat3 rotmat = mat3::rotate(360.0f / (float)nsides, 0.f, 1.f, 0.f); + mat3 rotmat = mat3::rotate(radians(360.0f) / (float)nsides, 0.f, 1.f, 0.f); vec3 p1(r1, -h * .5f, 0.f), p2(r2, h * .5f, 0.f), n; vec2 uv1(.0f, .0f), uv2(.0f, 1.0f), uvadd(1.0f / (float)nsides, .0f); if (close) @@ -51,7 +55,7 @@ void EasyMesh::AppendCylinder(int nsides, float h, float d1, float d2, n = vec3(r1, h * .5f, 0.f); n.y = r1 * (r1 - r2) / h; if (!smooth) - n = mat3::rotate(180.0f / nsides, 0.f, 1.f, 0.f) * n; + n = mat3::rotate(radians(180.0f) / nsides, 0.f, 1.f, 0.f) * n; n = normalize(n); //Two passes necessary to ensure "weighted quad" compatibility @@ -154,7 +158,7 @@ void EasyMesh::AppendCapsule(int ndivisions, float h, float d) /* Fill in the icosahedron vertices, rotating them so that there * is a vertex at [0 1 0] and [0 -1 0] after normalisation. */ float phi = 0.5f + 0.5f * sqrt(5.f); - mat3 m = mat3::rotate(degrees(asin(1.f / sqrt(2.f + phi))), + mat3 m = mat3::rotate(asin(1.f / sqrt(2.f + phi)), vec3(0.f, 0.f, 1.f)); for (int i = 0; i < 4; i++) { @@ -548,7 +552,7 @@ void EasyMesh::AppendStar(int nbranches, float d1, float d2, AddVertex(vec3(0.f, 0.f, 0.f)); SetCurVertTexCoord(vec2(.5f, .5f)); SetCurVertTexCoord2(vec2(.5f, .5f)); - mat3 rotmat = mat3::rotate(180.0f / nbranches, 0.f, 1.f, 0.f); + mat3 rotmat = mat3::rotate(radians(180.0f) / nbranches, 0.f, 1.f, 0.f); vec3 p1(r1, 0.f, 0.f), p2(r2, 0.f, 0.f); vec3 uv1(0.f, 0.f, -.5f * ((float)r1 / maxr)), uv2(0.f, 0.f, -.5f * ((float)r2 / maxr)); @@ -600,7 +604,7 @@ void EasyMesh::AppendExpandedStar(int nbranches, float d1, float d2, float extra AddVertex(vec3(0.f, 0.f, 0.f)); SetCurVertTexCoord(vec2(.5f, .5f)); SetCurVertTexCoord2(vec2(.5f, .5f)); - mat3 rotmat = mat3::rotate(180.0f / nbranches, 0.f, 1.f, 0.f); + mat3 rotmat = mat3::rotate(radians(180.0f) / nbranches, 0.f, 1.f, 0.f); vec3 p1(r1, 0.f, 0.f), p2(r2, 0.f, 0.f), p3(r1 + extrar, 0.f, 0.f), p4(r2 + extrar, 0.f, 0.f);; vec3 uv1(0.f, 0.f, -.5f * ((float)r1 / maxr)), @@ -652,7 +656,7 @@ void EasyMesh::AppendDisc(int nsides, float d, bool fade) AddVertex(vec3(0.f, 0.f, 0.f)); SetCurVertTexCoord(vec2(.5f, .5f)); SetCurVertTexCoord2(vec2(.5f, .5f)); - mat3 rotmat = mat3::rotate(360.0f / nsides, 0.f, 1.f, 0.f); + mat3 rotmat = mat3::rotate(radians(360.0f) / nsides, 0.f, 1.f, 0.f); vec3 p1(r, 0.f, 0.f); vec3 uv(.5f, .0f, .0f); @@ -680,7 +684,7 @@ void EasyMesh::AppendSimpleTriangle(float d, bool fade) //XXX : This operation is done to convert radius to diameter without changing all the code. float size = d * .5f; - mat3 m = mat3::rotate(120.f, 0.f, 1.f, 0.f); + mat3 m = mat3::rotate(radians(120.f), 0.f, 1.f, 0.f); vec3 p(0.f, 0.f, size); AddVertex(p); SetCurVertTexCoord(vec2(.5f, 0.133975f)); SetCurVertTexCoord2(vec2(.5f, 0.133975f)); @@ -773,9 +777,9 @@ void EasyMesh::AppendCog(int nbsides, float h, float d10, float d20, if (r12 < 0) h = -h; - mat3 rotmat = mat3::rotate(180.0f / nbsides, 0.f, 1.f, 0.f); - mat3 smat1 = mat3::rotate(sidemul * 180.0f / nbsides, 0.f, 1.f, 0.f); - mat3 smat2 = mat3::rotate(sidemul * -360.0f / nbsides, 0.f, 1.f, 0.f); + mat3 rotmat = mat3::rotate(radians(180.0f) / nbsides, 0.f, 1.f, 0.f); + mat3 smat1 = mat3::rotate(sidemul * radians(180.0f) / nbsides, 0.f, 1.f, 0.f); + mat3 smat2 = mat3::rotate(sidemul * radians(-360.0f) / nbsides, 0.f, 1.f, 0.f); vec3 p[12]; diff --git a/src/easymesh/easymeshtransform.cpp b/src/easymesh/easymeshtransform.cpp index b1f3f055..8c5f818e 100644 --- a/src/easymesh/easymeshtransform.cpp +++ b/src/easymesh/easymeshtransform.cpp @@ -1,17 +1,21 @@ // -// EasyMesh-Transform: The code belonging to transform operations +// Lol Engine // -// Copyright: (c) 2010-2015 Sam Hocevar -// (c) 2009-2015 Cédric Lecacheur -// (c) 2009-2015 Benjamin "Touky" Huet -// This program is free software; you can redistribute it and/or -// modify it under the terms of the Do What The Fuck You Want To -// Public License, Version 2, as published by Sam Hocevar. See -// http://www.wtfpl.net/ for more details. +// Copyright © 2010—2015 Sam Hocevar +// © 2009—2015 Cédric Lecacheur +// © 2009—2015 Benjamin “Touky” Huet +// +// Lol Engine is free software. It comes without any warranty, to +// the extent permitted by applicable law. You can redistribute it +// and/or modify it under the terms of the Do What the Fuck You Want +// to Public License, Version 2, as published by the WTFPL Task Force. +// See http://www.wtfpl.net/ for more details. // #include +// EasyMesh-Transform — The code belonging to transform operations + namespace lol { @@ -49,7 +53,7 @@ void EasyMesh::Rotate(float degrees, vec3 const &axis) return; } - mat3 m = mat3::rotate(degrees, axis); + mat3 m = mat3::rotate(radians(degrees), axis); for (int i = m_cursors.last().m1; i < m_vert.count(); i++) { m_vert[i].m_coord = m * m_vert[i].m_coord; @@ -159,7 +163,7 @@ void EasyMesh::DoMeshTransform(MeshTransform ct, Axis axis0, Axis axis1, float n case MeshTransform::Twist: { vec3 rotaxis = vec3(1.f); rotaxis[(axis0.ToScalar() + 1) % 3] = .0f; rotaxis[(axis0.ToScalar() + 2) % 3] = .0f; - m_vert[i].m_coord = mat3::rotate(m_vert[i].m_coord[axis0.ToScalar()] * n0 + noff, rotaxis) * m_vert[i].m_coord; + m_vert[i].m_coord = mat3::rotate(radians(m_vert[i].m_coord[axis0.ToScalar()] * n0 + noff), rotaxis) * m_vert[i].m_coord; break; } case MeshTransform::Shear: @@ -180,7 +184,7 @@ void EasyMesh::DoMeshTransform(MeshTransform ct, Axis axis0, Axis axis1, float n case MeshTransform::Bend: { vec3 rotaxis = vec3(1.f); rotaxis[(axis1.ToScalar() + 1) % 3] = .0f; rotaxis[(axis1.ToScalar() + 2) % 3] = .0f; - m_vert[i].m_coord = mat3::rotate(m_vert[i].m_coord[axis0.ToScalar()] * n0 + noff, rotaxis) * m_vert[i].m_coord; + m_vert[i].m_coord = mat3::rotate(radians(m_vert[i].m_coord[axis0.ToScalar()] * n0 + noff), rotaxis) * m_vert[i].m_coord; break; } } diff --git a/src/lol/math/matrix.h b/src/lol/math/matrix.h index 7dfbc0ad..2e76110e 100644 --- a/src/lol/math/matrix.h +++ b/src/lol/math/matrix.h @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2010-2015 Sam Hocevar +// Copyright © 2010—2015 Sam Hocevar // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -120,10 +120,10 @@ struct mat_t #endif /* Helpers for transformation matrices */ - static mat_t rotate(T degrees); - static inline mat_t rotate(mat_t m, T degrees) + static mat_t rotate(T radians); + static inline mat_t rotate(mat_t m, T radians) { - return rotate(degrees) * m; + return rotate(radians) * m; } void printf() const; @@ -222,8 +222,8 @@ struct mat_t static mat_t scale(T x); static mat_t scale(T x, T y, T z); static mat_t scale(vec_t v); - static mat_t rotate(T degrees, T x, T y, T z); - static mat_t rotate(T degrees, vec_t v); + static mat_t rotate(T radians, T x, T y, T z); + static mat_t rotate(T radians, vec_t v); static mat_t fromeuler_xyz(vec_t const &v); static mat_t fromeuler_xzy(vec_t const &v); @@ -251,9 +251,9 @@ struct mat_t static mat_t fromeuler_zxz(T phi, T theta, T psi); static mat_t fromeuler_zyz(T phi, T theta, T psi); - static inline mat_t rotate(mat_t m, T degrees, vec_t v) + static inline mat_t rotate(mat_t m, T radians, vec_t v) { - return rotate(degrees, v) * m; + return rotate(radians, v) * m; } void printf() const; @@ -384,19 +384,19 @@ struct mat_t return translate(v) * m; } - static inline mat_t rotate(T degrees, T x, T y, T z) + static inline mat_t rotate(T radians, T x, T y, T z) { - return mat_t(mat_t::rotate(degrees, x, y, z), (T)1); + return mat_t(mat_t::rotate(radians, x, y, z), (T)1); } - static inline mat_t rotate(T degrees, vec_t v) + static inline mat_t rotate(T radians, vec_t v) { - return mat_t(mat_t::rotate(degrees, v), (T)1); + return mat_t(mat_t::rotate(radians, v), (T)1); } - static inline mat_t rotate(mat_t &m, T degrees, vec_t v) + static inline mat_t rotate(mat_t &m, T radians, vec_t v) { - return rotate(degrees, v) * m; + return rotate(radians, v) * m; } static mat_t fromeuler_xyz(vec_t const &v); @@ -428,7 +428,7 @@ struct mat_t /* Helpers for view matrices */ static mat_t lookat(vec_t eye, vec_t center, vec_t up); - /* Helpers for projection matrices */ + /* Helpers for projection matrices; FOV values are in radians */ static mat_t ortho(T left, T right, T bottom, T top, T near, T far); static mat_t ortho(T width, T height, T near, T far); static mat_t frustum(T left, T right, T bottom, T top, T near, T far); diff --git a/src/lol/math/transform.h b/src/lol/math/transform.h index debfb43d..35516be6 100644 --- a/src/lol/math/transform.h +++ b/src/lol/math/transform.h @@ -147,8 +147,8 @@ struct quat_t : public linear_ops::base } /* Create a unit quaternion representing a rotation around an axis. */ - static quat_t rotate(T degrees, T x, T y, T z); - static quat_t rotate(T degrees, vec_t const &v); + static quat_t rotate(T radians, T x, T y, T z); + static quat_t rotate(T radians, vec_t const &v); /* Create a unit quaternion representing a rotation between two vectors. * Input vectors need not be normalised. */ @@ -157,7 +157,7 @@ struct quat_t : public linear_ops::base /* Convert from Euler angles. The axes in fromeuler_xyx are * x, then y', then x", ie. the axes are attached to the model. * If you want to rotate around static axes, just reverse the order - * of the arguments. Angle values are in degrees. */ + * of the arguments. Angle values are in radians. */ static quat_t fromeuler_xyx(vec_t const &v); static quat_t fromeuler_xzx(vec_t const &v); static quat_t fromeuler_yxy(vec_t const &v); @@ -175,7 +175,7 @@ struct quat_t : public linear_ops::base * but since everyone does it…). The axes in fromeuler_xyz are * x, then y', then z", ie. the axes are attached to the model. * If you want to apply yaw around x, pitch around y, and roll - * around z, use fromeuler_xyz. Angle values are in degrees. + * around z, use fromeuler_xyz. Angle values are in radians. * If you want to rotate around static axes, reverse the order in * the function name (_zyx instead of _xyz) AND reverse the order * of the arguments. */ diff --git a/src/math/matrix.cpp b/src/math/matrix.cpp index 03549ff8..45c9decd 100644 --- a/src/math/matrix.cpp +++ b/src/math/matrix.cpp @@ -1,11 +1,13 @@ // -// Lol Engine +// Lol Engine // -// Copyright: (c) 2010-2014 Sam Hocevar -// This program is free software; you can redistribute it and/or -// modify it under the terms of the Do What The Fuck You Want To -// Public License, Version 2, as published by Sam Hocevar. See -// http://www.wtfpl.net/ for more details. +// Copyright © 2010—2015 Sam Hocevar +// +// Lol Engine is free software. It comes without any warranty, to +// the extent permitted by applicable law. You can redistribute it +// and/or modify it under the terms of the Do What the Fuck You Want +// to Public License, Version 2, as published by the WTFPL Task Force. +// See http://www.wtfpl.net/ for more details. // #include @@ -48,10 +50,10 @@ template<> mat4 mat4::translate(vec3 v) return translate(v.x, v.y, v.z); } -template<> mat2 mat2::rotate(float degrees) +template<> mat2 mat2::rotate(float radians) { - float st = sin(radians(degrees)); - float ct = cos(radians(degrees)); + float st = sin(radians); + float ct = cos(radians); mat2 ret; @@ -64,10 +66,10 @@ template<> mat2 mat2::rotate(float degrees) return ret; } -template<> mat3 mat3::rotate(float degrees, float x, float y, float z) +template<> mat3 mat3::rotate(float radians, float x, float y, float z) { - float st = sin(radians(degrees)); - float ct = cos(radians(degrees)); + float st = sin(radians); + float ct = cos(radians); float len = std::sqrt(x * x + y * y + z * z); float invlen = len ? 1.0f / len : 0.0f; @@ -96,9 +98,9 @@ template<> mat3 mat3::rotate(float degrees, float x, float y, float z) return ret; } -template<> mat3 mat3::rotate(float degrees, vec3 v) +template<> mat3 mat3::rotate(float radians, vec3 v) { - return rotate(degrees, v.x, v.y, v.z); + return rotate(radians, v.x, v.y, v.z); } template<> mat3::mat_t(quat const &q) @@ -195,7 +197,7 @@ template<> mat4 mat4::frustum(float left, float right, float bottom, template<> mat4 mat4::perspective(float fov_y, float width, float height, float near, float far) { - float t2 = lol::tan(radians(fov_y) * 0.5f); + float t2 = lol::tan(fov_y * 0.5f); float t1 = t2 * width / height; return frustum(-near * t1, near * t1, -near * t2, near * t2, near, far); @@ -210,7 +212,7 @@ template<> mat4 mat4::shifted_perspective(float fov_y, float screen_size, float screen_ratio_yx, float near, float far) { - float tan_y = tanf(radians(fov_y) * .5f); + float tan_y = tanf(fov_y * .5f); ASSERT(tan_y > 0.000001f); float dist_scr = (screen_size * screen_ratio_yx * .5f) / tan_y; diff --git a/src/math/transform.cpp b/src/math/transform.cpp index 1c56456d..36a278b5 100644 --- a/src/math/transform.cpp +++ b/src/math/transform.cpp @@ -15,18 +15,18 @@ namespace lol { -template<> quat quat::rotate(float degrees, vec3 const &v) +template<> quat quat::rotate(float radians, vec3 const &v) { - float half_angle = radians(degrees) * 0.5f; + float half_angle = radians * 0.5f; vec3 tmp = normalize(v) * sin(half_angle); return quat(cos(half_angle), tmp.x, tmp.y, tmp.z); } -template<> quat quat::rotate(float degrees, float x, float y, float z) +template<> quat quat::rotate(float radians, float x, float y, float z) { - return quat::rotate(degrees, vec3(x, y, z)); + return quat::rotate(radians, vec3(x, y, z)); } template<> quat quat::rotate(vec3 const &src, vec3 const &dst) @@ -110,17 +110,16 @@ static inline vec3 quat_toeuler_generic(quat const &q, int i, int j, int k) 1.f - 2.f * (sq(q[1 + k]) + sq(q[1 + j]))); } - return degrees(ret / n); + return ret / n; } static inline mat3 mat3_fromeuler_generic(vec3 const &v, int i, int j, int k) { mat3 ret; - vec3 const w = radians(v); - float const s0 = sin(w[0]), c0 = cos(w[0]); - float const s1 = sin(w[1]), c1 = cos(w[1]); - float const s2 = sin(w[2]), c2 = cos(w[2]); + float const s0 = sin(v[0]), c0 = cos(v[0]); + float const s1 = sin(v[1]), c1 = cos(v[1]); + float const s2 = sin(v[2]), c2 = cos(v[2]); /* (2 + i - j) % 3 means x-y-z direct order; otherwise indirect */ float const sign = ((2 + i - j) % 3) ? 1.f : -1.f; @@ -163,7 +162,7 @@ static inline mat3 mat3_fromeuler_generic(vec3 const &v, int i, int j, int k) static inline quat quat_fromeuler_generic(vec3 const &v, int i, int j, int k) { - vec3 const half_angles = radians(v * 0.5f); + vec3 const half_angles = v * 0.5f; float const s0 = sin(half_angles[0]), c0 = cos(half_angles[0]); float const s1 = sin(half_angles[1]), c1 = cos(half_angles[1]); float const s2 = sin(half_angles[2]), c2 = cos(half_angles[2]); diff --git a/src/scene.cpp b/src/scene.cpp index 8b35025f..8ceb8042 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -456,7 +456,7 @@ void Scene::ReleaseAllPrimitiveRenderers(uintptr_t key) } //----------------------------------------------------------------------------- -void Scene::AddTile(TileSet *tileset, int id, vec3 pos, int o, vec2 scale, float angle) +void Scene::AddTile(TileSet *tileset, int id, vec3 pos, int o, vec2 scale, float degrees) { ASSERT(id < tileset->GetTileCount()); @@ -464,7 +464,7 @@ void Scene::AddTile(TileSet *tileset, int id, vec3 pos, int o, vec2 scale, float mat4 model = mat4::translate(pos) * mat4::scale(scale.x, scale.y, 1.f) * mat4::translate(size.x * 0.5f, size.y * 0.5f, 0.f) - * mat4::rotate(scale.x * scale.y < 0 ? angle : -angle, + * mat4::rotate(radians(scale.x * scale.y < 0 ? degrees : -degrees), vec3::axis_z); AddTile(tileset, id, model); diff --git a/src/t/entity/camera.cpp b/src/t/entity/camera.cpp index bd7bff7f..8836a1e8 100644 --- a/src/t/entity/camera.cpp +++ b/src/t/entity/camera.cpp @@ -1,5 +1,5 @@ // -// Lol Engine — Unit tests +// Lol Engine — Unit tests for the camera object // // Copyright © 2010—2015 Sam Hocevar // © 2013 Benjamin “Touky” Huet @@ -36,7 +36,7 @@ lolunit_declare_fixture(camera_test) m_lookat = mat4::lookat(eye, target, up); q_lookat = quat(mat3(m_lookat)); v_lookat = vec3::toeuler_zyx(q_lookat); - fov = 90.f; + fov = radians(90.f); screen_size = 800.f; screen_ratio = 1.0f; near = 1.f; diff --git a/src/t/math/quat.cpp b/src/t/math/quat.cpp index e005095a..0250a86f 100644 --- a/src/t/math/quat.cpp +++ b/src/t/math/quat.cpp @@ -1,5 +1,5 @@ // -// Lol Engine — Unit tests +// Lol Engine — Unit tests for quaternions // // Copyright © 2010—2015 Sam Hocevar // @@ -166,9 +166,9 @@ lolunit_declare_fixture(quaternion_test) lolunit_declare_test(rotation) { - /* Check that rotating 10 degrees twice means rotating 20 degrees */ - quat a = quat::rotate(10.f, vec3::axis_x); - quat b = quat::rotate(20.f, vec3::axis_x); + /* Check that rotating 1 radian twice means rotating 2 radians */ + quat a = quat::rotate(1.f, vec3::axis_x); + quat b = quat::rotate(2.f, vec3::axis_x); quat c = a * a; lolunit_assert_doubles_equal(c.w, b.w, 1e-5); @@ -176,7 +176,7 @@ lolunit_declare_fixture(quaternion_test) lolunit_assert_doubles_equal(c.y, b.y, 1e-5); lolunit_assert_doubles_equal(c.z, b.z, 1e-5); - /* Check that rotating 10 degrees then 20 is the same as 20 then 10 */ + /* Check that rotating 1 radian then 2 is the same as 2 then 1 */ quat d = a * b; quat e = b * a; @@ -188,7 +188,7 @@ lolunit_declare_fixture(quaternion_test) lolunit_declare_test(to_axis_angle) { - quat q = quat::rotate(10.f, vec3::axis_x); + quat q = quat::rotate(0.3f, vec3::axis_x); vec3 axis = q.axis(); float angle = q.angle(); @@ -196,7 +196,7 @@ lolunit_declare_fixture(quaternion_test) lolunit_assert_doubles_equal(0.0, axis.y, 1e-6); lolunit_assert_doubles_equal(0.0, axis.z, 1e-6); - lolunit_assert_doubles_equal(10.0, (double)degrees(angle), 1e-6); + lolunit_assert_doubles_equal(0.3f, (double)angle, 1e-6); } lolunit_declare_test(from_two_vectors) @@ -248,7 +248,7 @@ lolunit_declare_fixture(quaternion_test) { for (int i = 0; i < 100; ++i) { - vec3 angles(rand(360.f), rand(360.f), rand(360.f)); + vec3 angles(rand(100.f), rand(100.f), rand(100.f)); /* Tait-Bryan */ quat q1 = quat::fromeuler_xyz(angles); @@ -296,7 +296,7 @@ lolunit_declare_fixture(quaternion_test) { /* We check that fromeuler_xyx and fromeuler_xyz give the * same result if the 3rd angle is zero. */ - vec3 angles(rand(360.f), rand(360.f), 0.f); + vec3 angles(rand(radians(360.f)), rand(radians(360.f)), 0.f); quat q1, q2; q1 = quat::fromeuler_xyz(angles); @@ -355,7 +355,7 @@ lolunit_declare_fixture(quaternion_test) { /* We check that fromeuler_zyz and fromeuler_xyz give the * same result if the 1st angle is zero. */ - vec3 angles(0.f, rand(360.f), rand(360.f)); + vec3 angles(0.f, rand(radians(360.f)), rand(radians(360.f))); quat q1, q2; q1 = quat::fromeuler_xyz(angles); diff --git a/src/t/math/rotation.cpp b/src/t/math/rotation.cpp index 5f4283cc..46ac3f38 100644 --- a/src/t/math/rotation.cpp +++ b/src/t/math/rotation.cpp @@ -1,5 +1,5 @@ // -// Lol Engine — Unit tests +// Lol Engine — Unit tests for rotations (matrices and quaternions) // // Copyright © 2010—2015 Sam Hocevar // @@ -26,7 +26,7 @@ lolunit_declare_fixture(rotation_test) lolunit_declare_test(rotate_2d) { /* Rotations must be CCW */ - mat2 m90 = mat2::rotate(90.f); + mat2 m90 = mat2::rotate(radians(90.f)); vec2 a(2.f, 3.f); vec2 b = m90 * a; @@ -41,24 +41,24 @@ lolunit_declare_fixture(rotation_test) lolunit_declare_test(compose_2d) { - /* Rotating 20 degrees twice must equal rotating 40 degrees */ - mat2 m20 = mat2::rotate(20.f); - mat2 m40 = mat2::rotate(40.f); - mat2 m20x20 = m20 * m20; + /* Rotating 1 radian twice must equal rotating 2 radians */ + mat2 m1 = mat2::rotate(1.f); + mat2 m2 = mat2::rotate(2.f); + mat2 m1x1 = m1 * m1; - lolunit_assert_doubles_equal(m20x20[0][0], m40[0][0], 1e-5); - lolunit_assert_doubles_equal(m20x20[1][0], m40[1][0], 1e-5); + lolunit_assert_doubles_equal(m1x1[0][0], m2[0][0], 1e-5); + lolunit_assert_doubles_equal(m1x1[1][0], m2[1][0], 1e-5); - lolunit_assert_doubles_equal(m20x20[0][1], m40[0][1], 1e-5); - lolunit_assert_doubles_equal(m20x20[1][1], m40[1][1], 1e-5); + lolunit_assert_doubles_equal(m1x1[0][1], m2[0][1], 1e-5); + lolunit_assert_doubles_equal(m1x1[1][1], m2[1][1], 1e-5); } lolunit_declare_test(rotate_3d) { /* Rotations must be CCW along each axis */ - mat3 m90x = mat3::rotate(90.f, 1.f, 0.f, 0.f); - mat3 m90y = mat3::rotate(90.f, 0.f, 1.f, 0.f); - mat3 m90z = mat3::rotate(90.f, 0.f, 0.f, 1.f); + mat3 m90x = mat3::rotate(radians(90.f), 1.f, 0.f, 0.f); + mat3 m90y = mat3::rotate(radians(90.f), 0.f, 1.f, 0.f); + mat3 m90z = mat3::rotate(radians(90.f), 0.f, 0.f, 1.f); vec3 a(2.f, 3.f, 4.f); vec3 b = m90x * a; @@ -88,39 +88,39 @@ lolunit_declare_fixture(rotation_test) lolunit_declare_test(compose_3d) { - /* Rotating 20 degrees twice must equal rotating 40 degrees */ - mat3 m20 = mat3::rotate(20.f, 1.f, 2.f, 3.f); - mat3 m40 = mat3::rotate(40.f, 1.f, 2.f, 3.f); - mat3 m20x20 = m20 * m20; - - lolunit_assert_doubles_equal(m20x20[0][0], m40[0][0], 1e-5); - lolunit_assert_doubles_equal(m20x20[1][0], m40[1][0], 1e-5); - lolunit_assert_doubles_equal(m20x20[2][0], m40[2][0], 1e-5); - - lolunit_assert_doubles_equal(m20x20[0][1], m40[0][1], 1e-5); - lolunit_assert_doubles_equal(m20x20[1][1], m40[1][1], 1e-5); - lolunit_assert_doubles_equal(m20x20[2][1], m40[2][1], 1e-5); - - lolunit_assert_doubles_equal(m20x20[0][2], m40[0][2], 1e-5); - lolunit_assert_doubles_equal(m20x20[1][2], m40[1][2], 1e-5); - lolunit_assert_doubles_equal(m20x20[2][2], m40[2][2], 1e-5); + /* Rotating 1 radian twice must equal rotating 2 radians */ + mat3 m1 = mat3::rotate(1.f, 1.f, 2.f, 3.f); + mat3 m2 = mat3::rotate(2.f, 1.f, 2.f, 3.f); + mat3 m1x1 = m1 * m1; + + lolunit_assert_doubles_equal(m1x1[0][0], m2[0][0], 1e-5); + lolunit_assert_doubles_equal(m1x1[1][0], m2[1][0], 1e-5); + lolunit_assert_doubles_equal(m1x1[2][0], m2[2][0], 1e-5); + + lolunit_assert_doubles_equal(m1x1[0][1], m2[0][1], 1e-5); + lolunit_assert_doubles_equal(m1x1[1][1], m2[1][1], 1e-5); + lolunit_assert_doubles_equal(m1x1[2][1], m2[2][1], 1e-5); + + lolunit_assert_doubles_equal(m1x1[0][2], m2[0][2], 1e-5); + lolunit_assert_doubles_equal(m1x1[1][2], m2[1][2], 1e-5); + lolunit_assert_doubles_equal(m1x1[2][2], m2[2][2], 1e-5); } lolunit_declare_test(quaternion_transform) { /* Rotating using a quaternion must equal rotating using a matrix */ - mat3 m20 = mat3::rotate(20.f, 1.f, 2.f, 3.f); - quat q20 = quat::rotate(20.f, 1.f, 2.f, 3.f); + mat3 m1 = mat3::rotate(1.f, 1.f, 2.f, 3.f); + quat q1 = quat::rotate(1.f, 1.f, 2.f, 3.f); vec3 a(-2.f, 4.f, 3.f); - vec3 b = m20 * a; - vec3 c = q20.transform(a); + vec3 b = m1 * a; + vec3 c = q1.transform(a); lolunit_assert_doubles_equal(c.x, b.x, 1e-5); lolunit_assert_doubles_equal(c.y, b.y, 1e-5); lolunit_assert_doubles_equal(c.z, b.z, 1e-5); - float n = norm(q20); + float n = norm(q1); lolunit_assert_doubles_equal(n, 1.0, 1e-5); } @@ -129,8 +129,8 @@ lolunit_declare_fixture(rotation_test) { /* A rotation matrix converted to a quaternion should match the * quaternion built with the same parameters */ - quat q1 = quat::rotate(20.f, 1.f, 2.f, 3.f); - quat q2 = quat(mat3::rotate(20.f, 1.f, 2.f, 3.f)); + quat q1 = quat::rotate(1.f, 1.f, 2.f, 3.f); + quat q2 = quat(mat3::rotate(1.f, 1.f, 2.f, 3.f)); lolunit_assert_doubles_equal(q2.w, q1.w, 1e-5); lolunit_assert_doubles_equal(q2.x, q1.x, 1e-5); @@ -148,8 +148,8 @@ lolunit_declare_fixture(rotation_test) { /* A quaternion converted to a rotation matrix should match the * rotation matrix built with the same parameters */ - mat3 m1 = mat3::rotate(60.f, 1.f, -2.f, 3.f); - mat3 m2 = mat3(quat::rotate(60.f, 1.f, -2.f, 3.f)); + mat3 m1 = mat3::rotate(3.f, 1.f, -2.f, 3.f); + mat3 m2 = mat3(quat::rotate(3.f, 1.f, -2.f, 3.f)); lolunit_assert_doubles_equal(m2[0][0], m1[0][0], 1e-5); lolunit_assert_doubles_equal(m2[1][0], m1[1][0], 1e-5); @@ -174,8 +174,8 @@ lolunit_declare_fixture(rotation_test) { /* Combining two rotation matrices should match the matrix created * from the combination of the two equivalent quaternions */ - mat3 m1 = mat3::rotate(60.f, 1.f, -2.f, 3.f); - mat3 m2 = mat3::rotate(20.f, -3.f, 1.f, -3.f); + mat3 m1 = mat3::rotate(3.f, 1.f, -2.f, 3.f); + mat3 m2 = mat3::rotate(1.f, -3.f, 1.f, -3.f); mat3 m3 = m2 * m1; mat3 m4(quat(m2) * quat(m1)); @@ -197,8 +197,8 @@ lolunit_declare_fixture(rotation_test) { /* Combining two quaternions should match the quaternion created * from the combination of the two equivalent rotation matrices */ - quat q1 = quat::rotate(60.f, 1.f, -2.f, 3.f); - quat q2 = quat::rotate(20.f, -3.f, 1.f, -2.f); + quat q1 = quat::rotate(3.f, 1.f, -2.f, 3.f); + quat q2 = quat::rotate(1.f, -3.f, 1.f, -2.f); quat q3 = q2 * q1; quat q4(mat3(q2) * mat3(q1)); diff --git a/src/t/math/sqt.cpp b/src/t/math/sqt.cpp index 6e170a0b..64b41b87 100644 --- a/src/t/math/sqt.cpp +++ b/src/t/math/sqt.cpp @@ -18,7 +18,7 @@ namespace lol { static sqt const test_sqt_1(1.5f, - quat::rotate(radians(20.f), + quat::rotate(1.1f, normalize(vec3(1.f, 2.f, 3.f))), vec3(1.f, -1.f, 0.5f));