This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // This implementation does not support shear transform. | |
| // Not-uniform scale is supported. | |
| // | |
| // If you need to support shear then 'true' matrix inversion algorithm | |
| // shoudl be used, for example, gaussian elimination will work. | |
| // | |
| Matrix3x4 get_inverse_transform(const Matrix3x4& m) | |
| { | |
| Vector3 scale = get_scale_from_transform(m); | |
| Vector3 inv_scale = Vector3(1) / scale; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| constexpr bool perform_expensive_numerical_analysis_to_prevent_intersection_behind_ray_origin = true; // could noticeable slowdown algorithm (like 2x) | |
| // | |
| // Sven Woop, Carsten Benthin, and Ingo Wald, Watertight Ray/Triangle Intersection, | |
| // Journal of Computer Graphics Techniques (JCGT), vol. 2, no. 1, 65-82, 2013 | |
| // http://jcgt.org/published/0002/01/05/ | |
| // | |
| float intersect_triangle_watertight(const Ray& ray, const Vector3& p0, const Vector3& p1, const Vector3& p2, Vector3* barycentrics) | |
| { | |
| const int kz = ray.direction.abs().max_dimension(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #pragma optimize("", off) | |
| void dummy_modify_variable(void* p) {} | |
| void dummy_use_variable(const void *p) {} | |
| #pragma optimize("", on) | |
| template <typename T> | |
| void make_unpredictable_for_compiler(T& var) { | |
| dummy_modify_variable(&var); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <cstdio> | |
| #include <chrono> | |
| struct Timestamp { | |
| Timestamp() : t(std::chrono::steady_clock::now()) {} | |
| std::chrono::time_point<std::chrono::steady_clock> t; | |
| }; | |
| double elapsed_milliseconds(Timestamp t) { | |
| auto duration = std::chrono::steady_clock::now() - t.t; | |
| auto nanoseconds = std::chrono::duration_cast<std::chrono::nanoseconds>(duration).count(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <cstdio> | |
| #include <cstring> | |
| #include <cassert> | |
| int main(int argc, char** argv) { | |
| if (argc < 2) return -1; | |
| FILE* f = fopen(argv[1], "r+b"); | |
| if (!f) return -2; | |
| fseek(f, 0x33, SEEK_SET); | |
| int vertex_count = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct Text_File_Lines { | |
| std::string text; | |
| std::vector<size_t> line_start_positions; // the last element is a position at the end of the file | |
| }; | |
| struct Text_File_Parser { | |
| private: | |
| size_t pos = 0; | |
| int line = -1; | |
| Text_File_Lines* text_file = nullptr; |