Getting the mouse worldspace position under the mouse?

Aah, fair enough! I’m glad that you found the problem! (And that it was something fairly straightforward!) :slight_smile:

I hope I wasn’t too rude earlier. I’ve been having a bit of a fit in the morning lately… the heater in my room at uni keeps waking me up and then I can’t fall back asleep… leads to a lot of anxiety (and anger) later on after attempting to stay awake with coffee…

I dunno about the raycast code I looked at because I had trouble finding what class datatype it was using… I did get something other than a zero vec3, but it was some obscenely large or small value (I’m talking scientific notation in the printout type of scale) that did not help.

I actually had no idea that Panda3d was made for Disney. Good to know. I’ll try figuring this out further…

Um heads up this just occurred and IDK what I did to cause it. I don’t recall changing anything between my last boot up and this occurring.

Speaking for myself, don’t worry about it–I think that most of us have times that find us irritable. :slight_smile:

And indeed, the circumstances that you describe do seem like they could incur some irritatability, indeed!

Perhaps it would help to see the your code–then perhaps we can see where you’re going wrong!

In general, however, and when using Panda’s internal collision system (as opposed to a third-party system like Bullet), a ray-cast produces a CollisionEntry object. (See here for more detail.) This object contains a number of pieces of data, including a hit-position, hit-normal, the NodePath that was hit, and more.

That said, perhaps a practical example might help. Aside from the one in the manual, and the one provided by serega above, my “Beginner’s Tutorial” covers basic ray-casting. Perhaps the description given there will help you to figure out what particular is causing you trouble.

The specific lesson that starts teaching the matter is this one, I believe–but it does refer to and build upon elements from previous lessons, so you may want to start earlier in the tutorial, perhaps even from the beginning.

That is odd! Again, it might help to see your code–but otherwise, are you seeing any error output along with this behaviour, perhaps?

1 Like

I’m not sure. I’ve been looking at my VCS to find what change I could have made that caused this but nothing helps.

I do not want to give up my code. Other demos of using panda3d and kivy work just fine…

Something I’ve discovered: I checked out an earlier (working) commit and I still get this problem.

I mean, you don’t have to show the whole thing. (Indeed, I’d rather you didn’t: that could be a lot of code to comb through!) Instead, it might help to see relevant excerpts, which is likely safe enough unless you’re doing something quite cutting-edge.

That said, if your earlier commit is showing the problem, then it may not be in your code, as such, but perhaps in your environment.

Hmm… You say that the panda demos work, but your own code doesn’t. Are you running them in different manners at all–say via your IDE when running your code and via a terminal when running the demos?

And what happens if you run a very simple “hello world”-style program in place of your own code–something like the following:

from direct.showbase.ShowBase import ShowBase

from direct.gui.OnscreenText import OnscreenText

class Game(ShowBase):
    def __init__(self):

        self.text = OnscreenText("KITTENS!", scale = 0.5)

app = Game()

Nah. I literally copied & pasted your code and same thing…

On a related note… where are the config.prc and log file folders located under ubuntu linux with p3d? I haven’t found them documented anywhere nor do I know what to look for to find them.

WEIRD. I just reinstalled panda3d to my local conda environment and it seems to work again… Or at least I’m getting errors instead of a blank screen. I’m gonna keep investi-muh-gating.

Very strange! I’m glad that you’ve made progress, at least!

Just to check: What happens if you run a Panda program–such as the “hello world” program that I gave above–from the terminal? Something like this:


I think that the location depends on whether you installed Panda via pip/pip3 or via a deb-installer.

On my installation, the PRC-file seems to be located on the following path:


I’m not sure about the log-file–I haven’t looked for one for ages, and have had enough installations of Panda3D that I wouldn’t likely be confident that any log that I found by searching would be from the current one. ^^;

I recall seeing mention of its location somewhere, but I forget where, alas…

(I’ve generally found that, when using the SDK and thus being in debug-mode, relevant messages tend to be printed to the terminal or IDE output-window, so a log-file hasn’t been important to me.)

I did run your hello world program. That’s the one I copied and pasted. Same problem before. I seem to be able to get things done now though. Apart from VCS issues…

I took the presence of the IDE in the background of your screenshot to indicate that you ran it through the IDE, and not through a terminal. If that’s not the case, then fair enough!

But yeah, if you have things working, then nevermind either way!

UM so I kinda got this thing to work again. My problem goes back to that world space position. I don’t mean selecting a given object, I mean the exact world space position beneath the mouse. So objects can be put there, with precision, and preferably with some preference for the closest object to the camera (ie. in z-order, if we’re ordering them closest first, its the zero-eth element excluding the camera)

If you don’t want to represent the plane as an 3d object, you can use this.

If I recall correctly, there’s an easier means of getting a line-plane intersection in Panda:

See here:

Did you ever get that ray-casting approach working? If so, then what was lacking there? Perhaps we can improve upon it!

If you didn’t, then how far did you get?

My feeling is that ray-casting is likely to be the most straightforward means of doing this, and that it should be pretty precise. After all, it should do exactly what you seem to be describing: find the nearest surface-point under the mouse.

@Thaumaturge In fact, I already used the Plane() class in 2011 to implement gizmo for the editor.

Fair enough, and my apologies then! I do stand by recommending the Plane() class over doing the maths by hand, however!

@Thaumaturge actually no I realized that (months ago) I had used a similar bit of code to do camera terrain grabbing… so I copied that code and got what I wanted only there is no model intersecting detection. In other words, I’ve got my position in world space beneath the mouse but no collision/intersection detected…

@WhereIsTheLove I recommend that you decide what you want in the end. You contradict yourself every post.

Okay, fair enough–in that case I stand by my suggestion of ray-casting. As I said, it should do just what you want, by the sounds of it.