#Making a cube rotate on two axes

368 messages · Page 1 of 1 (latest)

harsh shell
#

I'm trying to make a cube rotate on two different axes (the ones shown in the videos) and I think I've figured out how I should do it but actually pulling it off is the difficult part.

#

when the xs on the top reach the points marked in red the crosses on the bottom should be fully extended on the y axis. When the crosses on the top reach the points marked in blue the crosses on the bottom should go towards the blue line but still keep their x movement.

#

The xs on the bottom control the rotation shown in the first clip and the xs on the top control the rotation shown in the second clip.

harsh shell
near jacinth
#

the issue is getting matrices to work in gd

harsh shell
blazing herald
#

I want to learn projections for gd levels now. But havent taken linear algebra since 2020 . Kind of forgotten most of it

harsh shell
#

Alright lmk if you find anything ^^

blazing herald
#

What you want to do is find the desired rotation matrix and then multiply it by that [100/010] matrix and the coords of your pt. Then you will get a point in gds xy plane

#

Then you will have expressions with sin and cos t of course. So you'll want to be somewhat clever use of follow triggers and rotations to figure out how to move the point

#

Hope it helps! It honestly doesn't seem too hard :) since you can add movements by putting two move triggers simultaneously

harsh shell
#

That's way beyond my knowledge but I'll see if I can pull it off somehow

blazing herald
#

If you want I or someone else can help, if you give the desired axis of rotation

#

I can't for another hour or so since I'm away from my computer

harsh shell
#

The rotation that I want to make is basically just that the red and green axes have their rotation linked together wile the blue axis is stuck at 0

blazing herald
#

Oh, okay

#

That's very easy, just multiply the three rotation matrices

harsh shell
#

okay but how would I get rotation matrices into gd?

blazing herald
#

No, you don't

#

The idea is to describe the movement of the points okay?

#

Then you can use those descriptions to use normal triggers to move the points

#

I'm sure someone smarter than me could make an automated tool for this. But this is very doable just by hand

harsh shell
#

That really doesn't make sense to me, I have no knowledge of how linear algebra works so using that method would be hell for me

blazing herald
#

I'll do it for you and sent you a copy :)

#

But, ill be like, 45 minutes sry !

#

im away from my computer rn and it might take a while

harsh shell
#

Alright, I'm not in a rush so there's no need to worry

blazing herald
#

👌

blazing herald
harsh shell
#

what?

blazing herald
#

Red first then green then blue?

harsh shell
#

no red and green at the same time

#

blue stays at 0

blazing herald
#

So blue doesn't do anything?

harsh shell
#

yeah

blazing herald
#

There's a difference, think about if you have a die and you rotate it left then up

#

That's different than rotating up then left

harsh shell
#

Yeah but you can rotate up and left at the same time

#

which is what I'm trying to do

blazing herald
#

Oh, okay. I think ik what you mean

blazing herald
#

hey ! i am back and have expressions for all the points. now just to put them in GD :) could take me half an hour to an hour, i estimate.

#

@harsh shell distance between vertices of cube?

#

oh nvm i see it, 4 grid spaces

blazing herald
#

@harsh shell 98151922

#

I made it 3x3x3 for ease; if you want 4x4x4 move group two 5 mini-spaces(1/3 grid space) to the right, and move group three 5 mini-spaces(1/3 grid space) up

#

hope this helps!

#

(and of course adjust the vertices to 4x4 as well)

harsh shell
#

sorry I was gone for a bit

#

I was more so looking for a method that I could use rather than just a copy of it

#

I'm not doing this for a level, I'm just doing it for the experience

blazing herald
#

Well, generate the rotation matrix and then multiply it by the coords of the cube for an expression for each point. Then use follow triggers and basic trig knowledge to move each point

harsh shell
blazing herald
harsh shell
#

Some of it, yes

blazing herald
#

Okay, the linear algebra is really simple (just arithmetic, really). Just google the rotation matrix you want

#

(you can find general rotation matrix about your desired axis in some amount of degrees. Just set that amount to variable t)

#

Then you take only the first two rows of your rotation matrix. That's a 3x2 matrix

#

Then you multiply that by the coordinates of your point! Then you will get a 2x1 matrix where top is your desired x position and bottom is desired y position

#

Does it make sense?

#

In your example, the axis of rotation was the vector (1,1,1). Which is from the origin (bottom left of cube) to that point (top right of cube)

#

Then you make that into a unit vector. To do that, divide it by its magnitude (in this case sqrt 3) to get axis

harsh shell
#

This is way more advanced than anything I've done in my math courses

blazing herald
#

You'll be fine

#

It's really easy to multiply a matrix

harsh shell
#

I might give it a shot tomorrow

blazing herald
#

Go for it! It's pretty fun

#

I'm happy I did it. Now I am confident I can do stuff like that rotating moai face spu7nix made which went viral

near jacinth
#

i've always wondered ab that

#

bc there doesnt seem to be any simple or intuitive way to translate matrix multiplication to gd stuff using like, move or follow triggers

#

now if we had an area follow trigger that might change things

blazing herald
#

i did all the algebra outside of gd, just got expressions for the position of each point

#

so, then it's pretty easy at least with a rotation, since the movement is just sums of sinusoids. which can be done with the follow trigger following a rotating object

near jacinth
blazing herald
#

inside of gd you could make a calculator for a matrix multiplication, since i believe one of the new triggers lets u multiply pickups, but that's so much work for no reason. and you can't put a counter value into the follow trigger anyway

#

probably could do it in SPWN but i havent fully learned that yet. but if you have something much more complex than a cube rotating about some weird axis you wouldn't want to do everything by hand

near jacinth
#

yeahh

idle grotto
#

Thank you so much @harsh shell !!!! I'm reading this I'l reading this and I will give you more news

harsh shell
#

You should thank eel, he did basically all of the work lol

idle grotto
#

I haven't seen the matrix for now. But supposedly I should see them this year.

blazing herald
harsh shell
#

I could not have done anything with that link without your help though

idle grotto
#

But I knew Math could really help. Btw I know pretty well vectors and imaginary numbers. Is there a way to explain what you did with this ?

blazing herald
#

Oh nice!

idle grotto
#

Wow the amount of triggers there is absolutely nothing!! So basically the rotate 2 is one axis and the rotate 3 is the other one ?

blazing herald
#

So if an object follows the x position of 2, that's the same as moving the x position of the object like the cos t function

#

And if it follows the x position of 3, that's the same as -sin t

#

Similarly following y position of 2 is like the sin t, and y position of 3 is like cos t

idle grotto
#

Ok but how do I choose a rotation amont on each axis ?

#

Aka I want to choose my t for each individual axis

blazing herald
#

I'm not sure what you mean, but say I have the point and it needs to move following (x,y) = (cos t + √3 sin t, 2 sin t)

#

Then it would follow 2 with 1 mod x and 2 mod y, and follow 3 with -√3 mod x and 0 mod y

near jacinth
#

holy shit yall are nerding out

blazing herald
#

Not as much as my dad who's a mathematician and saw what I did and was like couldn't you have done this with quaternions

near jacinth
#

tbf how would one represent complex or hypercomplex numbers in gd

blazing herald
#

Idk, I feel like after you simplify it to what gd could understand you'd have to get the same result

idle grotto
#

So basically I would like to move the cube auround both axis independently using player inputs. I am done with plyer inputs and now I just need the 3d cube working.

blazing herald
idle grotto
idle grotto
blazing herald
#

What it sounds like is either you can move one basic axis at a time (very easy) or you are trying to be able to rotate the axis around (hard)

#

If you just want to rotate along the x y or z axis it is much simpler than rotating around <1,1,1> which is what was done here

blazing herald
#

Okay, I am pretty sure there are like YouTube tutorials or something in that case

idle grotto
#

Yes ok but

  • I still haven't learned about matrix :(
  • is it possible to rotate a certain amount around x axis and then from the position in wich is the cube, rotate it around the y axis and eventually repeat.
  • I know I'm not very clear but I try.
blazing herald
#

If it's a fixed amount definitely, if it's continuous amount if it's possible would require some creativity

#

You know, it could actually be possible if you use scale trigger to adjust your unit circle accordingly

idle grotto
blazing herald
#

I'm not sure. I'll try to create this tomorrow, I can't play gd today

idle grotto
blazing herald
#

this is somewhat exciting for me

#

Anyway, go through that link that EkPek sent, it will explain how to use a rotation matrix

idle grotto
#

I totally understand. And if you manage to do it, this would be a great help for my project!

blazing herald
#

You hit the coords of the point with the rotation matrix and the projection matrix to find the coords of the projected point =)

idle grotto
#

The issue is to know the coords of the point after you did a first rotation.

blazing herald
#

Oh, that will depend on the angle of rotation

#

So, you hit the original coords with the rotation matrix, which depends on the angle

#

Thats the new coords

idle grotto
#

Yes this is the idea. Now how do you automate this in gd ?

