JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
Vertex.java
Go to the documentation of this file.
1/**
2 * Copyright 2011-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.geom;
29
30import com.jogamp.math.Vec2f;
31import com.jogamp.math.Vec3f;
32import com.jogamp.math.Vert3fImmutable;
33
34/**
35 * A Vertex exposing Vec3f vertex- and texture-coordinates.
36 */
37public final class Vertex implements Vert3fImmutable {
38 private int id;
39 private boolean onCurve;
40 private final Vec3f coord = new Vec3f();
41 private final Vec3f texCoord = new Vec3f();
42
43 public Vertex() {
44 this.id = Integer.MAX_VALUE;
45 }
46
47 /** Copy ctor */
48 public Vertex(final Vertex src) {
49 this.id = Integer.MAX_VALUE;
50 coord.set(src.getCoord());
51 texCoord.set(src.getTexCoord());
52 setOnCurve(src.isOnCurve());
53 }
54
55 public Vertex(final int id, final boolean onCurve, final Vec3f texCoord) {
56 this.id = id;
57 this.onCurve = onCurve;
58 this.texCoord.set(texCoord);
59 }
60
61 public Vertex(final int id, final boolean onCurve, final float texCoordX, final float texCoordY, final float texCoordZ) {
62 this.id = id;
63 this.onCurve = onCurve;
64 this.texCoord.set(texCoordX, texCoordY, texCoordZ);
65 }
66
67 public Vertex(final Vec3f coord, final boolean onCurve) {
68 this.id = Integer.MAX_VALUE;
69 this.coord.set(coord);
70 setOnCurve(onCurve);
71 }
72
73 public Vertex(final Vec2f coord, final boolean onCurve) {
74 this.id = Integer.MAX_VALUE;
75 this.coord.set(coord, 0f);
76 setOnCurve(onCurve);
77 }
78
79 public Vertex(final float x, final float y, final boolean onCurve) {
80 this(x, y, 0, onCurve);
81 }
82
83 public Vertex(final float[] coordsBuffer, final int offset, final int length, final boolean onCurve) {
84 this(coordsBuffer[offset+0], coordsBuffer[offset+1], 2 < length ? coordsBuffer[offset+2] : 0f, onCurve);
85 }
86
87 public Vertex(final float x, final float y, final float z, final boolean onCurve) {
88 this.id = Integer.MAX_VALUE;
89 coord.set(x, y, z);
90 setOnCurve(onCurve);
91 }
92
93 public final void setCoord(final Vec3f coord) {
94 this.coord.set(coord);
95 }
96
97 public void setCoord(final Vec2f coord) {
98 this.coord.set(coord, 0f);
99 }
100
101 public final void setCoord(final float x, final float y, final float z) {
102 coord.set(x, y, z);
103 }
104
105 public final void setCoord(final float x, final float y) {
106 coord.set(x, y, 0f);
107 }
108
109 @Override
110 public int getCoordCount() {
111 return 3;
112 }
113
114 @Override
115 public final Vec3f getCoord() {
116 return coord;
117 }
118
119 public final void setX(final float x) {
120 coord.setX(x);
121 }
122
123 public final void setY(final float y) {
124 coord.setY(y);
125 }
126
127 public final void setZ(final float z) {
128 coord.setZ(z);
129 }
130
131 @Override
132 public final float x() {
133 return coord.x();
134 }
135
136 @Override
137 public final float y() {
138 return coord.y();
139 }
140
141 @Override
142 public final float z() {
143 return coord.z();
144 }
145
146 public final boolean isOnCurve() {
147 return onCurve;
148 }
149
150 public final void setOnCurve(final boolean onCurve) {
151 this.onCurve = onCurve;
152 }
153
154 public final int getId(){
155 return id;
156 }
157
158 public final void setId(final int id){
159 this.id = id;
160 }
161
162 /**
163 * @param obj the Object to compare this Vertex with
164 * @return true if {@code obj} is a Vertex and not null, on-curve flag is equal and has same vertex- and tex-coords.
165 */
166 @Override
167 public boolean equals(final Object obj) {
168 if( obj == this) {
169 return true;
170 }
171 if( null == obj || !(obj instanceof Vertex) ) {
172 return false;
173 }
174 final Vertex v = (Vertex) obj;
175 return this == v ||
176 isOnCurve() == v.isOnCurve() &&
178 getCoord().isEqual( v.getCoord() );
179 }
180
181 @Override
182 public final int hashCode() {
183 throw new InternalError("hashCode not designed");
184 }
185
186 public final Vec3f getTexCoord() {
187 return texCoord;
188 }
189
190 public final void setTexCoord(final Vec3f v) {
191 texCoord.set(v);
192 }
193
194 public final void setTexCoord(final float s, final float t, final float p) {
195 texCoord.set(s, t, p);
196 }
197
198 /**
199 * @return deep copy of this Vertex element via {@link Vertex#Vertex(Vertex)}
200 */
201 public Vertex copy(){
202 return new Vertex(this);
203 }
204
205 @Override
206 public String toString() {
207 return "[ID: " + id + ", onCurve: " + onCurve +
208 ": p " + coord +
209 ", t " + texCoord + "]";
210 }
211}
A Vertex exposing Vec3f vertex- and texture-coordinates.
Definition: Vertex.java:37
Vertex(final float[] coordsBuffer, final int offset, final int length, final boolean onCurve)
Definition: Vertex.java:83
final void setCoord(final Vec3f coord)
Definition: Vertex.java:93
final void setId(final int id)
Definition: Vertex.java:158
Vertex(final int id, final boolean onCurve, final Vec3f texCoord)
Definition: Vertex.java:55
Vertex(final Vec3f coord, final boolean onCurve)
Definition: Vertex.java:67
final Vec3f getTexCoord()
Definition: Vertex.java:186
final void setTexCoord(final Vec3f v)
Definition: Vertex.java:190
Vertex(final Vec2f coord, final boolean onCurve)
Definition: Vertex.java:73
final void setZ(final float z)
Definition: Vertex.java:127
final void setOnCurve(final boolean onCurve)
Definition: Vertex.java:150
final boolean isOnCurve()
Definition: Vertex.java:146
final void setX(final float x)
Definition: Vertex.java:119
boolean equals(final Object obj)
Definition: Vertex.java:167
Vertex(final Vertex src)
Copy ctor.
Definition: Vertex.java:48
void setCoord(final Vec2f coord)
Definition: Vertex.java:97
final void setY(final float y)
Definition: Vertex.java:123
final void setTexCoord(final float s, final float t, final float p)
Definition: Vertex.java:194
Vertex(final float x, final float y, final boolean onCurve)
Definition: Vertex.java:79
Vertex(final int id, final boolean onCurve, final float texCoordX, final float texCoordY, final float texCoordZ)
Definition: Vertex.java:61
final void setCoord(final float x, final float y, final float z)
Definition: Vertex.java:101
Vertex(final float x, final float y, final float z, final boolean onCurve)
Definition: Vertex.java:87
final void setCoord(final float x, final float y)
Definition: Vertex.java:105
2D Vector based upon two float components.
Definition: Vec2f.java:37
void set(final Vec2f o)
this = o, returns this.
Definition: Vec2f.java:73
3D Vector based upon three float components.
Definition: Vec3f.java:37
void setX(final float x)
Definition: Vec3f.java:158
boolean isEqual(final Vec3f o, final float epsilon)
Equals check using a given FloatUtil#EPSILON value and FloatUtil#isEqual(float, float,...
Definition: Vec3f.java:383
void setZ(final float z)
Definition: Vec3f.java:160
void setY(final float y)
Definition: Vec3f.java:159
Vec3f set(final Vec3f o)
this = o, returns this.
Definition: Vec3f.java:79