我正在使用以下代码旋转 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;
}
}
代码按预期旋转,但无论我点击视图中的哪个位置,它都会旋转。我希望它只在接触导入的模型时旋转。我该怎么做?