Raydium 3D Game Engine

Official forum for everything about Raydium, ManiaDrive, MeMak, ...
It is currently Fri Mar 29, 2024 10:55 am

All times are UTC




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: Sun May 06, 2007 1:48 am 
Offline

Joined: Sun May 06, 2007 1:33 am
Posts: 9
Hi all, i'm a raydium newbie.
I need to track the object that is currently under the mouse, so that one can select it and make some action related to the object.
I think was a simple task, but I can't find a good way.
Is there a way to attach a ray to the camera? (instead of an object), or I have to make an object follow the camera and then attach a ray to it?
Maybe someone as just done (i have see an old post in the forum about this).

Another thing... Is there a way to try memak? is there a release? I can't find a place to download. And memak seem like what I want to do with raydium.

Thanks
Dave


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 06, 2007 12:48 pm 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
You mean a pick function, right?
I'm afraid is not yet ready. Xfennec had added it on his TODO list, but there is no news about.


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 06, 2007 2:35 pm 
Offline

Joined: Sun May 06, 2007 1:33 am
Posts: 9
yes I mean a pick function.
Thanks, I know that ...in fact I'm trying to do it myself, using a ray.
The only difficult I have is to attach the ray to the camera...some idea about that?
Thanks
Dave


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 06, 2007 4:30 pm 
Offline
User avatar

Joined: Sun Mar 16, 2003 2:53 am
Posts: 2591
Location: gnniiiii (Scrat)
Hi,

As vicente said, there's a picking system in work (almost finished, now).
But for now, there a few other way to do it. For example, you add a box element in the scene, and "attach" the camera on it (raydium_ode_element_camera_inboard...()). Then, you can also attach a ray to this element. The only thing there is that you must move your camera like an regular element, and not using the regular camera functions.

... but one thing is sure, "picking" is not easy ;)

PS : MeMak is "only" a project. There's not a single line of code. But you can find a few models, sounds, terrains, and such things in this forum :) (for example, there a few screenshots here : viewtopic.php?t=196 [french])


Top
 Profile  
 
 Post subject: picking
PostPosted: Sun May 06, 2007 7:41 pm 
Offline

Joined: Sun Oct 09, 2005 10:46 pm
Posts: 759
Hello,

Here is my implement of picking
Everything is there. I just hope code is not so dirty

Difficulty is to integrate this with Raydium style :)

Xfennec can you give me function prototype you'll like, i'll finish the implementation.

Have a nice day
Ouille


