I’m a 3D newbie and I used the AXECUBE example to get x and y rotations working independently, but I can’t figure out how to chain them together in axe syntax and I’m not sure what I’m doing wrong. If anybody could point me in the right direction or give me an example program with composite rotations it would be greatly appreciated.
Techno wrote:
I’m a 3D newbie and I used the AXECUBE example to get x and y rotations working independently, but I can’t figure out how to chain them together in axe syntax and I’m not sure what I’m doing wrong. If anybody could point me in the right direction or give me an example program with composite rotations it would be greatly appreciated.

What do you mean by "chain them together" exactly? do you mean applying the rotations to the model vertices? (P.S. if you could post example code with your questions so we know the context that would make it easier to diagnose and fix.)
Thanks for replying so quickly, the code below contains two independent rotations that were taken from the AXECUBE example, just in a form I found easier to read. I could only get them to work on their own. By "chain them together" I mean I want to be able to rotate the vertices of the cube in two axes at once, if that makes sense.

SourceCoder 3 (AXECUBE) wrote:
:.CUBE
:[F7F7F7F7F708]->GDB1
:[F7F7F7F708F7]
:[F7F7F708F7F7]
:[F70808F708F7]
:[F70808F7F708]
:[F70808080808]
:[08F70808F7F7]
:[08F708080808]
:[08F708F7F708]
:[0808F7080808]
:[0808F708F7F7]
:[0808F7F708F7]
:
:0->theta
:0->T
:DiagnosticOff
:Repeat getKey(15)
: theta+1->theta
: . T+1->T
: ClrDraw
: sin(theta)->S
: cos(theta)->C
: sin(theta)->M
: cos(theta)->N
:
: For(A,0,11)
: A*6+GDB1->B
:
: .X ROTATION
: sign{B+1)->G
: sign{B+2)->Z
: . y' = y * cos(angle) - z * sin(angle);
: G*N-(Z*M)->Y
: . z' = z * cos(angle) + y * sin(angle);
: Z*N+(G*M)->Z
: sign{B)*128->X
:
: sign{B+4)->G
: sign{B+5)->W
: . y' = y * cos(angle) - z * sin(angle);
: G*N-(W*M)->V
: . z' = z * cos(angle) + y * sin(angle);
: W*N+(G*M)->W
: sign{B+3)*128->U
:
: .Y ROTATION
: sign{B)->G
: sign{B+2)->Z
: . x' = x * cos(angle) + z * sin(angle);
: G*C+(Z*S)->X
: . z' = z * cos(angle) - x * sin(angle);
: Z*C-(G*S)->Z
: sign{B+1)*128->Y
:
: sign{B+3)->G
: sign{B+5)->W
: . x' = x * cos(angle) + z * sin(angle);
: G*C+(W*S)->U
: . z' = z * cos(angle) - x * sin(angle);
: W*C-(G*S)->W
: sign{B+4)*128->V
:
: Z+4500/64->Z
: W+4500/64->W
: Line(X//Z+48,Y//Z+32,U//W+48,V//W+32)
: End
: DispGraph
:End
Looks like you are using 2d rotations on 2 different axes.

You can do a 3d rotation: https://en.wikipedia.org/wiki/Rotation_formalisms_in_three_dimensions
I am using the 3D rotation equations for x:
y' = y * cos(angle) - z * sin(angle)
z' = z * cos(angle) + y * sin(angle)
x' = x
And for y:
x' = x * cos(angle) + z * sin(angle)
z' = z * cos(angle) - x * sin(angle)
y' = y
I think then to chain then together, you would actually need to do the Y rotation on the output of the X rotation. So when doing the Y rotation, instead of pulling G, Z, etc. from B, use the result of the X rotation's calculation for the input.

Sorry, I don't know Axe syntax, so just going by what think I see happening.
I switched to using composite rotation by multiplying the X and Y rotation matrices and using them together to transform the vertices, but it produces the same output of random spinning lines.

SourceCoder 3 (AXECUBE) wrote:
:.CUBE
:[F7F7F7F7F708]->GDB1
:[F7F7F7F708F7]
:[F7F7F708F7F7]
:[F70808F708F7]
:[F70808F7F708]
:[F70808080808]
:[08F70808F7F7]
:[08F708080808]
:[08F708F7F708]
:[0808F7080808]
:[0808F708F7F7]
:[0808F7F708F7]
:
:0->theta
:0->T
:DiagnosticOff
:Repeat getKey(15)
: T+1->T
: . T+1->T
: ClrDraw
: sin(theta)->S
: cos(theta)->C
: sin(T)->M
: cos(T)->N
:
: For(A,0,11)
: A*6+GDB1->B
:
: . Rotation
: sign{B)->J
: sign{B+1)->G
: sign{B+2)->I
: . G is a placeholder for y
: . J is a placeholder for x
: . I is a placeholder for z
: . x' = cosBX + sinB * sinaY + sinB * cosaZ;
: (N*J)+(M*M*G)+(M*N*I)->X
: . y' = cosaY - sinaZ
: G*N-(I*M)->Y
: . z' = -sinBX + cosB * sinaY + cosB * cosaZ
: (-1*M*J)+(N*M*G)+(N*N*I)->Z
:
: sign{B+3)->J
: sign{B+4)->G
: sign{B+5)->R
: . G is a placeholder for y
: . J is a placeholder for x
: . R is a placeholder for w(which is z of the second vertex)
: . x' = cosBX + sinB * sinaY + sinB * cosaZ;
: (N*J)+(M*M*G)+(M*N*R)->U
: . y' = cosaY - sinaZ
: G*N-(R*M)->V
: . z' = -sinBX + cosB * sinaY + cosB * cosaZ
: (-1*M*J)+(N*M*G)+(N*N*R)->W
:
: Z+4500/64->Z
: W+4500/64->W
: Line(X//Z+48,Y//Z+32,U//W+48,V//W+32)
: End
: DispGraph
:End
I got the rotation code to work but I'm having trouble with precision as my cube keeps wiggling:

SourceCoder 3 (AXECUBE) wrote:
:.CUBE
:[F7F7F7F7F708]->GDB1
:[F7F7F7F708F7]
:[F7F7F708F7F7]
:[F70808F708F7]
:[F70808F7F708]
:[F70808080808]
:[08F70808F7F7]
:[08F708080808]
:[08F708F7F708]
:[0808F7080808]
:[0808F708F7F7]
:[0808F7F708F7]
:
:0->theta
:0->T
:DiagnosticOff
:FnOn
:Repeat getKey(15)
: theta+1->theta
: T+1->T
: ClrDraw
: sin(theta)->S
: cos(theta)->C
: sin(T)->M
: cos(T)->N
:
: For(A,0,11)
: A*6+GDB1->B
: sign{B}->X->G
: sign{B+1}->Y->O
: sign{B+2}->Z->R
: sign{B+3}->U->P
: sign{B+4}->V->F
: sign{B+5}->W->J
:
: . ----\-X ROTATION----\-
: . G acts as a placeholder for the Y variable, since we're performing operations on the actual Y variable and it cannot change.
: . y' = y * cos(angle) - z * sin(angle);
: O*N-(Z*M)->Y//31->Y
: . z' = z * cos(angle) + y * sin(angle);
: Z*N+(O*M)->Z//31->Z
: X*4->X
:
: . y' = y * cos(angle) - z * sin(angle);
: F*N-(J*M)->V//31->V
: . z' = z * cos(angle) + y * sin(angle);
: J*N+(F*M)->W//31->W
: U*4->U
:
: . ----\-Y ROTATION----\-
: . G acts as a placeholder for the X variable, since we're performing operations on the actual X variable and should change.
: . x' = x * cos(angle) + z * sin(angle);
: X->G
: G*C+(Z*S)->X//31->X
: . z' = z * cos(angle) - x * sin(angle);
: Z*C-(G*S)->Z//31->Z
: Y*4->Y
:
: U->G
: . x' = x * cos(angle) + z * sin(angle);
: G*C+(W*S)->U//31->U
: . z' = z * cos(angle) - x * sin(angle);
: W*C-(G*S)->W//31->W
: V*4->V
:
: ...
: If V>=127
: Disp 5
: End
: ...
:
: Z+700/64->Z
: W+700/64->W
: Line(X//Z+48,Y//Z+32,U//W+48,V//W+32)
: End
: DispGraph
:End
It's probably the division that's wriggling. I just don't know how to fix it.
try always rounding down the last 4 bits.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement