【问题标题】:About touch events for imported 3d model in NinevehGL framework关于 NinevehGL 框架中导入 3d 模型的触摸事件
【发布时间】:2012-12-05 08:58:32
【问题描述】:

我正在使用此代码旋转 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;
    }
}

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

【问题讨论】:

    标签: iphone ios opengl-es 3d-rendering


    【解决方案1】:

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

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

    注意: NinevehGL 有他们的own forum 来讨论与框架相关的事情。请在此处发布查询以获得良好和快速的响应。

    【讨论】:

    • 感谢您的回复..有什么方法可以获取 3d 对象的框架吗?我没有找到任何..
    • 我觉得最好把你的问题发到nineveh.gl/community/forum他们会在一天内回复
    【解决方案2】:

    以下代码可能对您有所帮助,

    -(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博文。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      • 2017-07-30
      • 1970-01-01
      • 2011-03-30
      • 2013-05-09
      • 1970-01-01
      相关资源
      最近更新 更多