Skip to content

Commit 7ca7e01

Browse files
author
BlitW0
committed
Final Submission
0 parents  commit 7ca7e01

35 files changed

+2164
-0
lines changed

.editorconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# EditorConfig is awesome: http://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
# Unix-style newlines with a newline ending every file
7+
[*]
8+
end_of_line = lf
9+
insert_final_newline = true
10+
11+
# 4 space indentation
12+
[*.{cpp,h}]
13+
indent_style = space
14+
indent_size = 4

.gitignore

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
2+
# Created by https://www.gitignore.io/api/c++,linux,macos,cmake,qtcreator
3+
4+
### C++ ###
5+
# Prerequisites
6+
*.d
7+
8+
# Compiled Object files
9+
*.slo
10+
*.lo
11+
*.o
12+
*.obj
13+
14+
# Precompiled Headers
15+
*.gch
16+
*.pch
17+
18+
# Compiled Dynamic libraries
19+
*.so
20+
*.dylib
21+
*.dll
22+
23+
# Fortran module files
24+
*.mod
25+
*.smod
26+
27+
# Compiled Static libraries
28+
*.lai
29+
*.la
30+
*.a
31+
*.lib
32+
33+
# Executables
34+
*.exe
35+
*.out
36+
*.app
37+
38+
### CMake ###
39+
CMakeCache.txt
40+
CMakeFiles
41+
CMakeScripts
42+
Testing
43+
Makefile
44+
cmake_install.cmake
45+
install_manifest.txt
46+
compile_commands.json
47+
CTestTestfile.cmake
48+
build
49+
50+
### Linux ###
51+
*~
52+
53+
# temporary files which can be created if a process still has a handle open of a deleted file
54+
.fuse_hidden*
55+
56+
# KDE directory preferences
57+
.directory
58+
59+
# Linux trash folder which might appear on any partition or disk
60+
.Trash-*
61+
62+
# .nfs files are created when an open file is removed but is still being accessed
63+
.nfs*
64+
65+
### macOS ###
66+
*.DS_Store
67+
.AppleDouble
68+
.LSOverride
69+
70+
# Icon must end with two \r
71+
Icon
72+
73+
# Thumbnails
74+
._*
75+
76+
# Files that might appear in the root of a volume
77+
.DocumentRevisions-V100
78+
.fseventsd
79+
.Spotlight-V100
80+
.TemporaryItems
81+
.Trashes
82+
.VolumeIcon.icns
83+
.com.apple.timemachine.donotpresent
84+
85+
# Directories potentially created on remote AFP share
86+
.AppleDB
87+
.AppleDesktop
88+
Network Trash Folder
89+
Temporary Items
90+
.apdisk
91+
92+
### QtCreator ###
93+
# gitignore for Qt Creator like IDE for pure C/C++ project without Qt
94+
#
95+
# Reference: http://doc.qt.io/qtcreator/creator-project-generic.html
96+
97+
98+
99+
# Qt Creator autogenerated files
100+
101+
102+
# A listing of all the files included in the project
103+
*.files
104+
105+
# Include directories
106+
*.includes
107+
108+
# Project configuration settings like predefined Macros
109+
*.config
110+
111+
# Qt Creator settings
112+
*.creator
113+
114+
# User project settings
115+
*.creator.user*
116+
117+
# Qt Creator backups
118+
*.autosave
119+
120+
121+
# End of https://www.gitignore.io/api/c++,linux,macos,cmake,qtcreator
122+
123+
CMakeLists.txt.user

Assignment 2.pdf

79.1 KB
Binary file not shown.

