Sign in to follow this  
Followers 0
malu05

3D Calculations

8 posts in this topic

#1 ·  Posted (edited)

Introduction:

Hello.

Im working on the World Of Warcraft Advanced Machinima Tool but need some help with some of the 3D Calculations i use.

We have the cameras position (X,Y,Z) and rotation (X,Z)

They are defined as: posx1 posy1 posz1

And the target is defined as posx2 posy2 posz2

What i want to do is to have the camera always facing towards the target.

So i need to calculate the Rotaion X and Z for the camera.

In my head that sounds very simple but it does not work that well.

The problem:

The X and Z rotation is not defined in 360degrees.

Both goes from 0 to 6.2833 where 6.2833 is 360

And not only that, the X rotation is counterclockwise while the Z rotation is clockwise

You can see it here:

The main Coord system is mirrored.

And the camera rotation is also mirrored.

Posted Image

Posted Image

Let take a example, here is a little 3D space.

Posted Image

Now to calculate the X rotation i need the X and Y values of both target and camera.

Posted Image

$radToDeg = -180 / $pi
$result = atan(($posy1 - $posy2) / ($posx2 - $posx1)) * $radToDeg
            if $posx2 < $posx1 Then
                if $result < 0 Then
                    $result = 270 + $result
                Else
                    $result = 270 + $result
                EndIf
            EndIf
            if $posx2 >= $posx1 Then
                if $result < 0 Then
                    $result = 90 + $result
                Else
                    $result = 90 + $result
                EndIf
            EndIf
            $result = $result - 360
            $result = (($result + 360 - ($result * 2)) + 180)
                        

                       $RotCalcX = $result /  57.294733659064504320977830121115 ;Scaled down to the 0 to 6.2833 ratiooÝ÷ ØÚ0¶¬¥ªí±ç¦¶Þ×M¢ºÞrÕ¡zx&«¢éݶ­j¸¶Ø^^º-jب+²±º.Ûh¶­j¸´­¶®Z¶*'ÆÛkÉ2J)Üz)ÞyÛh©q©ºV­ì~Û¢ØXjwYêÞË(ë­ª¡×¢§^Â
