Could anyone help me to make a 1st person like camera movement based on the worldtranslate and worldrotate. Thanks in advanced.
Here is an example which uses x, y and z-rotation. This may be suitable for games with free movement in 3 dimensions. First add variables for translation and rotation your framework class:
- Code:
//in your class definition
EVECTOR3D vrot;
EVECTOR3D vtrans;
And initialize them in the constructor. The default position is above the model and moved away from the camera.
- Code:
vrot.x = 0;
vrot.y = 0;
vrot.z = 0;
vtrans.x = 0;
vtrans.y = -1024 * 16;
vtrans.z = -2048 * 256;
Matrix math is used to determine the speed in which of the x, y and z-axis the camera moves. This depends on the rotation of the camera. Add code to OnNextFrame:
- Code:
EVECTOR3D vtransadd;
long matrix[16];
ClassEMath::MatrixLoadIdentity(matrix);
ecd.math->MatrixSetRotate((unsigned short)vrot.x, (unsigned short)vrot.y, (unsigned short)vrot.z, matrix);
vtransadd.x = ((4096 * matrix[8]) >> 12);
vtransadd.y = -((4096 * matrix[9]) >> 12);
vtransadd.z = ((4096 * matrix[10]) >> 12);
These can be used to add to the translation vector to change position:
- Code:
if (ecd.input->KeyHold(DIAM_MENUCONFIRM))
{
vtrans.x += vtransadd.x * (long)timedelta / 64;
vtrans.y += vtransadd.y * (long)timedelta / 64;
vtrans.z += vtransadd.z * (long)timedelta / 64;
}
The camera rotation can be changed with the arrow keys:
- Code:
if (ecd.input->KeyHold(DIAM_MENUUP))
vrot.x -= timedelta;
else if (ecd.input->KeyHold(DIAM_MENUDOWN))
vrot.x += timedelta;
if (ecd.input->KeyHold(DIAM_MENULEFT))
vrot.y -= timedelta;
else if (ecd.input->KeyHold(DIAM_MENURIGHT))
vrot.y += timedelta;
Finally use these for the WorldTranslate and WorldRotate functions:
- Code:
display->WorldReset();
display->WorldRotate(vrot.x, vrot.y, vrot.z);
display->WorldTranslate(-vtrans.x / 16, vtrans.y / 16, vtrans.z / 16);
Let us know if it helps