Elements of Graphics: Assignment Seven


Due Midnight, Thursday Nov 20.

In this assignment you will texture map the cube and tetrahedron from the last two assignments. You should leave them lighted the way they were before, just add the texture to this. To do so, you would find two jpeg or gif files that you like to use as textures, one for the cube and one for the tetrahedron. The one on the cube will be easier to see, so use your favorite on on that.

Start with your own program from the last assignment. You will have to do some further modifications to Box.java to add texture coordinates to all the faces (see how it is done in Tetrahedron.java and adapt that).

To read in a texture file that you want to use, put the file in the directory with your programs, and add this code to TetrahedronCollision.java or whatever your main class is.

// Grab a texture
TextureLoader texLoad = new TextureLoader("filename.jpg", this);
Texture2D myTexture = (Texture2D) texLoad.getTexture();

To put a texture on an object, you'll need to modify its appearance similarly to the following.

// Create a silver box, add it to the scene graph.
// cubeRotate.addChild(new ColorCube());
Shape3D cube = new Box(2.0f, 2.0f, 2.0f);
Appearance bapp = cube.getAppearance();
Color3f bColor = new Color3f(0.37f, 0.37f, 0.37f);
Color3f bHilite = new Color3f(0.89f, 0.89f, 0.89f);
bapp.setMaterial(new Material(bColor, black, bColor, bHilite, 17.0f));
bapp.setTexture(myTexture);
TextureAttributes btexAttr = new TextureAttributes();
btexAttr.setTextureMode(TextureAttributes.MODULATE);
bapp.setTextureAttributes(btexAttr);

Once you've managed to get the two different textures to show up on all the faces of the cube and tetrahedron respectively, you're home free. Don't forget to turn in the texture files along with your code when you use TURNIN this time.


Don Fussell