Thursday, July 9, 2009

Transformations added

Devast added transformations to NaroCAD. Kudos from me!

Here are his struggles doing it:

After struggling with naro and occ for a week, seem i finally have managed simple transformations. Now there are 4 options which can be used: pivot point (center), translation, rotation and scale. Pivot point is used for rotation and scaling, so these two operations are always done around pivot. Translation is plain simple, just apply translation to the shape. Rotation is stored as 3 euler angles, not very handy ofcourse, but acceptable for manual control. And finally scaling is stored as 3 values, one for each axis, thus allowing non-uniform scaling.

Overall design (which was developed on the second attempt) is very simple. There is transformation (gp_GTrsf) that is applied to the shape. Every time a new transformation should be applied, old transformation is unapplied (i.e. applied inverted). For example we have current transformation tr1 and we want to add some rotation. Delta rotation is computed (that is difference between new and old euler angles, example: current is 45, new is 100, than delta will be 55 degrees). So to apply rotation we create new gp_GTrsf wich rotates around the pivot using delta rotation, define tr2 transformation as tr2 = tr1.Multiply(rotate_delta), then to make change we use BRepBuilderAPI_GTransform to apply tr1.Inverted followed by tr2 (same delta logic is also used for translation and scaling).

Now looking forward to find bugs!

No comments: