Malicondi Malicondi loading

Coding3dnow wrote:

ok but how do I rotate that cube by the x y and z axis
Because this was brought back up, I felt that I should answer this and it's quite simple, it just uses a little trigonometry. The formula to rotate around the y axis(left right) is this:

x' = (x * cos of (y dir)) - (z * sin of (y dir))
z' = (x * sin of (y dir)) + (z * cos of (y dir))

for the x axis (up down) it's this:

y' = (y * cos of (x dir)) - (z * sin of (x dir))
z' = (y * sin of (x dir)) + (z * cos of (x dir))

and for the z axis (imagine turning your head to the side) it's this:

x' = (x * cos of (z dir)) - (y * sin of (z dir))
y' = (x * sin of (z dir)) + (y * cos of (z dir))

For these, its best to use a custom block to store the original x, y, and z values or this won't work, as x', y', and z' all stand for the changed variables, but the formulas depend on the original values.

For 3d projects, since sin and cos are computationally expensive, using sin and cos in all of these formulas a total of 12 times for a single object is very slow. So i recommend first getting the cos and sin values at the start of every tick before you any formulas to speed this up greatly, like so: (directions will also need variables)
define calc trig
set [cosX v] to ([cos v] of (x dir))
set [sinX v] to ([sin v] of (x dir))
set [cosY v] to ([cos v] of (y dir))
set [sinY v] to ([sin v] of (y dir))
set [cosZ v] to ([cos v] of (z dir))
set [sinZ v] to ([sin v] of (z dir))
in scratch blocks the way to use these formulas will be as so: (i will be using cos and sin variables for this)

for y rotation (left right):
set [x v] to (((x) * (cosY)) - ((z) * (sinY
set [z v] to (((x) * (sinY)) - ((z) * (sinY
for x rotation (up down):
set [y v] to (((y) * (cosX)) - ((z) * (sinX
set [z v] to (((y) * (sinX)) - ((z) * (sinX
for z rotation (turning head to side):
set [x v] to (((x) * (cosZ)) - ((y) * (sinZ
set [y v] to (((x) * (sinZ)) - ((y) * (sinZ
If you want a little more explanation, see this tutorial.
Hope this helps!