News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Math function

Started by Farabi, July 13, 2005, 02:45:04 PM

Previous topic - Next topic

Farabi

This function will calculate a x,y,z coordinate to 2D screen.




; For commercial purpose please contact me

.data?
VP dword ?
x_res dword ?
y_res dword ?

.code

SetResolution proc width:dword,heigth:dword

push width
pop x_res
push heigth
pop y_res

ret
SetResolution endp

SetViewPoint proc value:dword

push value
pop VP

ret
SetViewPoint endp

To3D proc x:dword,y:dword,z:dword
LOCAL f,g,sx,sy,sz:dword
LOCAL xc,yc:dword
; sx=x*f/z + 1/2 nMaxX
; sy=y*g/z + 1/2 nMaxY
; f=w/tan(a)
; g=h/tan(b)

; Not bad. This function now shorter and faster.

invoke CenterScreen,x_res,y_res
mov xc,edx
mov yc,eax

xor edx,edx
mov eax,x
mov ecx,VP
imul ecx
idiv z
add eax,xc
mov xc,eax

xor edx,edx
mov eax,y
mov ecx,VP
imul ecx
idiv z
add eax,yc
mov yc,eax

mov edx,xc
mov eax,yc



ret
To3D endp
[/end]
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Eóin

I'm curious as to what method you use to map the 3d coordinates to 2d ones? The simplest and fastest method is to simply take the x & y for the coords and z for the depthbuffer. I believe this is what OpenGL does.

Your method would seem to be something like isometric, though with a variable angle or something. What is the a and b mentioned in the comments?

Farabi

Quote from: Eóin on July 13, 2005, 07:54:35 PM
I'm curious as to what method you use to map the 3d coordinates to 2d ones? The simplest and fastest method is to simply take the x & y for the coords and z for the depthbuffer. I believe this is what OpenGL does.

Your method would seem to be something like isometric, though with a variable angle or something. What is the a and b mentioned in the comments?

That value is used to adjust the screen. That value is not used anymore. As you can see x and y is divided by z, if there is no other multiplication the result will be always zero. Get F function is dividing a number with tan value, and since the tan result always above zero and less than 1, dividing it mean multiply it.
Sorry for my lack of english.

Maybe you can made a test on which is fastest, OpenGL plot pixel or my function if you have time. Im not too understand using OpenGL function.

BTW thanks for the response.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

daydreamer

I prefer to first calculate a constant and use RCP instruction on that and MULPS at the same time x and y with that constant
I also think you should use floats instead of ints, or fixed point
because otherwise you have no range inbetween z=1,z=2,z=3
for example you have a point x200,y100,z2, move it in z direction you get pixel without smooth movement, like z=1:point at 200,100, z=2:point at 100,50 etc

Farabi

Quote from: daydreamer on July 14, 2005, 10:59:43 AM
I prefer to first calculate a constant and use RCP instruction on that and MULPS at the same time x and y with that constant
I also think you should use floats instead of ints, or fixed point
because otherwise you have no range inbetween z=1,z=2,z=3
for example you have a point x200,y100,z2, move it in z direction you get pixel without smooth movement, like z=1:point at 200,100, z=2:point at 100,50 etc


Floating point calculation is very slow. Even SSE2 instruction for me is not fast enough. my computer system is damage a month ago and i lost my intel tutorial so i cannot see the explanation about mulps instruction.

But movaps instruction is cool. Very fast on my 1.7 Ghz computer.

here is the sample programming, im still aranged the source code. I cannot provide the source right now.

Quote
Hello,

Thank you for contacting Microsoft Customer Service.

We reviewed your creation, it is very good.  We appreciate your interest to Microsoft.

Are you interested to join the Microsoft work force? If yes, please visit http://members.microsoft.com/careers/default.mspx
It has all the latest career postings and information on how to apply for careers.  It even has a tool that helps you build a quick resume and send it to us.

Should you have other questions or concerns, please feel free to write back.

Thank you,

Margareth
Microsoft Online Customer Service Representative

If Microsoft going to hire me, i will not confused about money anymore and keep everything free.

[attachment deleted by admin]
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Seb

Quote from: Farabi on July 14, 2005, 06:45:27 PM
Quote from: daydreamer on July 14, 2005, 10:59:43 AM
I prefer to first calculate a constant and use RCP instruction on that and MULPS at the same time x and y with that constant
I also think you should use floats instead of ints, or fixed point
because otherwise you have no range inbetween z=1,z=2,z=3
for example you have a point x200,y100,z2, move it in z direction you get pixel without smooth movement, like z=1:point at 200,100, z=2:point at 100,50 etc


Floating point calculation is very slow. Even SSE2 instruction for me is not fast enough. my computer system is damage a month ago and i lost my intel tutorial so i cannot see the explanation about mulps instruction.

But movaps instruction is cool. Very fast on my 1.7 Ghz computer.

here is the sample programming, im still aranged the source code. I cannot provide the source right now.

Quote
Hello,

Thank you for contacting Microsoft Customer Service.

We reviewed your creation, it is very good.  We appreciate your interest to Microsoft.

Are you interested to join the Microsoft work force? If yes, please visit http://members.microsoft.com/careers/default.mspx
It has all the latest career postings and information on how to apply for careers.  It even has a tool that helps you build a quick resume and send it to us.

Should you have other questions or concerns, please feel free to write back.

Thank you,

Margareth
Microsoft Online Customer Service Representative

If Microsoft going to hire me, i will not confused about money anymore and keep everything free.

You sent Microsoft your creation to possibly apply for a job? No offense, but whatever you wrote - Microsoft's programmers can do it twice as good.

Mark Jones

Did you even read the forum captions, Seb?

NO BASHING else you're out of here.

No offense, of course.
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

Seb

Quote from: Mark Jones on July 14, 2005, 08:30:50 PM
Did you even read the forum captions, Seb?

NO BASHING else you're out of here.

No offense, of course.

What? I asked him a simple question and provided my opinion on the whole matter (which actually is a fact). I didn't mean or did bash him.

Edit: Anyway, I'm not gonna start an arguement just because you didn't actually understand what I said. Nice code though Farabi.

BogdanOntanu

Microsoft is just beeing polite...
to get hired there you would have to go through a series of tests that are not your choice
and I bet ASM will not be among them ;) but spoken and understood English will surely be one test.

Besides the money... I see no purpose in getting a job at Microsoft :P
No ASM  EQU no fun ;)


Ambition is a lame excuse for the ones not brave enough to be lazy.
http://www.oby.ro

Farabi

I send them this map. Take a look at microsoft date system, maybe I can do something good. I know how smart MS engineer is, it is an honor to work with them.
I think this is out of topic. So any question more on 3D math programming?
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

Quote from: BogdanOntanu on July 15, 2005, 09:13:40 PM
Microsoft is just beeing polite...
to get hired there you would have to go through a series of tests that are not your choice
and I bet ASM will not be among them ;) but spoken and understood English will surely be one test.

Besides the money... I see no purpose in getting a job at Microsoft :P
No ASM  EQU no fun ;)




I think I will ask them to cooperate if they gonna test me. So I can avoid the test and keep programming.  :bdg
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

This is the screenshot of my map.



This is the screenshot test of my 3D graphics.



I compared it with nehe OpenGL tutorial.




All of the software is tested on 2.8 Ghz machine.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

Use it on anything you like, also if you dont mind, please send me money to pay my dial up connection(no need to send if you dont want to, and just use this if you like).

[attachment deleted by admin]
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"