/** * Copyright (c) 2008-2014 Ardor Labs, Inc. * * This file is part of Ardor3D. * * Ardor3D is free software: you can redistribute it and/or modify it * under the terms of its license which may be found in the accompanying * LICENSE file or at . */ package com.ardor3d.example.basic; import com.ardor3d.bounding.BoundingBox; import com.ardor3d.example.ExampleBase; import com.ardor3d.example.Purpose; import com.ardor3d.image.Texture; import com.ardor3d.math.MathUtils; import com.ardor3d.math.Matrix3; import com.ardor3d.math.Vector3; import com.ardor3d.renderer.state.MaterialState; import com.ardor3d.renderer.state.MaterialState.ColorMaterial; import com.ardor3d.renderer.state.TextureState; import com.ardor3d.scenegraph.Mesh; import com.ardor3d.scenegraph.shape.Box; import com.ardor3d.scenegraph.shape.Quad; import com.ardor3d.util.ReadOnlyTimer; import com.ardor3d.util.TextureManager; /** * A simple example showing a textured and lit box spinning. */ @Purpose(htmlDescriptionKey = "com.ardor3d.example.basic.BoxExample", // thumbnailPath = "com/ardor3d/example/media/thumbnails/basic_BoxExample.jpg", // maxHeapMemory = 64) public class BoxExample extends ExampleBase { /** Keep a reference to the box to be able to rotate it each frame. */ private Mesh box; /** Rotation matrix for the spinning box. */ private final Matrix3 rotate = new Matrix3(); /** Angle of rotation for the box. */ private double angle = 0; /** Axis to rotate the box around. */ private final Vector3 axis = new Vector3(1, 1, 0.5f).normalizeLocal(); public static void main(final String[] args) { ExampleBase example = mystart(BoxExample.class); example.addTexture(); } @Override protected void updateExample(final ReadOnlyTimer timer) { // Update the angle using the current tpf to rotate at a constant speed. angle += timer.getTimePerFrame() * 50; // Wrap the angle to keep it inside 0-360 range angle %= 360; } @Override protected void initExample() { _canvas.setTitle("Box Example"); // Create a new box centered at (0,0,0) with width/height/depth of size 10. //box = new Box("Box", new Vector3(0, 0, -20), 5, 5, 5); box = new Quad("Quad", 5,5); // Set a bounding box for frustum culling. box.setModelBound(new BoundingBox()); // Move the box out from the camera 15 units. box.setTranslation(new Vector3(0, 0, -15)); // Give the box some nice colors. box.setRandomColors(); // Attach the box to the scenegraph root. _root.attachChild(box); //Mesh box2 = new Box("Box", new Vector3(0, 0, 0), 5, 5, 5); Mesh box2 = new Quad("Quad", 8,8); // Set a bounding box for frustum culling. box2.setModelBound(new BoundingBox()); // Move the box out from the camera 15 units. box2.setTranslation(new Vector3(0, 0, -14)); // Give the box some nice colors. box2.setRandomColors(); // Attach the box to the scenegraph root. _root.attachChild(box2); // Add a texture to the box. final TextureState ts = new TextureState(); tex1 = TextureManager.load("images/ardor3d_white_256.jpg", Texture.MinificationFilter.Trilinear, true); ts.setTexture(tex1); box.setRenderState(ts); // Add a material to the box, to show both vertex color and lighting/shading. final MaterialState ms = new MaterialState(); ms.setColorMaterial(ColorMaterial.Diffuse); box.setRenderState(ms); // Add a texture to the box. final TextureState ts2 = new TextureState(); tex2 = TextureManager.load("images/ardor3d_white_256.jpg", Texture.MinificationFilter.Trilinear, true); ts2.setTexture(tex2); box2.setRenderState(ts2); // Add a material to the box, to show both vertex color and lighting/shading. final MaterialState ms2 = new MaterialState(); ms2.setColorMaterial(ColorMaterial.Diffuse); box2.setRenderState(ms2); tex3 = TextureManager.load("images/ardor3d_white_256.jpg", Texture.MinificationFilter.Trilinear, true); } }