3

I want to create a CC3MeshNode with boundingvolume in cocos3d. I have created a CC3MeshNode with a pod file. I want to get notification on collision .

 -(void) initializeScene 
    {
    [self addContentFromPODFile: @"hello-world.pod" withName:@"pod1"];
    CC3MeshNode *object1 = (CC3MeshNode*)[self getNodeNamed: @"pod1"]; 
    CC3MeshNod *object2=[[object1 copyWithName:@"pod1"]autorelease];    
    [object1 populateAsSolidBox:CC3BoundingBoxMake(9.5, 5.0, 4.0, 0.0, 0.0, 0.0)];                 object1.location=cc3v(-5.0, 0.0, 0.0);  object2.location=cc3v(5.0, 0.0, 0.0);  
    [self addChild:object2];    
    CCActionInterval *move1=[CC3MoveTo actionWithDuration:3.0 moveTo:cc3v(-1.0, 0.0, 0.0)];    CCActionInterval *move2=[CC3MoveTo actionWithDuration:3.0 moveTo:cc3v(1.0, 0.0, 0.0)];    [object1 runAction:move1];    
    [object2 runAction:move2];
    }
        -(void) updateAfterTransform: (CC3NodeUpdatingVisitor*) visitor
         {
                if([object1 doesIntersectNode:object2])       
                NSLog(@"Collision !!!!!!!!!!!!!!!!!!!!!!");
        }

I tried to assign boundingvolume but didnt work. Actually i am confused in implementing boundingvolume for cc3MeshNode

David Rönnqvist
  • 56,267
  • 18
  • 167
  • 205
Karan Alangat
  • 2,154
  • 4
  • 25
  • 56

1 Answers1

2

Your comment above says:

I get error in [object1 populateAsSolidBox:CC3BoundingBoxMake(9.5, 5.0, 4.0, 0.0, 0.0, 0.0)];

Here's why you have the error. From the CC3Foundation documentation it looks like you are setting the max values in CC3BoundingboxMake to a value lower than the mins (they are all zero), in the call

CC3BoundingBoxMake(9.5, 5.0, 4.0, 0.0, 0.0, 0.0)]; 

That is, from the link above, the signature of CC3BoundingBoxMake() is

CC3BoundingBoxMake ( GLfloat minX,
                     GLfloat minY,
                     GLfloat minZ,
                     GLfloat maxX,
                     GLfloat maxY,
                     GLfloat maxZ 
)

where your minX is 9.5 and your maxX is 0.0, your minY is 5.0 and your maxY is 0.0, and your minZ is 4.0 and your maxZ is 0.0.

Bart
  • 19,692
  • 7
  • 68
  • 77
  • @ Yatin Saraiya ,Thanks for Your reply. I got that code from stack overflow itself. And when i tried your answer got the following error.>>>> 2013-07-17 17:47:31.015 collision sample[3006:c07] -[CC3PODResourceNode populateAsSolidBox:]: unrecognized selector sent to instance 0x8c829d02013-07-17 17:47:31.017 collision sample[3006:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CC3PODResourceNode populateAsSolidBox:]: unrecognized selector sent to instance 0x8c829d0' – Karan Alangat Jul 17 '13 at 12:39