5.0

5.0 | 1 rating Rate this file 41 downloads (last 30 days) File Size: 2.24 KB File ID: #19760

Arcball like 3D figure rotation

by Andrea Tagliasacchi

 

29 Apr 2008 (Updated 13 May 2008)

Code covered by BSD License  

Example that shows how to add arcball control to a 3D window

Download Now | Watch this File

File Information
Description

One of the major drawbacks of matlab is the lack of a way of changing the viewpoint of a 3D mesh using a natural (arcball) interaction.

In this simple function I demonstrate the arcball interaction allowing a 3D sphere to be moved naturally. Run the function and drag and drop with your mouse on the sphere surface.

A very important aspect that you should note is that I am rotating the ACTUAL 3D object instead of the viewpoint.

There is a specific reason for this choice. The OpenGL lighting is linked to the axis in matlab, thus, if you rotate the veiwpoint, the lighting on the mesh surface wouldn't change. On the other hand, if you rotate your object using hgttransoforms you achieve this result.

It is now apparently bug-free :)

MATLAB release MATLAB 7.6 (R2008a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
30 Apr 2008 Noone U. Noh

The cause of your "bug" is likely that at each step you rotate the object that was rotated in the last step. Each rotation introduces a little bit of round-off errors that are being magnified by doing it a zillion times. Instead, you should always make the rotations with respect to the original (unrotated) object.

12 May 2008 Noone U. Noh2

Actually that is not true. If you check, the rotation is applied to the model which is "saved" in M_previous in the moment the first mouse click take place. That doesn't change anymore during dragging.

12 May 2008 Andrea Tagliasacchi

Thanks for the observation anyway. I took a look at the code again and even though Noh2 observation was correct, there was a similar bug. The "rotation direction" was embedded in model space using the inverse of the current rotation matrix (taken from graphic context) and not the one of the original model.

I will upload the final version.
There was also a vector normalization missing that might have caused other issues.

13 Sep 2008 P G

The sphere example proposed in the code does not work with Matlab 7.0.0.19920 (R14) and 7.0.4.352 (R14). There may be a problem between surf objects and hgtransform. It works properly with mesh and surface objects. Great work, thanks.

Please login to add a comment or rating.
Updates
13 May 2008

Corrected a bug in the rotation direction update which caused the "bug".

Now it works nicely.

Tag Activity for this File
Tag Applied By Date/Time
gui tools Andrea Tagliasacchi 22 Oct 2008 09:59:35
example Andrea Tagliasacchi 22 Oct 2008 09:59:35
arcball Andrea Tagliasacchi 22 Oct 2008 09:59:35
3d Andrea Tagliasacchi 22 Oct 2008 09:59:35
rotate Andrea Tagliasacchi 22 Oct 2008 09:59:35
viewpoint Andrea Tagliasacchi 22 Oct 2008 09:59:35
mesh Andrea Tagliasacchi 22 Oct 2008 09:59:35
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com