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)
|
* 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)
|
||||||
*
|
*
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
|
@ -34,13 +34,21 @@ int main(void)
|
||||||
camera.fovy = 45.0f; // Camera field-of-view Y
|
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);
|
// Load a cylinder model for testing
|
||||||
Model model = LoadModelFromMesh(mesh);
|
Model model = LoadModelFromMesh(GenMeshCylinder(0.2f, 1.0f, 32));
|
||||||
|
|
||||||
// Some required variables
|
// Generic quaternion for operations
|
||||||
Quaternion q1 = { 0 };
|
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
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
@ -50,6 +58,10 @@ int main(void)
|
||||||
{
|
{
|
||||||
// Update
|
// 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))
|
if (!IsKeyDown(KEY_SPACE))
|
||||||
{
|
{
|
||||||
v1.x += 0.01f;
|
v1.x += 0.01f;
|
||||||
|
@ -68,7 +80,7 @@ int main(void)
|
||||||
q1 = QuaternionFromMatrix(m1);
|
q1 = QuaternionFromMatrix(m1);
|
||||||
m3 = QuaternionToMatrix(q1);
|
m3 = QuaternionToMatrix(q1);
|
||||||
|
|
||||||
v2 = QuaternionToEuler(q1);
|
v2 = QuaternionToEuler(q1); // Angles returned in radians
|
||||||
|
|
||||||
m4 = MatrixRotateZYX(v2);
|
m4 = MatrixRotateZYX(v2);
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
@ -83,10 +95,13 @@ int main(void)
|
||||||
|
|
||||||
model.transform = m1;
|
model.transform = m1;
|
||||||
DrawModel(model, (Vector3){ -1, 0, 0 }, 1.0f, RED);
|
DrawModel(model, (Vector3){ -1, 0, 0 }, 1.0f, RED);
|
||||||
|
|
||||||
model.transform = m2;
|
model.transform = m2;
|
||||||
DrawModel(model, (Vector3){ 1, 0, 0 }, 1.0f, RED);
|
DrawModel(model, (Vector3){ 1, 0, 0 }, 1.0f, RED);
|
||||||
|
|
||||||
model.transform = m3;
|
model.transform = m3;
|
||||||
DrawModel(model, (Vector3){ 0, 0, 0 }, 1.0f, RED);
|
DrawModel(model, (Vector3){ 0, 0, 0 }, 1.0f, RED);
|
||||||
|
|
||||||
model.transform = m4;
|
model.transform = m4;
|
||||||
DrawModel(model, (Vector3){ 0, 0, -1 }, 1.0f, RED);
|
DrawModel(model, (Vector3){ 0, 0, -1 }, 1.0f, RED);
|
||||||
|
|
||||||
|
@ -94,23 +109,13 @@ int main(void)
|
||||||
|
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
if (v2.x < 0) v2.x += PI*2;
|
DrawText(TextFormat("%2.3f", v1.x), 20, 20, 20, (v1.x == v2.x)? GREEN: BLACK);
|
||||||
if (v2.y < 0) v2.y += PI*2;
|
DrawText(TextFormat("%2.3f", v1.y), 20, 40, 20, (v1.y == v2.y)? GREEN: BLACK);
|
||||||
if (v2.z < 0) v2.z += PI*2;
|
DrawText(TextFormat("%2.3f", v1.z), 20, 60, 20, (v1.z == v2.z)? GREEN: BLACK);
|
||||||
|
|
||||||
Color cx,cy,cz;
|
DrawText(TextFormat("%2.3f", v2.x), 200, 20, 20, (v1.x == v2.x)? GREEN: BLACK);
|
||||||
cx = cy = cz = BLACK;
|
DrawText(TextFormat("%2.3f", v2.y), 200, 40, 20, (v1.y == v2.y)? GREEN: BLACK);
|
||||||
if (v1.x == v2.x) cx = GREEN;
|
DrawText(TextFormat("%2.3f", v2.z), 200, 60, 20, (v1.z == v2.z)? GREEN: BLACK);
|
||||||
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);
|
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
|
@ -20,10 +20,12 @@ int main(void)
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - generate random values");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - generate random values");
|
||||||
|
|
||||||
int framesCounter = 0; // Variable used to count frames
|
// SetRandomSeed(0xaabbccff); // Set a custom random seed if desired, by default: "time(NULL)"
|
||||||
|
|
||||||
int randValue = GetRandomValue(-8, 5); // Get a random integer number between -8 and 5 (both included)
|
int randValue = GetRandomValue(-8, 5); // Get a random integer number between -8 and 5 (both included)
|
||||||
|
|
||||||
|
int framesCounter = 0; // Variable used to count frames
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,6 @@ int main(void)
|
||||||
worldSpaceCamera.target.y = (int)screenSpaceCamera.target.y;
|
worldSpaceCamera.target.y = (int)screenSpaceCamera.target.y;
|
||||||
screenSpaceCamera.target.y -= worldSpaceCamera.target.y;
|
screenSpaceCamera.target.y -= worldSpaceCamera.target.y;
|
||||||
screenSpaceCamera.target.y *= virtualRatio;
|
screenSpaceCamera.target.y *= virtualRatio;
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
|
@ -122,7 +122,7 @@ int main(void)
|
||||||
BeginMode3D(cameraPlayer1);
|
BeginMode3D(cameraPlayer1);
|
||||||
DrawScene();
|
DrawScene();
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
DrawText("PLAYER1 W/S to move", 0, 0, 20, RED);
|
DrawText("PLAYER1 W/S to move", 10, 10, 20, RED);
|
||||||
EndTextureMode();
|
EndTextureMode();
|
||||||
|
|
||||||
// Draw Player2 view to the render texture
|
// Draw Player2 view to the render texture
|
||||||
|
@ -131,7 +131,7 @@ int main(void)
|
||||||
BeginMode3D(cameraPlayer2);
|
BeginMode3D(cameraPlayer2);
|
||||||
DrawScene();
|
DrawScene();
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
DrawText("PLAYER2 UP/DOWN to move", 0, 0, 20, BLUE);
|
DrawText("PLAYER2 UP/DOWN to move", 10, 10, 20, BLUE);
|
||||||
EndTextureMode();
|
EndTextureMode();
|
||||||
|
|
||||||
// Draw both views render textures to the screen side by side
|
// Draw both views render textures to the screen side by side
|
||||||
|
|
|
@ -24,6 +24,9 @@ int main(void)
|
||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [textures] example - textured polygon");
|
||||||
|
|
||||||
|
// Define texture coordinates to map our texture to poly
|
||||||
Vector2 texcoords[MAX_POINTS] = {
|
Vector2 texcoords[MAX_POINTS] = {
|
||||||
(Vector2){ 0.75f, 0.0f },
|
(Vector2){ 0.75f, 0.0f },
|
||||||
(Vector2){ 0.25f, 0.0f },
|
(Vector2){ 0.25f, 0.0f },
|
||||||
|
@ -38,22 +41,24 @@ int main(void)
|
||||||
(Vector2){ 0.75f, 0.0f} // Close the poly
|
(Vector2){ 0.75f, 0.0f} // Close the poly
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Define the base poly vertices from the UV's
|
||||||
|
// NOTE: They can be specified in any other way
|
||||||
Vector2 points[MAX_POINTS] = { 0 };
|
Vector2 points[MAX_POINTS] = { 0 };
|
||||||
|
|
||||||
// Create the poly coords from the UV's
|
|
||||||
// you don't have to do this you can specify
|
|
||||||
// them however you want
|
|
||||||
for (int i = 0; i < MAX_POINTS; i++)
|
for (int i = 0; i < MAX_POINTS; i++)
|
||||||
{
|
{
|
||||||
points[i].x = (texcoords[i].x - 0.5f)*256.0f;
|
points[i].x = (texcoords[i].x - 0.5f)*256.0f;
|
||||||
points[i].y = (texcoords[i].y - 0.5f)*256.0f;
|
points[i].y = (texcoords[i].y - 0.5f)*256.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [textures] example - textured polygon");
|
// Define the vertices drawing position
|
||||||
|
// NOTE: Initially same as points but updated every frame
|
||||||
|
Vector2 positions[MAX_POINTS] = { 0 };
|
||||||
|
for (int i = 0; i < MAX_POINTS; i++) positions[i] = points[i];
|
||||||
|
|
||||||
|
// Load texture to be mapped to poly
|
||||||
Texture texture = LoadTexture("resources/cat.png");
|
Texture texture = LoadTexture("resources/cat.png");
|
||||||
|
|
||||||
float angle = 0.0f;
|
float angle = 0.0f; // Rotation angle (in degrees)
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
@ -63,10 +68,9 @@ int main(void)
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
// Update points rotation with an angle transform
|
||||||
|
// NOTE: Base points position are not modified
|
||||||
angle++;
|
angle++;
|
||||||
|
|
||||||
Vector2 positions[MAX_POINTS] = { 0 };
|
|
||||||
|
|
||||||
for (int i = 0; i < MAX_POINTS; i++) positions[i] = Vector2Rotate(points[i], angle*DEG2RAD);
|
for (int i = 0; i < MAX_POINTS; i++) positions[i] = Vector2Rotate(points[i], angle*DEG2RAD);
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
Before Width: | Height: | Size: 190 KiB After Width: | Height: | Size: 190 KiB |
Loading…
Add table
Add a link
Reference in a new issue