public static void SetTransform(this GKAgent2D agent, SCNMatrix4 newTransform) { var quatf = new SCNQuaternion(newTransform.Column3.Xyz, newTransform.Column3.W); SCNVector3 axis; #if !__OSX__ float angle; quatf.ToAxisAngle(out axis, out angle); agent.Rotation = -(angle + ((float)Math.PI / 2f)); agent.Position = new Vector2(newTransform.M41, newTransform.M43); #else nfloat angle; quatf.ToAxisAngle(out axis, out angle); agent.Rotation = -((float)angle + ((float)Math.PI / 2f)); agent.Position = new Vector2((float)newTransform.M41, (float)newTransform.M43); #endif }
SCNVector4 GetDirectionFromPosition(SCNVector3 currentPosition) { SCNVector3 target = LocationAlongPath(TimeAlongPath - 0.05f); SCNMatrix4 lookAt = SCNMatrix4.LookAt(currentPosition, target, new SCNVector3(0f, 1f, 0f)); SCNQuaternion q = lookAt.ToQuaternion(); nfloat angle = 0; q.ToAxisAngle(out target, out angle); if (PlayerCharacter.PlayerWalkDirection == WalkDirection.Left) { angle -= (nfloat)Math.PI; } return(new SCNVector4(0f, 1f, 0f, angle)); }