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