ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
Image.cpp
Go to the documentation of this file.
1#include "Image.h"
2
3Image::Image(const uint8_t* data, const uint8_t* rgbColors, unsigned int xPixels, unsigned int yPixels, uint8_t colors) {
4 this->data = data;
5 this->rgbColors = rgbColors;
6 this->xPixels = xPixels;
7 this->yPixels = yPixels;
8 this->colors = colors;
9}
10
11void Image::SetData(const uint8_t* data) {
12 this->data = data;
13}
14
15void Image::SetColorPalette(const uint8_t* rgbColors) {
16 this->rgbColors = rgbColors;
17}
18
20 this->size = size;
21}
22
24 this->offset = offset;
25}
26
27void Image::SetRotation(float angle) {
28 this->angle = angle;
29}
30
31void Image::SetHueAngle(float hueAngle) {
32 this->hueAngle = hueAngle;
33}
34
35RGBColor Image::GetRGB(const Vector3D& position, const Vector3D& normal, const Vector3D& uvw) {
36 Vector2D rPos = angle != 0.0f ? Vector2D(position.X, position.Y).Rotate(angle, offset) - offset : Vector2D(position.X, position.Y) - offset;
37
38 unsigned int x = (unsigned int)Mathematics::Map(rPos.X, size.X / -2.0f, size.X / 2.0f, float(xPixels), 0.0f);
39 unsigned int y = (unsigned int)Mathematics::Map(rPos.Y, size.Y / -2.0f, size.Y / 2.0f, float(yPixels), 0.0f);
40
41 if (x <= 1 || x >= xPixels || y <= 1 || y >= yPixels) return RGBColor();
42
43 unsigned int pos = data[x + y * xPixels] * 3;
44
45 if (pos > colors - (unsigned int)1) return RGBColor();
46
47 return RGBColor(rgbColors[pos], rgbColors[pos + 1], rgbColors[pos + 2]).HueShift(hueAngle);
48}
Defines an Image material for rendering images as textures in 3D rendering.
void SetColorPalette(const uint8_t *rgbColors)
Sets the color palette.
Definition Image.cpp:15
unsigned int xPixels
The width of the image in pixels.
Definition Image.h:29
void SetPosition(Vector2D offset)
Sets the position offset of the image.
Definition Image.cpp:23
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
RGBColor GetRGB(const Vector3D &position, const Vector3D &normal, const Vector3D &uvw) override
Calculates the RGB color at a specific position.
Definition Image.cpp:35
const uint8_t * rgbColors
Pointer to the color palette.
Definition Image.h:32
void SetSize(Vector2D size)
Sets the size of the image.
Definition Image.cpp:19
void SetData(const uint8_t *data)
Sets the image data.
Definition Image.cpp:11
Vector2D offset
The offset position of the image.
Definition Image.h:26
float angle
The rotation angle of the image in degrees.
Definition Image.h:27
uint8_t colors
The number of colors in the palette.
Definition Image.h:33
Image(const uint8_t *data, const uint8_t *rgbColors, unsigned int xPixels, unsigned int yPixels, uint8_t colors)
Constructs an Image material.
Definition Image.cpp:3
void SetRotation(float angle)
Sets the rotation angle of the image.
Definition Image.cpp:27
void SetHueAngle(float hueAngle)
Sets the hue adjustment angle of the image.
Definition Image.cpp:31
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
Represents a 2D vector (X, Y) and provides methods for vector arithmetic.
Definition Vector2D.h:27
Vector2D Rotate(const float &angle, const Vector2D &offset) const
Rotates this vector by a specified angle (in degrees or radians) around a given offset.
Definition Vector2D.cpp:124
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