請幫助我與射線採摘OpenGL ES 2.0的雷採摘,遠點
float aspect = fabsf(self.view.bounds.size.width/self.view.bounds.size.height);
GLKMatrix4 projectionMatrix = GLKMatrix4MakePerspective(GLKMathDegreesToRadians(35.0f), aspect, 0.1f, 1000.0f);
GLKMatrix4 modelViewMatrix = _mainmodelViewMatrix;
// some transformations
_mainmodelViewMatrix = modelViewMatrix;
_modelViewProjectionMatrix = GLKMatrix4Multiply(projectionMatrix, modelViewMatrix);
_normalMatrix = GLKMatrix3InvertAndTranspose(GLKMatrix4GetMatrix3(modelViewMatrix), NULL);
_modelViewProjectionMatrix和_normalMatrix把着色器
glUniformMatrix4fv(uniforms[UNIFORM_MODELVIEWPROJECTION_MATRIX], 1, 0, _modelViewProjectionMatrix.m);
glUniformMatrix3fv(uniforms[UNIFORM_NORMAL_MATRIX], 1, 0, _normalMatrix.m);
,並在觸摸結束
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 - 2 * position.y/self.view.bounds.size.height,
-1,
1);
GLKMatrix4 inversedMatrix = GLKMatrix4Invert(_modelViewProjectionMatrix, nil);
GLKVector4 near_point = GLKMatrix4MultiplyVector4(inversedMatrix, normalisedVector);
如何我可以得到遠點?我的近點是否正確?
謝謝!
我不知道,這是真的 – SAKrisT 2012-04-06 16:25:25
你說得對!但是,需要一個更多的操作和結果! – SAKrisT 2012-04-10 14:50:31