ScriptThis
by Matthew "Ashteth" Kee · in Torque Game Builder · 10/08/2005 (10:16 am) · 1 replies
I'd appreciate it if we could get the TGE sceneObject function "scriptThis" ported to the next version of T2D. I know its fairly simple, but adding it to the T2D SDK adds some consitency between T2D and TGE.
I'd also like to see a setPosition4() function that sets a sceneobject's position and size based upon the northwest and southeast bounding box corners. I realize that this may be a harder sale as this function does not take into account rotations, but in practice, I have found get/setPosition4 to be extremely useful. The nomenclature quite obviously can be changed, but it would be nice if we had built in functions to set position based upon the unrotated corners as opposed to object's center.
const char* t2dSceneObject::scriptThis(void)
{
return Con::getIntArg(getId());
}I'd also like to see a setPosition4() function that sets a sceneobject's position and size based upon the northwest and southeast bounding box corners. I realize that this may be a harder sale as this function does not take into account rotations, but in practice, I have found get/setPosition4 to be extremely useful. The nomenclature quite obviously can be changed, but it would be nice if we had built in functions to set position based upon the unrotated corners as opposed to object's center.
// -----------------------------------------------------------------------------
// Get / set position based upon object's 4 coordinates.
// -----------------------------------------------------------------------------
ConsoleMethod(t2dSceneObject, getPosition4, const char*, 2, 2,
"Gets the minimim and maximum unrotated bounding coordinates object is occupying.")
{
t2dVector vPos = object->getPositionNW();
t2dVector vSize = object->getSize();
// Create Returnable Buffer.
char* pBuffer = Con::getReturnBuffer(256);
// Format Buffer.
dSprintf(pBuffer, 256, "%d %d %d %d", vPos.mX, vPos.mY,
vPos.mX + vSize.mX, vPos.mY + vSize.mY);
// Return buffer.
return pBuffer;
}
ConsoleMethod(t2dSceneObject, setPosition4, void, 3, 3,
"(xlo ylo xhi yhi) - Sets the objects position.")
{
// Check Parameters.
if ( t2dSceneObject::getStringElementCount(argv[2]) < 2 )
{
Con::warnf("t2dSceneObject::setPosition - Invalid number of parameters!");
return;
}
t2dVector vPosLo;
vPosLo.mX = dAtof(t2dSceneObject::getStringElement(argv[2], 0));
vPosLo.mY = dAtof(t2dSceneObject::getStringElement(argv[2], 1));
t2dVector vPosHi;
vPosHi.mX = dAtof(t2dSceneObject::getStringElement(argv[2], 2));
vPosHi.mY = dAtof(t2dSceneObject::getStringElement(argv[2], 3));
// Set Position.
object->setPosition4( vPosLo, vPosHi );
// Update Container Configuration.
object->updateContainerConfig();
}
void t2dSceneObject::setPosition4(const t2dVector& vPosLo, const t2dVector& vPosHi)
{
t2dVector vSize;
vSize.mX = vPosHi.mX - vPosLo.mX;
vSize.mY = vPosHi.mY - vPosLo.mY;
setSize(vSize);
setPositionNW(vPosLo);
}
// Set Position.
void t2dSceneObject::setPositionNW(t2dVector pos)
{
t2dVector vSize = getSize();
pos.mX += vSize.mX / 2;
pos.mY += vSize.mY / 2;
setPosition(pos);
}
Associate Melv May
It's your lucky day as we've already added these. 'scriptThis' was transferred from the TGE sceneobject to the 't2dSceneObject' and here's the description for the equivalent "setPosition4" copied straight from the docs...
setArea() - Sets the objects area. (x1 / y1 / x2 / y2)
"%obj.setArea( "-20 -10 20 10" )"
x1/y1 Top-Left position of object.
x2/y2 Bottom-Left position of object.
NOTE:- This sets both the position and size of the object so that it covers the area
specified. Note that the objects current rotation is set to zero so that the area can be
correctly set!
There's also some retrieval functions for this, these being...
getArea() - Gets the objects area.
"%values = %obj.getArea()"
Retrieves the area (X1/Y1/X2/Y2) occupied by the object (in world units). See
"setArea()".
NOTE:- The area is always the clipping rectangle (bounding-box) and not the axiallyalign
bounding-box. This can be visualized as the largest box surrounding the object
using "setDebugOn(BIT(1));".
... and ...
getAreaMin() - Gets the objects area minimum point.
"%values = %obj.getAreaMin()"
Retrieves the point (X1/Y1) occupied by the object (in world units). See "setArea()".
NOTE:- The area is always the clipping rectangle (bounding-box) and not the axiallyalign
bounding-box. This can be visualized as the largest box surrounding the object
using "setDebugOn(BIT(1));". This call returns the first two values returned by
"getArea()".
... and ...
getAreaMax() - Gets the objects area maximum point.
"%values = %obj.getAreaMax()"
Retrieves the point (X2/Y2) occupied by the object (in world units). See "setArea()".
NOTE:- The area is always the clipping rectangle (bounding-box) and not the axiallyalign
bounding-box. This can be visualized as the largest box surrounding the object
using "setDebugOn(BIT(1));". This call returns the last two values returned by
"getArea()".
- Melv.