Game Development Community

dev|Pro Game Development Curriculum

TGB - PolyTool

by Phillip O'Shea · 10/18/2007 (2:08 pm) · 1 comments

You need to modify your source in order to implement this new function. You need to replace the function called "onMouseDragged" within "levelBuilderPolyTool.cc".

bool LevelBuilderPolyTool::onMouseDragged(LevelBuilderSceneWindow* sceneWindow, const t2dEditMouseStatus &mouseStatus)
{
    if (!mSceneObject || (sceneWindow != mSceneWindow))
        return false;

    // Drag vertex
    if (mDragVertex != -1)
    {      
        RectI bounds = sceneWindow->getObjectBoundsWindow(mSceneObject);

        //Store the new point
        Point2I vertexPoint = mouseStatus.event.mousePoint;

        //If its not within the bounds of the object, snap them to the bounds they extend past
        if (!bounds.pointInRect(vertexPoint))
        {
            if (vertexPoint.x > bounds.point.x + bounds.extent.x)
                vertexPoint.x = bounds.point.x + bounds.extent.x;
            else if (vertexPoint.x < bounds.point.x)
                vertexPoint.x = bounds.point.x;
          
            if (vertexPoint.y > bounds.point.y + bounds.extent.y)
                vertexPoint.y = bounds.point.y + bounds.extent.y;
            else if (vertexPoint.y < bounds.point.y)
                vertexPoint.y = bounds.point.y;
        }

        //Apply the position
        if (checkDragPoint(mNutList, mDragVertex, mSceneWindow->localToGlobalCoord(vertexPoint)))
        {
            mNutList[mDragVertex] = getCollisionPointObject(mSceneWindow, mSceneObject, mSceneWindow->localToGlobalCoord(vertexPoint));

            //Round to 6DP
            mNutList[mDragVertex].x = mRound(mNutList[mDragVertex].x);
            mNutList[mDragVertex].y = mRound(mNutList[mDragVertex].y);

            mAddUndo = true;
        }
    }
    return true;
}

It will allow you to move the point along the X (Y) axis even when your mouse extends beyond the Y (X) bounds of the object. For example: In the current build, if you wanted a point lying at (-1, -1), you would need to carefully drag the vertext uptowards the point, ensuring that your mouse never leaves the bounds. It would be often difficult to actually get it to the exact point you need it. In this case, you can drag the point out of the bounds and it will just ensure that it never moves outside of the box.

About the author

Head of Violent Tulip, a small independent software development company working in Wollongong, Australia. Go to http://www.violent-tulip.com/ to see our latest offerings.


#1
03/26/2008 (5:16 pm)
This really ought to make it into the official code base.