View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Arcball like 3D figure rotation

5.0 | 2 ratings Rate this file 4 Downloads (last 30 days) File Size: 2.24 KB File ID: #19760 Version: 1.0
image thumbnail

Arcball like 3D figure rotation



29 Apr 2008 (Updated )

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

| Watch this File

File Information

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   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (14)
19 Sep 2011 Sandor Toth

Thanks, this is a really great code!

Comment only
02 Jun 2010 Andrea Tagliasacchi

I never tried to do something like this but I am slightly curious to see it... I might end up doing it for fun sooner or later... If I do, I will let you know

Comment only
01 Jun 2010 p

p (view profile)

i need help with something.

i need to create a kind of arcball using images in matlab.
i have images of an object. and i should create a 3D object that the user can spin and see the images like a 3D model. i tried to use the regular arcball, and show my images, but it did'nt work out.

do you have an idea, please?

Comment only
23 May 2010 Andrea Tagliasacchi

standard "view" command. But I never liked it, it's very un-natural way of interaction.

Comment only
23 May 2010 p

p (view profile)

how can i rotate according the viewpoint, and move the camera, and not the object?

Comment only
17 May 2010 p

p (view profile)

this way i can show more than one image, because you can see few sidelocks at the same view. and i want to create a kind of movie between the views on a object, and create an arcball for object with my images...

Comment only
13 May 2010 Andrea Tagliasacchi

See the script. You will have the call to patch() with the sphere with a rectangle and then texture map it.

Comment only
13 May 2010 p

p (view profile)

but How can I add features that that the arcball have, like move according to a mouse input

Comment only
12 May 2010 Andrea Tagliasacchi

With images? you mean rotate an image in 3D? I guess you can just use a simple rectangular mesh (as a Patch object) and texture map it....

Comment only
12 May 2010 p

p (view profile)

nice work.
do you know how to create an arcball in matlab with images?
i mean that i wan't to create kind of mesh that have the images as vertexs.
tnx :)

13 Sep 2008 P G

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

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.

Comment only
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.

Comment only
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.

Comment only

Contact us