Mouse Picking

I’ve worked out code to gather a ray from screen space to world space. I am having trouble detecting what lies on this ray. I am trying to select a certain triangle in a mesh of triangles.

I looked around on google and found nothing comprehensive for this.

Can anyone share pseudo code or explain the details on this?

Thanks! <3

There has been someone on the LWJGL forum with exactly the same question.
I’ll just link it here: http://forum.lwjgl.org/index.php?topic=6242.0

So basically, you’re trying to detect ray-triangle intersection (intersection of a ray and a triangle).

There are several websites with articles and tutorials about detecting intersection (ray-triangle, ray-plane, ray-sphere, ray-point, etc.)

Here’s one that looks promising: http://www.lighthouse3d.com/tutorials/maths/ray-triangle-intersection/

You could try the 3D Math Primer for Graphics and Game Development (it’s a book, not a website). It has an entire chapter about detecting intersection. Also, make sure your method of transforming screen coordinates to normalized device coordinates actually works the way it should.

If you don’t want to implement ray-? intersection tests yourself, you could use a physics engine (jBullet, as I’m sure you already know, is the most popular, if not the only, physics engine for Java. It’s a port of the ever-popular Bullet physics engine, which was written in C++. Bullet Physics is tied in first place with Nvidia’s PhysX on the popularity rankings, but I’m pretty sure Bullet is easier to use than PhysX).

I think Bullet has a rayTest function to detect ray-? intersection, not too sure. Bullet can be a royal pain in the neck (it’s not very easy to use), but…hey, no complaints! It’s awesome!

Good luck and have fun! :slight_smile:

Thanks kaihh, I skimmed through it and it looked like a good artical. I searched through jgo, but not lwgl forums.

ShadedVertex, I’m opposed to using libraries like that. As you already know, but that information on what it was is great. Good reply. I won’t be using jbullet and I will definitely check out that link. I haven’t skimmed it yet. Unfortunately, I have no access to books or means to go get books with money. So that is difficult.

Once I figure this all out I’ll be sure to leave a contribution in the wiki. My movement article had a load of hits above the others in the front page. So I hoped I helped someone out.

Hm…yes, I do know that you particularly dislike 3rd-party libraries that spoon-feed you. Your dislike for external libraries such as jBullet and PhysX will be a major inconvenience, especially if you’re working with 3D.

Also, I’ve got a piece of advice that can benefit you greatly if you take heed of it: if you can’t acquire what you need, you’re not searching in the right places. I’m doing my best to be enigmatic with my words right now, because (strictly speaking) I’m advocating something I shouldn’t be.