Hello everyone, I am a newbie game developer
At the moment I am trying to understand matrix operations and how they can be applied for 3D drawing and for 3D gameplay tasks. Its tough so far as I am having trouble visualizing the kinds of things that are possible and with what sorts of matrix operations and in what order of matrix operations
Most of the tutorials I have found focus on drawing simple meshes to the screen and so describe the " model-view-projection " accumulation of matrices but not much beyond that.
The biggest problem area for me is figuring out in a intuitive and visual sense how to transform between coordinate spaces.
Some of the things I am trying to grasp and looking for answers are :
- How do we transform a element expressed in a " local coordinate space " into " scene coordinate space " ?
Lets say we have a position or point " pointA " expressed in the " local coordinate space " of game object " A "
and we have assigned a position and rotation and scale expressed in " scene coordinate space " to this same game object " A ".
Basically this scenario is equivalent to transforming a arbitrary vertex of some mesh that has been assigned a position and rotation and scale expressed in " scene space " into " scene space. "
If I understand correctly, we need to translate the given position and rotation and scale expressed in " scene coordinate space " that we assigned to game object " A " into a transformation matrix and then we need to perform the following :
transformedPointAInSceneSpace = ( transformationMatrixOfGameObject"A" ) * ( Vector4( pointA , 1 ) )
We don't need to concern ourselves with the " view matrix " or the " projection matrix " ... just the " model matrix. "
Am I correct ?
- How do we " combine " or accumulate the transformation matrices of objects in a parent - child relationship so that the position and rotation of the child object is expressed relative to the position and rotation of the parent object ?
Basically how do we accumulate or combine " coordinate spaces. "
Lets say we have a game object " A " with a transformation matrix and a game object " B " with a transformation matrix
and that game object " A " is the parent of game object " B "
If I understand correctly, we need to perform the following :
transformationMatrixOf"B"ExpressedRelativeTo"A" = ( transformationMatrixOfParent"A" ) * ( transformationMatrixOfChild"B" )
Is this correct ?
- How do we maintain the current position and rotation of a game object expressed in " scene coordinate space " when assigning it as a child of another game object ?
Lets say that we have a game object " B " that is in a existing parent-child relationship with game object " A. "
such that game object " B " is a child of game object " A. "
Now lets say that we " re-parent " game object " B " to game object " C. "
But to complicate matters, lets say that we want to maintain or retain the current position and rotation and scale expressed in " scene coordinate space " of game object " B " with the previous parent game object " A " after we have " re-parented " game object " B " with its new parent, game object " C. "
How would we go about this ?
First I think that we need to accumulate the transformation matrix of child game object " B " with the transformation matrix parent game object " A " so as to compute a position and rotation expressed in " scene coordinate space " of game object " B "
transformationMatrixOf"B"ExpressedRelativeTo"A" = ( transformationMatrixOfParent"A" ) * ( transformationMatrixOfChild"B" )
Then we would need to transform this transformation matrix representing a position and rotation expressed in " scene coordinate space " into the " local coordinate space " of game object " C. "
Which leads to my next question
- How do we transform a position or point expressed in " scene coordinate space " into a corresponding point or position expressed in the " local coordinate space " of a game object and vice versa ?
Lets say we have a position or point " pointA " expressed in the " scene coordinate space "
and that we have a game object " B " and that we have assigned a position and rotation and scale expressed in " scene coordinate space " to this same game object " B ".
If I understand correctly in order to transform a given position or point " pointA " expressed in " scene coordinate space " into a corresponding position or point expressed in the " local coordinate space " of game object " B " we need to first translate the position and rotation and scale expressed in " scene coordinate space " that we assigned to game object " B " into a transformation matrix then we need to " invert " this same transformation matrix and then multiply it with the position or point " pointA. "
transformedPointAInLocalSpaceOfGameObject"B" = ( Math.Invert( transformationMatrixOfGameObject"B" ) ) * ( Vector4( pointA , 1 ) )
Now how to do the opposite ?
Lets say we have our newly transformed point or position " pointA " expressed in the " local coordinate space " of game object " B. "
Now how to we transform this point or position " pointA " into " scene coordinate space " ?
I think we can simply do the standard :
transformedPointAInSceneSpace = ( transformationMatrixOfGameObject"B" ) * ( Vector4( pointA , 1 ) )
What about " inverting " the " inverse " of the transformation matrix of game object " B " and multiplying this with point or position " pointA " ?
transformedPointAInSceneSpace = ( Math.Invert( Math.Invert( transformationMatrixOfGameObject"B" ) ) ) * ( Vector4( pointA , 1 ) )
Is this possible to ? Which is the better approach ?
- How do we transform a position or point expressed in one " local coordinate space " into another " local coordinate space " ?
This sort of a weird question but it follows from talking about " local coordinate spaces " and " scene coordinate spaces " and translating between them
I think since we have two " local coordinate spaces " we effectively have a single " local coordinate space " and so any points or positions are in and operations are performed in effectively same single " local coordinate space " implicitly.
So no " transformation " step is required.
Looking at the above questions, they are pretty basic ... but I am really new at 3D transformation stuff
But I think that they pretty much cover the basic matrix math stuff that I am having difficulty with.
For more complex stuff could anyone please point me to a real good matrix math tutorial that moves beyond the simple math operations and describes actual and " common " gameplay and drawing usage scenarios ... and does so in basic and newbie friendly way for people that have difficulties with math ?
Or instead could someone please walk-through some common examples in simple language and simple maths how I can I do those " common " gameplay and drawing related things, like those described above, with a " standard " math library like JOML ( for Java ) or GML.
Thank-you