[Help] Block Class Design

Hey everyone, im really needing a lot of help in creating a 3D block class, Ive been looking around for some time and I havent found anything that could really help me. This is my first 3D game and I dont really know what to add into the class, and is it possible to have it render from the actual block class, or does it have to be rendered in the render class? Any help would be really appreciated. Im also looking for a basic structure of a random world generator. Thanks a lot :smiley:

[quote]does it have to be rendered in the render class?
[/quote]
Depends on your lib. Usually on libgdx I pass SpriteBatch to each class of this kind.

Im using lwjgl, and do you happen to know how to structure the class?

By structure you mean relation between class? well it’s up to your game mechanism. Or you mean this single block class? just fill it with necessary fields and methods. With lwjgl, you can call static GL to draw from within your block class directly.

Okay, and what type of fields and methods do you think I should incorporate, and do you happen to know how to make a cube with the same texture on all 6 sides?

For coordinates, find a point/vector3d which will be used to all 6 sides. Your class hold it and also texture REFERENCE. Class’s drawing method has to draw that texture 6 times with different position.

Ahh okay, and how would you have it on an actual block place, and not in the miidlle of it

Have a 3D point which stores the block’s location and translate to that location before you begin drawing. Next, bind your texture and draw the six faces of the cube as quads (or two triangles if you prefer). How you actually go about doing this really depends on how you implement drawing, but the basic idea is the same. A cube has eight verticies:

(0.5, 0.5, 0.5)
(0.5, -0.5, 0.5)
(-0.5, -0.5, 0.5)
(-0.5, 0.5, 0.5)
(0.5, 0.5, -0.5)
(0.5, -0.5, -0.5)
(-0.5, -0.5, -0.5)
(-0.5, 0.5, -0.5)

You use these verticies to draw the quads. Each face of the cube has one coordinate that is constant, so for instance, the four points

(0.5, 0.5, 0.5)
(0.5, -0.5, 0.5)
(-0.5, -0.5, 0.5)
(-0.5, 0.5, 0.5)

make up the front of the cube because they all have the same z coordinate. You get the other five faces the same way. If you don’t want to use +/-0.5 for all the coordinates you don’t have to, you could use 1 and 0, 1 and -1, or whatever you want. I chose 0.5 because this will give you a cube of unit side length (each edge is one unit long) and centered at the origin (the point (0,0,0)). Because you translated before drawing, the cube on the screen will be centered at (x, y, z) which is exactly what you want :slight_smile: Just remember to translate back to the origin before drawing the next cube.

Hope this helps.

Ohh okay, so it would automatically draw the cube on the “space”