void GLWidget::resizeGL(int w, int h) { width = w; height = h; radius = min(width, height) * .75; float aspect = (float)w/h; projMatrix = perspective(45.0f, aspect, 1.0f, 100.0f); viewMatrix = lookAt(vec3(0,0,-10),vec3(0,0,0),vec3(0,1,0)); modelMatrix = mat4(1.0f); glUseProgram(cubeProg); glUniformMatrix4fv(cubeProjMatrixLoc, 1, false, value_ptr(projMatrix)); glUniformMatrix4fv(cubeViewMatrixLoc, 1, false, value_ptr(viewMatrix)); glUniformMatrix4fv(cubeModelMatrixLoc, 1, false, value_ptr(modelMatrix)); glUniformMatrix4fv(cubeRotationMatrixLoc, 1, false, value_ptr(rotationMatrix)); glUseProgram(gridProg); glUniformMatrix4fv(gridProjMatrixLoc, 1, false, value_ptr(projMatrix)); glUniformMatrix4fv(gridViewMatrixLoc, 1, false, value_ptr(viewMatrix)); glUniformMatrix4fv(gridModelMatrixLoc, 1, false, value_ptr(modelMatrix)); glUniformMatrix4fv(gridRotationMatrixLoc, 1, false, value_ptr(rotationMatrix)); }
void easygl::draw() { // update camera //vec3 direction = rotate(orientation, vec3(0, 0, -1)); //vec3 direction = rotate(quat(0,0,0,0), vec3(0, 0, -1)); position = vec3(5.0f, 5.0f, 5.0f) + (movement.z * direction + movement.x * right - movement.y * up); target = position + direction; modelview = lookAt(position, target, up); projection = perspective(fieldOfView, aspectRatio, near, far); glViewport(0,0, viewportSize.x, viewportSize.y); if(viewportSize.y == 0) viewportSize.y = 1; aspectRatio = (float)viewportSize.x / (float)viewportSize.y; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glClearColor(0.0f,0.0f,0.0f,0.0f); //glEnable(GL_CULL_FACE); //glEnable(GL_LINE_SMOOTH); //glLineWidth(1.0f); // camera glMatrixMode(GL_PROJECTION); glLoadIdentity(); glLoadMatrixf(value_ptr(projection)); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glLoadMatrixf(value_ptr(modelview)); // light glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_POSITION, value_ptr(vec4(0.6f, 0.7f, 0.7f, 0.0f))); glLightfv(GL_LIGHT0, GL_AMBIENT, value_ptr(vec4(0.1f, 0.1f, 0.1f, 1.0f))); glLightfv(GL_LIGHT0, GL_DIFFUSE, value_ptr(vec4(1.0f, 0.9f, 0.8f, 1.0f))); glLightfv(GL_LIGHT0, GL_SPECULAR, value_ptr(vec4(1.0f, 1.0f, 1.0f, 1.0f))); // scene //drawGrid(); //drawRobot(); drawAxis(); //drawPath(); glColor3f(0.3f, 0, 0); glBegin(GL_QUADS); glVertex3f(d.min.x/10, d.min.y/10, -0.01f); glVertex3f(d.min.x/10, d.max.y/10, -0.01f); glVertex3f(d.max.x/10, d.max.y/10, -0.01f); glVertex3f(d.max.x/10, d.min.y/10, -0.01f); glEnd(); glBegin(GL_LINES); for(layer &l : d.layers){ for(contur &c : l.conts){ if(c.ctype == contur::toolpath || c.ctype == contur::input) displaycontour(&c); } } glEnd(); glFlush(); }
void easygl::drawBox(GLdouble width, GLdouble height, GLdouble depth) { const GLfloat vertices[8][3] = { {1.0, 1.0, 1.0}, {1.0, -1.0, 1.0}, {-1.0, -1.0, 1.0}, {-1.0, 1.0, 1.0}, {1.0, 1.0, -1.0}, {1.0, -1.0, -1.0}, {-1.0, -1.0, -1.0}, {-1.0, 1.0, -1.0} }; const GLfloat normals[6][3] = { {0.0, 0.0, 1.0}, {-1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, -1.0}}; const short faces[6][4] = { {3, 2, 1, 0}, {2, 3, 7, 6}, {0, 1, 5, 4}, {3, 0, 4, 7}, {1, 2, 6, 5}, {4, 5, 6, 7} }; glEnable(GL_LIGHTING); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, value_ptr(vec4(0.5f, 0.5f, 1.0f, 1.0f))); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, value_ptr(vec4(0.0f, 0.0f, 0.0f, 1.0f))); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 2.0f); glPushMatrix(); glTranslatef(0, height/2, 0); glScalef(width/2, height/2, depth/2); glBegin(GL_QUADS); for(int f = 0; f < 6; f++) { glNormal3fv(normals[f]); for(int i = 0; i < 4; i++) glVertex3fv(vertices[faces[f][i]]); } glEnd (); glPopMatrix(); glDisable(GL_LIGHTING); }
void GLWidget::mouseMoveEvent(QMouseEvent *event) { last.x = event->x(); last.y = event->y(); vec3 begin = pointOnVirtualTrackball(first); vec3 end = pointOnVirtualTrackball(last); float dotProduct = dot(normalize(begin), normalize(end)); float angle = acos(dotProduct); vec3 crossP = cross(begin, end); if(length(crossP) > .00001f) { rotationMatrix = rotate(mat4(1.0), angle, normalize(crossP)) * rotationMatrix; glUseProgram(cubeProg); glUniformMatrix4fv(cubeRotationMatrixLoc, 1, false, value_ptr(rotationMatrix)); glUseProgram(gridProg); glUniformMatrix4fv(gridRotationMatrixLoc, 1, false, value_ptr(rotationMatrix)); update(); } first.x = last.x; first.y = last.y; }
void Render::vector( const glm::vec3& vec, const glm::vec3& point , const glm::vec4& color/*=glm::vec4(1,1,1,1)*/ ) { glColor4fv(value_ptr(color)); glBegin(GL_LINES); glVertex3fv(value_ptr(point)); glVertex3fv(value_ptr(point + vec)); glEnd(); glBegin(GL_POINTS); glVertex3fv(value_ptr(point + vec)); glEnd(); glColor4f(1,1,1,1); }