What’s the relations between mouse’s coordination and panda3D’s coordination?
I print the mouse’s position, they are always 0.89,0.97 etc.
So how can I transmate the mouse’s position to panda3D’s position. Bcz I want my actor moving with my mouse.
Thanks a lot!
The mouse position is on screen space, so you will have to find a way to translate it into your coordinate system.
One way to do that is to cast a collisionray ( from camera_pos with camera_pos <-screen_pos in space as a direction) and catch the object colliding.
You can find a lots of post in that subject in the forum
Using a collision ray is probably overkill, unless there’s a good reason to use it in this case.
This piece of code kind of explains what you want:
(that code actually assumes your actor moves on a 2d plane)
Thank you pro-rsoft.
What I want is that: When I press my mouse button on the actor, and drag it on the screen, so the actor will be the position where mouse is.
When mouse is up, the actor is up, when mouse is down ,the actor is down,left and right are also like that. But the actor’s size won’t be smaller than it’s original size. In panda coordination , Y axis won’t be changed.
So how to do it?
I learn your codes and chessboard in samples, I still cann’t do it .
I think maybe I didn’t understand the Len’s functions getRelativePoint and getRelativeVector, I didn’t know what they do and I cann’t find anything about their description(the manual is so simple and I cann’t understand).
How to transmate the point2D of mouse to Point3D in my scene(Y axis won’t be changed)?
Well, you can’t just transform a 2D point into a 3D point. You always have to define a 2D plane somewhere (the chessboard, or the white floor in my sample) where the 3d object moves on.
But the 3d object’s size will be changed. Will be bigger or smaller when it is moving.
I won’t want its size to be changed.
The size hasn’t changed. It’s just farther away from the camera.
If that’s what you want, to move it over a plane parallel to the view, you can simply need to place the Plane in my code at the object’s position, and have it face the camera.