-1

我正在使用以下代码旋转 3d 模型:

_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;
    }
}

代码按预期旋转,但无论我点击视图中的哪个位置,它都会旋转。我希望它只在接触导入的模型时旋转。我该怎么做?

4

2 回答 2

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;
    }
}

但它仍然不会改变网格的边界框。你可以参考这篇博文。

于 2013-07-16T09:29:57.757 回答
1

为此,您必须使用委托手动获取 3d 模型对象框架(对应于屏幕)并与当前触摸位置CGRectContainsPoint进行比较。touchesMoved

_mesh.rotate仅当结果CGRectContainsPoint返回 YES时才编写代码。

注意: NinevehGL 有自己的论坛来讨论与框架相关的事情。请在那里发布查询以获得良好和快速的响应。

于 2012-12-05T09:18:14.690 回答