#Making a cube rotate on two axes
368 messages · Page 1 of 1 (latest)
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.
https://www.malinc.se/math/linalg/rotatecubeen.php found this which might help someone who's more experienced with math than me
the issue is getting matrices to work in gd
do you think that this method could work if I find a way to pull it off?
I'll check it out !
I want to learn projections for gd levels now. But havent taken linear algebra since 2020 . Kind of forgotten most of it
Alright lmk if you find anything ^^
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
That's way beyond my knowledge but I'll see if I can pull it off somehow
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
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
okay but how would I get rotation matrices into gd?
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
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
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
Alright, I'm not in a rush so there's no need to worry
👌
Btw! What order to do red green and blue in??
what?
Red first then green then blue?
So blue doesn't do anything?
yeah
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
Oh, okay. I think ik what you mean
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
@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)
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
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
The thing is, I have no idea how to do that which is why I wanted to try this method
Well, you could learn! I assume you know trig right?
Some of it, yes
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
This is way more advanced than anything I've done in my math courses
I might give it a shot tomorrow
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
how does one do it in gd?
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
do you want to check my level?
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
ill do that in a bit, yea
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
yeahh
Thank you so much @harsh shell !!!! I'm reading this I'l reading this and I will give you more news
You should thank eel, he did basically all of the work lol
I haven't seen the matrix for now. But supposedly I should see them this year.
It was your link, I just followed the instructions xd
I could not have done anything with that link without your help though
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 ?
Oh nice!
https://www.malinc.se/math/linalg/rotatecubeen.php here, this explains it
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 ?
No, I used those as kind of a unit circle
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
Ok but how do I choose a rotation amont on each axis ?
Aka I want to choose my t for each individual axis
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
holy shit yall are nerding out
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
Your dad is mathematician 🤩
HAHA
tbf how would one represent complex or hypercomplex numbers in gd
Idk, I feel like after you simplify it to what gd could understand you'd have to get the same result
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.
Ooh. So there is actually only one axis here. It goes from near bottom left to top far right
Yes. In this case using rotation to have sin and cos functions.
Ahhhhhhhhhhh that's why it looked weird to me !!
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
No I am trying the easy option
Okay, I am pretty sure there are like YouTube tutorials or something in that case
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.
Hmm. For question two it is tough. I'm not sure
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
It is a continuous and variable amount
I'm not sure. I'll try to create this tomorrow, I can't play gd today
Hummmm. I knew somehow scale triggers would be useful.
this is somewhat exciting for me
Anyway, go through that link that EkPek sent, it will explain how to use a rotation matrix
I totally understand. And if you manage to do it, this would be a great help for my project!
You hit the coords of the point with the rotation matrix and the projection matrix to find the coords of the projected point =)
The issue is to know the coords of the point after you did a first rotation.
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
Yes this is the idea. Now how do you automate this in gd ?
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
But the time is actually how long did the player press.
So is is not specific
You can have the unit circle you set up only rotate when the player presses
What I did in my example level was just rotate it at a continuous rate, but it's flexible
Ok I see
Oh, nice!
This is my global idea. Hopefully it will seem clearer.
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
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)
It's now two variables, you will get stuff like sin u cos v in your positions
You have time I'm not hurry at all.
You could also use trig identities here. I think this is the same as cos (u - v) - cos (u + v), or something like that
there are probably several ways to doit you could give it a shot as well
I am not very good at trig identity however I can transform trigonometry functions using euler's expression. But I guess I will let you do the math you are way better than me.
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...
Oh just google the identities nobody can remember them all
Well, it's more that each point has a position function which depends on both u and v 😅
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.
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
Yes that's why I think that we wnly need to focus on 6 points for now.
Yes hopefully 🙏. I really want to understand.
Not the math pert I think this should be the easiest. But the implementation part.
Doesn't this just work?
never mind, it doesn't work
i have another idea, but it will be very difficult...
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)
Yes but you'll have to wait a few days...
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
@blazing herald please give me your math
sorry, not been working on it :(
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 ?
these are the angles
this is how you multiply two cosines
Oh ok
But I wanted your formula for the (x,y) coords
it's cos(a)*cos(b) = 1/2 (cos(a+b)+cos(a-b))
there is a problem with this. take the coordinate say (1,1,1) of the original point of the cube
You can proof this by using euler's formula right?
probably, or taylor series
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
Yes I see. I will give you the formula I found on internet (that one on scratch)
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
I think there is a simpler way. I will show you. Just wait so I get to my computer
Ok
•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)
ALL OF THIS IN A MINUTE?!
So this will be very tedious to make in gd but it should be working
I just copied a formula I used for a rubik's cube in python a while ago.
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
What level are you talking about ?
Actually if you find a way to add instead of multiply I think this might be possible ?
You're multiplying by x y and z position of the current or original point?
Also, +300 is clearly not generalized
No x, y and z are the 3D coords of the point I want to get the 2D coords.
Yes idk what it does but it is there for some reason...
That's easy, just let z be the axis into the screen, then just ignore z
you mind just showing where you got it from?
im a bit skeptical hecause rubix cubes is a different scenario since they can only rotate 90 degrees at a time
I can't find it but it was from a scratch program. However I can show you how well it works.
I meant, show the scratch program
I can't find it. At least not now. Maybe I can look into my liked programmes. Because it was an online program.
I would like that the cam rotates auround the cube.
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
oh didn't realise this, but is that different than a fixed camera and the cube rotating?
But do show the result
No it is the exact same thing.
I'm not alone using my computer so I'll have to wait.
@blazing herald what time is it where you live?
1:12 pm
Ok. Would you like to voc or souhld I rather send a small video?
just send a video
WHAT
by spun7x
i forgot hwo to speel his name
it's definitely possible
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
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.
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
Oh I see !! This is smart !
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.
use endpoint for both
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 !
I actually don't need dynamic mode scince the cube won't rotate on both axis at the same time.
for now that looks so sick !!
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 !
no it doesn't do what I want.
You just need to have what if following always on the same x or y axis
As it
when you put two of the most intelligent fishes in a tank together and one of them has a question;
oh it was a question ?
damn mkv files...
as you can see it does not really do what I want. it even changes the sizes of the faces.
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
it seems like since you start from this position, you are having some difficulty. Because in your starting position you are already partly rotated
try starting from diamond shape position?
Yes I know. That's why the first thing I do it getting to a max rotated state. And as you can see it is not what I expexte even tho the rotations are both working separately.
But my max points are good ?
max points should move as the cube rotates no?
This is a question I am also asking. I realized that in my situation it makes no difference. But scince my situation is wrong I think that the max points have to move too. Which require to find the max points of the max points.
here
pretty sure the x position max points should be the +-cosine of the y position, and vice versa
@idle grotto
I don't really know what you mean by cos of y but in my case, to find the max positions, I took the square of the front face and I rotated it 45°.
Like say the position of the point is (-1,0) like, the left middle. Then when rotating upwards the y position shouldn't change. Max and min y position is 0 which is cosine of -1
when rotating sideways the x position changes as much as possible, max and min x position is +- 1 because cos 0 = 1
Cosine of -1 isn't 0
hmmmm you right
what am i sayin
what i mean is like.....
should move in the sine curve
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?
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
So is my formula good ?
Idk, i haven't tried it. It looks good enough on your video
did you make it in gd?
I mean this formula.
It would be very long. I would prefer to give a chance to the max point technique before.
oh, i don't think so hang on i want to clarify
the sine of the inverse cosine of x should be the max y position lol
so sqrt (1-x^2)
just in the circle
So it is (x,y) ± sin(1/cos(x)) ? Or just ± sin(1/cos(x)) ? I understand better the math than the English.
Inverse cosine is not 1/cos x unfortunately
Oh cos-¹ ?
So it is the same as sqrt(1-x^2) scince it is a circle ?
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)
Ok I get it ! So I just take the image on the circle function of the other coord.
wdym?
I understand myself. And this is how I will do it in gd.
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 😭
okay good luck!!! lmk if it works
I should also use the min point ?
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?
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.
oh, i dont really understand...
it seems like you know better how to put it into gd
Just watch the first half of the video.
Not at all.
we both are confused then 😅
i am gonna sleep now since its like 4 am lol
Yes that's what I thought. Good night !
cant you make something like that with area move
Aye good news yall
@idle grotto @blazing herald You can theoretically use Item Edit to make a rotation matrix
idk i didnt tag it
in #1082003291237535774
but how to move based on an item id?
anyway, would item edit accept non integers?
Move triggers + loop
If you use it with timers
can u elaborate?
ohh very smart
Ok I got it. But how do you do trig operation ?
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.
yeah i was wondering this
How
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
the only way is rotate trigger
It's really weirs cause the "300" does the exact sme thing as scale but the inverse.
I'm not sure how to make the diamond shape.
the diamond sahpe isn't exactly the max shape...
I am almost done !
I can't figure out the mar points for the y axis.
can you show me the math you did
that is if you still have it
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.
wave functions 💀
I did it !!!
do show
Nice!
I'm very busy this week so I'll show Friday
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...
JEEEEZ
That you !
Not uploaded. But I might make a 3d engine simpler to use.
based
The amount of math used on this scares me
Oh yeah, but still scares me because Im in preparatory and still gonna enter to 2nd semester, I still dont know these things xd
fair
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 !
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.
stolen from euler is crazy
Yes I'm not a good person
no i mean
it's funny that you would say that
because basically all of modern math is stolen from euler
Really ?