# SceneKit-Convert a rotation vector into rotation matrix

I'm very new and I'm studying this ARKit code from RPasecky/CubesInSpace on github where he/she convert the point of view 's rotation vector into a rotation matrix

https://raw.githubusercontent.com/RPasecky/CubesInSpace/master/CubesInSpace/MainViewController.swift

func calculateCameraDirection(cameraNode: SCNVector4) -> SCNVector3 {
let x = -cameraNode.x
let y = -cameraNode.y
let z = -cameraNode.z
let w = cameraNode.w
let cameraRotationMatrix = GLKMatrix3Make(cos(w) + pow(x, 2) * (1 - cos(w)),
x * y * (1 - cos(w)) - z * sin(w),
x * z * (1 - cos(w)) + y*sin(w),

y*x*(1-cos(w)) + z*sin(w),
cos(w) + pow(y, 2) * (1 - cos(w)),
y*z*(1-cos(w)) - x*sin(w),

z*x*(1 - cos(w)) - y*sin(w),
z*y*(1 - cos(w)) + x*sin(w),
cos(w) + pow(z, 2) * ( 1 - cos(w)))


It was called from here

    let rotation = self.sceneView.pointOfView!.rotation //else { return (SCNVector3Zero) }
let direction = calculateCameraDirection(cameraNode: rotation)


I understand the rotation of pointOfView that is passed in has x, y, z as the coordinate of the axis and w is the rotation angle. But how do I arrive at the code in the function? Which concepts should I learn about here?

I read about homogeneous vector, find rotation matrix between 2 vectors, and transformation matrix but this doesn't look like it

Thanks,

• If you want to know how to derive the formulas above, it might be a better question for the Math StackExchange. There's nothing particularly game-specific about constructing a 3x3 rotation matrix from an axis vector and rotation angle. – DMGregory Sep 7 '17 at 23:29
• oh, so based on this meta.stackexchange.com/questions/85017/… I guess I need to create a brand new question? Is it OK to have the same question on 2 stackexchange? – Motoko Sep 7 '17 at 23:41
• Cross-posts are discouraged. I think you can delete your question here and then ask a new one. Though there's also a good chance it's already been asked and you can just search out the answer without needing to wait for replies at all. – DMGregory Sep 7 '17 at 23:43