Set of Wrapper Functions for SetObjectVisualTransform()

This post comes about because I pm’d somebody regarding the function mentioned in the title of this thread. That reminded me of something from a good while ago. Quite some time ago I mentioned that I had created a set of wrapper functions for the (then) new SetObjectVisualTransform() function. The thing is I can’t remember actually posting them in here. If I have actually posted them before I apologise for repeating myself.

I created these functions for a few of reasons. Firstly, to make it more obvious to those who do not readily know the geometrical terms used to describe the various transforms. This has the added benefit in certain cases of making the code of your functions slightly easier to read. Secondly, because I made all of the functions return a void you can use them with the DelayCommand() function.

Before I actually post the functions here are a few notes.

  • With its name SetObjectVisualTransform(), it should be obvious that this function only affects the visual aspect of an object and not the object itself. So if you paint a bookshelf in an area and do various transforms on it, a PC can walk straight through it because the actual object is still where you painted it.
  • As these functions are so simple I have only checked that there are no syntax errors (i.e. they compile without error). They should work as billed but I make no guarantees.
  • The function DoTransform() is really intended as a private function to be used internally in some of the rest of the functions. While using it should not break anything, I do not recommend doing so as it will make your code less readable.

Code in next post.

TR

Here’s the code

// set of 16 wrapper functions for the SetObjectVisualTransform() function that all 
// return void which means that they can be used with DelayCommand()
// consists of 1 private function and 15 public ones

//
// function prototypes
//

// private function used by both move and rotate functions where more than one 
// direction is to be acted upon.
void DoTransform(object oObject, int nTransform, float fValue);

// Scale() changes the size of an object without changing its location
void Scale(object oObject, float fValue);

// MoveX() moves an object along the X plane
void MoveX(object oObject, float fValueX);

// MoveY() moves an object along the Y plane
void MoveY(object oObject, float fValueY);

// MoveZ() moves an object along the Z plane
void MoveZ(object oObject, float fValueZ);

// MoveXY() moves an object along both the X plane and the Y plane
void MoveXY(object oObject, float fValueX, float fValueY);

// MoveXZ() moves an object along both the X plane and the Z plane
void MoveXZ(object oObject, float fValueX, float fValueZ);

// MoveYZ() moves an object along both the Y plane and the Z plane
void MoveYZ(object oObject, float fValueY, float fValueZ);

// MoveXYZ() moves an object in all 3 planes
void MoveXYZ(object oObject, float fValueX, float fValueY, float fValueZ);

// RotateX() rotates an object about the X axis
void RotateX(object oObject, float fValueX);

// RotateY() rotates an object about the Y axis
void RotateY(object oObject, float fValueY);

// RotateZ() rotates an object about the Z axis
void RotateZ(object oObject, float fValueZ);

// RotateXY() rotates an object about both the X axis and the Y axis
void RotateXY(object oObject, float fValueX, float fValueY);

// RotateXZ() rotates an object about both the X axis and the Z axis
void RotateXZ(object oObject, float fValueX, float fValueZ);

// RotateYZ() rotates an object about both the Y axis and the Z axis
void RotateYZ(object oObject, float fValueY, float fValueZ);

// RotateXYZ() rotates an object about all 3 axes
void RotateXYZ(object oObject, float fValueX, float fValueY, float fValueZ);

//
// Actual functions
//

void DoTransform(object oObject, int nTransform, float fValue)
{
	float fDummy = SetObjectVisualTransform(oObject, nTransform, fValue);
}

void Scale(object oObject, float fValue)
{
	DoTransform(oObject, OBJECT_VISUAL_TRANSFORM_SCALE, fValue);
}

void MoveX(object oObject, float fValueX)
{
	float fDummy = SetObjectVisualTransform(oObject, OBJECT_VISUAL_TRANSFORM_TRANSLATE_X, fValueX);
}

void MoveY(object oObject, float fValueY)
{
	float fDummy = SetObjectVisualTransform(oObject, OBJECT_VISUAL_TRANSFORM_TRANSLATE_Y, fValueY);
}

void MoveZ(object oObject, float fValueZ)
{
	float fDummy = SetObjectVisualTransform(oObject, OBJECT_VISUAL_TRANSFORM_TRANSLATE_Z, fValueZ);
}

void MoveXY(object oObject, float fValueX, float fValueY)
{
	DoTransform(oObject, OBJECT_VISUAL_TRANSFORM_TRANSLATE_X, fValueX);
	DoTransform(oObject, OBJECT_VISUAL_TRANSFORM_TRANSLATE_Y, fValueY);
}

void MoveXZ(object oObject, float fValueX, float fValueZ)
{
	DoTransform(oObject, OBJECT_VISUAL_TRANSFORM_TRANSLATE_X, fValueX);
	DoTransform(oObject, OBJECT_VISUAL_TRANSFORM_TRANSLATE_Z, fValueZ);
}

void MoveYZ(object oObject, float fValueY, float fValueZ)
{
	DoTransform(oObject, OBJECT_VISUAL_TRANSFORM_TRANSLATE_Y, fValueY);
	DoTransform(oObject, OBJECT_VISUAL_TRANSFORM_TRANSLATE_Z, fValueZ);
}

void MoveXYZ(object oObject, float fValueX, float fValueY, float fValueZ)
{
	DoTransform(oObject, OBJECT_VISUAL_TRANSFORM_TRANSLATE_X, fValueX);
	DoTransform(oObject, OBJECT_VISUAL_TRANSFORM_TRANSLATE_Y, fValueY);
	DoTransform(oObject, OBJECT_VISUAL_TRANSFORM_TRANSLATE_Z, fValueZ);
}

void RotateX(object oObject, float fValueX)
{
	float fDummy = SetObjectVisualTransform(oObject, OBJECT_VISUAL_TRANSFORM_ROTATE_X, fValueX);
}

void RotateY(object oObject, float fValueY)
{
	float fDummy = SetObjectVisualTransform(oObject, OBJECT_VISUAL_TRANSFORM_ROTATE_Y, fValueY);
}

void RotateZ(object oObject, float fValueZ)
{
	float fDummy = SetObjectVisualTransform(oObject, OBJECT_VISUAL_TRANSFORM_ROTATE_Z, fValueZ);
}

void RotateXY(object oObject, float fValueX, float fValueY)
{
	DoTransform(oObject, OBJECT_VISUAL_TRANSFORM_ROTATE_X, fValueX);
	DoTransform(oObject, OBJECT_VISUAL_TRANSFORM_ROTATE_Y, fValueY);
}

void RotateXZ(object oObject, float fValueX, float fValueZ)
{
	DoTransform(oObject, OBJECT_VISUAL_TRANSFORM_ROTATE_X, fValueX);
	DoTransform(oObject, OBJECT_VISUAL_TRANSFORM_ROTATE_Z, fValueZ);
}

void RotateYZ(object oObject, float fValueY, float fValueZ)
{
	DoTransform(oObject, OBJECT_VISUAL_TRANSFORM_ROTATE_Y, fValueY);
	DoTransform(oObject, OBJECT_VISUAL_TRANSFORM_ROTATE_Z, fValueZ);
}

void RotateXYZ(object oObject, float fValueX, float fValueY, float fValueZ)
{
	DoTransform(oObject, OBJECT_VISUAL_TRANSFORM_ROTATE_X, fValueX);
	DoTransform(oObject, OBJECT_VISUAL_TRANSFORM_ROTATE_Y, fValueY);
	DoTransform(oObject, OBJECT_VISUAL_TRANSFORM_ROTATE_Z, fValueZ);
}

Hope this is of use to somebody.

TR

1 Like