stackgl / shader-school

:mortar_board: A workshopper for GLSL shaders and graphics programming
Other
4.28k stars 252 forks source link

Exercise 16 Geom-5 (Reflections) Wrong Answer (contains spoiler) #83

Closed physcopanda closed 9 years ago

physcopanda commented 10 years ago

Exercises 15 and 16 have the same answer! I think the correct answer is something like this:-

It doesn't seem to match the correct answer on screen, can anyone validate this as a correct rotation matrix?

highp mat4 rotation(highp vec3 n, highp float theta) {

  //TODO: Using Rodrigues' formula, find a matrix which performs a rotation about the axis n by theta radians

  return mat4(n.x*n.x*(1.0-cos(theta))+cos(theta),      n.y*n.x*(1.0-cos(theta))-n.z*sin(theta),    n.z*n.x*(1.0-cos(theta))+n.y*sin(theta),    0,
              n.x*n.y*(1.0-cos(theta))+n.z*sin(theta),n.y*n.y*(1.0-cos(theta))+cos(theta),          n.z*n.y*(1.0-cos(theta))-n.x*sin(theta),    0, 
                            n.x*n.z*(1.0-cos(theta))-n.y*sin(theta),n.y*n.z*(1.0-cos(theta))+n.x*sin(theta),    n.z*n.z*(1.0-cos(theta))+cos(theta),            0,
              0,                                                                        0,                                                                          0,                                                                          1.0);
}

#pragma glslify: export(rotation)
nnnnathann commented 9 years ago

I noticed this as well, I think your matrix is correct with the exception that it should be in column major:

highp mat4 rotation(highp vec3 n, highp float theta) {

  //TODO: Using Rodrigues' formula, find a matrix which performs a rotation about the axis n by theta radians
  return mat4(n.x*n.x*(1.0-cos(theta))+cos(theta), n.x*n.y*(1.0-cos(theta))+n.z*sin(theta), n.x*n.z*(1.0-cos(theta))-n.y*sin(theta), 0,
              n.y*n.x*(1.0-cos(theta))-n.z*sin(theta),n.y*n.y*(1.0-cos(theta))+cos(theta), n.y*n.z*(1.0-cos(theta))+n.x*sin(theta), 0, 
              n.z*n.x*(1.0-cos(theta))+n.y*sin(theta),n.z*n.y*(1.0-cos(theta))-n.x*sin(theta), n.z*n.z*(1.0-cos(theta))+cos(theta), 0,
              0, 0, 0, 1.0);
}

#pragma glslify: export(rotation)
mikolalysenko commented 9 years ago

Fixed