Need help with your Discussion

Get a timely done, PLAGIARISM-FREE paper
from our highly-qualified writers!

glass
pen
clip
papers
heaphones

Not sure how to do this

Not sure how to do this

Not sure how to do this

Question Description

CS 330 Practice Activity 9 Guidelines and RubricOverviewIn this course, practice activities will help you to learn OpenGL and build computer graphics skills thatyou will need to complete a successful final project.In Practice Activity 9, you will go beyond the requirement of the final project by animating a textured 3Dpyramid.If you have trouble completing the assignment, be sure to post your questions or issues to the GraphicsTroubleshooting discussion topic. It is essential to ask for help when you need it and successfullycomplete each activity, as the course continues to build on earlier learning.PromptFirst, read the resource on animating computer animation. Also review the Module Eight Tutorial onanimating a 3D cube. You will use similar methods to complete this assignment. Review Tutorial 1-2 forinstructions on creating a context.To complete this assignment, start with the code you developed to produce a textured 3D pyramid inModule Six.Add animation code that will allow the pyramid to rotate slowly in the XYZ axes.

/*

* Activity6.cpp

*/

#include <Windows.h>

#include <iostream>

#include <GL/glew.h>

#include <GL/freeglut.h>

//GLM Math Header Inclusions */

#include <glm/glm.hpp>

#include <glm/gtc/matrix_transform.hpp>

#include <glm/gtc/type_ptr.hpp>

using namespace std; // Standard namespace

#define GLSL(Version, Source) “#version ” #Version “n” #Source

#define WINDOW_TITLE “Modern OpenGL”

/* Variable declarations for shader, window size initialization, buffer and array objects*/

GLint shaderProgram, WindowWidth = 800, WindowHeight = 600;

GLuint VBO, VAO;

GLfloat cameraSpeed = 0.0005f; //Movement speed per frame

GLchar currentKey; //Will store key pressed

int keymod; //check for alt

GLfloat scale_by_y=2.0f;

GLfloat scale_by_z=2.0f;

GLfloat scale_by_x=2.0f;

GLfloat lastMouseX = 400, lastMouseY = 300; //locks mouse cursor at the center of the screen

GLfloat mouseXoffset, mouseYoffset , yaw = 0.0f ,pitch = 0.0f; //mouse offset , yaw and pitch variables

GLfloat sensitivity = 0.01f; //used for mouse and camera sensitivity

bool mouseDetected = true; //initially true when mouse is detected

bool rotate = false;

bool checkMotion = false;

bool checkZoom = false;

//Global vector declarations

glm::vec3 CameraPosition = glm::vec3(0.0f, 0.0f, 0.0f); // Initial camera position. Placed units in Z

glm::vec3 CameraUpY = glm::vec3(0.0f, 1.0f, 0.0f); //Temporary y unit vector

glm::vec3 CameraForwardZ = glm::vec3(0.0f, 0.0f, -1.0f); //Temporary z unit vector

glm::vec3 front; //temporary z unit vector for mouse

/*Function prototypes */

void UResizeWindow(int, int);

void URenderGraphics(void);

void UCreateShader(void);

void UCreateBuffers(void);

void UMouseMove(int x , int y);

void OnMouseClicks(int button, int state, int x , int y);

void onMotion(int x, int y);

/* Vector Shader Source Code */

/* Vertex Shader Source Code*/

const GLchar * vertexShaderSource =”#version 400 coren”

// Vertex data from Vertex Attrib Pointer 0

“layout(location = 0) in vec3 position;”

// Color data from Vertex Attrib Pointer 1

“layout(location = 1) in vec3 color;”

//variable to transfer color data to the fragment shader

“out vec3 mobileColor;”

//Global variables for the transform matrices

“uniform mat4 model;”

“uniform mat4 view;”

“uniform mat4 projection;”

“void main()n”

“{n”

// transforms vertices to clip coordinates

“gl_Position = projection * view * model * vec4(position, 1.0f);”

// references incoming color data

“mobileColor = color;”

“}n”;

/* Fragment Shader Source Code*/

