Center pointerlockcontrols on the mouse curosr - three.js

The problem
As the cursor locks, the cursor is set to the position of the screen where i clicked. But i would like to have my cursor centered to the screen. As that is not possible for security reasons, the only available option is to move the camera(maybe with lookAt) towards the cursor position.
In my example i would like that when the cursor is locked that the little gray square in the center of the screen provokes a hover. This meaning that the cursor is exactly in the center of my camera.
The reason i want to achieve this is because i would like my clicks to be performed from the center of the screen, if i for instance want to trigger the onclick of a 3D object in front of the camera.
I would like to know if it is possible to do so with the pointerlockcontrols and if yes, how could one proceed ?
What i have so far
At the time i've just tried the basic implementation of pointerlockcontrols but can't figure out the way to put the cursor in the desired position.
Unfortunately pointerlockcontrols does not work on my codesandbox example.
The code sandbox that unfortunately does not work
Thanks in advance for your help.

Found my answer here :
Screen centered pointer lock controls
the trick is just to move the raycast to the center of the screen.

Related

animation of an object wont center

hi guys i recently start experimenting lots of thing using points to make a particle effect and one of it try to create is a space wrap animation, the animation is correctly display but the position of the effect it wont center, it always goes in right or left i try to change the camera type and the position of the canvas camera it seems it dosen't help at all i think am missing something. can anyone help me to figure this out.
here is my code thanks
https://codesandbox.io/s/spacewrap-l82e3s?file=/src/App.js:0-1784

Panning in React Three Fiber

When I right click, I can move my camera up and down. By default, when my model loads, half of its body is out of the frame. I want to move the camera down, so the whole body fits in the frame. Is there a setting to do this? I’ve tried using camera position but that didn’t work. Thank you!
when I come across cases like this I do this:
try to scale down the object first, so that I can see the whole picture
add axesHelpers to object or scene, to figure out which direction should I move to
change position of camera accordingly.

Misplaced UI made with UI in hololens emulator

I got a small problem and I can’t really find the source of it. I just created a Canvas and put a Panel in the top right corner. I got it to the right scale at 3: for the Hololens and loaded it up in the Holoemulator. The problem is that even though the panel is supposed to be in the corner, it is placed almost in the middle of the screen in the end.
Is there anything I can do to fix this or is there something I am missing?
If I need to provide more information then please tell me.
Could you double-check the [Render mode] of your Canvas? Is it set as World Space? In this render mode, the Canvas will behave as any other 3D object and will render in front of or behind other objects in the scene based on 3D placement in the scene. You need to adjust the position of the canvas from the perspective of the camera.
However, according to your post, it seems that you want to place UI elements on the screen rendered on top of the scene. If so, You should turn the [Render mode] to [Screen Space - Camera]. More information please see: Canvas

wxToolBar changing device coordinates

Using the mouse I am drawing 2D shapes on the client area of a MDIChildFrame. Recently I have added a wxToolBar to the frame and when I now draw a shape on the client area it seems that the points have shifted by the size the toolbar. Imagine that with mouse I am clicking on (100,100) and drawing a line to (150,150); however, the line appears somewhere (75,75) to (125,125). By the way, wxMouseEvent GetPosition(); reports (100,100) to me.
Removing the toolbar fixes the problem however, I want to keep the toolbar for ease of tool selection.
I use the code:
m_ToolBar=new wxToolBar(this, wxID_ANY);
m_ToolBar->AddTool() //
m_ToolBar->Realize();
this->SetToolBar(m_ToolBar);
Any ideas will be appreciated.
You can always use wxWindow::GetClientAreaOrigin() to manually offset the coordinates by the toolbar height but normally this shouldn't be necessary, and if this doesn't happen with a "normal" frame but only happens with wxMDIChildFrame it would be a bug in wxWidgets that should be reported as usual.
It's also recommended to not draw over wxFrame itself but rather put a wxWindow into it and draw on it. This should also take care of your problem.

Shadow for custom mouse cursor

On "newer" Windows systems there is an option to make the OS draw a shadow beneath the mouse cursor:
However the custom cursors in my Delphi app don't show a shadow even if this setting is enabled. Do you have any idea how to arrange it so that Windows adds the shadow automagically? Or do I really have to check the user's preferences and conditionally draw the shadow myself like Mike Lischke did?
(This is a question that has been bugging me and others for some time:
Custom mouse cursor shadow
Custom cursor shadow
Custom cursor with shadow)
No, you don't need to check the user's global setting and draw the cursor yourself. You just need to provide a cursor with the alpha channel. Windows will either use alpha blending to draw your cursor or not, depending on the user's setting. Your cursors probably don't include the alpha channel so the shadow is never shown.

Resources