Issues with rotation

Basically, I’m trying to write my own mini engine of sorts and I’m sort of copying the way opengl does things. I’ve written my own gl function (I denote them al) and I’m keeping a model matrix, perspective matrix, and a view matrix. My alScale and alTranslate work perfectly but for some reason my alRotate seems to just translate as well as rotate.

I’ve only defined rotation around the x, y, and z axes and the matrix I multiply my model matrix by upon calling rotate is the following:


Matrix4x4 r = Matrix4x4();
  if (axis == 'x') {
	  r[1][1] = cos(angle);
	  r[1][2] = -sin(angle);
	  r[2][1] = sin(angle);
	  r[2][2] = cos(angle);
  }
  else if (axis == 'y') {
	  r[0][0] = cos(angle);
	  r[0][2] = sin(angle);
	  r[2][0] = -sin(angle);
	  r[2][2] = cos(angle);
  }
  else if (axis == 'z') {
	  r[0][0] = cos(angle);
	  r[0][1] = -sin(angle);
	  r[1][0] = sin(angle);
	  r[1][1] = cos(angle);
  }

  return r;

I ‘think’ I have the math right so I’m not sure what’s going on. I notice that whenever I increase the rotation angle for the x-axis, the y value of the points seem to get smaller…any ideas?

Upon more inspection it seems the math is correct. It is definitely rotating around the x axis but it seems to be rotating around some world x axis or something and not the objects own x axis. This is weird though because I definitely set up the object to be set at the origin so this is weird. But at least this gives me a place to start looking.

The order in which you multiply the matricies is important.
Which way have you done them? You could easily end up with a translation on your rotation if you multiply the wrong way round.