How to draw a line

  1. Why don’t you just use the Line class? It’s much easier.

  2. It could be because of multiple reasons, try making a single class testate case

  3. Besides, the code seems quite messy (you’re using Position in a place where Vector3f would be expected). Try to keep your code separated.

  4. You can look here if you don’t know what to do else : https://jmonkeyengine.github.io/wiki/jme3/advanced/custom_meshes.html

1 Like

Hello MisterCavespider,

  1. thanks for the input, i will look into the Line class.

  2. i will look into Line class first, it sounds more like what i need

  3. i started out without any game engine and build my own Position and Vector class and much more, some of which i discovered later were already implemented. Much of the more sophisticated classes are build upon my own implementation, for now i stick with them.

  4. i’ll have a look into that although i am doubting at the moment if meshes are the right solution for a 2d representation
    of a track layout.

1 Like

Nothing in your code jumps out as incorrect. It’s possible that the problem is elsewhere.

If you can’t find the issue then simplify the test into a single class test case that exhibits the issue and then post that.

1 Like

Mesh is a general term for the surface of something which is displayed. Along with a Material it makes up a Geometry.

Now jme being a 3d engine you have to do pretty much anything in 3d and use the guiNode. You have some simple 2d classes but for example there is no Sprite Sheet Support or 2d Physics. It might not be needed for a Track Editor so you are fine with jme but if you need some heavy 2d stuff you might need another engine or Code much stuff.

1 Like

I followed an example on stack exchange on how to use Line and it is now producing lines:

in init:

Node line1 = new Node();
        Node line2 = new Node();
        Node line3 = new Node();
        add2DLine( new Position ( 0.0, 1.0, 0.0), new Position (1.0, 0.0, 0.0), line1, 1 );
        add2DLine( new Position ( 0.0, 0.0, 0.0), new Position (0.0, 0.0, 1.0), line2, 2 );
        add2DLine( new Position ( 0.0, 0.0, 0.0), new Position (0.0, 1.0, 0.0), line3, 3 );
        View2D.attachChild( line1 );
        View2D.attachChild( line2 );
        View2D.attachChild( line3 );

and the line function with color added for debugging

private void add2DLine( Position A, Position B, Node myNode, int color ) {
        Line line = new Line(new Vector3f( (float) A.getXPos(), (float) A.getYPos(), (float) A.getZPos()), 
                             new Vector3f( (float) B.getXPos(), (float) B.getYPos(), (float) B.getZPos()));
        line.setLineWidth(2);
        Geometry geometry = new Geometry("Bullet", line);
        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        if ( color == 1 ) {
            mat.setColor("Color", ColorRGBA.Blue);
        };
        if ( color == 2 ) {
            mat.setColor("Color", ColorRGBA.Green);
        };
        if ( color == 3 ) {
            mat.setColor("Color", ColorRGBA.Red);
        };
        if ( color > 3 ) {
            mat.setColor("Color", ColorRGBA.Pink);
        };
        
        geometry.setMaterial( mat );           
        mat.getAdditionalRenderState().setFaceCullMode( RenderState.FaceCullMode.Off );
        geometry.setCullHint(Spatial.CullHint.Never); 
        geometry.updateGeometricState();  //unsure about this is necessary
         geometry.updateModelBound();     //unsure about this is necessary 
        myNode.attachChild(geometry);
    };

1 Like

For the future:

…and it’s a sticky at the top of the forum, too.

1 Like

Thanks, i changed the code post

1 Like