bool ComputerGraphics::update(float deltaTime) { // close the application if the window closes if (glfwWindowShouldClose(m_window) || glfwGetKey(m_window, GLFW_KEY_ESCAPE) == GLFW_PRESS) return false; // update the camera's movement m_camera->update(deltaTime); elapsedTime += deltaTime; //emitter.position += vec3(glm::sin(elapsedTime), 0, 0); emitter.Update(deltaTime, m_camera->getTransform()); // clear the gizmos out for this frame Gizmos::clear(); terrain.Update(deltaTime); Gizmos::addTransform(glm::mat4(1)); // ...for now let's add a grid to the gizmos for (int i = 0; i < 21; ++i) { Gizmos::addLine(vec3(-10 + i, 0, 10), vec3(-10 + i, 0, -10), i == 10 ? vec4(1, 1, 1, 1) : vec4(0, 0, 0, 1)); Gizmos::addLine(vec3(10, 0, -10 + i), vec3(-10, 0, -10 + i), i == 10 ? vec4(1, 1, 1, 1) : vec4(0, 0, 0, 1)); } // return true, else the application closes return true; }
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); }
vector< vector<vertexInfo>> ScreenNode(const vector< vector<vertexInfo>> &node) {//compute node in screen space setMatrix(); vector< vector<vertexInfo>> node_screen = node; for(int i = 0; i < (int)node.size(); i++) { for(int j = 0 ; j <(int)node[i].size(); j++) { vec4 v_pers = ::MVP * vec4(node[i][j].x, node[i][j].y, node[i][j].z, 1.0); vec4 v_screen = ::m_screen * vec4(v_pers/v_pers[3]); node_screen[i][j].x = v_screen.x; node_screen[i][j].y = v_screen.y; node_screen[i][j].z = v_screen.z; } } // for(int i = 0; i< (int)node_screen.size(); i++) // { // // for(int j = 0; j< (int)node_screen[i].size(); j++) // { // cout<<i*(int)node_screen.size() + j<<'\t'; // cout<<node_screen[i][j].x<<'\t'<<'\t'; // cout<<node_screen[i][j].y<<'\t'<<'\t'; // cout<<node_screen[i][j].z<<endl; // } // } return node_screen; }
bool UtilitySystems::update(float deltaTime) { // close the application if the window closes if (glfwWindowShouldClose(m_window) || glfwGetKey(m_window, GLFW_KEY_ESCAPE) == GLFW_PRESS) return false; // update the camera's movement m_camera->update(deltaTime); m_pNPC->update(deltaTime); // clear the gizmos out for this frame Gizmos::clear(); Gizmos::addTransform(glm::mat4(1)); // ...for now let's add a grid to the gizmos for (int i = 0; i < 21; ++i) { Gizmos::addLine(vec3(-10 + i, 0, 10), vec3(-10 + i, 0, -10), i == 10 ? vec4(1, 1, 1, 1) : vec4(0, 0, 0, 1)); Gizmos::addLine(vec3(10, 0, -10 + i), vec3(-10, 0, -10 + i), i == 10 ? vec4(1, 1, 1, 1) : vec4(0, 0, 0, 1)); } // return true, else the application closes return true; }
void BasicNetworkingApp::Draw() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); Gizmos::Clear(); Gizmos::AddTransform(glm::translate(m_pickPosition)); for (int i = 0; i < 21; ++i) { Gizmos::AddLine(vec3(-10 + i, 0, 10), vec3(-10 + i, 0, -10), i == 10 ? vec4(1, 1, 1, 1) : vec4(0, 0, 0, 1)); Gizmos::AddLine(vec3(10, 0, -10 + i), vec3(-10, 0, -10 + i), i == 10 ? vec4(1, 1, 1, 1) : vec4(0, 0, 0, 1)); } for (unsigned int i = 0; i < m_gameObjects.size(); i++) { GameObject& obj = m_gameObjects[i]; Gizmos::AddSphere(vec3(obj.xPos, 2, obj.zPos), 2, 32, 32, vec4(obj.redColour, obj.greenColour, obj.blueColour, 1), nullptr); } Gizmos::Draw(m_camera->GetProjectionView()); int width = 0; int height = 0; glfwGetWindowSize(m_window, &width, &height); glm::mat4 guiMatrix = glm::ortho<float>(0, (float)width, 0, (float)height); Gizmos::Draw2D(guiMatrix); }
mat4 GLFrame::get_camera_matrix(bool rotation_only) { vec3 x, z; mat4 mat(1); // Make rotation matrix // Z vector is reversed due to pespective projection matrix z = -forward; x = glm::cross(up, z); // Matrix has no translation information and is // transposed.... (rows instead of columns) mat[0] = vec4(x.x, up.x, z.x, 0); mat[1] = vec4(x.y, up.y, z.y, 0); mat[2] = vec4(x.z, up.z, z.z, 0); //mat[3] already set if (rotation_only) return mat; // Apply translation too mat4 trans(1); trans[3] = vec4(-origin, 1); //TODO //could instead of having the previous 2 lines just mat*(-origin) and drop the result //in column 4 of mat. I think that actually saves mult ops return mat*trans; }
void CheckersProject::Draw(FlyCamera &_gameCamera, float a_deltatime) { using glm::vec3; using glm::vec4; //BROWN UNDERBOARD Gizmos::addCylinderFilled(vec3(5.25, -1, 5.25), 10, 0.75, 4, vec4(0.545, 0.270, 0.074, 1), &rotate); ///Draw the Grid for (float c = 0; c <= m_cols- 1; c++) { for (float r = 0; r <= m_rows - 1; r++) { if (m_tileRed == false) { Gizmos::addCylinderFilled(vec3((r * m_scaleMod), 0, c * m_scaleMod), 1, 0.25, 4, vec4(0, 0, 0, 1), &rotate); m_tileRed = true; } else if (m_tileRed == true) { Gizmos::addCylinderFilled(vec3(r * m_scaleMod,0, c *m_scaleMod), 1, 0.25, 4, vec4(1, 0, 0, 1), &rotate); m_tileRed = false; } } m_tileRed = !m_tileRed; } ///Draw Tokens for (int c = 0; c <= m_cols - 1; c++) { for (int r = 0; r <= m_rows - 1; r++) { if (m_board[c][r] == PIECE::RED) { Gizmos::addCylinderFilled(vec3((r * m_scaleMod), 0.5, c * m_scaleMod), 0.5, 0.25, 16, vec4(1,0 , 0, 1), &rotate); } else if (m_board[c][r] == PIECE::REDKING) { Gizmos::addCylinderFilled(vec3((r * m_scaleMod), 0.5, c * m_scaleMod), 0.75, 0.55, 16, vec4(1, 0, 0, 1), &rotate); } else if (m_board[c][r] == PIECE::BLACK) { Gizmos::addCylinderFilled(vec3((r * m_scaleMod),0.5, c * m_scaleMod), 0.5, 0.25, 16, vec4(0 ,0, 0, 1), &rotate); } else if (m_board[c][r] == PIECE::BLACKKING) { Gizmos::addCylinderFilled(vec3((r * m_scaleMod), 0.5, c * m_scaleMod), 0.75, 0.55, 16, vec4(0, 0, 0, 1), &rotate); } else if (m_board[c][r] == PIECE::POSSIBLEMOVE) { Gizmos::addCylinderFilled(vec3((r * m_scaleMod), 0.5, c * m_scaleMod), 0.5, 0.25, 16, vec4(0, 1, 0, 1), &rotate); } } } }
void RayTracer::iniObjStack() {//initialize object //sphere ID = 1 //(x-a)^2 + (y-b)^2 + (z-c)^2 = r^2 //vec4(a, b, c, r) addObjectStack(vec4(3.0, 1.0, 1.0, 0.7), 1);//reflect object addObjectStack(vec4(0.0, 1.0, 0.0, 1.0), 1);//opaque object addObjectStack(vec4(0.5, 0.5, 2.5, 0.5), 1);//transparent object //plane ID = 2 //ax + by + cz + d =0 //vec4(a, b, c, d) addObjectStack(vec4(0.0, 1.0, 0.0, 0.0), 2);//opaque object addObjectStack(vec4(1.0, 0.0, 0.3, 1.0), 2);//reflect object }
void Geometry::transform(mat4 const &m) { mat4 it = glm::transpose(glm::inverse(m)); // Check.. Did I forget something? // \todo Mark each attributemap how they should be transformed auto polygon_centroids = polygon_attributes().maybe_find<vec3>("polygon_centroids"); auto polygon_normals = polygon_attributes().maybe_find<vec3>("polygon_normals"); auto point_locations = point_attributes().maybe_find<vec3>("point_locations"); auto point_normals = point_attributes().maybe_find<vec3>("point_normals"); auto corner_normals = corner_attributes().maybe_find<vec3>("corner_normals"); for (auto point : points()) { if (point_locations != nullptr && point_locations->has(point)) { point_locations->put(point, vec3(m * vec4(point_locations->get(point), 1.0f))); } if (point_normals != nullptr && point_normals->has(point)) { point_normals->put(point, vec3(it * vec4(point_normals->get(point), 0.0f))); } } for (auto polygon : polygons()) { if (polygon_centroids != nullptr && polygon_centroids->has(polygon)) { polygon_centroids->put(polygon, vec3(m * vec4(polygon_centroids->get(polygon), 1.0f))); } if (polygon_normals != nullptr && polygon_normals->has(polygon)) { polygon_normals->put(polygon, vec3(it * vec4(polygon_normals->get(polygon), 0.0f))); } if (corner_normals != nullptr) { for (auto corner : polygon->corners()) { if (corner_normals != nullptr && corner_normals->has(corner)) { corner_normals->put(corner, vec3(it * vec4(corner_normals->get(corner), 0.0f))); } } } } }
void Picking::CalculateRayFromPixel( const glm::ivec2& pixel, const glm::ivec2& windowSize, const glm::mat4& invViewProj, Ray* outRay ) const { // Clip space coordinates for the pixel. (-1,-1) in lower left corner, (-1,1) upper left corner, (1,-1) lower right corner. const vec2 mousePosNorm = vec2( -1.0f + 2.0f * (pixel.x / static_cast<float>(windowSize.x)), 1.0f - 2.0f * (pixel.y / static_cast<float>(windowSize.y)) ); // Translating pixel at near plane and far plane to world coordinates. Z-coordinate is depth into the screen (values between -1 and 1 are in view of camera). const vec4 nearHomogeneous = invViewProj * vec4( mousePosNorm.x, mousePosNorm.y, 0.0f, 1.0f ); const vec4 farHomogeneous = invViewProj * vec4( mousePosNorm.x, mousePosNorm.y, 1.0f, 1.0f ); const vec3 nearWorld = vec3( nearHomogeneous ) / nearHomogeneous.w; const vec3 farWorld = vec3( farHomogeneous ) / farHomogeneous.w; outRay->Position = nearWorld; outRay->Direction = glm::normalize( farWorld - nearWorld ); }
void OrthoCamera::updateMatrices() { vec3 s = glm::normalize(glm::cross(direction, upVector)); vec3 u = glm::normalize(glm::cross(s, direction)); mat4 untranslatedViewMatrix = mat4(vec4(s, 0), vec4(u, 0), vec4(direction, 0), vec4(0, 0, 0, 1.0f)); untranslatedViewMatrix = glm::transpose(untranslatedViewMatrix); viewMatrix = glm::translate(untranslatedViewMatrix, -focus); projectionMatrix = mat4(1/width, 0, 0, 0, 0, 1/height, 0, 0, 0, 0, 1/depth, 0, 0, 0, 0, 1); }
vec3 phong_tangent_space_shader::vertex( const mat4& viewmat, const vec3& v) const { auto res = viewmat * vec4(v, 1); return res / res.w; }
vec3 simple_texture_shader::vertex( const mat4& viewmat, const vec3& v) const { auto res = viewmat * vec4(v, 1); return res / res.w; }
vec3 normal_shader::vertex( const mat4& viewmat, const vec3& v) const { auto res = viewmat * vec4(v, 1); return res / res.w; }
vec3 shader_with_shadows::vertex( const mat4& viewmat, const vec3& v) const { auto res = viewmat * vec4(v, 1); return res / res.w; }
void ControlLayer::render(ESContext *esContext) { storeState(); // do real render prog.setUniform("CircleColor", vec4(0.0f, 0.0f, 0.0f, 0.2f)); leftPanel->panel->render(GL_TRIANGLE_FAN); rightPanel->panel->render(GL_TRIANGLE_FAN); prog.setUniform("CircleColor", vec4(0.0f, 0.0f, 1.0f, 0.8f)); if(leftPanel->isActive == TRUE) { leftPanel->hitPoint->render(GL_TRIANGLE_FAN); } if(rightPanel->isActive == TRUE) { rightPanel->hitPoint->render(GL_TRIANGLE_FAN); } recoverState(); }
void Blank::draw() { // clear the screen for this frame glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // ...for now let's add a grid to the gizmos for (int i = 0; i < 21; ++i) { Gizmos::addLine(vec3(-10 + i, 0, 10), vec3(-10 + i, 0, -10), i == 10 ? vec4(1, 1, 1, 1) : vec4(0, 0, 0, 1)); Gizmos::addLine(vec3(10, 0, -10 + i), vec3(-10, 0, -10 + i), i == 10 ? vec4(1, 1, 1, 1) : vec4(0, 0, 0, 1)); } // display the 3D gizmos Gizmos::draw(m_camera->getProjectionView()); }
void My_OpenGLWidget::resizeGL(int width, int height) { glViewport(0, 0, width, height); float aspectRatio = static_cast<float>(width) / static_cast<float>(height); //top, bottom, near, and far are still ok, aspect ratio is the problem float bottom = -1.0f; float nearZ = 2.0f; float top = nearZ * tan(3.14/8.0f); float farZ = -1.0f; float right = aspectRatio; float left = -aspectRatio; //near and far had namespace collisions //mat4 projectionScale = mat4(vec4(2.0f / (right - left), 0.0f, 0.0f, 0.0f), vec4(0.0f, 2.0f / (top - bottom), 0.0f, 0.0f), vec4(0.0f, 0.0f, 2.0f / (farZ - nearZ), 0.0f), vec4(0.0f, 0.0f, 0.0f, 1.0f)); mat4 projectionScale = mat4(vec4((nearZ/right), 0, 0, 0), vec4(0, (nearZ/top), 0,0), vec4(0,0,((-farZ+nearZ)/(farZ-nearZ)),((-2*farZ*nearZ)/(farZ-nearZ))), vec4(0,0,-1, 0)); //mat4 projectionTranslate = glm::translate(vec3(0.0f, 0.0f, 1.0f)); //projectionMatrix = projectionScale * projectionTranslate; projectionMatrix = projectionScale; }
inline vec3 unproject(const vec3 & win, const mat4 & inverse_mvp, const vec4 & viewport) { vec4 tmp = vec4(win, 1.0f); tmp.x = (tmp.x - viewport[0]) / viewport[2]; tmp.y = (tmp.y - viewport[1]) / viewport[3]; tmp = tmp * 2.0f - 1.0f; vec4 obj = inverse_mvp * tmp; obj /= obj.w; return vec3(obj); }
bool TestApplication::update(float deltaTime) { // close the application if the window closes if (glfwWindowShouldClose(m_window) || glfwGetKey(m_window, GLFW_KEY_ESCAPE) == GLFW_PRESS) return false; // update the camera's movement m_camera->update(deltaTime); // clear the gizmos out for this frame Gizmos::clear(); ////////////////////////////////////////////////////////////////////////// // YOUR UPDATE CODE HERE ////////////////////////////////////////////////////////////////////////// // an example of mouse picking if (glfwGetMouseButton(m_window, 0) == GLFW_PRESS) { double x = 0, y = 0; glfwGetCursorPos(m_window, &x, &y); // plane represents the ground, with a normal of (0,1,0) and a distance of 0 from (0,0,0) glm::vec4 plane(0, 1, 0, 0); m_pickPosition = m_camera->pickAgainstPlane((float)x, (float)y, plane); } Gizmos::addTransform(glm::translate(m_pickPosition)); // ...for now let's add a grid to the gizmos for (int i = 0; i < 21; ++i) { Gizmos::addLine(vec3(-10 + i, 0, 10), vec3(-10 + i, 0, -10), i == 10 ? vec4(1, 1, 1, 1) : vec4(0, 0, 0, 1)); Gizmos::addLine(vec3(10, 0, -10 + i), vec3(-10, 0, -10 + i), i == 10 ? vec4(1, 1, 1, 1) : vec4(0, 0, 0, 1)); } // return true, else the application closes return true; }
void My_OpenGLWidget::createCamera() { camLocation = vec4(0.0f, 0.0f, 2.0f, 1.0f); up = vec4(0.0f, 1.0f, 0.0f, 0.0f); focus = vec4(0.0, 0.0, 0.0, 1.0f); //create the three basis vectors vec4 n = glm::normalize(focus - camLocation); vec4 u = vec4(glm::cross(vec3(up.x, up.y, up.z), vec3(n.x, n.y, n.z)), 0.0f); vec4 v = vec4(glm::cross(vec3(n.x, n.y, n.z), vec3(u.x, u.y, u.z)), 0.0f); mat4 cameraRotation(vec4(u.x, v.x, n.x, 0.0f), vec4(u.y, v.y, n.y, 0.0f), vec4(u.z, v.z, n.z, 0.0f), vec4(0.0f, 0.0f, 0.0f, 1.0f)); mat4 cameraTranslation = glm::translate(vec3(-camLocation.x, -camLocation.y, -camLocation.z)); cameraMatrix = cameraTranslation * cameraRotation; }
void setViewFP() { using namespace glm; glm::mat4 Vinv(1.0); // right-left rotate Vinv = glm::rotate(glm::mat4(1.0), g_CamangleY, glm::vec3(0.0f, 1, 0)); Vinv = glm::rotate(Vinv, g_CamangleX, glm::vec3(1, 0, 0)); // get lookat vec vec4 t = Vinv * vec4(0, 0, -1, 1); g_lookAt.x = t.x; g_lookAt.y = t.y; g_lookAt.z = t.z; // S is translation with respect to Cam glm::mat4 S = glm::translate(glm::mat4(1.0), glm::vec3(g_CamDx, g_CamDy, g_CamDz)); glm::mat4 V = glm::inverse(Vinv); // S with respect to World vec4 camPos4f = vec4(g_CamPos.x, g_CamPos.y, g_CamPos.z, 1.0f); camPos4f = Vinv * S * V * camPos4f; g_CamPos.x = camPos4f.x; // == No player y movement g_CamPos.y = camPos4f.y; g_CamPos.z = camPos4f.z; // printf("g_CamPos: %f, %f, %f\n", g_CamPos.x, g_CamPos.y, g_CamPos.z); // xlate camera in world Vinv = translate(mat4(1), g_CamPos) * Vinv; //g_CamDz = g_CamDx = 0; g_view = inverse(Vinv); }
mat4 GLFrame::get_matrix(bool rotation_only) { mat4 matrix(1); vec3 x_axis = glm::cross(up, forward); matrix[0] = vec4(x_axis, 0); matrix[1] = vec4(up, 0); matrix[2] = vec4(forward, 0); /* matrix.setc1(x_axis); matrix.setc2(up); matrix.setc3(forward); */ // Translation (already done) if(!rotation_only) matrix[3] = vec4(origin, 0); //matrix.setc4(origin); return matrix; }
inline bool project(const vec3 & obj, const mat4 & mvp, const vec4 & viewport, vec2 & out) { vec4 tmp = vec4(obj, 1.0f); tmp = mvp * tmp; if (tmp.w < 0) return false; tmp /= tmp.w; tmp = tmp * 0.5f + 0.5f; tmp[0] = tmp[0] * viewport[2] + viewport[0]; tmp[1] = tmp[1] * viewport[3] + viewport[1]; out = vec2(tmp); return true; }
//Predefined vertex Data. Allows Creation of a 2D Object void Renderer::Generate2DObject() { Vertex vertexData[] = { { vec4(-50, 0, 50, 1), vec4(0, 1, 0, 0), vec3(1, 0, 0), glm::vec2(0, 1) }, { vec4(50, 0, 50, 1), vec4(0, 1, 0, 0), vec3(1, 0, 0), glm::vec2(1, 1) }, { vec4(50, 0, -50, 1), vec4(0, 1, 0, 0), vec3(1, 0, 0), glm::vec2(1, 0) }, { vec4(-50, 0, -50, 1), vec4(0, 1, 0, 0), vec3(1, 0, 0), glm::vec2(0, 0) }, }; unsigned int indexData[] = { 0, 1, 2, 0, 2, 3 }; glGenVertexArrays(1, &m_VAO); glBindVertexArray(m_VAO); glGenBuffers(1, &m_VBO); glBindBuffer(GL_ARRAY_BUFFER, m_VBO); glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex)* 4, vertexData, GL_STATIC_DRAW); glGenBuffers(1, &m_IBO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_IBO); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int)* 6, indexData, GL_STATIC_DRAW); //Position glEnableVertexAttribArray(0); glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0); //Tangent glEnableVertexAttribArray(1); glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(sizeof(vec4))); //Normal glEnableVertexAttribArray(2); glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(sizeof(vec4)* 2)); //Texture glEnableVertexAttribArray(3); glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), ((void*)(sizeof(vec4)* 2 + (sizeof(vec3))))); glBindVertexArray(0); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); }
frag_color shader_with_shadows::fragment( const vec3& bary, const mat3& verts, const mat3x2& tex_coords, const mat3& vert_norms) const { auto v = bary_lerp(verts[0], verts[1], verts[2], bary); auto shadow_v = shadow_xform * vec4(v, 1); shadow_v = shadow_v / shadow_v.w; auto shadow_z_val = shadow_zbuf.get((int)shadow_v.x, (int)shadow_v.y); float shadow_coeff = .3 + .7 * (shadow_z_val < shadow_v.z); auto frag_c = primary_shader->fragment(bary, verts, tex_coords, vert_norms); frag_c.c.scale(shadow_coeff); return frag_c; }
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; }
void QuatCam::HandleKeyboardInput(const double a_dt) { //Get the QuatCams forward/up/right vec3 vRight = vec3(m_worldTrans[0]); vec3 vUp = vec3(m_worldTrans[1]); vec3 vFrwrd = vec3(m_worldTrans[2]); vec3 moveDir(0.0f); //Retain a direction via with button is pressed if (Keyboard::isKeyDown(KEY_W)) moveDir -= vFrwrd; else if (Keyboard::isKeyDown(KEY_S)) moveDir += vFrwrd; else if (Keyboard::isKeyDown(KEY_A)) moveDir -= vRight; else if (Keyboard::isKeyDown(KEY_D)) moveDir += vRight; if (Keyboard::isKeyDown(KEY_E)) moveDir += vec3(0.0f, 1.0f, 0.0f); else if (Keyboard::isKeyDown(KEY_Q)) moveDir -= vec3(0.0f, 1.0f, 0.0f); m_flySpeed = GetBaseSpeed(); float vel = 10.0f; float maxSpeed = 25.0f; // Applying speed boosts if (Keyboard::isKeyDown(KEY_LEFT_SHIFT)) SetFlySpeed(vel * m_flySpeed); else if (m_flySpeed >= maxSpeed) SetFlySpeed(m_flySpeed * 0.98f); if (m_flySpeed <= 0.1f) SetFlySpeed(0.0f); //Apply movement to the current position if (length(moveDir) > 0.01f) { moveDir = ((float)a_dt * m_flySpeed) * normalize(moveDir); SetPosition(GetPosition() + vec4(moveDir, 0.0)); } }
void Torque::resetParticle() { bodyOrigin = vec3(0,0,0); angularVelocity = 1.5f; bodyOrigin = vec3(0,0,0); angle = 0.0f; length = 0.3f; for(int i = 0; i<bodyParticles.count(); i++) { vec4 pos = vec4(length, 0, 0, 0); bodyParticles[i]->particle->position = vec3(pos * glm::rotate(angle, vec3(0,0,1))); bodyParticles[i]->particle->velocity = vec3(0,0,0); length += lengthIncrement; angle += angleIncrement; } syncAllGraphics(); }
OGLMWindow::OGLMWindow(sf::VideoMode mode, const sf::String &title, unsigned int style) : sf::Window(mode, title, style), m_mode(mode), m_title(title), isFullscreen(false), isWireframeMode(false), isFPSCountEnabled(false) { light_position = vec3(0.0f, 3.0f, 1.0f); ambientLight = vec4(0.05f, 0.05f, 0.05f , 1.0f); std::string shader_dir = "./shaders/"; default_shader = new ShaderMan(shader_dir + "default"); flat_shader = new ShaderMan(shader_dir + "flat"); bufferman = new BufferMan(); Mesh::setBufferMan(bufferman); onLights(); }