# Newbs looking for vector class - I've put mine up on my site..

www.orbsoftware.com
(go to the nurd zone).

Comments appreciated. Especially ideas on improvement, things I’m doing wrong etc.

Thanks.

1)Some of the inner product stuff is wrong (unary operator in vector3.h and both in vector2.h).

2)Your sincos asm won’t work. You store the results to the pointer variables, so you’re missing one level of indirection.
Hint
MOV ESI,Cos
MOV EDI,Sin
FSTP [DWORD PTR] ESI
FSTP [DWORD PTR] EDI

3)Vector division? What’s that? Why is the inner product wrong? (please point it out!) and I’m not sure about the sincos bit.

Help me out here!

Look here, both are from your code (vector3d.h):

``````//Good
// Multiply (inner product) of two vectors.
//

inline REAL operator * ( const CVector3D& Left, const CVector3D& Right )
{
return ( ( Left.x * Right.x ) + ( Left.y * Right.y ) + ( Left.z * Right.z ) );
}
``````
``````//Bad!
// Multiply this vector with another (inner product).
//

inline CVector3D& operator *= ( const CVector3D& Left )
{
x *= Left.x;
y *= Left.y;
z *= Left.z;

return ( *this );
}
``````

Notice the difference? While I’m already at it, this would be the correct version:

inline CVector3D& operator = ( const CVector3D& Left )
{
x=y=z=x
Left.x+yLeft.y+zLeft.z;
return ( *this );
}

Similar mistake in vector2d.h (twice).

As for the sincos thing, a reference ( & ) is the same as a pointer, as far as inline assembly is concerned. You’re storing the calculated sine and cosine to the (temporary) pointers on the stack. You need to dereference them. Like I posted above.

{
__asm {