const GLchar * fragmentShaderSource =”#version 400 coren”

“in vec3 mobileColor;” // Variable to hold incoming color data from vertex shader

“out vec4 gpuColor;” // Variable to pass color data to the GPU

“void main()n”

“{n”

“gpuColor = vec4(mobileColor, 1.0);” // Sends color data to the GPU for rendering

“}n”;

/* Fragment Shader Source Code */

/* Main Program */

int main(int argc, char* argv[])

{

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);

glutInitWindowSize(WindowWidth, WindowHeight);

glutCreateWindow(WINDOW_TITLE);

glutReshapeFunc(UResizeWindow);

glewExperimental = GL_TRUE;

if (glewInit() != GLEW_OK)

{

std::cout << “Failed to initialize GLEW” << std::endl;

return -1;

}

UCreateShader();

UCreateBuffers();

// Use the Shader program

glUseProgram(shaderProgram);

glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Set background color

glutDisplayFunc(URenderGraphics);

glutPassiveMotionFunc(UMouseMove); // detect mouse move

glutMotionFunc(onMotion);

glutMouseFunc(OnMouseClicks);

glutMainLoop();

// Destroys Buffer objects once used

glDeleteVertexArrays(1, &VAO);

glDeleteBuffers(1, &VBO);

return 0;

}

/* Resizes the Window*/

void UResizeWindow(int w, int h)

{

WindowWidth = w;

WindowHeight = h;

glViewport(0, 0, WindowWidth, WindowHeight);

}

/* Renders graphics */

void URenderGraphics(void)

{

glEnable(GL_DEPTH_TEST); // Enable z-depth

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clears the screen

glBindVertexArray(VAO); // Active the Vertex Array object before rendering and transforming them

//* Create Movement Logic */

CameraForwardZ = front;

// Transforms the Object

glm::mat4 model;

model = glm::translate(model, glm::vec3(0.0f, 0.0f, 0.0f)); // Place the object at the center of the viewport

model = glm::rotate(model, 45.0f, glm::vec3(0.0, 1.0f, 0.0f)); // Rotate the object 45 degrees on the X

model = glm::scale(model, glm::vec3(scale_by_x,scale_by_y,scale_by_z)); // Increase the object size by a scale of 2

//Transforms the camera

glm::mat4 view;

view = glm::lookAt(CameraForwardZ, CameraPosition, CameraUpY);

// Creates a perspective projection

glm::mat4 projection;

projection = glm::perspective(45.0f, (GLfloat)WindowWidth / (GLfloat)WindowHeight, 0.1f, 100.0f);

// Retrieves and passes transform matrices to the Shader program

GLint modelLoc = glGetUniformLocation(shaderProgram, “model”);

GLint viewLoc = glGetUniformLocation(shaderProgram, “view”);

GLint projLoc = glGetUniformLocation(shaderProgram, “projection”);

glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));

glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(view));

glUniformMatrix4fv(projLoc, 1, GL_FALSE, glm::value_ptr(projection));

glutPostRedisplay();

// Draws the triangles

glDrawArrays(GL_TRIANGLES, 0, 36);

glBindVertexArray(0); // Deactivates the Vertex Array Object

glutSwapBuffers(); // Flips the back buffer with the front buffer every frame

}

/* Creates the Shader program */

void UCreateShader()

{

//Vertex shader

GLint vertexShader = glCreateShader(GL_VERTEX_SHADER); // Creates the Vertex shader

glShaderSource(vertexShader, 1, &vertexShaderSource, NULL); // Attaches the Vertex shader to the source code

glCompileShader(vertexShader); // Compiles the Vertex shader

// Fragment shader

GLint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); // Creates the Fragment shader

glShaderSource(fragmentShader, 1, &fragmentShaderSource, NULL); //Attaches the Fragment shader to the source code

glCompileShader(fragmentShader); // Compiles the Fragment shader

//Shader program

shaderProgram = glCreateProgram(); //Create the Shader program and returns an id

glAttachShader(shaderProgram, vertexShader); //Attach Vertex shader to the Shader program

glAttachShader(shaderProgram, fragmentShader);; // Attach Fragment shader to the shader program

glLinkProgram(shaderProgram); // Link vertex and fragment shader to shader program

//Delete the Vertex and Fragment shaders once linked

glDeleteShader(vertexShader);

glDeleteShader(fragmentShader);

}

void UCreateBuffers()

{

GLfloat vertices[] = {

//Positions //Color

//p1

-0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f,

0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f,

0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 0.0f,

0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 0.0f,

-0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 0.0f,

-0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f,

//p2

-0.5f, -0.5f, 0.5f, 0.0f, 1.0f, 0.0f,

0.5f, -0.5f, 0.5f, 0.0f, 1.0f, 0.0f,

0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,

0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,

-0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,

-0.5f, -0.5f, 0.5f, 0.0f, 1.0f, 0.0f,

//p3

-0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,

-0.5f, 0.5f, -0.5f, 0.0f, 0.0f, 1.0f,

-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, 1.0f,

-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, 1.0f,

-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,

-0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,

//p4

0.5f, 0.5f, 0.5f, 1.0f, 1.0f, 0.0f,

0.5f, 0.5f, -0.5f, 1.0f, 1.0f, 0.0f,

0.5f, -0.5f, -0.5f, 1.0f, 1.0f, 0.0f,

0.5f, -0.5f, -0.5f, 1.0f, 1.0f, 0.0f,

0.5f, -0.5f, 0.5f, 1.0f, 1.0f, 0.0f,

0.5f, 0.5f, 0.5f, 1.0f, 1.0f, 0.0f,

//p5

-0.5f, -0.5f, -0.5f, 0.0f, 1.0f, 1.0f,

0.5f, -0.5f, -0.5f, 0.0f, 1.0f, 1.0f,

0.5f, -0.5f, 0.5f, 0.0f, 1.0f, 1.0f,

0.5f, -0.5f, 0.5f, 0.0f, 1.0f, 1.0f,

-0.5f, -0.5f, 0.5f, 0.0f, 1.0f, 1.0f,

-0.5f, -0.5f, -0.5f, 0.0f, 1.0f, 1.0f,

-0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 1.0f,

0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 1.0f,

0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 1.0f,

0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 1.0f,

-0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 1.0f,

-0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 1.0f,

};

//Generate buffer ids

glGenVertexArrays(1, &VAO);

glGenBuffers(1, &VBO);

// Active the vertex Array object before binding and setting any VBOs and vertex Attribute Pointers

glBindVertexArray(VAO);

// Active the VBO

glBindBuffer(GL_ARRAY_BUFFER, VBO);

glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); //Copy vertices to VBO

//Set attribute pointer 0 to hold Position data

glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)0);

glEnableVertexAttribArray(0); // Enable vertex attribute

//Set attribute pointer 1 to hold Color data

glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));

glEnableVertexAttribArray(1); // Enable vertex attribute

glBindVertexArray(0); // Deactivates the VAO which is good practice

}

void UMouseMove(int x, int y){

front.x = 10.0f * cos(yaw);

front.y = 10.0f * sin(pitch);

front.z = sin(yaw) * cos(pitch) * 10.0f;

}

