SpinningVertex
May 8th, 2005, 01:57 AM
Hello everyone,... I'm new!
And I have a bit of a problem with my inline ASM in Delphi... well, to be honest, there is nothing worng with it. It's my code that's not really doing what I meant it to do. For some unexplainable reason.
The routine (written in Delphi) looks like this.
Procedure iVector3Motion (var Position : TSVector3; const Direction : TSVector3);
var
Projection : Single;
Begin
Position.Y := Position.Y + Direction.Force * sin(Direction.Tilt);
Projection := Direction.Force * cos(Direction.Tilt);
Position.Z := Position.Z + Projection * sin(Direction.Swivel);
Position.X := Position.X + Projection * cos(Direction.Swivel);
end;
It works,... but, unfortunetly not nearly as fast as I want it to be. As you can see, I move the 3D point named "Position" with the Vector "Direction".
The type TSVector3, is a simple [0..2] array of single with some added names for each of the items in the array. X, Y and Z for position and, Tilt,Swivel and Force for Direction.
Here is what I thought would work nicely in ASM,... but there is some bug and I just can't seem to find it. It Works without generating any errors but the values are not at all the same as I get from my Pascal routine. I'm hoping the bug will present itself politly to someone who looks at the code for the first time. :)
Procedure iVector3MotionAsm(var Position : TSVector3; const Direction : TSVector3);
asm
fLD [Direction.Force] // Load the force
fLD [Direction.Tilt] // Load Tilt. Force = ST[1]
fSinCos // Perform Sin AND Cos. Cos Result = ST[1]. Force = ST[2]
fMul ST(0), ST(2) // Multiply Sin(Tilt) with the Force
fAdd [Position.Y] // Add the current Y Position
fSTP [Position.Y] // Save Y.
// Current Stack is Cos(Tilt), Force = ST[1]
fMulp // Mul Cos(Tilt) with the force and pop the stack since the Force isn't needed anymore
// St[0] = Projection
fLD [Direction.Swivel] // Load Swivel making the Projection ST[1]
fSinCos // Perform Sin AND Cos. Sin = ST[0], Cos = ST[1], and Projection ST[2]
fMul ST(0), ST(2) // Multiply the Projection and and Sin(Swivel)
fAdd [Position.Z] // Add Z
fSTP [Position.Z] // Store Z
// Current Stack = cos(Swivel). ST[1] = Projection
fMulp // Multiply the Projection and cos(Swivel) and pop the Stack
fAdd [Position.X] // Add X
fSTP [Position.X] // Store X
fwait // wait and make sure everything went ok
end;
As I said earlier, I get no errors, only absurd values.
Niklas
And I have a bit of a problem with my inline ASM in Delphi... well, to be honest, there is nothing worng with it. It's my code that's not really doing what I meant it to do. For some unexplainable reason.
The routine (written in Delphi) looks like this.
Procedure iVector3Motion (var Position : TSVector3; const Direction : TSVector3);
var
Projection : Single;
Begin
Position.Y := Position.Y + Direction.Force * sin(Direction.Tilt);
Projection := Direction.Force * cos(Direction.Tilt);
Position.Z := Position.Z + Projection * sin(Direction.Swivel);
Position.X := Position.X + Projection * cos(Direction.Swivel);
end;
It works,... but, unfortunetly not nearly as fast as I want it to be. As you can see, I move the 3D point named "Position" with the Vector "Direction".
The type TSVector3, is a simple [0..2] array of single with some added names for each of the items in the array. X, Y and Z for position and, Tilt,Swivel and Force for Direction.
Here is what I thought would work nicely in ASM,... but there is some bug and I just can't seem to find it. It Works without generating any errors but the values are not at all the same as I get from my Pascal routine. I'm hoping the bug will present itself politly to someone who looks at the code for the first time. :)
Procedure iVector3MotionAsm(var Position : TSVector3; const Direction : TSVector3);
asm
fLD [Direction.Force] // Load the force
fLD [Direction.Tilt] // Load Tilt. Force = ST[1]
fSinCos // Perform Sin AND Cos. Cos Result = ST[1]. Force = ST[2]
fMul ST(0), ST(2) // Multiply Sin(Tilt) with the Force
fAdd [Position.Y] // Add the current Y Position
fSTP [Position.Y] // Save Y.
// Current Stack is Cos(Tilt), Force = ST[1]
fMulp // Mul Cos(Tilt) with the force and pop the stack since the Force isn't needed anymore
// St[0] = Projection
fLD [Direction.Swivel] // Load Swivel making the Projection ST[1]
fSinCos // Perform Sin AND Cos. Sin = ST[0], Cos = ST[1], and Projection ST[2]
fMul ST(0), ST(2) // Multiply the Projection and and Sin(Swivel)
fAdd [Position.Z] // Add Z
fSTP [Position.Z] // Store Z
// Current Stack = cos(Swivel). ST[1] = Projection
fMulp // Multiply the Projection and cos(Swivel) and pop the Stack
fAdd [Position.X] // Add X
fSTP [Position.X] // Store X
fwait // wait and make sure everything went ok
end;
As I said earlier, I get no errors, only absurd values.
Niklas