CMakeLists.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
project(graphics_asgn1)
2+
cmake_minimum_required(VERSION 2.8)
3+
aux_source_directory(src SRC_LIST)
4+
add_executable(${PROJECT_NAME} ${SRC_LIST})
5+
6+
include(FindPkgConfig)
7+
8+
pkg_check_modules(GLFW3 REQUIRED glfw3)
9+
include_directories(${GLFW3_INCLUDE_DIRS})
10+
target_link_libraries (${PROJECT_NAME} ${GLFW3_LIBRARIES})
11+
12+
pkg_check_modules(GLEW REQUIRED glew)
13+
include_directories(${GLEW_INCLUDE_DIRS})
14+
target_link_libraries (${PROJECT_NAME} ${GLEW_LIBRARIES})
15+
16+
if (NOT APPLE)
17+
pkg_check_modules(GL REQUIRED gl)
18+
include_directories(${GL_INCLUDE_DIRS})
19+
target_link_libraries (${PROJECT_NAME} ${GL_LIBRARIES})
20+
endif()
21+
22+
if (APPLE)
23+
target_link_libraries(${PROJECT_NAME} "-framework OpenGL")
24+
endif()
25+
26+
# pkg_check_modules(AO REQUIRED ao)
27+
# include_directories(${AO_INCLUDE_DIRS})
28+
# target_link_libraries (${PROJECT_NAME} ${AO_LIBRARIES})
29+
30+
# pkg_check_modules(LIBMPG123 REQUIRED libmpg123)
31+
# include_directories(${LIBMPG123_INCLUDE_DIRS})
32+
# target_link_libraries (${PROJECT_NAME} ${LIBMPG123_LIBRARIES})
33+
34+
configure_file(src/Sample_GL.vert Sample_GL.vert COPYONLY)
35+
configure_file(src/Sample_GL.frag Sample_GL.frag COPYONLY)
36+
# configure_file(assets/song.mp3 assets/song.mp3 COPYONLY)

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Graphics Assignment2
2+
=========================
3+
4+
Divyesh Jain - 20171171
5+
-------
6+
7+
Controls
8+
-------
9+
* W - move the plane forward
10+
* A, D - increase and decrease roll of the plane
11+
* Q, E - increase and decrease yaw of the plane
12+
* Z, C - increase and decrease pitch of the plane
13+
* Left Click - fire missiles
14+
* Right Click - drop bombs
15+
* V - toggle between different views (tower view, plane view, follow view, top view, helicopter view)
16+
* Mouse - to move view when using helicopter view
17+
18+
Details
19+
------
20+
* An arrow above the plane leads to next checkpoint
21+
* Vicinity of volcanoes is no fly zone
22+
* Enemy missiles reduce health
23+
* Dashboard shows information about plane

src/Sample_GL.frag

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#version 330 core
2+
3+
// Interpolated values from the vertex shaders
4+
in vec3 fragColor;
5+
6+
// output data
7+
out vec3 color;
8+
9+
void main()
10+
{
11+
// Output color = color specified in the vertex shader,
12+
// interpolated between all 3 surrounding vertices of the triangle
13+
color = fragColor;
14+
}

src/Sample_GL.vert

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#version 330 core
2+
3+
// input data : sent from main program
4+
layout (location = 0) in vec3 vertexPosition;
5+
layout (location = 1) in vec3 vertexColor;
6+
7+
uniform mat4 MVP;
8+
9+
// output data : used by fragment shader
10+
out vec3 fragColor;
11+
12+
void main ()
13+
{
14+
vec4 v = vec4(vertexPosition, 1); // Transform an homogeneous 4D vector
15+
16+
// The color of each vertex will be interpolated
17+
// to produce the color of each fragment
18+
fragColor = vertexColor;
19+
20+
// Output position of the vertex, in clip space : MVP * position
21+
gl_Position = MVP * v;
22+
}

src/arrow.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include "arrow.h"
2+
#include "main.h"
3+
4+
Arrow::Arrow(glm::vec3 position, color_t color, float l, float b) {
5+
this->position = position;
6+
this->rotation = 0;
7+
8+
GLfloat vertex_buffer_data[] = {
9+
-l/2, 0, -b/2,
10+
-l/2, 0, b/2,
11+
l/2, 0, b/2,
12+
13+
-l/2, 0, -b/2,
14+
l/2, 0, b/2,
15+
l/2, 0, -b/2,
16+
17+
0, 0, -b/2,
18+
0, 0, -b,
19+
b, 0, -b/2,
20+
21+
0, 0, -b/2,
22+
0, 0, -b,
23+
-b, 0, -b/2,
24+
};
25+
26+
this->object = create3DObject(GL_TRIANGLES, 36/3, vertex_buffer_data, color, GL_FILL);
27+
}
28+
29+
void Arrow::draw(glm::mat4 VP, glm::vec3 point_to) {
30+
Matrices.model = glm::mat4(1.0f);
31+
glm::mat4 translate = glm::translate (this->position); // glTranslatef
32+
33+
glm::vec3 to_axis = point_to - this->position;
34+
to_axis /= glm::length(to_axis);
35+
36+
glm::vec3 rotate_about = glm::cross(glm::vec3(0, 0, -1), to_axis);
37+
38+
float angle = acos(glm::dot(glm::vec3(0, 0, -1), to_axis));
39+
glm::mat4 rotate = glm::rotate(angle, rotate_about);
40+
41+
Matrices.model *= (translate * rotate);
42+
glm::mat4 MVP = VP * Matrices.model;
43+
glUniformMatrix4fv(Matrices.MatrixID, 1, GL_FALSE, &MVP[0][0]);
44+
draw3DObject(this->object);
45+
}
46+
47+
void Arrow::set_position(glm::vec3 position) {
48+
this->position = position;
49+
}
50+

