1.7.3 pickRect returning no results
by James Ford · in Torque Game Builder · 08/10/2008 (12:55 pm) · 10 replies
If pickRect is called and the rect is contained by, or only slightly larger than, an object's collision area it works properly (it will be picked). However, if the rect is much larger than the object, even though the object IS contained by the rect it will not be returned. Heres a simple mockup situation...
Add this to the end of game.cs for testing...
Here's a level file with an object for picking practice...
Let me know if there are any issues getting this test case to work.
What I found on my box is that if you draw a small rect that is contained by the object and release, it will be detected. If you drag a large rect, say, across most of the screen, it will find nothing.
Add this to the end of game.cs for testing...
//
// Code for the SelectionBox object.
//
new t2dShapeVector( SelectionBox )
{
LineColor = "1 1 1 1";
FillMode = false;
CollisionActiveSend = false;
CollisionActiveReceive = false;
CollisionPhysicsSend = false;
CollisionPhysicsReceive = false;
Visible = false;
};
SelectionBox.setPolyPrimitive(4);
function SelectionBox::setStartPoint( %this, %wpos )
{
%this.startPoint = %wpos;
%this.setSize(0,0);
%this.setPosition(%wpos);
}
function SelectionBox::setEndPoint( %this, %wpos )
{
%this.endPoint = %wpos;
%diff = t2dVectorSub( %this.endPoint, %this.startPoint );
%this.setSize( mAbs(%diff.x), mAbs(%diff.y) );
%pos = t2dVectorAdd( %this.startPoint, t2dVectorScale( %diff, 0.5 ) );
%this.setPosition( %pos );
}
//
// Mouse callbacks on the sceneWindow
//
function t2dSceneWindow::onMouseDown( %this, %modifier, %worldPosition, %clicks )
{
SelectionBox.Visible = true;
SelectionBox.setStartPoint( %worldPosition );
}
function t2dSceneWindow::onMouseDragged( %this, %modifier, %worldPosition, %clicks )
{
SelectionBox.setEndPoint( %worldPosition );
}
function t2dSceneWindow::onMouseUp( %this, %modifier, %worldPosition, %clicks )
{
SelectionBox.Visible = false;
SelectionSet.clear();
echo( "pickingRect : " @ SelectionBox.startPoint SPC SelectionBox.endPoint );
%list = $sceneGraph.pickRect( SelectionBox.startPoint, SelectionBox.endPoint );
echo( "found objects: " @ getWordCount(%list) );
}Here's a level file with an object for picking practice...
%levelContent = new t2dSceneGraph() {
canSaveDynamicFields = "1";
UseLayerSorting = "1";
layerSortMode0 = "Normal";
layerSortMode1 = "Normal";
layerSortMode2 = "Normal";
layerSortMode3 = "Normal";
layerSortMode4 = "Normal";
layerSortMode5 = "Normal";
layerSortMode6 = "Normal";
layerSortMode7 = "Normal";
layerSortMode8 = "Normal";
layerSortMode9 = "Normal";
layerSortMode10 = "Normal";
layerSortMode11 = "Normal";
layerSortMode12 = "Normal";
layerSortMode13 = "Normal";
layerSortMode14 = "Normal";
layerSortMode15 = "Normal";
layerSortMode16 = "Normal";
layerSortMode17 = "Normal";
layerSortMode18 = "Normal";
layerSortMode19 = "Normal";
layerSortMode20 = "Normal";
layerSortMode21 = "Normal";
layerSortMode22 = "Normal";
layerSortMode23 = "Normal";
layerSortMode24 = "Normal";
layerSortMode25 = "Normal";
layerSortMode26 = "Normal";
layerSortMode27 = "Normal";
layerSortMode28 = "Normal";
layerSortMode29 = "Normal";
layerSortMode30 = "Normal";
layerSortMode31 = "Normal";
DebugRendering = "0";
cameraPosition = "0 0";
cameraSize = "100 75";
new t2dStaticSprite(TestObj) {
imageMap = "moonBaseImageMap";
frame = "0";
canSaveDynamicFields = "1";
Position = "3.129 -1.198";
size = "10.750 10.250";
CollisionPhysicsSend = "0";
CollisionPhysicsReceive = "0";
CollisionDetectionMode = "CIRCLE";
mountID = "2";
};
};Let me know if there are any issues getting this test case to work.
What I found on my box is that if you draw a small rect that is contained by the object and release, it will be detected. If you drag a large rect, say, across most of the screen, it will find nothing.
About the author
http://jamesdev.info
#2
08/24/2008 (11:05 pm)
No replies, no bug-tracking ids? I only bother making these posts so future version of TGB are even better.
#3
Over the next few weeks I'll spend more time trolling through the forums and bumping old posts like these and help track down some nasty little bugs.
Thanks James!
08/24/2008 (11:29 pm)
I'll log it tonight.Over the next few weeks I'll spend more time trolling through the forums and bumping old posts like these and help track down some nasty little bugs.
Thanks James!
#4
08/28/2008 (4:35 am)
Logged into Jira as TGB-101.
#5
The bug is really simple to fix, but also could be causing a ton of people problems without them knowing whats going on...
The issue is, a circle that is entirely inside a polygon (not intersecting with any edges) will NOT TRIGGER A COLLISION.
Problem lies t2dPhysics::polygonCircleIntersect(...)
At the end of the for loop which looks like this,
This next line of code is the problem,
I replaced it with this,
11/01/2008 (10:14 pm)
Fixed this. The bug is really simple to fix, but also could be causing a ton of people problems without them knowing whats going on...
The issue is, a circle that is entirely inside a polygon (not intersecting with any edges) will NOT TRIGGER A COLLISION.
Problem lies t2dPhysics::polygonCircleIntersect(...)
At the end of the for loop which looks like this,
// Check all edges.
for ( const t2dVector *pv1 = pVertices, *pv2 = pVertices + numVertices - 1; vertex < numVertices; pv2 = pv1, ++pv1, ++vertex )
{
...This next line of code is the problem,
// Finish if no collision if ( !collision ) return false;
I replaced it with this,
// Finish if no collision.
// Or we could have a fully-contained circle!!!
if ( !collision && !polygonContained )
return false;
if ( !collision && polygonContained )
{
// Pick an arbitrary vert for the collision point.
colPoint = pVertices[0];
}
#6
Melv.
11/17/2008 (6:27 am)
Good catch James and thank you for your helpful submission. This has been fixed (TGB-101) and will be available in the next release.Melv.
#7
11/17/2008 (9:24 am)
Thank you sir!
#8
02/18/2010 (6:10 pm)
I downloaded Torque Game Builder from my products download page recently, and ran into this bug today. Is it not fixed still in the most recent version? Was I using the wrong version somehow?
#9
02/18/2010 (7:02 pm)
I'm not certain, but it sounds like perhaps not. You're best option is to take a look at the source code and apply the fix if necessary.
#10
02/19/2010 (6:32 am)
This will be included in the free upgrade v1.7.5 when it is released. There has been no release since this bug was submitted.
Associate James Ford
Sickhead Games
I also determined that this only happens with CollisionDetectionMode as CIRCLE or FULL. It actually works as you would expect with a POLYGON mode. I suspect a problem in this area could mess up a whole lot of things...