Chipmunk moonbuggy dynamic landscape
I've been playing around with chipmunk and just need a little advice on the best approach. I'm attempting to change the moonbuggy example to use one continious landscape. The current landscape is a series of points created as a static shape, so Im wondering which way would be best:
1) To remove the entire landscape object and replace it with another one.
2) Make the landscape really long and when reaching the end put the view back to the begining again
I dont know how easy it would be to make either method seemless and prevent confusing chipmunk. What do people here think may be best?
Thanks!
1) To remove the entire landscape object and replace it with another one.
2) Make the landscape really long and when reaching the end put the view back to the begining again
I dont know how easy it would be to make either method seemless and prevent confusing chipmunk. What do people here think may be best?
Thanks!
Infinite perlin noise terrain moon buggy:
http://howlingmoonsoftware.com/downloads/ByteRacer.zip
Written in mostly in Ruby, which you can see by digging around in the app bundle. Basically it generates chunks of terrain and adds/removes them when they enter/exit the screen. It also wraps the position of the car to keep it near the (0,0) and moves the terrain around it to match. This probably isn't really necessary, but I was playing around.
If you just want looping terrain, I'd just repeat the terrain and wrap the positions of bodies when they get near the ends.
http://howlingmoonsoftware.com/downloads/ByteRacer.zip
Written in mostly in Ruby, which you can see by digging around in the app bundle. Basically it generates chunks of terrain and adds/removes them when they enter/exit the screen. It also wraps the position of the car to keep it near the (0,0) and moves the terrain around it to match. This probably isn't really necessary, but I was playing around.
If you just want looping terrain, I'd just repeat the terrain and wrap the positions of bodies when they get near the ends.
Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Thanks! I'll have a look at that tonight
I've successfully managed to get most of this working but I'm having one remaining problem that I cant seem to solve.
The land is created and drawn and matches with the chipmunk shapes etc just fine, you can move forwards and backwards and the next and previous shapes are created and placed in the correct positions. However, if you say move backwards far enough for a new segment to be created in front of you, and move forwards again to where you started, it starts following shapes that should no longer be there. Eventually if you carry on going you will fall back down to where the land really is and be able to continue as normal.
I'm assuming this is due to old shapes not being removed properly, but I cant seem to get it working. I've attacked the relevent parts of my code below. Its either that or I'm not copying landSegments elements over properly, ie its a basic C mistake.
The land is created and drawn and matches with the chipmunk shapes etc just fine, you can move forwards and backwards and the next and previous shapes are created and placed in the correct positions. However, if you say move backwards far enough for a new segment to be created in front of you, and move forwards again to where you started, it starts following shapes that should no longer be there. Eventually if you carry on going you will fall back down to where the land really is and be able to continue as normal.
I'm assuming this is due to old shapes not being removed properly, but I cant seem to get it working. I've attacked the relevent parts of my code below. Its either that or I'm not copying landSegments elements over properly, ie its a basic C mistake.
Code:
struct Segment {
float *points;
cpShape *myshape[65];
};
typedef struct Segment Segment;
Segment landSegments[3];
updateTerrain() {
for (int s = midPoint-1; s <= midPoint+1 ; s++) {
for (int p = 0; p < noOfPointsPerSegment; p++) {
cpSpaceRemoveStaticShape(space, landSegments[s].myshape[p]);
cpVect b = cpv(d*50.0f, landSegments[s].points[p]*80.0f);
landSegments[s].myshape[p] = cpSegmentShapeNew(staticBody, a, b, 0.0f);
landSegments[s].myshape[p]->u = 1.0;
cpSpaceAddStaticShape(space, landSegments[s].myshape[p]);
a = b;
d+=1.0f;
}
}
}
processLand() {
if (nextSeg)
landSegments[0] = landSegments[1];
landSegments[1] = landSegments[2];
float *noise = createNoise(noOfPointsPerSegment, landSegments[1].points[noOfPointsPerSegment-1], TRUE);
landSegments[2].points = noise;
updateTerrain();
}
else if (prevSeg) {
landSegments[2] = landSegments[1];
landSegments[1] = landSegments[0];
float *noise = createNoise(noOfPointsPerSegment, landSegments[0].points[0], FALSE);
landSegments[0].points = noise;
updateTerrain();
}
}
I'm pretty sure its not to do with copying the arrays incorrectly. I'm sure it has to do with not removing the old shapes in chipmunk.
I've also tried removing all the shapes, re-adding them in a seperate loop and then calling cpSpaceRehashStatic(space); I've tried a few different combinations but none seem to work.
It would be great if anyone has any suggestions
I've also tried removing all the shapes, re-adding them in a seperate loop and then calling cpSpaceRehashStatic(space); I've tried a few different combinations but none seem to work.
It would be great if anyone has any suggestions
Typically, I went to bed and two mins later I solved it
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Attempting to add landscape IB buttons to an openGL View | Madrayken | 1 | 3,000 |
Oct 17, 2010 07:03 AM Last Post: iamflimflam1 |
|
| Landscape app sometimes thinks portrait | bruss14 | 1 | 1,859 |
Dec 30, 2009 01:32 PM Last Post: bruss14 |
|
| iPhone opengl 2d sprites landscape mode | mnorton | 6 | 4,868 |
Sep 9, 2009 08:27 PM Last Post: mnorton |
|
| How can I add autorotate (landscape, portrait) to an OpenGL ES app? | riruilo | 6 | 7,610 |
Feb 12, 2009 07:51 AM Last Post: AnotherJake |
|
| How to Achieve Landscape View Properly | bmantzey | 14 | 8,435 |
Nov 15, 2008 10:16 AM Last Post: Andy1988 |
|