void onMotion(int curr_x, int curr_y) {

//if left alt and mouse down are set

if(checkMotion){

//gets the direction the mouse was moved

mouseXoffset = curr_x – lastMouseX;

mouseYoffset = lastMouseY – curr_y;

//updates with new mouse coorditaes

lastMouseX = curr_x;

lastMouseY = curr_y;

//Applies sensitivity to mouse direction

mouseXoffset *= sensitivity;

mouseYoffset *= sensitivity;

//get the direction of the mouse

//if there is changes in yaw, then it is moving along X

if(yaw != yaw+mouseXoffset && pitch == pitch+mouseYoffset){

//INCREAMENT yaw

yaw += mouseXoffset;

//else movement in y

}else if(pitch != pitch+mouseYoffset && yaw == yaw+mouseXoffset ){

//increament y to move vertical

pitch += mouseYoffset;

}

front.x = 10.0f * cos(yaw);

front.y = 10.0f * sin(pitch);

front.z = sin(yaw) * cos(pitch) * 10.0f;

}

//check if user is zooming, alt, right mouse button and down

if(checkZoom){

//determine the direction of the , whether up or down

if(lastMouseY > curr_y){

//increament scale values

scale_by_y += 0.1f;

scale_by_x += 0.1f;

scale_by_z += 0.1f;

//redisplay

glutPostRedisplay();

}else{

//decreament scale values, zoom in

scale_by_y -= 0.1f;

scale_by_x -= 0.1f;

scale_by_z -= 0.1f;

//control zoom in size

if(scale_by_y < 0.2f){

scale_by_y = 0.2f;

scale_by_x = 0.2f;

scale_by_z = 0.2f;

}

glutPostRedisplay();

}

//update x and y

lastMouseY = curr_y;

lastMouseX = curr_x;

}

}

void OnMouseClicks(int button, int state, int x, int y) {

keymod = glutGetModifiers(); // checks for modifier keys like alt, shif and ctrl

checkMotion = false; //set checkMotion to false

//check if button is left, and mod is alt and state is down, all should be true

if(button == GLUT_LEFT_BUTTON && keymod == GLUT_ACTIVE_ALT && state == GLUT_DOWN) {

//if true then set motion true

checkMotion = true;

//zooming to be false

checkZoom = false;

}else if(button == GLUT_RIGHT_BUTTON && keymod == GLUT_ACTIVE_ALT && state == GLUT_DOWN){

//zoom to be true and motion to be false

checkMotion = false;

checkZoom = true;

}

}/*

* Activity6.cpp

*

* Created on: Aug 7, 2019

* Author: emir.hasanbeg_snhu

*/

#include <Windows.h>

#include <iostream>

#include <GL/glew.h>

#include <GL/freeglut.h>

//GLM Math Header Inclusions */

#include <glm/glm.hpp>

#include <glm/gtc/matrix_transform.hpp>

#include <glm/gtc/type_ptr.hpp>

using namespace std; // Standard namespace

#define GLSL(Version, Source) “#version ” #Version “n” #Source

#define WINDOW_TITLE “Modern OpenGL”

/* Variable declarations for shader, window size initialization, buffer and array objects*/

GLint shaderProgram, WindowWidth = 800, WindowHeight = 600;

GLuint VBO, VAO;

GLfloat cameraSpeed = 0.0005f; //Movement speed per frame

GLchar currentKey; //Will store key pressed

int keymod; //check for alt

GLfloat scale_by_y=2.0f;

GLfloat scale_by_z=2.0f;

GLfloat scale_by_x=2.0f;

GLfloat lastMouseX = 400, lastMouseY = 300; //locks mouse cursor at the center of the screen

GLfloat mouseXoffset, mouseYoffset , yaw = 0.0f ,pitch = 0.0f; //mouse offset , yaw and pitch variables

GLfloat sensitivity = 0.01f; //used for mouse and camera sensitivity

bool mouseDetected = true; //initially true when mouse is detected

bool rotate = false;

bool checkMotion = false;

bool checkZoom = false;

//Global vector declarations

glm::vec3 CameraPosition = glm::vec3(0.0f, 0.0f, 0.0f); // Initial camera position. Placed units in Z

glm::vec3 CameraUpY = glm::vec3(0.0f, 1.0f, 0.0f); //Temporary y unit vector

glm::vec3 CameraForwardZ = glm::vec3(0.0f, 0.0f, -1.0f); //Temporary z unit vector

glm::vec3 front; //temporary z unit vector for mouse

/*Function prototypes */

void UResizeWindow(int, int);

void URenderGraphics(void);

void UCreateShader(void);

void UCreateBuffers(void);

void UMouseMove(int x , int y);

void OnMouseClicks(int button, int state, int x , int y);

void onMotion(int x, int y);

/* Vector Shader Source Code */

/* Vertex Shader Source Code*/

const GLchar * vertexShaderSource =”#version 400 coren”

// Vertex data from Vertex Attrib Pointer 0

“layout(location = 0) in vec3 position;”

// Color data from Vertex Attrib Pointer 1

“layout(location = 1) in vec3 color;”

//variable to transfer color data to the fragment shader

“out vec3 mobileColor;”

//Global variables for the transform matrices

“uniform mat4 model;”

“uniform mat4 view;”

“uniform mat4 projection;”

“void main()n”

“{n”

// transforms vertices to clip coordinates

“gl_Position = projection * view * model * vec4(position, 1.0f);”

// references incoming color data

“mobileColor = color;”

“}n”;

/* Fragment Shader Source Code*/

const GLchar * fragmentShaderSource =”#version 400 coren”

“in vec3 mobileColor;” // Variable to hold incoming color data from vertex shader

“out vec4 gpuColor;” // Variable to pass color data to the GPU

“void main()n”

“{n”

“gpuColor = vec4(mobileColor, 1.0);” // Sends color data to the GPU for rendering

“}n”;

/* Fragment Shader Source Code */

/* Main Program */

int main(int argc, char* argv[])

{

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);

glutInitWindowSize(WindowWidth, WindowHeight);

glutCreateWindow(WINDOW_TITLE);

glutReshapeFunc(UResizeWindow);

glewExperimental = GL_TRUE;

if (glewInit() != GLEW_OK)

{

std::cout << “Failed to initialize GLEW” << std::endl;

return -1;

}

UCreateShader();

UCreateBuffers();

// Use the Shader program

glUseProgram(shaderProgram);

glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Set background color

glutDisplayFunc(URenderGraphics);

glutPassiveMotionFunc(UMouseMove); // detect mouse move

glutMotionFunc(onMotion);

glutMouseFunc(OnMouseClicks);

glutMainLoop();

// Destroys Buffer objects once used

glDeleteVertexArrays(1, &VAO);

glDeleteBuffers(1, &VBO);

return 0;

}

/* Resizes the Window*/

void UResizeWindow(int w, int h)

{

WindowWidth = w;

WindowHeight = h;

glViewport(0, 0, WindowWidth, WindowHeight);

}

/* Renders graphics */

void URenderGraphics(void)

{

glEnable(GL_DEPTH_TEST); // Enable z-depth

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clears the screen

glBindVertexArray(VAO); // Active the Vertex Array object before rendering and transforming them

//* Create Movement Logic */

CameraForwardZ = front;

// Transforms the Object

glm::mat4 model;

model = glm::translate(model, glm::vec3(0.0f, 0.0f, 0.0f)); // Place the object at the center of the viewport

model = glm::rotate(model, 45.0f, glm::vec3(0.0, 1.0f, 0.0f)); // Rotate the object 45 degrees on the X

model = glm::scale(model, glm::vec3(scale_by_x,scale_by_y,scale_by_z)); // Increase the object size by a scale of 2

//Transforms the camera

glm::mat4 view;

view = glm::lookAt(CameraForwardZ, CameraPosition, CameraUpY);

// Creates a perspective projection

glm::mat4 projection;

projection = glm::perspective(45.0f, (GLfloat)WindowWidth / (GLfloat)WindowHeight, 0.1f, 100.0f);

// Retrieves and passes transform matrices to the Shader program

GLint modelLoc = glGetUniformLocation(shaderProgram, “model”);

GLint viewLoc = glGetUniformLocation(shaderProgram, “view”);

GLint projLoc = glGetUniformLocation(shaderProgram, “projection”);

glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));

glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(view));

glUniformMatrix4fv(projLoc, 1, GL_FALSE, glm::value_ptr(projection));

glutPostRedisplay();

// Draws the triangles

glDrawArrays(GL_TRIANGLES, 0, 36);

glBindVertexArray(0); // Deactivates the Vertex Array Object

glutSwapBuffers(); // Flips the back buffer with the front buffer every frame

}

/* Creates the Shader program */

void UCreateShader()

{

//Vertex shader

GLint vertexShader = glCreateShader(GL_VERTEX_SHADER); // Creates the Vertex shader

glShaderSource(vertexShader, 1, &vertexShaderSource, NULL); // Attaches the Vertex shader to the source code

glCompileShader(vertexShader); // Compiles the Vertex shader

// Fragment shader

GLint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); // Creates the Fragment shader

glShaderSource(fragmentShader, 1, &fragmentShaderSource, NULL); //Attaches the Fragment shader to the source code

glCompileShader(fragmentShader); // Compiles the Fragment shader

//Shader program

shaderProgram = glCreateProgram(); //Create the Shader program and returns an id

glAttachShader(shaderProgram, vertexShader); //Attach Vertex shader to the Shader program

glAttachShader(shaderProgram, fragmentShader);; // Attach Fragment shader to the shader program

glLinkProgram(shaderProgram); // Link vertex and fragment shader to shader program

//Delete the Vertex and Fragment shaders once linked

glDeleteShader(vertexShader);

glDeleteShader(fragmentShader);

}

void UCreateBuffers()

{

GLfloat vertices[] = {

//Positions //Color

//p1

-0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f,

0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f,

0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 0.0f,

0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 0.0f,

-0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 0.0f,

-0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f,

//p2

-0.5f, -0.5f, 0.5f, 0.0f, 1.0f, 0.0f,

0.5f, -0.5f, 0.5f, 0.0f, 1.0f, 0.0f,

0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,

0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,

-0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,

-0.5f, -0.5f, 0.5f, 0.0f, 1.0f, 0.0f,

//p3

-0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,

-0.5f, 0.5f, -0.5f, 0.0f, 0.0f, 1.0f,

-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, 1.0f,

-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, 1.0f,

-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,

-0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,

//p4

0.5f, 0.5f, 0.5f, 1.0f, 1.0f, 0.0f,

0.5f, 0.5f, -0.5f, 1.0f, 1.0f, 0.0f,

0.5f, -0.5f, -0.5f, 1.0f, 1.0f, 0.0f,

0.5f, -0.5f, -0.5f, 1.0f, 1.0f, 0.0f,

0.5f, -0.5f, 0.5f, 1.0f, 1.0f, 0.0f,

0.5f, 0.5f, 0.5f, 1.0f, 1.0f, 0.0f,

//p5

-0.5f, -0.5f, -0.5f, 0.0f, 1.0f, 1.0f,

0.5f, -0.5f, -0.5f, 0.0f, 1.0f, 1.0f,

0.5f, -0.5f, 0.5f, 0.0f, 1.0f, 1.0f,

0.5f, -0.5f, 0.5f, 0.0f, 1.0f, 1.0f,

-0.5f, -0.5f, 0.5f, 0.0f, 1.0f, 1.0f,

-0.5f, -0.5f, -0.5f, 0.0f, 1.0f, 1.0f,

-0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 1.0f,

0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 1.0f,

0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 1.0f,

0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 1.0f,

-0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 1.0f,

-0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 1.0f,

};

//Generate buffer ids

glGenVertexArrays(1, &VAO);

glGenBuffers(1, &VBO);

// Active the vertex Array object before binding and setting any VBOs and vertex Attribute Pointers

glBindVertexArray(VAO);

// Active the VBO

glBindBuffer(GL_ARRAY_BUFFER, VBO);

glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); //Copy vertices to VBO

//Set attribute pointer 0 to hold Position data

glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)0);

glEnableVertexAttribArray(0); // Enable vertex attribute

//Set attribute pointer 1 to hold Color data

glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));

glEnableVertexAttribArray(1); // Enable vertex attribute

glBindVertexArray(0); // Deactivates the VAO which is good practice

}

void UMouseMove(int x, int y){

front.x = 10.0f * cos(yaw);

front.y = 10.0f * sin(pitch);

front.z = sin(yaw) * cos(pitch) * 10.0f;

}

