summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/arap.cpp40
-rw-r--r--src/arap.h8
-rwxr-xr-xsrc/glwidget.cpp7
-rw-r--r--src/graphics/shader.cpp8
-rw-r--r--src/graphics/shader.h2
-rw-r--r--src/graphics/shape.cpp44
-rw-r--r--src/graphics/shape.h6
-rwxr-xr-xsrc/main.cpp2
-rw-r--r--src/ocean/ocean.h9
9 files changed, 123 insertions, 3 deletions
diff --git a/src/arap.cpp b/src/arap.cpp
index 79fe475..94f2e3d 100644
--- a/src/arap.cpp
+++ b/src/arap.cpp
@@ -9,6 +9,7 @@
#include <Eigen/Core>
#include <Eigen/Sparse>
#include <Eigen/SVD>
+#include <QImage>
#include "ocean/ocean.h"
@@ -47,6 +48,45 @@ void ARAP::init
}
coeffMin = all_vertices.colwise().minCoeff();
coeffMax = all_vertices.colwise().maxCoeff();
+
+ minCorner = coeffMin;
+ maxCorner = coeffMax;
+
+
+// m_shape.initGroundPlane("cornell_box_full_lighting.png")
+// QImage ocean_floor_image;
+// GLuint ocean_floor_texture;
+// // Prepare filepath
+// QString ocean_floor_filepath = QString(":/resources/images/kitten.png");
+
+// // TASK 1: Obtain image from filepath
+// ocean_floor_image = QImage(ocean_floor_filepath);
+
+// // TASK 2: Format image to fit OpenGL
+// ocean_floor_image = ocean_floor_image.convertToFormat(QImage::Format_RGBA8888).mirrored();
+
+// // TASK 3: Generate kitten texture
+// glGenTextures(1, &ocean_floor_texture);
+
+// // TASK 9: Set the active texture slot to texture slot 0
+// glActiveTexture(GL_TEXTURE0);
+
+// // TASK 4: Bind kitten texture
+// glBindTexture(GL_TEXTURE_2D, ocean_floor_texture);
+
+// // TASK 5: Load image into kitten texture
+// glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ocean_floor_image.width(), ocean_floor_image.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, ocean_floor_image.bits());
+
+// // TASK 6: Set min and mag filters' interpolation mode to linear
+// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+// // TASK 7: Unbind kitten texture
+// glBindTexture(GL_TEXTURE_2D, 0);
+
+// // TASK 10: set the texture.frag uniform for our texture
+// glUseProgram(m_texture_shader);
+// glUniform1i(glGetUniformLocation(m_texture_shader, "sampler"), 0);
}
void ARAP::update(double seconds)
diff --git a/src/arap.h b/src/arap.h
index ca8967c..c4a24d7 100644
--- a/src/arap.h
+++ b/src/arap.h
@@ -1,6 +1,7 @@
#pragma once
#include "graphics/shape.h"
+#include "graphics/oceanshape.h"
#include "Eigen/StdList"
#include "Eigen/StdVector"
#include "ocean/ocean.h"
@@ -17,6 +18,7 @@ class ARAP
{
private:
Shape m_shape;
+ OceanShape m_oceanShape;
public:
ARAP();
@@ -38,6 +40,10 @@ public:
m_shape.draw(shader, mode);
}
+ void initGroundPlane(std::string texturePath, float depth, Shader* shader) {
+ m_shape.initGroundPlane(texturePath, depth, shader);
+ }
+
SelectMode select(Shader *shader, int vertex)
{
return m_shape.select(shader, vertex);
@@ -72,5 +78,7 @@ public:
ocean m_ocean;
double m_time = 0.00;
double m_timestep = 0.001;
+
+ Eigen::Vector3f minCorner, maxCorner;
};
diff --git a/src/glwidget.cpp b/src/glwidget.cpp
index 2801251..263b7dd 100755
--- a/src/glwidget.cpp
+++ b/src/glwidget.cpp
@@ -107,6 +107,8 @@ void GLWidget::initializeGL()
m_deltaTimeProvider.start();
m_intervalTimer.start(1000 / 60);
+
+ m_arap.initGroundPlane(":resources/images/kitty.png", 2, m_defaultShader);
}
void GLWidget::paintGL()
@@ -120,9 +122,14 @@ void GLWidget::paintGL()
m_defaultShader->setUniform("view", m_camera.getView());
Eigen::Matrix4f inverseView = m_camera.getView().inverse();
m_defaultShader->setUniform("inverseView", inverseView);
+ m_defaultShader->setUniform("widthBounds", m_arap.minCorner[0], m_arap.maxCorner[0]);
+ m_defaultShader->setUniform("lengthBounds", m_arap.minCorner[2], m_arap.maxCorner[2]);
+// m_defaultShader->setUniform("");
m_arap.draw(m_defaultShader, GL_TRIANGLES);
m_defaultShader->unbind();
+ glBindTexture(GL_TEXTURE_2D, 0);
+
glClear(GL_DEPTH_BUFFER_BIT);
// m_pointShader->bind();
diff --git a/src/graphics/shader.cpp b/src/graphics/shader.cpp
index 6ac9949..161eeae 100644
--- a/src/graphics/shader.cpp
+++ b/src/graphics/shader.cpp
@@ -83,6 +83,14 @@ void Shader::setUniform(const std::string &name, bool b) {
glUniform1i(m_uniforms[name], static_cast<GLint>(b));
}
+void Shader::setUniform(const std::string &name, Eigen::Vector3f v) {
+ glUniform3f(m_uniforms[name], static_cast<GLfloat>(v[0]), static_cast<GLfloat>(v[1]), static_cast<GLfloat>(v[2]));
+}
+
+void Shader::setUniform(const std::string &name, float a, float b) {
+ glUniform2f(m_uniforms[name], static_cast<GLfloat>(a), static_cast<GLfloat>(b));
+}
+
void Shader::setUniformArrayByIndex(const std::string &name, float f, size_t index) {
glUniform1f(m_uniformArrays[std::make_tuple(name, index)], f);
}
diff --git a/src/graphics/shader.h b/src/graphics/shader.h
index bc3c0c1..7e9dad4 100644
--- a/src/graphics/shader.h
+++ b/src/graphics/shader.h
@@ -32,6 +32,8 @@ public:
void setUniform(const std::string &name, float f);
void setUniform(const std::string &name, int i);
void setUniform(const std::string &name, bool b);
+ void setUniform(const std::string &name, Eigen::Vector3f v);
+ void setUniform(const std::string &name, float a, float b);
void setUniformArrayByIndex(const std::string &name, float f, size_t index);
void setUniformArrayByIndex(const std::string &name, const Eigen::Vector2f &vec2, size_t index);
diff --git a/src/graphics/shape.cpp b/src/graphics/shape.cpp
index 9459306..c5dde0d 100644
--- a/src/graphics/shape.cpp
+++ b/src/graphics/shape.cpp
@@ -1,6 +1,7 @@
#include "shape.h"
#include <iostream>
+//#include <QImage>
#include "graphics/shader.h"
using namespace Eigen;
@@ -126,8 +127,12 @@ void Shape::draw(Shader *shader, GLenum mode)
shader->setUniform("blue", m_blue);
shader->setUniform("alpha", m_alpha);
glBindVertexArray(m_surfaceVao);
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, ocean_floor_texture);
+ shader->setUniform("sampler", 1);
glDrawElements(mode, m_numSurfaceVertices, GL_UNSIGNED_INT, reinterpret_cast<GLvoid *>(0));
glBindVertexArray(0);
+ glBindTexture(GL_TEXTURE_2D, 0);
break;
}
case GL_POINTS:
@@ -276,3 +281,42 @@ void Shape::updateMesh(const std::vector<Eigen::Vector3i> &faces,
}
}
+void Shape::initGroundPlane(std::string texturePath, float depth, Shader* shader) {
+
+ // Prepare filepath
+ QString ocean_floor_filepath = QString(texturePath.c_str());
+
+ // TASK 1: Obtain image from filepath
+ this->ocean_floor_image = QImage(ocean_floor_filepath);
+
+ // TASK 2: Format image to fit OpenGL
+ ocean_floor_image = ocean_floor_image.convertToFormat(QImage::Format_RGBA8888).mirrored();
+ auto bits = this->ocean_floor_image.bits();
+ auto dat = ocean_floor_image.data_ptr();
+
+ // TASK 3: Generate texture
+ glGenTextures(1, &ocean_floor_texture);
+
+ // TASK 9: Set the active texture slot to texture slot 0
+ glActiveTexture(GL_TEXTURE0);
+
+ // TASK 4: Bind kitten texture
+ glBindTexture(GL_TEXTURE_2D, ocean_floor_texture);
+
+ // TASK 5: Load image into kitten texture
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ocean_floor_image.width(), ocean_floor_image.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, ocean_floor_image.bits());
+
+ // TASK 6: Set min and mag filters' interpolation mode to linear
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+ // TASK 7: Unbind kitten texture
+ glBindTexture(GL_TEXTURE_2D, 0);
+
+ // TASK 10: set the texture.frag uniform for our texture
+ glUseProgram(shader->id());
+// glUniform1i(glGetUniformLocation(shader->id(), "sampler"), 0);
+ shader->setUniform("sampler", 0);
+ glUseProgram(0);
+}
+
diff --git a/src/graphics/shape.h b/src/graphics/shape.h
index 1451c85..b909606 100644
--- a/src/graphics/shape.h
+++ b/src/graphics/shape.h
@@ -3,6 +3,8 @@
#include <GL/glew.h>
#include <vector>
#include <unordered_set>
+#include <QString>
+#include <QImage>
#define EIGEN_DONT_VECTORIZE
#define EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT
@@ -33,6 +35,8 @@ public:
void setColor(float r, float g, float b);
+ void initGroundPlane(std::string texturePath, float depth, Shader* shader);
+
void draw(Shader *shader, GLenum mode);
SelectMode select(Shader *shader, int vertex);
bool selectWithSpecifiedMode(Shader *shader, int vertex, SelectMode mode);
@@ -47,6 +51,8 @@ private:
GLuint m_surfaceVao;
GLuint m_surfaceVbo;
GLuint m_surfaceIbo;
+ GLuint ocean_floor_texture;
+ QImage ocean_floor_image;
unsigned int m_numSurfaceVertices;
unsigned int m_verticesSize;
diff --git a/src/main.cpp b/src/main.cpp
index a11e7d8..ae74af6 100755
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -12,7 +12,7 @@ int main(int argc, char *argv[])
// Create a Qt application
QApplication a(argc, argv);
- QCoreApplication::setApplicationName("ARAP");
+ QCoreApplication::setApplicationName("OCEAN");
QCoreApplication::setOrganizationName("CS 2240");
QCoreApplication::setApplicationVersion(QT_VERSION_STR);
diff --git a/src/ocean/ocean.h b/src/ocean/ocean.h
index 2387d2a..0d2d2c0 100644
--- a/src/ocean/ocean.h
+++ b/src/ocean/ocean.h
@@ -17,7 +17,12 @@ public:
void updateVertexAmplitudes(double t);
std::vector<Eigen::Vector3f> get_vertices();
std::vector<Eigen::Vector3i> get_faces();
-
+ int getLength() {
+ return this->length;
+ }
+ int getWidth() {
+ return this->width;
+ }
@@ -27,7 +32,7 @@ private:
const int width = 81; // width of grid
const int N = length * width; // total number of grid points
- const double A = 10.0; // numeric constant for the Phillips spectrum
+ const double A = 50.0; // numeric constant for the Phillips spectrum
const double V = .25; // wind speed
const std::pair<double, double> omega_wind
= std::make_pair(1.0, 0.0); // wind direction