Advertisement
Guest User

aak

a guest
Oct 28th, 2009
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.91 KB | None | 0 0
  1. package simu;
  2.  
  3. import jme.Tube;
  4.  
  5. import com.jme.app.SimpleGame;
  6. import com.jme.image.Texture.MagnificationFilter;
  7. import com.jme.image.Texture.MinificationFilter;
  8. import com.jme.image.Texture.WrapMode;
  9. import com.jme.math.FastMath;
  10. import com.jme.math.Quaternion;
  11. import com.jme.scene.state.TextureState;
  12. import com.jme.util.TextureManager;
  13.  
  14. /**
  15.  *
  16.  * Basic code to showcase the features of the modified tube.
  17.  *
  18.  * @author Ahmed Abdelkader
  19.  *
  20.  */
  21. public class TubeTest extends SimpleGame {
  22.  
  23.     private Tube tube;
  24.     private float outerRadius = 10;
  25.     private float innerRadius = 6;
  26.     private float height = 30;
  27.     private int axisSamples = 1;
  28.     private int radialSamples = 100;
  29.     private float arcAngle = 270;
  30.     private int angleSign = 1;
  31.     private int radiusSign = 1;
  32.    
  33.     protected void simpleInitGame() {
  34.         display.setTitle("Tube Test");
  35.        
  36.         tube = new Tube("", outerRadius, innerRadius, height, axisSamples, radialSamples, arcAngle);
  37.         tube.setLocalTranslation(0, -5, -40);
  38.         tube.setLocalRotation(new Quaternion().fromAngles(0, -FastMath.HALF_PI, -FastMath.QUARTER_PI));
  39.         rootNode.attachChild(tube);
  40.  
  41.         TextureState ts = display.getRenderer().createTextureState();
  42.         ts.setEnabled(true);
  43.         ts.setTexture(TextureManager.loadTexture("BlueLines.jpg",
  44.                 MinificationFilter.Trilinear, MagnificationFilter.Bilinear));
  45.         ts.getTexture().setWrap(WrapMode.Repeat);
  46.         rootNode.setRenderState(ts);
  47.     }
  48.    
  49.     @Override
  50.     protected void simpleUpdate() {
  51.         if(tpf < 1) {
  52.             arcAngle = arcAngle + angleSign * tpf * 360;
  53.             if(FastMath.abs(arcAngle) > 360) {
  54.                 angleSign = -angleSign;
  55.                 if(innerRadius == outerRadius || innerRadius == 0)
  56.                     radiusSign = -radiusSign;
  57.                 innerRadius += radiusSign * 1;
  58.             }
  59.         }
  60.         tube.updateGeometry(outerRadius, innerRadius, height, axisSamples, radialSamples, arcAngle * FastMath.PI/180);
  61.     }
  62.    
  63.     public static void main(String[] args) {
  64.         new TubeTest().start();
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement