// matrix ordering:
// XMatrix(x,y,z) // basically the X vector, and so on
// YMatrix(x,y,z)
// ZMatrix(x,y,z)
void MeshObject::GlobalRotateY(float roty){
float cosy = cos(roty);
float siny = sin(roty);
sf::Vector3<float> XMatrix(cosy,0,-siny);
sf::Vector3<float> ZMatrix(siny,0,cosy);
sf::Vector3<float> XMtransform((XMatrix * _XMatrix.x) + (ZMatrix * _XMatrix.z) + sf::Vector3<float>(0,_XMatrix.y,0));
sf::Vector3<float> ZMtransform((XMatrix * _ZMatrix.x) + (ZMatrix * _ZMatrix.z) + sf::Vector3<float>(0,_ZMatrix.y,0));
_XMatrix = XMtransform;
_ZMatrix = ZMtransform;
PointsToMatrix();
}
This has the odd effect of when the matrix is tilted on the X or Z axis, the code ends up rotating the mesh, but it also skews and squishes it in the process, so I had to have done something wrong.. heres working code for object oriented rotation, that I could easily build myself:
void MeshObject::RotateY(float roty){
for (unsigned int i=0;i<_verts.size();++i){
sf::Vector3<float> transform( _verts.x - _Position.x, _verts.y - _Position.y, _verts.z - _Position.z );
_verts = transform;
}
float cosy = cos(roty);
float siny = sin(roty);
sf::Vector3<float> XMatrix(cosy,0,-siny);
sf::Vector3<float> YMatrix(0,1,0);
sf::Vector3<float> ZMatrix(siny,0,cosy);
XMatrix = sf::Vector3<float> ((_XMatrix * XMatrix.x) + (_YMatrix * XMatrix.y) + (_ZMatrix * XMatrix.z));
YMatrix = sf::Vector3<float> ((_XMatrix * YMatrix.x) + (_YMatrix * YMatrix.y) + (_ZMatrix * YMatrix.z));
ZMatrix = sf::Vector3<float> ((_XMatrix * ZMatrix.x) + (_YMatrix * ZMatrix.y) + (_ZMatrix * ZMatrix.z));
_XMatrix = XMatrix;
_YMatrix = YMatrix;
_ZMatrix = ZMatrix;
PointsToMatrix();
for (unsigned int i=0;i<_verts.size();++i){
sf::Vector3<float> transform( _verts.x + _Position.x, _verts.y + _Position.y, _verts.z + _Position.z );
_verts = transform;
}
}
please help me, I have been having headaches when I try to understand what went wrong, and help will be appreciated ^.^, as it would let me focus on other matters of the program that sorely need attention