void GOComponent::NotifyOwnerGO() { GameObjectPtr ownerGO = mOwnerGO.lock(); if (!ownerGO.get()) return; UpdatePosition(ownerGO->GetGlobalPosition()); UpdateOrientation(ownerGO->GetGlobalOrientation()); UpdateScale(ownerGO->GetGlobalScale()); }
void Projectile_Bazooka::SetVelocity(const Vec2f& newVelocity) { Projectile::SetVelocity(newVelocity); UpdateOrientation(); }
void GOComponent::ReceiveMessage(Msg &msg) { if (msg.typeID == GameObject::MessageIDs::UPDATE_COMPONENT_TRANSFORM) { GameObjectPtr owner = mOwnerGO.lock(); if (owner) { UpdatePosition(owner->GetGlobalPosition()); UpdateOrientation(owner->GetGlobalOrientation()); } } if (msg.typeID == GameObject::MessageIDs::UPDATE_COMPONENT_POSITION) UpdatePosition(msg.params.GetValue<Ogre::Vector3>(0)); else if (msg.typeID == GameObject::MessageIDs::UPDATE_COMPONENT_ORIENTATION) UpdateOrientation(msg.params.GetValue<Ogre::Quaternion>(0)); else if (msg.typeID == GameObject::MessageIDs::UPDATE_COMPONENT_SCALE) UpdateScale(msg.params.GetValue<Ogre::Vector3>(0)); }
bool Projectile_Bazooka::Update(float elapsedTime, const Vec2f& gravity, const Vec2f& wind) { bool result = Projectile::Update(elapsedTime, gravity, wind); UpdateOrientation(); return result; }
void FPSCamera::SetPose(float3 posCamera, float yaw, float pitch) { m_pos = posCamera; m_yaw = yaw; m_pitch = pitch; // Update matrices UpdateOrientation(); UpdateWorldToClip(); }
void ThirdPersonCamera::Update() { real dt = TheTimer::Instance()->GetDT(); UpdateOrientation(dt); if (m_springsEnabled) UpdateViewMatrix(dt); else UpdateViewMatrix(); }
void MayaCamera::SetPose(float3 posTarget, float yaw, float pitch, float radius) { m_posTarget = posTarget; m_yaw = yaw; m_pitch = pitch; m_radius = radius; // Update matrices UpdateOrientation(); UpdateWorldToClip(); }
//------------------------------------------------------------------------ void CGunTurret::Update(SEntityUpdateContext &ctx, int update) { FUNCTION_PROFILER(gEnv->pSystem, PROFILE_GAME); if(m_frozen) return; CWeapon::Update(ctx, update); if(update==eIUS_FireMode && m_fm2) m_fm2->Update(ctx.fFrameTime, ctx.nFrameID); if(update!=eIUS_General) return; if(IsServer()) ServerUpdate(ctx,update); UpdateOrientation(ctx.fFrameTime); // rotate turret towards target, adhering to angle limits if(g_pGameCVars->i_debug_turrets == eGTD_Search) { DrawCircle(GetEntity()->GetWorldPos(), m_turretparams.mg_range); } // /* if(InternalIsFiring(false)) { IEntity* pCurrentTarget = gEnv->pEntitySystem->GetEntity(m_targetId); if(!pCurrentTarget) return; CSingle* pFM = (CSingle*)GetFireMode(0); Vec3 hit = pFM->GetProbableHit(2000.0f); Vec3 dir = pFM->NetGetFiringDir(hit, pFM->NetGetFiringPos(hit)); Vec3 pos = GetTargetPos(pCurrentTarget); Vec3 wpos = GetWeaponPos(); Vec3 tdir = (pos-wpos).normalized(); float angcos = tdir*dir; float ang = RAD2DEG(cry_acosf(angcos)); if(ang>2.0f) { CryLog("%X Shooting while not in cone, %.3f",GetEntity()->GetId(),ang); } float yaw, pitch; GetTargetAngles(pos,yaw,pitch); if(!IsAiming(pos,5.0f)) { CryLog("Turret %X firing at %X. Goal %.2f %.2f, target %.2f %.2f, diff %.2f %.2f",GetEntity()->GetId(),m_targetId,m_goalYaw,m_goalPitch,yaw,pitch,cry_fabsf(m_goalYaw-yaw),cry_fabsf(m_goalPitch-pitch)); } }*/ }
void FPSCamera::LookAt(float3 posCamera, float3 posTarget) { m_pos = posCamera; setTranslation(&m_viewToWorld, m_pos); // Calculate angles to look at posTarget float3 vecToTarget = posTarget - posCamera; ASSERT_WARN(!all(isnear(vecToTarget, 0.0f))); vecToTarget = normalize(vecToTarget); m_yaw = atan2f(-vecToTarget.z, vecToTarget.x); m_pitch = asinf(vecToTarget.y); // Update matrices UpdateOrientation(); UpdateWorldToClip(); }
void Transform::UpdateTransformMatrix() { if (m_isDirty) { UpdateOrientation(); m_direction = m_orientation * m_worldZ; m_upVector = m_orientation * m_worldY; m_rightVector = m_orientation * m_worldX; auto const T = glm::translate(glm::mat4(1.0), m_translation); auto const R = glm::mat4_cast(m_orientation) * glm::mat4(1.0); auto const S = glm::scale(glm::mat4(1.0), { m_scale }); m_transformMatrix = T * R * S; m_isDirty = false; } }
void MayaCamera::LookAt(float3 posCamera, float3 posTarget) { m_posTarget = posTarget; m_pos = posCamera; // Calculate angles to look at posTarget float3 vecToTarget = posTarget - posCamera; ASSERT_WARN(!all(isnear(vecToTarget, 0.0f))); m_radius = length(vecToTarget); vecToTarget /= m_radius; m_yaw = atan2f(-vecToTarget.z, vecToTarget.x); m_pitch = asinf(vecToTarget.y); // Update matrices UpdateOrientation(); m_pos = m_posTarget + m_radius * m_viewToWorld[2].xyz; setTranslation(&m_viewToWorld, m_pos); UpdateWorldToClip(); }
void AndroidCardboardController::Update() { UpdateOrientation(); UpdateButtons(); }
/**************************************************************************** Function: WORD GOLDrawCallback( void ) Description: This callback is performed at the beginning of the GOLDraw() function. Processing that needs to be done on a regular basis and is not triggered by a message should be done here. Precondition: None Parameters: None Returns: None Remarks: All graphic control adding and removing must be done from this function, not from the message callback. ***************************************************************************/ WORD GOLDrawCallback( void ) { switch (screenState) { // Display Start-up screen and play Welcome message case SCREEN_START: // Display the start up screen PictCreate( ID_ICON, // ID 0,0,GetMaxX(),GetMaxY(), // dimension PICT_DRAW, // will be displayed, has frame 1, // scale factor is x1 picture, // bitmap NULL ); // default GOL scheme screenState = SCREEN_START_DELAY; break; case SCREEN_START_DELAY: if(enableSoundFlag) { while(speakerBusy()); // Speaker: Welcome to MPLAB Starter Kit for PIC24H MCU Demonstration speakerActivate(SPEECH_ADDR_WELCOME, SPEECH_SIZE_WELCOME); Delay(6000); } // Initialize the reference timer TickInit(); // Initialize the accelerometer AccelerometerInit(); screenState = SCREEN_DISPLAY_MAIN; break; // Display Main screen case SCREEN_DISPLAY_MAIN: ShowScreenMain(); screenState = SCREEN_MAIN; displayChangeTime = tick; break; case SCREEN_MAIN: break; // Display Accelerometer Tri-axial Outputs graph case SCREEN_DISPLAY_GRAPH: ShowScreenGraph(); screenState = SCREEN_GRAPH; displayChangeTime = tick; break; case SCREEN_GRAPH: AccelerometerStop(); UpdateGraph(); break; // Display connect External Sensor information case SCREEN_DISPLAY_ES_INFO: ShowScreenESInfo(); screenState = SCREEN_ES_INFO; displayChangeTime = tick; break; case SCREEN_ES_INFO: Delay(2000); screenState = SCREEN_DISPLAY_ES_GRAPH; break; // Display External Sensor output graph case SCREEN_DISPLAY_ES_GRAPH: AccelerometerStop(); ShowScreenESGraph(); initESADC(); screenState = SCREEN_ES_GRAPH; displayChangeTime = tick; break; case SCREEN_ES_GRAPH: UpdateESGraph(); break; // Display Orientation screen case SCREEN_DISPLAY_ORIENTATION: ShowScreenOrientation(); screenState = SCREEN_ORIENTATION; displayChangeTime = tick; break; case SCREEN_ORIENTATION: UpdateOrientation(); break; // Display Games screen case SCREEN_DISPLAY_GAMES: ShowScreenGames(); screenState = SCREEN_GAMES; displayChangeTime = tick; break; case SCREEN_GAMES: break; // Display Bomber Jet screen case SCREEN_DISPLAY_JET: ShowScreenJet(); AccelerometerStop(); AccelerometerInit(); if(enableSoundFlag) { while(speakerBusy()); speakerActivate(SPEECH_ADDR_START, SPEECH_SIZE_START); while(speakerBusy()); } screenState = SCREEN_JET; displayChangeTime = tick; break; case SCREEN_JET: DrawJet(); break; // Display Snake screen case SCREEN_DISPLAY_SNAKE: ShowScreenSnake(); AccelerometerStop(); AccelerometerInit(); if(enableSoundFlag) { while(speakerBusy()); speakerActivate(SPEECH_ADDR_START, SPEECH_SIZE_START); while(speakerBusy()); } screenState = SCREEN_SNAKE; displayChangeTime = tick; break; case SCREEN_SNAKE: DrawSnake(); break; // Display Score screen case SCREEN_DISPLAY_SCORE: ShowScreenScore(); if(enableSoundFlag) { while(speakerBusy()); speakerActivate(SPEECH_ADDR_GAME, SPEECH_SIZE_GAME); while(speakerBusy()); speakerActivate(SPEECH_ADDR_OVER, SPEECH_SIZE_OVER); } displayChangeTime = tick; screenState = SCREEN_SCORE; break; case SCREEN_SCORE: break; } return 1; // Callback complete }
void UpdateAI(const uint32 diff) { // Falled to water in out of platform = die CheckPlayersInWater(); if (!UpdateVictim()) return; events.Update(diff); switch (events.ExecuteEvent()) { case EVENT_HARD_STARE: if (me->getVictim()) { DoPlaySoundToSet(me, 35334); // wound DoCast(me->getVictim(),SPELL_HARD_STARE); } events.ScheduleEvent(EVENT_HARD_STARE, 13000); break; case EVENT_GAZE: { Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0, 2.0f, true); if (!target) if (!me->HasUnitState(UNIT_STATE_CASTING)) DoCast(SPELL_GAZE); events.ScheduleEvent(EVENT_GAZE, 2000); break; } case EVENT_BERSERK: events.CancelEventGroup(0); // clear all events me->AI()->Talk(SAY_BERSERK); DoCast(SPELL_BERSERK_KILLALL); break; // Spectrum phase start case EVENT_LIGHT_SPECTRUM_SAY_SUMMON: FogKilled = 0; me->AI()->Talk(SAY_SUMMON_SPECTRUM); SummonSomeCreatures(RED_FOG, 3, 10.0f); // 3 red fog SummonSomeCreatures(BLUE_FOG, 1, 10.0f); // 1 blue fog events.ScheduleEvent(EVENT_LIGHT_SPECTRUM, 3000); break; case EVENT_LIGHT_SPECTRUM: me->AI()->Talk(SAY_SPECTRUM_INF); SummonBeamsEye(); break; // Spectrum phase end // Disintegration Beam phase start case EVENT_MAZE_TIME: Maze(true); events.ScheduleEvent(EVENT_MAZE_ORIENTATION, 5000); events.ScheduleEvent(EVENT_MAZE_END, 47000); events.ScheduleEvent(EVENT_MIND_DAGGERS, 6000); SendMazeToEyes(true); break; case EVENT_MAZE_ORIENTATION: UpdateOrientation(); TryKillPlayerInFront(); events.ScheduleEvent(EVENT_MAZE_ORIENTATION, 200); break; case EVENT_MAZE_END: Maze(false); SendMazeToEyes(false); events.ScheduleEvent(EVENT_LIGHT_SPECTRUM_SAY_SUMMON, 40000); break; case EVENT_MIND_DAGGERS: DoCast(SPELL_MIND_DAGGERS); events.ScheduleEvent(EVENT_MIND_DAGGERS, 6000); break; // Disintegration Beam phase end default: break; } if (!me->HasUnitState(UNIT_STATE_CASTING)) DoMeleeAttackIfReady(); }
void MayaCamera::Update(float timestep) { (void)timestep; // Track mouse motion int2 mousePos; GetCursorPos((POINT *)&mousePos); int2 mouseMove = mousePos - m_mousePosPrev; m_mousePosPrev = mousePos; // Handle mouse rotation if (m_mbuttonCur == MBUTTON_Left) { m_yaw -= m_rotateSpeed * mouseMove.x; m_yaw = modPositive(m_yaw, 2.0f*pi); m_pitch -= m_rotateSpeed * mouseMove.y; m_pitch = clamp(m_pitch, -0.5f*pi, 0.5f*pi); } // Retrieve controller state XINPUT_STATE controllerState = {}; float2 controllerLeftStick(0.0f), controllerRightStick(0.0f); float controllerLeftTrigger = 0.0f, controllerRightTrigger = 0.0f; if (m_controllerPresent) { // Look out for disconnection if (XInputGetState(0, &controllerState) == ERROR_SUCCESS) { // Decode axes and apply dead zones controllerLeftTrigger = float(max(0, controllerState.Gamepad.bLeftTrigger - XINPUT_GAMEPAD_TRIGGER_THRESHOLD)) / float(255 - XINPUT_GAMEPAD_TRIGGER_THRESHOLD); controllerRightTrigger = float(max(0, controllerState.Gamepad.bRightTrigger - XINPUT_GAMEPAD_TRIGGER_THRESHOLD)) / float(255 - XINPUT_GAMEPAD_TRIGGER_THRESHOLD); controllerLeftStick = float2(controllerState.Gamepad.sThumbLX, controllerState.Gamepad.sThumbLY); float lengthLeft = length(controllerLeftStick); if (lengthLeft > XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE) controllerLeftStick = (controllerLeftStick / lengthLeft) * (lengthLeft - XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE) / float(32768 - XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE); else controllerLeftStick = float2(0.0f); controllerRightStick = float2(controllerState.Gamepad.sThumbRX, controllerState.Gamepad.sThumbRY); float lengthRight = length(controllerRightStick); if (lengthRight > XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE) controllerRightStick = (controllerRightStick / lengthRight) * (lengthRight - XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE) / float(32768 - XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE); else controllerRightStick = float2(0.0f); } else { m_controllerPresent = false; } } // Handle controller rotation if (m_controllerPresent) { m_yaw -= m_controllerRotateSpeed * controllerRightStick.x * abs(controllerRightStick.x) * timestep; m_yaw = modPositive(m_yaw, 2.0f*pi); m_pitch += m_controllerRotateSpeed * controllerRightStick.y * abs(controllerRightStick.y) * timestep; m_pitch = clamp(m_pitch, -0.5f*pi, 0.5f*pi); } UpdateOrientation(); // Handle zoom if (m_mbuttonCur == MBUTTON_Right) { m_radius *= expf(mouseMove.y * m_zoomSpeed); } m_radius *= expf(-m_wheelDelta * m_zoomWheelSpeed); m_wheelDelta = 0; // Handle controller zoom if (m_controllerPresent && !(controllerState.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER)) { m_radius *= expf(-controllerLeftStick.y * abs(controllerLeftStick.y) * m_controllerZoomSpeed * timestep); } // Handle motion of target point if (m_mbuttonCur == MBUTTON_Middle) { m_posTarget -= m_rotateSpeed * mouseMove.x * m_radius * m_viewToWorld[0].xyz; m_posTarget += m_rotateSpeed * mouseMove.y * m_radius * m_viewToWorld[1].xyz; } // Handle controller motion of target point if (m_controllerPresent && (controllerState.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER)) { float3 localVelocity(0.0f); localVelocity.x = controllerLeftStick.x * abs(controllerLeftStick.x); localVelocity.y = square(controllerRightTrigger) - square(controllerLeftTrigger); localVelocity.z = -controllerLeftStick.y * abs(controllerLeftStick.y); m_posTarget += xfmVector(localVelocity, m_viewToWorld) * (m_radius * m_controllerMoveSpeed * timestep); } // Calculate remaining matrices m_pos = m_posTarget + m_radius * m_viewToWorld[2].xyz; setTranslation(&m_viewToWorld, m_pos); UpdateWorldToClip(); }
void FPSCamera::Update(float timestep) { // Track mouse motion int2 mousePos; GetCursorPos((POINT *)&mousePos); int2 mouseMove = mousePos - m_mousePosPrev; m_mousePosPrev = mousePos; // Handle mouse rotation if (m_mbuttonActivate == MBUTTON_None || m_mbuttonCur == m_mbuttonActivate) { m_yaw -= m_rotateSpeed * mouseMove.x; m_yaw = modPositive(m_yaw, 2.0f*pi); m_pitch -= m_rotateSpeed * mouseMove.y; m_pitch = clamp(m_pitch, -0.5f*pi, 0.5f*pi); } // Retrieve controller state XINPUT_STATE controllerState = {}; float2 controllerLeftStick(0.0f), controllerRightStick(0.0f); float controllerLeftTrigger = 0.0f, controllerRightTrigger = 0.0f; if (m_controllerPresent) { // Look out for disconnection if (XInputGetState(0, &controllerState) == ERROR_SUCCESS) { // Decode axes and apply dead zones controllerLeftTrigger = float(max(0, controllerState.Gamepad.bLeftTrigger - XINPUT_GAMEPAD_TRIGGER_THRESHOLD)) / float(255 - XINPUT_GAMEPAD_TRIGGER_THRESHOLD); controllerRightTrigger = float(max(0, controllerState.Gamepad.bRightTrigger - XINPUT_GAMEPAD_TRIGGER_THRESHOLD)) / float(255 - XINPUT_GAMEPAD_TRIGGER_THRESHOLD); controllerLeftStick = float2(controllerState.Gamepad.sThumbLX, controllerState.Gamepad.sThumbLY); float lengthLeft = length(controllerLeftStick); if (lengthLeft > XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE) controllerLeftStick = (controllerLeftStick / lengthLeft) * (lengthLeft - XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE) / float(32768 - XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE); else controllerLeftStick = float2(0.0f); controllerRightStick = float2(controllerState.Gamepad.sThumbRX, controllerState.Gamepad.sThumbRY); float lengthRight = length(controllerRightStick); if (lengthRight > XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE) controllerRightStick = (controllerRightStick / lengthRight) * (lengthRight - XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE) / float(32768 - XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE); else controllerRightStick = float2(0.0f); } else { m_controllerPresent = false; } } // Handle controller rotation if (m_controllerPresent) { m_yaw -= m_controllerRotateSpeed * controllerRightStick.x * abs(controllerRightStick.x) * timestep; m_yaw = modPositive(m_yaw, 2.0f*pi); m_pitch += m_controllerRotateSpeed * controllerRightStick.y * abs(controllerRightStick.y) * timestep; m_pitch = clamp(m_pitch, -0.5f*pi, 0.5f*pi); } UpdateOrientation(); // Handle translation // !!!UNDONE: acceleration based on how long you've been holding the button, // to make fine motions easier? float moveStep = timestep * m_moveSpeed; // !!!UNDONE: move keyboard tracking into an input system that respects focus, etc. if (GetAsyncKeyState(VK_SHIFT) || (controllerState.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER)) moveStep *= 3.0f; if (GetAsyncKeyState('W')) m_pos -= m_viewToWorld[2].xyz * moveStep; if (GetAsyncKeyState('S')) m_pos += m_viewToWorld[2].xyz * moveStep; if (GetAsyncKeyState('A')) m_pos -= m_viewToWorld[0].xyz * moveStep; if (GetAsyncKeyState('D')) m_pos += m_viewToWorld[0].xyz * moveStep; if (GetAsyncKeyState('E')) m_pos += m_viewToWorld[1].xyz * moveStep; if (GetAsyncKeyState('C')) m_pos -= m_viewToWorld[1].xyz * moveStep; if (m_controllerPresent) { float3 localVelocity(0.0f); localVelocity.x = controllerLeftStick.x * abs(controllerLeftStick.x); localVelocity.y = square(controllerRightTrigger) - square(controllerLeftTrigger); localVelocity.z = -controllerLeftStick.y * abs(controllerLeftStick.y); m_pos += xfmVector(localVelocity, m_viewToWorld) * (moveStep * m_controllerMoveSpeed); } // Calculate remaining matrices setTranslation(&m_viewToWorld, m_pos); UpdateWorldToClip(); }