开发者

How do i translate movement on the Canvas3D to movement in the virtual 3D world

开发者 https://www.devze.com 2022-12-30 22:39 出处:网络
My goal is to move a shape in the virtual world in such a way so that it ends up where the mouse pointer is on the canvas.

My goal is to move a shape in the virtual world in such a way so that it ends up where the mouse pointer is on the canvas.

What i have: -mouse position (x,y) on a Canvas3D object -Point3d object of where a pick ray starting from the Canvas3D viewport intersects with the first scene object. (point in 3D space of where i want to start the drag)

What i want: -Some way to translate the Point3d's coordinates so that the initial point of intersection (the Point3d object) is always overlapping the the mouse position on the canvas (same as开发者_如何学C when i used the pick ray to determine what the user clicked on from the Canvas3D object).

Thanks!


It sounds as if you want to use the plane which is parallel to the background plane and contains the intersection point with the object. You can use this plane even when the mouse moves beyond the actual background as it's just a mathematical concept which stretches to infinity.

I'm not a Java programmer so I can't give you code but I am a mathematician so here's equation you need ;)

Let P denote the original intersection point and call the background plane unit normal n. This normal is also the normal of our plane of interest. Let R denote a point on the ray and l denote it's unit direction vector.

Then the equation of the plane is (x-P).n = 0 for a point x in the plane (the . denotes dot product of two vectors). The equation of a point on the ray is x = R + t*l where t is any real number. The ray therefore intersects the plane when

(t*l + R - P).n = 0

i.e. when

t = (P - R).n / ( l.n )

This gives you a t value to plug back into your ray equation to give the intersection point.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号