I need some help translating one line of c++ code.

; fovX = (2 * atan (aspect * tan(fov / 2)))

where fovX, aspect and fov are 32bit floats.
The documentation for FPTAN and FPATAN confuse me.

Thanks in advance,
Homer.
Posted on 2004-01-10 07:30:39 by Homer
EvilHomer2k,
What aspect of the two floating point instructions do you not understand? Ratch


.DATA?

FOVX REAL4 ?

.DATA
TWO REAL4 2.0
FOV REAL4 3.0
ASPECT REAL4 5.0

.CODE
MAIN:
XOR EBP,EBP ;EBP=0

FLD [FOV]
FDIV [TWO]
FPTAN ;tangent function, ST(0)=1.0, ST(1)=tangent
FNSTSW AX ;AX=Floating Point Status Word

AND AX,1 SHL 10 ;check C2 in status word for overflow
.IF !ZERO?
INVOKIT MessageBox,EBP,BYTER('Tangent Function Overflow',0),EBP,EBP
.ENDIF

FXCH ;swap ST(0),ST(1)
FMUL [ASPECT]
FXCH ;swap ST(0),ST(1)
FPATAN ;arctan ST(1)/ST(0) where ST(0)=1.0
FMUL [TWO]
FSTP [FOVX]

END MAIN


 00000000			.DATA?

00000000 00000000 FOVX REAL4 ?

00000000 .DATA
00000000 40000000 TWO REAL4 2.0
00000004 40400000 FOV REAL4 3.0
00000008 40A00000 ASPECT REAL4 5.0

00000000 .CODE
00000000 MAIN:
00000000 33 ED XOR EBP,EBP ;EBP=0

00000002 D9 05 00000004 R FLD [FOV]
00000008 D8 35 00000000 R FDIV [TWO]
0000000E D9 F2 FPTAN ;tangent function, ST(0)=1.0, ST(1)=tangent
00000010 DF E0 FNSTSW AX ;AX=Floating Point Status Word

00000012 66| 25 0400 AND AX,1 SHL 10 ;check C2 in status word for overflow
.IF !ZERO?
INVOKIT MessageBox,EBP,BYTER('Tangent Function Overflow',0),EBP,EBP
0000000C 2 .DATA
0000000C 54 61 6E 67 65 2 ??0019 BYTE 'Tangent Function Overflow',0
6E 74 20 46 75
6E 63 74 69 6F
6E 20 4F 76 65
72 66 6C 6F 77
00
00000018 2 .CODE
00000018 55 4 PUSH EBP
00000019 55 4 PUSH EBP
0000001A 68 0000000C R 4 PUSH OFFSET ??0019
0000001F 55 4 PUSH EBP
00000020 E8 00000000 E 1 CALL MessageBox
.ENDIF

00000025 D9 C9 FXCH ;swap ST(0),ST(1)
00000027 D8 0D 00000008 R FMUL [ASPECT]
0000002D D9 C9 FXCH ;swap ST(0),ST(1)
0000002F D9 F3 FPATAN ;arctan ST(1)/ST(0) where ST(0)=1.0
00000031 D8 0D 00000000 R FMUL [TWO]
00000037 D9 1D 00000000 R FSTP [FOVX]

END MAIN
Posted on 2004-01-10 10:04:55 by Ratch
You may find some of the information usefull in Chap.10 of the following tutorial to understand the code suggested by Ratch.

http://www.masmforum.com/website/tutorials/fptute/index.html

(You may also find other usefull info in that tutorial. If you prefer, you can also download the entire tutorial from the site for offline viewing.)

Raymond
Posted on 2004-01-10 11:50:01 by Raymond