LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

3d picture zooming and rotating using the model view matrix

Can anyone help with this weird behavior I'm seeing:
I'm trying to make a 3d picture where the user can rotate the view around and zoom in and out.  The picture is a spherical Earth, with cylindrical objects represiting the earths axis. 
What happens is this:
when I first load the scene, all objects populate correctly and the user can rotate the camera around the earth.  There is no zoom control that I know of, so to adjust the zoom, I multiply the last column of the model view matrix (except the last row) by a scale factor.  This initally works and I can zoom in and out using this.  However once I update the model view matrix, as soon I attempt to rotate the camera, the camera jumps.  Specifically it jumps to looking down at the axis comming out of the north pole (no mater where I had the camera just before the update).
 
More detail:  I made it so that I could copy the current model view matrix to a temp, then another control to write from the temp.  In this way I was able to "update" the matrix with the same values currently in it.  When I do this then rotate the camera, the same thing happens.  I noticed that if I start the camera at the equator, and rotate strictly along the equator the last column doesn't change much (order of 10^-8).  When along the equator the last column is approx [0 0 4 1] (at my current zoom).  It stays this way as much as I move the camera.  But if I update the model view matrix (even if I just copy the current values to it), then move the camera just a hair, it jumps to the north pole and the last column approxmats [0 4 0 1].  Further, adjust the zoom so that I write [0 0 2 1], and move it, it becomes [0 2 0 1].  Then if I move it as if rotating around the equator and copy element 2 to 3 and 3 to 2, it comes up as if I just rotated it normally.
 
First: inital set up
Second: rotate camera
Third: copy current model view matrix to model view matrix
Fourth: attemp to move camera just a hair
Fifth: in the last column of the matrix - copy [1] to [2] and [2] to [1].  Notice this is nearly identical to the third view.
0 Kudos
Message 1 of 6
(7,011 Views)
I assume that you are using the built in camera controllers and that you are writing the model view matrix on the control. 
 
I think that our current implementation doesn't handle that very well.  Internally, we hold on to a few states in order to implement the camera controllers... notably
 
An eyepoint (where the camera is)
A zoom factor (this is how far you are from the pivot (in the case of the spherical camera controller).
 
These properties can get messed up when you write the model view matrix of the scene graph.. Specifically, as currently implemented,  the eyepoint gets set such that it is the current translation of the matrix and the zoom factor is set to 0 (so you are sitting right on top of the pivot)
 
Is it possible then, that you are just rotating your scene out of bounds?
 
I think it is probable. 
 
What I would try to do instead of writing the model view matrix directly, is to use the SetupCamera method instead.
 
This method allows you to set the camera's position, the pivot and what orientation you want to be in.
 
Jeff Peters
LabVIEW R & D
 
 
 
 
 
 
0 Kudos
Message 2 of 6
(7,005 Views)

Thanks for the help...I can't just use the setup camera because I need to be able to zoom in and out from where ever the user may have rotated the camera to.  So unless their is some way to read the current camera settings, which I have not found - the method only allows a write to.  I suppose I could compute those values from the model view matrix, but I don't know enough about what those numbers actually mean.

It is not possible that I simply rotated it out of bounds.  The camera moves from the equator latitude to looking down on the north pole when I just move it a hair.  Note that in the pictures the model view matrix is the same for pictures 2 and 3.  For picture 4 I just clicked and moved it a couple of pixels at most.  Also note that to get the last picture I just swapped model view matrix elements [1,3] and [2,3].  It appears that after the model view matrix is written to, you can no longer move the camera with the mouse controls properly.

0 Kudos
Message 3 of 6
(6,994 Views)
Hi Tiemanj,

@tiemanj wrote:

There is no zoom control that I know of...

If you are using the built in "Flying" or "Spherical" camera controller, you can control the zoom level by holding <Shift> and dragging within the display.  You can change the pivot point by holding <Ctrl> and dragging within the display.  This would let your users move the camera to any rotation or zoom level intuitively by only interacting with the display.  It would also avoid interacting with the model matrix directly, which appears to be the cause of this discontinuity. 

Hope this helps!

Cheers,
Spex
National Instruments

To the pessimist, the glass is half empty; to the optimist, the glass is half full; to the engineer, the glass is twice as big as it needs to be has a 2x safety factor...
0 Kudos
Message 4 of 6
(6,957 Views)
I have done some work with the 3D Picture control recently, including manipulation of the ModelView Matrix property, and also invoking the Camera Setup method of the control.
.  It has required a fair amount of trial and error since there isn't much documentation on how these work (I gained most of my insight from the web since it is OpenGL).

I have attached a jpg of one VI that I have developed that I use to set the Camera parameters based on a couple of user inputs.  In this case, I am moving the camera in unison with one object so that it is easier to observe the relative movement of other objects.  Also, X is up, Y is right and Z is forward (and you can use Z for zooming).  It is possible to rotate the Camera
 around the "fixed" object around the Y axis.  The Z offset controls how far away the camera is from the fixed object, (and hence the size of the image = zoom).  It makes use of calculating the Rotational matrices and then a direction cosine matrix.

As for manipulating the ModelView Matrix, I think as you have discovered, it is important to first read it and then only change the part you need to change.  In the case of rotation, the top-left 3x3 matrix is changed, set to the appropriate Direction Cosine matrix.  In the case of translation, set the appropriate value in the top 3 values (X,Y,Z) of the 4th (right) column.  The ModelView Matrix is a little different in terms of XYZ - Z is always into the screen, X is right and Y is up.  Setting the Z value should give you a zoom (of course it depends on where exactly the camera is pointing.

Message Edited by pauldavey on 11-16-2006 05:55 PM

0 Kudos
Message 5 of 6
(6,945 Views)

i know this thread belongs to sometime ago, but i have the same problem now. i need to mark some points on 3d object, and then i need to zoom any arbitary point, i try to use the model view matrix, but i need to redraw my object again and i have no idea how i can update the scene again, after i change my modelview matrix.

Also, i tried to use the  setup camera method, but the same problem , i cant read the current position of camera!!!!!!

 

so, is there any sample VI, or any idea that can help me? i'm looking forward. 

0 Kudos
Message 6 of 6
(6,156 Views)