[cairo] 3D in Cairo

Bill Spitzak spitzak at d2.com
Mon Feb 28 14:18:14 PST 2005


David Reveman wrote:

> I'm afraid the answer today is yes, but I'd like it to be, No.
> 
> "If you want to do 3d, you should instead be using OpenGL", I've heard
> this from more than one person and I don't like it...
> 
> Microsoft Avalon will make it really easy for developers to write simple
> efficient 3d applications in Windows.
> 
> I'm not sure cairo is the answer, but I think we need something that is
> sort of doing for 3d what cairo is doing for 2d.
> 
> I think that having some basic 3d stuff in cairo would be useful, but
> it's of course important that it doesn't complicates the 2d stuff.

I believe this can be done.

In my opinion if Cairo cannot do perspective distortions of an image it 
is going to be a serious impediment. This is the only missing graphical 
effect *required* to draw a 3D scene (everything else can be done in 
practical ways by the calling program, including slicing objects and 
reordering them to do occlusion, and calculating projected co-ordinates 
for perspective, and calculating colors for lighting. Hardware will 
speed this up, but only minor compared to the factor of thousands that 
hardware 3D projection will speed it up).

1. Support a 3x3 matrix for transformations. Transforming a point at 
x,y,w would be done by multiplying by this to get X,Y,W and then 
plotting on the screen at X/W, Y/W. The matrix can also be "normalized" 
so that the lower-right corner is always 1. This matrix can be directly 
loaded from 3D systems by ignoring the Z row and column from their 4x4 
matrix.

2. Lineto/moveto/etc would have new versions that take x,y,w 
coordinates. This is mostly so that curveto can do rational splines 
which support true conic sections (a free additional benifit to doing a 
3D system).

3. "stroke" produces undefined results if a perspective projection is in 
effect. This basically means that the bottom row is anything other than 
0,0,1. This avoids the need to perspective distort the pens and dashes, 
which is a useless (imho) effect anyway. Any other operations that cause 
trouble can also be said to have undefined results. The caller can push 
and pop the perspective transform around the path construction to get 
defined results.

4. If you are concerned about speed, keep flags around to indicate if 
any points in the current path have w != 1, and to indicate if the 
matrix has perspective transforms. If this is false then you can assumme 
W is 1 and ignore it.



More information about the cairo mailing list