Skip to content

ulidtko/wave-simulation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wave-simulation

A C++11/CMake/Boost/Qt/OpenGL excersize.

This code started in Feb 2012 as an employment excersize. Local Samsung R&D center¹ gave me an assignment, which was roughly formulated as:

Make a wave going over a picture. Bonus points for reflections, radial waves, etc.

I approached the problem by continuously solving the two-dimensional wave equation for a 2D displacement vector field using the finite difference method. Then there was a visualization using QGLWidget.

The result looks like this:

(15 MiB GIF, be patient).


The primary use of the code was to be read, by my interviewers. Thus I had a lovely excuse to making the whole project's code pretty and enjoyable to read. Yet it still even works!

The points I'm especially proud of in the codebase:

  • The use of a descriptive build system, CMake. Just start reading from the top-level CMakeLists.txt, then compare that with what you'd be seeing with MSVC, or say, XCode project files. Hint: massive repetitive barely readable, uneditable, un-vcs-mergeable hunks of GUID-filled piles of XML — none of that with CMake. That's why I love it (and also for nice&clean colorful make output with build percentage gauge; and for the ccmake build configuration tool; also for cross-platform generator backends (which means CMake generates GNU Makefiles, MSVC .vcproj files, XCode .xcodeproj's, etc — so that you can build the same CMake project on different platforms with different compilers and toolchains), easy IDE integration and modularity. Wait, did I just forget to mention its (by itself awesome) backwards compatibility management system?). Yeah... I love CMake.
  • The use of C++11. Back in February 2012 it was still new and cool and exciting. You'll find quite some C++11 features used directly in the code; as this was my personal project, I dropped them in whenever I could, just to try it out. Great stuff.

  • The separation of GUI-unrelated simulation logic from GUI itself. The core code is actually compiled as an independent static library (again, enjoy the breeze of CMake handling it), which doesn't link to Qt. Even for this small-sized project proper decoupling and separation of concerns is important: coding ODE solving inside the onTimer Qt event handler would be really bad engineering. In fact, I wanted to build an Android GUI too, very possibly with some touch input — and for this to ever happen (Qt 5 wasn't yet released back then), it'd be necessary for the core simulation library to be strictly separated from Qt GUI. And then some NDK with JNI, but that's an easy part.

  • The use of external components. As much as I liked braking up the monolithic project to loosely coupled components, I liked plugging in open-source components which I didn't write. I used Qt for GUI, OpenGL for drawing (like, 4 or 5 gl calls total in the code — but still, it's used), Eigen with UmfPack plugin for solving sparse algebra. I also like how all the dependencies are clearly declared in the top-level CMakeLists.txt. It's... beautiful.

I hope you enjoy reading the code as much as I enjoyed writing it.

Feel free to drop me a letter about how you feel about this.

About

A C++11/CMake/Boost/Qt/OpenGL excersize.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published