Blender V5.3
vector_rotate.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
8#include "kernel/svm/util.h"
9
11
12/* Vector Rotate */
13
16{
17 if (stack_valid(node.result_offset)) {
18
19 const float3 vector = stack_load(stack, node.vector);
20 const float3 center = stack_load(stack, node.center);
21 float3 result = make_float3(0.0f, 0.0f, 0.0f);
22
23 if (node.rotate_type == NODE_VECTOR_ROTATE_TYPE_EULER_XYZ) {
24 const float3 rotation = stack_load(stack, node.rotation); // Default XYZ.
25 const Transform rotationTransform = euler_to_transform(rotation);
26 if (node.invert) {
27 result = transform_direction_transposed(&rotationTransform, vector - center) + center;
28 }
29 else {
30 result = transform_direction(&rotationTransform, vector - center) + center;
31 }
32 }
33 else {
34 float3 axis;
35 float axis_length;
36 switch (node.rotate_type) {
38 axis = make_float3(1.0f, 0.0f, 0.0f);
39 axis_length = 1.0f;
40 break;
42 axis = make_float3(0.0f, 1.0f, 0.0f);
43 axis_length = 1.0f;
44 break;
46 axis = make_float3(0.0f, 0.0f, 1.0f);
47 axis_length = 1.0f;
48 break;
49 default:
50 axis = stack_load(stack, node.axis);
51 axis_length = len(axis);
52 break;
53 }
54 float angle = stack_load(stack, node.angle);
55 angle = node.invert ? -angle : angle;
56 result = (axis_length != 0.0f) ?
57 rotate_around_axis(vector - center, axis / axis_length, angle) + center :
58 vector;
59 }
60
61 stack_store_float3(stack, node.result_offset, result);
62 }
63}
64
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition btVector3.h:356
ccl_device_inline void stack_store_float3(ccl_private float *stack, const uint a, const float3 f)
ccl_device_inline bool stack_valid(const uint a)
ccl_device_inline T stack_load(const ccl_private float *stack, const uint a)
#define ccl_restrict
#define ccl_private
#define ccl_global
#define ccl_device_noinline
#define CCL_NAMESPACE_END
ccl_device_forceinline float3 make_float3(const float x, const float y, const float z)
float3 rotate_around_axis(float3 p, float3 axis, float angle)
float3 transform_direction(float3x3 mat, float3 direction)
@ NODE_VECTOR_ROTATE_TYPE_AXIS_Z
@ NODE_VECTOR_ROTATE_TYPE_AXIS_X
@ NODE_VECTOR_ROTATE_TYPE_EULER_XYZ
@ NODE_VECTOR_ROTATE_TYPE_AXIS_Y
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
ccl_device_inline T transform_direction_transposed(const ccl_private Transform *t, const T a)
Definition transform.h:176
ccl_device_inline Transform euler_to_transform(const float3 euler)
Definition transform.h:227
CCL_NAMESPACE_BEGIN ccl_device_noinline void svm_node_vector_rotate(ccl_private float *ccl_restrict stack, const ccl_global SVMNodeVectorRotate &ccl_restrict node)