3D Intersection and HUD functionality? (Urho3D Beginner)

#61

It depends on the desired freedom of movement for the object what you would map the new ray to. Do you want to map it to a sphere (equal distance to the camera), a plane facing the camera, the floor or maybe even another model? You would only need to cast a ray in the last case.

#62

@I3DB I canât find how relativeHandPosition is calculated in your example. That might contain the whole problem I have, I donât know how to calculate how far the object should move so that it stays under the finger.

@Modanung In my case, I just want to move a box along a single axis, and keep it under the finger the whole time. The camera distance and position can change, so I need to take that into account for the translate/position difference calculation. But it can be assumed that the camera wonât change while dragging.

#63

That comes from the event generator. This depends upon the device youâre using. You tap into a suitable event and handle it. If youâre using a touch screen device, you will get events that indicate the start and location (in x,y coordinates) and likely get updates as the finger slides. Youâll have to add the z coordinate if you want 3D movement, whereas the hololens provides a Vector3 already. This is no different than handling mouse click events, which indicate the position of mouse at click time.

#64

Well, I figured out a solution.

I create a Plane for possible movement at the point of the first/previous touch raycast hit and then find a point on the same plane for the subsequent touch using this code which I found here https://github.com/urho3d/Urho3D/issues/1504 :

`Vector3 result = cameraRay.origin_ + cameraRay.direction_ * dist;`

Then I subtract the coordinate(s) for the first point from this point to get the translate amount.

I am disappointed that such a common process still must be done manually, unless thereâs something easier that I am missing.

#65

Something like this should work:

``````float movementAlongAxis = (ray.origin_ + ray.HitDistance(
Plane(objectPos, ray.origin_.Orthogonalize(movementAxis))
) * ray.direction_).DistanceToPlane(objectPos, movementAxis);
``````

#66

@Modanung I donât think that would work. Movement shift is not in there. Both your points are objectPos. The DistanceToPlane would always be zero. Also, youâre missing a closing parentheses.

#67

It projects the ray onto a plane that lies along the movement axis and faces the camera after which the distance from that point to a plane - perpendicular to the axis and centered at the object - is calculated. This gives the distance from the objectâs center to the visually nearest point on the axis from the mouse cursor.

It may need some modifications, but thatâs the lines I believe you should think along.

#68

The charting sample shows simple activities with Touch input.