2012-12-05 55 views
-1

我旋轉3D模型與此代碼的觸摸事件對進口3D模型:關於在NinevehGL框架

_mesh = [[NGLMesh alloc] initWithFile:@"01.obj" settings:settings delegate:self]; 

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ 

    [super touchesMoved:touches withEvent:event]; 

    UITouch *touch; 
    CGPoint pointA,pointB; 

    if ([touches count]== 1) { 

     touch = [[touches allObjects]objectAtIndex:0]; 
     pointA = [touch locationInView:self.view]; 
     pointB = [touch previousLocationInView:self.view]; 
     //  _mesh.rotateY -= (pointA.x - pointB.x) * 0.5f; 
     //  _mesh.rotateX -= (pointA.y - pointB.y) * 0.5f; 

     _mesh.rotateY += (pointA.x - pointB.x) * 0.5f; 
    _mesh.rotateX += (pointA.y - pointB.y) * 0.5f; 
    } 
} 

代碼旋轉像它應該,但它旋轉無論身在何處的觀點我點擊。我希望它只在接觸導入模型時旋轉。我將如何做到這一點?

回答

1

對於這一點,必須手動獲得3D模型對象幀(對應於屏幕)和比較器使用CGRectContainsPoint當前觸摸位置在touchesMoved委託。

編寫代碼_mesh.rotate只有當結果CGRectContainsPoint返回YES。

注意: NinevehGL有他們的own forum來討論有關框架的事情。請在那裏發佈查詢以獲得良好和快速的回​​應。

+0

謝謝你的回覆..是否有任何方法來獲得3d對象的框架?我沒有找到任何.. – Sandeep

+0

我認爲在http://nineveh.gl/community/forum/上發佈您的問題會更好,他們會在一天內回覆 –

1

下面的代碼可能會幫助你在一定程度上,

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
[super touchesMoved:touches withEvent:event]; 

UITouch *touch; 
CGPoint pointA,pointB; 
if ([touches count]== 1) 
{ 
    touch = [[touches allObjects]objectAtIndex:0]; 
    pointA = [touch locationInView:self.view]; 
    pointB = [touch previousLocationInView:self.view]; 

    NGLTouching touchingStruct = [_camera touchingUnderPoint: pointA]; 

    if (touchingStruct.mesh) 
    { 
     _mesh.rotateY += (pointA.x - pointB.x) * 0.5f; 
     _mesh.rotateX += (pointA.y - pointB.y) * 0.5f; 
    } 
} 

但它仍然不會改變網格的邊框。您可以參考this博客文章。