Ok I'm trying to use LineArray to draw lines a arbitrary positions and from some angles and some positions they don't show up. Its quite possible that I'm using the LineArray incorrectly. If you guys could take a look at it I would greatly appreciate it.
The code is at the end of this post. The two methods on interest are createLines and updateLines. I decided not to commit it because I don't know where it should go exactly or if it even should be in SVN.
VanishingLinesTest.javapackage org.xith3d.test;
import java.util.Random;
import javax.vecmath.Color3f;
import net.jtank.input.KeyCode;
import net.jtank.input.MouseDevice;
import org.xith3d.render.base.Xith3DEnvironment;
import org.xith3d.render.canvas.Canvas3DWrapper;
import org.xith3d.render.canvas.CanvasConstructionInfo;
import org.xith3d.render.loop.ExtRenderLoop;
import org.xith3d.scenegraph.Appearance;
import org.xith3d.scenegraph.ColoringAttributes;
import org.xith3d.scenegraph.GeomDataInterface;
import org.xith3d.scenegraph.LineArray;
import org.xith3d.scenegraph.LineAttributes;
import org.xith3d.scenegraph.Node;
import org.xith3d.scenegraph.Shape3D;
import org.xith3d.scenegraph.TransformGroup;
import org.xith3d.utility.input.EgoInputAdapter;
import org.xith3d.utility.input.EgoInputAdapter.KeyCommand;
@Xith3DTest.Description
(
fulltext = {
"Shows how a LineArray is not always visible"
},
authors = { "Andrew Hanson (aka Patheros)" }
)
public class VanishingLinesTest extends ExtRenderLoop implements Xith3DTest
{
private EgoInputAdapter egoAdapter;
private GeomDataInterface lineData;
private float[] points = new float[6*10];
@Override
protected void loopIteration(long gameTime, long frameTime)
{
egoAdapter.updateView( gameTime, frameTime );
updateLines();
super.loopIteration( gameTime, frameTime );
}
private Xith3DTest.FinishListener finishListener;
@Override
protected void exit()
{
if (finishListener != null)
finishListener.onTestFinished();
else
super.exit();
}
/**
* Starts this test case.
*
* @param canvasInfo an object holding all information to create a Canvas3DWrapper
*/
public VanishingLinesTest(CanvasConstructionInfo canvasInfo, Xith3DTest.FinishListener finishListener) throws Exception
{
super( 128L ); // limit FPS to 128
Xith3DEnvironment env = new Xith3DEnvironment( this );
env.addChild(createLines());
Canvas3DWrapper canvas = new Canvas3DWrapper( canvasInfo );
env.addCanvas( canvas );
// initialize input
this.registerKeyboardAndMouse( canvas );
MouseDevice mouse = this.getMouse();
mouse.setExclusive( true );
this.egoAdapter = new EgoInputAdapter( env.getView(), canvas, 1.0f, -1.0f, 1.0f );
egoAdapter.createDefaultKeyBindings( true );
egoAdapter.unbindKey( KeyCommand.CROUCH );
this.registerInputListener( this.egoAdapter );
this.finishListener = finishListener;
this.begin();
}
public static void main(String[] args) throws Exception
{
new VanishingLinesTest( new CanvasConstructionInfo( Xith3DTest.DEFAULT_RESOLUTION,Canvas3DWrapper.DisplayMode.WINDOWED, "BaseTest" ), null );
}
@Override
public void onKeyReleased(int key)
{
switch (key)
{
case KeyCode.VK_ESCAPE:
this.end();
break;
}
}
private Node createLines() {
Random rnd = new Random(100);
for(int i=0;i<6*10;i++){
points[i] = (float)(10.0*rnd.nextFloat() - 5.0);
}
TransformGroup sceneBranch = new TransformGroup();
Appearance a = new Appearance();
LineAttributes lineAtr = new LineAttributes();
lineAtr.setLineWidth(3);
a.setLineAttributes(lineAtr);
a.setColoringAttributes(new ColoringAttributes(new Color3f(1,0,0),ColoringAttributes.SHADE_FLAT));
LineArray velLines = new LineArray(2*10,LineArray.COORDINATES);
lineData = velLines.getCoordinateData();
Shape3D s = new Shape3D(velLines,a);
Shape3D.setGlobalIgnoreBounds(true);
sceneBranch.addChild(s);
return sceneBranch;
}
private void updateLines() {
if(lineData!=null){
lineData.start();
lineData.setFloats(points ,0,6*10);
lineData.end();
}
}
}