News:

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

How to compute this?

Started by Farabi, July 11, 2009, 02:10:05 AM

Previous topic - Next topic

Farabi

Quote from: dedndave on July 11, 2009, 09:51:34 AM
i think you can do it however you like - the result will be the same

NightWare's equations should read:
(eq.1) new X = X * Cos(Z_Axis_Rotation) - Y * Sin(Z_Axis_Rotation)
(eq.2) new Y = Y * Cos(Z_Axis_Rotation) + X * Sin(Z_Axis_Rotation)

then:
(eq.3) new X = X * Cos(Y_Axis_Rotation) - Z * Sin(Y_Axis_Rotation)
(eq.4) new Z = Z * Cos(Y_Axis_Rotation) + X * Sin(Y_Axis_Rotation)

and
(eq.5) new Z = Z * Cos(X_Axis_Rotation) - Y * Sin(X_Axis_Rotation)
(eq.6) new Y = Y * Cos(X_Axis_Rotation) + Z * Sin(X_Axis_Rotation)

if you perform them in that order, you may eliminate eq.4 and eq.5, as you do not care about the Z displacement
so:
(eq.1) new X = X * Cos(Z_Axis_Rotation) - Y * Sin(Z_Axis_Rotation)
(eq.2) new Y = Y * Cos(Z_Axis_Rotation) + X * Sin(Z_Axis_Rotation)
(eq.3) new X = X * Cos(Y_Axis_Rotation) - Z * Sin(Y_Axis_Rotation)
(eq.4) new Y = Y * Cos(X_Axis_Rotation) + Z * Sin(X_Axis_Rotation)

EDIT
the value  for X in eq.3 is dependant on the result from eq.1
so, do them seperately
you can do them at once, but the equation becomes more complex
in code, this is going to be the fastest, anyways

Im curious about this equation.
I tryed to translate that equation to MASM code, here is mine:

push eax
;(eq.1) new X = X * Cos(Z_Axis_Rotation) - Y * Sin(Z_Axis_Rotation)
;(eq.2) new Y = Y * Cos(Z_Axis_Rotation) + X * Sin(Z_Axis_Rotation)
fldpi
fdiv CFLT(180.0)
fmul rotZ
fcos
fmul CFLT(0.1)

fldpi
fdiv CFLT(180.0)
fmul rotZ
fsin
fmul CFLT(0.1)
fsubr st(0),st(1)
fstp dfx
fstp dword ptr[esp]

fldpi
fdiv CFLT(180.0)
fmul rotZ
fcos
fmul CFLT(0.1)

fldpi
fdiv CFLT(180.0)
fmul rotZ
fsin
fmul CFLT(0.1)
fadd st(0),st(1)
fstp dfy
fstp dword ptr[esp]

;(eq.3) new X = X * Cos(Y_Axis_Rotation) - Z * Sin(Y_Axis_Rotation)
;(eq.4) new Z = Z * Cos(Y_Axis_Rotation) + X * Sin(Y_Axis_Rotation)
fldpi
fdiv CFLT(180.0)
fmul rotY
fcos
fmul dfx

fldpi
fdiv CFLT(180.0)
fmul rotY
fsin
fmul CFLT(0.1)
fsubr st(0),st(1)
fstp dfx
fstp dword ptr[esp]

fldpi
fdiv CFLT(180.0)
fmul rotY
fcos
fmul CFLT(0.1)

fldpi
fdiv CFLT(180.0)
fmul rotY
fsin
fmul dfx
fadd st(0),st(1)
fstp dfz
fstp dword ptr[esp]

; (eq.5) new Z = Z * Cos(X_Axis_Rotation) - Y * Sin(X_Axis_Rotation)
; (eq.6) new Y = Y * Cos(X_Axis_Rotation) + Z * Sin(X_Axis_Rotation)
fldpi
fdiv CFLT(180.0)
fmul rotX
fcos
fmul dfz

fldpi
fdiv CFLT(180.0)
fmul rotX
fsin
fmul dfy
fsubr st(0),st(1)
fstp dfz
fstp dword ptr[esp]

fldpi
fdiv CFLT(180.0)
fmul rotX
fcos
fmul dfy

fldpi
fdiv CFLT(180.0)
fmul rotX
fsin
fmul dfz
fadd st(0),st(1)
fstp dfy
fstp dword ptr[esp]
pop eax

fld dfx
fadd posX
fstp posX

fld dfy
fadd posY
fstp posY

fld dfz
fadd posZ
fstp posZ


But it was wrong, I wonder where is my mistake.
I uploaded my project for you to take a look.
Sorry for this, Im really stupid at math.


[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"

chrisw

Hi Farabi,

if you do some 3D graphics, you should definitely read about homogenous coordinates and the possible transformations with these. Rotation, scaling, perspective distortion or 2D projection are very easy to calculate using homogenous coordinates and the related transformation matrices. Since all  these operations are linear, you can combine all of the above transformations and more into one single matrix and calculate e.g. a rotation and a succeding translation together with the perspective distortion in one single matrix operation.

The english wikipedia article is to be found here: http://en.wikipedia.org/wiki/Homogeneous_coordinates.
Some very useful examples of transformation matrices are found in the german version of the article http://de.wikipedia.org/wiki/Homogene_Koordinaten, which you may understand even without speaking german.

Regards,
Christian


dedndave

#17
that is an awful lot of "F" instructions - lol
even if it works, it would be slow, and you'll be looking for a faster method

NightWare has the right idea - using matrices will be much faster
http://www.masm32.com/board/index.php?topic=11817.msg89927#msg89927

Farabi, my friend
if you want to write games - you are going to want to learn matrices
this math will be the basis of much of your code

matrix explained...
http://en.wikipedia.org/wiki/Matrix_(mathematics)

Euler angles
http://en.wikipedia.org/wiki/Euler_angles

they even have a cool animated gif - lol

FORTRANS

Hi,

   I second Christian's suggestion about homogeneous coordinates.  Once
you get it debugged, it's very convenient and powerful.  It may take
a bit of study to understand them, but it is well worth the effort.

Steve N.

Farabi

Quote from: chrisw on July 16, 2009, 08:46:53 AM
Hi Farabi,

if you do some 3D graphics, you should definitely read about homogenous coordinates and the possible transformations with these. Rotation, scaling, perspective distortion or 2D projection are very easy to calculate using homogenous coordinates and the related transformation matrices. Since all  these operations are linear, you can combine all of the above transformations and more into one single matrix and calculate e.g. a rotation and a succeding translation together with the perspective distortion in one single matrix operation.

The english wikipedia article is to be found here: http://en.wikipedia.org/wiki/Homogeneous_coordinates.
Some very useful examples of transformation matrices are found in the german version of the article http://de.wikipedia.org/wiki/Homogene_Koordinaten, which you may understand even without speaking german.

Regards,
Christian



Zhees, dont you know Im blind at math symbol?  :green
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

Any code donation for this anyone? I even dreaming this formula when Im sleep.
At least a binary form I can debug?
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

dancho

Maybe this links could help you,( because it's seems to me that you have problems with some basic 3d math background )

3D Geometry Primer: Chapter 1 by Bram de Greve - http://www.flipcode.com/archives/3D_Geometry_Primer_Chapter_1-Introduction.shtml
3D Geometry Primer: Chapter 2 by Bram de Greve - http://www.flipcode.com/archives/3D_Geometry_Primer_Chapter_2-Issue_01_Appendix.shtml
3D Maths for CG - http://www.lighthouse3d.com/opengl/maths/