Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Assembly (http://www.programmingforums.org/forum20.html)
-   -   Floats to doubles (http://www.programmingforums.org/showthread.php?t=6874)

Klarre Nov 7th, 2005 1:30 PM

Floats to doubles
 
I have a problem with floats and doubles.

I wanted to put a camera in my OpenGL scene. But when
I added the gluLookAt function, the program did'nt started
anymore.

I was using this code, and simply made a call like
:

_gluLookAt eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz
in my draw function.
These variables are created like this:
:

eyex dd 0.0

:

_gluLookAt macro A1, A2, A3, A4, A5, A6, A7, A8, A9
        push A9
        push A8
        push A7
        push A6
        push A5
        push A4
        push A3
        push A2
        push A1
        call gluLookAt
endm


I guessed that the problem was that the gluLookAt function expects 64 bits doubles,
instead of 32 bits floats. I tried my assumption by pushing twice as much on the stack.
Then the program started again, but with wrong values to gluLookAt of course.

How shall I solve this problem? How do I convert my floats to doubles? Is there
a simple way of doing this?

I am not an assembly guru, so try keeping the answears as clean as possible ;)

Thanks

/Klarre

Polyphemus_ Nov 7th, 2005 1:36 PM

Maybe this page helps: http://www.osdata.com/topic/language/asm/convert.htm

Good luck :)

Klarre Nov 7th, 2005 2:39 PM

Thanks for the link! It took me back on track again.

But...

I got that I should use the cdq instruction to extend the eax to edx. Right?

Am I thinking correct if I try using this rewritten code instead of the old one?

:

_gluLookAt macro A1, A2, A3, A4, A5, A6, A7, A8, A9
        mov eax, A9
        cdq
        push eax
        push edx

        mov eax, A8
        cdq
        push eax
        push edx

        ...

        mov eax, A1
        cdq
        push eax
        push edx

        call gluLookAt
endm


Klarre Nov 7th, 2005 4:12 PM

Problem solved...

iignotus Nov 7th, 2005 6:04 PM

Mind posting the solution to help others?

Klarre Nov 8th, 2005 5:09 AM

I solved it using constants. It is a solution so far. And next step is to use double variables instead, so I can move the camera around in real time.

The original function used
:

void gluLookAt(GLdouble eyeX, GLdouble eyeY, GLdouble eyeZ,
              GLdouble centerX, GLdouble centerY, GLdouble centerZ,
              GLdouble upX, GLdouble upY, GLdouble upZ);


In C++ the code would look like this:
:

double eyez = 45.0;
double upy  = 1.0;

gluLookAt(0, 0, eyez, 0, 0, 0, 0, upy, 0);


Rewritten in assembly it looks like this:
:

_45d0 equ 40468000h  ; eyez
_45d1 equ 0
_1d0  equ 1072693248 ; upy
_1d1  equ 0

;; upx, upy, upz pushed on the stack
push 0
push 0
push _1d0
push _1d1
push 0
push 0

;; centerx, centery, centerz pushed on the stack
push 0
push 0
push 0
push 0
push 0
push 0

;; eyex, eyey, eyez pushed on the stack
push _45d0
push _45d1
push 0
push 0
push 0
push 0

call gluLookAt



All times are GMT -5. The time now is 4:24 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC