User Tools

Site Tools


en:tutorials:cameras:fixing_camera_to_object

This is an old revision of the document!


Fixing the Camera to an Object manually using a Clock

If you wish the camera to be fixed on a moving object, you will need to use code to update it regularly. The camera's x and y coordinates are copied from the object, but not the z coordinate.

Code

void orxFASTCALL Update(const orxCLOCK_INFO *_pstClockInfo, void *_pContext)
{
	orxVECTOR cameraPosition = { 0,0,0 };
	orxCamera_GetPosition(camera, &cameraPosition);
 
	orxVECTOR heroPosition= { 0,0,0 };
	orxObject_GetPosition(hero, &heroPosition);
 
	cameraPosition.fX = heroPosition.fX;
	cameraPosition.fY = heroPosition.fY;
	orxCamera_SetPosition(camera, &cameraPosition);
...
}
 
orxSTATUS orxFASTCALL Init()
{
...
 
  orxClock_Register(orxClock_FindFirst(orx2F(-1.0f), orxCLOCK_TYPE_CORE), Update, orxNULL, orxMODULE_ID_MAIN, orxCLOCK_PRIORITY_LOWER);
...

Please note the use of orxCLOCK_PRIORITY_LOWER instead of orxCLOCK_PRIORITY_NORMAL. This mode ensures the camera is updated after all the objects which will ensure a rock solid lock.

en/tutorials/cameras/fixing_camera_to_object.1547519962.txt.gz · Last modified: 2019/01/14 22:39 (5 years ago) (external edit)