Voxel Engine Zombies Game - Problem

Oh all my code does is create a 16x16x16 cube that is hollow, for example


if ((y == size.y - 1) || (blockID[x][y + 1][z] == 0)) {
									vertexArray.add(new float[] { pos2.x, pos2.y, pos1.z, pos1.x, pos2.y, pos1.z, pos1.x, pos2.y, pos2.z, pos2.x, pos2.y, pos2.z });
									colourArray.add(new float[] { colour.x, colour.y, colour.z, colour.w, colour.x, colour.y, colour.z, colour.w, colour.x, colour.y, colour.z, colour.w, colour.x, colour.y, colour.z, colour.w });
								}
if ((y == 0) || (blockID[x][y - 1][z] == 0)) {
									vertexArray.add(new float[] { pos2.x, pos1.y, pos2.z, pos1.x, pos1.y, pos2.z, pos1.x, pos1.y, pos1.z, pos2.x, pos1.y, pos1.z });
									colourArray.add(new float[] { colour.x, colour.y, colour.z, colour.w, colour.x, colour.y, colour.z, colour.w, colour.x, colour.y, colour.z, colour.w, colour.x, colour.y, colour.z, colour.w });
								}

This checks if the block is the

  • max edge block or if the block above is air, if so render top view
  • min edge block or if the block below is air, if so render top view

This is then repeated to create a block that is only rendering the sides that are needed

So this also limits the amount of faces you are drawing then?

Frustum culling could be used to cull chunks that are not in the viewing plane.

I’m looking at using an octree for my chunks now which should make collision easier.

Hi!
If you need it, here is my Frustum class. It includes a method that checks if a block is in the frustum:

So i have been playing around with my 2D sprite-sheet to 3D model converter and was wondering what everyone thought of the weapons so far,

Models and names can be changed before the final game is released.

Can someone help me on this one problem I seem to keep having;

I can render my players weapon but when I rotate the weapon dosn’t rotate and keep at the same position as what I intended it to be at.


glTranslatef(x+.3f, y-0.3f, z-0.3f);
glRotatef(rX, 1.0f, 0.0f, 0.0f);
glRotatef(rY-90f, 0.0f, 1.0f, 0.0f);

This is my code for the model rotation for the weapon can someone help me please and thanks if you do :slight_smile:

Hi there!

How about:


glRotatef(rY-90f, 0.0f, 1.0f, 0.0f);
glTranslatef(x+.3f, y-0.3f, z-0.3f);
glRotatef(rX, 1.0f, 0.0f, 0.0f);

That should work.

  • Longor1996

I tried that combination before and it didn’t seem to work, thanks anyway for your help.

Do you not need to get your cameras rotation?

Something along the lines of:


Vector3f pos = getYourCameraPosition();
double cameraPitchInRadians = Math.toRadians(YourCamerasPitch);
double cameraYawInRadians = Math.toRadians(YourCamerasYaw);
float newX = (float) Math.sin(cameraYawInRadians);
float newY = (float) Math.sin(cameraPitchInRadians);
glRotatef(newY-90f, 0.0f, 1.0f, 0.0f);
glTranslatef(x+.3f, y-0.3f, z-0.3f);
glRotatef(newX, 1.0f, 0.0f, 0.0f);

Of course, your rx and ry maybe the same as newX and newY above?!

Regards

@marcuiulian13 - hi, I use something very similar.

How do you use yours? Do you give it the chunks x, y, z position and size, with x,y,z being the center of the chunk and z half its width?

Thanks

No, i give it the chunk’s x, y, z and it’s total size, because i don’t use the center of the object as the origin.

Ok, so if chunk is 16^3, and at xposition 4 ( 4 * 16 ), yposition 0, zposition 0 you pass in
cubeInFrustum(64, 0, 0, 16);

Thanks

Thanks so much steg90 I used the code that you provided and ended up adapting it a bit to get it to work with my engine and this was the final product I came to;


glLoadIdentity();
double cameraPitchInRadians = Math.toRadians(rY);
double cameraYawInRadians = Math.toRadians(rX);
float newX = (float) Math.sin(cameraYawInRadians);
float newY = (float) Math.sin(cameraPitchInRadians);
glRotatef(newX, 1.0f,0.0f, 0.0f);
glTranslatef(1.1f-0.8f,-1.1f,-1.3f);
glRotatef(newY-90.0f, 0.0f, 1.1f, 0.0f);

Glad I could help :slight_smile: