Comments on org.lwjgl.vector

Started by cfmdobbie, August 30, 2003, 12:08:28

Previous topic - Next topic

cfmdobbie


  • 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.

elias

1), 2), 6),7) fixed.

5) yes, why?

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

- elias

cfmdobbie

Thanks for the fixes! :D

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

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.

elias

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

cfmdobbie

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.

elias

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

cfmdobbie

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.

nala-naj

i use 4d vectors as quaternions so i can do smooth interpolation for rotations...

elias

You're probably right cfmdobbie. But now someone shows up and claim to use them after all :-) Two classes are probably needed then.

- elias

nala-naj

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 ;)

cfmdobbie

Hi Elias,

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

Matrix3f:
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:
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.

elias

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

princec

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 :)