Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Point into direction x y z
- levitm
-
Scratcher
5 posts
Point into direction x y z
Hello,
I came up with a nice project idea, and started really quickly, but after some progress I noticed that I had no idea how to calculate my rotation x and y (no z rotation) if I want to look from my position x1 y2 z2 exactly to a random point x2 y2 z2
Thanks for your help and have a great day
I came up with a nice project idea, and started really quickly, but after some progress I noticed that I had no idea how to calculate my rotation x and y (no z rotation) if I want to look from my position x1 y2 z2 exactly to a random point x2 y2 z2
Thanks for your help and have a great day
- levitm
-
Scratcher
5 posts
Point into direction x y z
thanks, but i meant with 3D coordinates, do you have any idea how to do that?
- ggenije2
-
Scratcher
100+ posts
Point into direction x y z
It's very complicated, I spent many months trying to create such a operation in my 3D engine.
If you want to see it go to https://scratch.mit.edu/projects/437548352/editor/ , sprite is “update” custom block is " Camera Look at position"
but that ,most likely,won't work for you that's because I use yxz euler rotations , any you probably use xyz as everyone else.
So I'm not sure what is the “clean” solution , my solution was found by “fail and try again hard trying”.
Here are two ways you can think of:
1.Look at this:
Rotation matrix multiplication
'A' is sin(x) , ‘a’ is cos(x), ‘B’ is sin(y) and so on,
You get this
b*c*x-C*a*y+A*B*c*y+A*C*z+B*a*c*z
C*b*x+A*B*C*y+a*c*y+B*C*a*z-A*c*z
-B*x+A*b*y+a*b*z
So to point to be in center of screen , this means that x and y needs to be 0, since x and y projected is equal to x/z*fl and y/z*fl, this means
that
b*c*x-C*a*y+A*B*c*y+A*C*z+B*a*c*z =0
and
C*b*x+A*B*C*y+a*c*y+B*C*a*z-A*c*z =0
So you need solve that two equations somehow.
2. Use quaternions
Try to find solution in quaternions and then convert it euler angles.
Here you can find all quaternion operations you need including converting it to euler and vice versa:
https://gist.github.com/aeroson/043001ca12fe29ee911e
So you find quaternion for look at, and then you convert it to euler angles.
There is no “quick easy solution”, I never saw someone using this beside me on scratch (I was using this in crystal seeker)
If you want to see it go to https://scratch.mit.edu/projects/437548352/editor/ , sprite is “update” custom block is " Camera Look at position"
but that ,most likely,won't work for you that's because I use yxz euler rotations , any you probably use xyz as everyone else.
So I'm not sure what is the “clean” solution , my solution was found by “fail and try again hard trying”.
Here are two ways you can think of:
1.Look at this:
Rotation matrix multiplication
'A' is sin(x) , ‘a’ is cos(x), ‘B’ is sin(y) and so on,
You get this
b*c*x-C*a*y+A*B*c*y+A*C*z+B*a*c*z
C*b*x+A*B*C*y+a*c*y+B*C*a*z-A*c*z
-B*x+A*b*y+a*b*z
So to point to be in center of screen , this means that x and y needs to be 0, since x and y projected is equal to x/z*fl and y/z*fl, this means
that
b*c*x-C*a*y+A*B*c*y+A*C*z+B*a*c*z =0
and
C*b*x+A*B*C*y+a*c*y+B*C*a*z-A*c*z =0
So you need solve that two equations somehow.
2. Use quaternions
Try to find solution in quaternions and then convert it euler angles.
Here you can find all quaternion operations you need including converting it to euler and vice versa:
https://gist.github.com/aeroson/043001ca12fe29ee911e
So you find quaternion for look at, and then you convert it to euler angles.
There is no “quick easy solution”, I never saw someone using this beside me on scratch (I was using this in crystal seeker)
- levitm
-
Scratcher
5 posts
Point into direction x y z
It's very complicated, I spent many months trying to create such a operation in my 3D engine.Okay, i guess i thought this theme is too simple. I`m gonna try out your tips, and text you if i got it working. Thanks alot for your help and your time
If you want to see it go to https://scratch.mit.edu/projects/437548352/editor/ , sprite is “update” custom block is " Camera Look at position"
but that ,most likely,won't work for you that's because I use yxz euler rotations , any you probably use xyz as everyone else.
So I'm not sure what is the “clean” solution , my solution was found by “fail and try again hard trying”.
Here are two ways you can think of:
1.Look at this:
Rotation matrix multiplication
'A' is sin(x) , ‘a’ is cos(x), ‘B’ is sin(y) and so on,
You get this
b*c*x-C*a*y+A*B*c*y+A*C*z+B*a*c*z
C*b*x+A*B*C*y+a*c*y+B*C*a*z-A*c*z
-B*x+A*b*y+a*b*z
So to point to be in center of screen , this means that x and y needs to be 0, since x and y projected is equal to x/z*fl and y/z*fl, this means
that
b*c*x-C*a*y+A*B*c*y+A*C*z+B*a*c*z =0
and
C*b*x+A*B*C*y+a*c*y+B*C*a*z-A*c*z =0
So you need solve that two equations somehow.
2. Use quaternions
Try to find solution in quaternions and then convert it euler angles.
Here you can find all quaternion operations you need including converting it to euler and vice versa:
https://gist.github.com/aeroson/043001ca12fe29ee911e
So you find quaternion for look at, and then you convert it to euler angles.
There is no “quick easy solution”, I never saw someone using this beside me on scratch (I was using this in crystal seeker)

- Discussion Forums
- » Help with Scripts
-
» Point into direction x y z



