Blender  V2.93
sky_float3.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 #ifndef __SKY_FLOAT3_H__
18 #define __SKY_FLOAT3_H__
19 
20 // minimal float3 + util_math.h implementation for nishita sky model
21 
22 #include <math.h>
23 
24 #ifndef M_PI_F
25 # define M_PI_F (3.1415926535897932f) /* pi */
26 #endif
27 #ifndef M_PI_2_F
28 # define M_PI_2_F (1.5707963267948966f) /* pi/2 */
29 #endif
30 #ifndef M_2PI_F
31 # define M_2PI_F (6.2831853071795864f) /* 2*pi */
32 #endif
33 
34 struct float3 {
35  float x, y, z;
36 
37  float3() = default;
38 
39  float3(const float *ptr) : x{ptr[0]}, y{ptr[1]}, z{ptr[2]}
40  {
41  }
42 
43  float3(const float (*ptr)[3]) : float3((const float *)ptr)
44  {
45  }
46 
47  explicit float3(float value) : x(value), y(value), z(value)
48  {
49  }
50 
51  explicit float3(int value) : x(value), y(value), z(value)
52  {
53  }
54 
55  float3(float x, float y, float z) : x{x}, y{y}, z{z}
56  {
57  }
58 
59  operator const float *() const
60  {
61  return &x;
62  }
63 
64  operator float *()
65  {
66  return &x;
67  }
68 
69  friend float3 operator*(const float3 &a, float b)
70  {
71  return {a.x * b, a.y * b, a.z * b};
72  }
73 
74  friend float3 operator*(float b, const float3 &a)
75  {
76  return {a.x * b, a.y * b, a.z * b};
77  }
78 
79  friend float3 operator-(const float3 &a, const float3 &b)
80  {
81  return {a.x - b.x, a.y - b.y, a.z - b.z};
82  }
83 
84  friend float3 operator-(const float3 &a)
85  {
86  return {-a.x, -a.y, -a.z};
87  }
88 
89  float length_squared() const
90  {
91  return x * x + y * y + z * z;
92  }
93 
94  float length() const
95  {
96  return sqrt(length_squared());
97  }
98 
99  static float distance(const float3 &a, const float3 &b)
100  {
101  return (a - b).length();
102  }
103 
104  friend float3 operator+(const float3 &a, const float3 &b)
105  {
106  return {a.x + b.x, a.y + b.y, a.z + b.z};
107  }
108 
109  void operator+=(const float3 &b)
110  {
111  this->x += b.x;
112  this->y += b.y;
113  this->z += b.z;
114  }
115 
116  friend float3 operator*(const float3 &a, const float3 &b)
117  {
118  return {a.x * b.x, a.y * b.y, a.z * b.z};
119  }
120 };
121 
122 inline float sqr(float a)
123 {
124  return a * a;
125 }
126 
127 inline float3 make_float3(float x, float y, float z)
128 {
129  return float3(x, y, z);
130 }
131 
132 inline float dot(const float3 &a, const float3 &b)
133 {
134  return a.x * b.x + a.y * b.y + a.z * b.z;
135 }
136 
137 inline float distance(const float3 &a, const float3 &b)
138 {
139  return float3::distance(a, b);
140 }
141 
142 inline float len_squared(float3 f)
143 {
144  return f.length_squared();
145 }
146 
147 inline float len(float3 f)
148 {
149  return f.length();
150 }
151 
152 inline float reduce_add(float3 f)
153 {
154  return f.x + f.y + f.z;
155 }
156 
157 #endif /* __SKY_FLOAT3_H__ */
typedef float(TangentPoint)[2]
sqrt(x)+1/max(0
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble z
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
static unsigned a[3]
Definition: RandGen.cpp:92
float len_squared(float3 f)
Definition: sky_float3.h:142
float3 make_float3(float x, float y, float z)
Definition: sky_float3.h:127
float len(float3 f)
Definition: sky_float3.h:147
float dot(const float3 &a, const float3 &b)
Definition: sky_float3.h:132
float reduce_add(float3 f)
Definition: sky_float3.h:152
float distance(const float3 &a, const float3 &b)
Definition: sky_float3.h:137
float sqr(float a)
Definition: sky_float3.h:122
friend float3 operator*(const float3 &a, float b)
Definition: sky_float3.h:69
friend float3 operator-(const float3 &a, const float3 &b)
Definition: sky_float3.h:79
float3(const float *ptr)
Definition: sky_float3.h:39
float3(float x, float y, float z)
Definition: sky_float3.h:55
float3(int value)
Definition: sky_float3.h:51
void operator+=(const float3 &b)
Definition: sky_float3.h:109
float length_squared() const
Definition: sky_float3.h:89
friend float3 operator+(const float3 &a, const float3 &b)
Definition: sky_float3.h:104
float3(const float(*ptr)[3])
Definition: sky_float3.h:43
float length() const
Definition: sky_float3.h:94
float z
Definition: sky_float3.h:35
float3()=default
float y
Definition: sky_float3.h:35
float3(float value)
Definition: sky_float3.h:47
static float distance(const float3 &a, const float3 &b)
Definition: sky_float3.h:99
friend float3 operator*(const float3 &a, const float3 &b)
Definition: sky_float3.h:116
float x
Definition: sky_float3.h:35
friend float3 operator-(const float3 &a)
Definition: sky_float3.h:84
friend float3 operator*(float b, const float3 &a)
Definition: sky_float3.h:74
PointerRNA * ptr
Definition: wm_files.c:3157