RSTools 3.1.0
Versatile C++20 utility library
Loading...
Searching...
No Matches
graphics.cpp

Vectors, a transformation matrix, seeded random numbers and colors.

Vectors, a transformation matrix, seeded random numbers and colors.

#include <iostream>
int main() {
using namespace RST::Maths;
namespace Colors = RST::Color;
// Vectors
const Vec2f position(3.f, 4.f);
const Vec2f velocity = Vec2f(1.f, 0.5f) * 2;
std::cout << "distance to origin: " << position.length() << '\n'; // 5
std::cout << "next position: " << position + velocity << '\n'; // (5, 5)
// Matrices: scale then move a point
const Matrix4f transform = Matrix4f::translation(1.f, 2.f, 3.f) * Matrix4f::scale(2.f);
std::cout << "transformed: " << transform.transformPoint(Vec3f(1.f, 1.f, 1.f)) << '\n'; // (3, 4, 5)
// Random numbers, reproducible once seeded
randomEngine().seed(42);
std::cout << "dice: " << random(1, 6) << ", chance: " << random(0.0, 1.0) << '\n';
// Colors
const Colors::Color sky = Colors::Color::fromHexString("#87CEEB").value_or(Colors::Blue);
const Colors::Color dusk = Colors::lerp(sky, Colors::Orange, 0.5f);
std::cout << "dusk: " << dusk << ", hue " << dusk.toHsv().h << '\n';
return 0;
}
Fixed-size matrix of Rows x Cols elements, stored in row-major order.
Definition Matrix.hpp:19
constexpr Vector3D< T > transformPoint(const Vector3D< T > &p) const
Transforms a point, translation included.
Definition Matrix.hpp:124
RGBA colors: hex and HSV conversions, blending, interpolation and named colors.
Definition Color.hpp:11
Math helpers: constants, interpolation, random numbers, 2D and 3D vectors and matrices.
Definition Constants.hpp:5
2D vector; arithmetic operators work component-wise, with a vector or a scalar.
Definition Vector.hpp:14
constexpr auto length() const noexcept
Definition Vector.hpp:69
3D vector; arithmetic operators work component-wise, with a vector or a scalar.
Definition Vector.hpp:135