diff options
| author | Ray <[email protected]> | 2020-11-01 13:39:48 +0100 |
|---|---|---|
| committer | Ray <[email protected]> | 2020-11-01 13:39:48 +0100 |
| commit | 8e15dae5ed8264565d3f94aeac7a663ce76a2e62 (patch) | |
| tree | 299a73e64ef3240746353b2353c73b284400c748 /examples/core | |
| parent | 5f79ad9765f1d01e72b84b257911ae8dd4dbc232 (diff) | |
| download | raylib-8e15dae5ed8264565d3f94aeac7a663ce76a2e62.tar.gz raylib-8e15dae5ed8264565d3f94aeac7a663ce76a2e62.zip | |
Review contributed examples
Diffstat (limited to 'examples/core')
| -rw-r--r-- | examples/core/core_quat_conversion.c | 57 | ||||
| -rw-r--r-- | examples/core/core_quat_conversion.png | bin | 0 -> 16887 bytes |
2 files changed, 26 insertions, 31 deletions
diff --git a/examples/core/core_quat_conversion.c b/examples/core/core_quat_conversion.c index 5f2fc36e..0b2bb01e 100644 --- a/examples/core/core_quat_conversion.c +++ b/examples/core/core_quat_conversion.c @@ -2,29 +2,21 @@ * * raylib [core] example - quat conversions * -* Welcome to raylib! +* Generally you should really stick to eulers OR quats... +* This tests that various conversions are equivalent. * -* generally you should really stick to eulers OR quats... -* This tests that various conversions are equivilant. -* -* You can find all basic examples on [C:\raylib\raylib\examples] directory and -* raylib official webpage: [www.raylib.com] -* -* Enjoy using raylib. :) -* -* This example has been created using raylib 1.0 (www.raylib.com) +* This example has been created using raylib 3.5 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * -* Copyright (c) 2013-2020 Ramon Santamaria (@raysan5) +* Example contributed by @chriscamacho and @codifies, reviewed by Ramon Santamaria (@raysan5) +* +* Copyright (c) 2020 @chriscamacho and @codifies * ********************************************************************************************/ #include "raylib.h" -#include "raymath.h" -#ifndef PI2 - #define PI2 PI*2 -#endif +#include "raymath.h" int main(void) { @@ -48,23 +40,25 @@ int main(void) SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- - Quaternion q1; - Matrix m1,m2,m3,m4; - Vector3 v1,v2; - + Quaternion q1; + Matrix m1,m2,m3,m4; + Vector3 v1,v2; + // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update - if (!IsKeyDown(KEY_SPACE)) { + //-------------------------------------------------------------------------------------- + if (!IsKeyDown(KEY_SPACE)) + { v1.x += 0.01; v1.y += 0.03; v1.z += 0.05; } - if (v1.x > PI2) v1.x-=PI2; - if (v1.y > PI2) v1.y-=PI2; - if (v1.z > PI2) v1.z-=PI2; + if (v1.x > PI*2) v1.x -= PI*2; + if (v1.y > PI*2) v1.y -= PI*2; + if (v1.z > PI*2) v1.z -= PI*2; q1 = QuaternionFromEuler(v1.x, v1.y, v1.z); m1 = MatrixRotateZYX(v1); @@ -74,10 +68,13 @@ int main(void) m3 = QuaternionToMatrix(q1); v2 = QuaternionToEuler(q1); - v2.x*=DEG2RAD; v2.y*=DEG2RAD; v2.z*=DEG2RAD; + v2.x *= DEG2RAD; + v2.y *= DEG2RAD; + v2.z *=DEG2RAD; m4 = MatrixRotateZYX(v2); - + //-------------------------------------------------------------------------------------- + // Draw //---------------------------------------------------------------------------------- BeginDrawing(); @@ -94,17 +91,16 @@ int main(void) mod.transform = m4; DrawModel(mod, (Vector3){0,0,-1},1.0,RED); - DrawGrid(10, 1.0f); EndMode3D(); - if (v2.x<0) v2.x+=PI2; - if (v2.y<0) v2.y+=PI2; - if (v2.z<0) v2.z+=PI2; + if (v2.x < 0) v2.x += PI*2; + if (v2.y < 0) v2.y += PI*2; + if (v2.z < 0) v2.z += PI*2; Color cx,cy,cz; - cx=cy=cz=BLACK; + cx = cy = cz = BLACK; if (v1.x == v2.x) cx = GREEN; if (v1.y == v2.y) cy = GREEN; if (v1.z == v2.z) cz = GREEN; @@ -113,7 +109,6 @@ int main(void) DrawText(TextFormat("%2.3f",v1.y),20,40,20,cy); DrawText(TextFormat("%2.3f",v1.z),20,60,20,cz); - DrawText(TextFormat("%2.3f",v2.x),200,20,20,cx); DrawText(TextFormat("%2.3f",v2.y),200,40,20,cy); DrawText(TextFormat("%2.3f",v2.z),200,60,20,cz); diff --git a/examples/core/core_quat_conversion.png b/examples/core/core_quat_conversion.png Binary files differnew file mode 100644 index 00000000..d4a9d14f --- /dev/null +++ b/examples/core/core_quat_conversion.png |
