There is a subtle difference here between 2D and 3D.  In conventional Java
applications the objects are layered on the screen.  On a mouse click the VM
looks for the object beneath the cursor in the topmost view layer and sees if
it has a listener attached.  It is oblivious to anything in lower layers.  In a
3D scene, the objects 'exist' in a world with depth information, a world where
the preception of the object is a function of your view point and other
environmental parameters.  When you click your mouse, how does the system know
what the perceived line of sight is from the cursor?  You can easily have
multiple active objects along the same line of sight, so which is activated by
the click?  You talk of clicking on the face of a cube, but what about the
backside of the cube?  It too would need an action listener  if it is to
respond while facing forward, but that listener is still active when facing
backwards.  A bigger problem would be trying to have a simple mouse listener
control an orbit behavior.  How do you define the center of the orbit, and what
happens when the viewpoint changes.  If the object with the 'orbit listener'
attached is in a distant, nearly invisible, background corner, it is still
active so a mouse move would suddenly slew the view around that object and
dramatically alter your view.  I have often looked for simple listeners like
that, but every time I do I can come up with scenarios where it would provide
the wrong answer.
    Java 3D attempts to deal with the problem with the use of behaviors.
Behaviors bascally come in two parts.  The first is essentially a listener
(wake up criterion) that tells the behavior when it is time to become active.
One of those listeners is AWTEvent so you could respond to mouse clicks, etc.
Others are more complex and ease the problem of dealing with interactions
between 3D objects.  The second major part of the behaviors is the complex
actions of how to manipulate 3D objects or viewpoint.  Behaviors can greatly
ease  this often used and tedious task.  Even a 'simple' orbit requires a
rotation of the view point about the orbit point (which is effectively
translated from the origin) followed by a rotation of the line of sight to look
back towards the orbit point.  Note though, that behaviors generally do not act
on the objects themselves, but on the transfrom groups which which manipulate
how the user perceives the object.
   There is nothing stopping you from taking AWT events and manipulating screen
objects with your own code.  For simple scenes where you maintain strict
control of the viewpoint and the objects within the scene, this  works fine and
will probably be easier and faster than Java3D.  As more objects get
introduced, as they begin to move relative to each other, or the user gets more
freedom to move around the scene, managing your events becomes much more
difficult.  I would suggest that you bite the bullet now and learn how to use
behaviors.
        - Gary Graf


Tomas Normark wrote:

> I want to implement interactions with a live scene graph such
> as selecting faces on an object or orbiting around and zooming
> in on it. The easy way to do this seems to be to register
> mouselisteners on the canvas3d and have them make appropriate
> updates to the scene graph.
>
> When I look at the Sun utility classes such as OrbitBehavior I
> see that they use behaviors for this purpose. What can be
> gained from using behaviors instead of simple mouselisteners
> on the canvas3d. Behaviors seem a bit more complicated to deal
> with, so I would like to avoid them if they don't give any
> benifit compared to ordinary mouselisteners.
>
> /Tomas
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff JAVA3D-INTEREST".  For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to