3D space: in accordance with the direction that the object is pointing with the mouse pointer

Given the 3D direction vector the camera is facing and the orientation / direction vector of the 3D object in three-dimensional space, how can I calculate the two-dimensional tilt that the mouse pointer must follow on the screen to visually move in the direction of the specified object?

Basically, I would like you to be able to click on the arrow and move it forward and backward, dragging it, but only if the mouse pointer stretches (roughly) along the length of the arrow, that is, in the direction in which it points to.

Thank you

+4
source share
2 answers

I am not sure that I understand your question 100%. Could you place the chart?

You can find their interest. I answered previous questions to calculate the local XYZ axis taking into account the direction of the camera (look), as well as the question of translate an object in a plane parallel to the camera .

Both examples use a vector point product , a Vector cross product to calculate the required vectors. In your example, a vector point product can also be used to display the angle between two vectors as soon as you find them.

+1
source

It depends on what kind of transformation you use to convert 3D real-world coordinates to 2d screen coordinates, for example. perspective, isometry, etc. Usually you will have a conversion forward (3d → 2d) and backward (2d → 3d) to a game where the inverse transformation loses information. (i.e. moving each three-dimensional point will be mapped to a single 2d point, but returning from a point may not give the same three-dimensional point). You can often project a mouse point onto an object to get the missing dimension.

For drag and drop, you usually get the user to specify the operation (translation on the projection plane, zooming in or out, rotation around the reference point). Your input is the mouse coordinate at the beginning and end of the drag and drop that you transform into your 3d coordinate system to get two 3d coordinates that will give you dx, dy, dz for drag / drop, etc.

0
source

Source: https://habr.com/ru/post/1393323/


All Articles