add print to ray

This commit is contained in:
h4570
2022-08-14 20:20:03 +02:00
parent 5c2ae9770e
commit 6e5b75e39b
2 changed files with 31 additions and 0 deletions
+25
View File
@@ -12,6 +12,8 @@
#include <tamtypes.h>
#include <math.h>
#include <algorithm>
#include <sstream>
#include <iomanip>
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