Review contributed examples
This commit is contained in:
parent
5f79ad9765
commit
8e15dae5ed
9 changed files with 129 additions and 145 deletions
|
@ -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);
|
||||
|
|
BIN
examples/core/core_quat_conversion.png
Normal file
BIN
examples/core/core_quat_conversion.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
Loading…
Add table
Add a link
Reference in a new issue