Matrixtransform is inherited from transform-group, so you can mount a Node object under it.
Sets its matrix to implement model transformation for its subnodes.
-- Use the local coordinate system for understanding (the local coordinate system is also called the inertial coordinate system, and its relative position with the model remains unchanged during the transformation process)
The following code:
// Create a Cylindrical Double R = 0.5; double H = 3.0; OSG: vec3 orginpt (0.0, 0.0, 0.0); OSG: ref_ptr <OSG :: geode> cylindergeode = new OSG: geode; OSG: ref_ptr <OSG: cylinder> geocylinder = new OSG: cylinder (orginpt, R, H); OSG :: ref_ptr <OSG: shapedrawable> cylinderdrawable = new OSG: shapedrawable (geocylinder. get (); cylinderdrawable-> setcolor (OSG: vec4 (1.0f, 0.0f, 0.0f, 1.0f); cylindergeode-> adddrawable (cylinderdrawable. get (); // -- the following operations are for the local coordinate system -- // first translate the cylinder (20.0,-12.0,-35.0) // then rotate the Z axis to vector N. At this time, the Z axis of the local coordinate system is consistent with that of the n vector. // then, translate the rotated model to 0.5 x H length in z direction (global coordinate system, equivalent to 0.5 x H length in N direction) // At last, enlarge the model to 2 times OSG :: vec3 N (1.0, 1.0,-1.0); OSG: vec3 Z (0.0, 0.0, 1.0); N. normalize (); OSG: ref_ptr <OSG: matrixtransform> Mt = new OSG: matrixtransform; MT-> setmatrix (OSG: matrix: Scale (OSG :: vec3 (2.0, 2.0, 2.0) * OSG: matrix: translate (OSG: vec3 (0, 0, 0.5 * H) * OSG: matrix :: rotate (z, n) * OSG: matrix: translate (OSG: vec3 (20.0,-12.0,-35.0); MT-> addchild (cylindergeode );
Based on the above features, you can calculate the three-dimensional coordinates of the changed model.
(Matrixtransform A contains matrixtransform B, and matrixtransform B contains a Model)
Then, the new coordinates of the Model(X, y, z) = (x, y, z) * B. matrix * A. matrix;