Original Post
Hey everybody, I have the following code to rotate a point around the Y axis of the origin: //rotate point "x, z" around Y at the origin by "a" degrees void Player::rotateAroundY(float &x, float &z, float a) { float cosa = cos(a); float sina = sin(a); float ax = x; float az = z; x = ((az * sina) + (ax * cosa)); z = ((az * cosa) - (ax * sina)); }; This is how it is being called in my test code (Simply to draw out the hitbox visibly so I can test my collision detection (which works, aside from factoring in this broken rotation)) glBegin(GL_LINE_LOOP); for (vertexVector::iterator vertex = m_helihitpoints.begin(); vertex != m_helihitpoints.end(); vertex++) { float xa = vertex->x; float ya = vertex->y; float za = vertex->z; rotateAroundY(xa, za, m_yRotation); glVertex3f(xa, ya, za); } glEnd(); (m_helihitpoints is a vector containing the vertices of the hitbox, m_yRotation is a value between 0 and 359.999.. etc.) Okay so the problems are as follows: Firstly, the points seem to rotate smoothly although at some 60 times the desired amount, (that is, it performs one whole rotation for every increment of m_yRotation by 6 (not the desired 1 rotation for 360 degrees)) and secondly (probably tied in) I would have thought that 0 degrees and 360 degrees would provide the same result? As it stands, when m_yRotation loops back from 0 to 359.99 or forward from 359.99 to 0, the resulting rotation jumps about 30 degrees in an instant... Maths isn't my strongest point, and I'm sure I'm either doing it wrong or it's something trivial. Sorry if this hasn't been the best explanation, been working on it for a bit too long now and my brain has kind of gone kaput. Please don't hesitate to ask any questions if you don't understand what I'm going on about!! Many thanks, Ross