Monday, February 06, 2006

Solid Geometry

Well,

Since the demo i have been working hard on ironing out the little issues we had left and adding some new 3D features into the engine.

I thought i would write my first indepth post on the technology behind the game, and explain how we are achieving 3d objects while maintaining (hopefully!) high frame rates. I am using a technique that was explained to me by kirill mourzenko several years ago, and i used a less advanced version in my earlier (unfinished) game Felony (on which Jon helped with the physics, and is actually how we hooked up for this game!)


Faking It

The 3d objects in Flash Racer are faked through a combination of clever scaling, animation and paralax scrolling. Firstly, for each object the distance is found between it and the center of the screen. For buildings, this distance is then used to offset the roof by an amount depending on the buildings height. So, as the building moves further from the center of the screen the roof becomes more offset, this creates the impression of perspective.



See how the building to the left appears to be leaning more? Of course for taller buildings this effect is even more dramatically increased. The roof of the building is also scaled up according to its height as objects closer to the camera should appear bigger!

The walls are wedge shaped images that are simply scaled to fit between the base of the building and the side of the roof, at the moment this calculation is performed every frame in the Camera Class, however this could be reduced for lower spec machines and i am looking into making this one of the many graphics options we are likly to include!


The final piece of the puzzle is to skew the wall image so that it fits when the roof is no longer above the building base. This is predone animation, with one keyframe for every single pixel of movement (81 keyframes in total), this is a very efficient way of achieveing the right look.







On a side note, i have noticed that you can now dynamically skew images in flash 8, this would have been ideal for this, however we are currently coding for flash player 6 in AS1 so it would be unreasonable to code only one feature in the brand new flash player! Maybe in a future version?


Pseudo Speed

These tall objects are great, because they add that extra level of depth to the game and just as importantly - because they are closer to the camera, they move faster and dramatically increase the feel of speed when racing! All we need now is a little blurring...

Any questions? Just leave a comment! Extra points if you can work out the cryptic title ;-)

5 comments:

Anonymous said...

Do you have any examples of this flash code? I'm interested in the way you've implemented the pseudo-3d objects in a top-down view.

Tom said...

Hi Imp,

If you look at the source you will see the SWF is actually hosted externally - on some free webspace. It is simply embedded like you would on any other webpage, you have to use the HTML view in the post editor to added the embed code...

Cheers

Tom said...
This comment has been removed by a blog administrator.
Tom said...

Hi Powerups,

Glad to hear you like the car dynamics! And yes believe it or not, although the blog hasn't been updated - we are still here.

Unforunatly, the main resource that we used to create the dynamics seems to have been taken down. You can access a version of the document here:

http://web.archive.org/web/20050207223102/http://home.planet.nl/~monstrous/

However, many of the images are missing.

stev4n said...

3d scanning from Surfdev, a specialist scanning service performed by a reverse engineering company.
Vaccum forming and CAD/CAM, APHWEB provide high specification work, working from drawings and models using modern and traditional methods.