Mount frustrations (solved)
by Ben Shive · in Torque Game Builder · 06/26/2006 (7:02 pm) · 5 replies
I'm trying to what should be a pretty simple procedure: when dropping an object, having it snap to a mount point on the nearest object. Between the mix of local and world coordinates, it's rapidly becoming a headache.
The documentation says that you can use the form getLocalPoint(X, Y) or getLocalPoint("X Y"). When I try to use the second, it gives me an error and suggests the first. When I use it as shown I get an error saying the wrong number of parameters are used.
Is there a better way to do this than having to grab the local offsets? I'm kind of surprised there's no explicit "mount to link point N on target object with optional offset".
%loc = $activeObj::selectedObj.getLinkPoint(1);
%picked = sceneWindow2D.getSceneGraph().pickRadius(
getWord(%loc, 0),
getWord(%loc, 1),
10);
echo("Drop near:" SPC %picked);
for(%i=0; %i < getWordCount(%picked); %i++) {
%targ = getWord(%picked, %i);
if(%targ.isSelectable $= "true" &&
%targ != $activeObj::selectedObj) {
echo("linkable:" SPC %targ);
echo(%targ.getLinkPoint(2));
echo($activeObj::selectedObj.getLinkPoint(1));
%localPt = t2dSceneObject::getLocalPoint(//%targ.getLinkPoint(2));
getWord(%targ.getLinkPoint(2), 0),
getWord(%targ.getLinkPoint(2), 1) );
echo(%localPt);
$activeObj::selectedObj.mount(
%targ,
getWord(%localPt, 0),
getWord(%localPt, 1),
0,
true,
true,
false,
false);
echo($activeObj::selectedObj.getPosition());
echo(%localPt);
}
}
The documentation says that you can use the form getLocalPoint(X, Y) or getLocalPoint("X Y"). When I try to use the second, it gives me an error and suggests the first. When I use it as shown I get an error saying the wrong number of parameters are used.
Is there a better way to do this than having to grab the local offsets? I'm kind of surprised there's no explicit "mount to link point N on target object with optional offset".
%loc = $activeObj::selectedObj.getLinkPoint(1);
%picked = sceneWindow2D.getSceneGraph().pickRadius(
getWord(%loc, 0),
getWord(%loc, 1),
10);
echo("Drop near:" SPC %picked);
for(%i=0; %i < getWordCount(%picked); %i++) {
%targ = getWord(%picked, %i);
if(%targ.isSelectable $= "true" &&
%targ != $activeObj::selectedObj) {
echo("linkable:" SPC %targ);
echo(%targ.getLinkPoint(2));
echo($activeObj::selectedObj.getLinkPoint(1));
%localPt = t2dSceneObject::getLocalPoint(//%targ.getLinkPoint(2));
getWord(%targ.getLinkPoint(2), 0),
getWord(%targ.getLinkPoint(2), 1) );
echo(%localPt);
$activeObj::selectedObj.mount(
%targ,
getWord(%localPt, 0),
getWord(%localPt, 1),
0,
true,
true,
false,
false);
echo($activeObj::selectedObj.getPosition());
echo(%localPt);
}
}
#2
getLocalPoint("52 ");
or
getLocalPoint(52, );
so use a debugger or some good 'ol error outs to determine the values of your x and y before calling the function.
Also, at or around line 4225 of t2dSceneObject.cc you can see in the code that the function provides for taking a vector or individual points. If it doesn't find the proper number of args, it prints
"t2dSceneObject::getLocalPoint() - Invalid number of parameters!"
06/26/2006 (10:37 pm)
Are you sure your x and y are populated the way you think you are? For example, you may think x = 52 and y = 110, but if y is in fact an empty string, you are in essence callinggetLocalPoint("52 ");
or
getLocalPoint(52, );
so use a debugger or some good 'ol error outs to determine the values of your x and y before calling the function.
Also, at or around line 4225 of t2dSceneObject.cc you can see in the code that the function provides for taking a vector or individual points. If it doesn't find the proper number of args, it prints
"t2dSceneObject::getLocalPoint() - Invalid number of parameters!"
#3
Interesting technique with the mount 'slots' to attach the items. It would make the level design a bit more complex with the extra images, plus I need to know what's currently connected to what on the game board. Thinking further that might not work too well for my implementation, since each game piece has multiple ways it can connect to the next.
@Ben V
I'm printing out the link point contents before I try the Local/World conversion, and I always get a value pair. Unless the getLinkPoint call is returning something funny I can't see everything seems to be in order as far as data. Guess I'll have to try feeding it some explicit values at each stage to see what might be causing the problem.
06/27/2006 (10:22 am)
@Stephen ZInteresting technique with the mount 'slots' to attach the items. It would make the level design a bit more complex with the extra images, plus I need to know what's currently connected to what on the game board. Thinking further that might not work too well for my implementation, since each game piece has multiple ways it can connect to the next.
@Ben V
I'm printing out the link point contents before I try the Local/World conversion, and I always get a value pair. Unless the getLinkPoint call is returning something funny I can't see everything seems to be in order as far as data. Guess I'll have to try feeding it some explicit values at each stage to see what might be causing the problem.
#4
I was doing:
%localPt = t2dSceneObject::getLocalPoint( getWord(%targ.getLinkPoint(2), 0), getWord(%targ.getLinkPoint(2), 1) );
corrected, it's now:
%localPt = %targ.getLocalPoint(getWord(%targ.getLinkPoint(2), 0), getWord(%targ.getLinkPoint(2), 1) );
When I was testing parameters, I was doing something similar with getWorldPoint as well. Something to improve the error messages on in the next version perhaps. :)
Current working code:
for(%i=0; %i < getWordCount(%picked); %i++) {
%targ = getWord(%picked, %i);
// ensure linkable obj
if(%targ.isSelectable $= "true" &&
%targ != $activeObj::selectedObj) {
echo("linkable:" SPC %targ);
// need to transform to local coordinates to mount
%localPt = %targ.getLocalPoint(
getWord(%targ.getLinkPoint(2), 0),
getWord(%targ.getLinkPoint(2), 1) );
%localPtOffset = $activeObj::selectedObj.getLocalPoint(
getWord($activeObj::selectedObj.getLinkPoint(1), 0),
getWord($activeObj::selectedObj.getLinkPoint(1), 1) );
echo(%localPt);
echo(%localPtOffset);
echo($activeObj::selectedObj.getLinkPoint(1));
%worldPt = sceneWindow2D.getWorldPoint("-2, -0.28");
//echo(%worldPt);
$activeObj::selectedObj.mount(
%targ,
getWord(%localPt, 0) - getWord(%localPtOffset, 0),
getWord(%localPt, 1) - getWord(%localPtOffset, 1),
0,
true,
true,
false,
false);
}
}
07/31/2006 (6:42 pm)
In case anyone else hits this with a search, the problem was twofold. The compiler was giving parameter messages when I wasn't even calling the functions on the correct objects! Instead of double-checking I was using the functions correctly, it lead me to believe that it was a parameter problem.I was doing:
%localPt = t2dSceneObject::getLocalPoint( getWord(%targ.getLinkPoint(2), 0), getWord(%targ.getLinkPoint(2), 1) );
corrected, it's now:
%localPt = %targ.getLocalPoint(getWord(%targ.getLinkPoint(2), 0), getWord(%targ.getLinkPoint(2), 1) );
When I was testing parameters, I was doing something similar with getWorldPoint as well. Something to improve the error messages on in the next version perhaps. :)
Current working code:
for(%i=0; %i < getWordCount(%picked); %i++) {
%targ = getWord(%picked, %i);
// ensure linkable obj
if(%targ.isSelectable $= "true" &&
%targ != $activeObj::selectedObj) {
echo("linkable:" SPC %targ);
// need to transform to local coordinates to mount
%localPt = %targ.getLocalPoint(
getWord(%targ.getLinkPoint(2), 0),
getWord(%targ.getLinkPoint(2), 1) );
%localPtOffset = $activeObj::selectedObj.getLocalPoint(
getWord($activeObj::selectedObj.getLinkPoint(1), 0),
getWord($activeObj::selectedObj.getLinkPoint(1), 1) );
echo(%localPt);
echo(%localPtOffset);
echo($activeObj::selectedObj.getLinkPoint(1));
%worldPt = sceneWindow2D.getWorldPoint("-2, -0.28");
//echo(%worldPt);
$activeObj::selectedObj.mount(
%targ,
getWord(%localPt, 0) - getWord(%localPtOffset, 0),
getWord(%localPt, 1) - getWord(%localPtOffset, 1),
0,
true,
true,
false,
false);
}
}
Torque 3D Owner Stephen Zepp
FYI, I'm doing something very similar, but I never thought about mounting directly to the "root", or "main" parent obect via it's linkpoint.
What I do is to have my base object with the linkpoints, then mount small static sprites to those points for a visual image of the linkpoint itself.
Then, when I want to mount my "to be mounted" object, I have an onMouseDown() callback on the mount image (I call them mount slots) which can handle the mounting easily. Different technique, and it does have some downsides (complex linkages being one of them), but it's quite flexible as well once you work out the kinks.