ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
MaterialAnimator.h
Go to the documentation of this file.
1/**
2 * @file MaterialAnimator.h
3 * @brief Provides functionality for animating transitions and blends between materials.
4 *
5 * This file defines the `MaterialAnimator` class, which enables dynamic material animations
6 * by combining multiple materials and blending them with animated opacities.
7 *
8 * @date 22/12/2024
9 * @author Coela Can't
10 */
11
12#pragma once
13
15#include "../CombineMaterial.h"
16#include "../Material.h"
17
18/**
19 * @class MaterialAnimator
20 * @brief Animates transitions and blends between multiple materials.
21 *
22 * The `MaterialAnimator` class uses an `EasyEaseAnimator` for smooth transitions
23 * between materials, allowing dynamic blending and effects in rendering systems.
24 *
25 * @tparam materialCount The maximum number of materials to animate.
26 */
27template<size_t materialCount>
28class MaterialAnimator : public Material {
29private:
31 CombineMaterial<materialCount> combineMaterial; ///< Combines multiple materials for rendering.
32 float materialRatios[materialCount]; ///< Stores the opacity ratios for each material.
33 Material* dictionary[materialCount]; ///< Holds the materials in the animator.
34 uint8_t currentMaterials = 0; ///< Tracks the number of materials added.
35 bool baseMaterialSet = false; ///< Indicates if the base material is set.
36
37public:
38 /**
39 * @brief Default constructor for `MaterialAnimator`.
40 */
42
43 /**
44 * @brief Sets the base material for the animation.
45 *
46 * @param method The method of blending for the base material.
47 * @param material Pointer to the base material.
48 */
49 void SetBaseMaterial(Material::Method method, Material* material);
50
51 /**
52 * @brief Adds a material to the animation with specified properties.
53 *
54 * @param method The blending method for this material.
55 * @param material Pointer to the material to be added.
56 * @param frames The number of frames for the transition.
57 * @param minOpacity The minimum opacity of the material during the animation.
58 * @param maxOpacity The maximum opacity of the material during the animation.
59 */
60 void AddMaterial(Material::Method method, Material* material, uint16_t frames, float minOpacity, float maxOpacity);
61
62 /**
63 * @brief Adds a specific frame for a material in the animation.
64 *
65 * @param material Reference to the material.
66 * @param opacity The opacity value for the frame.
67 */
68 void AddMaterialFrame(Material& material, float opacity);
69
70 /**
71 * @brief Retrieves the current opacity of a material.
72 *
73 * @param material Reference to the material.
74 * @return The current opacity of the material.
75 */
76 float GetMaterialOpacity(Material& material);
77
78 /**
79 * @brief Updates the animator, advancing the transitions.
80 */
81 void Update();
82
83 /**
84 * @brief Retrieves the color at a specific position, considering the blended materials.
85 *
86 * @param position The 3D position to sample the color.
87 * @param normal The normal vector at the position.
88 * @param uvw UVW coordinates at the position.
89 * @return The blended RGB color at the specified position.
90 */
91 RGBColor GetRGB(const Vector3D& position, const Vector3D& normal, const Vector3D& uvw) override;
92};
93
94#include "MaterialAnimator.tpp" // Includes the template implementation.
Combines multiple materials with different blending methods and opacities.
Declares the EasyEaseAnimator template class for advanced animation easing.
Base class for materials defining shading and rendering behavior.
Combines multiple materials with specified blending methods and opacities.
A template class for implementing advanced animation easing.
@ Cosine
Smooth cosine interpolation.
Material * dictionary[materialCount]
Holds the materials in the animator.
EasyEaseAnimator< materialCount > eEA
Animator for easing transitions.
void AddMaterial(Material::Method method, Material *material, uint16_t frames, float minOpacity, float maxOpacity)
Adds a material to the animation with specified properties.
float materialRatios[materialCount]
Stores the opacity ratios for each material.
MaterialAnimator()
Default constructor for MaterialAnimator.
CombineMaterial< materialCount > combineMaterial
Combines multiple materials for rendering.
bool baseMaterialSet
Indicates if the base material is set.
RGBColor GetRGB(const Vector3D &position, const Vector3D &normal, const Vector3D &uvw) override
Retrieves the color at a specific position, considering the blended materials.
void SetBaseMaterial(Material::Method method, Material *material)
Sets the base material for the animation.
float GetMaterialOpacity(Material &material)
Retrieves the current opacity of a material.
void AddMaterialFrame(Material &material, float opacity)
Adds a specific frame for a material in the animation.
void Update()
Updates the animator, advancing the transitions.
uint8_t currentMaterials
Tracks the number of materials added.
Abstract base class for rendering materials.
Definition Material.h:27
Method
Defines blending methods for combining colors.
Definition Material.h:33
Represents an RGB color and provides methods for manipulation.
Definition RGBColor.h:23
Represents a 3D vector (X, Y, Z) and provides methods for vector arithmetic.
Definition Vector3D.h:26