Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 7th, 2005, 1:30 PM   #1
Klarre
Game engine designer
 
Klarre's Avatar
 
Join Date: May 2005
Location: Sweden
Posts: 301
Rep Power: 4 Klarre is on a distinguished road
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
Klarre is offline   Reply With Quote
Old Nov 7th, 2005, 1:36 PM   #2
Polyphemus_
Expert Programmer
 
Polyphemus_'s Avatar
 
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4 Polyphemus_ is on a distinguished road
Maybe this page helps: http://www.osdata.com/topic/language/asm/convert.htm

Good luck
Polyphemus_ is offline   Reply With Quote
Old Nov 7th, 2005, 2:39 PM   #3
Klarre
Game engine designer
 
Klarre's Avatar
 
Join Date: May 2005
Location: Sweden
Posts: 301
Rep Power: 4 Klarre is on a distinguished road
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 is offline   Reply With Quote
Old Nov 7th, 2005, 4:12 PM   #4
Klarre
Game engine designer
 
Klarre's Avatar
 
Join Date: May 2005
Location: Sweden
Posts: 301
Rep Power: 4 Klarre is on a distinguished road
Problem solved...
Klarre is offline   Reply With Quote
Old Nov 7th, 2005, 6:04 PM   #5
iignotus
Professional Programmer
 
iignotus's Avatar
 
Join Date: Apr 2005
Location: Nowhere Special
Posts: 466
Rep Power: 4 iignotus is on a distinguished road
Send a message via AIM to iignotus
Mind posting the solution to help others?
__________________
% rc4 hexkey < input > output
#define S ,t=s[i],s[i]=s[j],s[j]=t /* rc4 hexkey <file */
unsigned char k[256],s[256],i,j,t;main(c,v,e)char**v;{++v;while(++i)s[ 
i]=i;for(c=0;*(*v)++;k[c++]=e)sscanf((*v)++-1,"%2x",&e);while(j+=s[i]
+k[i%c]S,++i);for(j=0;c=~getchar();putchar(~c^s[t+=s[i]]))j+=s[++i]S;}
iignotus is offline   Reply With Quote
Old Nov 8th, 2005, 5:09 AM   #6
Klarre
Game engine designer
 
Klarre's Avatar
 
Join Date: May 2005
Location: Sweden
Posts: 301
Rep Power: 4 Klarre is on a distinguished road
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
Klarre is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:28 AM.

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