# Vector class, overriding the - operator

This topic is 3984 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

##### Share on other sites
Temp.j and Temp.k are transposed in your operator-() function. Perhaps that's the problem.

##### Share on other sites
Temp.k = j - Vector.j;Temp.j = k - Vector.k;

##### Share on other sites
Thank you both.

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

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

Haha. Been there.

1. 1
2. 2
3. 3
Rutin
13
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633697
• Total Posts
3013404
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!