+ȧ-j åzÆîµúèÊ&y©àë"¶Z(Êân¦)í梭«­¢+Øí
±Õ±ÑI=ÑÑ¥½¸hÄ($$$ÀÌØíÉÍÕ±ÐÈôѸ  ÀÌØíÁ½ÍèÄ´ÀÌØíÁ½ÍhȤ¼ ÀÌØíÁ½ÍàÈ´ÀÌØíÁ½ÍàĤ¤¨ÀÌØíÉQ½($$%¥ÀÌØíÁ½ÍàȱÐìÀÌØíÁ½ÍàÄQ¡¸($$$%¥ÀÌØíÉÍÕ±ÐȱÐìÀQ¡¸($$$$$ÀÌØíÉÍÕ±ÐÈôÈÜÀ¬ÀÌØíÉÍÕ±ÐÈ($$$%±Í($$$$$ÀÌØíÉÍÕ±ÐÈôäÀ´ÀÌØíÉÍÕ±ÐÈ($$$%¹%($$%¹%($$%¥ÀÌØíÁ½ÍàÈÐìôÀÌØíÁ½ÍàÄQ¡¸($$$%¥ÀÌØíÉÍÕ±ÐȱÐìÀQ¡¸($$$$$ÀÌØíÉÍÕ±ÐÈôäÀ¬ÀÌØíÉÍÕ±ÐÈ($$$%±Í($$$$$ÀÌØíÉÍÕ±ÐÈôäÀ¬ÀÌØíÉÍÕ±ÐÈ($$$%¹%($$%¹%(($$$ÀÌØíÉÍÕ±ÐÈôÀÌØíÉÍÕ±ÐÈ´ÌØÀ($$$ÀÌØíÉÍÕ±ÐÈôÀÌØíÉÍÕ±ÐȬ´ÀÌØíÉÍÕ±ÐȬ´ÀÌØíÉÍÕ±ÐÈíQÕɸIÍÕ±ÐѼ±½­Ý¥ÍÉÍÕ±Ð($$$ÀÌØíÉÍÕ±ÐÈôÀÌØíÉÍÕ±ÐȼÔܸÈäÐÜÌÌØÔäÀØÐÔÀÐÌÈÀäÜÜàÌÀÄÈÄÄÄÔ($$$ÀÌØíÉÍÕ±ÐÈôÀÌØíÉÍÕ±ÐȬĸÔÜÀàÈÔ($$%¥ÀÌØíÉÍÕ±ÐÈÐìظÈàÌÌQ¡¸($$$$ÀÌØíÉÍÕ±ÐÈôÀÌØíÉÍÕ±ÐȴظÈàÌÌ($$%¹%($$%¥ÀÌØíÉÍÕ±ÐȱÐìÀQ¡¸($$$$ÀÌØíÉÍÕ±ÐÈôظÈàÌ̬ÀÌØíÉÍÕ±ÐÈ($$%¹%(í
±Õ±ÑI=ÑÑ¥½¸hÈ($$$ÀÌØíÉÍÕ±ÐÌôѸ  ÀÌØíÁ½ÍèÄ´ÀÌØíÁ½ÍhȤ¼ ÀÌØíÁ½ÍäÈ´ÀÌØíÁ½ÍäĤ¤¨ÀÌØíÉQ½($$%¥ÀÌØíÁ½ÍäȱÐìÀÌØíÁ½ÍäÄQ¡¸($$$%¥ÀÌØíÉÍÕ±Ð̱ÐìÀQ¡¸($$$$$ÀÌØíÉÍÕ±ÐÌôÈÜÀ¬ÀÌØíÉÍÕ±ÐÌ($$$%±Í($$$$$ÀÌØíÉÍÕ±ÐÌôäÀ´ÀÌØíÉÍÕ±ÐÌ($$$%¹%($$%¹%($$%¥ÀÌØíÁ½ÍäÈÐìôÀÌØíÁ½ÍäÄQ¡¸($$$%¥ÀÌØíÉÍÕ±Ð̱ÐìÀQ¡¸($$$$$ÀÌØíÉÍÕ±ÐÌôäÀ¬ÀÌØíÉÍÕ±ÐÌ($$$%±Í($$$$$ÀÌØíÉÍÕ±ÐÌôäÀ¬ÀÌØíÉÍÕ±ÐÌ($$$%¹%($$%¹%(($$$ÀÌØíÉÍÕ±ÐÌôÀÌØíÉÍÕ±ÐÌ´ÌØÀ($$$ÀÌØíÉÍÕ±ÐÌôÀÌØíÉÍÕ±Ð̬´ÀÌØíÉÍÕ±Ð̬´ÀÌØíÉÍÕ±ÐÌíQÕɸIÍÕ±ÐѼ±½­Ý¥ÍÉÍÕ±Ð($$$ÀÌØíÉÍÕ±ÐÌôÀÌØíÉÍÕ±Ð̼ÔܸÈäÐÜÌÌØÔäÀØÐÔÀÐÌÈÀäÜÜàÌÀÄÈÄÄÄÔ($$$ÀÌØíÉÍÕ±ÐÌôÀÌØíÉÍÕ±Ð̬ĸÔÜÀàÈÔ($$%¥ÀÌØíÉÍÕ±ÐÌÐìظÈàÌÌQ¡¸($$$$ÀÌØíÉÍÕ±ÐÌôÀÌØíÉÍÕ±Ð̴ظÈàÌÌ($$%¹%($$%¥ÀÌØíÉÍÕ±Ð̱ÐìÀQ¡¸($$$$ÀÌØíÉÍÕ±ÐÌôظÈàÌ̬ÀÌØíÉÍÕ±ÐÌ($$%¹%(($$$ÀÌØíI½Ñ
±hô ÀÌØíÉÍÕ±ÐȼȤ¬ ÀÌØíÉÍÕ±Ð̼Ȥì!½ÜÍ¡½Õ±¤¥¹Ñ¡ÍÈѽѡÈü
Edited by malu05

[center][u]WoW Machinima Tool[/u] (Tool for Machinima Artists) [/center]

Share this post


Link to post
Share on other sites



The X and Z rotation is not defined in 360degrees.

Both goes from 0 to 6.2833 where 6.2833 is 360

And not only that, the X rotation is counterclockwise while the Z rotation is clockwise

6.2833 = 2 pi

See unit circle:

http://en.wikipedia.org/wiki/Unit_circle

Share this post


Link to post
Share on other sites

6.2833 = 2 pi

See unit circle:

http://en.wikipedia.org/wiki/Unit_circle

Ahhh... didnt know that part. ^^

But im still not sure how to calculate the Camera rotation around the X axis

And how the 2 seperate calculations should be joined? (or if it even is 2 calculations)


[center][u]WoW Machinima Tool[/u] (Tool for Machinima Artists) [/center]

Share this post


Link to post
Share on other sites

RotZ:

0° = 0 pi (Horizon)

90° = pi / 2 = ~1.5 (Ground)

180° = pi = 3.14 (Rear Horizon - Upside-down)

270° = 3pi/2 = 4.71 (Sky)

360° = 2pi = 6.28 (Horizon)

Share this post


Link to post
Share on other sites

RotZ:

0° = 0 pi (Horizon)

90° = pi / 2 = ~1.5 (Ground)

180° = pi = 3.14 (Rear Horizon - Upside-down)

270° = 3pi/2 = 4.71 (Sky)

360° = 2pi = 6.28 (Horizon)

I think you miss understand.

Lets say the camera is located at -300 , 200 , 10 and the target is located at -351 , 240 , 11

How do i calculate the rotaion around the X axis?


[center][u]WoW Machinima Tool[/u] (Tool for Machinima Artists) [/center]

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I think you miss understand.

Lets say the camera is located at -300 , 200 , 10 and the target is located at -351 , 240 , 11

How do i calculate the rotaion around the X axis?

No I understand. I am helping you to understand the concept of radians so you can complete your task.

Edited by weaponx

Share this post


Link to post
Share on other sites

No I understand. I am helping you to understand the concept of radians so you can complete your task.

I found this on geocities.

http://www.geocities.com/wronski12/3d_tutor/basics.html

x2-x1                        y2-y1
tg(Yan)= -----  , tg(Zan)= ---------------------------
         z1-z2           sqrt((x2-x1)^2 + (z2-z1)^2)

Where the Yangel matches my calculation but the other calculation also gives a invalid result.


[center][u]WoW Machinima Tool[/u] (Tool for Machinima Artists) [/center]

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Seems like the first calculation i made can be used with some tweak. Tho i still would love a more clean calculation if someone knows how it should be done.

The first calculation devide's X and Y rotation by 2 and multiply them.

There is currently only 4 angels that are corrupt and that is when the X or Y position are close equal

Correct

Cameraposition =    -134.572677612305 .     -8935.6123046875 .  143.96760559082
Target Position =   -172.489761352539 .     -8899.083984375 .   144.477661132813

zx= 6.26973425214815 -      zy= 6.26922292422834
rotation set            = 6.26947858818825

Cameraposition =    -259.972808837891 .     -8795.4580078125 .  166.467803955078
Target Position =   -172.489761352539 .     -8899.083984375 .   144.477661132813

zx= 0.246262596623854 -     zy= 0.209104898862212
rotation set            = 0.227683747743033

In both of these examples the zx and zy are quite close.

WRONG:

Cameraposition =    -172.497985839844 .     -8950.833984375 .   143.96760559082
Target Position =   -172.489761352539 .     -8899.083984375 .   144.477661132813

zx= 4.72851227272154 -      zy= 6.27332948057586
rotation set            = 5.5009208766487

Cameraposition =    -192.866882324219 .     -8900.1630859375 .  150.919052124023
Target Position =   -172.489761352539 .     -8899.083984375 .   144.477661132813

zx= 0.306169381117432 -     zy= 1.40481149256352
rotation set            = 0.855490436840475

In the first example the camX position is within 1 coord of the targetX position, this results in a drop in the zx contra the zy.

In the sec example the camY position is within 2 coord of the targetY position, this results in a drop in the zy contra the zx.

so i guess i got a idea what the problem is.

So the fix was like this:

if _max($posx1,$posx2) - _min($posx1,$posx2) > _max($posy1,$posy2) - _min($posy1,$posy2) Then
    $RotCalcB = $result2 
Else    
    $RotCalcB = $result3 
EndIfoÝ÷ ØÚ0¶«z++mæèm¸§íî9×~vÛ§w}yJayÆ¥réZ¶*'±Ø}êߢ»(ì·ky«(*"zw^vêpØm+)ç¡ü"z·¡×ºÚ"µÍZYÛX^
    ÌÍÜÜÞK ÌÍÜÜÞHHÛZ[    ÌÍÜÜÞK ÌÍÜÜÞH ÝÈÛX^
    ÌÍÜÜÞLK    ÌÍÜÜÞLHHÛZ[   ÌÍÜÜÞLK    ÌÍÜÜÞLH[BBIÌÍÜÝ[H][
    ÌÍÜÜÞHH    ÌÍÜÜÖHÈ
    ÌÍÜÜÞH ÌÍÜÜÞJJH
    ÌÍÜYÑYÂBBZY    ÌÍÜÜÞ  È  ÌÍÜÜÞH[BBBZY   ÌÍÜÝ[   È[BBBBIÌÍÜÝ[HL
È  ÌÍÜÝ[BBBQ[ÙBBBBBIÌÍÜÝ[HLH  ÌÍÜÝ[BBBQ[YBBQ[YBBZY    ÌÍÜÜÞ  ÝÏH   ÌÍÜÜÞH[BBBZY   ÌÍÜÝ[   È[BBBBIÌÍÜÝ[HLH    ÌÍÜÝ[BBBQ[ÙBBBBBIÌÍÜÝ[HL
È  ÌÍÜÝ[BBBQ[YBBQ[YBBIÌÍÜÝ[H   ÌÍÜÝ[HÍBBIÌÍÜÝ[H   ÌÍÜÝ[
ÈIÌÍÜÝ[
ÈIÌÍÜÝ[BBIÌÍÜÝ[H   ÌÍÜÝ[È
ÍÊ    ÌÍÜJJBBBIÌÍÜÝ[H  ÌÍÜÝ[
È
    ÌÍÜKÌBBBZY  ÌÍÜÝ[   ÝÈ
    ÌÍÜJH[BBBIÌÍÜÝ[H ÌÍÜÝ[H
    ÌÍÜJBBBQ[YBBZY   ÌÍÜÝ[   È[BBBIÌÍÜÝ[H
    ÌÍÜJJÉÌÍÜÝ[BBQ[YBBIÌÍÔÝØ[ÐH   ÌÍÜÝ[BQ[ÙBÐØ[Ý[]HÝ][ÛBBIÌÍÜÝ[ÈH][
    ÌÍÜÜÞHH    ÌÍÜÜÖHÈ
    ÌÍÜÜÞLH    ÌÍÜÜÞLJJH
    ÌÍÜYÑYÂBBZY    ÌÍÜÜÞ  È  ÌÍÜÜÞH[BBBZY   ÌÍÜÝ[È È[BBBBIÌÍÜÝ[ÈHL
È  ÌÍÜÝ[ÂBBBQ[ÙBBBBBIÌÍÜÝ[ÈHLH  ÌÍÜÝ[ÂBBBQ[YBBQ[YBBZY  ÌÍÜÜÞ  ÝÏH   ÌÍÜÜÞH[BBBZY   ÌÍÜÝ[È È[BBBBIÌÍÜÝ[ÈHLH  ÌÍÜÝ[ÂBBBQ[ÙBBBBBIÌÍÜÝ[ÈHL
È  ÌÍÜÝ[ÂBBBQ[YBBQ[YBBIÌÍÜÝ[ÈH   ÌÍÜÝ[ÈHÍBBIÌÍÜÝ[ÈH   ÌÍÜÝ[È
ÈIÌÍÜÝ[È
ÈIÌÍÜÝ[ÂBBIÌÍÜÝ[ÈH   ÌÍÜÝ[ÈÈ
ÍÊ    ÌÍÜJJBBBIÌÍÜÝ[ÈH    ÌÍÜÝ[È
È
    ÌÍÜKÌBBBZY  ÌÍÜÝ[È ÝÈ
    ÌÍÜJH[BBBIÌÍÜÝ[ÏH   ÌÍÜÝ[ÈH
    ÌÍÜJBBBQ[YBBZY   ÌÍÜÝ[È È[BBBIÌÍÜÝ[ÏH
    ÌÍÜJJÉÌÍÜÝ[ÂBBQ[YBBIÌÍÔÝØ[ÐH ÌÍÜÝ[ÂBQ[Y
Edited by malu05

[center][u]WoW Machinima Tool[/u] (Tool for Machinima Artists) [/center]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0