Skip to content

Commit

Permalink
Finish
Browse files Browse the repository at this point in the history
  • Loading branch information
shucon committed Mar 5, 2018
1 parent f08670f commit 12f0ab8
Show file tree
Hide file tree
Showing 10 changed files with 287 additions and 74 deletions.
14 changes: 7 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
project(graphics_asgn1)
set (CMAKE_CXX_STANDARD 11)
cmake_minimum_required(VERSION 2.8)
aux_source_directory(src SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST})
Expand All @@ -17,14 +18,13 @@ pkg_check_modules(GL REQUIRED gl)
include_directories(${GL_INCLUDE_DIRS})
target_link_libraries (${PROJECT_NAME} ${GL_LIBRARIES})

# pkg_check_modules(AO REQUIRED ao)
# include_directories(${AO_INCLUDE_DIRS})
# target_link_libraries (${PROJECT_NAME} ${AO_LIBRARIES})
pkg_check_modules(AO REQUIRED ao)
include_directories(${AO_INCLUDE_DIRS})
target_link_libraries (${PROJECT_NAME} ${AO_LIBRARIES})

# pkg_check_modules(LIBMPG123 REQUIRED libmpg123)
# include_directories(${LIBMPG123_INCLUDE_DIRS})
# target_link_libraries (${PROJECT_NAME} ${LIBMPG123_LIBRARIES})
pkg_check_modules(LIBMPG123 REQUIRED libmpg123)
include_directories(${LIBMPG123_INCLUDE_DIRS})
target_link_libraries (${PROJECT_NAME} ${LIBMPG123_LIBRARIES})

configure_file(src/Sample_GL.vert Sample_GL.vert COPYONLY)
configure_file(src/Sample_GL.frag Sample_GL.frag COPYONLY)
# configure_file(assets/song.mp3 assets/song.mp3 COPYONLY)
2 changes: 1 addition & 1 deletion CMakeLists.txt.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.5.1, 2018-03-05T03:03:56. -->
<!-- Written by QtCreator 3.5.1, 2018-03-05T04:29:49. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
Expand Down
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
Graphics Boilerplate Code
=========================
OpenGL Assignment

This is boilerplate code for the assignments which might be helpful.
Installation Instructions

sudo apt install libglew-dev libglfw3-dev libglm-dev cmake pkg-config
Download QtCreator
Make and Run :)

License
-------
The MIT License https://meghprkh.mit-license.org/
Controls

Copyright &copy; 2018 Megh Parikh <[email protected]>
Use Left arrow key to move left, Use Right arrow key to move right, Use Up arrow key to move forward, Use down arrow key to move backward.
Use f to fire cannon and mouse to aim, c for camera views , s to change sail.

Scroll works on top-view mode.
28 changes: 15 additions & 13 deletions src/barrel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@

