mirror of
https://github.com/raysan5/raylib.git
synced 2025-11-03 09:14:23 +00:00
EXAMPLES: Format tweaks
This commit is contained in:
@@ -15,8 +15,8 @@
|
||||
*
|
||||
********************************************************************************************
|
||||
*
|
||||
* NOTE: To export a model from blender, make sure it is not posed, the vertices need to be
|
||||
* in the same position as they would be in edit mode and the scale of your models is
|
||||
* NOTE: To export a model from blender, make sure it is not posed, the vertices need to be
|
||||
* in the same position as they would be in edit mode and the scale of your models is
|
||||
* set to 0. Scaling can be done from the export menu.
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
@@ -85,17 +85,17 @@ int main(void)
|
||||
DrawGrid(10, 1.0f); // Draw a grid
|
||||
|
||||
// Draw order matters!
|
||||
if (distanceStatic > distanceRotating)
|
||||
if (distanceStatic > distanceRotating)
|
||||
{
|
||||
DrawBillboard(camera, bill, billPositionStatic, 2.0f, WHITE);
|
||||
DrawBillboardPro(camera, bill, source, billPositionRotating, billUp, size, origin, rotation, WHITE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawBillboardPro(camera, bill, source, billPositionRotating, billUp, size, origin, rotation, WHITE);
|
||||
DrawBillboard(camera, bill, billPositionStatic, 2.0f, WHITE);
|
||||
}
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* raylib [core] example - Using bones as socket for calculating the positioning of something
|
||||
*
|
||||
* Example complexity rating: [★★★★] 4/4
|
||||
*
|
||||
*
|
||||
* Example originally created with raylib 4.5, last time updated with raylib 4.5
|
||||
*
|
||||
* Example contributed by iP (@ipzaur) and reviewed by Ramon Santamaria (@raysan5)
|
||||
@@ -51,7 +51,7 @@ int main(void)
|
||||
LoadModel("resources/models/gltf/greenman_sword.glb"), // Index for the sword model is the same as BONE_SOCKET_HAND_R
|
||||
LoadModel("resources/models/gltf/greenman_shield.glb") // Index for the shield model is the same as BONE_SOCKET_HAND_L
|
||||
};
|
||||
|
||||
|
||||
bool showEquip[3] = { true, true, true }; // Toggle on/off equip
|
||||
|
||||
// Load gltf model animations
|
||||
@@ -63,7 +63,7 @@ int main(void)
|
||||
// indices of bones for sockets
|
||||
int boneSocketIndex[BONE_SOCKETS] = { -1, -1, -1 };
|
||||
|
||||
// search bones for sockets
|
||||
// search bones for sockets
|
||||
for (int i = 0; i < characterModel.boneCount; i++)
|
||||
{
|
||||
if (TextIsEqual(characterModel.bones[i].name, "socket_hat"))
|
||||
@@ -71,13 +71,13 @@ int main(void)
|
||||
boneSocketIndex[BONE_SOCKET_HAT] = i;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (TextIsEqual(characterModel.bones[i].name, "socket_hand_R"))
|
||||
{
|
||||
boneSocketIndex[BONE_SOCKET_HAND_R] = i;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (TextIsEqual(characterModel.bones[i].name, "socket_hand_L"))
|
||||
{
|
||||
boneSocketIndex[BONE_SOCKET_HAND_L] = i;
|
||||
@@ -99,7 +99,7 @@ int main(void)
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateCamera(&camera, CAMERA_THIRD_PERSON);
|
||||
|
||||
|
||||
// Rotate character
|
||||
if (IsKeyDown(KEY_F)) angle = (angle + 1)%360;
|
||||
else if (IsKeyDown(KEY_H)) angle = (360 + angle - 1)%360;
|
||||
@@ -112,7 +112,7 @@ int main(void)
|
||||
if (IsKeyPressed(KEY_ONE)) showEquip[BONE_SOCKET_HAT] = !showEquip[BONE_SOCKET_HAT];
|
||||
if (IsKeyPressed(KEY_TWO)) showEquip[BONE_SOCKET_HAND_R] = !showEquip[BONE_SOCKET_HAND_R];
|
||||
if (IsKeyPressed(KEY_THREE)) showEquip[BONE_SOCKET_HAND_L] = !showEquip[BONE_SOCKET_HAND_L];
|
||||
|
||||
|
||||
// Update model animation
|
||||
ModelAnimation anim = modelAnimations[animIndex];
|
||||
animCurrentFrame = (animCurrentFrame + 1)%anim.frameCount;
|
||||
@@ -140,7 +140,7 @@ int main(void)
|
||||
Transform *transform = &anim.framePoses[animCurrentFrame][boneSocketIndex[i]];
|
||||
Quaternion inRotation = characterModel.bindPose[boneSocketIndex[i]].rotation;
|
||||
Quaternion outRotation = transform->rotation;
|
||||
|
||||
|
||||
// Calculate socket rotation (angle between bone in initial pose and same bone in current animation frame)
|
||||
Quaternion rotate = QuaternionMultiply(outRotation, QuaternionInvert(inRotation));
|
||||
Matrix matrixTransform = QuaternionToMatrix(rotate);
|
||||
@@ -148,7 +148,7 @@ int main(void)
|
||||
matrixTransform = MatrixMultiply(matrixTransform, MatrixTranslate(transform->translation.x, transform->translation.y, transform->translation.z));
|
||||
// Transform the socket using the transform of the character (angle and translate)
|
||||
matrixTransform = MatrixMultiply(matrixTransform, characterModel.transform);
|
||||
|
||||
|
||||
// Draw mesh at socket position with socket angle rotation
|
||||
DrawMesh(equipModel[i].meshes[0], equipModel[i].materials[1], matrixTransform);
|
||||
}
|
||||
@@ -168,7 +168,7 @@ int main(void)
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadModelAnimations(modelAnimations, animsCount);
|
||||
UnloadModel(characterModel); // Unload character model and meshes/material
|
||||
|
||||
|
||||
// Unload equipment model and meshes/material
|
||||
for (int i = 0; i < BONE_SOCKETS; i++) UnloadModel(equipModel[i]);
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ int main(void)
|
||||
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
|
||||
camera.fovy = 45.0f;
|
||||
camera.projection = CAMERA_PERSPECTIVE;
|
||||
|
||||
|
||||
// Load texture to be applied to the cubes sides
|
||||
Texture2D texture = LoadTexture("resources/cubicmap_atlas.png");
|
||||
|
||||
@@ -69,7 +69,7 @@ int main(void)
|
||||
DrawCubeTexture(texture, (Vector3){ -2.0f, 2.0f, 0.0f }, 2.0f, 4.0f, 2.0f, WHITE);
|
||||
|
||||
// Draw cube with an applied texture, but only a defined rectangle piece of the texture
|
||||
DrawCubeTextureRec(texture, (Rectangle){ 0.0f, texture.height/2.0f, texture.width/2.0f, texture.height/2.0f },
|
||||
DrawCubeTextureRec(texture, (Rectangle){ 0.0f, texture.height/2.0f, texture.width/2.0f, texture.height/2.0f },
|
||||
(Vector3){ 2.0f, 1.0f, 0.0f }, 2.0f, 2.0f, 2.0f, WHITE);
|
||||
|
||||
DrawGrid(10, 1.0f); // Draw a grid
|
||||
@@ -85,7 +85,7 @@ int main(void)
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadTexture(texture); // Unload texture
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
@@ -171,7 +171,7 @@ void DrawCubeTextureRec(Texture2D texture, Rectangle source, Vector3 position, f
|
||||
rlSetTexture(texture.id);
|
||||
|
||||
// We calculate the normalized texture coordinates for the desired texture-source-rectangle
|
||||
// It means converting from (tex.width, tex.height) coordinates to [0.0f, 1.0f] equivalent
|
||||
// It means converting from (tex.width, tex.height) coordinates to [0.0f, 1.0f] equivalent
|
||||
rlBegin(RL_QUADS);
|
||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* raylib [core] example - Doing skinning on the gpu using a vertex shader
|
||||
*
|
||||
* Example complexity rating: [★★★☆] 3/4
|
||||
*
|
||||
*
|
||||
* Example originally created with raylib 4.5, last time updated with raylib 4.5
|
||||
*
|
||||
* Example contributed by Daniel Holden (@orangeduck) and reviewed by Ramon Santamaria (@raysan5)
|
||||
@@ -12,7 +12,7 @@
|
||||
* BSD-like license that allows static linking with closed source software
|
||||
*
|
||||
* Copyright (c) 2024-2025 Daniel Holden (@orangeduck)
|
||||
*
|
||||
*
|
||||
* Note: Due to limitations in the Apple OpenGL driver, this feature does not work on MacOS
|
||||
*
|
||||
********************************************************************************************/
|
||||
@@ -49,13 +49,13 @@ int main(void)
|
||||
|
||||
// Load gltf model
|
||||
Model characterModel = LoadModel("resources/models/gltf/greenman.glb"); // Load character model
|
||||
|
||||
|
||||
// Load skinning shader
|
||||
Shader skinningShader = LoadShader(TextFormat("resources/shaders/glsl%i/skinning.vs", GLSL_VERSION),
|
||||
TextFormat("resources/shaders/glsl%i/skinning.fs", GLSL_VERSION));
|
||||
|
||||
|
||||
characterModel.materials[1].shader = skinningShader;
|
||||
|
||||
|
||||
// Load gltf model animations
|
||||
int animsCount = 0;
|
||||
unsigned int animIndex = 0;
|
||||
@@ -75,7 +75,7 @@ int main(void)
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateCamera(&camera, CAMERA_THIRD_PERSON);
|
||||
|
||||
|
||||
// Select current animation
|
||||
if (IsKeyPressed(KEY_T)) animIndex = (animIndex + 1)%animsCount;
|
||||
else if (IsKeyPressed(KEY_G)) animIndex = (animIndex + animsCount - 1)%animsCount;
|
||||
@@ -94,12 +94,12 @@ int main(void)
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
BeginMode3D(camera);
|
||||
|
||||
|
||||
// Draw character mesh, pose calculation is done in shader (GPU skinning)
|
||||
DrawMesh(characterModel.meshes[0], characterModel.materials[1], characterModel.transform);
|
||||
|
||||
DrawGrid(10, 1.0f);
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
DrawText("Use the T/G to switch animation", 10, 10, 20, GRAY);
|
||||
@@ -113,7 +113,7 @@ int main(void)
|
||||
UnloadModelAnimations(modelAnimations, animsCount); // Unload model animation
|
||||
UnloadModel(characterModel); // Unload model and meshes/material
|
||||
UnloadShader(skinningShader); // Unload GPU skinning shader
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ int main(void)
|
||||
// Load gltf model
|
||||
Model model = LoadModel("resources/models/gltf/robot.glb");
|
||||
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
|
||||
|
||||
|
||||
// Load gltf model animations
|
||||
int animsCount = 0;
|
||||
unsigned int animIndex = 0;
|
||||
|
||||
@@ -47,7 +47,7 @@ int main(void)
|
||||
models[6] = LoadModelFromMesh(GenMeshKnot(1.0f, 2.0f, 16, 128));
|
||||
models[7] = LoadModelFromMesh(GenMeshPoly(5, 2.0f));
|
||||
models[8] = LoadModelFromMesh(GenMeshCustom());
|
||||
|
||||
|
||||
// NOTE: Generated meshes could be exported using ExportMesh()
|
||||
|
||||
// Set checked texture as default diffuse component for all models material
|
||||
|
||||
@@ -137,7 +137,7 @@ int main(void)
|
||||
RayCollision meshHitInfo = { 0 };
|
||||
for (int m = 0; m < tower.meshCount; m++)
|
||||
{
|
||||
// NOTE: We consider the model.transform for the collision check but
|
||||
// NOTE: We consider the model.transform for the collision check but
|
||||
// it can be checked against any transform Matrix, used when checking against same
|
||||
// model drawn multiple times with multiple transforms
|
||||
meshHitInfo = GetRayCollisionMesh(ray, tower.meshes[m], tower.transform);
|
||||
@@ -145,7 +145,7 @@ int main(void)
|
||||
{
|
||||
// Save the closest hit mesh
|
||||
if ((!collision.hit) || (collision.distance > meshHitInfo.distance)) collision = meshHitInfo;
|
||||
|
||||
|
||||
break; // Stop once one mesh collision is detected, the colliding mesh is m
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ int main()
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - point rendering");
|
||||
|
||||
Camera camera = {
|
||||
@@ -50,10 +50,10 @@ int main()
|
||||
bool useDrawModelPoints = true;
|
||||
bool numPointsChanged = false;
|
||||
int numPoints = 1000;
|
||||
|
||||
|
||||
Mesh mesh = GenMeshPoints(numPoints);
|
||||
Model model = LoadModelFromMesh(mesh);
|
||||
|
||||
|
||||
//SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
@@ -114,14 +114,14 @@ int main()
|
||||
.b = mesh.colors[i*4 + 2],
|
||||
.a = mesh.colors[i*4 + 3],
|
||||
};
|
||||
|
||||
|
||||
DrawPoint3D(pos, color);
|
||||
}
|
||||
}
|
||||
|
||||
// Draw a unit sphere for reference
|
||||
DrawSphereWires(position, 1.0f, 10, 10, YELLOW);
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
// Draw UI text
|
||||
@@ -129,12 +129,12 @@ int main()
|
||||
DrawText("Up - increase points", 20, 70, 20, WHITE);
|
||||
DrawText("Down - decrease points", 20, 100, 20, WHITE);
|
||||
DrawText("Space - drawing function", 20, 130, 20, WHITE);
|
||||
|
||||
|
||||
if (useDrawModelPoints) DrawText("Using: DrawModelPoints()", 20, 160, 20, GREEN);
|
||||
else DrawText("Using: DrawPoint3D()", 20, 160, 20, RED);
|
||||
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
@@ -151,7 +151,7 @@ int main()
|
||||
// Generate a spherical point cloud
|
||||
static Mesh GenMeshPoints(int numPoints)
|
||||
{
|
||||
Mesh mesh = {
|
||||
Mesh mesh = {
|
||||
.triangleCount = 1,
|
||||
.vertexCount = numPoints,
|
||||
.vertices = (float *)MemAlloc(numPoints*3*sizeof(float)),
|
||||
@@ -164,13 +164,13 @@ static Mesh GenMeshPoints(int numPoints)
|
||||
float theta = ((float)PI*rand())/RAND_MAX;
|
||||
float phi = (2.0f*PI*rand())/RAND_MAX;
|
||||
float r = (10.0f*rand())/RAND_MAX;
|
||||
|
||||
|
||||
mesh.vertices[i*3 + 0] = r*sinf(theta)*cosf(phi);
|
||||
mesh.vertices[i*3 + 1] = r*sinf(theta)*sinf(phi);
|
||||
mesh.vertices[i*3 + 2] = r*cosf(theta);
|
||||
|
||||
|
||||
Color color = ColorFromHSV(r*360.0f, 1.0f, 1.0f);
|
||||
|
||||
|
||||
mesh.colors[i*4 + 0] = color.r;
|
||||
mesh.colors[i*4 + 1] = color.g;
|
||||
mesh.colors[i*4 + 2] = color.b;
|
||||
@@ -179,6 +179,6 @@ static Mesh GenMeshPoints(int numPoints)
|
||||
|
||||
// Upload mesh data from CPU (RAM) to GPU (VRAM) memory
|
||||
UploadMesh(&mesh, false);
|
||||
|
||||
|
||||
return mesh;
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ int main(void)
|
||||
SetShaderValue(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, SHADER_UNIFORM_INT);
|
||||
|
||||
char skyboxFileName[256] = { 0 };
|
||||
|
||||
|
||||
if (useHDR)
|
||||
{
|
||||
TextCopy(skyboxFileName, "resources/dresden_square_2k.hdr");
|
||||
@@ -116,7 +116,7 @@ int main(void)
|
||||
{
|
||||
// Unload current cubemap texture to load new one
|
||||
UnloadTexture(skybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture);
|
||||
|
||||
|
||||
if (useHDR)
|
||||
{
|
||||
// Load HDR panorama (sphere) texture
|
||||
@@ -124,7 +124,7 @@ int main(void)
|
||||
|
||||
// Generate cubemap from panorama texture
|
||||
skybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture = GenTextureCubemap(shdrCubemap, panorama, 1024, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8);
|
||||
|
||||
|
||||
UnloadTexture(panorama); // Texture not required anymore, cubemap already generated
|
||||
}
|
||||
else
|
||||
@@ -223,7 +223,7 @@ static TextureCubemap GenTextureCubemap(Shader shader, Texture2D panorama, int s
|
||||
};
|
||||
|
||||
rlViewport(0, 0, size, size); // Set viewport to current fbo dimensions
|
||||
|
||||
|
||||
// Activate and enable texture for drawing to cubemap faces
|
||||
rlActiveTextureSlot(0);
|
||||
rlEnableTexture(panorama.id);
|
||||
@@ -232,7 +232,7 @@ static TextureCubemap GenTextureCubemap(Shader shader, Texture2D panorama, int s
|
||||
{
|
||||
// Set the view matrix for the current cube face
|
||||
rlSetUniformMatrix(shader.locs[SHADER_LOC_MATRIX_VIEW], fboViews[i]);
|
||||
|
||||
|
||||
// Select the current cubemap face attachment for the fbo
|
||||
// WARNING: This function by default enables->attach->disables fbo!!!
|
||||
rlFramebufferAttach(fbo, cubemap.id, RL_ATTACHMENT_COLOR_CHANNEL0, RL_ATTACHMENT_CUBEMAP_POSITIVE_X + i, 0);
|
||||
|
||||
@@ -32,7 +32,7 @@ int main(void)
|
||||
const int screenHeight = 450;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - tesseract view");
|
||||
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera camera = { 0 };
|
||||
camera.position = (Vector3){ 4.0f, 4.0f, 4.0f }; // Camera position
|
||||
@@ -43,16 +43,16 @@ int main(void)
|
||||
|
||||
// Find the coordinates by setting XYZW to +-1
|
||||
Vector4 tesseract[16] = {
|
||||
{ 1, 1, 1, 1 }, { 1, 1, 1, -1 },
|
||||
{ 1, 1, 1, 1 }, { 1, 1, 1, -1 },
|
||||
{ 1, 1, -1, 1 }, { 1, 1, -1, -1 },
|
||||
{ 1, -1, 1, 1 }, { 1, -1, 1, -1 },
|
||||
{ 1, -1, 1, 1 }, { 1, -1, 1, -1 },
|
||||
{ 1, -1, -1, 1 }, { 1, -1, -1, -1 },
|
||||
{ -1, 1, 1, 1 }, { -1, 1, 1, -1 },
|
||||
{ -1, 1, 1, 1 }, { -1, 1, 1, -1 },
|
||||
{ -1, 1, -1, 1 }, { -1, 1, -1, -1 },
|
||||
{ -1, -1, 1, 1 }, { -1, -1, 1, -1 },
|
||||
{ -1, -1, 1, 1 }, { -1, -1, 1, -1 },
|
||||
{ -1, -1, -1, 1 }, { -1, -1, -1, -1 },
|
||||
};
|
||||
|
||||
|
||||
float rotation = 0.0f;
|
||||
Vector3 transformed[16] = { 0 };
|
||||
float wValues[16] = { 0 };
|
||||
@@ -66,7 +66,7 @@ int main(void)
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
rotation = DEG2RAD*45.0f*GetTime();
|
||||
|
||||
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
Vector4 p = tesseract[i];
|
||||
@@ -92,9 +92,9 @@ int main(void)
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
|
||||
BeginMode3D(camera);
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
@@ -114,7 +114,7 @@ int main(void)
|
||||
}
|
||||
}
|
||||
EndMode3D();
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ int main()
|
||||
};
|
||||
|
||||
// Pick a color with a hue depending on cube position for the rainbow color effect
|
||||
// NOTE: This function is quite costly to be done per cube and frame,
|
||||
// NOTE: This function is quite costly to be done per cube and frame,
|
||||
// pre-catching the results into a separate array could improve performance
|
||||
Color cubeColor = ColorFromHSV((float)(((x + y + z)*18)%360), 0.75f, 0.9f);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user