I'm bored, no school today, so I'm learning how to do assembly with the floating point unit instruction set. I'm trying to normalize a vector, but I cannot access the vector's x,y,or z components, instead i've got to copy to a local variable. Any way around doing that? Here's the code (with comments)
Code:
void Vector3::Normalize()
{
#if 1
float basic = x*x + y*y + z*z;
_asm
{
FLD basic; //Put basic length into st(0)
FSQRT; //Put SQUARE ROOT of basic into st(0)
FSTP basic; //Store square root of basic into memory address of basic, pop stack
}
if(basic>.0001) //won't ever be exactly zero
{
//Can't seem to access this->x,y,or z
float x1 = x;
float y1 = y;
float z1 = z;
_asm
{
FLD x1; //Load into FPU stack element zero
FDIV basic; //divide by length
FSTP x1; //store in x1 and pop stack
FLD y1;
FDIV basic;
FSTP y1;
FLD z1;
FDIV basic;
FSTP z1;
}
x = x1;
y = y1;
z = z1;
}
#else
float magnitude = sqrt( (x * x) + (y * y) + (z * z) );
if(magnitude)
{
x /= magnitude;
y /= magnitude;
z /= magnitude;
}
#endif
}