Author Topic: How to calculate (using trig) rotation in axe?  (Read 3511 times)

0 Members and 1 Guest are viewing this topic.

Offline c4ooo

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 252
  • Rating: +10/-1
  • The impossible chemical compound.
    • View Profile
How to calculate (using trig) rotation in axe?
« on: March 04, 2015, 07:14:46 am »
i wanted to make a 3d game, but as ime not sure how to use the sin and cos function in axe as they return unexpected values.
How would i go about implementing rotation (for now, if i know haw to rotate round y i can rotate around any thing) around the y axis?
Thank you;
-German Kuznetsov
The impossible chemical compound.

Offline Sorunome

  • Fox Fox Fox Fox Fox Fox Fox!
  • Support Staff
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 7920
  • Rating: +374/-13
  • Derpy Hooves
    • View Profile
    • My website! (You might lose the game)
Re: How to calculate (using trig) rotation in axe?
« Reply #1 on: March 04, 2015, 07:49:22 am »
The sin( and the cos( functions both return values from -127 to +127. The period is from 0 to 256, so if you were to draw a sine curve it starts at 0, crosses the x-axis at 128 and ends again on the x-axis on 256.

THE GAME
Also, check out my website
If OmnomIRC is screwed up, blame me!
Click here to give me an internet!

Offline c4ooo

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 252
  • Rating: +10/-1
  • The impossible chemical compound.
    • View Profile
Re: How to calculate (using trig) rotation in axe?
« Reply #2 on: March 04, 2015, 09:58:01 pm »
The sin( and the cos( functions both return values from -127 to +127. The period is from 0 to 256, so if you were to draw a sine curve it starts at 0, crosses the x-axis at 128 and ends again on the x-axis on 256.

Yes. But if it returns values from -127 to +127, will that mean that I devide the final out put by 127? That's the part I don't get.
if you can provide some code that rotates (x,y) around the z axis that would be nice. (Originally I said y but I ment z)
-German Kuznetsov
The impossible chemical compound.

Offline Sorunome

  • Fox Fox Fox Fox Fox Fox Fox!
  • Support Staff
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 7920
  • Rating: +374/-13
  • Derpy Hooves
    • View Profile
    • My website! (You might lose the game)
Re: How to calculate (using trig) rotation in axe?
« Reply #3 on: March 05, 2015, 07:55:45 am »
According to https://www.siggraph.org/education/materials/HyperGraph/modeling/mod_tran/3drota.htm you have
Code: [Select]
x' = x*cos q - y*sin q
y' = x*sin q + y*cos q
z' = z

so in axe you'd do something like

Code: [Select]
x' = ((x*cos(q)) - (y*sin(q)))/127
y' = ((x*sin(q)) + (y*cos(q)))/127
z' = z

Note that you do not have floating point numbers in axe, so you divide as late as possible

THE GAME
Also, check out my website
If OmnomIRC is screwed up, blame me!
Click here to give me an internet!

Offline c4ooo

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 252
  • Rating: +10/-1
  • The impossible chemical compound.
    • View Profile
Re: How to calculate (using trig) rotation in axe?
« Reply #4 on: March 05, 2015, 01:04:03 pm »
Ok thanks! Going to try it out. Its just that i tried to look at the 3d cube demo program and got confused by the code!
-German Kuznetsov
The impossible chemical compound.

Offline TheMachine02

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 452
  • Rating: +105/-0
  • me = EF99+F41A
    • View Profile
Re: How to calculate (using trig) rotation in axe?
« Reply #5 on: March 05, 2015, 03:59:08 pm »
You also have to take care that you need a signed division (and not the unsigned) wich is //.
As a side note, dividing by 127 is mathematicly correct, but you doesn't want to do that  :P as it is verrry slow. Divide by 128 instead (and btw, the precision loss is almsot nothing)
AXE/asm programmer - unleash the power of z80 //C++//C

epic 3D things http://www.ntu.edu.sg/home/ehchua/programming/opengl/CG_BasicsTheory.html