void onMotion(int curr_x, int curr_y) {

//if left alt and mouse down are set

if(checkMotion){

//gets the direction the mouse was moved

mouseXoffset = curr_x – lastMouseX;

mouseYoffset = lastMouseY – curr_y;

//updates with new mouse coorditaes

lastMouseX = curr_x;

lastMouseY = curr_y;

//Applies sensitivity to mouse direction

mouseXoffset *= sensitivity;

mouseYoffset *= sensitivity;

//get the direction of the mouse

//if there is changes in yaw, then it is moving along X

if(yaw != yaw+mouseXoffset && pitch == pitch+mouseYoffset){

//INCREAMENT yaw

yaw += mouseXoffset;

//else movement in y

}else if(pitch != pitch+mouseYoffset && yaw == yaw+mouseXoffset ){

//increament y to move vertical

pitch += mouseYoffset;

}

front.x = 10.0f * cos(yaw);

front.y = 10.0f * sin(pitch);

front.z = sin(yaw) * cos(pitch) * 10.0f;

}

//check if user is zooming, alt, right mouse button and down

if(checkZoom){

//determine the direction of the , whether up or down

if(lastMouseY > curr_y){

//increament scale values

scale_by_y += 0.1f;

scale_by_x += 0.1f;

scale_by_z += 0.1f;

//redisplay

glutPostRedisplay();

}else{

//decreament scale values, zoom in

scale_by_y -= 0.1f;

scale_by_x -= 0.1f;

scale_by_z -= 0.1f;

//control zoom in size

if(scale_by_y < 0.2f){

scale_by_y = 0.2f;

scale_by_x = 0.2f;

scale_by_z = 0.2f;

}

glutPostRedisplay();

}

//update x and y

lastMouseY = curr_y;

lastMouseX = curr_x;

}

}

void OnMouseClicks(int button, int state, int x, int y) {

keymod = glutGetModifiers(); // checks for modifier keys like alt, shif and ctrl

checkMotion = false; //set checkMotion to false

//check if button is left, and mod is alt and state is down, all should be true

if(button == GLUT_LEFT_BUTTON && keymod == GLUT_ACTIVE_ALT && state == GLUT_DOWN) {

//if true then set motion true

checkMotion = true;

//zooming to be false

checkZoom = false;

}else if(button == GLUT_RIGHT_BUTTON && keymod == GLUT_ACTIVE_ALT && state == GLUT_DOWN){

//zoom to be true and motion to be false

checkMotion = false;

checkZoom = true;

}

}

Have a similar assignment? "Place an order for your assignment and have exceptional work written by our team of experts, guaranteeing you A results."

Order Solution Now

Our Service Charter


1. Professional & Expert Writers: Eminence Papers only hires the best. Our writers are specially selected and recruited, after which they undergo further training to perfect their skills for specialization purposes. Moreover, our writers are holders of masters and Ph.D. degrees. They have impressive academic records, besides being native English speakers.

2. Top Quality Papers: Our customers are always guaranteed of papers that exceed their expectations. All our writers have +5 years of experience. This implies that all papers are written by individuals who are experts in their fields. In addition, the quality team reviews all the papers before sending them to the customers.

3. Plagiarism-Free Papers: All papers provided by Eminence Papers are written from scratch. Appropriate referencing and citation of key information are followed. Plagiarism checkers are used by the Quality assurance team and our editors just to double-check that there are no instances of plagiarism.

4. Timely Delivery: Time wasted is equivalent to a failed dedication and commitment. Eminence Papers are known for the timely delivery of any pending customer orders. Customers are well informed of the progress of their papers to ensure they keep track of what the writer is providing before the final draft is sent for grading.

5. Affordable Prices: Our prices are fairly structured to fit in all groups. Any customer willing to place their assignments with us can do so at very affordable prices. In addition, our customers enjoy regular discounts and bonuses.

6. 24/7 Customer Support: At Eminence Papers, we have put in place a team of experts who answer all customer inquiries promptly. The best part is the ever-availability of the team. Customers can make inquiries anytime.

We Can Write It for You! Enjoy 20% OFF on This Order. Use Code SAVE20

Stuck with your Assignment?

Enjoy 20% OFF Today
Use code SAVE20