Zappy GUI
C++ graphic client: renderer, camera, network
Loading...
Searching...
No Matches
EntityRenderer.cpp
Go to the documentation of this file.
1#include "EntityRenderer.hpp"
2
3#include <cmath>
4
5#include "ColorPalette.hpp"
6#include "TileSlotMap.hpp"
7
8void EntityRenderer::drawPlayer(Vector3& worldPos, Color teamColor, float rotation, Model& model,
9 const Color* baseMats, float modelSize)
10{
11 // mat[0] idk what it controls
12 // mat[1] = internal transparent layer (reflects mat[3], lighter color)
13 // mat[2] = blush accent color
14 // mat[3] = internal body color (darker than mat[1])
15 // mat[4] = slime external small reflection (2 white blobs on top)
16 // mat[5] = seems to be the very outer reflection layer
17
20 model.materials[1].maps[MATERIAL_MAP_DIFFUSE].color = palette.outer;
22 model.materials[3].maps[MATERIAL_MAP_DIFFUSE].color = palette.inner;
24 model.materials[2].maps[MATERIAL_MAP_DIFFUSE].color = palette.blush;
25
26 DrawModelEx(model, worldPos, {0.0f, 1.0f, 0.0f}, rotation, {modelSize, modelSize, modelSize},
27 WHITE);
28
29 if (baseMats) _restoreModelBaseColors(model, baseMats);
30}
31
32void EntityRenderer::drawEgg(Vector3& worldPos, Color teamColor, Model& model, float rotation,
33 const Color* baseMats, float modelSize)
34{
35 // mat[0] = white base color, the shell
36 // mat[1] = inner part color (visible through shell)
37
38 model.materials[1].maps[MATERIAL_MAP_DIFFUSE].color = teamColor;
39 DrawModelEx(model, worldPos, {0.0f, 1.0f, 0.0f}, rotation, {modelSize, modelSize, modelSize},
40 WHITE);
41
42 if (baseMats) _restoreModelBaseColors(model, baseMats, 2);
43}
44
46 const std::array<int, 7>& slotIndices,
47 const std::array<float, 7>& rotations, const Vector3& tileCenter,
48 float tileSize, Model& foodModel, float foodModelSize,
49 Model& crystalModel, float crystalModelSize, float baseSize)
50{
51 for (int i = 0; i < 7; i++) {
52 int count = resources[i];
53 if (count <= 0 || slotIndices[i] < 0) continue;
54
55 auto [dx, dz] = TileSlotMap::slotOffset(slotIndices[i]);
56
57 // Size grows logarithmically with count
58 float size = baseSize * (1.0f + std::log(count + 1) * 0.3f);
59
60 Vector3 drawPos = {tileCenter.x + dx * tileSize, size / 2.0f, tileCenter.z + dz * tileSize};
61 float rotation = rotations[i];
62
63 if (i == 0) {
64 float s = foodModelSize * size;
65 DrawModelEx(foodModel, drawPos, {0.0f, 1.0f, 0.0f}, rotation, {s, s, s}, WHITE);
66 } else {
67 // DrawModelEx tint temporarily replaces diffuse color before draw, then restores it.
68 // Pass the mineral color as tint — raylib handles save/restore internally.
69 float s = crystalModelSize * size;
70 DrawModelEx(crystalModel, drawPos, {0.0f, 1.0f, 0.0f}, rotation, {s, s, s},
72 }
73 }
74}
75
76void EntityRenderer::_restoreModelBaseColors(Model& model, const Color* baseMats, int count)
77{
78 for (int i = 0; i < model.materialCount && i < count; i++)
79 model.materials[i].maps[MATERIAL_MAP_DIFFUSE].color = baseMats[i];
80}
static Color getResourceColor(int resourceIndex)
Returns the designated UI/3D color for a given resource index.
static bool colorEquals(Color a, Color b)
Utility to compare two colors for equality.
static constexpr Color KEEP
static SlimePalette getSlimePalette(Color teamColor)
Returns a slime palette with variations based on the team color.
static void drawEgg(Vector3 &worldPos, Color teamColor, Model &model, float rotation=0.0f, const Color *baseMats=nullptr, float modelSize=0.3f)
Draws an egg at the given world position.
static void drawResources(const Resources &resources, const std::array< int, 7 > &slotIndices, const std::array< float, 7 > &rotations, const Vector3 &tileCenter, float tileSize, Model &foodModel, float foodModelSize, Model &crystalModel, float crystalModelSize, float baseSize=0.15f)
Draws all resources for a tile using precomputed slot indices.
static void drawPlayer(Vector3 &worldPos, Color teamColor, float rotation, Model &model, const Color *baseMats, float modelSize=0.4f)
Draws a player at the given world position.
static void _restoreModelBaseColors(Model &model, const Color *baseMats, int count=6)
static std::pair< float, float > slotOffset(int slotIndex)
Returns the XZ offset pair {dx, dz} for a slot index (0-7).