Skip to content

Commit 7624807

Browse files
committed
first
0 parents  commit 7624807

22 files changed

+1224
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.xcuserstate
2+
/xcuserdata/*
3+
.DS_*

Cube.cpp

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
2+
#include "Cube.h"
3+
#include "Window.h"
4+
5+
6+
Cube::Cube(GLuint shader){
7+
//Shader program
8+
this->shaderProgram = shader;
9+
10+
//VAO objects
11+
//Create array object and buffers, remember to delete!
12+
glGenVertexArrays(1, &VAO);
13+
glGenBuffers(1, &VBO);
14+
glGenBuffers(1, &EBO);
15+
glGenBuffers(1, &NBO);
16+
17+
// Bind VAO
18+
glBindVertexArray(VAO);
19+
20+
// Bind VBO
21+
glBindBuffer(GL_ARRAY_BUFFER, VBO);
22+
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices_), vertices_, GL_STATIC_DRAW);
23+
24+
glEnableVertexAttribArray(0);
25+
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)0);
26+
27+
// Bind EBO
28+
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
29+
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices_), indices_, GL_STATIC_DRAW);
30+
31+
// Bind the normals
32+
glBindBuffer(GL_ARRAY_BUFFER, NBO);
33+
glBufferData(GL_ARRAY_BUFFER, sizeof(normals_), normals_, GL_STATIC_DRAW);
34+
35+
glEnableVertexAttribArray(1);
36+
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 3*sizeof(GLfloat), (GLvoid*)0);
37+
38+
glBindBuffer(GL_ARRAY_BUFFER, 0);
39+
glBindVertexArray(0);
40+
}
41+
42+
Cube::~Cube(){
43+
glDeleteVertexArrays(1, &VAO);
44+
glDeleteBuffers(1, &VBO);
45+
glDeleteBuffers(1, &NBO);
46+
glDeleteBuffers(1, &EBO);
47+
}
48+
49+
void Cube::draw(glm::mat4 C){
50+
51+
this->toWorld = C;
52+
53+
//Draw
54+
glm::mat4 modelview = Window::V * toWorld;
55+
56+
uProjection = glGetUniformLocation(shaderProgram, "projection");
57+
uModelview = glGetUniformLocation(shaderProgram, "modelview");
58+
// Now send these values to the shader program
59+
glUniformMatrix4fv(uProjection, 1, GL_FALSE, &Window::P[0][0]);
60+
glUniformMatrix4fv(uModelview, 1, GL_FALSE, &modelview[0][0]);
61+
glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "model"), 1, GL_FALSE, &this->toWorld[0][0]);
62+
63+
glBindVertexArray(VAO);
64+
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0);
65+
//glDrawArrays(GL_POINTS, 0, 24);
66+
glBindVertexArray(0);
67+
}
68+
69+
void Cube::update(){
70+
71+
}

Cube.h

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
2+
#ifndef CUBE
3+
#define CUBE
4+
#include "Geode.h"
5+
6+
class Cube : public Geode{
7+
public:
8+
Cube(GLuint shader);
9+
~Cube();
10+
11+
void draw(glm::mat4 C);
12+
void update();
13+
14+
protected:
15+
GLfloat vertices_[8][3] = {
16+
// "Front" vertices
17+
{-1.0, -1.0, 1.0},
18+
{1.0, -1.0, 1.0},
19+
{1.0, 1.0, 1.0},
20+
{-1.0, 1.0, 1.0},
21+
// "Back" vertices
22+
{-1.0, -1.0, -1.0},
23+
{1.0, -1.0, -1.0},
24+
{1.0, 1.0, -1.0},
25+
{-1.0, 1.0, -1.0}
26+
};
27+
28+
GLfloat normals_[8][3] = {
29+
// "Front"
30+
{-1.0f/3, -1.0f/3, 1.0f/3},
31+
{1.0f/3, -1.0f/3, 1.0f/3},
32+
{1.0f/3, 1.0f/3, 1.0f/3},
33+
{0.0, 1.0, 0.0},
34+
// "Back"
35+
{-1.0f/3, -1.0f/3, -1.0f/3},
36+
{1.0f/3, -1.0f/3, -1.0f/3},
37+
{1.0f/3, 1.0f/3, -1.0f/3},
38+
{-1.0f/3, 1.0f/3, -1.0f/3}
39+
};
40+
41+
GLuint indices_[6][6] = {
42+
// Front face
43+
{0, 1, 2, 2, 3, 0},
44+
// Top face
45+
{1, 5, 6, 6, 2, 1},
46+
// Back face
47+
{7, 6, 5, 5, 4, 7},
48+
// Bottom face
49+
{4, 0, 3, 3, 7, 4},
50+
// Left face
51+
{4, 5, 1, 1, 0, 4},
52+
// Right face
53+
{3, 2, 6, 6, 7, 3}
54+
};
55+
56+
glm::mat4 toWorld;
57+
};
58+
59+
#endif

Geode.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "Geode.h"

Geode.h

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef GEODE
2+
#define GEODE
3+
#include "Node.h"
4+
5+
class Geode : public Node{
6+
public:
7+
virtual void draw(glm::mat4 C) = 0;
8+
virtual void update() = 0;
9+
10+
protected:
11+
GLuint VBO, VAO, EBO, NBO;
12+
GLuint uProjection, uModelview;
13+
GLuint shaderProgram;
14+
15+
glm::mat4 toWorld;
16+
};
17+
18+
#endif

Group.cpp

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#include "Group.h"
2+
#include "MatrixTransform.h"
3+
#include "Node.h"
4+
#include "Geode.h"
5+
#include <iostream>
6+
7+
Group::Group(){
8+
children = std::vector<Node*>();
9+
}
10+
11+
Group::~Group(){
12+
//Dlete all it's children
13+
for(auto child : children){
14+
delete child;
15+
}
16+
}
17+
18+
//Add a child
19+
void Group::addChild(Node *n){
20+
children.push_back(n);
21+
}
22+
//Remove a child
23+
void Group::removeChild(Node *n){
24+
//children.remove(n);
25+
}
26+
//Draw all the children
27+
void Group::draw(glm::mat4 C){
28+
glm::vec4 translation = C * glm::vec4(0,0,0,1);
29+
center = translation;
30+
for(auto child : children){
31+
child->draw(C);
32+
}
33+
}
34+
//Update because piazza said so
35+
void Group::update() {
36+
37+
}
38+
39+
void Group::setBoundsForRobot(){
40+
// boundingSphere = new Sphere();
41+
}
42+
43+
void Group::drawBoundingSphere(GLuint shader){
44+
45+
}
46+
47+
std::vector<Node*> Group::getChildrenVector(){
48+
return children;
49+
}
50+
51+
glm::vec3 Group::getPoint(){
52+
return glm::vec3(center.x, center.y, center.z);
53+
}
54+
55+
56+
57+
58+
59+
60+
61+

Group.h

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#ifndef GROUP
2+
#define GROUP
3+
#include "Node.h"
4+
#include <glm/gtc/matrix_transform.hpp>
5+
#include <list>
6+
#include <vector>
7+
//#include "Sphere.h"
8+
9+
class Group : public Node{
10+
public:
11+
Group();
12+
~Group();
13+
//Add a child
14+
void addChild(Node *n);
15+
//Remove a child
16+
void removeChild(Node *n);
17+
//Draw all the children
18+
virtual void draw(glm::mat4 C);
19+
//Update because piazza said so
20+
void update();
21+
22+
void setBoundsForRobot();
23+
void drawBoundingSphere(GLuint);
24+
glm::vec3 getPoint();
25+
26+
std::vector<Node*> getChildrenVector();
27+
28+
protected:
29+
std::vector<Node*> children;
30+
31+
// Sphere* boundingSphere;
32+
glm::vec4 center;
33+
float radius = 1.75f;
34+
};
35+
36+
#endif

MatrixTransform.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include "MatrixTransform.h"
2+
3+
//Constructor
4+
MatrixTransform::MatrixTransform(glm::mat4 C){
5+
this->M = C * M;
6+
}
7+
//Destructor
8+
MatrixTransform::~MatrixTransform(){
9+
for(auto child : children){
10+
delete child;
11+
}
12+
Group::~Group();
13+
}
14+
15+
//Update the MT
16+
void MatrixTransform::update(glm::mat4 update){
17+
this->M = update * M;
18+
}
19+
20+
//Pass down this transformation to all children
21+
void MatrixTransform::draw(glm::mat4 C){
22+
glm::mat4 M_new = C * M;
23+
24+
for(auto child : children){
25+
child->draw(M_new);
26+
}
27+
}
28+
29+
//Get the child beneath this MT
30+
Node* MatrixTransform::getChild(){
31+
return this->children[0];
32+
}

MatrixTransform.h

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef MTFORM
2+
#define MTFORM
3+
#include <stdio.h>
4+
#include "Group.h"
5+
6+
class MatrixTransform : public Group{
7+
public:
8+
MatrixTransform(glm::mat4);
9+
~MatrixTransform();
10+
//Pass down this transformation to all children
11+
void draw(glm::mat4 C);
12+
void update(glm::mat4);
13+
Node* getChild();
14+
protected:
15+
//Model matrix
16+
glm::mat4 M = glm::mat4(1.0f);
17+
};
18+
19+
#endif

Node.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#include "Node.h"
2+

Node.h

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef NODE
2+
#define NODE
3+
#include "glm/glm.hpp"
4+
#define GLFW_INCLUDE_GLEXT
5+
#ifdef __APPLE__
6+
#define GLFW_INCLUDE_GLCOREARB
7+
#else
8+
#include <GL/glew.h>
9+
#endif
10+
#include <GLFW/glfw3.h>
11+
12+
class Node {
13+
public:
14+
virtual void draw(glm::mat4 C) = 0; //Used to draw the geodes
15+
virtual void update() = 0; //Used to update the bounding sphere
16+
17+
};
18+
19+
#endif

0 commit comments

Comments
 (0)