After translating the pseudo-code, the first thing I needed to do was figure out the relationship between the positions and faces of the magnets. I started off drawing the vertices, calculating the positions of the corners, and then labeling them in a counterclockwise manner to account for the face indices. Once I shipped it off to the graphics card the next thing to do was to draw them. To draw both magnets I needed to first draw it’s components in reverse order starting with poles and then the magnet body. When I needed to account for flipping all I needed to do was negate the translation values. Once I had the magnets drawn, I needed to implement the mouse events that detected, moved, flipped, and interacted with the magnets. To do so I needed to find a pattern between shifting each magnet based on the current click. In the end it came down to basic math with displacement and re-centering each magnet.
At first I had tried to duplicate the amount of positions to represent each magnet, but when I managed to draw the individual components of a magnet I realized that I had extraneous position data that could be cleaned up. When I was adapting the pseudo-code I had a hard time translating some of the conditionals and the basic vector operations. My solution, although it adds a few lines of code, breaks the pseudo-code into smaller chunks for ease of use. As I was working with the struct, I was increasingly disliking the way I was referencing it and its values so I decided to switch it over to a pointer to a struct of magnets. While the syntax was cleaner, it was a little tricky initializing the values and updating the project. Another issue was my lack of understanding of how to convert back and forth between pixel coordinates and openGL’s expected coordinates. However, once I implemented orthographic projection, the logic behind interacting with the magnets “clicked” (pardon the pun).