Blender  V2.93
svm_vector_rotate.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2020 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 /* Vector Rotate */
20 
22  float *stack,
23  uint input_stack_offsets,
24  uint axis_stack_offsets,
25  uint result_stack_offset)
26 {
27  uint type, vector_stack_offset, rotation_stack_offset, center_stack_offset, axis_stack_offset,
28  angle_stack_offset, invert;
29 
31  input_stack_offsets, &type, &vector_stack_offset, &rotation_stack_offset, &invert);
33  axis_stack_offsets, &center_stack_offset, &axis_stack_offset, &angle_stack_offset);
34 
35  if (stack_valid(result_stack_offset)) {
36 
37  float3 vector = stack_load_float3(stack, vector_stack_offset);
38  float3 center = stack_load_float3(stack, center_stack_offset);
39  float3 result = make_float3(0.0f, 0.0f, 0.0f);
40 
42  float3 rotation = stack_load_float3(stack, rotation_stack_offset); // Default XYZ.
43  Transform rotationTransform = euler_to_transform(rotation);
44  if (invert) {
45  result = transform_direction_transposed(&rotationTransform, vector - center) + center;
46  }
47  else {
48  result = transform_direction(&rotationTransform, vector - center) + center;
49  }
50  }
51  else {
52  float3 axis;
53  switch (type) {
55  axis = make_float3(1.0f, 0.0f, 0.0f);
56  break;
58  axis = make_float3(0.0f, 1.0f, 0.0f);
59  break;
61  axis = make_float3(0.0f, 0.0f, 1.0f);
62  break;
63  default:
64  axis = normalize(stack_load_float3(stack, axis_stack_offset));
65  break;
66  }
67  float angle = stack_load_float(stack, angle_stack_offset);
68  angle = invert ? -angle : angle;
69  result = (len_squared(axis) != 0.0f) ?
71  vector;
72  }
73 
74  stack_store_float3(stack, result_stack_offset, result);
75  }
76 }
77 
unsigned int uint
Definition: BLI_sys_types.h:83
@ NODE_VECTOR_ROTATE_TYPE_AXIS_Z
@ NODE_VECTOR_ROTATE_TYPE_AXIS_X
@ NODE_VECTOR_ROTATE_TYPE_EULER_XYZ
@ NODE_VECTOR_ROTATE_TYPE_AXIS_Y
NSNotificationCenter * center
_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 type
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition: btVector3.h:356
CCL_NAMESPACE_BEGIN ccl_device_inline float3 stack_load_float3(float *stack, uint a)
ccl_device_inline float stack_load_float(float *stack, uint a)
ccl_device_forceinline void svm_unpack_node_uchar3(uint i, uint *x, uint *y, uint *z)
ccl_device_inline void stack_store_float3(float *stack, uint a, float3 f)
ccl_device_forceinline void svm_unpack_node_uchar4(uint i, uint *x, uint *y, uint *z, uint *w)
ccl_device_inline bool stack_valid(uint a)
#define ccl_device
#define CCL_NAMESPACE_END
#define make_float3(x, y, z)
ShaderData
std::vector< ElementType, Eigen::aligned_allocator< ElementType > > vector
Definition: vector.h:39
CCL_NAMESPACE_BEGIN ccl_device float invert(float color, float factor)
Definition: svm_invert.h:19
CCL_NAMESPACE_BEGIN ccl_device void svm_node_vector_rotate(ShaderData *sd, float *stack, uint input_stack_offsets, uint axis_stack_offsets, uint result_stack_offset)
ccl_device_inline float3 rotate_around_axis(float3 p, float3 axis, float angle)
Definition: util_math.h:563
ccl_device_inline float2 normalize(const float2 &a)
ccl_device_inline float len_squared(const float3 a)
ccl_device_inline Transform euler_to_transform(const float3 euler)
ccl_device_inline float3 transform_direction(const Transform *t, const float3 a)
ccl_device_inline float3 transform_direction_transposed(const Transform *t, const float3 a)