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(); }