diff --git a/shaders/fragment.glsl b/shaders/fragment.glsl index 09793a1..32d846f 100644 --- a/shaders/fragment.glsl +++ b/shaders/fragment.glsl @@ -40,7 +40,7 @@ vec3 hsv_to_rgb(float h, float s, float v) void main () { vec3 materialColor = hsv_to_rgb(zPos, 1, 1); - float diffuse = clamp(dot(normalize(norm), -normalize(vec3(0,0,1))), 0, 0.6); + float diffuse = clamp(dot(normalize(norm), -normalize(vec3(0,0,1))), 0.2, 0.6); vec3 color = materialColor*diffuse; frag_colour = vec4(color, 1.0); diff --git a/src/GLObjects/Mesh.h b/src/GLObjects/Mesh.h index 9778b5a..d90d6b8 100644 --- a/src/GLObjects/Mesh.h +++ b/src/GLObjects/Mesh.h @@ -18,7 +18,6 @@ protected: std::vector _xs; std::vector _ys; mutable std::vector _normals; - mutable std::array _adjacentTriangles; public: Mesh(ShaderProgram* shader, std::size_t size); @@ -34,7 +33,6 @@ protected: protected: virtual float heightMap(std::size_t nx, std::size_t ny) const = 0; - virtual float heightMap(float fx, float fy) const = 0; }; diff --git a/src/GLObjects/SpectralMesh.cpp b/src/GLObjects/SpectralMesh.cpp index e4bbf8a..1d97834 100644 --- a/src/GLObjects/SpectralMesh.cpp +++ b/src/GLObjects/SpectralMesh.cpp @@ -6,6 +6,13 @@ SpectralMesh::SpectralMesh(ShaderProgram *shader, std::size_t size): Mesh(shader _data = new float[size*size]; _spectrLine = new float[2*size]; _spectrLineComplex = (fftwf_complex*)fftwf_malloc((_size + 1)*sizeof(fftwf_complex)); + + float step = 1.0f/size; + for(std::size_t i = 0; i < size; ++i) { + _xs[i] = log10f(step*i + 1) - 0.5f; + _ys[i] = step*i - 0.5f; + std::cout << "[" << _xs[i] << ", " << _ys[i] << "]" << std::endl; + } } SpectralMesh::~SpectralMesh() { @@ -18,10 +25,6 @@ float SpectralMesh::heightMap(std::size_t nx, std::size_t ny) const { return *(_data + _size*ny + nx); } -float SpectralMesh::heightMap(float, float) const { - return 0.f; -} - void SpectralMesh::addLine(float *line, std::size_t depth) { fftwf_plan plan = fftwf_plan_dft_r2c_1d(2*_size, line, _spectrLineComplex, FFTW_ESTIMATE); fftwf_execute(plan); diff --git a/src/GLObjects/SpectralMesh.h b/src/GLObjects/SpectralMesh.h index 8ade9f6..22442aa 100644 --- a/src/GLObjects/SpectralMesh.h +++ b/src/GLObjects/SpectralMesh.h @@ -17,7 +17,6 @@ public: private: float heightMap(std::size_t nx, std::size_t ny) const override final; - float heightMap(float fx, float fy) const override final; void normalizeArray(float* array, std::size_t size); }; diff --git a/src/GLObjects/WaveMesh.cpp b/src/GLObjects/WaveMesh.cpp index a33ca2f..c643eac 100644 --- a/src/GLObjects/WaveMesh.cpp +++ b/src/GLObjects/WaveMesh.cpp @@ -7,12 +7,6 @@ float WaveMesh::heightMap(std::size_t nx, std::size_t ny) const { return cosf(d - _shift)*expf(-d/10.0f)/4; } -[[deprecated]] -float WaveMesh::heightMap(float fx, float fy) const { - float d = 50*sqrtf(fx*fx + fy*fy); - return cosf(d - _shift)*expf(-d/10.0f)/2; -} - void WaveMesh::setShift(float shift) { _shift = shift; update(); diff --git a/src/GLObjects/WaveMesh.h b/src/GLObjects/WaveMesh.h index 718d799..71465a3 100644 --- a/src/GLObjects/WaveMesh.h +++ b/src/GLObjects/WaveMesh.h @@ -15,7 +15,6 @@ public: private: float heightMap(std::size_t nx, std::size_t ny) const override final; - float heightMap(float fx, float fy) const override final; }; diff --git a/src/OGL.cpp b/src/OGL.cpp index ddff4b0..b1bb060 100644 --- a/src/OGL.cpp +++ b/src/OGL.cpp @@ -1,6 +1,7 @@ #include "OGL.h" #include "Camera.h" #include "utils.h" +#include "GLObjects/WaveMesh.h" #include #include @@ -149,7 +150,13 @@ void OGL::run() { updateFpsCounter(); glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); +// double time = glfwGetTime(); +// float shift = (float)fmod(time, 2*3.1415926); + for(IGLObject* obj: _glObjects) { +// WaveMesh* mesh = dynamic_cast(obj); +// mesh->setShift(shift*2); + //obj->scale(glm::vec3(1.0f, 1.0f, 1.0f)); obj->update(); obj->draw(); diff --git a/src/main.cpp b/src/main.cpp index bc46322..bfdb333 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,32 +20,32 @@ int main(int argc, char** argv) { ShaderProgram program("../shaders/vertex.glsl", "../shaders/fragment.glsl"); OGL::instance()->setCurShaderProgram(&program); -// SpectralMesh mesh(&program, 512); - WaveMesh mesh(&program, 128); + SpectralMesh mesh(&program, 512); +// WaveMesh mesh(&program, 128); mesh.create(); OGL::instance()->addObject(&mesh); Camera::instance()->init(); -// AudioPlayer player(musicFile); -// float* line = new float[2048]; -// memset(line, 0, 2048); -// player.setStreamListener([&mesh, line](float *data, std::size_t framesCount, std::size_t depth, std::size_t channels) { -// memmove(line, line + 1024, 1024); -// if(channels > 1) { // if we have more than one channel, use the first -// for(std::size_t i = 0, j = 0; i < framesCount; i += channels, ++j) { -// line[1024 + j] = data[i]; -// } -// } else { -// memcpy(line + 1024, data, 1024); -// } -// -// mesh.addLine(line, depth); -// mesh.addLine(line + 256, depth); -// mesh.addLine(line + 512, depth); -// mesh.addLine(line + 768, depth); -// }); -// player.play(); + AudioPlayer player(musicFile); + float* line = new float[2048]; + memset(line, 0, 2048); + player.setStreamListener([&mesh, line](float *data, std::size_t framesCount, std::size_t depth, std::size_t channels) { + memmove(line, line + 1024, 1024); + if(channels > 1) { // if we have more than one channel, use the first + for(std::size_t i = 0, j = 0; i < framesCount; i += channels, ++j) { + line[1024 + j] = data[i]; + } + } else { + memcpy(line + 1024, data, 1024); + } + + mesh.addLine(line, depth); + mesh.addLine(line + 256, depth); + mesh.addLine(line + 512, depth); + mesh.addLine(line + 768, depth); + }); + player.play(); OGL::instance()->run(); // delete[] line;