You know about the Companion Cube in Portal, and noticed how when you pick the cube up and move the camera around, the cube's facing will always stay the same to the player's camera view.

I'm working on something similar to that using matrix math.

This is my current progress:

And here's my current code:

As you can see, I am using the following algorithm to calculate the rotation:

worldRotNew = worldRotOrig * viewRotOrig * inv(viewRotCurrent)

However, it doesn't seem to be correct. When I set cameraManipulateFlag to true, the cube is slanted like a forward slash ( / ), which is when I'm picking up the cube. If the variable is set to false, I am not picking up the cube, so things are normal. I'm just trying to get it to rotate, so the cube always look towards the camera.

My question is:

Attached is the current source code. I really do appreciate any help! Thanks!

I'm working on something similar to that using matrix math.

This is my current progress:

And here's my current code:

Code:

```
void Player::Manipulate(std::shared_ptr<GameObject> obj, 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.
C3D_Mtx inverse, result;
Mtx_Copy(&inverse, ¤tViewMatrix);
Mtx_Inverse(&inverse);
Mtx_Multiply(&result, &modelMatrix, &this->oldViewMatrix);
Mtx_Multiply(&modelMatrix, &result, &inverse);
}
else {
Mtx_Copy(&this->oldViewMatrix, ¤tViewMatrix);
}
}
```

As you can see, I am using the following algorithm to calculate the rotation:

worldRotNew = worldRotOrig * viewRotOrig * inv(viewRotCurrent)

However, it doesn't seem to be correct. When I set cameraManipulateFlag to true, the cube is slanted like a forward slash ( / ), which is when I'm picking up the cube. If the variable is set to false, I am not picking up the cube, so things are normal. I'm just trying to get it to rotate, so the cube always look towards the camera.

**I'm not worried about translation and scaling for now.**My question is:

**How to get the cube to always look at the camera when rotating the player's camera?**

Attached is the current source code. I really do appreciate any help! Thanks!