Deactivate Cameramouse

39 views
Skip to first unread message

Dominik Scharnagl

unread,
Jun 9, 2022, 9:11:47 AM6/9/22
to Jzy3d
Hello, 

I am working on being able to pick and drag primitives across the screen in jzy3d. Everything works fine, but there is one problem I have. So I when I pick an object and then dragg the mouse around, the object moves as planed, but the camera moves at the same time, which makes controlling the movement of the primitive really hard.
Is there anyway to deactivate that the mouse drags the camera aswell and then activate it again after I moved the object to the new position? 

Sincerly,
Dominik

Martin Pernollet

unread,
Jun 15, 2022, 4:12:22 AM6/15/22
to jz...@googlegroups.com
Hi,

You probably have enabled the existing default mouse controller. All depend how you implemented the mouse controller grabbing objects.

If you added your own mouse controller, simply do not invoke chart.getMouse() to prevent the default camera mouse controller from being initialized. 

If you want to toggle between camera move and object drag (which I would do), then override the existing mouse controller to support your behaviour and then override de chart factory to let it initialize your own mouse controller. The selectable scatter demo from the Jzy3D guide is a good example for you since it shows how to create a mouse controller able to switch between two behaviour (camera move or scatter select) based on keyboard actions.

Hope this helps!

Martin

--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes "Jzy3d".
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse jzy3d+un...@googlegroups.com.
Cette discussion peut être lue sur le Web à l'adresse https://groups.google.com/d/msgid/jzy3d/3d046655-8122-4fa5-9149-78d8e1155416n%40googlegroups.com.

Dominik Scharnagl

unread,
Jun 21, 2022, 7:44:06 AM6/21/22
to Jzy3d
Hello,

thanks that works now, but that shows me another problem. I use the mouseDragged() function of my own mouse controller to move an object to the mouse position, when its dragged and I have an object picked.

Problem is that the calculation from the mouse position to the position on the chart sometimes gets me wrong numbers, which lets the moveing object jitter.
Sometimes I get random 0.0 or 1.1920929E-6 for my X Values or z=-0.06359947. Or just Random negative Values, which dont make sense. I calculte the position on the chart with the view.projectMouse() function, with a flipped y value.

And I dont know why that is. This bug only happens on drag sometimes. I implemented the calculation of the mouse position on the mouseClicked() to see if it works and that function allways gives me the correct answer.

Could it be, that the projectMouse function does not work right during dragging? If so are there any other ways to get the mouse position from the (x,y) values to a coord3d on the chart?

Sincerly,
Dominik

Martin Pernollet

unread,
Jun 21, 2022, 8:44:13 AM6/21/22
to jz...@googlegroups.com
Hi Dominik,

Great that you could go ahead!

I understand your problem but it is difficult to think of a solution without being able to reproduce it. Could you send a simple program to allow reproducing your problem, especially for the x,y values?

The z value you get depends on the window z value that was provided to gluUnProject. My implementation simply states that z=0 but this may not be true : it should actually be configured between the near and far clipping plane, which could be fixed. You can read about gluUnProject here to better understand.

A reproducible example can help me fix this.

Cheers,

Martin


Dominik Scharnagl

unread,
Jun 22, 2022, 8:09:11 AM6/22/22
to Jzy3d
Hello Martin,

I put my code from my mouse controller here and a video showing the bug and the output from my calculated position next to it.
If you need anything more just ask.

Sincerly,
Dominik
MousErrorCode.txt
2022-06-22 14-03-07.mp4

Martin Pernollet

unread,
Jun 22, 2022, 8:45:47 AM6/22/22
to jz...@googlegroups.com
Thank you, the video is really clear. 

I believe your controller is correct and that the error may stand inside the API.

Would it be possible for you to provide a complete standalone Java program with a main() function so that I can run it? Something similar to a tutorial example that prompts a complete scene configured with your mouse controller. I don't need the pom file and complete packaging, just a single java file.

Cheers,

Martin


Dominik Scharnagl

unread,
Jun 22, 2022, 9:26:01 AM6/22/22
to Jzy3d
Hello,

the single java file is here. I hope it helps.

Sincerly,
Dominik
TestClass.java

Martin Pernollet

unread,
Jun 23, 2022, 3:46:34 PM6/23/22
to jz...@googlegroups.com
Hi,

I modified your program to use AWT since Newt is lagging on my macOS. I needed to fix something on the AWT mouse controller so I pushed the updated sources and just deployed the jar (2.1.1-SNAPSHOT), which should let you run my modifications without trouble.

I got something a bit better by changing the Z value of the screen coordinates. Using value 1 instead of 0 let me move the green sphere correctly, however 
- jitter appears after moving other spheres
- sometime the sphere is not exactly under mouse (while sometime it is)

I modified the sample to show you how to define this Z value by yourself. To choose how to configure it, gluUnProject documentation may help. It should be between 0 and 1, 0 being the near clipping plane of the camera, 1 being the far clipping plane. I tried to get the "screen Z value" of the picked sphere to set it but it did not help. Here's what the doc says
You did a couple of things right 
- Not squaring the scene to avoid transforms that may lead to erroneous projection
- Disabling HiDPI to avoid multiplying mouse coordinates with pixel ratio

So for now I don't have other ideas to help you. Let me know if you find a solution, I'll tell you if I get something better.

Martin

TestClassAWT.java

Dominik Scharnagl

unread,
Jun 24, 2022, 6:10:16 AM6/24/22
to Jzy3d
Hi,

thanks for trying and for the tipp at least. I will try if I can find a way to fix it. If I do I will answer here again.

Still thanks for the help,

Dominik

Martin Pernollet

unread,
Jun 24, 2022, 6:34:22 AM6/24/22
to jz...@googlegroups.com
You are welcome.

Two things coming to my mind that may help : 
  • the modelToScreen and screenToModel method are most likely not culprits : they are used a lot for text layout which works correctly (e.g. see TextRenderer class).
  • the shift between the mouse position and the sphere seams related to the axis. The shift is often either equal to axis height, or equal to the distance between axis and canvas border.


Reply all
Reply to author
Forward
0 new messages