Sand Toy Project
As a project in Computing I created a powder and physics simulation game written in C++.
The game is Sand Toy, it can simulate powders, liquids, gasses, and solids.
Using a gird-like structure it can easily process large amounts of information
lag-free, including processing a whole screen full of matter, meaning that Sand
Toy ether works or doesn't work with the settings.
Sand Toy uses Parallel Processing to process its information, I’m using a Nvidia package (CUDA) for the parallel processing. For the visuals I’m using OpenGL, an open-source cross-platform package. Sand toy is unique to most other powder simulation games because it uses a grid-like structure, making it easier to process large amounts of information because all the GPU has to do is check their neighbour instead of searching for their neighbours in the list of particles, (why The Powder Toy lags when there is more particles and increased activity).
Things I have learned:
- Fluent parallel processing in CUDA
- Good practices in coding for Linux and Windows
- How to load images from files in OpenGL
- Make images to load in OpenGL
- Render text in OpenGL
- Read and write to files
- Convert data to binary
- Read and write binary to and from files
- Good practices to avoid memory leaks
One of the challenges I faced during the project was getting particles to
stop going into the same space as each other, because everything is
happening at the same time therefore each CUDA process can’t know if
another process is done or if another particle wants to go where the
particle is intending to go.
Another issue I encountered was displaying all the pixels on the screen, because displaying all the pixels was the only task that didn’t use CUDA. I worked out I could generate images for CUDA to display the pixels, meaning I could keep all the particle data stored on the GPU because it takes time to copy large amounts of data, since the particle data is around 25 megabytes in size.
Another issue I encountered was memory leaks, where a pointer (variable that points to the reference) gets deleted or reset and the reference (the actual variable location) attached to it doesn't get removed, and ends up unreachable in the RAM and uses up data until the computer runs out of memory, I fixed this by making sure I deleted the pointers reference when I no longer needed them, and when I wrote a new reference to a pointer.
If I had more time I would have fixed a bug in the code (that is related to the first challenge mentioned), because it is caused by a process copying the particles to move them. The particles copy each other in one process and appear empty because they haven't finished coping, then another process sees the particle as free and copies itself there. If I had more time I also would have added Chemical Reactions (chemicals react with each other, there's fire, explosions, etc) and Mass (Oil should float on water and smoke should rise). I didn't have enough time to add these features before the presentation so I left them out.
Space Shooter project
My project was to create a game in C++ using OpenGL, OpenGL is
a low-level library for displaying 3D and 2D content on a screen.
My goal was to create a space game in C++. Some of the difficulties
I encountered was movement, it was hard to get the player to move
in the direction they were facing in. I had to learn more advanced
maths such as sin and cos to manage circles. The movement uses the
sin and cos variables to manage the x, y and z coordinates.
Later another issue I encountered was to add flying objects into the game, such as Asteroids and various other objects such as the stars and the sun. I wasn't sure how I would go about doing this because C++ has a fixed limitation on how big arrays get. An array is a fixed container that holds multiple elements, and I wasn't sure how I could have a variable amount of elements in one container. I found a resource online, it was to use vectors, a container library that acts as a container with a varible size to hold objects in.
Once I did this I had to figure out how to check if objects are touching each other, and work out the distance between two objects, since most of the objects I used where circles. I worked out a formula to get the 2D and 3D distance between 2 objects. I did this with square root.
I learned atan2 so I could implement gravity to the sun, this was hard because I wasn't entirely sure on the exact dimensions my game was using, the resources online that I found weren't completely valid, so I had to test it myself. What atan2 does, it finds the angle two 2 dimensional points on a plane, the syntax is atan2(y, x). atan2(11, -20) = 2.6387494426619322, but this is in radial calculation mode, I want an angle so I multiply this by 180 then divide by pi then add 180 and I have the angle as 331.18920625702697 degrees.
Things I have learned:
- Move the camera (actually moving the world)
- Change the camera angle (this is actually rotating everything around the camera)
- Create a variable list using vectors
- Make the window full screen
- Implement basic lighting
- Implement sound into the game
- How to make classes and structures in C++
- More advanced maths including sin, cos, and atan2
- Include a 2D graphics overlay on a 3D game
- Move and rotate objects
- Move an object (or the player) in a specified angle
- Get the angle between 2 objects, both in 2D space and 3D space
- Get the distance between 2 objects, both in 2D space and 3D space
Animated box project
I created an animation for a Digital Technology assignment that is written in C++. It is very basic since he is new to graphics in C++. The box moves from left to right continuously until the window is closed. One of my issues was that I was having trouble getting the box to render. To render the box I had to click the window to force it to render. I was using this using windows threads meaning that this couldn't be compiled on a Linux machine. Now this uses the OpenGL timer functions and it renders properly and so now it can actually be compiled to be used on Linux. A future improvement would be to add a feature to move around, possibly add a few more shapes as well as the square.