Moving Objects against Mouse Cursor

Ok, I figured out how to select 3D objects on screen with the mouse (I cleaned the manual code up a bit more),

but now I need to make the selected 3D object move with the mouse cursor.

The problem here is the fact, the mouse coords are 2D, while the 3D object’s coords are in 3D, and there’s no 3D to 2D coord converter function/method.

How would his be done with P3D?

Since the mouse pointer can only move in 2 coordinates and the 3d object in 3 then you need to ditch one dimension. How about putting a collision plane that a mouse ray will collide with? That will give you a point in 3d space. Depending on how you place the plane you can move the selected object up-down and left-right, forward-backward and up-down or left-right and forward-backward.

If you have a “ground” you can use that for colliding with the mouse ray and if you need to raise or lower the 3d object… well how about using the mouse-wheel for setting Z?

[Super-fast mouse ray collisions with ground plane)

This is better than using collision detection.

I have a ray going from the cam to the mouse 2D Pos, that is how I am selecting my 3D object. You would think there would be a way to retrieve the x,y,z point at the end of the ray, that is, the point where the ray touch a surface. I could simply use that point to move my 3D object, since that point will change was the cursor moves across screen.

I tried using the example in the Chessboard app, but hand no success.

nearPoint = render.getRelativePoint(, MouseCtrlr.Col_Ray.getOrigin());
                nearVec = render.getRelativeVector(, MouseCtrlr.Col_Ray.getDirection());
                Tland.PickObj1.setPos(self.PointAtZ(.5, nearPoint, nearVec));


I haven an idea… I’m going to try it.


I think I solved the issue. In fact, I solved it earlier, but I thought things were not working right because my 3D object was moving away from the mouse cursor. That wasn’t the case; it was the fact my 3D object didn’t have a centered origin.

I centered the 3D object and tried the same code and now it follows the cursor. Finally. It was as simple is getting the surface point from the into collision object and moving the 3D object to that point.

I think my code is much easier to understand too. I’m going to write example programs of things that gave me trouble so new P3D users can learn how to do it without looking at complex code from P3D Pros.

Someone told me along time ago… Sounding smart or looking smart mean nothing… It’s how well you can make others unstand what you know.

That’s why I love listening to older people… They have the sweetest quotes. Lol