Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const rotation = Quat.fromAxisAngle(new Vec3([0, 1, 0]), t / 10000)
- function fromAxisAngle(axis: Vec3, angle: number, dest = new Quat()): Quat {
- angle *= 0.5
- const sin = Math.sin(angle)
- dest.x = axis.x * sin
- dest.y = axis.y * sin
- dest.z = axis.z * sin
- dest.w = Math.cos(angle)
- return dest
- }
- toMat4(dest = new Mat4()): Mat4 {
- const { x, y, z, w } = this
- const x2 = x + x
- const y2 = y + y
- const z2 = z + z
- const xx = x * x2
- const xy = x * y2
- const xz = x * z2
- const yy = y * y2
- const yz = y * z2
- const zz = z * z2
- const wx = w * x2
- const wy = w * y2
- const wz = w * z2
- dest.init([
- 1 - (yy + zz), xy - wz, xz + wy, 0,
- xy + wz, 1 - (xx + zz), yz - wx, 0,
- xz - wy, yz + wx, 1 - (xx + yy), 0,
- 0, 0, 0, 1,
- ])
- return dest
- }
- precision mediump float;
- attribute vec3 aVertexPosition;
- attribute vec2 aVertexUV;
- uniform mat4 uModelMatrix;
- uniform mat4 uViewMatrix;
- uniform mat4 uProjectionMatrix;
- varying vec2 vUV;
- void main(void) {
- vUV = aVertexUV;
- gl_Position = uProjectionMatrix * uViewMatrix * uModelMatrix * vec4(aVertexPosition.xyz, 1.0);
- }
- precision mediump float;
- attribute vec3 aVertexPosition;
- attribute vec2 aVertexUV;
- struct Transform {
- float scale;
- vec3 translation;
- vec4 rotation;
- };
- uniform Transform uModel;
- uniform Transform uView;
- uniform mat4 uProjection;
- varying vec2 vUV;
- vec3 rotateVector(vec4 quat, vec3 vec) {
- return vec + 2.0 * cross(cross(vec, quat.xyz) + quat.w * vec, quat.xyz);
- }
- void main(void) {
- vUV = aVertexUV;
- vec3 world = rotateVector(uModel.rotation, aVertexPosition * uModel.scale) + uModel.translation;
- vec3 view = rotateVector(uView.rotation, world * uView.scale) + uView.translation;
- gl_Position = uProjection * vec4(view, 1.0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement