简体   繁体   中英

How does one interact with OBJ-based 3D models on iPhone?

I have a few different OBJ files that I am able to parse and display. This code is based on Jeff LaMarche's The Start of a WaveFront OBJ File Loader Class . However, I need some means of detecting what coordinates I have selected within a displayed model. Usually there is one model displayed at a time but sometimes there will be two or more on the screen and I want to set up a NSNotificationCenter object to notify other sections of code as to which object is "selected". I have also looked at javacom's "OpenGL ES for iPhone : A Simple Tutorial" and would like to model the behavior of what I'm trying to program after his.

This is my current line of logic:

  • Setup a means to detect where a user has touched the screen
  • Have those coordinates compared with the current coordinates of a OBJ-based model
  • If they match, indicate said touch as being within the bounds of the object
  • The touchable set of coordinates must scale with the model. Currently the model is able to scale so I will most likely need to be able follow this scaling.

Also note, I don't need to move the model around on the screen. Just detect when it's been touched whether there is one model or several being displayed.

While this is most likely quite simple, I've been stumped by this for months now. I would really appreciate any light others can shed on this topic.

Use gluUnProject on the touch coordinates to get a vector going from the screen into the world, and then intersect it with your models to see if one of them has been touched. gluUnProject isn't by default available on iPhone, but you can look up implementations of it. http://www.mesa3d.org/ has an open source implementation.

Read about gluUnProject here: http://web.iiit.ac.in/~vkrishna/data/unproj.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM