static orxSTATUS orxFASTCALL Run() { orxSTATUS eResult = orxSTATUS_SUCCESS; orxVECTOR vMousePos, vGravity; /* Updates generator's status */ orxObject_Enable(spstGenerator, orxInput_IsActive("Spawn")); /* Gets mouse position in world space */ if(orxRender_GetWorldPosition(orxMouse_GetPosition(&vMousePos), orxNULL, &vMousePos)) { orxVECTOR vGeneratorPos; /* Gets generator position */ orxObject_GetPosition(spstGenerator, &vGeneratorPos); /* Keeps generator's Z coord */ vMousePos.fZ = vGeneratorPos.fZ; /* Updates generator's position */ orxObject_SetPosition(spstGenerator, &vMousePos); } /* Gets gravity vector from input */ orxVector_Set(&vGravity, orxInput_GetValue("GravityX"), -orxInput_GetValue("GravityY"), orxFLOAT_0); /* Significant enough? */ if(orxVector_GetSquareSize(&vGravity) > orx2F(0.5f)) { static orxVECTOR svSmoothedGravity = { orx2F(0.0f), orx2F(-1.0f), orx2F(0.0f) }; /* Gets smoothed gravity from new value (low-pass filter) */ orxVector_Lerp(&svSmoothedGravity, &svSmoothedGravity, &vGravity, orx2F(0.05f)); /* Updates camera rotation */ orxCamera_SetRotation(orxViewport_GetCamera(spstViewport), orxMATH_KF_PI_BY_2 + orxVector_FromCartesianToSpherical(&vGravity, &svSmoothedGravity)->fTheta); } // Is quit action active? if(orxInput_IsActive("Quit")) { // Logs orxLOG("Quit action triggered, exiting!"); // Sets return value to orxSTATUS_FAILURE, meaning we want to exit eResult = orxSTATUS_FAILURE; } return eResult; }
/** 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); }