Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added symmetric trackball controls #6096

Closed
wants to merge 1 commit into from

Conversation

daron1337
Copy link
Contributor

I was searching for threejs controls similar to vtk/paraview visualization software.
Using TrackballControls.js, if I click on the canvas in the center and I move the mouse along the y axis the camera rotates as expected. If I click on the canvas in a point which is distant from the center ( example on the right side of the cube ), the camera rotates in two directions and not only following my mouse movement.
See: http://jsfiddle.net/ugxbktLt/5/
I was expecting that the camera rotates following only the vector between the start point ( mousedown ) and end point generated by mouse movement and NOT considering the position of the start point.The simulated trackball is in the center of the canvas.

With SymmetricTrackballControls.js we can rotate camera independently from the position of the mouse on the canvas but considering only the mouse movement.

See:
http://stackoverflow.com/questions/28560130/threejs-trackball-controls-camera-rotation

@WestLangley
Copy link
Collaborator

Thanks for this contribution. I have a few comments:

  1. This is a 95% copy and paste of TrackballControls.js. Perhaps we can find a better solution... : - )
  2. In any event, I actually like the behavior of this approach better. Would you mind linking to "before and after" live examples so others can easily compare?
  3. Your approach is dependent on the aspect ratio of the canvas. So a diagonal mouse-drag will yield a very different response if the aspect ratio is 5 vs 1/5. I would use screen.height only in your calculation.
  4. What features did you remove, and why?

@mrdoob
Copy link
Owner

mrdoob commented Feb 18, 2015

In any event, I actually like the behavior of this approach better. Would you mind linking to "before and after" live examples so others can easily compare?

Agreed! I prefer this behaviour too!

@daron1337
Copy link
Contributor Author

Thank you guys. I did this because since I worked in the past a lot with vtk/paraview I noticed that the way TrackballControls apply rotation is not suitable for camera controls in image-based modeling application.

  1. Yes I modified TrackballControls replacing the mouseProjectionOnBall function with a 2D projection on a circle and then we reimplemented the rotate camera function. Since zoom and pan were fine, I did not touch them. Why rewrite everything if something already exists and it works? If it is a problem to re-use existing code, I can try to rewrite everything from scratch but imho it is not useful. Suggestions?
  2. Yes of course.
  3. Thank you, my mistake, I will fix it asap.
  4. As I said I changed the rotate behavior trying to replicate vtk camera rotation style. That's why the rotation is static and the dynamic dumping factor applies only for zoom/pan

@WestLangley
Copy link
Collaborator

Would you be willing to modify the existing TrackballControls with your changes? -- without removing the staticMoving property?

@daron1337
Copy link
Contributor Author

Yes, of course.
I think the best solution is to add to TrackballControls a new feature ( cylindricalRotation ) which enables the rotation independently from the position of the mouse on the canvas but considering only the mouse movement. I will set it to true by default.
Then I will add staticMoving also for the cylindricalRotation.

@crobi
Copy link
Contributor

crobi commented Feb 19, 2015

How do you rotate the scene around the view axis with this approach?

With the old trackball, you click and drag the mouse along a big circle (one that touches the canvas at all four borders), giving you a pure rotation around the viewing axis (assuming you perfectly follow that virtual circle). With this new trackball, I would assume that you need to perform two or three separate mouse drags?

By the way: if you're going to use a cube object for the example, how about uniquely coloring or texturing (e.g., like dice) its sides? That would make it easier to understand the rotation.

@daron1337
Copy link
Contributor Author

Your observation is correct, you need to perform two or three different mouse drags. As I explained before this is a different approach. Better? It depends what do you need. For my purpose, it is better.
I will update the TrackballControls with a new variable in order to be able to switch from cylindricalRotation to sphericRotation ( the old one ) and I will update the existing example with a key bind (R) for switching between modalities.

@daron1337
Copy link
Contributor Author

Since, as suggested, I updated existing TrackballControls by adding a new feature ( cylindricalRotation ) instead of creating a separated control library as in this pull request, I close this and I will resubmit a new pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants