Solution for picking
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
GLKVector4 normalisedVector = GLKVector4Make((2 * position.x / self.view.bounds.size.width - 1),
(2 * (self.view.bounds.size.height-position.y) / self.view.bounds.size.height - 1), -1, 1); GLKMatrix4 inversedMatrix = GLKMatrix4Invert(_modelViewProjectionMatrix, nil); GLKVector4 near_point = GLKMatrix4MultiplyVector4(inversedMatrix, normalisedVector); near_point.v[3] = 1.0/near_point.v[3]; near_point = GLKVector4Make(near_point.v[0]*near_point.v[3], near_point.v[1]*near_point.v[3], near_point.v[2]*near_point.v[3], 1); normalisedVector.z = 1.0; GLKVector4 far_point = GLKMatrix4MultiplyVector4(inversedMatrix, normalisedVector); far_point.v[3] = 1.0/far_point.v[3]; far_point = GLKVector4Make(far_point.v[0]*far_point.v[3], far_point.v[1]*far_point.v[3], far_point.v[2]*far_point.v[3], 1); |
On