Blender V5.3
types_float3x3.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2026 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
11
12#include "util/math_float3.h"
13#include "util/types_base.h"
14#include "util/types_float3.h"
15#include "util/types_float4.h"
17
19
20/* NOTE: Elements might be padded to 16 bytes. */
21struct float3x3 {
22#if !defined(__KERNEL_GPU__)
23 __forceinline const float3 &operator[](int i) const
24 {
25 util_assert(i >= 0);
26 util_assert(i < 3);
27 return *(&x + i);
28 }
30 {
31 util_assert(i >= 0);
32 util_assert(i < 3);
33 return *(&x + i);
34 }
35#endif
36
40};
41
42/* Construct new 3x3 matrix from the given coordinate system (rows of the matrix). */
44{
45 return {x, y, z};
46}
47
52
54{
55 return make_float3x3(
56 make_float3(1.0f, 0.0f, 0.0f), make_float3(0.0f, 1.0f, 0.0f), make_float3(0.0f, 0.0f, 1.0f));
57}
58
59/* Packed float3x3.
60 * Potentially smaller than float3 for storage, with no requirement for alignment.
61 *
62 * For math operations this must be converted to float3x3, so that on the CPU SIMD instructions
63 * can be used. */
65 packed_float3x3() = default;
66
68
70 {
71 return make_float3x3(x, y, z);
72 }
73
75 {
76 x = a.x;
77 y = a.y;
78 z = a.z;
79 return *this;
80 }
81
85};
86static_assert(sizeof(packed_float3x3) == 36, "packed_float3x3 expected to be exactly 36 bytes");
87
88#if defined __METAL_PRINTF__
89# define print_float3x3(label, a) \
90 metal::os_log_default.log_debug(label ":\n%.8f %.8f %.8f\n%.8f %.8f %.8f\n%.8f %.8f %.8f", \
91 (a).x.x, \
92 (a).x.y, \
93 (a).x.z, \
94 (a).y.x, \
95 (a).y.y, \
96 (a).y.z, \
97 (a).z.x, \
98 (a).z.y, \
99 (a).z.z)
100#else
101ccl_device_inline void print_float3x3(const ccl_private char *label, const float3x3 a)
102{
103# ifdef __KERNEL_PRINTF__
104 printf("%s:\n%.8f %.8f %.8f\n%.8f %.8f %.8f\n%.8f %.8f %.8f\n",
105 label,
106 (double)a.x.x,
107 (double)a.x.y,
108 (double)a.x.z,
109 (double)a.y.x,
110 (double)a.y.y,
111 (double)a.y.z,
112 (double)a.z.x,
113 (double)a.z.y,
114 (double)a.z.z);
115# else
116 (void)label;
117 (void)a;
118# endif
119}
120#endif
121
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
Definition btQuadWord.h:117
#define printf
#define util_assert(statement)
#define ccl_private
#define ccl_device_inline
#define ccl_device_inline_method
#define __forceinline
#define CCL_NAMESPACE_END
ccl_device_forceinline float3 make_float3(const float x, const float y, const float z)
CCL_NAMESPACE_BEGIN ccl_device_inline float3 zero_float3()
Definition math_float3.h:17
float z
Definition sky_math.h:136
float y
Definition sky_math.h:136
float x
Definition sky_math.h:136
__forceinline float3 & operator[](int i)
__forceinline const float3 & operator[](int i) const
packed_float3 z
ccl_device_inline_method packed_float3x3 operator=(const float3x3 a)
packed_float3 x
packed_float3 y
ccl_device_inline_method packed_float3x3(const float3x3 m)
packed_float3x3()=default
ccl_device_inline void print_float3x3(const ccl_private char *label, const float3x3 a)
ccl_device_inline float3x3 identity_float3x3()
ccl_device_inline float3x3 zero_float3x3()
ccl_device_inline float3x3 make_float3x3(const float3 x, const float3 y, const float3 z)