Changeset 612d1f6 in opengl-game for new-game.cpp
- Timestamp:
- Jul 31, 2018, 3:05:35 AM (6 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- e9347b4
- Parents:
- fabed35
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
new-game.cpp
rfabed35 r612d1f6 145 145 void transformObject(SceneObject& obj, const mat4& transform, GLuint ubo); 146 146 147 void translateLaser(SceneObject& laser, const vec3& translation, GLuint ubo); 148 147 149 void renderMainMenu(); 148 150 void renderMainMenuGui(); … … 213 215 214 216 /* 215 * TODO: Make lasers shoot from the ends of the ship's wings when the user presses a button and disappear after a second or so216 217 * TODO: Asteroid movement currently depends on framerate, fix this in a generic/reusable way 217 218 */ … … 1041 1042 transformObject(objects[0], translate(mat4(1.0f), vec3(0.01f, 0.0f, 0.0f)), ubo); 1042 1043 1043 // TODO: Update the rotation of the lasers as they moves so they point towards the camera1044 1044 if (leftLaserIdx != -1) { 1045 trans formObject(objects[leftLaserIdx], translate(mat4(1.0f), vec3(0.01f, 0.0f, 0.0f)), ubo);1045 translateLaser(objects[leftLaserIdx], vec3(0.01f, 0.0f, 0.0f), ubo); 1046 1046 } 1047 1047 if (rightLaserIdx != -1) { 1048 trans formObject(objects[rightLaserIdx], translate(mat4(1.0f), vec3(0.01f, 0.0f, 0.0f)), ubo);1048 translateLaser(objects[rightLaserIdx], vec3(0.01f, 0.0f, 0.0f), ubo); 1049 1049 } 1050 1050 } … … 1052 1052 transformObject(objects[0], translate(mat4(1.0f), vec3(-0.01f, 0.0f, 0.0f)), ubo); 1053 1053 1054 // TODO: Update the rotation of the lasers as they moves so they point towards the camera1055 1054 if (leftLaserIdx != -1) { 1056 trans formObject(objects[leftLaserIdx], translate(mat4(1.0f), vec3(-0.01f, 0.0f, 0.0f)), ubo);1055 translateLaser(objects[leftLaserIdx], vec3(-0.01f, 0.0f, 0.0f), ubo); 1057 1056 } 1058 1057 if (rightLaserIdx != -1) { 1059 trans formObject(objects[rightLaserIdx], translate(mat4(1.0f), vec3(-0.01f, 0.0f, 0.0f)), ubo);1058 translateLaser(objects[rightLaserIdx], vec3(-0.01f, 0.0f, 0.0f), ubo); 1060 1059 } 1061 1060 } … … 1630 1629 float zAxisRotation = -atan2(glm::dot(glm::cross(normal, laserToCam), glm::normalize(ray)), glm::dot(normal, laserToCam)); 1631 1630 1632 obj.model_base = mat4(1.0f); 1633 obj.model_base = rotate(mat4(1.0f), zAxisRotation, vec3(0.0f, 0.0f, 1.0f)) * obj.model_base; 1634 obj.model_base = rotate(mat4(1.0f), xAxisRotation, vec3(1.0f, 0.0f, 0.0f)) * obj.model_base; 1635 obj.model_base = rotate(mat4(1.0f), yAxisRotation, vec3(0.0f, 1.0f, 0.0f)) * obj.model_base; 1636 obj.model_base = translate(mat4(1.0f), start) * obj.model_base; 1631 obj.model_base = rotate(mat4(1.0f), zAxisRotation, vec3(0.0f, 0.0f, 1.0f)); 1637 1632 1638 1633 initObject(obj); 1634 1635 obj.model_transform = rotate(mat4(1.0f), xAxisRotation, vec3(1.0f, 0.0f, 0.0f)) * obj.model_transform; 1636 obj.model_transform = rotate(mat4(1.0f), yAxisRotation, vec3(0.0f, 1.0f, 0.0f)) * obj.model_transform; 1637 obj.model_transform = translate(mat4(1.0f), start) * obj.model_transform; 1639 1638 1640 1639 return obj; … … 1857 1856 } 1858 1857 1858 void translateLaser(SceneObject& laser, const vec3& translation, GLuint ubo) { 1859 if (laser.deleted) return; 1860 1861 // TODO: A lot of the values I calculate here can be calculated once and saved when the laser is created, 1862 // and then re-used here 1863 1864 mat4 new_model_transform = translate(mat4(1.0f), translation) * laser.model_transform; 1865 1866 vec3 start = vec3(laser.model_transform * vec4(0.0f, 0.0f, 0.0f, 1.0f)); 1867 vec3 end = vec3(laser.model_transform * vec4(0.0f, 0.0f, laser.points[2] + laser.points[20], 1.0f)); 1868 1869 vec3 ray = end - start; 1870 float length = glm::length(ray); 1871 1872 float xAxisRotation = asin(ray.y / length); 1873 float yAxisRotation = atan2(-ray.x, -ray.z); 1874 1875 vec3 normal(rotate(mat4(1.0f), yAxisRotation, vec3(0.0f, 1.0f, 0.0f)) * 1876 rotate(mat4(1.0f), xAxisRotation, vec3(1.0f, 0.0f, 0.0f)) * 1877 vec4(0.0f, 1.0f, 0.0f, 1.0f)); 1878 1879 // To project point P onto line AB: 1880 // projection = A + dot(AP,AB) / dot(AB,AB) * AB 1881 vec3 projOnLaser = start + glm::dot(cam_pos - start, ray) / (length*length) * ray; 1882 vec3 laserToCam = cam_pos - projOnLaser; 1883 1884 float zAxisRotation = -atan2(glm::dot(glm::cross(normal, laserToCam), glm::normalize(ray)), glm::dot(normal, laserToCam)); 1885 1886 laser.model_base = rotate(mat4(1.0f), zAxisRotation, vec3(0.0f, 0.0f, 1.0f)); 1887 1888 transformObject(laser, translate(mat4(1.0f), translation), ubo); 1889 } 1890 1859 1891 void renderScene(map<GLuint, BufferInfo>& shaderBufferInfo, 1860 1892 GLuint color_sp, GLuint texture_sp, GLuint laser_sp,
Note:
See TracChangeset
for help on using the changeset viewer.