No longer look through the wall

Web July 14th, 2007

In last two weeks, I was bothered by the visibility problem of dojox.gfx3d library. Eventually, I decided to review the Computer Graphics 101, and checked out Fundamentals of Computer Graphics, second edition from the library. This books poses two approaches: Z Buffer and Binary Space Partition(BSP).

Z Buffer is pixel based, and does not fit for our requirement, we don’t have the luxury to implement a render pipe using JavaScript. While BSP is primitive based, we still need to draw all the 3D objects in the viewport, just in a Painter’s algorithm manner.

The idea is for any polygon, for example, (a, b, c), the space is divided by the plane into two space: plus and minus. For any arbitrary vertex p, if (pa) dotProduct n = 0, p is inside the plane, > 0, p is in the plus space, vice versa for minus space. n is the normal vector that is perpendicular the plate, defined as:

n = ( b – a ) crossProduct ( c – a )

When Viewport render 3D objects, it iterates all its children and apply the camera transform to map the 3D objects to the new coordination system, then build the BSP tree based upon the polygonized vertices. At the end, in-order-transverse the BSP tree to draw the 2D shape to the canvas.

So far, this algorithm works for triangle, and theoretically works fine for all polygons. we may need to consider how to bring the Edge to the table, and I do believe the Scene needs to be refactored unless some constraints are imposed to the Scene.

Here is the snapshot of the latest working copy.

Where is the time machine?

Gentoo July 11th, 2007

After several times unsuccessful hibernation, the JFS file system is screwed up by the forceful shutdown. There are some directories with weired access control in the portage, that cause the fsck.jfs exit abnormally. Eventually, I decided to clean up this morning using the ultimate way: format.

I did a full stage4 backup first, and then format the disk and tried to recover from the stage4 tar ball. Oops, here is an fatal error. It looks like the backup met some errors then exited with a success message. That is really not funny.

Anyway, I had a backup one week ago, it is old since I update the system everyday, yes, that is the typical Gentoo users’ behavior. But wait, I just got the second half of the split stage4 tar ball, where is the first half?

Where is the time machine?

Yet yet another cube

Web July 1st, 2007

I made a huge mistake on the last post, Yet another cube. In that post, I attached a quick-n-dirty implementation of dojox.gfx3d that work in Firefox only. Unfortunately, no source code is attached except gfx3d.js and a symbol link to my home directory. I untared the tar ball, and it worked, of course it just linked to my working copy! Here is the current snapshot.

In this implementation, I took the lazy evaluation, thanks to Eugene’s advice:
Once a 3D object is created in dojox.gfx3d.Viewport, only meta is recorded. The real DOM node is not constructed till the last minute, when dojox.gfx3d.render is called. That simplify the development and eliminate the dependencies of SVG and VML renders under the hood.

Cube in Firefox and MSIE



Above is screenshot in Firefox 2.0 and MSIE 6.0, you can see the inconsistence of the coordination system, we would fix that later. And here are more to consider:

  • Scene support so we can apply the world transform in a group of objects
  • Texture support: solid and gradient for more sophisticated texture
  • Z-order

Once we solve these problem, the next step is just to propagate it to other more complicated objects.