CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Installing SQL Server 2008
  • Writing UDFs for Firebird Embedded SQL Server
  • [Updated] Shutdown Manager
  • Building Windows Azure Cloud Service Applications with Azure Storage and the Azure SDK

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Other Programming > Assembly
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Assembly Questions and Answers for Assembly here!

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old May 8th, 2005, 01:57 AM
    SpinningVertex SpinningVertex is offline
    Junior Member
     
    Join Date: May 2005
    Posts: 6
    SpinningVertex is on a distinguished road (10+)
    Question Moving a Point along a 3D Vector,... help!

    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.
    Code:
    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.
    Code:
    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
    Reply With Quote
      #2    
    Old May 8th, 2005, 03:40 AM
    SpinningVertex SpinningVertex is offline
    Junior Member
     
    Join Date: May 2005
    Posts: 6
    SpinningVertex is on a distinguished road (10+)
    Re: Moving a Point along a 3D Vector,... help!

    I found the bug! The fSinCos places sin and cos in the oposit order in the stack.

    So,... is there a way to delete this thread? Or is anyone interested in the solution?
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Other Programming > Assembly


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 04:21 PM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
    Copyright WebMediaBrands Inc. 2002-2009