Reviewed examples
This commit is contained in:
parent
d47d7c0001
commit
c20df9aa47
6 changed files with 166 additions and 156 deletions
|
@ -10,7 +10,7 @@
|
|||
*
|
||||
* Example contributed by Chris Camacho (@chriscamacho) and reviewed by Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* Copyright (c) 2020 Chris Camacho (@chriscamacho) and Ramon Santamaria (@raysan5)
|
||||
* Copyright (c) 2020-2021 Chris Camacho (@chriscamacho) and Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
|
@ -32,15 +32,23 @@ int main(void)
|
|||
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
|
||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||
camera.projection = CAMERA_PERSPECTIVE; // Camera mode type
|
||||
camera.projection = CAMERA_PERSPECTIVE; // Camera mode type
|
||||
|
||||
Mesh mesh = GenMeshCylinder(0.2f, 1.0f, 32);
|
||||
Model model = LoadModelFromMesh(mesh);
|
||||
// Load a cylinder model for testing
|
||||
Model model = LoadModelFromMesh(GenMeshCylinder(0.2f, 1.0f, 32));
|
||||
|
||||
// Some required variables
|
||||
// Generic quaternion for operations
|
||||
Quaternion q1 = { 0 };
|
||||
Matrix m1 = { 0 }, m2 = { 0 }, m3 = { 0 }, m4 = { 0 };
|
||||
Vector3 v1 = { 0 }, v2 = { 0 };
|
||||
|
||||
// Transform matrices required to draw 4 cylinders
|
||||
Matrix m1 = { 0 };
|
||||
Matrix m2 = { 0 };
|
||||
Matrix m3 = { 0 };
|
||||
Matrix m4 = { 0 };
|
||||
|
||||
// Generic vectors for rotations
|
||||
Vector3 v1 = { 0 };
|
||||
Vector3 v2 = { 0 };
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
@ -50,6 +58,10 @@ int main(void)
|
|||
{
|
||||
// Update
|
||||
//--------------------------------------------------------------------------------------
|
||||
if (v2.x < 0) v2.x += PI*2;
|
||||
if (v2.y < 0) v2.y += PI*2;
|
||||
if (v2.z < 0) v2.z += PI*2;
|
||||
|
||||
if (!IsKeyDown(KEY_SPACE))
|
||||
{
|
||||
v1.x += 0.01f;
|
||||
|
@ -68,7 +80,7 @@ int main(void)
|
|||
q1 = QuaternionFromMatrix(m1);
|
||||
m3 = QuaternionToMatrix(q1);
|
||||
|
||||
v2 = QuaternionToEuler(q1);
|
||||
v2 = QuaternionToEuler(q1); // Angles returned in radians
|
||||
|
||||
m4 = MatrixRotateZYX(v2);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
@ -83,10 +95,13 @@ int main(void)
|
|||
|
||||
model.transform = m1;
|
||||
DrawModel(model, (Vector3){ -1, 0, 0 }, 1.0f, RED);
|
||||
|
||||
model.transform = m2;
|
||||
DrawModel(model, (Vector3){ 1, 0, 0 }, 1.0f, RED);
|
||||
|
||||
model.transform = m3;
|
||||
DrawModel(model, (Vector3){ 0, 0, 0 }, 1.0f, RED);
|
||||
|
||||
model.transform = m4;
|
||||
DrawModel(model, (Vector3){ 0, 0, -1 }, 1.0f, RED);
|
||||
|
||||
|
@ -94,23 +109,13 @@ int main(void)
|
|||
|
||||
EndMode3D();
|
||||
|
||||
if (v2.x < 0) v2.x += PI*2;
|
||||
if (v2.y < 0) v2.y += PI*2;
|
||||
if (v2.z < 0) v2.z += PI*2;
|
||||
DrawText(TextFormat("%2.3f", v1.x), 20, 20, 20, (v1.x == v2.x)? GREEN: BLACK);
|
||||
DrawText(TextFormat("%2.3f", v1.y), 20, 40, 20, (v1.y == v2.y)? GREEN: BLACK);
|
||||
DrawText(TextFormat("%2.3f", v1.z), 20, 60, 20, (v1.z == v2.z)? GREEN: BLACK);
|
||||
|
||||
Color cx,cy,cz;
|
||||
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;
|
||||
|
||||
DrawText(TextFormat("%2.3f", v1.x), 20, 20, 20, cx);
|
||||
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);
|
||||
DrawText(TextFormat("%2.3f", v2.x), 200, 20, 20, (v1.x == v2.x)? GREEN: BLACK);
|
||||
DrawText(TextFormat("%2.3f", v2.y), 200, 40, 20, (v1.y == v2.y)? GREEN: BLACK);
|
||||
DrawText(TextFormat("%2.3f", v2.z), 200, 60, 20, (v1.z == v2.z)? GREEN: BLACK);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue