Greetings young Master Josh!
I've seen on one of the videos, that ships can dock on bigger ships, or land on them. I'd like to know how do you make it possible.
Do you use vectors or matrices for that, and how do you combine the one ship's orientation with the bigger ones?
Thank you for your attention!
Tora out!
Post
Mon Aug 12, 2013 2:50 am
#2
In general it is the same math that allows a weapon or thruster to be attached to a ship, a smoke trail attached to a missile, etc.
The usual formulation is composition of frames via matrix multiplication:
If A is the orientation matrix for the parent and B is the orientation matrix for the child, then A * B is the orientation matrix for the child when attached to the parent. Reading right to left you think of this as "first, apply the child's matrix B, then apply the parent's matrix A." Which really just means that B is attached to A.
It doesn't have to be matrices, as discussed in recent dev logs, but in general you have some way of "composing" frames so that you can handle "attached" entities like hardpoints. It really just means that you apply one frame after another. The parent frame is applied after a child frame to create the perception that the child is attached to the parent. Another way to think of it is that the child's frame is interpreted as being specified with respect to the local space of the parent (instead of in world space). So you go from local space -> parent space -> world space (i.e., A * B). A ship being docked is the exact same as a hardpoint being attached!
Hope it helps!
Re: Maths behind landing/docking
Hi again Tora,TorakunSama wrote:Greetings young Master Josh!
I've seen on one of the videos, that ships can dock on bigger ships, or land on them. I'd like to know how do you make it possible.
Do you use vectors or matrices for that, and how do you combine the one ship's orientation with the bigger ones?
Thank you for your attention!
Tora out!
In general it is the same math that allows a weapon or thruster to be attached to a ship, a smoke trail attached to a missile, etc.
The usual formulation is composition of frames via matrix multiplication:
If A is the orientation matrix for the parent and B is the orientation matrix for the child, then A * B is the orientation matrix for the child when attached to the parent. Reading right to left you think of this as "first, apply the child's matrix B, then apply the parent's matrix A." Which really just means that B is attached to A.
It doesn't have to be matrices, as discussed in recent dev logs, but in general you have some way of "composing" frames so that you can handle "attached" entities like hardpoints. It really just means that you apply one frame after another. The parent frame is applied after a child frame to create the perception that the child is attached to the parent. Another way to think of it is that the child's frame is interpreted as being specified with respect to the local space of the parent (instead of in world space). So you go from local space -> parent space -> world space (i.e., A * B). A ship being docked is the exact same as a hardpoint being attached!
Hope it helps!
“Whether you think you can, or you think you can't--you're right.” ~ Henry Ford
Post
Mon Aug 12, 2013 6:44 am
#3
Re: Maths behind landing/docking
Thanks YMaster Josh,
It's not very mathis but I think it might help, I'll give it a shot.
Matrix multiplication, hein?
I saw it as adding the host's position to the difference between the two . That gives the right position, but the guest ship can't move on it's own.
Now I don't see how to keep the guest's position relative or local to the host's.
Once again, thank you for your time!
It's not very mathis but I think it might help, I'll give it a shot.
Matrix multiplication, hein?
I saw it as adding the host's position to the difference between the two . That gives the right position, but the guest ship can't move on it's own.
Now I don't see how to keep the guest's position relative or local to the host's.
Once again, thank you for your time!
Post
Mon Aug 12, 2013 12:17 pm
#4
When you first dock, you need to compute the guest frame with respect to the host frame (since at the time of docking, the guest will still be in world space). You mentioned "difference between the two" ~ that's exactly the right concept, but we need the generalized version of it. The formula is:
B' = A^ * B
Where ^ means inverse. If you have a B in world space and want to convert it to A's space, the way to do so is multiplication by A's inverse frame. To check that it makes sense, just note that if you transform B' by A again, you get the original B:
A * B' = A * (A^ * B) = B
Which is exactly what you want: it means that we preserved the world space orientation of B when we moved it from world space to A's space.
Re: Maths behind landing/docking
Oh I left that bit out:TorakunSama wrote:Thanks YMaster Josh,
It's not very mathis but I think it might help, I'll give it a shot.
Matrix multiplication, hein?
I saw it as adding the host's position to the difference between the two . That gives the right position, but the guest ship can't move on it's own.
Now I don't see how to keep the guest's position relative or local to the host's.
Once again, thank you for your time!
When you first dock, you need to compute the guest frame with respect to the host frame (since at the time of docking, the guest will still be in world space). You mentioned "difference between the two" ~ that's exactly the right concept, but we need the generalized version of it. The formula is:
B' = A^ * B
Where ^ means inverse. If you have a B in world space and want to convert it to A's space, the way to do so is multiplication by A's inverse frame. To check that it makes sense, just note that if you transform B' by A again, you get the original B:
A * B' = A * (A^ * B) = B
Which is exactly what you want: it means that we preserved the world space orientation of B when we moved it from world space to A's space.
“Whether you think you can, or you think you can't--you're right.” ~ Henry Ford
Post
Wed Aug 14, 2013 3:20 am
#5
Re: Maths behind landing/docking
Ah, I see, seems straight forward, however, how do you invert the object's transform, do you invert all components, or is there a math function to invert it? As far as I know, the transform I use is a 4 Vectors Matrix. I can't have a vector or matrix to the exponent -1!
I probably don't get the invertion part.
Note: Forgive my ignorance, I was denied this part of high school maths!
I probably don't get the invertion part.
Note: Forgive my ignorance, I was denied this part of high school maths!
Post
Wed Aug 14, 2013 3:34 am
#6
Have a look at a bunch of fancy symbols to convince yourself that I'm speaking the mathematical truth, then go gently lift the code from this stackoverflow post if you'd like an implementation of a 4x4 inversion function.
Re: Maths behind landing/docking
Yes there's an analagous inverse operation for matrices, but not quite as straightforward as inverting all the components.TorakunSama wrote:Ah, I see, seems straight forward, however, how do you invert the object's transform, do you invert all components, or is there a math function to invert it? As far as I know, the transform I use is a 4 Vectors Matrix. I can't have a vector or matrix to the exponent -1!
I probably don't get the invertion part.
Note: Forgive my ignorance, I was denied this part of high school maths!
Have a look at a bunch of fancy symbols to convince yourself that I'm speaking the mathematical truth, then go gently lift the code from this stackoverflow post if you'd like an implementation of a 4x4 inversion function.
“Whether you think you can, or you think you can't--you're right.” ~ Henry Ford
Post
Wed Aug 14, 2013 9:04 am
#7
One more question, is the vector (x,y,z) the inverse of (z,x,y) or of (-x,-y,z) or again (1/x, 1/y, 1/z)? Depending on the outcome, maybe one can just manually swap/invert each element of the matrix (a 4 vectors one).
Re: Maths behind landing/docking
I'm not doubting! I'm asking! As I said, I did not have the opportunity to see this in school, even then it's been some years since I left schools! Sorry, should have done some research before asking!Have a look at a bunch of fancy symbols to convince yourself that I'm speaking the mathematical truth, then go gently lift the code from this stackoverflow post if you'd like an implementation of a 4x4 inversion function.
One more question, is the vector (x,y,z) the inverse of (z,x,y) or of (-x,-y,z) or again (1/x, 1/y, 1/z)? Depending on the outcome, maybe one can just manually swap/invert each element of the matrix (a 4 vectors one).
Post
Wed Aug 14, 2013 10:39 am
#8
~Sly
Re: Maths behind landing/docking
well if you represent the vector as a matrix [x,y,z] then it would be 1/determinant [x,y,z] where the determinant is x-y+z I believeTorakunSama wrote:I'm not doubting! I'm asking! As I said, I did not have the opportunity to see this in school, even then it's been some years since I left schools! Sorry, should have done some research before asking!Have a look at a bunch of fancy symbols to convince yourself that I'm speaking the mathematical truth, then go gently lift the code from this stackoverflow post if you'd like an implementation of a 4x4 inversion function.
One more question, is the vector (x,y,z) the inverse of (z,x,y) or of (-x,-y,z) or again (1/x, 1/y, 1/z)? Depending on the outcome, maybe one can just manually swap/invert each element of the matrix (a 4 vectors one).
~Sly
IVE BEEN OUT OF MY MIND A LONG TIME
Post
Wed Aug 14, 2013 2:10 pm
#9
For a matrix, the situation is different, the inverse M' is defined such that M * M' = I, where I is the identity matrix. You can't obtain M' just be 'inverting' the vector components, unfortunately. The general formula involves something called a determinant and something called an adjoint matrix, neither of which are particularly easy to explain
Re: Maths behind landing/docking
I suppose you could say that v' = (1/x, 1/y, 1/z) would be the multiplicative inverse, since v * v' = 1, and that (-x, -y, -z) would be the additive inverse, since v + v' = 0. But AFAIK one doesn't usually talk about vector inverses.TorakunSama wrote:I'm not doubting! I'm asking! As I said, I did not have the opportunity to see this in school, even then it's been some years since I left schools! Sorry, should have done some research before asking!Have a look at a bunch of fancy symbols to convince yourself that I'm speaking the mathematical truth, then go gently lift the code from this stackoverflow post if you'd like an implementation of a 4x4 inversion function.
One more question, is the vector (x,y,z) the inverse of (z,x,y) or of (-x,-y,z) or again (1/x, 1/y, 1/z)? Depending on the outcome, maybe one can just manually swap/invert each element of the matrix (a 4 vectors one).
For a matrix, the situation is different, the inverse M' is defined such that M * M' = I, where I is the identity matrix. You can't obtain M' just be 'inverting' the vector components, unfortunately. The general formula involves something called a determinant and something called an adjoint matrix, neither of which are particularly easy to explain
Although you can think of the vector as a matrix, it is not a square matrix, so it has neither a determinant nor an inverse. An inverse M' needs to satisfy both M * M' = I and M' * M = I. This doesn't make sense for a non-square matrix M since the size requirement of M' (how many rows/cols it has) would change depending on whether it was left-multiplied or right-multiplied, due to the nature of matrix multiplication. So you can't possibly have a single matrix M' that satisfies both if M is non-square.Slymodi wrote:well if you represent the vector as a matrix [x,y,z] then it would be 1/determinant [x,y,z] where the determinant is x-y+z I believe
~Sly
“Whether you think you can, or you think you can't--you're right.” ~ Henry Ford
Post
Wed Aug 14, 2013 3:19 pm
#10
Re: Maths behind landing/docking
Hmm, I though you had a simpler solution than I did!
All I have to do is to apply the host movement and rotation to the guests + an offset!
I'll stick with my own method, but would still be interested in your approach!
I'm very grateful for your efforts, Master Josh, Sly!
All I have to do is to apply the host movement and rotation to the guests + an offset!
I'll stick with my own method, but would still be interested in your approach!
I'm very grateful for your efforts, Master Josh, Sly!
Post
Wed Aug 14, 2013 4:23 pm
#11
Re: Maths behind landing/docking
If you're using c++ I strongly recommend the glm library. You can always remake specific classes if you find you need different performance later.
It can handle anything glsl can, which means matrix, vectors, and many useful functions related to them, are immediately available with a simple syntax.
It can handle anything glsl can, which means matrix, vectors, and many useful functions related to them, are immediately available with a simple syntax.
woops, my bad, everything & anything actually means specific and conformed