Barrel::Barrel(float x, float y, color_t color) {
this->position = glm::vec3(x, y, 0);
this->size = size;
//rotation = 20;
// ngift = -1;
// Our vertices. Three consecutive floats give a 3D vertex; Three consecutive vertices give a triangle.
// A cube has 6 faces with 2 triangles each, so this makes 6*2=12 triangles, and 12*3 vertices
this->size = 10;
int pos=0,i,k,n=100;
float j=0;

GLfloat vertex_buffer_data[180*n+18];
GLfloat g_vertex_buffer_data[180*n];
float pi = 3.14159, angle = 0, theta=(2*pi)/n;
for(j=0;j<4;j+=0.2){
for(j=0;j<2;j+=0.1){
for(i=0;i<n;i++){
g_vertex_buffer_data[pos++]= 10*j;
g_vertex_buffer_data[pos++]= 0.0f;
Expand All @@ -33,13 +29,13 @@ Barrel::Barrel(float x, float y, color_t color) {
}

static const GLfloat l_vertex_buffer_data[] = {
0.0,-1*this->size, 0.0,
38.0, this->size, 0.0,
38.0,-1*this->size, 0.0,
0.0,0.0,-1*this->size,
19.0,0.0, this->size,
19.0,0.0,-1*this->size,

0.0,-1*this->size, 0.0,
38.0, this->size, 0.0,
0.0, this->size, 0.0
0.0,0.0,-1*this->size,
19.0,0.0, this->size,
0.0,0.0, this->size,
};

for(i=0;i<180*n+18;i++){
Expand All @@ -66,4 +62,10 @@ void Barrel::draw(glm::mat4 VP) {

void Barrel::set_position(float x, float y) {
this->position = glm::vec3(x, y, 0);
}
}

bounding_box_t Barrel::bounding_box() {
float x = this->position.x, y = this->position.y;
bounding_box_t bbox = { x, y, 9, 9};
return bbox;
}
42 changes: 38 additions & 4 deletions src/cube.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ Cube::Cube(float x, float y, color_t color) {
this->position = glm::vec3(x, y, 0);
this->rotation = 0;
this->launch_speed = 0;
speed = 1.0;
// Our vertices. Three consecutive floats give a 3D vertex; Three consecutive vertices give a triangle.
// A cube has 6 faces with 2 triangles each, so this makes 6*2=12 triangles, and 12*3 vertices
speed = 2.0;
this->angular_speed = 0.25;
this->speed_y = 0;
this->level_angle = 0;
this->acceleration_y = -0.0001;

static const GLfloat vertex_buffer_data[] = {
4.0f,-6.0f,-2.0f,
3.0f, 6.0f, 2.0f,
Expand Down Expand Up @@ -78,9 +81,13 @@ void Cube::draw(glm::mat4 VP) {
Matrices.model = glm::mat4(1.0f);
glm::mat4 translate = glm::translate (this->position); // glTranslatef
glm::mat4 rotate = glm::rotate((float) (this->rotation * M_PI / 180.0f), glm::vec3(0, 0, 1));
glm::mat4 rotate1 = glm::rotate((float) (this->level_angle * M_PI / 180.0f), glm::vec3(
this->position.x,
this->position.y,
this->position.z - 2));
// No need as coords centered at 0, 0, 0 of cube arouund which we waant to rotate
// rotate = rotate * glm::translate(glm::vec3(0, -0.6, 0));
Matrices.model *= (translate * rotate);
Matrices.model *= (translate * rotate * rotate1);
glm::mat4 MVP = VP * Matrices.model;
glUniformMatrix4fv(Matrices.MatrixID, 1, GL_FALSE, &MVP[0][0]);
draw3DObject(this->object);
Expand All @@ -105,6 +112,33 @@ void Cube::tick() {
// this->position.y -= speed;
}

void Cube::shm(){
if(this->acceleration_y > 0){
if(this->position.y + speed_y > 60.7){
acceleration_y = -acceleration_y;
speed_y = 0.02;
}
else{
// this->position.y += speed_y;
speed_y -= acceleration_y;
}
}
if(this->acceleration_y < 0){
if(this->position.y - speed_y < 60.1){
acceleration_y = -acceleration_y;
speed_y = 0.02;
}
else{
// this->position.y -= speed_y;
speed_y += acceleration_y;
}
}
if(level_angle < -5.0f || level_angle > 5.0f){
angular_speed = -angular_speed;
}
this->level_angle += angular_speed;
}

bounding_box_t Cube::bounding_box() {
float x = this->position.x, y = this->position.y;
bounding_box_t bbox = { x, y, 9, 9};
Expand Down
5 changes: 5 additions & 0 deletions src/cube.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ class Cube {
float launch_speed;
void draw(glm::mat4 VP);
void set_position(float x, float y);
float angular_speed;
float speed_y;
float level_angle;
float acceleration_y;
void tick();
void shm();
bounding_box_t bounding_box();
double speed;
private:
Expand Down
5 changes: 4 additions & 1 deletion src/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ void mouseButton(GLFWwindow *window, int button, int action, int mods) {
}

void scroll_callback(GLFWwindow *window, double xoffset, double yoffset) {
// Do something
if(yoffset<0)
zoom_camera(1);
if(yoffset>0)
zoom_camera(-1);
}

void cursor_position_callback(GLFWwindow* window, double xpos, double ypos) {
Expand Down
Loading

0 comments on commit 12f0ab8

Please sign in to comment.