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



:dazzled: Im working on a bvh reader, I thought it could be simpler but Im stuck. I only have the length value of X,Y,Z and the rotation value and I need to translate the real coordinate by calculating the length using the X,Y,Z rotation value.
Anyone have any information?
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

NightWare

for real, you need to calc the sine and the cosine of the angle (your rotation value), then you multiply them by the length and you have your 2 values for a 2D representation.

for integer, you can use a table to speedup things, example in TURN HER effect in this topic : http://www.masm32.com/board/index.php?topic=10624.0

EDIT :
new X = ( X * Cos(Angle_Rotation) - Y * Sin(Angle_Rotation) )
new Y = ( Y * Cos(Angle_Rotation) + X * Sin(Angle_Rotation) )

Farabi

Quote from: NightWare on July 11, 2009, 02:37:47 AM
for real, you need to calc the sine and the cosine of the angle (your rotation value), then you multiply them by the length and you have your 2 values for a 2D representation.

for integer, you can use a table to speedup things, example in TURN HER effect in this topic : http://www.masm32.com/board/index.php?topic=10624.0

EDIT :
new X = ( X * Cos(Angle_Rotation) - Y * Sin(Angle_Rotation) )
new Y = ( Y * Cos(Angle_Rotation) + X * Sin(Angle_Rotation) )


What about the Z value? I think the z position is changed somehow.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

dedndave

apply the same set of equations again
you can do it in one step, but it is more complex (3rd order equations)

i was trying to simplify it by using the pythagorean theorem
but, you have angles - you have to use trig

Farabi

Quote from: dedndave on July 11, 2009, 05:03:11 AM
apply the same set of equations again
you can do it in one step, but it is more complex (3rd order equations)

i was trying to simplify it by using the pythagorean theorem
but, you have angles - you have to use trig

Z and X pair or Z and Y pair?
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

dedndave

#5
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

Mark Jones

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

NightWare

Quote from: Farabi on July 11, 2009, 04:38:05 AM
What about the Z value? I think the z position is changed somehow.

sorry, your graph was in 2D so i've supposed you wanted to rotate on 1 axis. now if you want to rotate around every axis, you should consider using matrix, because it's possible to reduce the rotations to 1 unique matrix (global rotation matrix), to do that you must multiply the 3 differents matrix. but in reverse order (to obtain A*B matrix, you must multiply B*A). by doing this you will avoid the problems mentionned by dedndave.

rotation around the X axis :
   1,0,0,0
   0,Cos(Angle_X),Sin(Angle_X),0
   0,-Sin(Angle_X),Cos(Angle_X),0
   0,0,0,1

rotation around the Y axis :
   Cos(Angle_Y),0,-Sin(Angle_Y),0
   0,1,0,0
   Sin(Angle_Y),0,Cos(Angle_Y),0
   0,0,0,1

rotation around the Z axis :
   Cos(Angle_Z),Sin(Angle_Z),0,0
   -Sin(Angle_Z),Cos(Angle_Z),0,0
   0,0,1,0
   0,0,0,1

Farabi

I dont understand computation with matrix.
Here is the working formula,

