Archived

This topic is now archived and is closed to further replies.

Guest Anonymous Poster

'PRCL_RayIntersectsBox' ??

Recommended Posts

Well, your ray will be in view space and the bounding box will be in local vertex space. That obviously isn't going to work.

You need to use the transformed version of the bounding box which is stored in every segment after transformation (seg->bbox.tbox).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster

I am still trying to determine which entity the user is picking when
clicking on the viewport. I am using the 'MakeRay' func from the pr examples
to make a ray based on the position of the mouse when the user clicks the
viewport. In this specific case i have a game board represented on the
screen by a bunch of hexes and the user rolls the dice and then clicks on a
hex to move to... but this is niether here nor there... Then I am using
'PRCL_RayIntersectsBox' to see if the user clicked on a specific hex by
taking the hex object's outer segment ("l_hex_floo") bounding box and
converting it to a 'PR_BOX' like this:

for(i=0;iSeg = PR_FindSegment(g.board.entityi],"l_hex_floo");

box.min.x = Seg->bbox.tbox[0].x;
box.max.x = Seg->bbox.tbox[4].x;
box.min.y = Seg->bbox.tbox[0].y;
box.max.y = Seg->bbox.tbox[4].y;
box.min.z = Seg->bbox.tbox[0].z;
box.max.z = Seg->bbox.tbox[4].z;

res = PRCL_RayIntersectsBox (&box, &g.pickray, &t);
if (res != PRCL_FALSE)
return i;
}

First: I am guessing at which tbox coords i need... and probably this is wrong (index 0 and 4 for min and max ??) I didn't see this documented in the docs or header files so i don't know what is what...

Second: I tried using the 'pickobj' example code to pick a specific triangle, but I was not getting any hits... so i am suspecting that 'makeray' isn't doing what i think it is. Isn't makeray creating a ray whose start point is at the viewport where the mouse is located and whose endpoint extends stright 'into' the screen ? I was getting a hit when i would click in erroneous and empty areas on the edges of the screen....

Also, I am doing all of this in windowed mode, but i don't think there is any problem there because i ran the pickobj example in a window and all works fine...

I just can't figure out what i am doing wrong...


Any help would be appreciated.

Steve B.

Share this post


Link to post
Share on other sites
Hi,

If you just need to click on a entity (area covered by bbox or radius) then the routine below should do the trick. I use in my current game to know if my cross hair is over a targetable object. It works by projecting the entity world position into screen coords (the position it's center would be when rendered to the screen). With the sx and sy you can thus check to see if the mouse is withing the bbox. If your objects will be a variable dist from the cam, you will have to take in consideration the scaled bbox.

Note: do a final check to make sure that sx and sy are within your viewport

If you have any problems or questions email me: jdsgames@jdsgames.com or jdsgames@netzero.net


// this function will take a point in world space, project it and return the
camera
// and screen coords. If the projected point is not visible, the function
will return false
bool GV_ProjectPoint(PR_POINT *wpos, PR_POINT*cpos, long *sx, long *sy)
{

PR_VERTEX vt;
PR_VERTEX_DATA vtdata;

// clear
cpos->x = 0;
cpos->y = 0;
cpos->z =0;
*sx = 0;
*sy = 0;

// init vertext data
vt.x = wpos->x;
vt.y = wpos->y;
vt.z = wpos->z;
vt.vdata = &vtdata;

// transform to screen space
PR_TransformVertexList(&vt, &vtdata, 1, PR_ViewMatrix);

// get camera coords
cpos->x = vtdata.vx;
cpos->y = vtdata.vy;
cpos->z = vtdata.vz;

// check if not in screen space
if (vtdata.vz < 0) return false;

// calc screen coords
*sx = (vtdata.vx*vtdata.ooz *
active_viewport.xscale)+active_viewport.centerx;
*sy = active_viewport.centery-(vtdata.vy*vtdata.ooz*active_viewport.yscale);

// if at dead-center return false
if ((*sx == active_viewport.centerx) &&
(*sy == active_viewport.centery)) return false;

return true;
}

------------------
Jarrod Davis

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I am trying to determine which entity the user is picking when clicking on the viewport. I am using the 'MakeRay' func from the pr examples to make a ray based on the position of the mouse when the user clicks the viewport. Then I am using 'PRCL_RayIntersectsBox' to see if the user clicked on a specific object by taking the object's bounding box and converting it to a 'PR_BOX' like this:

box.min.x = g.board.object->bbox.minx;
box.max.x = g.board.object->bbox.maxx;
box.min.y = g.board.object->bbox.miny;
box.max.y = g.board.object->bbox.maxy;
box.min.z = g.board.object->bbox.minz;
box.max.z = g.board.object->bbox.maxz;

I then pass the box into 'PRCL_RayIntersectsBox' along with the ray from 'makeray' but something somewheer is awry... can anyone tell me a correct/better way ??

Share this post


Link to post
Share on other sites