# Line and Arc

If it isn’t needed. Just ignore it.

And I have a question.

How can I apply antialiasing effect for these meshes?

[java]

import java.nio.FloatBuffer;

import com.jme3.scene.Mesh;

import com.jme3.scene.VertexBuffer.Type;

import com.jme3.util.BufferUtils;

/**

• An arc consists of line segments.

*
• @author Lim, YongHoon

*/

public class Arc extends Mesh {

/**
• @param samples
• ``````       sampling rate to create arc<br />
``````
• ``````       radius of arc<br />
``````
• @param start
• ``````       start angle(in radian)<br />
``````
• @param end
• ``````       end angle(in radian)<br />
``````

*/

public Arc(int samples, float radius, float start, float end) {

FloatBuffer vertexBuf = createBuffer(samples, radius, start, end);

setBuffer(Type.Position, 3, vertexBuf);

setMode(Mode.LineStrip);

updateBound();

updateCounts();

}

private FloatBuffer createBuffer(int sample, float radius, float start,

float end) {

FloatBuffer buf = BufferUtils.createVector3Buffer(sample);

buf.rewind();

float arc = end - start;

for (int i = 0; i < sample; i++) {

float theta = start + arc / (sample - 1) * i;

float x = (float) (Math.cos(theta) * radius);

float y = (float) (Math.sin(theta) * radius);

buf.put(x).put(y).put(0);

}

return buf;

}

}

import java.nio.FloatBuffer;

import com.jme3.math.Vector3f;

import com.jme3.scene.Mesh;

import com.jme3.scene.VertexBuffer;

import com.jme3.scene.VertexBuffer.Format;

import com.jme3.scene.VertexBuffer.Type;

import com.jme3.scene.VertexBuffer.Usage;

import com.jme3.util.BufferUtils;

/**

• Line

*
• @author Lim, YongHoon

*

*/

public class Line extends Mesh {

/**
• Create single line with start/end point

*
• @param start
• ``````       start poisition<br />
``````
• @param end
• ``````       end position<br />
``````

*/

public Line(Vector3f start, Vector3f end) {

this(Mode.Lines, new Vector3f[] { start, end });

}

/**

• Create lines

*
• @param mode
• ``````       Mode.Lines, Mode.LineLoop, Mode.LineStrip<br />
``````
• @param points
• ``````       line points<br />
``````

*/

public Line(Mode mode, Vector3f… points) {

FloatBuffer data = BufferUtils.createFloatBuffer(points);

VertexBuffer vpb = new VertexBuffer(Type.Position);

vpb.setupData(Usage.Static, 3, Format.Float, data);

setBuffer(vpb);

setMode(mode);

updateBound();

updateCounts();

}

}

import com.jme3.app.SimpleApplication;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.FastMath;

import com.jme3.math.Vector3f;

import com.jme3.scene.Geometry;

import com.jme3.scene.Mesh;

import com.jme3.scene.Mesh.Mode;

import com.jme3.scene.shape.Arc;

import com.jme3.scene.shape.Line;

public class TestLine extends SimpleApplication {

public static void main(String[] args){

TestLine app = new TestLine();

app.start();

}

@Override

public void simpleInitApp() {

Vector3f[] loopPoints = new Vector3f[] {

new Vector3f(0, 0, 0),

new Vector3f(1, 0, 0),

new Vector3f(1, 1, 0),

new Vector3f(0, 1, 0),

};

Vector3f[] linePoints = new Vector3f[] {

new Vector3f(0, 0, 0),

new Vector3f(1, 0, 0),

new Vector3f(1, 1, 0),

new Vector3f(0, 1, 0),

};

Vector3f[] lineStrip = new Vector3f[] {

new Vector3f(0, 0, 0),

new Vector3f(1, 0, 0),

new Vector3f(1, 1, 0),

new Vector3f(0, 1, 0),

};

Line l1 = new Line(Mode.LineLoop, loopPoints);

Line l2 = new Line(Mode.Lines, linePoints);

Line l3 = new Line(Mode.LineStrip, lineStrip);

l1.setLineWidth(1);

l2.setLineWidth(2);

l3.setLineWidth(4);

Geometry geom1 = addGeometry(“Loop”, l1, ColorRGBA.White);

Geometry geom2 = addGeometry(“Lines”, l2, ColorRGBA.Red);

Geometry geom3 = addGeometry(“Strip”, l2, ColorRGBA.Blue);

geom1.setLocalTranslation(-2, 0, 0);

geom3.setLocalTranslation(2, 0, 0);

Arc arc = new Arc(64, 1, 0, FastMath.HALF_PI);

Geometry arcGeom = addGeometry(“Arc”, arc, ColorRGBA.Cyan);

arcGeom.setLocalTranslation(-2, 3, 0);

Arc circle = new Arc(64, 1, 0, FastMath.TWO_PI);

Geometry circleGeom = addGeometry(“Arc”, circle, ColorRGBA.Cyan);

circleGeom.setLocalTranslation(2, 3, 0);

}

private Geometry addGeometry(String name, Mesh mesh, ColorRGBA color) {

Geometry geom = new Geometry(name, mesh);

Material mat = new Material(assetManager, “Common/MatDefs/Misc/SolidColor.j3md”);

mat.setColor(“m_Color”, color);

geom.setMaterial(mat);

rootNode.attachChild(geom);

return geom;

}

}

[/java]