Mesh picking on guiObjectView, seeking direction
by Joshua Leeming · in Torque 3D Professional · 05/10/2011 (6:42 am) · 2 replies
Hi all,
I've kinda thrown myself in the deep end.
Currently I'm working on a slightly modified version of guiObjectView (I've modified mouse methods) and am hoping to use the new class eventually as a drag n drop interface for equipping player clothing and items.
In my implementation of onMouseMove, I am trying to determine the visible mesh that is under my cursor, so that on the mouse down events, or via a console method, I can toggle said mesh.
I thought it would be as simple as doing a raycast from mModel (which is TSShapeInstance) since that seemed to do a raycast on meshes, but I'm not entirely sure that I'm correct (not having any luck so far)
If anybody has some pointers of where to look in the source to get what I need (or if there's an easier way to do the same thing) it would be appreciated... I'm hoping to be able to use the visible mesh....
I've kinda thrown myself in the deep end.
Currently I'm working on a slightly modified version of guiObjectView (I've modified mouse methods) and am hoping to use the new class eventually as a drag n drop interface for equipping player clothing and items.
In my implementation of onMouseMove, I am trying to determine the visible mesh that is under my cursor, so that on the mouse down events, or via a console method, I can toggle said mesh.
I thought it would be as simple as doing a raycast from mModel (which is TSShapeInstance) since that seemed to do a raycast on meshes, but I'm not entirely sure that I'm correct (not having any luck so far)
If anybody has some pointers of where to look in the source to get what I need (or if there's an easier way to do the same thing) it would be appreciated... I'm hoping to be able to use the visible mesh....
#2
If anyone has any critiques/review points on my code lemme know too - I'm still learning as I go.
11/25/2011 (8:23 pm)
Solution for anyone who's interested:bool GuiObjectView::checkOverObject(const Point2I& mousePoint)
{
RayInfo r;
Point3F screenPoint((F32)mousePoint.x, (F32)mousePoint.y, 1.0f);
Point3F worldPoint;
if (unproject(screenPoint, &worldPoint)) {
Point3F vec = worldPoint - mCameraPos;
Point3F start = mCameraPos;
vec.normalizeSafe();
Point3F end = mCameraPos + vec * 10000;
if (mModel->castRayRendered(start, end, &r, 0))
return true;
}
return false;
}
//------------------------------------------------------------------------------
void GuiObjectView::onMouseMove( const GuiEvent & event )
{
bool obj = checkOverObject(event.mousePoint);
if(obj != mMouseOverObject)
{
mMouseOverObject = obj;
if (mMouseOverObject)
onMouseEnter_callback();
else
onMouseLeave_callback();
}
}If anyone has any critiques/review points on my code lemme know too - I'm still learning as I go.
Torque Owner Joshua Leeming
Default Studio Name
I've since revisited and now have an aim to implement what I hope is a much simpler solution. I'm now looking to fire the onmouseenter and onmouseleave callbacks when the mouse is over the model in the GUI - not just over the container. Since I know the model, and can have a callback on mousedown - this should be enough for me to do what I need to do....
That said, I'm still having some difficulties, and would still appreciate any pointers from the community.
bool GuiObjectView::checkOnEnter(const Point2I& mousePoint) { SceneObject* mo_obj = 0; RayInfo r; Point3F pos; mCameraMatrix.getColumn(3,&pos); Point3F screenPoint((F32)mousePoint.x, (F32)mousePoint.y, 1.0f); Point3F worldPoint; if (unproject(screenPoint, &worldPoint)) { Point3F vec = worldPoint - pos; Point3F start = pos; vec.normalizeSafe(); Point3F end = pos + vec * 10000; RayInfo hit_info; if (gClientContainer.castRay(start, end, StaticShapeObjectType, &hit_info)) mo_obj = dynamic_cast<SceneObject*>(hit_info.object); } return (mo_obj); } void GuiObjectView::onMouseEnter( const GuiEvent & event ) { if(checkOnEnter(event.mousePoint)) ..I also added:
Since I figured raycasts wouldn't collide if there was nothing to collide with!? Maybe I got this part wrong as well as it's the visible mesh I want the raycast to hit...or maybe I got the raycast wrong (or both), I'm not so sure.
Please lemme know if you have any pointers this time round.
Thanks
J
EDIT. OK...first thing I found is that I'm checking onMouseEnter instead of onMouseMove...I've sorted that out! *face palm*