I want to draw my cubes using 12 tringles instead of 6 quads.
Would u not render the points this way giving u 2 triangles per face
1 /3
| / |
2/ 4
0,1
0,0
1,1
1,0
This is just the x and y but you can just adapt it for each of the other faces.
Hello there.
It’s very easy to split a Quad into two triangles.
// Label your 4 Vertices from A-D
A GL11.glTexCoord2f(spriteX, spriteY + small); GL11.glVertex3f(x1, y1 + height, z1);
B GL11.glTexCoord2f(spriteX, spriteY); GL11.glVertex3f(x1, y1 + height, z1 + length);
C GL11.glTexCoord2f(spriteX + small, spriteY); GL11.glVertex3f(x1 + width, y1 + height, z1 + length);
D GL11.glTexCoord2f(spriteX + small, spriteY + small); GL11.glVertex3f(x1 + width, y1 + height, z1);
Clockwise:
Triangle A is: A B C
Triangle B is: A C D
Result:
// Triangle A
A GL11.glTexCoord2f(spriteX, spriteY + small); GL11.glVertex3f(x1, y1 + height, z1);
B GL11.glTexCoord2f(spriteX, spriteY); GL11.glVertex3f(x1, y1 + height, z1 + length);
C GL11.glTexCoord2f(spriteX + small, spriteY); GL11.glVertex3f(x1 + width, y1 + height, z1 + length);
// Triangle B
A GL11.glTexCoord2f(spriteX, spriteY + small); GL11.glVertex3f(x1, y1 + height, z1);
C GL11.glTexCoord2f(spriteX + small, spriteY); GL11.glVertex3f(x1 + width, y1 + height, z1 + length);
D GL11.glTexCoord2f(spriteX + small, spriteY + small); GL11.glVertex3f(x1 + width, y1 + height, z1);
I hope this helps.
- Longor1996
Thank you. It work but the problem is that the face culling doesn’t draw the bot face anymore. It has something to do if it is clockwise or not.
Hi Pauler.
Thank you. It work but the problem is that the face culling doesn’t draw the bot face anymore. It has something to do if it is clockwise or not.
It’s incredible easy! Just flip the edge vertices.
Clockwise:
Triangle A is: A B C
Triangle B is: A C D
Counter-Clockwise:
Triangle A is: C B A
Triangle B is: D C A
- Longor1996
7sfS5fmzDjk
Sadly, water can’t expand to another chunk.
Looking cool, keep up the good work!
Wow that’s fantastic! I love how that’s all working.
Sadly, water can’t expand to another chunk.
I’m sure you will find a way to solve that. When I did the water on my map I stored the water In another array, this was partly because I used a second render pass to draw it semi -transparent. But it also solved the problem of it not being bound to chunks.
I’m not suggesting you do that, but a temporary list of moving water may help get around that. Or some good methods that deal with chunk boundaries. Looks great!
I found some time and started working on the engine again, but I still cannot get the holding cube right. Can someone send me a working piece of code about the holding cube?
Some of the strangle results:
VFrsQmG3zQw
Paul.
Draw it last and don’t do any depth testing.
Mike
I looks like you are not translating and rotating it properly.
this is from a page on my blockworld page
// draw the block the player is holding GL11.glLoadIdentity(); //move the camera GL11.glRotatef(20, 1.0f, 0, 0); //lookupdown GL11.glRotatef(360.0f - yrot, 0, 1.0f, 0); //360.0f - yrot GL11.glTranslatef(-xpos, (-walkbias/3) - 0.25f - (float)playerheight - hedHeight, -zpos); //move the block infront of the player float xblokpos = xpos - (float) Math.sin((yrot-18) * piover180) * 0.24f; float zblokpos = zpos - (float) Math.cos((yrot-18) * piover180) * 0.24f; GL11.glTranslatef(xblokpos, playerheight+1.83f, zblokpos); GL11.glRotatef(340.0f + yrot, 0,1f, 0f);
its rotated to the side of the player by 18, and tilted down by 20 (GL11.glRotatef(20, 1.0f, 0, 0); )
Once the camera is rotated, I place the block infront of the player with xblokpos zblockpos (the block is 0.24 units from the player camera)
The block is then rotated to maintain its relative rotation to the player
I have also reduced the effect of the walkbias by /3 to minimise, but not remove the bobbing effect on the block, as its close to the camera.Hope this is of some help. The values you want to use may be trial and error! To get the look you want to have.
you can also download my code, its on there somewhere. This part is halfway down the render method
I don’t translate the position - just set identity and position the cube after.
I just do:
glLoadIdentity();
GL11.glRotatef(10, 0, 0, 1);
GL11.glTranslatef(-0.05f, (walkbias / 2.3f) + 0.9f, 0.4f);
// draw cube
The above is called after my camera has been translated.
glLoadIdentity();
GL11.glRotatef(10, 0, 0, 1);
GL11.glTranslatef(-0.05f, (walkbias / 2.3f) + 0.9f, 0.4f);
// draw cube
What walkbias is?
It’s just a value that is calculated to get a bobbing effect - I got the idea from Vermeer who I believe got it from one of nehe’s tuts.
You can just do:
GL11.glTranslatef(-0.05f, 0.9f, 0.4f);
You may have to play around with the values dependant on your camera position.
I found some time and started working on the engine again, but I still cannot get the holding cube right. Can someone send me a working piece of code about the holding cube?
Some of the strangle results:
VFrsQmG3zQw
Paul.
Yes walkbias is from NEHE’s tutorial. I have scaled it down by 2.3 as the motion does not need to be as pronounced as the full bias of the character.
Draw it last and don’t do any depth testing.
Mike
I looks like you are not translating and rotating it properly.
this is from a page on my blockworld page
// draw the block the player is holding GL11.glLoadIdentity(); //move the camera GL11.glRotatef(20, 1.0f, 0, 0); //lookupdown GL11.glRotatef(360.0f - yrot, 0, 1.0f, 0); //360.0f - yrot GL11.glTranslatef(-xpos, (-walkbias/3) - 0.25f - (float)playerheight - hedHeight, -zpos); //move the block infront of the player float xblokpos = xpos - (float) Math.sin((yrot-18) * piover180) * 0.24f; float zblokpos = zpos - (float) Math.cos((yrot-18) * piover180) * 0.24f; GL11.glTranslatef(xblokpos, playerheight+1.83f, zblokpos); GL11.glRotatef(340.0f + yrot, 0,1f, 0f);
its rotated to the side of the player by 18, and tilted down by 20 (GL11.glRotatef(20, 1.0f, 0, 0); )
Once the camera is rotated, I place the block infront of the player with xblokpos zblockpos (the block is 0.24 units from the player camera)
The block is then rotated to maintain its relative rotation to the player
I have also reduced the effect of the walkbias by /3 to minimise, but not remove the bobbing effect on the block, as its close to the camera.Hope this is of some help. The values you want to use may be trial and error! To get the look you want to have.
you can also download my code, its on there somewhere. This part is halfway down the render method
I don’t translate the position - just set identity and position the cube after.
I just do:
glLoadIdentity();
GL11.glRotatef(10, 0, 0, 1);
GL11.glTranslatef(-0.05f, (walkbias / 2.3f) + 0.9f, 0.4f);
// draw cube
The above is called after my camera has been translated.
glLoadIdentity();
GL11.glRotatef(10, 0, 0, 1);
GL11.glTranslatef(-0.05f, (walkbias / 2.3f) + 0.9f, 0.4f);
// draw cube
What walkbias is?