/** Creates a camera from config * @param[in] _zConfigID Config ID * @ return orxCAMERA / orxNULL */ orxCAMERA *orxFASTCALL orxCamera_CreateFromConfig(const orxSTRING _zConfigID) { orxCAMERA *pstResult; /* Checks */ orxASSERT(sstCamera.u32Flags & orxCAMERA_KU32_STATIC_FLAG_READY); /* Search for camera */ pstResult = orxCamera_Get(_zConfigID); /* Not already created? */ if(pstResult == orxNULL) { /* Pushes section */ if((orxConfig_HasSection(_zConfigID) != orxFALSE) && (orxConfig_PushSection(_zConfigID) != orxSTATUS_FAILURE)) { /* Creates 2D default camera */ pstResult = orxCamera_Create(orxCAMERA_KU32_FLAG_2D); /* Valid? */ if(pstResult != orxNULL) { orxVECTOR vPosition; orxFLOAT fNear, fFar, fWidth, fHeight; /* Gets frustum info */ fNear = orxConfig_GetFloat(orxCAMERA_KZ_CONFIG_FRUSTUM_NEAR); fFar = orxConfig_GetFloat(orxCAMERA_KZ_CONFIG_FRUSTUM_FAR); fWidth = orxConfig_GetFloat(orxCAMERA_KZ_CONFIG_FRUSTUM_WIDTH); fHeight = orxConfig_GetFloat(orxCAMERA_KZ_CONFIG_FRUSTUM_HEIGHT); /* Applies it */ orxCamera_SetFrustum(pstResult, fWidth, fHeight, fNear, fFar); /* Has zoom? */ if(orxConfig_HasValue(orxCAMERA_KZ_CONFIG_ZOOM) != orxFALSE) { orxFLOAT fZoom; /* Gets config zoom */ fZoom = orxConfig_GetFloat(orxCAMERA_KZ_CONFIG_ZOOM); /* Valid? */ if(fZoom > orxFLOAT_0) { /* Applies it */ orxCamera_SetZoom(pstResult, fZoom); } } /* Has a position? */ if(orxConfig_GetVector(orxCAMERA_KZ_CONFIG_POSITION, &vPosition) != orxNULL) { /* Updates camera position */ orxCamera_SetPosition(pstResult, &vPosition); } /* Updates object rotation */ orxCamera_SetRotation(pstResult, orxMATH_KF_DEG_TO_RAD * orxConfig_GetFloat(orxCAMERA_KZ_CONFIG_ROTATION)); /* Stores its reference key */ pstResult->zReference = orxConfig_GetCurrentSection(); /* Protects it */ orxConfig_ProtectSection(pstResult->zReference, orxTRUE); /* Adds it to reference table */ orxHashTable_Add(sstCamera.pstReferenceTable, orxString_ToCRC(pstResult->zReference), pstResult); /* Updates status flags */ orxStructure_SetFlags(pstResult, orxCAMERA_KU32_FLAG_REFERENCED, orxCAMERA_KU32_FLAG_NONE); } /* Pops previous section */ orxConfig_PopSection(); } else { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_RENDER, "Cannot find config section named (%s).", _zConfigID); /* Updates result */ pstResult = orxNULL; } } /* Done! */ return pstResult; }
/** Update callback */ void orxFASTCALL Update(const orxCLOCK_INFO *_pstClockInfo, void *_pstContext) { orxVECTOR vPos, vSoldierPos; orxCAMERA *pstCamera; orxFLOAT fWidth, fHeight, fX, fY; /* *** CAMERA CONTROLS *** */ /* Gets first viewport camera */ pstCamera = orxViewport_GetCamera(pstViewport); /* Camera rotate left? */ if(orxInput_IsActive("CameraRotateLeft")) { /* Rotates camera CCW */ orxCamera_SetRotation(pstCamera, orxCamera_GetRotation(pstCamera) + orx2F(-4.0f) * _pstClockInfo->fDT); } /* Camera rotate right? */ if(orxInput_IsActive("CameraRotateRight")) { /* Rotates camera CW */ orxCamera_SetRotation(pstCamera, orxCamera_GetRotation(pstCamera) + orx2F(4.0f) * _pstClockInfo->fDT); } /* Camera zoom in? */ if(orxInput_IsActive("CameraZoomIn")) { /* Camera zoom in */ orxCamera_SetZoom(pstCamera, orxCamera_GetZoom(pstCamera) * orx2F(1.02f)); } /* Camera zoom out? */ if(orxInput_IsActive("CameraZoomOut")) { /* Camera zoom out */ orxCamera_SetZoom(pstCamera, orxCamera_GetZoom(pstCamera) * orx2F(0.98f)); } /* Gets camera position */ orxCamera_GetPosition(pstCamera, &vPos); /* Camera right? */ if(orxInput_IsActive("CameraRight")) { /* Updates position */ vPos.fX += orx2F(500) * _pstClockInfo->fDT; } /* Camera left? */ if(orxInput_IsActive("CameraLeft")) { /* Updates position */ vPos.fX -= orx2F(500) * _pstClockInfo->fDT; } /* Camera down? */ if(orxInput_IsActive("CameraDown")) { /* Updates position */ vPos.fY += orx2F(500) * _pstClockInfo->fDT; } /* Camera up? */ if(orxInput_IsActive("CameraUp")) { /* Updates position */ vPos.fY -= orx2F(500) * _pstClockInfo->fDT; } /* Updates camera position */ orxCamera_SetPosition(pstCamera, &vPos); /* *** VIEWPORT CONTROLS *** */ /* Gets viewport size */ orxViewport_GetRelativeSize(pstViewport, &fWidth, &fHeight); /* Viewport scale up? */ if(orxInput_IsActive("ViewportScaleUp")) { /* Scales viewport up */ fWidth *= orx2F(1.02f); fHeight*= orx2F(1.02f); } /* Viewport scale down? */ if(orxInput_IsActive("ViewportScaleDown")) { /* Scales viewport down */ fWidth *= orx2F(0.98f); fHeight*= orx2F(0.98f); } /* Updates viewport size */ orxViewport_SetRelativeSize(pstViewport, fWidth, fHeight); /* Gets viewport position */ orxViewport_GetPosition(pstViewport, &fX, &fY); /* Viewport right? */ if(orxInput_IsActive("ViewportRight")) { /* Updates position */ fX += orx2F(500) * _pstClockInfo->fDT; } /* Viewport left? */ if(orxInput_IsActive("ViewportLeft")) { /* Updates position */ fX -= orx2F(500) * _pstClockInfo->fDT; } /* Viewport down? */ if(orxInput_IsActive("ViewportDown")) { /* Updates position */ fY += orx2F(500) * _pstClockInfo->fDT; } /* Viewport up? */ if(orxInput_IsActive("ViewportUp")) { /* Updates position */ fY -= orx2F(500) * _pstClockInfo->fDT; } /* Updates viewport position */ orxViewport_SetPosition(pstViewport, fX, fY); /* *** SOLDIER MOVE UPDATE *** */ /* Gets mouse world position? */ orxRender_GetWorldPosition(orxMouse_GetPosition(&vPos), orxNULL, &vPos); /* Gets object current position */ orxObject_GetWorldPosition(pstSoldier, &vSoldierPos); /* Keeps Z value */ vPos.fZ = vSoldierPos.fZ; /* Moves the soldier under the cursor */ orxObject_SetPosition(pstSoldier, &vPos); }