blazing herald
#

Well, your expression for the coords will depend on time. Something like x = 1/2 sin t, y = 2 cos t

#

Then you can use the follow triggers how I described to set it up

idle grotto
#

So is is not specific

blazing herald
#

What I did in my example level was just rotate it at a continuous rate, but it's flexible

idle grotto
#

Ok I see

blazing herald
#

Oh, nice!

idle grotto
blazing herald
#

Ik what you mean

#

It will be very tedious but I believe it is possible

#

I'll make it tomorrow. My idea is to use scale triggers with the sine easing modes to do this. You need a more complicated matrix but it should be manageable

idle grotto
#

One axis is so damn easy compared to this. But two axis is the minimal required to my project. No matter what axis. (Except the axis that is perpendicular to the screen, that would be too easy)

blazing herald
#

It's now two variables, you will get stuff like sin u cos v in your positions

idle grotto
blazing herald
#

there are probably several ways to doit you could give it a shot as well

idle grotto
#

So basically we would have one function of u (wich images are (x,y) coords) for x axis and one function of v for the y axis. And the we will have to find a way to recreate those functions in gd and be able to use them both no matter the order and the starting values of u and v. Yeah...

blazing herald
blazing herald
idle grotto
#

Yes of course it is for each point...

#

Hopefully we only have 6 of them (for now).

#

Also I saw that there is a lot of new stuff in the move and rotate trigger. Maybe this could be useful.

blazing herald
#

Yep, although you could do any points a cube is easiest

#

The more I think about it the easier it seems to do.. hope I will be able to explain what I did though

idle grotto
idle grotto
#

Not the math pert I think this should be the easiest. But the implementation part.

blazing herald
blazing herald
#

never mind, it doesn't work

#

i have another idea, but it will be very difficult...

idle grotto
#

Wait a minute. I already know the function we need scince I already did it for a python 3d cube. It is a math function that takes as input 3d coords and 2 axis camera rot and returns 2d coords. I just have to plug the 3d coords to each of the 6 corners and we are done !

#

Except I don't have my computer right here but you can find it on scratch (this is where I found it)

blazing herald
#

Nice!

#

i also have figured out a way to do it. let's both do it and compare =)

idle grotto
#

Yes but you'll have to wait a few days...

idle grotto
#

How do you multiply cos(something) and cos(something else) in geometry dash ?

#

Also could you give me the equation you used ? Because mine is a bit long and maybe not the best

idle grotto
#

@blazing herald please give me your math

blazing herald
idle grotto
#

Ah yes...

#

So the issue is that we can add some sin and cos by simply stacking follows but it is harder to multiply

#

a and b are the angles ? And this is the formula for which corner of the cube ?

blazing herald
#

this is how you multiply two cosines

idle grotto
#

Oh ok

blazing herald
#

wait nvm...

#

i got identity wrong

idle grotto
#

But I wanted your formula for the (x,y) coords

blazing herald
#

it's cos(a)*cos(b) = 1/2 (cos(a+b)+cos(a-b))

blazing herald
idle grotto
blazing herald
#

anyway, you have a point, and say you want to rotate it around the y axis, you multiply it by this matrix

#

but then what ends up happening to the position of each point is that it gets multiplied by many matrices, after many rotations. and then you get increasingly complicated expressions, you can't program them into gd

idle grotto
#

Yes I see. I will give you the formula I found on internet (that one on scratch)

blazing herald
#

so what my idea was is to figure out the maximum and minimum x values for each point, which depends on height, and point will always move in sine shape

#

and also to figure out maximum and minimum y values, which would depend on the x value of the point

#

but i haven't really tried it out yet

idle grotto
#

I think there is a simpler way. I will show you. Just wait so I get to my computer

blazing herald
#

Ok

idle grotto
#

•2Dx = (cos(xrot)*x + sin(xrot)*z) * scale/(sin(yrot)*y + cos(yrot) * (cos(yrot)*z - sin(xrot)*x) +300
•2Dy = (cos(yrot)*y - (sin(yrot) * (cos(xrot)*z - sin(xrot)*x))) * (scale/(sin(yrot)y + cos(yrot)(cos(xrot)*z - sin(xrot)*x) +300))

I know that this works. I just need to use trigger identities to avoid multiply/divide trig function.

#

Oh wait the * are bugging and making ittalic.

#

•2Dx = (cos(xrot)x + sin(xrot)z) scale/(sin(yrot)y + cos(yrot) (cos(yrot)z - sin(xrot)x) +300
•2Dy = (cos(yrot)y - (sin(yrot) (cos(xrot)z - sin(xrot)x))) (scale/(sin(yrot)y + cos(yrot)(cos(xrot)z - sin(xrot)x) +300))

There you go (I believe)

wooden mauve
#

ALL OF THIS IN A MINUTE?!

idle grotto
#

So this will be very tedious to make in gd but it should be working

idle grotto
wooden mauve
#

If someone can make a TESSERACT going inside/and out of itself when the player jumps to that cetain point whilst moving on an x and y axes. then this is defo possible

idle grotto
idle grotto
blazing herald
#

Also, +300 is clearly not generalized

idle grotto
idle grotto
blazing herald
blazing herald
#

im a bit skeptical hecause rubix cubes is a different scenario since they can only rotate 90 degrees at a time

idle grotto
blazing herald
idle grotto
#

I can't find it. At least not now. Maybe I can look into my liked programmes. Because it was an online program.

idle grotto
blazing herald
#

here is why I'm skeptical btw. This seems to just depend on the total x rotation and the total y rotation. However, if you rotate x then y it's different than rotating y then x

blazing herald
idle grotto
#

I'm not alone using my computer so I'll have to wait.

idle grotto
#

@blazing herald what time is it where you live?

idle grotto
#

Ok. Would you like to voc or souhld I rather send a small video?

blazing herald
#

just send a video

wooden mauve
#

by spun7x

#

i forgot hwo to speel his name

blazing herald
#

in WHAT, though, the movements are programmed in beforehand, which is simpler

#

In a way, simpler, at least. Obviously extremely much more complex to make overall

idle grotto
# wooden mauve by spun7x

In this case it is a precise animation. In my case the angle depends on player's inputs. And I don't know how to use any external programs to build.

blazing herald
# idle grotto In this case it is a precise animation. In my case the angle depends on player's...

in your case, the endpoints of the x position of each point should be the +-cosine of the y position. and the endpoints of the y position should be the +- cosine of the x position. Then you can move them accordingly, and i think you can use dynamic move trigger with sine in out easing and pause/resume triggers to make each point move back and forth between the endpoints how you want them to

#

that's how I would try to do it, at least

idle grotto
#

So I rotate the enpoints (wich are the max distance that a corner can be from the center ig ?) normally auround the first axis and then I use those endpoints to move each corner to its corresponding endpoint with the sin in option to make the animation looks like it is rotating at constant speed. Except I'm scared the animation would not look good if I am not moving precisely from an endpoint to an other but it os worth it. I'll give it a shot. So now we only have to find a way to rotate the cube (with its enpoints) around the first axis no matter the secondary axis rot amount. Or maybe we can use the endpoint trick for both axis ?

Anyway this is genius. I'm very happy we are having some ideas through our discussions.

blazing herald
#

however i'm not sure if it works (if it doesn't work, it would probably be because dynamic mode in triggers don't work how one might expect), it's just an idea. dont rly want to try it out, am making my own level now

#

but good luck !

idle grotto
idle grotto
#

for now that looks so sick !!

idle grotto
#

if I use the pause trigger instead of the spawn, I could keep the smooth animation !!!

#

it looks like the dynamic mode bypasses the only x / only y. so I won't be able to do the smooth animation.

#

the cube looks a little bit streched when max rotated but it works !

idle grotto
#

no it doesn't do what I want.

blazing herald
#

As it

wooden mauve
#

when you put two of the most intelligent fishes in a tank together and one of them has a question;

idle grotto
#

damn mkv files...

#

btw this is the video of my cube using my scratch formula. as you can see there is a little distortion effect but it looks fine

blazing herald
#

try starting from diamond shape position?

idle grotto
idle grotto
blazing herald
idle grotto
blazing herald
#

pretty sure the x position max points should be the +-cosine of the y position, and vice versa

#

@idle grotto

idle grotto
blazing herald
#

when rotating sideways the x position changes as much as possible, max and min x position is +- 1 because cos 0 = 1

blazing herald
#

hmmmm you right

#

what am i sayin

#

what i mean is like.....

#

should move in the sine curve

idle grotto
#

You mean let's say our point is (x,y) the the max on x axis is (x,y) ± (0,cos(yπ)) or something like this?

blazing herald
#

it should be based on the y position

#

when y = +-1, it's 0

#

when y = 0, it's 1

#

and it moves in the circle shape

idle grotto
#

So is my formula good ?

blazing herald
#

did you make it in gd?

idle grotto
blazing herald
#

the sine of the inverse cosine of x should be the max y position lol

#

so sqrt (1-x^2)

#

just in the circle

idle grotto
#

So it is (x,y) ± sin(1/cos(x)) ? Or just ± sin(1/cos(x)) ? I understand better the math than the English.

blazing herald
idle grotto
#

Oh cos-¹ ?

blazing herald
#

yeah

#

let me draw

idle grotto
#

So it is the same as sqrt(1-x^2) scince it is a circle ?

blazing herald
#

yes

#

see, any point on line to the right will have the same max y position, since rotating it that way doesn't change the x position (nor the x position of the projection)

#

and the height of the line is the formula for the circle, which is sqrt (1-x^2)

idle grotto
#

Ok I get it ! So I just take the image on the circle function of the other coord.

idle grotto
#

I understand myself. And this is how I will do it in gd.

blazing herald
#

anyway doing it this way if it even works would need four extra groups (the max/min x and y position) for each of the 8 point on the cube 😭

blazing herald
idle grotto
#

I should also use the min point ?

blazing herald
#

how do you move the point?

#

i thought you would do target + dynamic mode , but in both the x and y directions

#

or.. another way to be have just one point as the target, and teleport it when you start rotating another direction?

idle grotto
#

In the video I sent the inner points are the min pos. While some corners are getting to their max points, some other are getting to their min.

blazing herald
#

oh, i dont really understand...

#

it seems like you know better how to put it into gd

idle grotto
idle grotto
blazing herald
#

i am gonna sleep now since its like 4 am lol

idle grotto
#

Yes that's what I thought. Good night !

simple trout
near jacinth
#

Aye good news yall

#

@idle grotto @blazing herald You can theoretically use Item Edit to make a rotation matrix

idle grotto
#

I have no idea how item edit works.

#

How is this thread tagged resolved ?

near jacinth
#

idk i didnt tag it

near jacinth
blazing herald
#

anyway, would item edit accept non integers?

near jacinth
near jacinth
blazing herald
blazing herald
idle grotto
#

Ok I got it. But how do you do trig operation ?

idle grotto
# near jacinth Move triggers + loop

This wouldn't be precise enought a smarter way to do this would be to decrease the counter timer at constant speed while moving the object at a constant speed and stop the move trigger when the counter reaches 0.

simple trout
simple trout
#

actually i think i get the idea of it

#

you just use item edit to multiply the vector by the entries in the matrix and sum them up for the resulting vector but

#

how the fuck are you going to do sin and cos in gd

idle grotto
idle grotto
idle grotto
idle grotto
#

I found a way to make elipse using move triggers.

#

I think I figures out something

idle grotto
#

the diamond sahpe isn't exactly the max shape...

idle grotto
#

I am almost done !

idle grotto
#

I can't figure out the mar points for the y axis.

simple trout
#

that is if you still have it

idle grotto
#

I noticed that when I rotate auround the y axis, only the y coord of the points move. and it follows a sinusoid. I just nee a way to determine the amplitude and the phase of that function for each point to figure out the max points.

simple trout
#

wave functions 💀

idle grotto
#

I did it !!!

simple trout
#

do show

blazing herald
idle grotto
idle grotto
#

Truns out I did it on my phone and I can't load it on pc. so i'll have to record it from my phone...

idle grotto
#

nvm it worked !

#

nah mkv format...

#

better !

blazing herald
#

pretty nice!

#

well done :D

near jacinth
#

JEEEEZ

rapid zephyr
#

Holy shit

#

The nerding out paid off nicely

simple trout
#

that's really cool

#

drop the id ❤️

idle grotto
#

That you !

idle grotto
simple trout
#

based

shy pulsar
#

The amount of math used on this scares me

simple trout
#

linear algebra is the best math though

#

at least it isn't c*lculus

shy pulsar
simple trout
#

fair

idle grotto
# shy pulsar The amount of math used on this scares me

Actually I stole the formula from someone else, I simplified it with euleur's formula (stolen from euleur) and I recreated it in gd by myself and the help of eel. He told me how to recreate trig functions in gd and I found out you can stack follow triggers so I didn't have to make a very complex thing for each points. So thank you everyone !

idle grotto
#

Btw there is an other advantage to my system not only it can make cubes rotate bit it can make a 3d engine! You just need to find a way to order which face should be displayed in front of wich one.

idle grotto
#

Yes I'm not a good person

simple trout
#

no i mean

#

it's funny that you would say that

#

because basically all of modern math is stolen from euler

idle grotto
#

Really ?