Difference between revisions of "Documentation/DevGuide/Drawings/Transforming"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (FINAL VERSION FOR L10N)
(Added Java syntax highlight)
(2 intermediate revisions by 2 users not shown)
Line 6: Line 6:
 
|PrevPage=Documentation/DevGuide/Drawings/Rotating and Shearing
 
|PrevPage=Documentation/DevGuide/Drawings/Rotating and Shearing
 
|NextPage=Documentation/DevGuide/Drawings/Ordering
 
|NextPage=Documentation/DevGuide/Drawings/Ordering
}}
+
}} {{Documentation/DevGuideLanguages|Documentation/DevGuide/Drawings/{{SUBPAGENAME}}}}  
{{Documentation/DevGuideLanguages|Documentation/DevGuide/Drawings/{{SUBPAGENAME}}}}  
+
 
 
  {{DISPLAYTITLE:Transforming}}
 
  {{DISPLAYTITLE:Transforming}}
Changing the size, rotation and shearing of an object can be done by using the transformation mechanism provided by {{PRODUCTNAME}}. The matrix of our API is a standard homogenous 3x3 matrix that may be used together with the java.awt.geom.AffineTransform class from Java. The transformation received describes the actual values of the transformations as a linear combination of the single matrices. The basic object without transformation has a size of (1, 1) and a position of (0, 0), and is not rotated or sheared. Thus, to transform an object get its matrix and multiply from the left side to influence the current appearance. To set the whole transformation directly, build a combined matrix of the single values mentioned above and apply it to the object.
 
<!--[SOURCE:Drawing/ObjectTransformationDemo.java]-->
 
  
 +
Changing the size, rotation and shearing of an object can be done by using the transformation mechanism provided by {{PRODUCTNAME}}. The matrix of our API is a standard homogenous 3x3 matrix that may be used together with the java.awt.geom.AffineTransform class from Java. The transformation received describes the actual values of the transformations as a linear combination of the single matrices. The basic object without transformation has a size of (1, 1) and a position of (0, 0), and is not rotated or sheared. Thus, to transform an object get its matrix and multiply from the left side to influence the current appearance. To set the whole transformation directly, build a combined matrix of the single values mentioned above and apply it to the object. <!--[SOURCE:Drawing/ObjectTransformationDemo.java]-->
 +
<source lang="java">
 
   XPropertySet xPropSet = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, xShape );
 
   XPropertySet xPropSet = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, xShape );
  // take the current tranformation matrix
+
// take the current tranformation matrix
  HomogenMatrix3 aHomogenMatrix3 = (HomogenMatrix3)xPropSet.getPropertyValue("Transformation");
+
HomogenMatrix3 aHomogenMatrix3 = (HomogenMatrix3)xPropSet.getPropertyValue("Transformation");
  java.awt.geom.AffineTransform aOriginalMatrix = new java.awt.geom.AffineTransform(aHomogenMatrix3.Line1.Column1, aHomogenMatrix3.Line2.Column1,
+
java.awt.geom.AffineTransform aOriginalMatrix =  
      aHomogenMatrix3.Line1.Column2, aHomogenMatrix3.Line2.Column2,
+
new java.awt.geom.AffineTransform(aHomogenMatrix3.Line1.Column1,  
      aHomogenMatrix3.Line1.Column3, aHomogenMatrix3.Line2.Column3 );
+
                                  aHomogenMatrix3.Line2.Column1,
  // rotate the object by 15 degrees
+
                                  aHomogenMatrix3.Line1.Column2,  
  AffineTransform aNewMatrix1 = new AffineTransform();
+
                                  aHomogenMatrix3.Line2.Column2,
  aNewMatrix1.setToRotation(Math.PI /180 * 15);
+
                                  aHomogenMatrix3.Line1.Column3,  
  aNewMatrix1.concatenate(aOriginalMatrix);
+
                                  aHomogenMatrix3.Line2.Column3 );
  // and translate the object by 2cm on the x-axis
+
// rotate the object by 15 degrees
  AffineTransform aNewMatrix2 = new AffineTransform();
+
AffineTransform aNewMatrix1 = new AffineTransform();
  aNewMatrix2.setToTranslation(2000, 0);
+
aNewMatrix1.setToRotation(Math.toRadians(15));
  aNewMatrix2.concatenate(aNewMatrix1);
+
aNewMatrix1.concatenate(aOriginalMatrix);
  double aFlatMatrix[] = new double[6];aNewMatrix2.getMatrix(aFlatMatrix);
+
// and translate the object by 2cm on the x-axis
  // convert the flatMatrix to our HomogenMatrix3 structure
+
AffineTransform aNewMatrix2 = new AffineTransform();
  aHomogenMatrix3.Line1.Column1 = aFlatMatrix[0];
+
aNewMatrix2.setToTranslation(2000, 0);
  aHomogenMatrix3.Line2.Column1 = aFlatMatrix[1];
+
aNewMatrix2.concatenate(aNewMatrix1);
  aHomogenMatrix3.Line1.Column2 = aFlatMatrix[2];
+
double aFlatMatrix[] = new double[6];aNewMatrix2.getMatrix(aFlatMatrix);
  aHomogenMatrix3.Line2.Column2 = aFlatMatrix[3];
+
// convert the flatMatrix to our HomogenMatrix3 structure
  aHomogenMatrix3.Line1.Column3 = aFlatMatrix[4];
+
aHomogenMatrix3.Line1.Column1 = aFlatMatrix[0];
  aHomogenMatrix3.Line2.Column3 = aFlatMatrix[5];
+
aHomogenMatrix3.Line2.Column1 = aFlatMatrix[1];
  xPropSet.setPropertyValue("Transformation", aHomogenMatrix3);
+
aHomogenMatrix3.Line1.Column2 = aFlatMatrix[2];
 +
aHomogenMatrix3.Line2.Column2 = aFlatMatrix[3];
 +
aHomogenMatrix3.Line1.Column3 = aFlatMatrix[4];
 +
aHomogenMatrix3.Line2.Column3 = aFlatMatrix[5];
 +
xPropSet.setPropertyValue("Transformation", aHomogenMatrix3);</source>
  
{{PDL1}}
+
{{PDL1}}  
  
[[Category:Documentation/Developer's Guide/Drawing Documents and Presentation Documents]]
+
[[Category:Documentation/Developer's_Guide/Drawing_Documents_and_Presentation_Documents]]

Revision as of 12:36, 13 January 2013




Changing the size, rotation and shearing of an object can be done by using the transformation mechanism provided by OpenOffice.org. The matrix of our API is a standard homogenous 3x3 matrix that may be used together with the java.awt.geom.AffineTransform class from Java. The transformation received describes the actual values of the transformations as a linear combination of the single matrices. The basic object without transformation has a size of (1, 1) and a position of (0, 0), and is not rotated or sheared. Thus, to transform an object get its matrix and multiply from the left side to influence the current appearance. To set the whole transformation directly, build a combined matrix of the single values mentioned above and apply it to the object.

  XPropertySet xPropSet = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, xShape );
 // take the current tranformation matrix
 HomogenMatrix3 aHomogenMatrix3 = (HomogenMatrix3)xPropSet.getPropertyValue("Transformation");
 java.awt.geom.AffineTransform aOriginalMatrix = 
 new java.awt.geom.AffineTransform(aHomogenMatrix3.Line1.Column1, 
                                  aHomogenMatrix3.Line2.Column1,
                                  aHomogenMatrix3.Line1.Column2, 
                                  aHomogenMatrix3.Line2.Column2,
                                  aHomogenMatrix3.Line1.Column3, 
                                  aHomogenMatrix3.Line2.Column3 );
 // rotate the object by 15 degrees
 AffineTransform aNewMatrix1 = new AffineTransform();
 aNewMatrix1.setToRotation(Math.toRadians(15));
 aNewMatrix1.concatenate(aOriginalMatrix);
 // and translate the object by 2cm on the x-axis
 AffineTransform aNewMatrix2 = new AffineTransform();
 aNewMatrix2.setToTranslation(2000, 0);
 aNewMatrix2.concatenate(aNewMatrix1);
 double aFlatMatrix[] = new double[6];aNewMatrix2.getMatrix(aFlatMatrix);
 // convert the flatMatrix to our HomogenMatrix3 structure
 aHomogenMatrix3.Line1.Column1 = aFlatMatrix[0];
 aHomogenMatrix3.Line2.Column1 = aFlatMatrix[1];
 aHomogenMatrix3.Line1.Column2 = aFlatMatrix[2];
 aHomogenMatrix3.Line2.Column2 = aFlatMatrix[3];
 aHomogenMatrix3.Line1.Column3 = aFlatMatrix[4];
 aHomogenMatrix3.Line2.Column3 = aFlatMatrix[5];
 xPropSet.setPropertyValue("Transformation", aHomogenMatrix3);
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages