11/* 
2-  * Copyright (c) 2009-2012  jMonkeyEngine 
2+  * Copyright (c) 2009-2025  jMonkeyEngine 
33 * All rights reserved. 
44 * 
55 * Redistribution and use in source and binary forms, with or without 
3535import  com .jme3 .app .SimpleApplication ;
3636import  com .jme3 .audio .AudioData ;
3737import  com .jme3 .audio .AudioNode ;
38- import  com .jme3 .math .FastMath ;
38+ import  com .jme3 .font .BitmapText ;
39+ import  com .jme3 .material .Material ;
40+ import  com .jme3 .math .ColorRGBA ;
3941import  com .jme3 .math .Vector3f ;
4042import  com .jme3 .scene .Geometry ;
43+ import  com .jme3 .scene .Mesh ;
44+ import  com .jme3 .scene .debug .Grid ;
4145import  com .jme3 .scene .shape .Sphere ;
42- import  com .jme3 .scene .shape .Torus ;
46+ 
47+ import  java .util .Locale ;
4348
4449/** 
4550 * Test Doppler Effect 
@@ -49,46 +54,68 @@ public class TestDoppler extends SimpleApplication {
4954    private  float  pos  = -5 ;
5055    private  float  vel  = 5 ;
5156    private  AudioNode  ufoNode ;
57+     private  BitmapText  bmp ;
5258
53-     public  static  void  main (String [] args ){
54-         TestDoppler  test  = new  TestDoppler ();
55-         test .start ();
59+     public  static  void  main (String [] args )  {
60+         TestDoppler  app  = new  TestDoppler ();
61+         app .start ();
5662    }
5763
5864    @ Override 
5965    public  void  simpleInitApp () {
60-         flyCam .setMoveSpeed (10 );
61- 
62-         Torus  torus  = new  Torus (10 , 6 , 1 , 3 );
63-         Geometry  g  = new  Geometry ("Torus Geom" , torus );
64-         g .rotate (-FastMath .HALF_PI , 0 , 0 );
65-         g .center ();
66- 
67-         g .setMaterial (assetManager .loadMaterial ("Common/Materials/RedColor.j3m" ));
68- //        rootNode.attachChild(g); 
66+         configureCamera ();
67+         bmp  = createLabelText (10 , 20 , "<placeholder>" );
6968
7069        ufoNode  = new  AudioNode (assetManager , "Sound/Effects/Beep.ogg" , AudioData .DataType .Buffer );
7170        ufoNode .setLooping (true );
7271        ufoNode .setPitch (0.5f );
7372        ufoNode .setRefDistance (1 );
7473        ufoNode .setMaxDistance (100000000 );
7574        ufoNode .setVelocityFromTranslation (true );
76-         ufoNode . play ( );
75+         rootNode . attachChild ( ufoNode );
7776
78-         Geometry  ball  = new  Geometry ("Beeper" , new  Sphere (10 , 10 , 0.1f ));
79-         ball .setMaterial (assetManager .loadMaterial ("Common/Materials/RedColor.j3m" ));
77+         Geometry  ball  = makeShape ("Beeper" , new  Sphere (10 , 10 , .5f ), ColorRGBA .Red );
8078        ufoNode .attachChild (ball );
8179
82-         rootNode .attachChild (ufoNode );
80+         Geometry  grid  = makeShape ("DebugGrid" , new  Grid (21 , 21 , 2 ), ColorRGBA .Gray );
81+         grid .center ().move (0 , 0 , 0 );
82+         rootNode .attachChild (grid );
83+ 
84+         ufoNode .play ();
8385    }
8486
87+     private  void  configureCamera () {
88+         flyCam .setMoveSpeed (15f );
89+         flyCam .setDragToRotate (true );
90+ 
91+         cam .setLocation (Vector3f .UNIT_XYZ .mult (12 ));
92+         cam .lookAt (Vector3f .ZERO , Vector3f .UNIT_Y );
93+     }
8594
8695    @ Override 
8796    public  void  simpleUpdate (float  tpf ) {
8897        pos  += tpf  * vel ;
89-         if  (pos  < -10  || pos  > 10 ) {
98+         if  (pos  < -10f  || pos  > 10f ) {
9099            vel  *= -1 ;
91100        }
92-         ufoNode .setLocalTranslation (new  Vector3f (pos , 0 , 0 ));
101+         ufoNode .setLocalTranslation (pos , 0f , 0f );
102+         bmp .setText (String .format (Locale .ENGLISH , "Audio Position: (%.2f, %.1f, %.1f)" , pos , 0f , 0f ));
103+     }
104+ 
105+     private  BitmapText  createLabelText (int  x , int  y , String  text ) {
106+         BitmapText  bmp  = new  BitmapText (guiFont );
107+         bmp .setText (text );
108+         bmp .setLocalTranslation (x , settings .getHeight () - y , 0 );
109+         bmp .setColor (ColorRGBA .Red );
110+         guiNode .attachChild (bmp );
111+         return  bmp ;
112+     }
113+ 
114+     private  Geometry  makeShape (String  name , Mesh  mesh , ColorRGBA  color ) {
115+         Geometry  geo  = new  Geometry (name , mesh );
116+         Material  mat  = new  Material (assetManager , "Common/MatDefs/Misc/Unshaded.j3md" );
117+         mat .setColor ("Color" , color );
118+         geo .setMaterial (mat );
119+         return  geo ;
93120    }
94121}
0 commit comments