Wall Carving
Karl Afanasjev, Kaarel Parve, Simon Prii
Repository link: https://github.com/ui-1/wallcarving
The goal was to have a dynamically generated wall that can be "mined into". Clicking somewhere on the wall adds new vertices and edges into a graph structure that is then used to (re)generate the wall geometry. In the end, this is what we got implemented:
- WASD + mouse to move and look around
- A wall class that regenerates its VAO when (and only when) any of its vertices or edges have changed
- Mouse click finds the position that was clicked on the wall (Möller–Trumbore)
- Clicking on the wall pushes a hole into it
When user clicks on the geometry then a wall changing algorithm is invoked which changes the mesh based on the position of the click in 3D space. It moves vertices away from the click and splits edges that got too long in the process, therefore adds new vertices. The algorithm is described fairly well with the following picture series.
The geometry of the wall is stored in a class that keeps track of all the data it needs and provides methods to modify it:
- vertices as a vector of vec3's
- edges as a n x n matrix of booleans where
edges[i][j] == true
iff vertices with the indexes i and j are connected - methods to add, set, and remove vertices
- methods to set and check whether or not two vertices are connected
- a rendering method to be called in the main loop
A boolean value is used as a "flag" to keep track of whether or not anything significant has changed in the wall's structure -- it's set to true whenever vertices are added, for example. That way, we can re-render the wall's geometry if and only if there is any actual need to do so. The method called from the program's main loop creates a new VAO and sets the boolean back to false.
Example of clicking on the wall: