From 6e5b75e39bff9321220d78af3cafad7bd8cc00c4 Mon Sep 17 00:00:00 2001 From: h4570 Date: Sun, 14 Aug 2022 20:20:03 +0200 Subject: [PATCH] add print to ray --- engine/inc/physics/ray.hpp | 6 ++++++ engine/src/physics/ray.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/engine/inc/physics/ray.hpp b/engine/inc/physics/ray.hpp index c58bf13..85eac67 100644 --- a/engine/inc/physics/ray.hpp +++ b/engine/inc/physics/ray.hpp @@ -9,6 +9,7 @@ */ #include "math/vec4.hpp" +#include #pragma once @@ -52,6 +53,11 @@ class Ray { /** Returns inverse direction */ Vec4 invDir() const; + + void print() const; + void print(const char* name) const; + void print(const std::string& name) const { print(name.c_str()); } + std::string getPrint(const char* name = nullptr) const; }; } // namespace Tyra \ No newline at end of file diff --git a/engine/src/physics/ray.cpp b/engine/src/physics/ray.cpp index 45eb9a3..d91d9f2 100644 --- a/engine/src/physics/ray.cpp +++ b/engine/src/physics/ray.cpp @@ -12,6 +12,8 @@ #include #include #include +#include +#include namespace Tyra { @@ -74,4 +76,27 @@ Vec4 Ray::invDir() const { 1 / this->direction.z, 1); } +void Ray::print() const { + auto text = getPrint(nullptr); + printf("%s\n", text.c_str()); +} + +void Ray::print(const char* name) const { + auto text = getPrint(name); + printf("%s\n", text.c_str()); +} + +std::string Ray::getPrint(const char* name) const { + std::stringstream res; + if (name) { + res << name << "("; + } else { + res << "Ray("; + } + res << std::fixed << std::setprecision(4); + res << origin.getPrint("origin") << ", " << direction.getPrint("direction") + << ")"; + return res.str(); +} + } // Namespace Tyra \ No newline at end of file