# Attaching lines (later rays) to the face of a box

I realize this as a basic problem, but for some reason, I’m not finding the answer.

I have a box centered at (2,2,2) with halfExtents of (1,1,1).

I have a bunch of lines that all converge on a single point. Imagine a cone built out of lines. I’ve been trying to move the point at which they all converge to the center of the face of a box. So I set the local translation and rotation of the lines to that of the box. (The lines are created by a method I wrote that returns the Geometry of the line, so i am rotating and translating this geometry)

When the box has edges parallel to the worldspace axis, I can add the halfextent of one side of the box to the lines to get them to appear on the face. However when i spin the box, this completely messes everything up. I need to be able to move and spin the box by any rotation/translation and have the cone of lines stay on center of the same face, always point outward. Basically I just want to attach them all to the face of this box.

I hope I’ve explained it well enough above. Any help would be greatly appreciated. below is some sample code of how I am creating lines and drawing them, etc.

First I create a line. Then translate the line, then Draw the line: Here’s my code with the methods below:

[java]

/* In a loop, Tvals are a calculated to show the value of the ending point of a particular line, then the following occurs

loop { Tvals are calculated, …

/

Geometry test = CreateLine(Vector3f.ZERO, Tvals, lineColor.get(colorIndex));

//Rotates the lines to face the same as the sensor box.

Quaternion lineRot = physicsBox.getLocalRotation();

/
Apply the rotation to the line */

test.setLocalTranslation(physicsBox.getLocalTranslation());

test.setLocalRotation(lineRot);

//Now add this new line to the Vector of Geometries called “LineContainer”

} // end the loop

//Once all the lines are created and rotated, they are drawn

DrawLines(lineContainer);

[/java]

Below are the methods, First is the create line method, which makes it much easier to create a particular line:

[java] public Geometry CreateLine(Vector3f start, Vector3f end, ColorRGBA color) {

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

mat.setColor(“m_Color”, color);

LineSegment test = new LineSegment(start, end);

Mesh lineMesh = new Mesh();

lineMesh.setMode(Mesh.Mode.Lines);

lineMesh.setBuffer(VertexBuffer.Type.Position, 3, new float[]{start.x, start.y, start.z, end.x, end.y, end.z});

lineMesh.setBuffer(VertexBuffer.Type.Index, 2, new short[]{0, 1});

lineMesh.updateBound();

lineMesh.updateCounts();

Geometry lineGeometry = new Geometry(“line”, lineMesh);

lineGeometry.setMaterial(mat);

return lineGeometry;

}

[/java]

Below is the method that actually draws the lines to screen.

[java] private void DrawLines(Vector lineContainer) {

//System.out.println(lineContainer.size());

for (int i = 0; i < lineContainer.size(); i++) {

rootNode.attachChild((Spatial) lineContainer.get(i));

}

} [/java]