Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- QVector3D Plotter3DES::rotateVector(QVector3D reference, QVector3D vector){
- float a,b,y;
- QVector3D aux;
- float size = sqrt(reference.x()*reference.x()+reference.y()*
- reference.y()+reference.z()*reference.z());
- y = M_PI/4;
- a = -acos((reference.x()-reference.y())/(sqrt(2)*size));
- b = asin(reference.z()/(size*sin(a)));
- aux.setX(vector.z()*sin(b)*sin(y) + vector.y()*(cos(a)*cos(b)*sin(y)
- + sin(a)*cos(y)) + vector.x()*(cos(a)*cos(y) - cos(b)*sin(a)*sin(y)));
- aux.setY(vector.z()*sin(b)*cos(y) + vector.y()*(cos(a)*cos(b)*cos(y)
- - sin(a)*sin(y)) - vector.x()*(cos(a)*sin(y) + cos(b)*sin(a)*cos(y)));
- aux.setZ(vector.z()*cos(b) - vector.y()*cos(a)*sin(b) + vector.x()*sin(a)*sin(b));
- return aux;
- }
- void Plotter3DES::plotVector(QVector3D vector){
- glLineWidth(1.5f);
- float size = sqrt(vector.x()*vector.x()+vector.y()*vector.y()+vector.z()*vector.z());
- const int vertexLocation = program.attributeLocation("vertex");
- program.enableAttributeArray(vertexLocation);
- static QVector<GLuint> const idxs = {0,1};
- GLfloat v[6] = {0.f,0.f,0.f,vector.x(),vector.y(),vector.z()};
- program.setUniformValue("color", QColor(Qt::magenta));
- program.setAttributeArray(vertexLocation, v, 3);
- glDrawElements(GL_LINES, idxs.size(), GL_UNSIGNED_INT, idxs.constData());
- QVector3D points[6];
- points[0] = {1.f,0.0,0.0};
- points[1] = {1.f-0.02f,0.01f,0.0};
- points[2] = {1.f-0.02f,0.0,0.01f};
- points[3] = {1.f-0.02f,-0.01f,0.0};
- points[4] = {1.f-0.02f,0.0,-0.01f};
- points[5] = {1.f-0.02f,0.01f,0.0};
- for (int i=0; i<6; i++){
- points[i]=rotateVector(vector,points[i]);
- }
- static GLfloat vectorVertices[18];
- for (int i=0;i<6;i++){
- vectorVertices[3*i]=points[i].x()*size;
- vectorVertices[3*i+1]=points[i].y()*size;
- vectorVertices[3*i+2]=points[i].z()*size;
- }
- program.setAttributeArray(vertexLocation, vectorVertices, 3);
- glDrawArrays(GL_TRIANGLE_FAN, 0, 6);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement