1
Feb/10
3

Little progress update!

Between times full of study and work I found some time again to work on a few projects. But first I want to apologize to the people who commented on articles here in the period of about May – December 2009, due to the crapload of spam I recieved in the comments I wasn’t able to filter out spam from my readers. And have thus removed all the pending comments from that period. Now back to where I started, the projects I’m working on at the moment… Recently I made a mock up for a collaberative multi user chat/drawing application meant for sharing ideas, sketches, links and possibly files. Unfortunately I can’t share this with you now for technical and financial reasons. What I can share with you is the progress I made when I recently returned to my particle and constraint engine! Having learned a few more fundamental mathematical skills I found it worth looking at Thomas Jakobsen’s article ‘Advanced Character Physics’ again. And a few day’s later we have the beginnings of a very scalable and probably efficient physics engine (see it in action after the read more link). In the coming weeks I will refine the engine, rewrite ponstructor, release ponstructor and possibly the physics engine as well!

There were a few people impressed and interested in the 3D engine, currently it is not high on my to do-list since there are many better and more efficient offerings out there like Papervision 3D, Away 3D and Sandy. But as soon as I release Ponstructor and the physics engine I might find time to revisit the 3D engine since there is room for a lot of improvement and rewriting.

11
Jan/09
10

Ponstructor beta release!

Since the last post I’ve been quietly working on a real good version of the bridge builder game for flash.  Take a look at the result after the ‘Continue Reading’ link and tell me what you think, (or if you spotted a bug) in the comments.

28
Dec/08
2

Bridge Builder Game! (Concept)

Constraint based bridge simulator

Constraint based bridge simulator

Some of you might remember a game called pontifex or bridge builder if you don’t; it’s a game in which you construct a bridge with beams and than let a train or car drive over it to see whether it holds. It is really fun and quite educational at the same time (equals morally appropriate right?). After some more research into rigid body constraints I found out that pontifex probably used the same stuff like I used in the 2D constraint based rope. So with some minor modifications it was easy to create a bridge simulator and with a littlebit more code even a bridge builder. It is still far from a game suitable for release and profit but it is definatly a playable minigame. Take a look at the working example by clicking the  ‘Continue Reading’ link.

26
Dec/08
19

2D Constraint based rope

Constraint based rope simulation

Constraint based rope simulation

So I was looking into some cool stuff to do with my 3D engine when I came across this. I’ve always been a fan of physics simulation based realism so I began to work this out in 2D. The first demo was using elastic constraints between particles but that made a very instable system. It can be improved with better integrators like RK4 but that still didn’t result in the desired result. I might have other plans for these elastic constraints later though. You can read more about elastic constraints here [Gaffer's tutorial on spring physics] and here [Gamasutra's "Exploring spring models"]. So I went on with inelastic infinitely ’stiff’ constraints which were mentioned in this ["Advanced Character Physics" by Thomas Jakobsen] great resource on computer physics simulation. The result worked out pretty well and will be easy to port to 3D. Which will happen when I’m done with a little (very interesting) side project using the same code. More about that later… Check out the working demo after the ‘Continue Reading’ link.

2
Nov/08
0

3D Graphing in flash

Made a few quick mock ups for simple graphing programs using my 3D engine in Flash. Currently there is still a lot of room for improvement in speed, light angles and (invisible) shadows are being calculated which is unnecessary. Check out the applications in realtime at the read link;

One dimensional graph in 3D

One variable graph in 3D

Two dimensional graph in 3D

Two variable graph in 3D

1
Nov/08
4

V0.65 – Shadows in 3D!

Made a great lot of very usefull changes in this version. First and most basic being the addition of line and dot primitives in the rewritten frame loop. This allows for some really cool stuff you will see soon (3D graphs!). And the rewriting of the frame loop added a lot more possibilities for the future as well, with respect to light, shadows and glows. Checkout a realtime demo of the action after the read link.

A demo of the AS3 3D Engine doing shadows, realtime demo after the read link.

A demo of the AS3 3D Engine doing shadows, realtime demo after the read link.

20
Sep/08
0

3D Engine V0.52

Made a huge leap forward the last few weeks, this version of the engine is actually quite usefull and easy for most simple 3D things. But I’m not quite ready to release source code yet there are still a few things to do, to make it more of a complete engine. Below is a demo of what it is capable of right now;

Bugfixes:

  • Altered the 3D camera translation function to something that also works when looking down on an object.

Known bugs:

  • The triangular polygons are now textured with only two triangles, this can still be increased…
  • Focal point singularity, some 3D points that are in the focal point of the camera move to an infinite distance.
  • Some polygons are incorrectly culled.

New features:

  • Added a cylinder primitive
  • Added a cone primitive
  • Added UV mapping for all primitves; cube, sphere, cylinder and cone
  • Added 3D lighting, for the moment it will support multiple light entities with only white light
  • Added ambient lighting
  • Added 3D surface normals
  • Added colouring and texturing support for triangular polygons

Upcoming features:

  • View frustum culling
  • Performance increase
  • Directional light and light with different colours
  • Roll camera movement
  • Object rotation
  • Texture perspective correction
  • 3D particles!

Maybe phong shading will also be possible one day with gradients but it’s not uber important. And I thought about doing shadows with the new bitmapfilter api, but that is all still very experimental. What matters the most at the moment is creating a finished version of which I will release all the source code for free. Soon I will also post about the inner workings of a 3D engine, something that I couldn’t find (as in all info being on one page) on the interwebs.

30
Aug/08
0

3D Engine V0.3

Made quite some progress lately. Got the constructSphere function up quite quickly, the UV mapping and copyPixels took a little longer but in the end really paid off:

Currently the UV mapping only works with spheres, but it will be easy to implement it into other models later. I’m quite pleased already with the performance; the demo above renders 529 polygons with a high resolution texture (1350×675 pixels). However there is still room for lots of improvement;

Bugfixes:

  • Added function moveObject, wich if drawing faces should be used instead of moveGroup. (Otherwise the midPoints don’t move and thus making the z-sorting work incorrectly.)
  • Reversed the y transformation in the process of making 2D points from 3D coordinates, because in the flash coordinate system the y axis is reversed

Known bugs:

  • For some reason transparent bitmaps don’t work yet, I’ll have to look into the different copyPixels and beginBitmapFill functions for this one…
  • For some reason looking down from above gives a distorted and unreallistic view, I’m not sure where this problem came from.
  • Faces that have one, two or three points behind the camera are rendered ackwardly, but this will be fixed in the next version with view frustum culling.
  • The backface culling function is not perfect yet, the top of the sphere shows about 3 faces beeing culled that shouldn’t be culled.
  • The edges of UV faces are visible sometimes, this is due to the repeat parameter I use to create parts of the bitmap fill might be able to fix this with a bit of a different matrix algorithm.

New features:

  • Textures from images
  • The function moveObject to move objects
  • A debug mode
  • The sphere primitive
  • UV mapping for spheres
  • Backface culling

Upcoming features:

  • Phong shading
  • More primitives
  • View frustum culling
  • Lighting and shadows
  • Performance improvements
  • Rotate object functions
  • And a few more…

The navigation is still somewhat ackward for the sake of simplicity;

  • W,S let you move along the z-axis
  • A,D let you move along the x-axis
  • Numpad 2 and 8 let you move along the y-axis
  • Left and right arrow keys let you rotate left and right
  • Up and down arrow keys let you rotate up and down

Thanks to Senocular and Lifeztream for these two classes;
Senocular’s keyObject class – for detecting multiple keyboard presses at once
Lifeztream’s FPS class – for displaying the 3D engine performance

25
Aug/08
0

Queue loader items in an AS3 class

I wrote a class lately to queue loader items in AS3. I use it to load textures for my 3D engine but you can use it without modification for the loading of other files. The class is very simple, and doesn’t give any information about the loading progress apart from when it finishes loading all files. The class comes in handy when trying to load multiple files and have one event listener when all files are loaded. Below an example of the implementation:

[sourcecode language='actionscript']import qLoader; // You can change the package to for example com.input.qLoader;
var loader:qLoader = new qLoader();
// You can add relative file locations, but SWF’s online will likely
// only accept url’s on the same domain.
// You can activate debug traces by enabling the debug mode once the
// class has been created by uncommenting the following line:
// loader.mDebug = true;
loader.addLoad(”textures/stone.jpg”);
loader.addLoad(”textures/stone2.jpg”);
loader.addLoad(”textures/stone3.jpg”);
loader.addLoad(”textures/stone4.jpg”);
loader.addLoad(”textures/stone5.jpg”);
loader.addEventListener(”completeQ”,onLoaded);
// Initiate the loader
loader.initiate();

function onLoaded(evt:Event):void {
// In this example I create a bitmapData object
var bm:BitmapData = new BitmapData(loader.mFinishedItems["textures/stone.jpg"].width,loader.mFinishedItems["textures/stone.jpg"].height,false);
bm.draw(loader.mFinishedItems["textures/stone.jpg"],new Matrix());
}[/sourcecode]

The class needs to be an extension on the EventDispatcher class to work (otherwise it cannot dispatch events). I might update the class with progress info (like 100/4555Kb) or something and the loadNext() and loadItems() functions are the same but I’m too lazy for that now.

qLoader.as

Tagged as: , ,
20
Aug/08
3

Bitmap skewing class

Finally, after two days of trial and error, I got my bitmap skewing class working. The class is based upon Flash and Math’s work, especially the algorithm for ‘triangulating’ (I know this is not the right word) distorted quadrilaterals. The class is quite complete there might be another function for simply rendering textures onto triangles instead of quadrilaterals. See the class in action below, adjust the “AA” level (I know it’s not really the same, but couldn’t think of a nicer term) to increase or decrease the level of precision. The higher the AA level the better it looks. Lower AA levels increase performance. The same counts for the noise reduction, which decreases the performance when turned on.

Download the skew.as class

The usage is fairly simple;

[sourcecode language='actionscript']import com.skew;
// First boolean is for noise reduction the second for debug mode
var sk:skew = new skew(false,false);
// For skews with a greater precision than 1
sk.AASkew(a,b,c,d,bitmap,sp,AAh,AAv);
// For skews with a precision of 1
sk.transformer(a,b,c,d,bitmap,sp,AAh,AAv);
// With a,b,c,d being arrays containing 2 dimensional points e.g. a = [10,10];
// And bitmap being a bitmapData object
// sp being a sprite or shape
// AAh and AAv respectively being the horizontal and vertical “AA” levels[/sourcecode]

The sk.transformer function is quite an increase in performance from the sk.AASkew function because it doesn’t require mapping the non distorted bitmap.

EDIT: Updated the skew class with a better variable name for the smoothing parameter and corrected the skew functions to smooth both halves. Thanks to Banana.