Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I use this method to move a single object in 3D space, it accounts for a local offset based on where the cursor ray hits the widget and the center of the widget.

        var cursorRay = cursor.Ray;

        Vector3 goalPosition = translationWidget.GoalPosition;
        Vector3 position = cursorRay.Origin + cursorRay.Direction * grabDistance;

        // Constrain object movement based on selected axis
        switch (translationWidget.AxisSelected)
        {
            case AxisSelected.All: goalPosition = position; break;
            case AxisSelected.None: break;
            case AxisSelected.X: goalPosition.X = position.X; break;
            case AxisSelected.Y: goalPosition.Y = position.Y; break;
            case AxisSelected.Z: goalPosition.Z = position.Z; break;
        }

        translationWidget.GoalPosition = goalPosition;

        Vector3 p = goalPosition - translationWidget.LocalOffset;

        objectSelected.Position = p;

I would like to move multiple objects based on the same principle and using a widget which is located at the average position of all the objects currently selected.

I thought that I would have to translate each object based on their offset from the average point and then include the local offset.

        var cursorRay = cursor.Ray;

        Vector3 goalPosition = translationWidget.GoalPosition;
        Vector3 position = cursorRay.Origin + cursorRay.Direction * grabDistance;

        // Constrain object movement based on selected axis
        switch (translationWidget.AxisSelected)
        {
            case AxisSelected.All: goalPosition = position; break;
            case AxisSelected.None: break;
            case AxisSelected.X: goalPosition.X = position.X; break;
            case AxisSelected.Y: goalPosition.Y = position.Y; break;
            case AxisSelected.Z: goalPosition.Z = position.Z; break;
        }

        translationWidget.GoalPosition = goalPosition;

        Vector3 p = goalPosition - translationWidget.LocalOffset;

        int numSelectedObjects = objectSelectedList.Count;

        for (int i = 0; i < numSelectedObjects; ++i)
        {
            objectSelectedList[i].Position = 
        (objectSelectedList[i].Position - translationWidget.Position) + p;
    }

This doesn't work as the object starts shaking, which I think is because I haven't accounted for the new offset correctly. Where have I gone wrong?

share|improve this question
What's the difference between the translationWidget.GoalPosition and translationWidget.Position? I assume that the latter means the current position and the GoalPosition means the intended position. – Romoku Sep 2 '12 at 21:31
GrabbedPosition would be a better word to describe GoalPosition. It is where the mouse ray collides with the widget. – user1423893 Sep 2 '12 at 21:55

closed as too localized by Byte56, Josh Petrie, Trevor Powell, bummzack, Nick Wiggill Jan 2 at 12:31

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

Browse other questions tagged or ask your own question.