Thursday, December 23, 2010

23 December 2010

Resumed work on getting the pan gesture for translation up. Tried out another method of translation after studying a similar application. This method does not apply the calculation of the frustum's length at a particular z-axis, which at first made me wonder why it worked so well on that application.

- (void)panGestureCaptured:(UIGestureRecognizer *)gesture
{
...
...
...

static CGPoint currentLocation;
static CGPoint previousLocation;
ModelTransformation *obj = [[ModelTransformation alloc] init];
int objIndex = [eaglView retrieveObjectWithUniqueColors:gesture];
Vertex3D tempCurrentPosition = [eaglView getNodePositionWithIndex:objIndex];
if(gesture.state == UIGestureRecognizerStateBegan)
{
currentLocation = [gesture locationInView:[gesture view]];
currentLocation = [self convertToGL:currentLocation];
}
else if (gesture.state == UIGestureRecognizerStateChanged)
{
previousLocation = CGPointMake(currentLocation.x, currentLocation.y);
currentLocation = [gesture locationInView:[gesture view]];
currentLocation = [self convertToGL:currentLocation];
CGPoint diff = CGPointMake(currentLocation.x - previousLocation.x, currentLocation.y - previousLocation.y);
obj.xTranslation = tempCurrentPosition.x + diff.x;
obj.yTranslation = tempCurrentPosition.y + diff.y;
obj.ifTranslate = YES;
obj.node = objIndex;
[eaglView setTransformation:obj];
[obj release];
}
}

- (CGPoint)convertToGL:(CGPoint)uiPoint
{
float newY = eaglView.frame.size.height - uiPoint.y;
float newX = eaglView.frame.size.width - uiPoint.x;
CGPoint ret;
switch ([UIDevice currentDevice].orientation) {
case UIDeviceOrientationPortrait:
ret = CGPointMake(uiPoint.x, newY);
break;
case UIDeviceOrientationPortraitUpsideDown:
ret = CGPointMake(newX, uiPoint.y);
break;
case UIDeviceOrientationLandscapeLeft:
ret.x = uiPoint.y;
ret.y = uiPoint.x;
break;
case UIDeviceOrientationLandscapeRight:
ret.x = newY;
ret.y = newX;
break;
}
return ret;
}

This seems to work really nicely with some of the models that we have. Some of them just do not seem to work well at all.

No comments:

Post a Comment