I'm have a weird issue with a pair of GLKVector3 structs. I get them from two calls to an objc method axisForIndex:
, then pass them to a C function getContactPoint
to perform a computation. However, when the argument of both calls to axisForIndex:
are zero, their values "vanish" after I enter the method -- that is, the value of first.x might be .55 outside the method, but it is 0 inside. When I look at them in the debugger, none of their fields are filled in, and when I print description I get something like (GLKVector3) varName = <variable not available>
. However, checking the values in the method calling getContactPoint
before and after it is called shows that they are as they should be. I'm using Xcode6-Beta6 to compile and run the code.
Here's the code:
GLKVector3 first = [self axisForIndex: oneAxisIndex]; // the structs I want to use
GLKVector3 second = [other axisForIndex: twoAxisIndex];
//in this method they have garbage values
result.contactLocation = getContactPoint(first,
second,
ptOnEdgeOne,
ptOnEdgeTwo);
//test to see if the result was computed correctly
if (result.contactLocation.x == 0 && result.contactLocation.y == 0 && result.contactLocation.z == 0) {
NSLog(@"%ld,%ld", (unsigned long)oneAxisIndex, (unsigned long)twoAxisIndex);
}
result.interpenetration = bestOverlap;
return result;
Here is the implementation of getContactPoint, the method where the values are undefined.
GLKVector3 getContactPoint(GLKVector3 axisOne,
GLKVector3 axisTwo,
GLKVector3 ptOnEdgeOne,
GLKVector3 ptOnEdgeTwo) {
GLKVector3 toSt = GLKVector3Subtract(ptOnEdgeOne, ptOnEdgeTwo);
GLfloat dpStaOne = GLKVector3DotProduct(axisOne, toSt);
GLfloat dpStaTwo = GLKVector3DotProduct(axisTwo, toSt);
GLfloat smOne = GLKVector3Length(axisOne);
GLfloat smTwo = GLKVector3Length(axisTwo);
GLfloat dotProductEdges = GLKVector3DotProduct(axisTwo, axisOne);
GLfloat denom = smOne * smTwo - dotProductEdges * dotProductEdges;
GLfloat a = (dotProductEdges * dpStaOne - smTwo * dpStaOne)/denom;
GLfloat b = (smOne * dpStaTwo - dotProductEdges * dpStaOne)/denom;
GLKVector3 nearestPtOnOne = GLKVector3MultiplyScalar(GLKVector3Add(ptOnEdgeOne, axisOne), a);
GLKVector3 nearestPtOnTwo = GLKVector3MultiplyScalar(GLKVector3Add(ptOnEdgeTwo, axisTwo), b);
return GLKVector3Add(GLKVector3MultiplyScalar(nearestPtOnOne, 0.5), GLKVector3MultiplyScalar(nearestPtOnTwo, 0.5));
}
Implementation of axisForIndex.
-(GLKVector3) axisForIndex: (NSUInteger) index
{
GLKVector4 vec = GLKMatrix4GetColumn(self.transformationMatrix, index);
return GLKVector3Make(vec.x, vec.y, vec.z);
}