Vector class, overriding the - operator

Started by
3 comments, last by Omaha 16 years, 3 months ago
Hi, I'm still trying to find the problem with my messed up normals, and I've managed to trace the problem to my vector class. I'm using the following code to override the minus operator:

SYM_VECTOR SYM_VECTOR::operator -(SYM_VECTOR Vector)
{
	SYM_VECTOR Temp;
	
	Temp.i = i - Vector.i;
	Temp.k = j - Vector.j;
	Temp.j = k - Vector.k;

	return Temp;
}

Very simple. However, the following two expressions give me different results, yet in practice they are exactly the same:

SYM_VECTOR v1, v2, v3, b1, b2;

b1 = v2 - v1;
b2 = v3 - v1;


SYM_VECTOR v1, v2, v3, b1, b2;

b1.i = v2.i - v1.i;
b1.j = v2.j - v1.j;
b1.k = v2.k - v1.k;

b2.i = v3.i - v1.i;
b2.j = v3.j - v1.j;
b2.k = v3.k - v1.k;

Any help appreciated.

"The right, man, in the wrong, place, can make all the dif-fer-rence in the world..." - GMan, Half-Life 2

A blog of my SEGA Megadrive development adventures: http://www.bigevilcorporation.co.uk

Advertisement
Temp.j and Temp.k are transposed in your operator-() function. Perhaps that's the problem.
Temp.k = j - Vector.j;Temp.j = k - Vector.k;
Thank you both.

I think I need sleep. I've scanned over that function over 20 times :/

"The right, man, in the wrong, place, can make all the dif-fer-rence in the world..." - GMan, Half-Life 2

A blog of my SEGA Megadrive development adventures: http://www.bigevilcorporation.co.uk

Quote:Original post by deadstarI think I need sleep. I've scanned over that function over 20 times :/


Haha. Been there.

This topic is closed to new replies.

Advertisement