View Full Version : Newbs looking for vector class - I've put mine up on my site..

Robbo

07-21-2002, 02:51 AM

www.orbsoftware.com (http://www.orbsoftware.com)

(go to the nurd zone).

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

Thanks.

zeckensack

07-21-2002, 06:08 PM

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? http://www.opengl.org/discussion_boards/ubb/wink.gif

Robbo

07-21-2002, 11:20 PM

Why is the inner product wrong? (please point it out!) and I'm not sure about the sincos bit.

Help me out here!

zeckensack

07-21-2002, 11:37 PM

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? http://www.opengl.org/discussion_boards/ubb/smile.gif

While I'm already at it, this would be the correct version:

inline CVector3D& operator *= ( const CVector3D& Left )

{

x=y=z=x*Left.x+y*Left.y+z*Left.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.

void Sincos(float radians,float& sine,float& cosine)

{

__asm {

FLD radians

FSINCOS

MOV ESI,sine //load target address for sine

MOV EDI,cosine //ditto for cosine

FSTP DWORD PTR [EDI] //store cos

FSTP DWORD PTR [ESI] //store sine

}

}If you want to store to double precision, you just omit the 'DWORD PTR' stuff. If you want to store long double, you can use 'TBYTE PTR' (aka ten bytes).

Robbo

07-22-2002, 01:40 AM

Ah! Of course - thanks for these.

Doh!

Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.