; X=X+(length*(sin( ( (22/7)/180)*RotationY))*-1)
; Y=Y+(length*cos( (22/7)/180)*RotationY))
; Z=Z+(length*(sin( ( (22/7)/180)*RotationX))


With that computation I can move arround the 3D world. But my problem now is how to compute the position of X,Y,Z using the Z degree.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Tedd

Quote from: Farabi on July 15, 2009, 02:46:54 PM
...my problem now is how to compute the position of X,Y,Z using the Z degree.

You still use the same formula, but the X and Y rotations are default values (no rotation) - possibly zero, depending on how you arrange your axes.
No snowflake in an avalanche feels responsible.

Farabi

Quote from: Tedd on July 15, 2009, 03:04:51 PM
Quote from: Farabi on July 15, 2009, 02:46:54 PM
...my problem now is how to compute the position of X,Y,Z using the Z degree.

You still use the same formula, but the X and Y rotations are default values (no rotation) - possibly zero, depending on how you arrange your axes.

Im must be stupid. Can you explain more? Or maybe a "Complete idiot guide" tutorial for this?
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

dedndave

i have never tried the matrix method Farabi
but, i googled "global rotation matrix" (as per NightWare) and found a lot of material
"rotation matrix" also a good google

FORTRANS

Hi,

http://www.cgafaq.info/wiki/Geometry_basics

   That is the Geometry basics page of the comp.graphics.algorithms FAQ.
It has a "How do I rotate a 3D point around an arbitrary axis?" link.

HTH,

Steve N.

NightWare

#13
Quote from: Farabi on July 15, 2009, 02:46:54 PM
I dont understand computation with matrix.

multiplying matrices is quite easy, you just need to multiply the lines of the first matrix by the columns of the second, example :

matrix A :
A, B, C
D, E, F
G, H, I

matrix B :
1, 2, 3
4, 5, 6
7, 8, 9

matrix C (here A*B) :
(A*1)+(B*4)+(C*7), (A*2)+(B*5)+(C*8), (A*3)+(B*6)+(C*9)
(D*1)+(E*4)+(F*7), (D*2)+(E*5)+(F*8), (D*3)+(E*6)+(F*9)
(G*1)+(H*4)+(I*7), (G*2)+(H*5)+(I*8), (G*3)+(H*6)+(I*9)

a sse Code :

; eax = OFFSET of X rotation matrix ) must be 4*4 matrix (even if we only use 3*3)
; ebx = OFFSET of Y rotation matrix )
; ecx = OFFSET of Z rotation matrix )
; edx = OFFSET of the point to calc
movaps XMM0,OWORD PTR [ecx]
movaps XMM1,OWORD PTR [ecx+4*DWORD]
movaps XMM2,OWORD PTR [ecx+8*DWORD]
movaps XMM5,OWORD PTR [eax]
movaps XMM6,OWORD PTR [eax+4*DWORD]
movaps XMM7,OWORD PTR [eax+8*DWORD]
movaps XMM3,XMM0
movaps XMM4,XMM0
shufps XMM0,XMM0,0C0h
shufps XMM3,XMM3,0D5h
shufps XMM4,XMM4,0EAh
mulps XMM0,XMM5
mulps XMM3,XMM6
mulps XMM4,XMM7
addps XMM0,XMM3
addps XMM0,XMM4
movaps XMM3,XMM1
movaps XMM4,XMM1
shufps XMM1,XMM1,0C0h
shufps XMM3,XMM3,0D5h
shufps XMM4,XMM4,0EAh
mulps XMM1,XMM5
mulps XMM3,XMM6
mulps XMM4,XMM7
addps XMM1,XMM3
addps XMM1,XMM4
movaps XMM3,XMM2
movaps XMM4,XMM2
shufps XMM2,XMM2,0C0h
shufps XMM3,XMM3,0D5h
shufps XMM4,XMM4,0EAh
mulps XMM2,XMM5
mulps XMM3,XMM6
mulps XMM4,XMM7
addps XMM2,XMM3
addps XMM2,XMM4
movaps XMM6,OWORD PTR [ebx]
movaps XMM7,OWORD PTR [ebx+4*DWORD]
movaps XMM5,OWORD PTR [ebx+8*DWORD]
movaps XMM3,XMM6
movaps XMM4,XMM6
shufps XMM6,XMM6,0C0h
shufps XMM3,XMM3,0D5h
shufps XMM4,XMM4,0EAh
mulps XMM6,XMM0
mulps XMM3,XMM1
mulps XMM4,XMM2
addps XMM6,XMM3
addps XMM6,XMM4
movaps XMM3,XMM7
movaps XMM4,XMM7
shufps XMM7,XMM7,0C0h
shufps XMM3,XMM3,0D5h
shufps XMM4,XMM4,0EAh
mulps XMM7,XMM0
mulps XMM3,XMM1
mulps XMM4,XMM2
addps XMM7,XMM3
addps XMM7,XMM4
movaps XMM3,XMM5
movaps XMM4,XMM5
shufps XMM5,XMM5,0C0h
shufps XMM3,XMM3,0D5h
shufps XMM4,XMM4,0EAh
mulps XMM5,XMM0
mulps XMM3,XMM1
mulps XMM4,XMM2
addps XMM4,XMM5
addps XMM4,XMM3
; here, the global rotation matrix is in XMM6, XMM7 and XMM4


;
; here, we transpose the global rotation matrix (in XMM6, XMM7 et XMM4) to increase speed calc after...
;
movaps XMM5,XMM6
movlhps XMM5,XMM7
movhlps XMM7,XMM6
movaps XMM6,XMM5
shufps XMM5,XMM4,0C8h
shufps XMM6,XMM4,0DDh
shufps XMM7,XMM4,0E8h
; here, the global rotation matrix is in XMM5, XMM6 and XMM7


;
; here, we calc a simple point (with our matrix in XMM5, XMM6 and XMM7)
; after the global matrix is calculated, you just need to repeat this operation for every points
;
movaps XMM0,OWORD PTR [edx]
movaps XMM1,XMM0
movaps XMM2,XMM0
shufps XMM0,XMM0,000h
shufps XMM1,XMM1,055h
shufps XMM2,XMM2,0AAh
mulps XMM0,XMM5
mulps XMM1,XMM6
mulps XMM2,XMM7
addps XMM0,XMM1
addps XMM0,XMM2
; here, XMM0 = _,newZ,newY,newX


it can appear a lot of work, but matrices have a lot of advantages, for example, you can calc the reflection/refraction (R) by just multiply the global matrix by the R matrix.

EDIT : oops a small error in the code, corrected.

Farabi

NightWare:
:U I will studying it. I think I got it.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"