2014-07-14 35 views
0

©有一个3d对象。GLKit对象不能正常旋转

我与这样的触摸旋转它:

-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 
UITouch *touch = [touches anyObject]; 
CGPoint location = [touch locationInView:self.view]; 
CGPoint lastLoc = [touch previousLocationInView:self.view]; 
CGPoint diff = CGPointMake(lastLoc.x - location.x, lastLoc.y - location.y); 

float rotX = -1 * GLKMathDegreesToRadians(diff.y/2.0); 
float rotY = GLKMathDegreesToRadians(diff.x/3.0); 


GLKVector3 yAxis = GLKMatrix4MultiplyAndProjectVector3(GLKMatrix4Invert(_rotMatrix, &isInvertible), GLKVector3Make(0, 0, 1)); 
_rotMatrix = GLKMatrix4Rotate(_rotMatrix, rotY, yAxis.x, yAxis.y, yAxis.z); 

GLKVector3 xAxis = GLKVector3Make(1, 0, 0); 
_rotMatrix = GLKMatrix4Rotate(_rotMatrix, rotX, xAxis.x, xAxis.y, xAxis.z); 

} 

和设置矩阵是这样的:

_modelViewMatrix = GLKMatrix4Identity; 

_modelViewMatrix = GLKMatrix4Translate(_modelViewMatrix, 0.0f, 0.0f, -60.0f); 
_modelViewMatrix = GLKMatrix4Translate(_modelViewMatrix, 0.0f, 5.5f, -4.0f); 
// i know i can to this by one code 

//çevirme işlemleri ilki klimanın kameraya doğru bakması için 
//ikincisi parmak hareketlerinden gelen transform matrisi 
// 90 derece döndermeyi kapatıyorum 
_modelViewMatrix = GLKMatrix4RotateX(_modelViewMatrix, GLKMathDegreesToRadians(90.0f)); 
_modelViewMatrix = GLKMatrix4Multiply(_modelViewMatrix, _rotMatrix); 

_modelViewMatrix = GLKMatrix4Translate(_modelViewMatrix, 0.0f, -5.5f, +4.0f); 

self.reflectionMapEffect.transform.modelviewMatrix = _modelViewMatrix; 

我正在翻译modelViewMatrix物体中心。旋转它。比翻译回来。比在z上翻译-65。但每次我都试图去做。它像在同一个矢量上一样旋转。我认为对象有它自己的中心。并与自己的中心和场景中心一起旋转。

如何用代码更改对象的中心或者如何正确旋转此对象?

回答

0

矩阵乘法的工作方式是考虑对象基向量。你可以把它想象成一个第一人称视角(从对象/模型来看)。如果你先移动物体(平移),然后旋转物体仍然处于相同的位置,但面对不同的旋转,这意味着它不会模拟轨道。如果您将操作更改为先旋转,然后移动它将模拟绕轨道(但也旋转)。例如,如果您将模型旋转到正确的位置,而不是向前翻译,则看起来好像会翻译成正确的。所以真正的轨道运动首先由一定角度旋转,然后由半径平移,然后以相同的负角旋转。再次尝试从模型的角度来看。

我希望这可以帮助你,因为你没有解释你到底需要完成什么。