Hello Guest

Comments on org.lwjgl.vector

  • 12 Replies
  • 16349 Views
Comments on org.lwjgl.vector
« on: August 30, 2003, 12:08:28 »
  • Matrix3f.transpose(): m00 = dest.m00 etc should read dest.m00 = m00 etc.
  • Matrix4f.transpose(): Same as above, also doesn't allocate a new dest matrix if null.
  • Vector2f/3f/4f.normalise(): NaN vector dimensions with 0-length vector.
  • Vector2f/3f/4f.angle(): NaN angle with 0-length vectors.
  • Vector4f: Is this really intended to be a 4-dimensional vector? :shock:
  • Vector uses normalize(), Vector2f/3f/4f use normalise.
  • Vector2f: No toString() method implemented.


Is the org.lwjgl.vector package used internally, or is it only provided for application use?
ellomynameis Charlie Dobbie.

*

Offline elias

  • *****
  • 899
    • http://oddlabs.com
Comments on org.lwjgl.vector
« Reply #1 on: August 30, 2003, 14:19:02 »
1), 2), 6),7) fixed.

5) yes, why?

I'm not entirely sure what to do about the rest. What do you suggest?

 - elias

Comments on org.lwjgl.vector
« Reply #2 on: August 30, 2003, 15:23:40 »
Thanks for the fixes! :D

Well, for normalize(), the base Vector class does this:

Code: [Select]
public final Vector normalize() {
float len = length();
if (len != 0.0f) {
float l = 1.0f / len;
return scale(l);
} else {
assert false;
return this;
}
}


So it's probably best to follow suit.  Assert false for those in debug mode, continue with as sane data as possible otherwise.

As for angle, not sure.  An Exception is the really correct result - but you don't want that!  Use whatever you think is best, whether it be faking a zero result, or still returning NaN in that situation - using NaN at least lets the user take some action.  Whichever you choose, add it to Javadoc as a special case and maybe check the lengths first - you can shortcut a dot-product and an acos that way?


Regarding 4D vectors - I just have no idea what I'd use them for...! :wink:
ellomynameis Charlie Dobbie.

*

Offline elias

  • *****
  • 899
    • http://oddlabs.com
Comments on org.lwjgl.vector
« Reply #3 on: August 30, 2003, 17:16:38 »
4D vectors are not used very often, but they exist for the sake of completeness - OpenGL does it magic to 4d vectors (x, y, z, w) you know, although w is 1 most of the time. Projection matrices are good examples because they generally make the transformed vertices have a w != 1.

 - elias

Comments on org.lwjgl.vector
« Reply #4 on: August 30, 2003, 17:25:30 »
Oh, but that's where my question really comes from I suppose.  Vector4f is an actual 4D vector, not a 3D vector with a scaling factor.  Is this not intentional?
ellomynameis Charlie Dobbie.

*

Offline elias

  • *****
  • 899
    • http://oddlabs.com
Comments on org.lwjgl.vector
« Reply #5 on: August 30, 2003, 17:43:47 »
I'm not sure how to answer that. Is a 3d vector with a scaling factor not a 4d vector with special interpretation? Or are you saying that we should apply the scaling after Matrix4f.transform and use 3d vectors all the way?

 - elias

Comments on org.lwjgl.vector
« Reply #6 on: August 30, 2003, 18:37:25 »
Erm, I may be utterly wrong here!  I really should do a bit more reading in this area.  :oops:

I would have thought that a 3D vector with a scaling factor as opposed to a 4D vector would have various changes - the w value is *not* another dimension, so for example the lengthSquared() calculation is not x * x + y * y + z * z + w * w but wx * wx + wy * wy + wz * wz; translate() shouldn't take a w parameter (you can't translate the scalar); in add() you can't just add each value together, you need to equalize the vectors' w values, then add the x, y, z values; negate() and scale() should probably just alter w.

Does any of that sound right? :?
ellomynameis Charlie Dobbie.

Comments on org.lwjgl.vector
« Reply #7 on: August 30, 2003, 20:03:07 »
i use 4d vectors as quaternions so i can do smooth interpolation for rotations...

*

Offline elias

  • *****
  • 899
    • http://oddlabs.com
Comments on org.lwjgl.vector
« Reply #8 on: August 31, 2003, 06:53:58 »
You're probably right cfmdobbie. But now someone shows up and claim to use them after all :-) Two classes are probably needed then.

 - elias

Comments on org.lwjgl.vector
« Reply #9 on: August 31, 2003, 06:58:43 »
i didnt use the vectors in lwjgl... i'm just saying that in general, i use a 4d vectors for quaternions... if you need someone to use those classes in lwjgl, i suppose i could use them ;)

Comments on org.lwjgl.vector
« Reply #10 on: September 01, 2003, 11:28:12 »
Hi Elias,

Sorry to be a nuisance, but the transpose methods aren't quite right.  Try these instead:

Matrix3f:
Code: [Select]
public Matrix3f transpose(Matrix3f dest) {

if (dest == null) {
// New matrix needed to store transpose
dest = new Matrix3f();
}

if (this == dest) {
// Destination and source are the same!  Run the in-place
// transpose instead as the copy transpose will be destructive.
transpose();
} else {
// Destination differs from source.  Perform copy transpose
dest.m00 = m00;
dest.m01 = m10;
dest.m02 = m20;
dest.m10 = m01;
dest.m11 = m11;
dest.m12 = m21;
dest.m20 = m02;
dest.m21 = m12;
dest.m22 = m22;
}

return dest;
}


Matrix4f:
Code: [Select]
public Matrix4f transpose(Matrix4f dest) {

if (dest == null) {
// New matrix needed to store transpose
dest = new Matrix3f();
}

if (this == dest) {
// Destination and source are the same!  Run the in-place
// transpose instead as the copy transpose will be destructive.
transpose();
} else {
// Destination differs from source.  Perform copy transpose
dest.m00 = m00;
dest.m01 = m10;
dest.m02 = m20;
dest.m03 = m30;
dest.m10 = m01;
dest.m11 = m11;
dest.m12 = m21;
dest.m13 = m31;
dest.m20 = m02;
dest.m21 = m12;
dest.m22 = m22;
dest.m23 = m32;
dest.m30 = m03;
dest.m31 = m13;
dest.m32 = m23;
dest.m33 = m33;
}

return dest;
}


Oh, and by the way, there appears to be an... err... "event" in the CVS logs that looks quite amusing.  About two weeks ago, did Cas go and delete the entire project? :lol:

Cheers,
Charlie.
ellomynameis Charlie Dobbie.

*

Offline elias

  • *****
  • 899
    • http://oddlabs.com
Comments on org.lwjgl.vector
« Reply #11 on: September 01, 2003, 12:39:15 »
Sorry about that, and do keep being annoying as long as you fix bugs! Yes, Cas did in fact destroy the entire project once.

 - elias

*

Offline princec

  • *****
  • 1933
    • Puppygames
Comments on org.lwjgl.vector
« Reply #12 on: September 01, 2003, 12:56:17 »
Yeah, and you'd better all be really nice and pray to appropriate gods in a timely fashion or Eclipse will delete it again just to spite everyone. (It was, indeed, a bug in Eclipse)

Cas :)