GRRLIB / GRRLIB

Wii coding library
http://grrlib.santo.fr
MIT License
133 stars 16 forks source link

Various issues with the camera #21

Closed hexadecimal-chocolate closed 2 years ago

hexadecimal-chocolate commented 2 years ago

I've found a few issues with the camera recently. The most likely problem is that I'm not using it properly, if I'm not, please tell me.

Problem 1: When using GRRLIB_Camera3dSettings to change the position of the camera, it seems to pivot towards the origin. One way around this is to change the rotation of the same axis by the same amounts.

Problem 2: When rotating the camera, the closer I get to 90 degrees in any direction, the slower the rotation gets. The camera never rotates a full 360 degrees.

Like I said, I'm probably using the camera wrong, this is how I am updating it every frame: GRRLIB_Camera3dSettings(position.x, position.y, position.z, 0, 1, 0, rotation.x, rotation.y, rotation.z);

Crayon2000 commented 2 years ago

Hello, the GRRLIB_Camera3dSettings function is used to set values that are used by the guLookAt function in libogc. Here is the documentation in case it can help you:

/*!
 * \fn void guLookAt(Mtx mt,guVector *camPos,guVector *camUp,guVector *target)
 * \brief Sets a world-space to camera-space transformation matrix.
 *
 * \details Create the matrix \a m by specifying a camera position (\a camPos), a camera "up" direction (\a camUp), and a target
 * position (\a target).
 *
 * The camera's reference viewing direction is the -z axis. The camera's reference 'up' direction is the +y axis.
 *
 * This function is especially convenient for creating a tethered camera, aiming at an object, panning, or specifying an
 * arbitrary view.
 *
 * \param[out] mt New viewing matrix.
 * \param[in] camPos Vector giving 3D camera position in world space.
 * \param[in] camUp Vector containing camera "up" vector; does not have to be a unit vector.
 * \param[in] target Vector giving 3D target position in world space.
 *
 * \return none
 */

So nothing mentions rotation.

I think I will need to change the documentation for GRRLIB_Camera3dSettings because it is wrong since 2009:

 * @param posx x position of the camera.
 * @param posy y position of the camera.
 * @param posz z position of the camera.
 * @param upx Alpha component.
 * @param upy Alpha component.
 * @param upz Alpha component.
 * @param lookx x up position of the camera.
 * @param looky y up position of the camera.
 * @param lookz z up position of the camera.

I guess it should be replaced by something like this:

 * @param posx x position of the camera.
 * @param posy y position of the camera.
 * @param posz z position of the camera.
 * @param upx x up position of the camera.
 * @param upy y up position of the camera.
 * @param upz z up position of the camera.
 * @param lookx x position of the target.
 * @param looky y position of the target.
 * @param lookz z position of the target.
hexadecimal-chocolate commented 2 years ago

Thanks, I was wondering what the alpha component was. Changing upx, upy, and upz still didn't have the desired effect, so to rotate the camera do I have to set lookx, looky, and lookz to a point relative to the camera in the direction I want, or is there an easier way?