Skip to content

Commit

Permalink
Allow easier change of colors
Browse files Browse the repository at this point in the history
  • Loading branch information
RicardoEPRodrigues committed Oct 19, 2017
1 parent 74de733 commit 1912df0
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 60 deletions.
9 changes: 3 additions & 6 deletions src/Tangram/Parallelogram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@ namespace ThreeEngine {
transform.SetIdentity();
}

Parallelogram::Parallelogram(Parallelogram::Vertex vertices[3]) {
shaderProgram = nullptr;
transform.SetIdentity();

for (int i = 0; i < 3; ++i) {
Vertices[i] = vertices[i];
Parallelogram::Parallelogram(GLfloat RGBA[6][4]) : Parallelogram() {
for (int i = 0; i < 6; ++i) {
std::copy(std::begin(RGBA[i]), std::end(RGBA[i]), Vertices[i].RGBA);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Tangram/Parallelogram.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ namespace ThreeEngine {

Parallelogram();

Parallelogram(Vertex vertices[6]);
explicit Parallelogram(GLfloat RGBA[6][4]);

virtual ~Parallelogram();
~Parallelogram() override;

void Init() override;

Expand Down
9 changes: 3 additions & 6 deletions src/Tangram/Square.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@ namespace ThreeEngine {
transform.SetIdentity();
}

Square::Square(Square::Vertex vertices[3]) {
shaderProgram = nullptr;
transform.SetIdentity();

for (int i = 0; i < 3; ++i) {
Vertices[i] = vertices[i];
Square::Square(GLfloat RGBA[6][4]) : Square() {
for (int i = 0; i < 6; ++i) {
std::copy(std::begin(RGBA[i]), std::end(RGBA[i]), Vertices[i].RGBA);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Tangram/Square.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ namespace ThreeEngine {

Square();

Square(Vertex vertices[6]);
explicit Square(GLfloat RGBA[6][4]);

virtual ~Square();
~Square() override;

void Init() override;

Expand Down
102 changes: 67 additions & 35 deletions src/Tangram/Tangram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,15 @@ namespace ThreeEngine {
triangle->shaderProgram = wireframeProgram;
}
{ // Square
auto* square = new Square();
GLfloat RGBA[6][4] = {
{1.0f, 0.0f, 0.0f, 1.0f},
{0.5f, 0.1f, 0.8f, 1.0f},
{0.0f, 0.0f, 1.0f, 1.0f},
{0.5f, 0.1f, 0.8f, 1.0f},
{0.3f, 0.1f, 0.8f, 1.0f},
{0.0f, 0.0f, 1.0f, 1.0f}
};
auto* square = new Square(RGBA);
square->transform = Matrix::TranslationMatrix({-0.8f, 0, 0, 0});
actors.push_back((IActor*) square);

Expand Down Expand Up @@ -97,12 +105,12 @@ namespace ThreeEngine {
triangle->shaderProgram = wireframeProgram;
}
{ // Big triangle to the Top
Triangle::Vertex vertices[3] = {
{{0.0f, 0.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 0.0f, 1.0f}},
{{0.7071f, 0.0f, 0.0f, 1.0f}, {1.0f, 1.0f, 0.0f, 1.0f}},
{{0.0f, 0.7071f, 0.0f, 1.0f}, {1.0f, 0.0f, 1.0f, 1.0f}}
GLfloat RGBA[3][4] = {
{1.0f, 0.0f, 0.0f, 1.0f},
{1.0f, 1.0f, 0.0f, 1.0f},
{1.0f, 0.0f, 1.0f, 1.0f}
};
auto* triangle = new Triangle(vertices);
auto* triangle = new Triangle(RGBA);
Matrix2 transform2D =
(TMatrix<2, 2>) Matrix2::RotationMatrix(45) * Matrix2::ScaleMatrix(2, 2);
triangle->transform = viewM *
Expand All @@ -113,12 +121,12 @@ namespace ThreeEngine {
triangle->shaderProgram = colorProgram;
}
{ // Small triangle at the center
Triangle::Vertex vertices[3] = {
{{0.0f, 0.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 1.0f, 1.0f}},
{{0.7071f, 0.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 1.0f, 1.0f}},
{{0.0f, 0.7071f, 0.0f, 1.0f}, {0.0f, 0.0f, 1.0f, 1.0f}}
GLfloat RGBA[3][4] = {
{1.0f, 0.0f, 1.0f, 1.0f},
{0.0f, 1.0f, 1.0f, 1.0f},
{0.0f, 0.0f, 1.0f, 1.0f}
};
auto* triangle = new Triangle(vertices);
auto* triangle = new Triangle(RGBA);
Matrix2 transform2D = (TMatrix<2, 2>) Matrix2::RotationMatrix(-135);
triangle->transform = viewM * Matrix(transform2D);
actors.push_back((IActor*) triangle);
Expand Down Expand Up @@ -147,7 +155,15 @@ namespace ThreeEngine {
triangle->shaderProgram = colorProgram;
}
{ // Square
auto* square = new Square();
GLfloat RGBA[6][4] = {
{1.0f, 0.0f, 0.0f, 1.0f},
{0.5f, 0.1f, 0.8f, 1.0f},
{0.0f, 0.0f, 1.0f, 1.0f},
{0.5f, 0.1f, 0.8f, 1.0f},
{0.3f, 0.1f, 0.8f, 1.0f},
{0.0f, 0.0f, 1.0f, 1.0f}
};
auto* square = new Square(RGBA);
Matrix2 transform2D =
(TMatrix<2, 2>) Matrix2::RotationMatrix(-45);
square->transform = viewM * Matrix(transform2D);
Expand Down Expand Up @@ -220,12 +236,12 @@ namespace ThreeEngine {
triangle->shaderProgram = colorProgram;
}
{ // Small triangle at the center
Triangle::Vertex vertices[3] = {
{{0.0f, 0.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 1.0f, 1.0f}},
{{0.7071f, 0.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 1.0f, 1.0f}},
{{0.0f, 0.7071f, 0.0f, 1.0f}, {0.0f, 0.0f, 1.0f, 1.0f}}
GLfloat RGBA[3][4] = {
{1.0f, 0.0f, 1.0f, 1.0f},
{0.0f, 1.0f, 1.0f, 1.0f},
{0.0f, 0.0f, 1.0f, 1.0f}
};
auto* triangle = new Triangle(vertices);
auto* triangle = new Triangle(RGBA);
Matrix2 transform2D = (TMatrix<2, 2>) Matrix2::RotationMatrix(135);
triangle->transform =
viewM * Matrix::TranslationMatrix({0, -.5f, 0, 0}) * Matrix(transform2D);
Expand All @@ -234,12 +250,12 @@ namespace ThreeEngine {
triangle->shaderProgram = colorProgram;
}
{ // Big triangle to the Top
Triangle::Vertex vertices[3] = {
{{0.0f, 0.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 0.0f, 1.0f}},
{{0.7071f, 0.0f, 0.0f, 1.0f}, {1.0f, 1.0f, 0.0f, 1.0f}},
{{0.0f, 0.7071f, 0.0f, 1.0f}, {1.0f, 0.0f, 1.0f, 1.0f}}
GLfloat RGBA[3][4] = {
{1.0f, 0.0f, 0.0f, 1.0f},
{1.0f, 1.0f, 0.0f, 1.0f},
{1.0f, 0.0f, 1.0f, 1.0f}
};
auto* triangle = new Triangle(vertices);
auto* triangle = new Triangle(RGBA);
Matrix2 transform2D =
(TMatrix<2, 2>) Matrix2::RotationMatrix(45) * Matrix2::ScaleMatrix(2, 2);
triangle->transform =
Expand All @@ -249,7 +265,15 @@ namespace ThreeEngine {
triangle->shaderProgram = colorProgram;
}
{ // Square
auto* square = new Square();
GLfloat RGBA[6][4] = {
{1.0f, 0.0f, 0.0f, 1.0f},
{0.5f, 0.1f, 0.8f, 1.0f},
{0.0f, 0.0f, 1.0f, 1.0f},
{0.5f, 0.1f, 0.8f, 1.0f},
{0.3f, 0.1f, 0.8f, 1.0f},
{0.0f, 0.0f, 1.0f, 1.0f}
};
auto* square = new Square(RGBA);
Matrix2 transform2D =
(TMatrix<2, 2>) Matrix2::RotationMatrix(-45);
square->transform =
Expand Down Expand Up @@ -296,12 +320,12 @@ namespace ThreeEngine {
triangle->shaderProgram = wireframeProgram;
}
{ // Big triangle to the Top
Triangle::Vertex vertices[3] = {
{{0.0f, 0.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 0.0f, 1.0f}},
{{0.7071f, 0.0f, 0.0f, 1.0f}, {1.0f, 1.0f, 0.0f, 1.0f}},
{{0.0f, 0.7071f, 0.0f, 1.0f}, {1.0f, 0.0f, 1.0f, 1.0f}}
GLfloat RGBA[3][4] = {
{1.0f, 0.0f, 0.0f, 1.0f},
{1.0f, 1.0f, 0.0f, 1.0f},
{1.0f, 0.0f, 1.0f, 1.0f}
};
auto* triangle = new Triangle(vertices);
auto* triangle = new Triangle(RGBA);
Matrix2 transform2D =
(TMatrix<2, 2>) Matrix2::ScaleMatrix(2, 2);
triangle->transform =
Expand All @@ -312,14 +336,22 @@ namespace ThreeEngine {
triangle->shaderProgram = colorProgram;
}
{ // Square
auto* square = new Square();
GLfloat RGBA[6][4] = {
{1.0f, 0.0f, 0.0f, 1.0f},
{0.5f, 0.1f, 0.8f, 1.0f},
{0.0f, 0.0f, 1.0f, 1.0f},
{0.5f, 0.1f, 0.8f, 1.0f},
{0.3f, 0.1f, 0.8f, 1.0f},
{0.0f, 0.0f, 1.0f, 1.0f}
};
auto* square = new Square(RGBA);
Matrix2 transform2D =
(TMatrix<2, 2>) Matrix2::RotationMatrix(-45);
square->transform =
viewM * Matrix::TranslationMatrix({-0.8f, 0.0f, 0, 0}) * Matrix(transform2D);
actors.push_back((IActor*) square);

square->shaderProgram = wireframeProgram;
square->shaderProgram = colorProgram;
}
{ // Parallelogram
auto* parallelogram = new Parallelogram();
Expand All @@ -342,12 +374,12 @@ namespace ThreeEngine {
triangle->shaderProgram = wireframeProgram;
}
{ // Small triangle at the center
Triangle::Vertex vertices[3] = {
{{0.0f, 0.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 1.0f, 1.0f}},
{{0.7071f, 0.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 1.0f, 1.0f}},
{{0.0f, 0.7071f, 0.0f, 1.0f}, {0.0f, 0.0f, 1.0f, 1.0f}}
GLfloat RGBA[3][4] = {
{1.0f, 0.0f, 1.0f, 1.0f},
{0.0f, 1.0f, 1.0f, 1.0f},
{0.0f, 0.0f, 1.0f, 1.0f}
};
auto* triangle = new Triangle(vertices);
auto* triangle = new Triangle(RGBA);
triangle->transform =
viewM * Matrix::TranslationMatrix({0.7071f + .2f, -.7071f, 0, 0});
actors.push_back((IActor*) triangle);
Expand Down
9 changes: 3 additions & 6 deletions src/Tangram/Triangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@ namespace ThreeEngine {
transform.SetIdentity();
}

Triangle::Triangle(Triangle::Vertex vertices[3]) {
shaderProgram = nullptr;
transform.SetIdentity();

Triangle::Triangle(GLfloat RGBA[3][4]) : Triangle() {
for (int i = 0; i < 3; ++i) {
Vertices[i] = vertices[i];
std::copy(std::begin(RGBA[i]), std::end(RGBA[i]), Vertices[i].RGBA);
}
}

Expand All @@ -50,7 +47,7 @@ namespace ThreeEngine {
glGenVertexArrays(1, &vaoId);
glBindVertexArray(vaoId);
{
glGenBuffers(1, vboId);
glGenBuffers(2, vboId);

glBindBuffer(GL_ARRAY_BUFFER, vboId[0]);
glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);
Expand Down
4 changes: 2 additions & 2 deletions src/Tangram/Triangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ namespace ThreeEngine {

Triangle();

Triangle(Vertex vertices[3]);
explicit Triangle(GLfloat RGBA[3][4]);

virtual ~Triangle();
~Triangle() override;

void Init() override;

Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ int main(int argc, char* argv[]) {

{
Tangram engine;
engine.shapeToShow = Tangram::ShapeType::HEART;
engine.shapeToShow = Tangram::ShapeType::FISH;
engine.Init(argc, argv);
engine.Run();
}
Expand Down

0 comments on commit 1912df0

Please sign in to comment.