[ad_1]
I’m attempting to make a voxel sport whereas studying about OpenGL. The world is made up of many chunks of voxels. Therefore there’s a Chunk
class, containing an array of components
(which for now simply are ints indicating if a voxel is stable (1) or empty(0) ).
There is a single World
object that shops an std::vector<chunk> chunks
member record. world
is chargeable for creating and initializing all the chunks inside. However, an essential step in rendering the precise voxels is for the chunks to create a mesh based mostly on which voxels are empty and that are full. To do that, every chunk
iterates over its component
array. If a voxel is stable, then it checks the orthogonally adjoining voxels and creates a quad
(a category that encapsulates two triangles formatted for OpenGL) face on every uncovered facet.
An situation arises when the examined voxel is on the sting of its chunk
. To test adjoining voxels previous the sting, it must know knowledge from a neighboring chunk
about them. I’ve already tried storing a listing Chunk* neighbors[6]
of neighboring chunks in every chunk
, and assigning them through the world
earlier than producing the mesh. However this nonetheless leaves holes the place quads ought to have been generated alongside some borders, and inside partitions of quads alongside others the place none ought to have been generated.
To generalize the method and make it extra accessible to entry details about any voxel on the earth (which may clearly be helpful in a while for gameplay causes), I then determined to implement a PositionInWorldIsStable(x, y, z)
perform within the World
class. The thought is that every chunk solely must retailer a pointer to the world
that owns all of them, and it might probably then name this perform to entry any chunk on the earth if it wants data (on this early case, nearly solidity). However, right here I run into an issue.
The World
class definition in World.h
already consists of the Chunk class #embody "Chunk.h"
so it might probably retailer the record of chunks, since usually the world needs to be appearing on them and never the opposite manner round. When I attempt to go backward and let the chunks entry details about the opposite chunks via the world, they should retailer a World* world
referring to the only world object that owns them. To permit the chunks to make use of the sort World
I have to #embody "World.h"
within the Chunk.h
file. This is clearly an issue; now I’m defining two courses by one another. Is there anyway I can get round this and permit every chunk
to entry the perform in world
or the record?
For context, that is in all probability the biggest undertaking I’ve ever tried and I’m undoubtedly not used to working with this many shifting elements, however the entire level is to achieve expertise. That stated, the undertaking was an extension of a learnOpenGL tutorial undertaking in visible studio; for no matter purpose the tutorial makes use of header information for all class definitions, and solely makes use of a .cpp
file for the file containing major()
. I’ve been following suite since I have not usually had to make use of each ever earlier than, however apparently there’s a manner to do that by ahead declaring the courses every of their .h
information and together with every of their .cpp
information (or maybe vice-versa). I have not tried this in case it is plenty of work to create .cpp
‘s for each header concerned, but when that is the really useful answer I wish to know.
Please keep in mind I’m actively attempting to be taught and get this to work; I welcome recommendation together with criticism, but when your reply is to name me silly for attempting or say I should not even be trying this but you’re neither serving to me be taught nor serving to the programming neighborhood to develop.
[ad_2]