-
Notifications
You must be signed in to change notification settings - Fork 0
/
utility.hpp
68 lines (52 loc) · 1.82 KB
/
utility.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// Created by Mehmet Fatih BAKIR on 08/03/2017.
//
#pragma once
#include <glm/vec3.hpp>
#include <iosfwd>
#include <boost/variant/static_visitor.hpp>
#include <array>
namespace glm
{
std::ostream& operator<<(std::ostream& os, const vec3& v);
}
template <typename ReturnType, typename... Lambdas>
struct lambda_visitor;
template <typename ReturnType, typename Lambda1, typename... Lambdas>
struct lambda_visitor< ReturnType, Lambda1 , Lambdas...>
: public lambda_visitor<ReturnType, Lambdas...>, public Lambda1 {
using Lambda1::operator();
using lambda_visitor< ReturnType , Lambdas...>::operator();
lambda_visitor(Lambda1 l1, Lambdas... lambdas)
: Lambda1(l1), lambda_visitor< ReturnType , Lambdas...> (lambdas...)
{}
};
template <typename ReturnType, typename Lambda1>
struct lambda_visitor<ReturnType, Lambda1>
: public boost::static_visitor<ReturnType>, public Lambda1 {
using Lambda1::operator();
lambda_visitor(Lambda1 l1)
: boost::static_visitor<ReturnType>(), Lambda1(l1)
{}
};
template <typename ReturnType>
struct lambda_visitor<ReturnType>
: public boost::static_visitor<ReturnType> {
lambda_visitor() : boost::static_visitor<ReturnType>() {}
};
template <typename ReturnType, typename... Lambdas>
lambda_visitor<ReturnType, Lambdas...> make_lambda_visitor(Lambdas... lambdas) {
return { lambdas... };
}
namespace rtr
{
template <class T>
auto lerp(const T& a, const T& b, float t)
{
return (1 - t) * a + t * b;
}
glm::vec3 random_point(const glm::vec3& around, const std::array<glm::vec3, 3>& a, const std::array<float, 3>& ranges);
glm::vec3 get_normal(const glm::vec3& dir);
glm::vec3 sample_hemisphere(int ms_id, int max_ms);
glm::vec3 sample_hemisphere(const glm::vec3& towards,int ms_id, int max_ms);
}