Hi Guys,
I am using Obj-C latest version on iPad. I am trying to create several ChipmunkCircleShape with different radius and I noticed that when that they collide, they bounce off each other before even they come in contact. Another weird thing is that if the colliding shapes are much different is size, say radius 4.0f vs radius 100.0f, the small shape goes all the way to the center of the big shape before bouncing off. It's almost as if one shape (perhaps the one moving faster) expects other shape to be same size as itself. What am I doing wrong? Please help.
Just for testing purposes, I put all the shapes same size and they worked perfectly. Also, I want to mention another problem (just in case this problem is causing the above one) - Space bounds are off both towards down and to the right.
Thanks
ChipmunkCircleShape with different radius exhibit weird beh
-
- Posts: 18
- Joined: Thu Jun 13, 2013 4:56 pm
- Contact:
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: ChipmunkCircleShape with different radius exhibit weird
Say what now? O_o
It sounds like you may have issue with rendering. What are you using for drawing and how are you handling coordinates?
It sounds like you may have issue with rendering. What are you using for drawing and how are you handling coordinates?
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 18
- Joined: Thu Jun 13, 2013 4:56 pm
- Contact:
Re: ChipmunkCircleShape with different radius exhibit weird
I am using CGRectMake to make UIImageView with rectangles and then draw circle using CAShapeLayer within rectangle bounds. Please see below
- (void)setLayerProperties {
CAShapeLayer *layer = (CAShapeLayer *)self.layer;
layer.path = [UIBezierPath bezierPathWithOvalInRect:self.bounds].CGPath;
layer.fillColor = datapointColor.CGColor;
}
Chipmunk Body and shape are then laid on top of these circles using -
body = [space add:[ChipmunkBody bodyWithMass:normalizedLoanAmt andMoment:INFINITY]];
...
ChipmunkShape *shape = [space add:[ChipmunkCircleShape circleWithBody:body radius:size/2 offset:cpvzero]];
and then updated as follows -
-(void)update:(id)sender
{
cpFloat dt = displayLink.duration*displayLink.frameInterval;
[space step:dt];
for (ChipmunkBody *eachbody in origBodies) {
UIImageView *view = (UIImageView *) [eachbody data];
[view setTransform:eachbody.affineTransform];
}
}
- (void)setLayerProperties {
CAShapeLayer *layer = (CAShapeLayer *)self.layer;
layer.path = [UIBezierPath bezierPathWithOvalInRect:self.bounds].CGPath;
layer.fillColor = datapointColor.CGColor;
}
Chipmunk Body and shape are then laid on top of these circles using -
body = [space add:[ChipmunkBody bodyWithMass:normalizedLoanAmt andMoment:INFINITY]];
...
ChipmunkShape *shape = [space add:[ChipmunkCircleShape circleWithBody:body radius:size/2 offset:cpvzero]];
and then updated as follows -
-(void)update:(id)sender
{
cpFloat dt = displayLink.duration*displayLink.frameInterval;
[space step:dt];
for (ChipmunkBody *eachbody in origBodies) {
UIImageView *view = (UIImageView *) [eachbody data];
[view setTransform:eachbody.affineTransform];
}
}
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: ChipmunkCircleShape with different radius exhibit weird
So I'm about 95% certain that the issue is that the origin of your CALayers just isn't quite where you think it is. An issue that has come up in the past with people using UIKit is that different UIKit components have different origins. Some seem to use the center and some seem to use a corner. That would make all of your objects positions be drawn translated by half of their size. Because of that, I've always set the center property of a UIKit component explicitly to CGPointZero when attaching them to ChipmunkBodies.
I've never used CAShapeLayers, but I'd be willing to be it's just an issue of drawing coordinates. I can guarantee you that there is nothing wrong with the circle collision code in Chipmunk.
I've never used CAShapeLayers, but I'd be willing to be it's just an issue of drawing coordinates. I can guarantee you that there is nothing wrong with the circle collision code in Chipmunk.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 18
- Joined: Thu Jun 13, 2013 4:56 pm
- Contact:
Re: ChipmunkCircleShape with different radius exhibit weird
It's likely something wrong in my code. But I am wondering why everything works fine with the exact same code when I make all CAShapeLayer the same size. The issue only appears if I vary the size of CAShapeLayer.
Also, do you have any examples with multiple ChipmunkBody objects with varying sizes? Thanks for your help.
Also, do you have any examples with multiple ChipmunkBody objects with varying sizes? Thanks for your help.
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: ChipmunkCircleShape with different radius exhibit weird
If none of them are rotating and they are all the same size then you wouldn't notice the offsets. Is that part of the problem?
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 18
- Joined: Thu Jun 13, 2013 4:56 pm
- Contact:
Re: ChipmunkCircleShape with different radius exhibit weird
It's true that none of them are rotating but I still don't get why the offset is visible when they are different sizes.
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: ChipmunkCircleShape with different radius exhibit weird
Well, when they all have the same size, their position is all offset by the same amount. When they are different sizes, their position offset will all be wrong by a different amount which I think is what is causing your issue.
If you set their origin using the "view.center = CGPointZero" fix, that should fix the alignment problems. Otherwise when you set the transform, it's setting the transform relative to a different point on different views.
If you set their origin using the "view.center = CGPointZero" fix, that should fix the alignment problems. Otherwise when you set the transform, it's setting the transform relative to a different point on different views.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 18
- Joined: Thu Jun 13, 2013 4:56 pm
- Contact:
Re: ChipmunkCircleShape with different radius exhibit weird
That fixed the problem. Thanks.
Who is online
Users browsing this forum: Bing [Bot] and 124 guests