src/arrow.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "main.h"
2+
3+
#ifndef ARR_H
4+
#define ARR_H
5+
6+
7+
class Arrow {
8+
public:
9+
Arrow() {}
10+
Arrow(glm::vec3 position, color_t color, float l, float b);
11+
glm::vec3 position;
12+
float rotation;
13+
void draw(glm::mat4 VP, glm::vec3 point_to);
14+
void set_position(glm::vec3 position);
15+
private:
16+
VAO *object;
17+
};
18+
19+
#endif // ARR_H

src/ball.cpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#include "ball.h"
2+
#include "main.h"
3+
4+
Ball::Ball(float x, float y, color_t color) {
5+
this->position = glm::vec3(x, y, 0);
6+
this->rotation = 0;
7+
speed = 1;
8+
// Our vertices. Three consecutive floats give a 3D vertex; Three consecutive vertices give a triangle.
9+
// A cube has 6 faces with 2 triangles each, so this makes 6*2=12 triangles, and 12*3 vertices
10+
static const GLfloat vertex_buffer_data[] = {
11+
-1.0f,-1.0f,-1.0f, // triangle 1 : begin
12+
-1.0f,-1.0f, 1.0f,
13+
-1.0f, 1.0f, 1.0f, // triangle 1 : end
14+
1.0f, 1.0f,-1.0f, // triangle 2 : begin
15+
-1.0f,-1.0f,-1.0f,
16+
-1.0f, 1.0f,-1.0f, // triangle 2 : end
17+
1.0f,-1.0f, 1.0f,
18+
-1.0f,-1.0f,-1.0f,
19+
1.0f,-1.0f,-1.0f,
20+
1.0f, 1.0f,-1.0f,
21+
1.0f,-1.0f,-1.0f,
22+
-1.0f,-1.0f,-1.0f,
23+
-1.0f,-1.0f,-1.0f,
24+
-1.0f, 1.0f, 1.0f,
25+
-1.0f, 1.0f,-1.0f,
26+
1.0f,-1.0f, 1.0f,
27+
-1.0f,-1.0f, 1.0f,
28+
-1.0f,-1.0f,-1.0f,
29+
-1.0f, 1.0f, 1.0f,
30+
-1.0f,-1.0f, 1.0f,
31+
1.0f,-1.0f, 1.0f,
32+
1.0f, 1.0f, 1.0f,
33+
1.0f,-1.0f,-1.0f,
34+
1.0f, 1.0f,-1.0f,
35+
1.0f,-1.0f,-1.0f,
36+
1.0f, 1.0f, 1.0f,
37+
1.0f,-1.0f, 1.0f,
38+
1.0f, 1.0f, 1.0f,
39+
1.0f, 1.0f,-1.0f,
40+
-1.0f, 1.0f,-1.0f,
41+
1.0f, 1.0f, 1.0f,
42+
-1.0f, 1.0f,-1.0f,
43+
-1.0f, 1.0f, 1.0f,
44+
1.0f, 1.0f, 1.0f,
45+
-1.0f, 1.0f, 1.0f,
46+
1.0f,-1.0f, 1.0f
47+
};
48+
49+
this->object = create3DObject(GL_TRIANGLES, 12*3, vertex_buffer_data, color, GL_FILL);
50+
}
51+
52+
void Ball::draw(glm::mat4 VP) {
53+
Matrices.model = glm::mat4(1.0f);
54+
glm::mat4 translate = glm::translate (this->position); // glTranslatef
55+
glm::mat4 rotate = glm::rotate((float) (this->rotation * M_PI / 180.0f), glm::vec3(1, 0, 0));
56+
// No need as coords centered at 0, 0, 0 of cube arouund which we waant to rotate
57+
// rotate = rotate * glm::translate(glm::vec3(0, -0.6, 0));
58+
Matrices.model *= (translate * rotate);
59+
glm::mat4 MVP = VP * Matrices.model;
60+
glUniformMatrix4fv(Matrices.MatrixID, 1, GL_FALSE, &MVP[0][0]);
61+
draw3DObject(this->object);
62+
}
63+
64+
void Ball::set_position(float x, float y) {
65+
this->position = glm::vec3(x, y, 0);
66+
}
67+
68+
void Ball::tick() {
69+
// this->rotation += speed;
70+
// this->position.x -= speed;
71+
// this->position.y -= speed;
72+
}
73+

0 commit comments

Comments
 (0)