Code:
void Translate(double dx,double dy,double dz)
{
double trans[4][4];
double result[4][4];
trans[0][0]=1.0;
trans[0][1]=0.0;
trans[0][2]=0.0;
trans[0][3]=dx;
trans[1][0]=0.0;
trans[1][1]=1.0;
trans[1][2]=0.0;
trans[1][3]=dy;
trans[2][0]=0.0;
trans[2][1]=0.0;
trans[2][2]=1.0;
trans[2][3]=dz;
trans[3][0]=0.0;
trans[3][1]=0.0;
trans[3][2]=0.0;
trans[3][3]=1.0;
MatMult(trans,master,result);
MatCopy(result,master);
}
//Would be faster for one-dimensional array
void MatMult(double m1[4][4], double m2[4][4], double r[4][4])
{
for (int i=0;i<4;i++)
{
for (int j=0;j<4;j++
{
result[i][j]=((m1[i][0]*m2[0][j])+(m1[i][1]*m2[1][j])+(m1[i][2]*m2[2][j])+(m1[i][3]*m2[3][j]));
}
}
}
void MatCopy(double source[4][4],double target[4][4])
{
for (int i=0;i<4;i++)
{
target[i][0]=source[i][0];
target[i][1]=source[i][1];
target[i][2]=source[i][2];
target[i][3]=source[i][3];
}
}
This is part of my DOS 3D engine setup. Now OpenGL and DirectX both do this stuff for you. Before you transform your object - translate it to where you want it. Then rotate it and transform it.
The -x,-y,-z comes into play when you wish to move your player through the world - translate all objects by the negative vector of the player.