Pages: 1
Author Topic: Selecting 3D faces by mouse  (30,518 Views)
Offline (Unknown gender) FroggestSpirit

Member
Joined: Mar 2013
Posts: 79
View profile
Posted on: January 01, 2014, 05:33:32 PM
Currently, I'm working on updating my model editor for my custom format for my game. I have a feature, where you can select faces of a 3D model by clicking them, or dragging a rectangle over the ones you want.
This is all accomplished by drawing the model twice a frame. Once with all faces drawn as different colors, and then drawn as what the user sees.
This allows me to use the get color function under the mouse (or every pixel in the rectangle) to see what faces are selected.
The problem with this, is that the bigger the rectangle is, the longer it takes, because it checks every pixel in it (sometimes taking up to one whole minute, or longer). A single mouse click, or small rectangle works pretty much instantly though.
I want to know if there is a better way to accomplish this, mainly just for speed improvements. Programs like Anim8or do it instantly
Offline (Unknown gender) daz

Contributor
Joined: Jul 2010
Posts: 167
View profile
Reply #1 Posted on: January 01, 2014, 07:40:31 PM
I think this is usually done with raycasting (it's what I've used, at least), but there's no implementation in enigma at the moment so you'd have to roll it yourself.
Offline (Unknown gender) Goombert

Developer
Joined: Jan 2013
Posts: 2,991
View profile
Reply #2 Posted on: January 01, 2014, 08:04:22 PM
You basically just project the mouse into the scene as daz said, Glu actually has a glProject and glUnproject function for this.

http://www.opengl.org/sdk/docs/man2/xhtml/gluUnProject.xml

There is also Phantom107's example on the EDC.
http://enigma-dev.org/edc/games.php?game=48

But basically, you need to do it yourself using a matrix.
http://stackoverflow.com/questions/19485046/2d-screen-coordinate-to-3d-position-directx-9-box-select

We haven't added the matrix functions yet, Harri was supposed to be doing that.
Offline (Unknown gender) FroggestSpirit

Member
Joined: Mar 2013
Posts: 79
View profile
Reply #3 Posted on: January 01, 2014, 11:20:43 PM
Thanks guys, i'll investigate into that
Pages: 1