im using ray triangle intersection algorithm. (12 triangles on the surface of the cube) im sure the problem is not related with that because ive used that intersection many times before. just create a cube and then create another meshnode which is extracted from the data of the bounding box of the cube. add them to the scene and you will see that bounding box is drawn to somewhere else. The codes are below.
CC3Material *cubeMaterial = [CC3Material material];
cubeMaterial.color=ccc3(0xff,0xff,0xff);
cubeMaterial.shininess = 1.0f;
cubeMaterial.isOpaque=FALSE;
cubeMaterial.diffuseColor=CCC4FMake(0.7, 0.7, 0.7, 0.8);
//CC3BoundingBox bbb = makeBounds(8, 5, 5, 20, 0, 0);
handNode = makeCube(8, 5, 5, endPos.x, endPos.y, endPos.z, true);
handNode.material = cubeMaterial;
handNode.material.diffuseColor = CCC4FMake(1.0, 0.5, 0.0, 0.8);
[self addChild:handNode];
//have to create this dummy node for the trick to fix the problem
CC3MeshNode * a = makeWireWidth(handNode.boundingBox, ccRED, 3.0);
handNode.location=a.location;
cube and bounding wire box creation functions below:
// make a wire box (a little bigger than the bounds)
CC3MeshNode* makeWireWidth(CC3BoundingBox bounds, ccColor3B wireColor, float wireWidth)
{
CC3LineNode *wire = [[[CC3LineNode alloc] init] autorelease];
CC3BoundingBox wireBounds;
wireBounds.minimum = cc3v(bounds.minimum.x-0.01f, bounds.minimum.y-0.01f, bounds.minimum.z-0.01f);
wireBounds.maximum = cc3v(bounds.maximum.x+0.01f, bounds.maximum.y+0.01f, bounds.maximum.z+0.01f);
[wire populateAsWireBox:wireBounds];
wire.color = wireColor;
wire.name = @"wire";
wire.isTouchEnabled = NO;
wire.lineWidth = wireWidth;
wire.shouldSmoothLines = YES;
return wire;
}
CC3MeshNode* makeCube(float xSize, float ySize, float zSize,
float originX, float originY, float originZ, BOOL wired)
{
CC3BoundingBox bounds = makeBounds(xSize, ySize, zSize, originX, originY, originZ);
CC3MeshNode *cube = [[[CC3MeshNode alloc] init] autorelease];
[cube populateAsSolidBox:bounds];
if (wired)
{
[cube addChild:makeWire(bounds)];
}
//following line is not working
cube.location=cc3v(originX,originY,originZ);
return cube;
}
CC3BoundingBox makeBounds(float xSize, float ySize, float zSize,
float originX, float originY, float originZ)
{
CC3BoundingBox bounds;
bounds.minimum = cc3v(originX-xSize/2,originY-ySize/2,originZ-zSize/2);
bounds.maximum = cc3v(originX+xSize/2,originY+ySize/2,originZ+zSize/2);
return bounds;
}