Example Code

Rotate 3D object relative to its current rotation

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview

This example demonstrates rotating an object in a 3D Picture Control.


Description

If you want to rotate an object in a 3D Picture Control relative to its current rotation, you can't just use Rotate Object.vi or Set Rotation.vi alone. You need to transform the axis you want to rotate along into the current rotation of the object. In order to do this you need to multiply a rotation matrix based on the current rotation of the object by the axis you want to rotate along. Then you can use Rotate Object.vi to rotate the object.


Requirements

LabVIEW 2012 (or compatible)


Steps to Implement or Execute Code

Download both VIs (one is a subVI).

Run Rotate 3D object LV2012 NIVerified.vi.


Additional Information or References:

 

Rotate 3D object relative to its current rotation FP.png

 

The first step in rotating an object relative to its current rotation is to use the Get Rotation.vi.  This VI returns an axis and the angle that the object is rotated along that axis.  Then we generate a rotation matrix using these two pieces of information.  This matrix is then multiplied using matrix multiplication with the axis we want to now rotate the object along.  This will return a new axis which is relative to the current rotation of the object.  Then we can use the Rotate 3D object LV2012 NIVerified.vi to rotate along this axis by the angle desired.

 

This is the overall example program which responds to user input and changes the rotation based on that.

Rotate 3D object relative to its current rotation BD.png

 

This VI builds the rotation matrix from the object's current rotation and rotates for the desired angles.

SubVI block diagram.png

 


Notes

I put the generation of the rotation matrix and multiplication of the rotation matrix into a sub VI to make the code cleaner and not reproduce the same logic in each case of the event structure.


**This document has been updated to meet the current required format for the NI Code Exchange.**

Jared S.
Applications Engineering
National Instruments

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
Manukun
Member
Member
on

Hi,

it is possible to determine yaw, pitch and roll from there "get rotation"? Thanks in advance.

Best regards.

pauldavey
Active Participant
Active Participant
on

If you wanted to simplify the code a lot, you could retrieve the SceneObject's Transformation matrix, which is a 4x4 Matrix, and post-multiply it with the Homogenous version of the required new Rotation Matrix (so essentially you would not require your formula node).  The Homogenous version of the Rotation Matrix is simply adding an extra row and column of zeroes, with the bottom right corner being set to 1.