mirror of
https://github.com/raysan5/raylib.git
synced 2026-04-12 01:59:09 -04:00
Remove trailing spaces
This commit is contained in:
@ -43,7 +43,7 @@
|
||||
// Module Functions Declaration
|
||||
//------------------------------------------------------------------------------------
|
||||
static bool IsUpperBodyBone(const char *boneName);
|
||||
static void UpdateModelAnimationBones(Model *model, ModelAnimation *anim1, int frame1,
|
||||
static void UpdateModelAnimationBones(Model *model, ModelAnimation *anim1, int frame1,
|
||||
ModelAnimation *anim2, int frame2, float blend, bool upperBodyBlend);
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
@ -86,7 +86,7 @@ int main(void)
|
||||
int animIndex1 = 3; // Attack animation (index 3)
|
||||
int animCurrentFrame0 = 0;
|
||||
int animCurrentFrame1 = 0;
|
||||
|
||||
|
||||
// Validate indices
|
||||
if (animIndex0 >= animCount) animIndex0 = 0;
|
||||
if (animIndex1 >= animCount) animIndex1 = (animCount > 1) ? 1 : 0;
|
||||
@ -109,7 +109,7 @@ int main(void)
|
||||
// Update animation frames
|
||||
ModelAnimation anim0 = anims[animIndex0];
|
||||
ModelAnimation anim1 = anims[animIndex1];
|
||||
|
||||
|
||||
animCurrentFrame0 = (animCurrentFrame0 + 1)%anim0.keyframeCount;
|
||||
animCurrentFrame1 = (animCurrentFrame1 + 1)%anim1.keyframeCount;
|
||||
|
||||
@ -117,11 +117,11 @@ int main(void)
|
||||
// When upperBodyBlend is ON: upper body = attack (1.0), lower body = walk (0.0)
|
||||
// When upperBodyBlend is OFF: uniform blend at 0.5 (50% walk, 50% attack)
|
||||
float blendFactor = (upperBodyBlend? 1.0f : 0.5f);
|
||||
UpdateModelAnimationBones(&model, &anim0, animCurrentFrame0,
|
||||
UpdateModelAnimationBones(&model, &anim0, animCurrentFrame0,
|
||||
&anim1, animCurrentFrame1, blendFactor, upperBodyBlend);
|
||||
|
||||
// raylib provided animation blending function
|
||||
//UpdateModelAnimationEx(model, anim0, (float)animCurrentFrame0,
|
||||
//UpdateModelAnimationEx(model, anim0, (float)animCurrentFrame0,
|
||||
// anim1, (float)animCurrentFrame1, blendFactor);
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
@ -142,8 +142,8 @@ int main(void)
|
||||
// Draw UI
|
||||
DrawText(TextFormat("ANIM 0: %s", anim0.name), 10, 10, 20, GRAY);
|
||||
DrawText(TextFormat("ANIM 1: %s", anim1.name), 10, 40, 20, GRAY);
|
||||
DrawText(TextFormat("[SPACE] Toggle blending mode: %s",
|
||||
upperBodyBlend? "Upper/Lower Body Blending" : "Uniform Blending"),
|
||||
DrawText(TextFormat("[SPACE] Toggle blending mode: %s",
|
||||
upperBodyBlend? "Upper/Lower Body Blending" : "Uniform Blending"),
|
||||
10, GetScreenHeight() - 30, 20, DARKGRAY);
|
||||
|
||||
EndDrawing();
|
||||
@ -180,7 +180,7 @@ static bool IsUpperBodyBone(const char *boneName)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Check if bone name contains upper body keywords
|
||||
if (strstr(boneName, "spine") != NULL || strstr(boneName, "chest") != NULL ||
|
||||
strstr(boneName, "neck") != NULL || strstr(boneName, "head") != NULL ||
|
||||
@ -189,12 +189,12 @@ static bool IsUpperBodyBone(const char *boneName)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Blend two animations per-bone with selective upper/lower body blending
|
||||
static void UpdateModelAnimationBones(Model *model, ModelAnimation *anim0, int frame0,
|
||||
static void UpdateModelAnimationBones(Model *model, ModelAnimation *anim0, int frame0,
|
||||
ModelAnimation *anim1, int frame1, float blend, bool upperBodyBlend)
|
||||
{
|
||||
// Validate inputs
|
||||
@ -204,59 +204,59 @@ static void UpdateModelAnimationBones(Model *model, ModelAnimation *anim0, int f
|
||||
{
|
||||
// Clamp blend factor to [0, 1]
|
||||
blend = fminf(1.0f, fmaxf(0.0f, blend));
|
||||
|
||||
|
||||
// Ensure frame indices are valid
|
||||
if (frame0 >= anim0->keyframeCount) frame0 = anim0->keyframeCount - 1;
|
||||
if (frame1 >= anim1->keyframeCount) frame1 = anim1->keyframeCount - 1;
|
||||
if (frame0 < 0) frame0 = 0;
|
||||
if (frame1 < 0) frame1 = 0;
|
||||
|
||||
|
||||
// Get bone count (use minimum of all to be safe)
|
||||
int boneCount = model->skeleton.boneCount;
|
||||
if (anim0->boneCount < boneCount) boneCount = anim0->boneCount;
|
||||
if (anim1->boneCount < boneCount) boneCount = anim1->boneCount;
|
||||
|
||||
|
||||
// Blend each bone
|
||||
for (int boneIndex = 0; boneIndex < boneCount; boneIndex++)
|
||||
{
|
||||
// Determine blend factor for this bone
|
||||
float boneBlendFactor = blend;
|
||||
|
||||
|
||||
// If upper body blending is enabled, use different blend factors for upper vs lower body
|
||||
if (upperBodyBlend)
|
||||
{
|
||||
const char *boneName = model->skeleton.bones[boneIndex].name;
|
||||
bool isUpperBody = IsUpperBodyBone(boneName);
|
||||
|
||||
|
||||
// Upper body: use anim1 (attack), Lower body: use anim0 (walk)
|
||||
// blend = 0.0 means full anim0 (walk), 1.0 means full anim1 (attack)
|
||||
if (isUpperBody) boneBlendFactor = blend; // Upper body: blend towards anim1 (attack)
|
||||
else boneBlendFactor = 1.0f - blend; // Lower body: blend towards anim0 (walk) - invert the blend
|
||||
}
|
||||
|
||||
|
||||
// Get transforms from both animations
|
||||
Transform *bindTransform = &model->skeleton.bindPose[boneIndex];
|
||||
Transform *animTransform0 = &anim0->keyframePoses[frame0][boneIndex];
|
||||
Transform *animTransform1 = &anim1->keyframePoses[frame1][boneIndex];
|
||||
|
||||
|
||||
// Blend the transforms
|
||||
Transform blended = { 0 };
|
||||
blended.translation = Vector3Lerp(animTransform0->translation, animTransform1->translation, boneBlendFactor);
|
||||
blended.rotation = QuaternionSlerp(animTransform0->rotation, animTransform1->rotation, boneBlendFactor);
|
||||
blended.scale = Vector3Lerp(animTransform0->scale, animTransform1->scale, boneBlendFactor);
|
||||
|
||||
|
||||
// Convert bind pose to matrix
|
||||
Matrix bindMatrix = MatrixMultiply(MatrixMultiply(
|
||||
MatrixScale(bindTransform->scale.x, bindTransform->scale.y, bindTransform->scale.z),
|
||||
QuaternionToMatrix(bindTransform->rotation)),
|
||||
MatrixTranslate(bindTransform->translation.x, bindTransform->translation.y, bindTransform->translation.z));
|
||||
|
||||
|
||||
// Convert blended transform to matrix
|
||||
Matrix blendedMatrix = MatrixMultiply(MatrixMultiply(
|
||||
MatrixScale(blended.scale.x, blended.scale.y, blended.scale.z),
|
||||
QuaternionToMatrix(blended.rotation)),
|
||||
MatrixTranslate(blended.translation.x, blended.translation.y, blended.translation.z));
|
||||
|
||||
|
||||
// Calculate final bone matrix (similar to UpdateModelAnimationBones)
|
||||
model->boneMatrices[boneIndex] = MatrixMultiply(MatrixInvert(bindMatrix), blendedMatrix);
|
||||
}
|
||||
@ -276,7 +276,7 @@ static void UpdateModelAnimationBones(Model *model, ModelAnimation *anim0, int f
|
||||
bool bufferUpdateRequired = false; // Flag to check when anim vertex information is updated
|
||||
|
||||
// Skip if missing bone data or missing anim buffers initialization
|
||||
if ((mesh.boneWeights == NULL) || (mesh.boneIndices == NULL) ||
|
||||
if ((mesh.boneWeights == NULL) || (mesh.boneIndices == NULL) ||
|
||||
(mesh.animVertices == NULL) || (mesh.animNormals == NULL)) continue;
|
||||
|
||||
for (int vCounter = 0; vCounter < vertexValuesCount; vCounter += 3)
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
* raylib [models] example - animation blending
|
||||
*
|
||||
* Example complexity rating: [★★★★] 4/4
|
||||
*
|
||||
*
|
||||
* Example originally created with raylib 5.5, last time updated with raylib 6.0
|
||||
*
|
||||
* Example contributed by Kirandeep (@Kirandeep-Singh-Khehra) and reviewed by Ramon Santamaria (@raysan5)
|
||||
@ -57,7 +57,7 @@ int main(void)
|
||||
// WARNING: It requires SUPPORT_GPU_SKINNING enabled on raylib (disabled by default)
|
||||
Shader skinningShader = LoadShader(TextFormat("resources/shaders/glsl%i/skinning.vs", GLSL_VERSION),
|
||||
TextFormat("resources/shaders/glsl%i/skinning.fs", GLSL_VERSION));
|
||||
|
||||
|
||||
// Assign skinning shader to all materials shaders
|
||||
//for (int i = 0; i < model.materialCount; i++) model.materials[i].shader = skinningShader;
|
||||
|
||||
@ -105,7 +105,7 @@ int main(void)
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateCamera(&camera, CAMERA_ORBITAL);
|
||||
|
||||
|
||||
if (IsKeyPressed(KEY_P)) animPause = !animPause;
|
||||
|
||||
if (!animPause)
|
||||
@ -127,7 +127,7 @@ int main(void)
|
||||
}
|
||||
|
||||
// Set animation transition
|
||||
animTransition = true;
|
||||
animTransition = true;
|
||||
animBlendTimeCounter = 0.0f;
|
||||
animBlendFactor = 0.0f;
|
||||
}
|
||||
@ -182,7 +182,7 @@ int main(void)
|
||||
animCurrentFrame0 += animFrameSpeed0;
|
||||
if (animCurrentFrame0 >= anims[animIndex0].keyframeCount) animCurrentFrame0 = 0.0f;
|
||||
UpdateModelAnimation(model, anims[animIndex0], animCurrentFrame0);
|
||||
//UpdateModelAnimationEx(model, anims[animIndex0], animCurrentFrame0,
|
||||
//UpdateModelAnimationEx(model, anims[animIndex0], animCurrentFrame0,
|
||||
// anims[animIndex1], animCurrentFrame1, 0.0f); // Same as above, first animation frame blend
|
||||
}
|
||||
else if (currentAnimPlaying == 1)
|
||||
@ -191,7 +191,7 @@ int main(void)
|
||||
animCurrentFrame1 += animFrameSpeed1;
|
||||
if (animCurrentFrame1 >= anims[animIndex1].keyframeCount) animCurrentFrame1 = 0.0f;
|
||||
UpdateModelAnimation(model, anims[animIndex1], animCurrentFrame1);
|
||||
//UpdateModelAnimationEx(model, anims[animIndex0], animCurrentFrame0,
|
||||
//UpdateModelAnimationEx(model, anims[animIndex0], animCurrentFrame0,
|
||||
// anims[animIndex1], animCurrentFrame1, 1.0f); // Same as above, second animation frame blend
|
||||
}
|
||||
}
|
||||
@ -213,7 +213,7 @@ int main(void)
|
||||
DrawModel(model, position, 1.0f, WHITE); // Draw animated model
|
||||
|
||||
DrawGrid(10, 1.0f);
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
if (animTransition) DrawText("ANIM TRANSITION BLENDING!", 170, 50, 30, BLUE);
|
||||
@ -221,18 +221,18 @@ int main(void)
|
||||
// Draw UI elements
|
||||
//---------------------------------------------------------------------------------------------
|
||||
if (dropdownEditMode0) GuiDisable();
|
||||
GuiSlider((Rectangle){ 10, 38, 160, 12 },
|
||||
GuiSlider((Rectangle){ 10, 38, 160, 12 },
|
||||
NULL, TextFormat("x%.1f", animFrameSpeed0), &animFrameSpeed0, 0.1f, 2.0f);
|
||||
GuiEnable();
|
||||
if (dropdownEditMode1) GuiDisable();
|
||||
GuiSlider((Rectangle){ GetScreenWidth() - 170.0f, 38, 160, 12 },
|
||||
GuiSlider((Rectangle){ GetScreenWidth() - 170.0f, 38, 160, 12 },
|
||||
TextFormat("%.1fx", animFrameSpeed1), NULL, &animFrameSpeed1, 0.1f, 2.0f);
|
||||
GuiEnable();
|
||||
|
||||
// Draw animation selectors for blending transition
|
||||
// NOTE: Transition does not start until requested
|
||||
// NOTE: Transition does not start until requested
|
||||
GuiSetStyle(DROPDOWNBOX, DROPDOWN_ITEMS_SPACING, 1);
|
||||
if (GuiDropdownBox((Rectangle){ 10, 10, 160, 24 }, TextJoin(animNames, animCount, ";"),
|
||||
if (GuiDropdownBox((Rectangle){ 10, 10, 160, 24 }, TextJoin(animNames, animCount, ";"),
|
||||
&animIndex0, dropdownEditMode0)) dropdownEditMode0 = !dropdownEditMode0;
|
||||
|
||||
// Blending process progress bar
|
||||
@ -249,7 +249,7 @@ int main(void)
|
||||
TextFormat("FRAME: %.2f / %i", animFrameProgress0, anims[animIndex0].keyframeCount),
|
||||
&animFrameProgress0, 0.0f, (float)anims[animIndex0].keyframeCount);
|
||||
for (int i = 0; i < anims[animIndex0].keyframeCount; i++)
|
||||
DrawRectangle(60 + (int)(((float)(GetScreenWidth() - 180)/(float)anims[animIndex0].keyframeCount)*(float)i),
|
||||
DrawRectangle(60 + (int)(((float)(GetScreenWidth() - 180)/(float)anims[animIndex0].keyframeCount)*(float)i),
|
||||
GetScreenHeight() - 60, 1, 20, BLUE);
|
||||
|
||||
// Draw playing timeline with keyframes for anim1[]
|
||||
@ -257,7 +257,7 @@ int main(void)
|
||||
TextFormat("FRAME: %.2f / %i", animFrameProgress1, anims[animIndex1].keyframeCount),
|
||||
&animFrameProgress1, 0.0f, (float)anims[animIndex1].keyframeCount);
|
||||
for (int i = 0; i < anims[animIndex1].keyframeCount; i++)
|
||||
DrawRectangle(60 + (int)(((float)(GetScreenWidth() - 180)/(float)anims[animIndex1].keyframeCount)*(float)i),
|
||||
DrawRectangle(60 + (int)(((float)(GetScreenWidth() - 180)/(float)anims[animIndex1].keyframeCount)*(float)i),
|
||||
GetScreenHeight() - 30, 1, 20, BLUE);
|
||||
//---------------------------------------------------------------------------------------------
|
||||
|
||||
@ -270,7 +270,7 @@ int main(void)
|
||||
UnloadModelAnimations(anims, animCount); // Unload model animation
|
||||
UnloadModel(model); // Unload model and meshes/material
|
||||
UnloadShader(skinningShader); // Unload GPU skinning shader
|
||||
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@ -94,26 +94,26 @@ int main(void)
|
||||
BeginMode3D(camera);
|
||||
|
||||
DrawModel(model, position, 1.0f, WHITE);
|
||||
|
||||
|
||||
DrawGrid(10, 1.0f);
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
// Draw UI, select anim and playing speed
|
||||
GuiSetStyle(DROPDOWNBOX, DROPDOWN_ITEMS_SPACING, 1);
|
||||
if (GuiDropdownBox((Rectangle){ 10, 10, 140, 24 }, TextJoin(animNames, animCount, ";"),
|
||||
if (GuiDropdownBox((Rectangle){ 10, 10, 140, 24 }, TextJoin(animNames, animCount, ";"),
|
||||
&animIndex, dropdownEditMode)) dropdownEditMode = !dropdownEditMode;
|
||||
|
||||
GuiSlider((Rectangle){ 260, 10, 500, 24 }, "FRAME SPEED: ", TextFormat("x%.1f", animFrameSpeed),
|
||||
&animFrameSpeed, 0.1f, 2.0f);
|
||||
|
||||
// Draw playing timeline with keyframes
|
||||
GuiLabel((Rectangle){ 10, GetScreenHeight() - 64.0f, GetScreenWidth() - 20.0f, 24 },
|
||||
GuiLabel((Rectangle){ 10, GetScreenHeight() - 64.0f, GetScreenWidth() - 20.0f, 24 },
|
||||
TextFormat("CURRENT FRAME: %.2f / %i", animFrameProgress, anims[animIndex].keyframeCount));
|
||||
GuiProgressBar((Rectangle){ 10, GetScreenHeight() - 40.0f, GetScreenWidth() - 20.0f, 24 }, NULL, NULL,
|
||||
&animFrameProgress, 0.0f, (float)anims[animIndex].keyframeCount);
|
||||
for (int i = 0; i < anims[animIndex].keyframeCount; i++)
|
||||
DrawRectangle(10 + (int)(((float)(GetScreenWidth() - 20)/(float)anims[animIndex].keyframeCount)*(float)i),
|
||||
DrawRectangle(10 + (int)(((float)(GetScreenWidth() - 20)/(float)anims[animIndex].keyframeCount)*(float)i),
|
||||
GetScreenHeight() - 40, 1, 24, BLUE);
|
||||
|
||||
EndDrawing();
|
||||
|
||||
@ -60,7 +60,7 @@ int main(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
@ -109,7 +109,7 @@ int main(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Remove the closest voxel if one was hit
|
||||
if (voxelFound)
|
||||
{
|
||||
@ -145,9 +145,9 @@ int main(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
EndMode3D();
|
||||
|
||||
|
||||
// Draw reference point for raycasting to delete blocks
|
||||
DrawCircle(GetScreenWidth()/2, GetScreenHeight()/2, 4, RED);
|
||||
|
||||
@ -161,7 +161,7 @@ int main(void)
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadModel(cubeModel);
|
||||
|
||||
|
||||
CloseWindow();
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@ -92,7 +92,7 @@ int main(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: WARNING: On PLATFORM_WEB it requires a big amount of memory to process input image
|
||||
// TODO: WARNING: On PLATFORM_WEB it requires a big amount of memory to process input image
|
||||
// and generate the required cubemap image to be passed to rlLoadTextureCubemap()
|
||||
Image image = LoadImage("resources/skybox.png");
|
||||
skybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture = LoadTextureCubemap(image, CUBEMAP_LAYOUT_AUTO_DETECT);
|
||||
|
||||
@ -41,7 +41,7 @@ int main(void)
|
||||
|
||||
Model model = LoadModel("resources/models/obj/plane.obj"); // Load model
|
||||
Texture2D texture = LoadTexture("resources/models/obj/plane_diffuse.png"); // Load model texture
|
||||
|
||||
|
||||
SetTextureWrap(texture, TEXTURE_WRAP_REPEAT); // Force Repeat to avoid issue on Web version
|
||||
|
||||
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture; // Set map diffuse texture
|
||||
|
||||
Reference in New Issue
Block a user