|
@@ -4,6 +4,7 @@ import {
|
|
addNodeElement,
|
|
addNodeElement,
|
|
nodeProxy,
|
|
nodeProxy,
|
|
vec4,
|
|
vec4,
|
|
|
|
+ mat2,
|
|
mat4,
|
|
mat4,
|
|
} from '../shadernode/ShaderNode.js';
|
|
} from '../shadernode/ShaderNode.js';
|
|
import { cos, sin } from '../math/MathNode.js';
|
|
import { cos, sin } from '../math/MathNode.js';
|
|
@@ -12,23 +13,47 @@ class RotateNode extends TempNode {
|
|
|
|
|
|
constructor( positionNode, rotationNode ) {
|
|
constructor( positionNode, rotationNode ) {
|
|
|
|
|
|
- super( 'vec3' );
|
|
|
|
|
|
+ super();
|
|
|
|
|
|
this.positionNode = positionNode;
|
|
this.positionNode = positionNode;
|
|
this.rotationNode = rotationNode;
|
|
this.rotationNode = rotationNode;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- setup() {
|
|
|
|
|
|
+ getNodeType( builder ) {
|
|
|
|
+
|
|
|
|
+ return this.positionNode.getNodeType( builder );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ setup( builder ) {
|
|
|
|
|
|
const { rotationNode, positionNode } = this;
|
|
const { rotationNode, positionNode } = this;
|
|
|
|
|
|
- const rotation = rotationNode;
|
|
|
|
- const rotationXMatrix = mat4( vec4( 1.0, 0.0, 0.0, 0.0 ), vec4( 0.0, cos( rotation.x ), sin( rotation.x ).negate(), 0.0 ), vec4( 0.0, sin( rotation.x ), cos( rotation.x ), 0.0 ), vec4( 0.0, 0.0, 0.0, 1.0 ) );
|
|
|
|
- const rotationYMatrix = mat4( vec4( cos( rotation.y ), 0.0, sin( rotation.y ), 0.0 ), vec4( 0.0, 1.0, 0.0, 0.0 ), vec4( sin( rotation.y ).negate(), 0.0, cos( rotation.y ), 0.0 ), vec4( 0.0, 0.0, 0.0, 1.0 ) );
|
|
|
|
- const rotationZMatrix = mat4( vec4( cos( rotation.z ), sin( rotation.z ).negate(), 0.0, 0.0 ), vec4( sin( rotation.z ), cos( rotation.z ), 0.0, 0.0 ), vec4( 0.0, 0.0, 1.0, 0.0 ), vec4( 0.0, 0.0, 0.0, 1.0 ) );
|
|
|
|
|
|
+ const nodeType = this.getNodeType( builder );
|
|
|
|
+
|
|
|
|
+ if ( nodeType === 'vec2' ) {
|
|
|
|
+
|
|
|
|
+ const cosAngle = rotationNode.cos();
|
|
|
|
+ const sinAngle = rotationNode.sin();
|
|
|
|
+
|
|
|
|
+ const rotationMatrix = mat2(
|
|
|
|
+ cosAngle, sinAngle,
|
|
|
|
+ sinAngle.negate(), cosAngle
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ return rotationMatrix.mul( positionNode );
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+
|
|
|
|
+ const rotation = rotationNode;
|
|
|
|
+ const rotationXMatrix = mat4( vec4( 1.0, 0.0, 0.0, 0.0 ), vec4( 0.0, cos( rotation.x ), sin( rotation.x ).negate(), 0.0 ), vec4( 0.0, sin( rotation.x ), cos( rotation.x ), 0.0 ), vec4( 0.0, 0.0, 0.0, 1.0 ) );
|
|
|
|
+ const rotationYMatrix = mat4( vec4( cos( rotation.y ), 0.0, sin( rotation.y ), 0.0 ), vec4( 0.0, 1.0, 0.0, 0.0 ), vec4( sin( rotation.y ).negate(), 0.0, cos( rotation.y ), 0.0 ), vec4( 0.0, 0.0, 0.0, 1.0 ) );
|
|
|
|
+ const rotationZMatrix = mat4( vec4( cos( rotation.z ), sin( rotation.z ).negate(), 0.0, 0.0 ), vec4( sin( rotation.z ), cos( rotation.z ), 0.0, 0.0 ), vec4( 0.0, 0.0, 1.0, 0.0 ), vec4( 0.0, 0.0, 0.0, 1.0 ) );
|
|
|
|
+
|
|
|
|
+ return rotationXMatrix.mul( rotationYMatrix ).mul( rotationZMatrix ).mul( vec4( positionNode, 1.0 ) ).xyz;
|
|
|
|
|
|
- return rotationXMatrix.mul( rotationYMatrix ).mul( rotationZMatrix ).mul( vec4( positionNode, 1.0 ) ).xyz;
|
|
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|