[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.gef3d] Re: Draw3d Program

Madhu,

On 2009-03-24 17:16:08 +0100, madhu.samuel@xxxxxxxxxxxx (Madhu Samuel) said:
Can you please provide a simple draw3d program, say a program which displays a cube in the 3d space. This would help to understand the concept of how a draw3d program works?

In Draw2d we have layouts to keep the child IFigure objects. In Draw3d how are the Figure3d objects placed?

Draw3D works exactly the same way Draw2D does. As in Draw2D, figures can be placed directly or using a layout (preferred, but not used in the GEF3D examples yet).


How is a 3D figure placed? There is a method IFigure3D.getPosition3D(). You can call the setters of Position3D in order to place a figure in 3D. Actually, you can place a 3D figure using setBounds() (or setSize() or setLocation(), but you can only set the x and y positions then, of course (since you can use these 2D methods, it actually is possible to use a 2D layout in order to arrange 3D figures).

It is recommended using a LayoutManager, and LayoutManagers are working exactly as they do in Draw2D. Unfortunately, we haven't implemented any LayoutManagers yet, since we are placing the figures directly (shame on us ;-) ). There is an XYZLayoutManager, but is isn't implemented yet. So you'll have to write a LayoutManager yourself.

OK, there is one layout manager ready: The SurfaceLayout. It is used in GraphFigure3D (in the example). It is not a "complete" layout manager, but it can be "added" to an existing layout manager. What it does is pretty simple: It sets the z coordinate of a figure in order to place a 3D child on top of the surface of its parent. Why is that necessary? In Draw3D, the x- and y-axis are oriented just as in 2D. The origin is on the top-left, the x-axis is oriented from left to right and the y-axis from top to bottom. Well, in 3D you can look around with a camera, but forget about that for the moment. In most 3D systems, the coordinate systems is oriented differently, that is the origin is at the bottom-left corner of the screen, and the y-axis points upwards. In order to make the coordinate system of the 3D system similar to the 2D one, we flipped the system (that is we rotated it around the x-axis). Are you familiar with coordinate systems and 3D? It's not that complicated. Simply use your right hand (see http://en.wikipedia.org/wiki/Right-handed_coordinate_system ). Now, "rotate" your hand until your thumb looks to the right (the x-axis) and your forefinger downwards (the y-axis) (Warning: I'm not liable for any injuries ;-) ). This is the coordinate system of Draw3D (I hope you can recognize my ASCII art):

+------> X
|\
| \
|  \
v   _|
Y    Z

As you will notice, the middle finger (the z-axis) is looking backward (at you). This is true for Draw3D, too. This has consequences for placing figures in 3D: In order to place a figure with depth=50 on a surface (for example the x-y-plane), it has to be placed at z=-50. The SurfaceLayout does that for you. The surface layout certainly is only useable for 3D children, since 2D children are always "placed" on the surface of their 3D parent.

Of course, Draw3D is not limited to the SurfaceLayout, as the interface Position3D suggests you can rotate and place 3D figures everywhere you want. The MultiEditorModelContainerFigure places their children on top of each other, again we are not using a layout here, and we have to fix this. (Our examples are quick and dirty hacks for testing the functionality. So we didn't used any layout since it is easier to follow the effect of placing a figure without it...)

Cheers

Jens