Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

11991 Posts in 1587 Topics- by 3508 Members - Latest Member: PienueDut

26. May 2012, 08:56:56 am
Xith3D CommunityGeneral CategorySupport (Moderator: Marvin Fröhlich)Vanishing Lines
Pages: [1]
Print
Author Topic: Vanishing Lines  (Read 1458 times)
Patheros
Getting respectable
***
Offline Offline

Posts: 267


Dead Dolphin


View Profile WWW Email
« on: 29. January 2007, 10:40:56 pm »

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.java


Code:
package 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();
}
}
}
Logged

"I like my method, what was my method again?" - Jon
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #1 on: 29. January 2007, 11:36:48 pm »

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 looks correct. I think you mean the disappearing of the lines when they are close to the left or right border of the Canvas3D. This looks like a bug I fixed a few days ago. I will track it.

I decided not to commit it because I don't know where it should go exactly or if it even should be in SVN.

Well, the code shouldn't be committed to SVN at all in this form. The test cases demonstrate how things work, but not how they don't work Wink. But with another comment just commit it to org.xith3d.test.geometry. A good comment could be "This test case demonstrates the use of LineArray".

Marvin
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #2 on: 29. January 2007, 11:56:35 pm »

OK, looks like there's something wrong with the Bounds of a LineArray. I will further track that tomorrow.

Marvin
Logged
'n ddrylliog
Guru
*****
Offline Offline

Posts: 1188



View Profile WWW Email
« Reply #3 on: 30. January 2007, 06:40:12 pm »

OK, looks like there's something wrong with the Bounds of a LineArray. I will further track that tomorrow.
I always thought the bounds were something to clean up in Xith3D.

(note for users : Marvin found several bugs caused by wrong Bounds the past few months)
Logged
Patheros
Getting respectable
***
Offline Offline

Posts: 267


Dead Dolphin


View Profile WWW Email
« Reply #4 on: 31. January 2007, 09:33:06 pm »

But with another comment just commit it to org.xith3d.test.geometry. A good comment could be "This test case demonstrates the use of LineArray".

Done. Its now called package org.xith3d.test.geometry.LineArrayTest. (in xith-tk) It's slightly different from whats posted above. Mainly it has the SkyBoxTest sky box in the background so its less disorienting, also the lines are give a slight random velocity.
Logged

"I like my method, what was my method again?" - Jon
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #5 on: 03. February 2007, 11:19:02 pm »

I fixed this issue. Well, I fixed several Bounds related bugs. But there's still the need to call updateBounds( false ) on the lines-Shape3D. I have added this to the LineArrayTest.

Marvin
Logged
'n ddrylliog
Guru
*****
Offline Offline

Posts: 1188



View Profile WWW Email
« Reply #6 on: 05. February 2007, 06:15:24 pm »

I fixed this issue. Well, I fixed several Bounds related bugs. But there's still the need to call updateBounds( false ) on the lines-Shape3D. I have added this to the LineArrayTest.
can't this be avoided ??
ex. in PolygonAttributes in the setPolygonMode() method, call updateBounds( false ) when arg=PolygonAttributes.POLYGON_LINE ??
Logged
Patheros
Getting respectable
***
Offline Offline

Posts: 267


Dead Dolphin


View Profile WWW Email
« Reply #7 on: 05. February 2007, 07:52:19 pm »

why does updateBounds(false) need to be called?
Logged

"I like my method, what was my method again?" - Jon
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #8 on: 05. February 2007, 08:24:05 pm »

why does updateBounds(false) need to be called?

The bounds are stored in the Shape3D instance. And since a Geometry can be shared by many Shape3D instances, the Geometry (your line data) cannot simply notify the Shape3D to update it's bounds.

Marvin
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic