29package com.jogamp.math;
55 return new Vec4f(
this);
58 public Vec4f(
final float[] xyzw) {
62 public Vec4f(
final float x,
final float y,
final float z,
final float w) {
85 public Vec4f set(
final float x,
final float y,
final float z,
final float w) {
94 public Vec4f set(
final float[] xyzw) {
112 public void set(
final int i,
final float val) {
114 case 0: x = val;
break;
115 case 1: y = val;
break;
116 case 2: z = val;
break;
117 case 3: w = val;
break;
118 default:
throw new IndexOutOfBoundsException();
123 public float[]
get(
final float[] xyzw) {
132 public float get(
final int i) {
138 default:
throw new IndexOutOfBoundsException();
142 public float x() {
return x; }
143 public float y() {
return y; }
144 public float z() {
return z; }
145 public float w() {
return w; }
147 public void setX(
final float x) { this.x = x; }
148 public void setY(
final float y) { this.y = y; }
149 public void setZ(
final float z) { this.z = z; }
150 public void setW(
final float w) { this.w = w; }
154 this.x = Math.
max(this.x, m.x);
155 this.y = Math.
max(this.y, m.y);
156 this.z = Math.
max(this.z, m.z);
157 this.w = Math.
max(this.w, m.w);
162 this.x = Math.
min(this.x, m.x);
163 this.y = Math.
min(this.y, m.y);
164 this.z = Math.
min(this.z, m.z);
165 this.w = Math.
min(this.w, m.w);
171 return new Vec4f(
this).scale(val);
187 public Vec4f mul(
final float sx,
final float sy,
final float sz,
final float sw) {
224 return new Vec4f(
this).add(arg);
237 public Vec4f add(
final float dx,
final float dy,
final float dz,
final float dw) {
256 return new Vec4f(
this).sub(arg);
286 return (
float) Math.sqrt(
lengthSq());
293 return x*x + y*y + z*z + w*w;
307 final float invSqr = 1.0f / (float)Math.sqrt(
lengthSq);
324 final float dx = x - o.x;
325 final float dy = y - o.y;
326 final float dz = z - o.z;
327 final float dw = w - o.w;
328 return dx*dx + dy*dy + dz*dz + dw*dw;
335 return (
float)Math.sqrt(
distSq(o));
344 return x*o.x + y*o.y + z*o.z + w*o.w;
358 return (
float) Math.acos(
cosAngle(o) );
410 if( o instanceof
Vec4f ) {
419 return x +
" / " + y +
" / " + z +
" / " + w;
Basic Float math utility functions.
static boolean isZero(final float a, final float epsilon)
Returns true if value is zero, i.e.
static boolean isEqual(final float a, final float b, final float epsilon)
Returns true if both values are equal, i.e.
3D Vector based upon three float components.
4D Vector based upon four float components.
Vec4f add(final Vec4f b)
this = this + b, returns this.
Vec4f toArray(final float[] xyzw)
xyzw[0..3] = this.
Vec4f div(final Vec4f a)
this = this / a, returns this.
Vec4f mul(final Vec4f a, final Vec4f b)
this = a * b, returns this.
Vec4f max(final Vec4f m)
this = max(this, m), returns this.
Vec4f plus(final Vec4f a, final Vec4f b)
this = a + b, returns this.
Vec4f(final float x, final float y, final float z, final float w)
Vec4f min(final Vec4f m)
this = min(this, m), returns this.
Vec4f scale(final float s)
this = this * s, returns this.
Vec4f mul(final float val)
Returns this * val; creates new vector.
Vec4f add(final float dx, final float dy, final float dz, final float dw)
this = this + { dx, dy, dz, dw }, returns this.
Vec4f normalize()
Normalize this vector in place.
Vec4f div(final Vec4f a, final Vec4f b)
this = a / b, returns this.
Vec4f plus(final Vec4f arg)
Returns this + arg; creates new vector.
float angle(final Vec4f o)
Return the angle between two vectors in radians.
float cosAngle(final Vec4f o)
Return the cosines of the angle between two vectors.
Vec4f sub(final Vec4f b)
this = this - b, returns this.
Vec4f minus(final Vec4f arg)
Returns this - arg; creates new vector.
float dist(final Vec4f o)
Return the distance between this vector and the given one.
Vec4f mul(final Vec4f s)
this = this * s, returns this.
boolean isEqual(final Vec4f o, final float epsilon)
Equals check using a given FloatUtil#EPSILON value and FloatUtil#isEqual(float, float,...
float dot(final Vec4f o)
Return the dot product of this vector and the given one.
float lengthSq()
Return the squared length of this vector, a.k.a the squared norm or squared magnitude
boolean isEqual(final Vec4f o)
Equals check using FloatUtil#EPSILON in FloatUtil#isEqual(float, float).
boolean equals(final Object o)
Vec4f(final float[] xyzw)
float length()
Return the length of this vector, a.k.a the norm or magnitude
Vec4f(final Vec3f o, final float w)
Creating new Vec4f using { o, w }.
Vec4f minus(final Vec4f a, final Vec4f b)
this = a - b, returns this.
float distSq(final Vec4f o)
Return the squared distance between this vector and the given one.
Vec4f mul(final float sx, final float sy, final float sz, final float sw)
this = this * { sx, sy, sz, sw }, returns this.
boolean isZero()
Return true if all components are zero, i.e.