Game Development Reference
In-Depth Information
public void SetScale(double x, double y)
{
double oldX = _positionX;
double oldY = _positionY;
SetPosition(0, 0);
Matrix mScale = new Matrix();
mScale.SetScale(new Vector(_scaleX, _scaleY, 1));
mScale = mScale.Inverse();
ApplyMatrix(mScale);
mScale = new Matrix();
mScale.SetScale(new Vector(x, y, 1));
ApplyMatrix(mScale);
SetPosition(oldX, oldY);
_scaleX = x;
_scaleY = y;
}
public void SetRotation(double rotation)
{
double oldX = _positionX;
double oldY = _positionY;
SetPosition(0, 0);
Matrix mRot = new Matrix();
mRot.SetRotate(new Vector(0, 0, 1), _rotation);
ApplyMatrix(mRot.Inverse());
mRot = new Matrix();
mRot.SetRotate(new Vector(0, 0, 1), rotation);
ApplyMatrix(mRot);
SetPosition(oldX, oldY);
_rotation = rotation;
}
These extra functions allow the sprite to be rotated and scaled as needed. They
are a little more expensive, but it's very easy to transfer these functions to a 3D
model. These functions can be trimmed down quite a bit to gain a performance
boost.
Optimization
It's important to focus on games and only optimize when it's needed. For most
games, the matrix class is already as fast as it needs to be, but programmers, as a
 
Search WWH ::




Custom Search