Asteroids in 3D… and a bit of 2D
Cathy Leung | 1 February, 2010 | 6:12
So I’ve been working on this little demo in preparation for the upcoming (very very soon…docs left only) release of C3DL’s webGL release. I adapted it from Peter Callaghan’s Asteroids game and the models were from an old demo made as part of our user testing last year.
This demo is kind of cool because it demonstrates many of the features of C3DL and puts it all together in one. Namely it uses:
- collada model loading – you can export to collada from a good number of modeling programs including blender, 3ds max and google sketchup
- particle systems – watch the rocks when they explode!
- lighting – ok… this is not featured well… I’ll try to see if I can do better with it
- picking – click on rock to identify which one

Wow, now that's a cool demo! :D
Andor Salga | 1 February, 2010 | 15:08Wow, now that’s a cool demo!
It's unbelievable how far browser technology has come! I'm sure
Paul | 12 February, 2010 | 17:23It’s unbelievable how far browser technology has come! I’m sure that your library will become ubiquitous as webgl adoption progresses.
I was wondering if there is a forum for C3DL
Phreak Nation | 1 December, 2010 | 19:58I was wondering if there is a forum for C3DL or something because I have a few questions I was needing to have a question answered. Below is my Q. There is not enough resources that is for sure. I love C3DL and would love to see a forum put up
I want to turn the player in the direction he is moving. Thus far all he does is rotate based on the center cords. Which is annoying to say the least. Thanks for any help.
var pos = player.getPosition();
playerX += (destinationX - pos[0]) * speedCurrent;
playerZ += (destinationZ - pos[2]) * speedCurrent;
var radians = Math.atan2(playerZ, playerX);
if (radians!=oldyaw) {
player.yaw((radians-oldyaw));
oldyaw=radians;
}
player.setPosition([playerX,0,playerZ]);
We don't really have a forums, but if you post
Cathy Leung | 2 December, 2010 | 2:07We don’t really have a forums, but if you post a comment generally we will try to see what we can do to help.
I’m not sure as I have not tried this but perhaps you can set the lookatpoint of the camera to be directly in front of you? Let me experiment with that and see if that works.
This is a diablo styled game and the player moves
Phreak Nation | 2 December, 2010 | 18:12This is a diablo styled game and the player moves based on where the mouse is clicked. I managed everything but the “player” spins based on the center[0,0,0] of the map and not himself relative to the location. He spins how he should, if it was based on the center of the map…lol
Heres an update to the code. As you can tell the lookpoint is the character, rather alittle above as to not give the effect of looking lower than him.
function update() {
var pos = player.getPosition();
if (mouse_left) {
// Grab mouse cords based on X,Y and translate them to 3d cords, X,Y,Z
destinationX = worldCoords[0];
destinationZ = worldCoords[2];
if (speedCurrent 0.01) speedCurrent *= decay;
else speedCurrent = 0;
}
playerX += (destinationX - pos[0]) * speedCurrent;
playerZ += (destinationZ - pos[2]) * speedCurrent;
var radians = Math.atan2(playerZ, playerX);
// var degrees = radians / (Math.PI / 180);
if (radians!=oldyaw) {
// Rotate player based on old position to new position
player.yaw(radians-oldyaw);
// Shows yaw in debug area
$("#debug").html(radians-oldyaw);
// remember old yaw
oldyaw=radians;
}
// Move player
player.setPosition([playerX,0,playerZ]);
// Move camera based on players location and look relative to his position
cam.setPosition([playerX+150,300,playerZ+150]);
cam.setLookAtPoint([playerX, 50.0, playerZ]);
// Move a light based on players position
diffuse.setPosition([playerX+50,100,playerZ+50]);
// Replenish stats based on game time
statReplinish();
}
I have fixed this issue. If you would like to
Phreak Nation | 11 December, 2010 | 7:14I have fixed this issue. If you would like to view the source code please head over to http://www.phreak-nation.com/new_terra/
Was not working with the link.