jPCT - a 3d engine for Java => Support => Topic started by: Hmm on April 25, 2007, 06:16:49 pm

Title: Making a pair of dice
Post by: Hmm on April 25, 2007, 06:16:49 pm

I'm currently trying to create a simple die with jPCT (6 sided cube with a number on each side, represented by circles).  I've currently set up the cube, and loaded the textures into the texture manager.  I've set the cube up so that it rotates around over and over again in order to show it's sides.  How can I apply the 128x128 textures to the sides of the cube?  As I understand it, each side is actually made up of 4 polygons, so I've tried applying the same square texture to each of the four polygons on each side.  However, when I rotate the cube like this:

Code: [Select]
...the circles appear to "slide" across the surface of the cube as it rotates.  Am I supposed to set the textures to lock or something?

Thanks for any help!
Title: Re: Making a pair of dice
Post by: EgonOlsen on April 25, 2007, 07:04:25 pm
No, if the texture ccordinates are correct and the texturing mode isn't set to environment mapping, the textures should stay in place. A little snippet showing how you set up the cube and assign the textures may help to spot the problem.
Title: Re: Making a pair of dice
Post by: Hmm on April 25, 2007, 07:10:17 pm
Alright, it appears that environment mapping was on, so I removed the code that set it.  :-[

Unfortunately, now the textures don't appear at all.

Anyway, here's the (very primative) object which will eventually become the die.  I create an object of this class after the world has been set up, and it rotates properly, but displays no textures:

Code: [Select]
protected class die extends Object3D
public die()
super (Primitives.getCube(1.0f));
PolygonManager myPolygons = this.getPolygonManager();
myPolygons.setPolygonTexture(0, dice.myTexMan.getTextureID("face1"));
myPolygons.setPolygonTexture(2, dice.myTexMan.getTextureID("face1"));
myPolygons.setPolygonTexture(4, dice.myTexMan.getTextureID("face1"));
myPolygons.setPolygonTexture(6, dice.myTexMan.getTextureID("face1"));
myPolygons.setPolygonTexture(1, dice.myTexMan.getTextureID("face6"));
myPolygons.setPolygonTexture(3, dice.myTexMan.getTextureID("face6"));
myPolygons.setPolygonTexture(5, dice.myTexMan.getTextureID("face6"));
myPolygons.setPolygonTexture(7, dice.myTexMan.getTextureID("face6"));


The textures are already loaded correctly (since they worked before removing the environment mapping statement), and dice.myTexMan is a valid TextureManager for the current world.

Thanks again for your help :)
Title: Re: Making a pair of dice
Post by: EgonOlsen on April 25, 2007, 07:16:23 pm
Well, the problem is, that the cube created by Primitives is actually a simple lathe object without correct texture coordinates applied. That's why the texture doesn't show when not using env-mapping. The same problem has been discussed here: http://www.jpct.net/forum2/index.php/topic,393.0.html (http://www.jpct.net/forum2/index.php/topic,393.0.html) I've also posted some code in that thread to create a cube at runtime from single triangles. I suggest to use that one instead.
Title: Re: Making a pair of dice
Post by: Melssj5 on April 26, 2007, 02:09:23 am
Well, if you create the cube by primitives it will be a kind of difficult to apply textures as you want, Its better if you create your 3d model on a another software like 3d studio max and then export it as 3ds and then load it. When you load it on that way the textures will appear just as they were put on the 3d modeller software.