FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Topics & Contributions
   Responsive Form, Games
(Moderator: REAS)
   Another example of translating mouse coords to 3d.
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: Another example of translating mouse coords to 3d.  (Read 2523 times)
jsg


Another example of translating mouse coords to 3d.
« on: Nov 25th, 2004, 12:14am »

Hi all,
 
I've been working on a 3d path editor as part of a larger project, and for awhile I was having a lot of trouble getting points to drag around correctly in 3d as moved by the mouse.
 
There were a few posts on this topic, most notably the (hugely helpful) pitaru/fry discussion here:
 
http://processing.org/discourse/yabb/board_Contribution_Respons_ive_action_display_num_1045181982.html  
 
but unfortunately the provided links don't work anymore. So, here's a link to my applet, in the hopes that the source may prove useful.
 
http://www.andrew.cmu.edu/user/jgarrets/cubedemo
 
The basic idea is as fry described it: Rather than moving the camera around, move the world around. This makes mouse editing of points easy, since the camera is always looking down the z-axis. The specific way it's implemented here is:
 
1. When the mouse is clicked and dragged in the world, rotation is applied in loop() before anything is drawn. The rotation angle is changed by the magnitude of the mouse movement.
 
2. When the mouse is released, the world spins to the angle of the current rotation, and the rotation is reset to zero. In this way, when the mouse is released, the viewpoint realigns to the z-axis and the world is transformed. To the user, it looks like nothing's changed.
 
3. Specific points stay under the mouse now by simply applying (mouseX-pmouseX) and (mouseY-pmouseY) to the points' locations, scaled by the ratio of the point's distance away from the screen. This last bit is done because the view has a certain perspective projection to it (it isn't orthogonal).
 
The code is something of a disaster (I went through and commented it up just now), but hopefully the idea is clear.
 
flight404

WWW Email
Re: Another example of translating mouse coords to
« Reply #1 on: Dec 13th, 2004, 11:14pm »

Did you pull your example?  Id like to gander at it.
 
r
 
Pages: 1 

« Previous topic | Next topic »