JCarnac3D-OGL provides 2 types of vector nodes :
Linear vector
Circular vector
The default vector node implementation is the class : cgJOGL3DSimpleVectorNode
To create a linear vector, you need 3 pieces of information :
The origin (point3d)
The direction (vector3d)
The length of the vector (double)
Sample code
//create a vector //origin = (0.5, 0.5, 0.5) //direction = (-1,1,1) //length = 1 cgJOGL3DSimpleVectorNode pink = new cgJOGL3DSimpleVectorNode(new Point3d(0.5d, 0.5d, 0.5d), new Vector3d(-1d, 1d, 1d), 1d); //set the vector attributes (color, line width, ...) pink.getAttribute().setLineColor(Color.PINK); //add the vector to the scenegraph rootNode.addNode(pink);
You can specify several rendering attributes on the vector.
The following sample code shows you how to modify the global vector aspect.
Sample code
cgJOGL3DSimpleVectorNode vector = new cgJOGL3DSimpleVectorNode(new Point3d(0.5d, 0.5d, 0.5d), new Vector3d(-1d, 1d, 1d), 1d); //set the vector attributes (color, line width, ...) vector.getAttribute().setLineColor(Color.PINK); vector.getAttribute().setLineWidth(3); vector.setArrowTipLength(100); vector.setArrowTipAperture(Math.PI/2);
Sample code
cgJOGL3DSimpleVectorNode vector = new cgJOGL3DSimpleVectorNode(new Point3d(0.5d, 0.5d, 0.5d), new Vector3d(-1d, 1d, 1d), 1d); //set the vector attributes (color, line width, ...) vector.getAttribute().setLineColor(Color.PINK); vector.getAttribute().setLineWidth(3); vector.setArrowTipLength(100); vector.setArrowTipAperture(Math.PI/6);
The vector size can be defined in 2 different modes : Model space or View space.
In model space mode, the vector size is interpreted as a distance in model coordinates.
In view space mode, the vector size is not affected by the model matrix scale and therefore is not affected by simple zooming operation. However, it is not a size in pixels since the vector size on the screen is changed depending on its orientation (a vector facing the user for example will have a size of 0 pixels on the screen.
To select a size mode, you can use the setSizeMode(SizeMode.???); method.
There are 2 ways to display a circular vector in JCarnac3D-OGL :
cgJOGL3DSimpleCircularVectorNode which displays the arc as a line strip.
It is well suited for thin vectors. Indeed, when the line width grows, artifacts will appear due to OpenGL line strip rendering limitation.
cgJOGL3DTriangulatedCircularVectorNode which displays the arc as a triangle strip.
It is well suited for thick vectors to avoid rendering artifacts.
The cgJOGL3DTriangulatedCircularVectorNode should be the prefered choice (leaving the cgJOGL3DSimpleCircularVectorNode to simple cases).
To create a circular vector, you need the following information :
A position, the center of the "circle" (point3d)
An axis, the axis around which the rotation is done, orthogonal to the vector plane. (vector3d)
A radius (double)
An offset angle, do determine the starting position of the arc (double, commonly 0)
A spreading angle to determine the ending position of the arc. (similar to the vector length)
When using the cgJOGL3DTriangulatedCircularVectorNode, the line width is not exactly a line width but determines the width of the triangle strip. It is possible to change the behavior of the vector as follows :
Sample code
Post to LiveJournal
cgJOGL3DTriangulatedCircularVectorNode thickCircVec = new cgJOGL3DTriangulatedCircularVectorNode(new Point3d(0, 50d, 0), new Vector3d(0, 1, 1), 100d, 0, 3 * Math.PI / 2); thickCircVec.setWidthDisplayMode(cgJOGL3DTriangulatedCircularVectorNode.WIDTH_MODE_INTERPOLATED_AXIS);
The Width display mode value can take 4 different values (constant defined in the cgJOGL3DAbstractCircularVectorNode class) :
WIDTH_MODE_VIEW : the width is always in the view plane (similar to a standard line width).
WIDTH_MODE_AXIS : the width is computed in the axis direction (perpendicular to the vector plane).
WIDTH_MODE_ORTHO_AXIS : the width is computed in the vector plane (perpendicular to the vector axis).
WIDTH_MODE_INTERPOLATED_AXIS : the width mode switches between AXIS and ORTHO_AXIS mode, depending on the view direction.