Fix viewmodel stability and item textures - v1.6.2

This commit is contained in:
Michael Howard 2026-04-23 15:18:36 -05:00
parent 3d23e0c896
commit d5745bcd79
7 changed files with 36 additions and 18 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 476 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 647 KiB

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 476 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 647 KiB

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 476 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 647 KiB

After

Width:  |  Height:  |  Size: 5.0 KiB

View File

@ -659,7 +659,7 @@ int main(void)
camera3D.projection = CAMERA_PERSPECTIVE; camera3D.projection = CAMERA_PERSPECTIVE;
// 3D Block Textures Setup // 3D Block Textures Setup
Texture2D blockTextures[16] = {0}; Texture2D blockTextures[32] = {0};
blockTextures[DIRT] = LoadTexture("assets/dirt.png"); blockTextures[DIRT] = LoadTexture("assets/dirt.png");
blockTextures[GRASS] = LoadTexture("assets/grass.png"); blockTextures[GRASS] = LoadTexture("assets/grass.png");
blockTextures[COBBLESTONE] = LoadTexture("assets/cobblestone.png"); blockTextures[COBBLESTONE] = LoadTexture("assets/cobblestone.png");
@ -686,6 +686,10 @@ int main(void)
blockTextures[STICK] = LoadTexture("assets/stick.png"); blockTextures[STICK] = LoadTexture("assets/stick.png");
blockTextures[WOOD_AXE] = LoadTexture("assets/wooden_axe.png"); blockTextures[WOOD_AXE] = LoadTexture("assets/wooden_axe.png");
// Explicitly check for successful load and print warning if fail
if (blockTextures[STICK].id == 0) TraceLog(LOG_WARNING, "FAILED TO LOAD STICK TEXTURE");
if (blockTextures[WOOD_AXE].id == 0) TraceLog(LOG_WARNING, "FAILED TO LOAD AXE TEXTURE");
// Inventory Crafting State // Inventory Crafting State
InventorySlot craftingSlots[4]; // Default to AIR/0 InventorySlot craftingSlots[4]; // Default to AIR/0
InventorySlot craftingResult(AIR, 0); InventorySlot craftingResult(AIR, 0);
@ -1054,8 +1058,8 @@ int main(void)
DrawTexturePro(titleTexture, sourceRec, destRec, origin, 0.0f, WHITE); DrawTexturePro(titleTexture, sourceRec, destRec, origin, 0.0f, WHITE);
EndMode2D(); EndMode2D();
// Show Version Number (v1.6.1) in Red // Show Version Number (v1.6.2) in Red
DrawTextEx(customFont, "v1.6.1", (Vector2){ (float)currentWidth - 140, (float)currentHeight - 40 }, 22, 1.0f, RED); DrawTextEx(customFont, "v1.6.2", (Vector2){ (float)currentWidth - 140, (float)currentHeight - 40 }, 22, 1.0f, RED);
} }
Vector2 mousePos = GetMousePosition(); Vector2 mousePos = GetMousePosition();
@ -1651,7 +1655,8 @@ int main(void)
rlDisableDepthTest(); // Draw on top rlDisableDepthTest(); // Draw on top
rlPushMatrix(); rlPushMatrix();
// Transform to camera space manually for the viewmodel // Build a stable viewmodel matrix
// We use the camera's right/up/forward but dampen the vertical tilt
Vector3 forwardVM = Vector3Subtract(camera3D.target, camera3D.position); Vector3 forwardVM = Vector3Subtract(camera3D.target, camera3D.position);
forwardVM = Vector3Normalize(forwardVM); forwardVM = Vector3Normalize(forwardVM);
Vector3 rightVM = Vector3CrossProduct(forwardVM, camera3D.up); Vector3 rightVM = Vector3CrossProduct(forwardVM, camera3D.up);
@ -1659,27 +1664,40 @@ int main(void)
Vector3 upVM = Vector3CrossProduct(rightVM, forwardVM); Vector3 upVM = Vector3CrossProduct(rightVM, forwardVM);
upVM = Vector3Normalize(upVM); upVM = Vector3Normalize(upVM);
Vector3 handPos = Vector3Add(camera3D.position, Vector3Scale(forwardVM, 0.4f)); // Horizontal-only forward for arm orientation
handPos = Vector3Add(handPos, Vector3Scale(rightVM, 0.25f)); Vector3 hForward = { forwardVM.x, 0, forwardVM.z };
handPos = Vector3Add(handPos, Vector3Scale(upVM, -0.2f - swingVal * 0.1f)); hForward = Vector3Normalize(hForward);
// Draw Arm float swingVal = sinf(swingTime * PI);
DrawCube(handPos, 0.08f, 0.2f, 0.08f, (Color){220, 180, 150, 255});
// Hand position relative to camera
Vector3 handPos = Vector3Add(camera3D.position, Vector3Scale(forwardVM, 0.45f));
handPos = Vector3Add(handPos, Vector3Scale(rightVM, 0.28f));
handPos = Vector3Add(handPos, Vector3Scale(upVM, -0.25f - swingVal * 0.15f));
// Draw Arm (rotated cube)
// We use rlgl to rotate it to point roughly forward
rlPushMatrix();
rlTranslatef(handPos.x, handPos.y, handPos.z);
rlRotatef(camYaw * 180.0f/PI, 0, 1, 0); // Yaw with camera
rlRotatef(-20.0f - swingVal * 30.0f, 1, 0, 0); // Slight slant
DrawCube((Vector3){0,0,0}, 0.08f, 0.1f, 0.35f, (Color){220, 180, 150, 255});
rlPopMatrix();
// Draw Held Item // Draw Held Item
int heldBT = hotbar[activeHotbarSlot].blockType; int heldBT = hotbar[activeHotbarSlot].blockType;
if (heldBT != AIR) { if (heldBT != AIR) {
Vector3 itemPos = Vector3Add(handPos, Vector3Scale(upVM, 0.1f)); Vector3 itemPos = Vector3Add(handPos, Vector3Scale(forwardVM, 0.12f));
itemPos = Vector3Add(itemPos, Vector3Scale(forwardVM, 0.1f)); itemPos = Vector3Add(itemPos, Vector3Scale(upVM, 0.12f));
itemPos = Vector3Add(itemPos, Vector3Scale(rightVM, -0.05f));
if (heldBT < STICK) { Texture2D itemTex = (heldBT == GRASS) ? grassTopTexture : (heldBT == CRAFTING_TABLE ? craftingSideTexture : blockTextures[heldBT]);
// Block if (itemTex.id > 0) {
DrawCube(itemPos, 0.15f, 0.15f, 0.15f, blockTint); // Draw as a billboard facing the camera for best clarity
DrawCubeWires(itemPos, 0.151f, 0.151f, 0.151f, BLACK); DrawBillboard(camera3D, itemTex, itemPos, 0.18f, WHITE);
} else { } else {
// Item (Stick/Axe) - use small thin cube for now // Fallback
Color itemColor = (heldBT == STICK) ? BROWN : DARKGRAY; DrawCube(itemPos, 0.1f, 0.1f, 0.1f, RED);
DrawCube(itemPos, 0.03f, 0.25f, 0.03f, itemColor);
} }
} }
rlPopMatrix(); rlPopMatrix();