Advertisement

Clicking on 3d Terrain

Started by October 30, 2002 05:26 AM
3 comments, last by Dhennos 22 years, 3 months ago
Hello everybody, first off all, sorry for cross/double posting. I''m really in need of some help and I thus I posted this topic in a few catagories so a lot of people will see it. Sorry. My problem has to do with the well known object selection/picking in a 3d scene. I''ve done alot of research but it doesnt make sense to me. The seatch function is down so i cannot search the board. Sorry. I REAAALLLYY want to make this ( I''m making a small game in my spare time) work, so please if anyone can brainstorm with me or give me some pointers I will be very happy THE PROBLEM: I have a terrain in 3d and an md2 model is walking on it. Now I placed my camera above the model and I want to clik on the terrain with my mouse. The md2 model is supposed to walk over there just like an rpg/rts. I''ve studied object picking and object selection through color selection and names, but I cant give every polygone in my terrain a name or a color for selection purposes. There are way to much polygones in a terrain. Also I''ve looked at gluUnproject and GluProject (opengL). Now I think this is what I have to use, but I think I have to check ALL my polygones on the terrain if my ray from my mouse has collided with one of them. Once again...there are way to much polygones to check for collision. So, my question is: Does someone have any idea , no matter what, some math function or idea to have my md2 model walk towards my mouse? Maybe I dont even have to use picking/slecting??? Thank you in advance... ANY help is appreciated. I really want to make this work.
use simple tree of boundig boxes and test intersection of ray with BB.

          struct{BoundingBox bbox;Node *leftchild;           //editedNode *rightchild;          //editedPolygons *pPolygons;int num_of_polygons;}Node;        

then create the tree,where leftchild's bbox is 1.half of parent's bbox and rightchild's bbox is 2.half of parent's bbox:

A -A include all terrain
| |
AA AB -AA include left half,AB right half
| | | |
AAA AAB ABA ABB

AAA,AAB,ABA and ABB are leafs,which does not point to other bb and which contain array of polygons of your terrain.

Then for finding polygon:

         Node* FindNodeInTree(Node *root,RAY ray){//collide ray with this BB?If no,then quitif(!CollideRayWithBB(root->bbox,ray)return NULL;//ok,ray collide with this bb,//so point root to the leaf?if(root->leftchild==NULL && root->rightchild==NULL )return root;//pointer to the leaf returned,will be used for getting polygons//we are somewhere in the middle...Node *temp=NULL;temp=FindNodeInTree(root->leftchild,ray)//is our polygon on the left?If not,then must be on the rightif(temp==NULL)return FindNodeInTree(root->rightchild,ray);return temp;}          

So after you call this function,you receive pointer to the node of tree,which will contain array of polygons.

But now you have other problem:have to make the tree

I hope it help you...



[edited by - AlexanderCZ on October 30, 2002 9:31:11 AM]

[edited by - AlexanderCZ on October 30, 2002 9:32:54 AM]
Advertisement
quote:
Original post by Dhennos
first off all, sorry for cross/double posting. I''m really in need of some help and I thus I posted this topic in a few catagories so a lot of people will see it. Sorry.



I''ll let you off, but please don''t do this again. Find the most appropriate forum (which actually is this forum in the case of this post), and be patient waiting for an answer. Don''t expect people to answer you immediately, because we''re not obligated to do that.

quote:
Original post by Dhennos
THE PROBLEM:
I have a terrain in 3d and an md2 model is walking on it. Now I placed my camera above the model and I want to clik on the terrain with my mouse. The md2 model is supposed to walk over there just like an rpg/rts.

I''ve studied object picking and object selection through color selection and names, but I cant give every polygone in my terrain a name or a color for selection purposes. There are way to much polygones in a terrain.

Also I''ve looked at gluUnproject and GluProject (opengL). Now I think this is what I have to use, but I think I have to check ALL my polygones on the terrain if my ray from my mouse has collided with one of them. Once again...there are way to much polygones to check for collision.



Actually, you''re on the right track. The OpenGL selection technique is actually quite good and fairly fast, but the unproject approach is better. Essentially, unproject the screen space mouse point to calculate a ray that points from the front to the back clip plane, passing through the point on the view frustum that corresponds to the screen space pixel of the mouse cursor. AlexanderCZ has given you a very good approach, the Axis-Aligned Bounding Box (AABB) tree, which gives you a VERY fast check on boxes then once you''ve found the lowest level box checking against just a few individual triangles. I actually would suggest using a quadtree structure to organize your AABB''s, because the quadtree gives you a natural way to sort the boxes front-to-back. This is important since, depending on the camera angle you may be looking at a series of hills and if you''re clicking on the frontmost hill you''d want to find the intersection with the frontmost AABB rather than something further away. The quadtree eliminates the need to do a qsort to get the front-to-back ordering.


Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net
I''m sorry for crossposting but the problem is not everyone looks in every ''subforum'' . My problem could fit in more then one catagorie and thus someone only looking at the opengl forum doesnt see this post.

But i understand that crossposting isnt allowed because (like on the other thread was said) we could merge all forums.

I''m sorry , but I really hoped someone could help me on this.

Thank you very much for helping me out, both of you, and again sorry. I''m going to look into you solution, and tell you if it worked out OK.

If anyone else has some good ideas I''m still interested

Thanx
quote:
Original post by Dhennos
I''m sorry for crossposting but the problem is not everyone looks in every ''subforum'' . My problem could fit in more then one catagorie and thus someone only looking at the opengl forum doesnt see this post.



There''s no need to apologize. I knew that you understood the crossposting guideline and carefully considered where to post, . And I know that you''ll be just a conscientious in the future.

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net

This topic is closed to new replies.

Advertisement