Camera& Camera::stereo(float _c, float _e) { isStereo = true; _convergence = _c; _eyeSep = _e; float top, bottom, leftL, rightL, leftR, rightR; top = nearPlane * tan(radians(fovy)/2); bottom = -top; float a = aspect * tan(radians(fovy)/2) * convergence(); float b = a - eyeSep()/2; float c = a + eyeSep()/2; leftR = -c * nearPlane/convergence(); rightR = b * nearPlane/convergence(); leftL = -b * nearPlane/convergence(); rightL = c * nearPlane/convergence(); //rightProjection = Matrix4f::perspective(leftR, rightR, bottom, top, nearPlane, farPlane ); //rightTranslate = Matrix4f::translate( -eyeSep/2, 0.0f, 0.0f ); //leftProjection = Matrix4f::perspective(leftL, rightL, bottom, top, nearPlane, farPlane ); //leftTranslate = Matrix4f::translate( eyeSep/2, 0.0f, 0.0f ); rightProjection = glm::frustum(leftR, rightR, bottom, top, nearPlane, farPlane ); rightTranslate = glm::translate(mat4(1.0), vec3(-eyeSep()/2, 0.0f, 0.0f) ); leftProjection = glm::frustum(leftL, rightL, bottom, top, nearPlane, farPlane ); leftTranslate = glm::translate(mat4(1.0), vec3(eyeSep()/2, 0.0f, 0.0f) ); isTransformed = true; return *this; }
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 importanceSampleLight(vec3 pt, materialLayer* ml, vec3 norm, vec2 uv, vec3 oDir, vec3* ret_iDir, color* ret_weight) { float r1, r2; r1 = nrand(); r2 = nrand(); vec3 x2 = vec3(3 * r1 - 1.5, 6, 12 * r2 - 6); vec3 dirXtoX2 = x2 - pt; vec3 iDir = normalize(x2 - pt); vec3 norm2 = vec3(0, -1, 0); float prob = 1.f / (3.f * 12.f); float cosAngle = dot(norm, iDir); float cosAngle2 = dot(norm2, -iDir); float G = max(0.001, cosAngle2) / dot(dirXtoX2, dirXtoX2); color brdf = BRDF(ml, norm, uv.x, uv.y, oDir, iDir); int chi = dot(norm, norm2) < 0 ? 1 : 0; *ret_iDir = iDir; //*ret_pdf = max(0.001f, prob / G); *ret_weight = brdf * chi * max(0.001, cosAngle2) / (dot(dirXtoX2, dirXtoX2) * prob); }
void Scene::setProjection() { _proj = glm::perspective(_fov, float(_width) / float(_height), _depthMin, _depthMax); glViewport(0, 0, _width, _height); // Set the size for the settings quad float size = 0.03; float qWidth = size; float aspectRatio = float(_width) / float(_height); float qHeight = size * aspectRatio; float qTransX = 1.0 - qWidth - size * 0.5; float qTransY = -1.0 + qHeight + size * 0.5; mat4 qScale = glm::scale(mat4(), vec3(qWidth, qHeight, 1.0)); mat4 qTrans = glm::translate(mat4(), vec3(qTransX, qTransY, 0)); _settingsIconModel = qTrans * qScale; qScale = glm::scale(mat4(), vec3(1.0 / qWidth, 1.0 / qHeight, 1.0)); qTrans = glm::translate(mat4(), vec3(-qTransX, -qTransY, 1.0)); _settingsIconModelInv = qScale * qTrans; }
void SceneBasic_Uniform::render() { glClear(GL_COLOR_BUFFER_BIT); rotationMatrix = glm::rotate(mat4(1.0f), angle, vec3(0.0f,0.0f,1.0f)); GLuint location = glGetUniformLocation(programHandle, "RotationMatrix"); if( location >= 0 ) { glUniformMatrix4fv(location, 1, GL_FALSE, &rotationMatrix[0][0]); } glBindVertexArray(vaoHandle); glDrawArrays(GL_TRIANGLES, 0, 3 ); }
void SceneSpot::render() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); vec4 lightPos = vec4(10.0f * cos(angle), 10.0f, 10.0f * sin(angle), 1.0f); prog.setUniform("Spot.position", view * lightPos); mat3 normalMatrix = mat3( vec3(view[0]), vec3(view[1]), vec3(view[2]) ); prog.setUniform("Spot.direction", normalMatrix * vec3(-lightPos) ); prog.setUniform("Kd", 0.9f, 0.5f, 0.3f); prog.setUniform("Ks", 0.95f, 0.95f, 0.95f); prog.setUniform("Ka", 0.9f * 0.3f, 0.5f * 0.3f, 0.3f * 0.3f); prog.setUniform("Shininess", 100.0f); model = mat4(1.0f); model *= glm::translate(vec3(0.0f,0.0f,-2.0f)); model *= glm::rotate(45.0f, vec3(0.0f,1.0f,0.0f)); model *= glm::rotate(-90.0f, vec3(1.0f,0.0f,0.0f)); setMatrices(); teapot->render(); prog.setUniform("Kd", 0.9f, 0.5f, 0.3f); prog.setUniform("Ks", 0.95f, 0.95f, 0.95f); prog.setUniform("Ka", 0.9f * 0.3f, 0.5f * 0.3f, 0.3f * 0.3f); prog.setUniform("Shininess", 100.0f); model = mat4(1.0f); model *= glm::translate(vec3(-1.0f,0.75f,3.0f)); model *= glm::rotate(-90.0f, vec3(1.0f,0.0f,0.0f)); setMatrices(); torus->render(); prog.setUniform("Kd", 0.7f, 0.7f, 0.7f); prog.setUniform("Ks", 0.9f, 0.9f, 0.9f); prog.setUniform("Ka", 0.2f, 0.2f, 0.2f); prog.setUniform("Shininess", 180.0f); model = mat4(1.0f); setMatrices(); plane->render(); }
void SceneDiffuse::initScene() { cout << "Compiling Shaders" << endl; compileAndLinkShader(); glEnable(GL_DEPTH_TEST); if (loadCamMatFlag){ cout << "Loading Camera Matrices: "; camMatVec = new vector<mat4>(); //glm::mat4 camMatrix; loadCameraMatrices("cameraMatrix.txt", camMatVec); cout << camMatVec->size() << " matrices"<<endl; view = (*camMatVec)[0]; //view = glm::lookAt(vec3(0.0f, 0.0f, 2.0f), vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 1.0f, 0.0f)); } else{ view = glm::lookAt(vec3(0.0f, 0.0f, 2.0f), vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 1.0f, 0.0f)); //view = glm::mat4(1.0f); } cout << "Loading Mesh" << endl; //ogre = new VBOMesh("../media/bs_ears.obj", true, false, false); ogre = new VBOMesh("C:\\Android&BMO.obj", true, false, false); //torus = new VBOTorus(0.7f, 0.3f, 30, 30); model = mat4(1.0f); //view = glm::lookAt(vec3(0.0f, 0.0f, 2.0f), vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 1.0f, 0.0f)); projection = mat4(1.0f); prog.setUniform("Kd", 0.9f, 0.5f, 0.3f); prog.setUniform("Ld", 1.0f, 1.0f, 1.0f); prog.setUniform("LightPosition", view * vec4(5.0f, 5.0f, 2.0f, 1.0f)); }
void Agent::Update(float delta) { vec3 testInput = vec3(m_position.x, m_position.y, 0); m_clock += delta; m_memoryClock += delta; float memoryFrequency = 1.f; if (m_memoryClock > memoryFrequency) { m_memoryClock -= memoryFrequency; vec3 testInput = vec3(m_position.x, m_position.y, 0); AddToMemory(testInput); m_neuralNetwork->TrainNetwork(m_memory); } m_position += m_velocity * delta; if (CheckBounds()) { m_facingDirection = 44.f / 7.f * (float)((rand() % 1000) / 1000.f); m_velocity.x = m_maxSpeed * sin(m_facingDirection); m_velocity.y = m_maxSpeed * cos(m_facingDirection); } m_neuralNetwork->RenderDebug(vec2(30, 30), 200, m_memory); m_foodClock--; m_waterClock--; }
void SceneDirectional::render() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); prog.setUniform("Kd", 0.8f, 0.8f, 0.8f); prog.setUniform("Ks", 0.9f, 0.9f, 0.9f); prog.setUniform("Ka", 0.1f, 0.1f, 0.1f); prog.setUniform("Shininess", 180.0f); model = mat4(1.0f); model *= glm::rotate(glm::radians(90.0f), vec3(0.0f,1.0f,0.0f)); setMatrices(); torus->render(); prog.setUniform("Kd", 0.4f, 0.4f, 0.4f); prog.setUniform("Ks", 0.9f, 0.9f, 0.9f); prog.setUniform("Ka", 0.1f, 0.1f, 0.1f); prog.setUniform("Shininess", 180.0f); model = mat4(1.0f); model *= glm::translate(vec3(0.0f,-0.45f,0.0f)); setMatrices(); //plane->render(); }
vec3 randRayInSphere() { float rx = 0, ry = 0, rz = 0; // technically, this is faster, sooooo :P while (rx*rx + ry*ry + rz*rz <= 1.0f) { rx = 2 * nrand() - 1.0f; ry = 2 * nrand() - 1.0f; rz = 2 * nrand() - 1.0f; if (rx*rx + ry*ry + rz*rz >= 0.98f) continue; break; } return normalize(vec3(rx, ry, rz)); }
void SceneRefractCube::render() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); vec3 cameraPos = vec3( 7.0f * cos(angle), 2.0f, 7.0f * sin(angle)); view = glm::lookAt(cameraPos, vec3(0.0f,0.0f,0.0f), vec3(0.0f,1.0f,0.0f)); prog.setUniform("WorldCameraPosition", cameraPos); //view = glm::lookAt(vec3(0.0f,2.0f,0.0f), vec3(0.0f,0.0f,0.0f), vec3(0.0f,0.0f,1.0f)); prog.setUniform("DrawSkyBox", true); model = mat4(1.0f); setMatrices(); sky->render(); prog.setUniform("DrawSkyBox", false); prog.setUniform("Material.Eta", 0.94f); prog.setUniform("Material.ReflectionFactor", 0.1f); model = mat4(1.0f); model *= glm::translate(vec3(0.0f,-1.0f,0.0f)); model *= glm::rotate(-90.0f, vec3(1.0f,0.0f,0.0f)); setMatrices(); teapot->render(); }
void My_OpenGLWidget::paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /************* If new attributes/uniforms are added, make sure they are set up here *********/ mat4 modelMatrix = glm::rotate(glm::rotate(downAngle, vec3(1.0f, 0.0f, 0.0f)), leftAngle, vec3(0.0f, 1.0f, 0.0f)); mat4 projMatrix = projectionMatrix * cameraMatrix; glUniformMatrix4fv(modelMatrixLocation, 1, GL_FALSE, &modelMatrix[0][0]); glUniformMatrix4fv(viewMatrixLocation, 1, GL_FALSE, &projMatrix[0][0]); glUniform4f(camVecLocation,camLocation.x, camLocation.y, camLocation.z, 1.0f); sg->traverse(cameraMatrix );//traverse the scene graph sg->draw(vLocation, vNormal, vShiny, cLocation, vbo, vbo2, vbo3, cbo); }
void SceneTessTeapotDepth::initScene() { compileAndLinkShader(); glClearColor(0.5f,0.5f,0.5f,1.0f); glEnable(GL_DEPTH_TEST); teapot = new VBOTeapotPatch(); ///////////// Uniforms //////////////////// prog.setUniform("MinTessLevel", 2); prog.setUniform("MaxTessLevel", 15); prog.setUniform("MaxDepth", 20.0f); prog.setUniform("MinDepth", 2.0f); prog.setUniform("LineWidth", 0.8f); prog.setUniform("LineColor", vec4(0.05f,0.0f,0.05f,1.0f)); prog.setUniform("LightPosition", vec4(0.0f,0.0f,0.0f,1.0f)); prog.setUniform("LightIntensity", vec3(1.0f,1.0f,1.0f)); prog.setUniform("Kd", vec3(0.9f, 0.9f, 1.0f)); ///////////////////////////////////////////// glPatchParameteri(GL_PATCH_VERTICES, 16); }
void easygl::init() { target = vec3(0, 1, 0); up = vec3(0, 1, 0); orientation = quat(); direction = vec3(0, 0, -1); right = cross(up, direction); up = cross(direction, right); position = vec3(5.0f, 5.0f, 5.0f); fieldOfView = 60.0f; near = 0.1f, far = 1000.0f; aspectRatio = 1.0; dragl = false; dragr = false; //sphere.load("sphere.stl", vec4(1.0f, 0.0f, 1.0f, 1.0f)); for(layer &l : d.layers){ l.findcontours(); l.offset(1); l.show(); } }
void display() { static float angle = 0.0; angle +=0.5; glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); shader->begin(); /// init shader data glm::vec3 eyePos = glm::vec3(0.0,0.0,3.0); // init light in the scene glm::vec3 lightPos = glm::vec3(0.0,0.0,1.0); vec3 La = vec3(0.5,0.5,0.5); vec3 Ld = vec3(1.0,1.0,1.0); vec3 Ls = vec3(1.0,1.0,1.0); // init model material vec3 Ka = vec3(0.2,0.2,0.2); vec3 Kd = vec3(1.0,1.0,1.0); vec3 Ks = vec3(1.0,1.0,1.0); float shiness = 5.0; glm::mat4 projection_matrix = glm::perspective(45.0f,(float)width/height,1.0f,1000.0f); glm::mat4 view_matrix = glm::lookAt(eyePos,glm::vec3(0.0),glm::vec3(0.0,1.0,0.0)); view_matrix = glm::rotate(view_matrix,xAngle,glm::vec3(0.0,1.0,0.0)); view_matrix = glm::rotate(view_matrix,yAngle,glm::vec3(1.0,0.0,0.0)); glm::mat4 model_matrix = glm::rotate(glm::mat4(1.0),angle,glm::vec3(0.0,1.0,0.0)); model_matrix = glm::translate(model_matrix,glm::vec3(0.0,0.0,0)); /// populate shader data to shader shader->setUniform("eyePos",eyePos); // for light shader->setUniform("light.position",lightPos); shader->setUniform("light.La",La); shader->setUniform("light.Ld",Ld); shader->setUniform("light.Ls",Ls); // for material shader->setUniform("mat.Ka",Ka); shader->setUniform("mat.Kd",Kd); shader->setUniform("mat.Ks",Ks); shader->setUniform("mat.shiness",shiness); shader->setUniform("view_matrix",view_matrix); shader->setUniform("projection_matrix",projection_matrix); shader->setUniform("model_matrix",model_matrix); model->draw(); model_matrix = glm::translate(glm::mat4(1.0),lightPos); shader->setUniform("model_matrix",model_matrix); glutWireSphere(0.2,10,10); glutSwapBuffers(); }
void SceneToon::render() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); projection = glm::perspective(60.0f, (float)width/height, 0.3f, 100.0f); vec4 lightPos = vec4(10.0f * cos(angle), 10.0f, 10.0f * sin(angle), 1.0f); prog.setUniform("Light.position", view * lightPos); prog.setUniform("Kd", 0.9f, 0.5f, 0.3f); prog.setUniform("Ka", 0.9f * 0.3f, 0.5f * 0.3f, 0.3f * 0.3f); model = mat4(1.0f); model *= glm::translate(vec3(0.0f,0.0f,-2.0f)); model *= glm::rotate(45.0f, vec3(0.0f,1.0f,0.0f)); model *= glm::rotate(-90.0f, vec3(1.0f,0.0f,0.0f)); setMatrices(); teapot->render(); prog.setUniform("Kd", 0.9f, 0.5f, 0.3f); prog.setUniform("Ka", 0.9f * 0.3f, 0.5f * 0.3f, 0.3f * 0.3f); model = mat4(1.0f); model *= glm::translate(vec3(-1.0f,0.75f,3.0f)); model *= glm::rotate(-90.0f, vec3(1.0f,0.0f,0.0f)); setMatrices(); torus->render(); prog.setUniform("Kd", 0.7f, 0.7f, 0.7f); prog.setUniform("Ka", 0.2f, 0.2f, 0.2f); model = mat4(1.0f); setMatrices(); plane->render(); }
void SceneADS::initScene() { compileAndLinkShader(); glEnable(GL_DEPTH_TEST); torus = new VBOTorus(0.7f, 0.3f, 50, 50); model = mat4(1.0f); model *= glm::rotate(glm::radians(-35.0f), vec3(1.0f,0.0f,0.0f)); model *= glm::rotate(glm::radians(35.0f), vec3(0.0f,1.0f,0.0f)); view = glm::lookAt(vec3(0.0f,0.0f,2.0f), vec3(0.0f,0.0f,0.0f), vec3(0.0f,1.0f,0.0f)); projection = mat4(1.0f); vec4 worldLight = vec4(5.0f,5.0f,2.0f,1.0f); prog.setUniform("Material.Kd", 0.9f, 0.5f, 0.3f); prog.setUniform("Light.Ld", 1.0f, 1.0f, 1.0f); prog.setUniform("Light.Position", view * worldLight ); prog.setUniform("Material.Ka", 0.9f, 0.5f, 0.3f); prog.setUniform("Light.La", 0.4f, 0.4f, 0.4f); prog.setUniform("Material.Ks", 0.8f, 0.8f, 0.8f); prog.setUniform("Light.Ls", 1.0f, 1.0f, 1.0f); prog.setUniform("Material.Shininess", 100.0f); }
void SceneJitter::render() { // Pass 1 (shadow map generation) view = lightFrustum->getViewMatrix(); projection = lightFrustum->getProjectionMatrix(); glBindFramebuffer(GL_FRAMEBUFFER, shadowFBO); glClear(GL_DEPTH_BUFFER_BIT); glViewport(0,0,shadowMapWidth,shadowMapHeight); glUniformSubroutinesuiv( GL_FRAGMENT_SHADER, 1, &pass1Index); glEnable(GL_CULL_FACE); glCullFace(GL_FRONT); glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(2.5f,10.0f); drawBuildingScene(); glDisable(GL_POLYGON_OFFSET_FILL); // Pass 2 (render) // vec3 cameraPos(11.5f * cos(angle),7.0f,11.5f * sin(angle)); // view = glm::lookAt(cameraPos,vec3(0.0f),vec3(0.0f,1.0f,0.0f)); // prog.setUniform("Light.Position", view * vec4(lightPos,1.0f)); // projection = glm::perspective(50.0f, (float)width/height, 0.1f, 100.0f); vec3 cameraPos(1.8f * cos(angle),0.7f,1.8f * sin(angle)); view = glm::lookAt(cameraPos,vec3(0.0f,-0.175f,0.0f),vec3(0.0f,1.0f,0.0f)); prog.setUniform("Light.Position", view * vec4(lightFrustum->getOrigin(),1.0)); projection = glm::perspective(50.0f, (float)width/height, 0.1f, 100.0f); glBindFramebuffer(GL_FRAMEBUFFER, 0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glViewport(0,0,width,height); glUniformSubroutinesuiv( GL_FRAGMENT_SHADER, 1, &pass2Index); glDisable(GL_CULL_FACE); drawBuildingScene(); glFinish(); }
void SceneMultiLight::render() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); prog.setUniform("Kd", 0.4f, 0.4f, 0.4f); prog.setUniform("Ks", 0.9f, 0.9f, 0.9f); prog.setUniform("Ka", 0.1f, 0.1f, 0.1f); prog.setUniform("Shininess", 180.0f); model = mat4(1.0f); model *= glm::rotate(90.0f, vec3(0.0f,1.0f,0.0f)); setMatrices(); mesh->render(); prog.setUniform("Kd", 0.1f, 0.1f, 0.1f); prog.setUniform("Ks", 0.9f, 0.9f, 0.9f); prog.setUniform("Ka", 0.1f, 0.1f, 0.1f); prog.setUniform("Shininess", 180.0f); model = mat4(1.0f); model *= glm::translate(vec3(0.0f,-0.45f,0.0f)); setMatrices(); plane->render(); }
void Bullet::update(float delta) { age += delta; if (flying) { // Wind and gravity. velocity += delta*vec3(0.0f, -1.0f, -6.0f); // Apply friction. velocity *= 0.99f; rotation.x = glm::atan(velocity.z, velocity.y); } // Update position; position += delta*velocity; }
void easygl::movemouse(double x, double y){ mouse = ivec2(x, y); vec3 screen=vec3(x,viewportSize.y - y,zbuf); vec3 pos= unProject(screen,dragmodelview,projection,vec4(0,0, viewportSize.x, viewportSize.y)); glmouse = vec2(pos.x,pos.y); if(dragl && screen.z != 1) { vec2 gldiff = (gllastmouse - glmouse); movement -= glm::vec3(gldiff,0); }else{ dragmodelview = modelview; glReadPixels(x,viewportSize.y - y,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&zbuf); } gllastmouse = glmouse; lastMouse = mouse; }
vec3 Line::Intersection(Line &l1, Line &l2, float Epsilon) { vec3 point1, point2; Line::ClosestPointsOnTwoLines(l1, l2, point1, point2); if(Epsilon > Line::DistanceTwoPoints(point1, point2)) { l2.m_numberOfIntersections += 1; l2.found = true; return Line::AveragePoint(point1, point2); } else { return vec3(0.0f,0.0f,0.0f); } }
void SceneParticlesFeedback::initScene() { compileAndLinkShader(); GLuint programHandle = prog.getHandle(); renderSub = glGetSubroutineIndex(programHandle, GL_VERTEX_SHADER, "render"); updateSub = glGetSubroutineIndex(programHandle, GL_VERTEX_SHADER, "update"); glClearColor(0.1f,0.1f,0.1f,0.0f); //glEnable(GL_PROGRAM_POINT_SIZE); glPointSize(10.0f); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); plane = new VBOPlane(13.0f, 10.0f, 200, 2); projection = mat4(1.0f); angle = PI / 2.0f; model = mat4(1.0f); initBuffers(); glGenQueries(1, &query); const char * texName = "texture/bluewater.png"; QImage img(texName, "PNG"); QImage texImg = QGLWidget::convertToGLFormat(img); // Copy texture to OpenGL GLuint texID; glGenTextures(1,&texID); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texID); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texImg.width(), texImg.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, texImg.bits()); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); prog.setUniform("ParticleTex", 0); prog.setUniform("ParticleLifetime", 3.5f); prog.setUniform("Accel", vec3(0.0f,-0.4f,0.0f)); setMatrices(); }
void Agent::HurtAgent(float damage) { m_health1 -= damage; m_health2 -= damage; if (m_health1 < 0.f || m_health2 < 0.f) { int screenWidth = 0; int screenHeight = 0; glfwGetWindowSize(glfwGetCurrentContext(), &screenWidth, &screenHeight); AddToMemory(vec3(m_position.x, m_position.y, 1)); m_neuralNetwork->TrainNetwork(m_memory); m_startingPosition.x = (float)(rand() % screenWidth); m_startingPosition.y = (float)(rand() % 2 * screenHeight); float size = 20.f; float facing = 44.f / 7.0f * (float)((rand() % 1000) / 1000.f); Setup(m_startingPosition, m_diameter, m_colour, facing); } }
void Update() { int t2 = SDL_GetTicks(); dt = float(t2-t); t = t2; for( int s=0; s<stars.size(); ++s ) { // Add code for update of stars float V = 0.00025; stars[s].z= stars[s].z-V*dt; if( stars[s].z <= 0 ) stars[s].z += 1; if( stars[s].z > 1 ) stars[s].z -= 1; color = 0.2f * vec3(1,1,1) / (stars[s].z*stars[s].z); //cout<<"z="<<stars[s].z<<endl; //cout<<"dt="<<dt<<endl; } }
void BBox::render() const { // 7--------6 // /| / // / | /| // / | / | // 3--------2 | // | 4-----|--5 // | / | / // |/ | / // | |/ // 0--------1 using glm::vec3; vec3 pVertices[8] = { vec3(m_v3Min.x, m_v3Min.y, m_v3Min.z), vec3(m_v3Max.x, m_v3Min.y, m_v3Min.z), vec3(m_v3Max.x, m_v3Max.y, m_v3Min.z), vec3(m_v3Min.x, m_v3Max.y, m_v3Min.z), vec3(m_v3Min.x, m_v3Min.y, m_v3Max.z), vec3(m_v3Max.x, m_v3Min.y, m_v3Max.z), vec3(m_v3Max.x, m_v3Max.y, m_v3Max.z), vec3(m_v3Min.x, m_v3Max.y, m_v3Max.z), }; GLushort pLineIndices[24] = { 0,1, 1,2, 2,3, 3,0, //front 0,4, 1,5, 2,6, 3,7, //front to back 4,5, 5,6, 6,7, 7,4, //back }; glColor3f(1.0f,0.0f,0.0f); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, 0, pVertices); glDrawElements(GL_LINES, 24, GL_UNSIGNED_SHORT, pLineIndices); glDisableClientState(GL_VERTEX_ARRAY); }
TEST( CollisionLibrary, EntitySetGet ) { ICollisionEntity* entity = g_CollisionDetection.CreateEntity(); const vec3 setPosition = vec3( -3.0f, -11.0f, 7.0f ); const quat setOrientation = quat( 0.0f, 0.0f, 1.0f, 0.0f ); const float setScale = 2.0f; entity->SetPosition ( setPosition ); entity->SetOrientation ( setOrientation ); entity->SetScale ( setScale ); EXPECT_EQ( setPosition, entity->GetPosition() ); EXPECT_EQ( setOrientation, entity->GetOrientation() ); EXPECT_EQ( setScale, entity->GetScale() ); g_CollisionDetection.DestroyEntity( entity ); g_CollisionDetection.Shutdown(); }
void DisplayCanvas::handleMouseUp(wxMouseEvent& evt) { if(has_dragged_) return; // Render just the pieces and indicators (back buffer, to avoid flicker) prerender(); renderPieces(); renderIndicators(); vec3 world_coords; if(unproject(evt.GetPosition(), world_coords)) { // Shift from worldspace into "chess-space". The +0.02 is to prevent // the base of the piece from sticking into the square below it. vec3 loc = glm::floor(world_coords + vec3(4, 4, 4.02)); click(loc.x, loc.y, loc.z); } }
void ScenePaint::initScene() { compileAndLinkShader(); glClearColor(0.1f,0.1f,0.1f,1.0f); glEnable(GL_DEPTH_TEST); prog.setUniform("NoiseTex", 0); GLuint noiseTex = NoiseTex::generate2DTex(32.0f); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, noiseTex); teapot = new VBOTeapot(14, mat4(1.0f)); prog.setUniform("Light.Intensity", vec3(1.0f,1.0f,1.0f)); lightPos = vec4(0.0f,0.0f,0.0f,1.0f); }
void Room::Intersection(Edge &camsEdge) { vec3 tempPoint; for(int i = 0; i < camsEdge.a.size(); i++) { for(int j = 0; j < camsEdge.b.size(); j++) { tempPoint = Line::intersection(camsEdge.a[i], camsEdge.b[j], camsEdge.m_maxError); if(tempPoint != vec3(0,0,0)) { camsEdge.points.push_back(tempPoint); } } } camsEdge.a.clear(); camsEdge.b.clear(); }