How to zoom with keyboard?

Ok, so I want to implement my zoom feature, but I want it to be keyboard-driven. Just because. :slight_smile:

So, I’m looking through the tutorials, and I see how to zoom with the mouse, but that’s a built-in behavior, and I can’t see the source code. And I don’t want to do it that way.

So then I look some more and I see how to get the ViewPlatform transfrom object from the SimpleUniverse, but then they use another pre-built behavior, with the keyboard, but not the way I want it.

Clearly, I want to create my own Behavior from scratch. So, then I look around and find the javadoc for the Transform3D class, and I see methods for rotation. But most of the other methods don’t make much sense to me.

So, two questions:

  1. Is there a tutorial/faq/example out there that will help me better understand the many methods of the Transform3D class?

  2. If I just want to move the viewer closer to/farther away from my object, I think that’s along the Z axis. So, how do I just add to or subtract from the Z-coordinate of the viewing platform? Not rotating, just moving in a straight line?

Thanks in advance for your help to an annoying newbie,
Kit

The 3 main operations on Transform3D matrix are:

  • translations
  • rotations
  • scaling
    Many of the methods are used to set or get these components of the matrix. All the get/set methods are there to get or modify a component.

There are of course other methods which have more specific use, but you don’t really need to know them.

A very usefull (and more specific) method you could use is: ‘lookAt(Point3d eye, Point3d center, Vector3d up)’

Here is an example (i hope i don’t make any mistake…):


TransformGroup viewTransform myUniverse.getViewingPlatform().getViewPlatformTransform();
Transform3D newView = new Transform3D();
newView.lookAt (new Vector3d(0,0,z), new Vector3d(0,0,0), new Vector3d(0,1,0));
newView.invert();
viewTransform.setTransform(newView);

I think this should work. (can’t test it here!)

cheers

Ok, it seems that what I really need is a good tutorial of how 4x4 matrix math relates to 3D coordinate space. Presumably the Java3D stuff is just their own version of some universal mathematical truths.

– Off to find elightenment –

  • Kit

PS - Should I understand this one day, I’ll let you know. :wink:

You can dig this math subject if you want but it won’t help you to program!
Make this for pleasure of learning but not if you wanna know how to program. Java’s transform3D functionality is already optimal.
Learn how to use it’s methods if you wanna program, look for matrix algebra if you wanna learn maths :wink:

The world of math is so impressive… It’s really amazing.

Well, I like math as much as the next guy, but I’d rather not learn it in-depth for the few functions I want my app to do. This is not a generalized 3D world; it’s just a few objects that I want to be able to rotate and zoom in on.

My problem is that to do a zoom-in action, for instance, I have to create the correct matrix, and I don’t know how to go about it. I can’t seem to find any tutorials that say something like:

“You are looking at object X. To zoom closer to it, create a Transform3D object using matrix (a,b,c) and multiply it times blahblahblah …”

I tried your example, and it wants points instead of vectors.

The Javadoc for the Transform3D class seems to assume an understanding of matrix transformation math. So, with no decent tutorials/explanations (that I can find), my next step would seem to be to learn the math. Which is fine, it just slows me down, and this is only a tiny part of my project.

I really appreciate your input, though, and I’m sure that at some point it will just “click”. Hopefuly it will be without my having to become an expert in homogenous coordinates and projective geometry.

  • Kit

of course, understanding the world of matrix won’t harm. Learning about it takes time, but once you know, you know how it works “under the hood” (which is sometimes usefull)…

And about the:
“You are looking at object X. To zoom closer to it, create a Transform3D object using matrix (a,b,c) and multiply it times blahblahblah …”

There are many ways to achieve this.

  1. You could change the scale of the main transformGroup.
  2. You could move the main transformGroup nearer to the eye viewpoint.
  3. You could change the eye’s “resizing” factor.
  4. You could move the eye viewpoint nearer to the object. (That’s what my first solution proposal was, because i find it’s the most nicest & natural way to do it)
  5. and many others…

There is not one universal solution!

And about the ‘lookAt’: yes, it’s Point3d and no vectors, sorry. (If you’ve replaced the vectors with points, doesn’t it work?)

good luck with math!

Just remember that if you are using the “lookat” function with the ViewPlatform you will need to invert it. That really threw me for a while.

And remember that “zooming” usually doesn’t mean to move the camera closer to object (or vice versa) but to decrease the FOV (while the distance between camera and the object stays the same).