JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
CrossHair.java
Go to the documentation of this file.
1/**
2 * Copyright 2010-2023 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28package com.jogamp.graph.ui.shapes;
29
30import com.jogamp.graph.curve.OutlineShape;
31import com.jogamp.graph.ui.GraphShape;
32import com.jogamp.opengl.GL2ES2;
33import com.jogamp.opengl.GLProfile;
34
35/**
36 * A GraphUI Crosshair {@link GraphShape}
37 * <p>
38 * GraphUI is GPU based and resolution independent.
39 * </p>
40 */
41public class CrossHair extends GraphShape {
42 private float width, height, lineWidth;
43
44 public CrossHair(final int renderModes, final float width, final float height, final float linewidth) {
45 super(renderModes);
46 this.width = width;
47 this.height = height;
48 this.lineWidth = linewidth;
49 }
50
51 public final float getWidth() { return width; }
52 public final float getHeight() { return height; }
53 public final float getLineWidth() { return lineWidth; }
54
55 public void setDimension(final float width, final float height, final float lineWidth) {
56 this.width = width;
57 this.height = height;
58 this.lineWidth = lineWidth;
60 }
61
62 @Override
63 protected void addShapeToRegion(final GLProfile glp, final GL2ES2 gl) {
64 final OutlineShape shape = new OutlineShape();
65
66 final float lwh = lineWidth/2f;
67
68 final float tw = getWidth();
69 final float th = getHeight();
70 final float twh = tw/2f;
71 final float thh = th/2f;
72
73 final float ctrX = 0f, ctrY = 0f;
74 final float ctrZ = 0f;
75
76 // middle vertical (CCW!)
77 shape.moveTo(ctrX-lwh, ctrY-thh, ctrZ);
78 shape.lineTo(ctrX+lwh, ctrY-thh, ctrZ);
79 shape.lineTo(ctrX+lwh, ctrY+thh, ctrZ);
80 shape.lineTo(ctrX-lwh, ctrY+thh, ctrZ);
81 shape.closePath();
82
83 // middle horizontal (CCW!)
84 shape.moveTo(ctrX-twh, ctrY-lwh, ctrZ);
85 shape.lineTo(ctrX+twh, ctrY-lwh, ctrZ);
86 shape.lineTo(ctrX+twh, ctrY+lwh, ctrZ);
87 shape.lineTo(ctrX-twh, ctrY+lwh, ctrZ);
88 shape.closePath();
89
90 shape.setIsQuadraticNurbs();
92
93 resetGLRegion(glp, gl, null, shape);
94 region.addOutlineShape(shape, null, rgbaColor);
95 box.resize(shape.getBounds());
97 }
98
99 @Override
100 public String getSubString() {
101 return super.getSubString()+", dim "+getWidth() + " x " + getHeight();
102 }
103}
A Generic shape objects which is defined by a list of Outlines.
final void setIsQuadraticNurbs()
Claim this outline's vertices are all OutlineShape.VerticesState#QUADRATIC_NURBS, hence no cubic tran...
final void moveTo(final float x, final float y, final float z)
Start a new position for the next line segment at given point x/y (P1).
final void lineTo(final float x, final float y, final float z)
Add a line segment, intersecting the last point and the given point x/y (P1).
final void setSharpness(final float s)
Sets sharpness, defaults to DEFAULT_SHARPNESS.
final void closePath()
Closes the current sub-path segment by drawing a straight line back to the coordinates of the last mo...
final void addOutlineShape(final OutlineShape shape, final AffineTransform t, final Vec4f rgbaColor)
Add the given OutlineShape to this region with the given optional AffineTransform.
Definition: Region.java:616
Graph based GLRegion Shape.
Definition: GraphShape.java:55
final void resetGLRegion(final GLProfile glp, final GL2ES2 gl, final TextureSequence colorTexSeq, int vertexCount, int indexCount)
Reset the GLRegion and reserving its buffers to have a free capacity for vertexCount and indexCount e...
final void markShapeDirty()
Marks the shape dirty, causing next draw() to recreate the Graph shape and reset the region.
Definition: Shape.java:688
final Vec4f rgbaColor
Default base-color w/o color channel, will be modulated w/ pressed- and toggle color.
Definition: Shape.java:261
final Shape setRotationPivot(final float px, final float py, final float pz)
Set unscaled rotation origin, aka pivot.
Definition: Shape.java:620
A GraphUI Crosshair GraphShape.
Definition: CrossHair.java:41
CrossHair(final int renderModes, final float width, final float height, final float linewidth)
Definition: CrossHair.java:44
void setDimension(final float width, final float height, final float lineWidth)
Definition: CrossHair.java:55
void addShapeToRegion(final GLProfile glp, final GL2ES2 gl)
Definition: CrossHair.java:63
final AABBox resize(final AABBox newBox)
Resize the AABBox to encapsulate another AABox.
Definition: AABBox.java:274
final Vec3f getCenter()
Returns computed center of this AABBox of getLow() and getHigh().
Definition: AABBox.java:737
Specifies the the OpenGL profile.
Definition: GLProfile.java:77