ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
UVMap.cpp
Go to the documentation of this file.
1#include "UVMap.h"
2
3UVMap::UVMap(const uint8_t* data, const uint8_t* rgbColors, uint16_t xPixels, uint16_t yPixels, uint8_t colors)
4 : Image(data, rgbColors, xPixels, yPixels, colors) {
5 this->size = Vector2D(1.0f, 1.0f);
6}
7
8RGBColor UVMap::GetRGB(const Vector3D& position, const Vector3D& normal, const Vector3D& uvw) {
9 Vector2D rPos = Vector2D(1.0f - uvw.X, uvw.Y);
10
11 uint16_t x = (uint16_t)Mathematics::Map(rPos.X, 0.0f, size.X, float(xPixels), float(0));
12 uint16_t y = (uint16_t)Mathematics::Map(rPos.Y, 0.0f, size.Y, float(yPixels), float(0));
13
14 if (x < 0 || x >= xPixels || y < 0 || y >= yPixels) return RGBColor();
15
16 uint16_t pos = data[x + y * xPixels] * 3;
17
18 if (pos >= (uint16_t(colors - 1))) return RGBColor();
19
20 return RGBColor(rgbColors[pos], rgbColors[pos + 1], rgbColors[pos + 2]).HueShift(hueAngle);
21}
A material class for mapping UV texture coordinates to RGB colors.
Represents an image-based material with support for transformations and palette adjustments.
Definition Image.h:23
unsigned int xPixels
The width of the image in pixels.
Definition Image.h:29
const uint8_t * data
Pointer to the image data.
Definition Image.h:31
float hueAngle
The hue adjustment angle of the image.
Definition Image.h:28
unsigned int yPixels
The height of the image in pixels.
Definition Image.h:30
const uint8_t * rgbColors
Pointer to the color palette.
Definition Image.h:32
uint8_t colors
The number of colors in the palette.
Definition Image.h:33
Vector2D size
The size of the image.
Definition Image.h:25
static T Map(T value, T inLow, T inMax, T outMin, T outMax)
Maps a value from one range to another.
Represents an RGB color and provides methods for manipulation.
Definition RGBColor.h:23
RGBColor HueShift(const float &hueDeg)
Shifts the hue of the color by a specified angle in degrees.
Definition RGBColor.cpp:65
UVMap(const uint8_t *data, const uint8_t *rgbColors, uint16_t xPixels, uint16_t yPixels, uint8_t colors)
Constructs a UVMap with the given image data and color palette.
Definition UVMap.cpp:3
RGBColor GetRGB(const Vector3D &position, const Vector3D &normal, const Vector3D &uvw) override
Retrieves the RGB color at a given 3D position using UV mapping.
Definition UVMap.cpp:8
Represents a 2D vector (X, Y) and provides methods for vector arithmetic.
Definition Vector2D.h:27
float X
The X-component of the 2D vector.
Definition Vector2D.h:29
float Y
The Y-component of the 2D vector.
Definition Vector2D.h:30
Represents a 3D vector (X, Y, Z) and provides methods for vector arithmetic.
Definition Vector3D.h:26
float X
The X-component of the 3D vector.
Definition Vector3D.h:28
float Y
The Y-component of the 3D vector.
Definition Vector3D.h:29