Code:
int raydium_mouse_pick(float dist,raydium_pick_info * pick_pt)
{
    GLint viewport[4];
   GLdouble modelview[16],projection[16],dX, dY, dZ;
    int id;
    float min_dist;   
   dGeomID ray;
   dContact pt;
   signed char (*f)(int,int, dContact *);
   
   f=raydium_ode_CollideCallback;
   
    raydium_camera_replace();
   glGetDoublev( GL_MODELVIEW_MATRIX, modelview );
   glGetDoublev( GL_PROJECTION_MATRIX, projection );
   glGetIntegerv( GL_VIEWPORT, viewport );
    // Get mouse pointed coordinate
   gluUnProject( (float)raydium_mouse_x, (float)(raydium_window_ty - raydium_mouse_y), (float) -1.0, modelview, projection, viewport, &dX, &dY, &dZ);

   //Create Ray   
   ray =  dCreateRay (raydium_ode_object[raydium_ode_object_find("GLOBAL")].group,dist);
   // Set ray origin and dist
   dGeomRaySet (ray, raydium_camera_x, raydium_camera_y,raydium_camera_z,dX-raydium_camera_x, dY-raydium_camera_y, dZ-raydium_camera_z);
   
   id=-1;
   min_dist=dist;
   
   {
       // Private callback for ray picking only
       void dNearPickback (void *data, dGeomID o1, dGeomID o2)
        {
            #define N 400
            static  dContact contact[N];
            int i,n;
           
            // Recurse into space
            if(dGeomIsSpace (o1) || dGeomIsSpace (o2))
            {
                raydium_ode_Object *oo1, *oo2;
                signed char (*g)(int,int);
                oo1=dGeomGetData(o1);
                oo2=dGeomGetData(o2);
                g=raydium_ode_ObjectNearCollide;
                if(g && !g(oo1->id,oo2->id)) return;
                dSpaceCollide2 (o1,o2,data,&dNearPickback);
                return;
            }
           
           
            if (o1==ray || o2==ray) {
                raydium_ode_Element *e1,*e2;
               
                //Should never exist, but in case of swap o2 ray, o1 object
                if (o2!=ray){
                    o1=o2;
                    o2=ray;
                }
           
                e1=dGeomGetData(o1);
               
                n = dCollide (o1,o2,N,&contact[0].geom,sizeof(dContact));
               
                for (i=0; i<n; i++) {
                   
                    if(f)
                    {
                        int id1;
                        id1=-1;
                        if(e1) id1=e1->id;
                        // Can't test between two object since ray not wrapped to a raydium_element
                        if(!f(id1,id1,&contact[i])) continue;
                    }

                    if (contact[i].geom.g1==ray)
                        if (contact[i].geom.depth<min_dist){
                            min_dist=contact[i].geom.depth;
                                memcpy(&pt,&contact[i],sizeof(dContact));
                            id = e2->id;
                        }
                   
                    if (contact[i].geom.g2==ray)
                        if (contact[i].geom.depth<min_dist){
                            min_dist=contact[i].geom.depth;
                            memcpy(&pt,&contact[i],sizeof(dContact));
                            id = e1->id;
                        }
                }
            }
        }
       
        dSpaceCollide2((dGeomID) raydium_ode_space,ray,(void *) NULL,&dNearPickback);
   }
   
   dGeomDestroy(ray);
   if (pick_pt)
        memcpy(pick_pt,&pt,sizeof(raydium_pick_info));
    return id;
   
}


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 06, 2007 9:43 pm 
Offline

Joined: Sun May 06, 2007 1:33 am
Posts: 9
Yhea! Thanks Ouille
Your function works out of the box!! :)

Only one thing: where is raydium_pick_info * defined?
I can make the function works only removed the second parameter (it is usefull?)

really, really thanks
Dave


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 06, 2007 10:24 pm 
Offline
User avatar

Joined: Sun Mar 16, 2003 2:53 am
Posts: 2591
Location: gnniiiii (Scrat)
Code:
typedef dContact raydium_pick_info;

See ODE documentation, it may gives you some informations about touched elements, and the contact vector. Consider this as advanced informations on contact.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 13, 2007 12:12 am 
Offline

Joined: Fri Jul 13, 2007 12:07 am
Posts: 3
Hi, I'm the guy that asked about a Pick function back in September '05 :)

I've been patiently waiting ever since, and am very glad to see its under development. Will it be a function similar to that proposed in the old thread - int raydium_ode_pick_mouse(int *element, dReal *localx, dReal *localy, dReal *localz); ?

To me that'd be ideal as it'd return not only the x/y location of the pick, but the identities of all potential objects under the cursor as well.

regards,
Andrew


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 13, 2007 2:27 am 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
Xfennec should be back tomorrow, maybe he could tell you more about.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 08, 2007 10:41 pm 
Offline

Joined: Fri Jul 13, 2007 12:07 am
Posts: 3
<bump>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 08, 2007 11:12 pm 
Offline
User avatar

Joined: Sun Mar 16, 2003 2:53 am
Posts: 2591
Location: gnniiiii (Scrat)
I've bumped the suitable devel thread. More soon.

Ref: viewtopic.php?p=5194 [french]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 08, 2007 11:26 pm 
Offline

Joined: Fri Jul 13, 2007 12:07 am
Posts: 3
Ok, thanks Xfennec, good to see you back :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 39 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group