Use matrixtransform in OSG to implement model translation, rotation, and scaling.

Source: Internet
Author: User

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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.