Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Object rotation as opposed to inertial rotation of a point  (Read 1315 times)

0 Members and 1 Guest are viewing this topic.

Weeve

  • Jr. Member
  • **
  • Posts: 87
  • C++ Programmer (Intermediate), 3D Artist (Skilled)
    • View Profile
    • Email
Object rotation as opposed to inertial rotation of a point
« on: February 27, 2012, 12:03:46 am »
Hey, I can't figure out how in the world to get object rotation, but I got inertial rotation down, I was wondering if anyone could explain it better? heres my rotation code on the y axis for inertial (yrot being the value, _Matrix is a member variable for the current rotation) and I wrote it all by hand, so it might be a little unfamiliaure

Code: [Select]
void MeshObject::RotateY(float roty){
    for (unsigned int i=0;i<_verts.size();++i){
        sf::Vector3<float> transform( _verts[i].x - _Position.x, _verts[i].y - _Position.y, _verts[i].z - _Position.z );

        _verts[i] = transform;
    }

    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;

    for (unsigned int i=0;i<_verts.size();++i){
        sf::Vector3<float> transform((XMatrix * _verts[i].x) + (ZMatrix * _verts[i].z) + sf::Vector3<float>(0,_verts[i].y,0));
        _verts[i] = transform;
    }

    for (unsigned int i=0;i<_verts.size();++i){
        sf::Vector3<float> transform( _verts[i].x + _Position.x, _verts[i].y + _Position.y, _verts[i].z + _Position.z );

        _verts[i] = transform;
    }
}
Long live rapid project development! -- Kestrel3D Game-Engine nearing completion

 

anything