Blender V4.3
sky_float3.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2020-2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#ifndef __SKY_FLOAT3_H__
10#define __SKY_FLOAT3_H__
11
12// minimal float3 + util_math.h implementation for nishita sky model
13
14#include <math.h>
15
16#ifndef M_PI_F
17# define M_PI_F (3.1415926535897932f) /* pi */
18#endif
19#ifndef M_PI_2_F
20# define M_PI_2_F (1.5707963267948966f) /* pi/2 */
21#endif
22#ifndef M_2PI_F
23# define M_2PI_F (6.2831853071795864f) /* 2*pi */
24#endif
25
26struct float3 {
27 float x, y, z;
28
29 float3() = default;
30
31 float3(const float *ptr) : x{ptr[0]}, y{ptr[1]}, z{ptr[2]} {}
32
33 float3(const float (*ptr)[3]) : float3((const float *)ptr) {}
34
35 explicit float3(float value) : x(value), y(value), z(value) {}
36
37 explicit float3(int value) : x(value), y(value), z(value) {}
38
39 float3(float x, float y, float z) : x{x}, y{y}, z{z} {}
40
41 operator const float *() const
42 {
43 return &x;
44 }
45
46 operator float *()
47 {
48 return &x;
49 }
50
51 friend float3 operator*(const float3 &a, float b)
52 {
53 return {a.x * b, a.y * b, a.z * b};
54 }
55
56 friend float3 operator*(float b, const float3 &a)
57 {
58 return {a.x * b, a.y * b, a.z * b};
59 }
60
61 friend float3 operator-(const float3 &a, const float3 &b)
62 {
63 return {a.x - b.x, a.y - b.y, a.z - b.z};
64 }
65
66 friend float3 operator-(const float3 &a)
67 {
68 return {-a.x, -a.y, -a.z};
69 }
70
71 float length_squared() const
72 {
73 return x * x + y * y + z * z;
74 }
75
76 float length() const
77 {
78 return sqrt(length_squared());
79 }
80
81 static float distance(const float3 &a, const float3 &b)
82 {
83 return (a - b).length();
84 }
85
86 friend float3 operator+(const float3 &a, const float3 &b)
87 {
88 return {a.x + b.x, a.y + b.y, a.z + b.z};
89 }
90
91 void operator+=(const float3 &b)
92 {
93 this->x += b.x;
94 this->y += b.y;
95 this->z += b.z;
96 }
97
98 friend float3 operator*(const float3 &a, const float3 &b)
99 {
100 return {a.x * b.x, a.y * b.y, a.z * b.z};
101 }
102};
103
104inline float sqr(float a)
105{
106 return a * a;
107}
108
109inline float3 make_float3(float x, float y, float z)
110{
111 return float3(x, y, z);
112}
113
114inline float dot(const float3 &a, const float3 &b)
115{
116 return a.x * b.x + a.y * b.y + a.z * b.z;
117}
118
119inline float distance(const float3 &a, const float3 &b)
120{
121 return float3::distance(a, b);
122}
123
124inline float len_squared(float3 f)
125{
126 return f.length_squared();
127}
128
129inline float len(float3 f)
130{
131 return f.length();
132}
133
134inline float reduce_add(float3 f)
135{
136 return f.x + f.y + f.z;
137}
138
139#endif /* __SKY_FLOAT3_H__ */
sqrt(x)+1/max(0
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
Definition btQuadWord.h:117
local_group_size(16, 16) .push_constant(Type b
int len
draw_view in_light_buf[] float
float len_squared(float3 f)
Definition sky_float3.h:124
float3 make_float3(float x, float y, float z)
Definition sky_float3.h:109
float dot(const float3 &a, const float3 &b)
Definition sky_float3.h:114
float reduce_add(float3 f)
Definition sky_float3.h:134
float distance(const float3 &a, const float3 &b)
Definition sky_float3.h:119
float sqr(float a)
Definition sky_float3.h:104
friend float3 operator*(const float3 &a, float b)
Definition sky_float3.h:51
friend float3 operator-(const float3 &a, const float3 &b)
Definition sky_float3.h:61
float3(const float *ptr)
Definition sky_float3.h:31
float3(float x, float y, float z)
Definition sky_float3.h:39
float3(int value)
Definition sky_float3.h:37
void operator+=(const float3 &b)
Definition sky_float3.h:91
float length_squared() const
Definition sky_float3.h:71
friend float3 operator+(const float3 &a, const float3 &b)
Definition sky_float3.h:86
float3(const float(*ptr)[3])
Definition sky_float3.h:33
float length() const
Definition sky_float3.h:76
float z
Definition sky_float3.h:27
float3()=default
float y
Definition sky_float3.h:27
float3(float value)
Definition sky_float3.h:35
static float distance(const float3 &a, const float3 &b)
Definition sky_float3.h:81
friend float3 operator*(const float3 &a, const float3 &b)
Definition sky_float3.h:98
float x
Definition sky_float3.h:27
friend float3 operator-(const float3 &a)
Definition sky_float3.h:66
friend float3 operator*(float b, const float3 &a)
Definition sky_float3.h:56
PointerRNA * ptr
Definition wm_files.cc:4126