IPhone : Confused with scene kit angles

on Sunday, February 22, 2015

I am using scene kit to make a fps controller and I found this sample code online. I understand everything but the second assignment of the impulse vector. Could someone go over what is going on in the line



impulse = SCNVector3(
x: impulse.x * cos(angle) - impulse.z * sin(angle),
y: 0,
z: impulse.x * -sin(angle) - impulse.z * cos(angle)
)


Thanks



func renderer(aRenderer: SCNSceneRenderer, updateAtTime time: NSTimeInterval) {

//get walk gesture translation
var translation = walkGesture.translationInView(self.view)

//create impulse vector for hero
let angle = heroNode.presentationNode().rotation.w * heroNode.presentationNode().rotation.y
var impulse = SCNVector3(x: max(-1, min(1, Float(translation.x) / 50)), y: 0, z: max(-1, min(1, Float(-translation.y) / 50)))
impulse = SCNVector3(
x: impulse.x * cos(angle) - impulse.z * sin(angle),
y: 0,
z: impulse.x * -sin(angle) - impulse.z * cos(angle)
)
heroNode.physicsBody?.applyForce(impulse, impulse: true)
}

0 comments:

Post a Comment