Context:
I have 3 matrices used in a specially crafted 3D library. It does not use OpenGL nor DirectX, but I'm guessing it's a DirectX variant implementation, where the camera moves around in the 3D world, instead of staying put at the world origin.
I have model matrix, used to manipulate the 3D objects in 3D space. That includes rotation, translation, and scaling.
I have a view matrix, used to determine where in 3D space is the camera located. I translate the view matrix to move the camera around.
And finally, I have the projection matrix, where it uses stereoscopic perspective. This is aided by a slider that determines the inter-ocular distance for left and right perspective render targets.
Using these matrices, I am on the path to implement a "3D Object Pick Up" mechanic, so the player can "pick" up objects and hold them in front of the camera until they "let go". The issue I am having at the moment, is obtaining the vector position to move the objects up close to the player and move them in a circle around the camera. I figured I can apply matrix transformations on the model matrix to move them, but that causes the 3D objects to move erratically.
Problem:
Here's a simple GIF animation showing the target vector position that I wanted to obtain via camera view matrix.
I would like to have this position that is always at a set distance away from the player's camera position while the player is rotating the camera around. This position will be the spot where the player engages with objects by "picking them up" and "holding them at that location as the camera looks around.
Even though it's 2D in the GIF, I am referring to a 3D pick up vector position, translated from the camera view matrix.
Current Progress:
I only know how to set the object's rotation, so it will always face the camera as the object is "held" by the player. Here's the following code:
void Player::Manipulate(std::shared_ptr<GameObject> obj, C3D_Mtx& currentProjectionMatrix, C3D_Mtx& currentViewMatrix, C3D_Mtx& modelMatrix){
if (this->cameraManipulateFlag){
//Matrix and C3D_Mtx.
//C3D_Mtx requires all rows to be [WZYX], instead of the other way around (XYZW).
//This is due to how the GPU reads the matrix data.
//Everything else mathematically is the same.
//Rotation - Obtaining the inverse matrix.
C3D_Mtx inverse, result;
Mtx_Copy(&inverse, ¤tViewMatrix);
Mtx_Inverse(&inverse);
//Rotation - Multiplying the inverse with other matrices to get the actual rotation.
Mtx_Multiply(&result, &modelMatrix, &this->oldViewMatrix);
Mtx_Multiply(&modelMatrix, &result, &inverse);
}
else {
Mtx_Copy(&this->oldViewMatrix, ¤tViewMatrix);
}
}
Does anyone know how to obtain the vector position in front of the camera by a set distance (usually 4 to 6 unit vectors away from the player camera view)? Thanks in advance.
I'm stuck on this problem for 2 weeks now. And nothing is progressing.