@Bill Hollings
Sorry, I didn't include the ray-box intersection code, before. But, I've included it here in this post. Anyhow, I've been reading up more on the subject and I guess the correct term in 3D game development for what I'm trying to do is creating "Decals". And, it looks like there's more to this than just figuring out the coordinates a user touched on a 3D object. You mentioned that this is a feature that's in development and I look forward to that feature in a future cocos3d release. But in the meantime, I guess I'll challenge myself into figuring this out.
thanks for your help.
-(void) nodeSelected: (CC3Node*) aNode byTouchEvent: (uint) touchType at: (CGPoint) touchPoint {
CC3Ray touchLoc = [self.activeCamera unprojectPoint:touchPoint];
CC3MeshNode* meshNode = (CC3MeshNode*)[self getNodeNamed: @"boxNode"];
CC3GLMatrix *mat = meshNode.transformMatrixInverted;
CC3Vector loc = [mat transformLocation:touchLoc.startLocation];
CC3Vector dir = [mat transformDirection:touchLoc.direction];
CC3BoundingBox box = meshNode.localContentBoundingBox;
GLfloat txMin,txMax,tyMin,tyMax,tzMin,tzMax;
BOOL intersect;
if(dir.x >= 0) {
txMin = (box.minimum.x - loc.x)/dir.x;
txMax = (box.maximum.x - loc.x)/dir.x;
}
else {
txMin = (box.maximum.x - loc.x)/dir.x;
txMax = (box.minimum.x - loc.x)/dir.x;
}
if(dir.y >= 0) {
tyMin = (box.minimum.y - loc.y)/dir.y;
tyMax = (box.maximum.y - loc.y)/dir.y;
}
else {
tyMin = (box.maximum.y - loc.y)/dir.y;
tyMax = (box.minimum.y - loc.y)/dir.y;
}
if(txMin > tyMax || tyMin > txMax) {
intersect = NO;
}
else {
intersect = YES;
}
if(tyMin > txMin) txMin = tyMin;
if(tyMax < txMax) txMax = tyMax;
if(dir.z >= 0) {
tzMin = (box.minimum.z - loc.z)/dir.z;
tzMax = (box.maximum.z - loc.z)/dir.z;
}
else {
tzMin = (box.maximum.z - loc.z)/dir.z;
tzMax = (box.minimum.z - loc.z)/dir.z;
}
if (txMin > tzMax || tzMin > txMax) intersect = NO;
if (tzMin > txMin) txMin = tzMin;
if (tzMax < txMax) txMax = tzMax;
LogInfo(@"txMin = %f | txMax = %f | tyMin = %f | tyMax = %f | tzMin = %f | tzMax = %f", txMin,txMax,tyMin,tyMax,tzMin,tzMax);
}