c++ - Rotate points openGL -


i've trying generate figures revolution reading profile of figure ply. follow steps here , other similar questioons, problem persist. when try rotate ply 2 points 36 stesps if puth camara on top cilinder:

cilinder ply

my code after revision of method rotate is:

void figura::rotatey(int ngiros){ //variables de rotacion.   //double alfa = 2*m_pi/ngiros;   int long_perfil = vertices.size();    vector<_vertex3f> new_vertices;    cout << long_perfil << " vertices" << endl;    _vertex3f aux1, aux2;   for(int i=0; < ngiros; i++){      double alfa = (2*m_pi/ngiros)*i;      for(int j=0;  j < long_perfil; j++){          aux1 = vertices.at(j);          aux1._0 = (cos(alfa) * aux1._0) + (sin(alfa) * aux1._2);          aux1._2 = (cos(alfa) * aux1._2) - (sin(alfa) * aux1._0);        vertices.push_back(aux1);     }   }    //vertices.clear();   //vertices = new_vertices;    //caras   for(int i=0; < vertices.size(); i++){      _vertex3i aux(i, i+1, i+long_perfil);      _vertex3i aux2(i, i+long_perfil+1, i+1);      caras.push_back(aux);      caras.push_back(aux2);      }    } } 

i can't find error. welcome.

it looks you're unclear on coordinate system original curve in, , how you're applying rotation it. current code, you're rotating points variable amount, keep them within same plane. can tell looking @ code superficially: never set value y-coordinate of of points, whole result not 3d shape, entirely in y=0 plane. flat pancake...

another thing need careful don't modify values while you're still using old value:

     aux1._0 = (cos(alfa) * aux1._0) + (sin(alfa) * aux1._2);      aux1._2 = (cos(alfa) * aux1._2) - (sin(alfa) * aux1._0); 

here, you're modifying value of aux1._0 in first statement, while second statement should in fact still use old value.

let's original curve in x/y-plane, , want rotate around y-axis. result in nice 3d shape, x-coordinates of curve should positive:

     ^ y      |      |--      |  \      |   \_      |     |   x --------------->      |     |      |    /      |   /      | _/      |/ 

picture z-axis pointing out of screen.

now, rotate curve given angle alpha around y-axis, leave y-coordinate unchanged, , rotate point (x, 0) alpha within xz-plane new values x , z. new coordinates (x', y', z') input point (x, y) of shape then:

x' = x * cos(alpha) y' = y z' = x * sin(alpha) 

as modified version of code:

for(int i=0; < ngiros; i++){     double alfa = (2*m_pi/ngiros)*i;     for(int j=0;  j < long_perfil; j++){         aux1 = vertices.at(j);         aux2._0 = cos(alfa) * aux1._0;         aux2._1 = aux1._1;         aux2._2 = sin(alfa) * aux1._0;          vertices.push_back(aux2);     } } 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -