Hi Javier,
Here I am attaching a sample file that draws arrows.
the arrow class has a function that will return a "TransformGroup" node
having the arrow below it.
This is a 3D arrow and made up of two cones and a cylinder.
The input parameters are arrow diameter, start point and end point.
(Note: if you are populating large number of arrows in the scene, you
better opt for a different way to represent the same. So that you can
instanciate the same object in the scene)
Cheers
Nath
______________________________________________________________________________
On Tue, 9 May 2000, [iso-8859-1] S�nchez Sanz, Javier wrote:
> Hi, I need a geometry of an arrow (ej: ->). Does anyone code or a library of
> any kind of arrows?
> Thanks in advance.
> Javi
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff JAVA3D-INTEREST". For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
>
import java.applet.Applet;
import java.awt.Frame;
import java.awt.event.*;
import com.sun.j3d.utils.applet.MainFrame;
import java.awt.BorderLayout;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.*;
import javax.media.j3d.*;
import javax.vecmath.*;
public class arrow extends Applet
{
public static void main(String[] args)
{
Applet scene = new arrow();
Frame jFrame = new MainFrame(scene, 500, 500);
}
//Constructor for the applet
public arrow()
{
setLayout(new BorderLayout());
Canvas3D jCanvas3D = new Canvas3D(null);
add("Center", jCanvas3D);
BranchGroup jScene = createSceneGraph();
jScene.compile();
SimpleUniverse jVirtualUniverse = new SimpleUniverse(jCanvas3D);
jVirtualUniverse.getViewingPlatform().setNominalViewingTransform();
jVirtualUniverse.addBranchGraph(jScene);
}
//Creates an 3Darrow between point stPt and endPt
public TransformGroup createArrow(float ArrowDia, Vector3f stPt, Vector3f endPt)
{
float arrowDir = ((endPt.y-stPt.y)/Math.abs(endPt.y-stPt.y));
double lenSq = (stPt.x-endPt.x)*(stPt.x-endPt.x) +
(stPt.y-endPt.y)*(stPt.y-endPt.y) +
(stPt.z-endPt.z)*(stPt.z-endPt.z);
float ArrowLen = (float) Math.sqrt(lenSq);
float ArrowHeadLen = 5.0f*ArrowDia;
float ArrowHeadDia = 2.0f*ArrowDia;
float ArrowTailDia = ArrowDia;
float AroowTailLen = 2.5f*ArrowDia;
float CylenderLen = ArrowLen - ArrowHeadLen - AroowTailLen;
//Rotation Matrix for whole arrow (cylinder + two cones)
Matrix4f RotMat = new Matrix4f();
float CosTheta = (endPt.x - stPt.x)/ArrowLen;
float SinTheta = (endPt.y - stPt.y)/ArrowLen;
System.out.println("Value of Cos");
System.out.print(CosTheta);
System.out.println("Value of Sin");
System.out.print(SinTheta);
RotMat.m00 = SinTheta;
RotMat.m01 = CosTheta;
RotMat.m02 = 0.0f;
RotMat.m03 = stPt.x + (endPt.x - stPt.x)/2.0f -
arrowDir*(ArrowHeadLen-AroowTailLen)/2.0f;
RotMat.m10 = -CosTheta;
RotMat.m11 = SinTheta;
RotMat.m12 = 0.0f;
RotMat.m13 = stPt.y + (endPt.y - stPt.y)/2.0f -
arrowDir*(ArrowHeadLen-AroowTailLen)/2.0f;
RotMat.m20 = 0.0f;
RotMat.m21 = 0.0f;
RotMat.m22 = 1.0f;
RotMat.m23 = stPt.z + (endPt.z - stPt.z)/2.0f -
arrowDir*(ArrowHeadLen-AroowTailLen)/2.0f;
RotMat.m30 = 0.0f;
RotMat.m31 = 0.0f;
RotMat.m32 = 0.0f;
RotMat.m33 = 1.0f;
//Apperance for the arrow
Appearance caAppearance = new Appearance();
ColoringAttributes caColor;
caColor = new ColoringAttributes();
caColor.setColor(0.8f,0.8f,0.8f);
caAppearance.setColoringAttributes(caColor);
Transform3D caTransform = new Transform3D();
caTransform.set(RotMat);
TransformGroup caTransformGroup = new TransformGroup(caTransform);
Node cArrowCylinder = new Cylinder(ArrowDia, CylenderLen, caAppearance);
Transform3D arrowHeadTransform = new Transform3D();
arrowHeadTransform.set(new
Vector3f(0.0f,CylenderLen/2.0f+0.5f*ArrowHeadLen,0.0f));
TransformGroup arrowHeadTransformGroup = new TransformGroup(arrowHeadTransform);
Transform3D arrowTailTransform = new Transform3D();
arrowTailTransform.set(new
Vector3f(0.0f,-CylenderLen/2.0f-0.5f*AroowTailLen,0.0f));
Transform3D arrowTailTransformTmp = new Transform3D();
arrowTailTransformTmp.rotZ(Math.PI);
arrowTailTransform.mul(arrowTailTransformTmp);
TransformGroup arrowTailTransformGroup = new TransformGroup(arrowTailTransform);
Node ArrowHeadCone = new Cone(ArrowHeadDia, ArrowHeadLen, 1, caAppearance);
Node ArrowTailCone = new Cone(ArrowTailDia, AroowTailLen, 1, caAppearance);
arrowHeadTransformGroup.addChild(ArrowHeadCone);
arrowTailTransformGroup.addChild(ArrowTailCone);
caTransformGroup.addChild(arrowHeadTransformGroup);
caTransformGroup.addChild(arrowTailTransformGroup);
caTransformGroup.addChild(cArrowCylinder);
return caTransformGroup;
}
public BranchGroup createSceneGraph()
{
BranchGroup SceneRoot = new BranchGroup();
float PCylnRadius = 0.05f;
SceneRoot.addChild(createArrow(0.02f, new Vector3f(-0.2f,-0.25f,0.0f), new
Vector3f(-0.6f,0.25f,0.0f)));
SceneRoot.addChild(createArrow(0.02f, new Vector3f(0.5f,-0.25f,0.0f), new
Vector3f(0.6f,0.25f,0.0f)));
SceneRoot.addChild(createArrow(0.02f, new Vector3f(0.0f,0.25f,0.0f), new
Vector3f(0.0f,-0.25f,0.0f)));
SceneRoot.addChild(createArrow(0.02f, new Vector3f(0.35f,0.25f,0.0f), new
Vector3f(0.35f,-0.25f,0.0f)));
return SceneRoot;
}
}