bool InputHandlerOIS::mouseMoved(const OIS::MouseEvent& arg) { mMouseSampleAccumulator[0] += arg.state.X.rel; mMouseSampleAccumulator[1] += arg.state.Y.rel; mTotalMouseNumSamples[0] += Math::roundToInt(Math::abs((float)arg.state.X.rel)); mTotalMouseNumSamples[1] += Math::roundToInt(Math::abs((float)arg.state.Y.rel)); // Update sample times used for determining sampling rate. But only if something was // actually sampled, and only if this isn't the first non-zero sample. if (mLastMouseUpdateFrame != gTime().getFrameIdx()) { if (arg.state.X.rel != 0 && !Math::approxEquals(mMouseSmoothedAxis[0], 0.0f)) mTotalMouseSamplingTime[0] += gTime().getFrameDelta(); if (arg.state.Y.rel != 0 && !Math::approxEquals(mMouseSmoothedAxis[1], 0.0f)) mTotalMouseSamplingTime[1] += gTime().getFrameDelta(); mLastMouseUpdateFrame = gTime().getFrameIdx(); } RawAxisState zState; zState.abs = (float)arg.state.Z.abs; zState.rel = (float)arg.state.Z.rel; onAxisMoved(0, zState, (UINT32)InputAxis::MouseZ); return true; }
CharacterCollisionFlags PhysXCharacterController::move(const Vector3& displacement) { PxControllerFilters filters; filters.mFilterCallback = this; filters.mFilterFlags = PxQueryFlag::eANY_HIT | PxQueryFlag::eSTATIC | PxQueryFlag::eDYNAMIC | PxQueryFlag::ePREFILTER; filters.mCCTFilterCallback = this; float curTime = gTime().getTime(); float delta = curTime - mLastMoveCall; mLastMoveCall = curTime; PxControllerCollisionFlags collisionFlag = mController->move(toPxVector(displacement), mMinMoveDistance, delta, filters); CharacterCollisionFlags output; if (collisionFlag.isSet(PxControllerCollisionFlag::eCOLLISION_DOWN)) output.set(CharacterCollisionFlag::Down); if (collisionFlag.isSet(PxControllerCollisionFlag::eCOLLISION_UP)) output.set(CharacterCollisionFlag::Up); if (collisionFlag.isSet(PxControllerCollisionFlag::eCOLLISION_SIDES)) output.set(CharacterCollisionFlag::Sides); return output; }
EditorScriptManager::EditorScriptManager() :mEditorAssembly(nullptr), mProgramEdClass(nullptr), mUpdateMethod(nullptr) { SPtr<EditorResourceLoader> resourceLoader = bs_shared_ptr_new<EditorResourceLoader>(); GameResourceManager::instance().setLoader(resourceLoader); loadMonoTypes(); ScriptAssemblyManager::instance().loadAssemblyInfo(EDITOR_ASSEMBLY); ScriptEditorInput::startUp(); ScriptEditorVirtualInput::startUp(); ScriptEditorApplication::startUp(); ScriptHandleSliderManager::startUp(); ScriptGizmoManager::startUp(ScriptAssemblyManager::instance()); HandleManager::startUp<ScriptHandleManager>(ScriptAssemblyManager::instance()); ScriptDragDropManager::startUp(); ScriptProjectLibrary::startUp(); MenuItemManager::startUp(ScriptAssemblyManager::instance()); ToolbarItemManager::startUp(ScriptAssemblyManager::instance()); ScriptFolderMonitorManager::startUp(); ScriptSelection::startUp(); ScriptInspectorUtility::startUp(); mOnDomainLoadConn = ScriptObjectManager::instance().onRefreshDomainLoaded.connect(std::bind(&EditorScriptManager::loadMonoTypes, this)); mOnAssemblyRefreshDoneConn = ScriptObjectManager::instance().onRefreshComplete.connect(std::bind(&EditorScriptManager::onAssemblyRefreshDone, this)); triggerOnInitialize(); // Trigger OnEditorStartUp const String EDITOR_ON_STARTUP = "Program::OnEditorStartUp"; mEditorAssembly->invoke(EDITOR_ON_STARTUP); // Initial update mLastUpdateTime = gTime().getTime(); mUpdateMethod->invoke(nullptr, nullptr); }
InputHandlerOIS::InputHandlerOIS(unsigned int hWnd) :mInputManager(nullptr), mMouse(nullptr), mKeyboard(nullptr), mLastMouseUpdateFrame(0), mTimestampClockOffset(0) { mMouseSampleAccumulator[0] = 0; mMouseSampleAccumulator[1] = 0; mTotalMouseSamplingTime[0] = 1.0f / 125.0f; // Use 125Hz as initial pooling rate for mice mTotalMouseSamplingTime[1] = 1.0f / 125.0f; mTotalMouseNumSamples[0] = 1; mTotalMouseNumSamples[1] = 1; mMouseSmoothedAxis[0] = 0.0f; mMouseSmoothedAxis[1] = 0.0f; mMouseZeroTime[0] = 0.0f; mMouseZeroTime[1] = 0.0f; OIS::ParamList pl; std::ostringstream windowHndStr; windowHndStr << hWnd; pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); #if defined BS_PLATFORM == BS_PLATFORM_WIN32 pl.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_FOREGROUND" ))); pl.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_NONEXCLUSIVE"))); pl.insert(std::make_pair(std::string("w32_keyboard"), std::string("DISCL_FOREGROUND"))); pl.insert(std::make_pair(std::string("w32_keyboard"), std::string("DISCL_NONEXCLUSIVE"))); #elif defined BS_PLATFORM == BS_PLATFORM_LINUX || BS_PLATFORM == BS_PLATFORM_APPLE pl.insert(std::make_pair(std::string("x11_mouse_grab"), std::string("false"))); pl.insert(std::make_pair(std::string("x11_mouse_hide"), std::string("false"))); pl.insert(std::make_pair(std::string("x11_keyboard_grab"), std::string("false"))); pl.insert(std::make_pair(std::string("XAutoRepeatOn"), std::string("true"))); #endif mInputManager = OIS::InputManager::createInputSystem(pl); if (mInputManager->getNumberOfDevices(OIS::OISKeyboard) > 0) { mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject(OIS::OISKeyboard, true)); mKeyboard->setEventCallback(this); } if (mInputManager->getNumberOfDevices(OIS::OISMouse) > 0) { mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject(OIS::OISMouse, true)); mMouse->setEventCallback(this); } UINT32 numGamepads = mInputManager->getNumberOfDevices(OIS::OISJoyStick); for (UINT32 i = 0; i < numGamepads; i++) { mGamepads.push_back(GamepadData()); GamepadData& gamepadData = mGamepads.back(); gamepadData.gamepad = static_cast<OIS::JoyStick*>(mInputManager->createInputObject(OIS::OISJoyStick, true)); gamepadData.listener = bs_new<GamepadEventListener>(this, i); gamepadData.gamepad->setEventCallback(gamepadData.listener); } // OIS reports times since system start but we use time since program start mTimestampClockOffset = gTime().getStartTimeMs(); }
void HandleManager::draw(const SPtr<Camera>& camera) { UINT64 frameIdx = gTime().getFrameIdx(); if (frameIdx != mLastDrawFrameIdx) { mDrawManager->clear(); queueDrawCommands(); mLastDrawFrameIdx = frameIdx; } mDrawManager->draw(camera); }
void DragAndDropManager::_update() { if(!mIsDragInProgress) return; // This generally happens when window loses focus and capture is lost (for example alt+tab) int captureActive = mCaptureActive.load(); if (!captureActive && mCaptureChanged.load() && (gTime().getFrameIdx() > mCaptureChangeFrame.load())) // Wait one frame to insure input (like mouse up) gets a chance to be processed { endDrag(false); mCaptureChanged.store(false); } }
void EditorScriptManager::update() { float curTime = gTime().getTime(); float diff = curTime - mLastUpdateTime; if (diff > EDITOR_UPDATE_RATE) { mUpdateMethod->invoke(nullptr, nullptr); INT32 numUpdates = Math::floorToInt(diff / EDITOR_UPDATE_RATE); mLastUpdateTime += numUpdates * EDITOR_UPDATE_RATE; } ScriptGizmoManager::instance().update(); ScriptDragDropManager::instance().update(); ScriptFolderMonitorManager::instance().update(); ScriptEditorApplication::update(); }
float InputHandlerOIS::smoothMouse(float value, UINT32 idx) { UINT32 sampleCount = 1; float deltaTime = gTime().getFrameDelta(); if (deltaTime < 0.25f) { float secondsPerSample = mTotalMouseSamplingTime[idx] / mTotalMouseNumSamples[idx]; if (value == 0.0f) { mMouseZeroTime[idx] += deltaTime; if (mMouseZeroTime[idx] < secondsPerSample) value = mMouseSmoothedAxis[idx] * deltaTime / secondsPerSample; else mMouseSmoothedAxis[idx] = 0; } else { mMouseZeroTime[idx] = 0; if (mMouseSmoothedAxis[idx] != 0) { if (deltaTime < secondsPerSample * (sampleCount + 1)) value = value * deltaTime / (secondsPerSample * sampleCount); else sampleCount = Math::roundToInt(deltaTime / secondsPerSample); } mMouseSmoothedAxis[idx] = value / sampleCount; } } else { mMouseSmoothedAxis[idx] = 0.0f; mMouseZeroTime[idx] = 0.0f; } return value; }
/* **** This test is designed to test the validity of the three add members of the PolyFit class **** Addition to the PolyFit object is tested with individual datum, gpstk::Vectors of data and **** std::vectors of data. **** These are tested against a least squares polynomial fit that was done by hand **** Please note isSingular, Solution, Degreem N and Solve were tested inderectly **** Please note, I don't know enough about Covariance to test it for the example by hand */ void xPolyFit :: addTest (void) { gpstk::PolyFit<double> AddSingle(2); gpstk::PolyFit<double> AddGVect(2); gpstk::PolyFit<double> AddSVect(2); double data[4] = {0.,2.,4.,-1.}; double time[4] = {3.,3.,4.,2.,}; gpstk::Vector<double> gData(4,0.); gData[0] = 0.; gData[1] = 2.; gData[2] = 4.; gData[3] = -1.; gpstk::Vector<double> gTime(4,0.); gTime[0] = 3.; gTime[1] = 3.; gTime[2] = 4.; gTime[3] = 2.; std::vector<double> vData(4,0.); vData[0] = 0.; vData[1] = 2.; vData[2] = 4.; vData[3] = -1.; std::vector<double> vTime(4,0.); vTime[0] = 3.; vTime[1] = 3.; vTime[2] = 4.; vTime[3] = 2.; //Done by hand gpstk::Vector<double> ExpSolution(2,0.); ExpSolution[0] = 152./59; ExpSolution[1] = 20./59; for (int i =0;i<4;i++) { AddSingle.Add(time[i],data[i]); } gpstk::Vector<double> SingleSolution = AddSingle.Solution(); CPPUNIT_ASSERT_DOUBLES_EQUAL(ExpSolution[0],SingleSolution[0],1e-6); CPPUNIT_ASSERT_DOUBLES_EQUAL(ExpSolution[1],SingleSolution[1],1e-6); CPPUNIT_ASSERT_EQUAL((unsigned) 4, AddSingle.N()); CPPUNIT_ASSERT_EQUAL((unsigned) 2, AddSingle.Degree()); CPPUNIT_ASSERT_EQUAL(false, AddSingle.isSingular()); //Add on an unweighted sample, N should increase but everything else should be the same AddSingle.Add(7.,20.,0); gpstk::Vector<double> SingleSolution2 = AddSingle.Solution(); CPPUNIT_ASSERT_DOUBLES_EQUAL(ExpSolution[0],SingleSolution2[0],1e-6); CPPUNIT_ASSERT_DOUBLES_EQUAL(ExpSolution[1],SingleSolution2[1],1e-6); CPPUNIT_ASSERT_EQUAL((unsigned) 5, AddSingle.N()); CPPUNIT_ASSERT_EQUAL((unsigned) 2, AddSingle.Degree()); CPPUNIT_ASSERT_EQUAL(false, AddSingle.isSingular()); AddGVect.Add(gTime,gData); gpstk::Vector<double> gVectSolution = AddGVect.Solution(); CPPUNIT_ASSERT_DOUBLES_EQUAL(ExpSolution[0],gVectSolution[0],1e-6); CPPUNIT_ASSERT_DOUBLES_EQUAL(ExpSolution[1],gVectSolution[1],1e-6); CPPUNIT_ASSERT_EQUAL((unsigned) 4, AddGVect.N()); CPPUNIT_ASSERT_EQUAL((unsigned) 2, AddGVect.Degree()); CPPUNIT_ASSERT_EQUAL(false, AddGVect.isSingular()); AddSVect.Add(vTime,vData); gpstk::Vector<double> sVectSolution = AddSVect.Solution(); CPPUNIT_ASSERT_DOUBLES_EQUAL(ExpSolution[0],sVectSolution[0],1e-6); CPPUNIT_ASSERT_DOUBLES_EQUAL(ExpSolution[1],sVectSolution[1],1e-6); CPPUNIT_ASSERT_EQUAL((unsigned) 4, AddSVect.N()); CPPUNIT_ASSERT_EQUAL((unsigned) 2, AddSVect.Degree()); CPPUNIT_ASSERT_EQUAL(false, AddSVect.isSingular()); }
void CameraFlyer::update() { bool goingForward = gVirtualInput().isButtonHeld(mMoveForward); bool goingBack = gVirtualInput().isButtonHeld(mMoveBack); bool goingLeft = gVirtualInput().isButtonHeld(mMoveLeft); bool goingRight = gVirtualInput().isButtonHeld(mMoveRight); bool fastMove = gVirtualInput().isButtonHeld(mFastMove); bool camRotating = gVirtualInput().isButtonHeld(mRotateCam); if (camRotating != mLastButtonState) { if (camRotating) Cursor::instance().hide(); else Cursor::instance().show(); mLastButtonState = camRotating; } float frameDelta = gTime().getFrameDelta(); if (camRotating) { mYaw += Degree(gVirtualInput().getAxisValue(mHorizontalAxis) * ROTATION_SPEED * frameDelta); mPitch += Degree(gVirtualInput().getAxisValue(mVerticalAxis) * ROTATION_SPEED * frameDelta); mYaw = wrapAngle(mYaw); mPitch = wrapAngle(mPitch); Quaternion yRot; yRot.fromAxisAngle(Vector3::UNIT_Y, Radian(mYaw)); Quaternion xRot; xRot.fromAxisAngle(Vector3::UNIT_X, Radian(mPitch)); Quaternion camRot = yRot * xRot; camRot.normalize(); SO()->setRotation(camRot); } Vector3 direction = Vector3::ZERO; if (goingForward) direction += SO()->getForward(); if (goingBack) direction -= SO()->getForward(); if (goingRight) direction += SO()->getRight(); if (goingLeft) direction -= SO()->getRight(); if (direction.squaredLength() != 0) { direction.normalize(); float multiplier = 1.0f; if (fastMove) multiplier = FAST_MODE_MULTIPLIER; mCurrentSpeed = Math::clamp(mCurrentSpeed + ACCELERATION * frameDelta, START_SPEED, TOP_SPEED); mCurrentSpeed *= multiplier; } else { mCurrentSpeed = 0.0f; } float tooSmall = std::numeric_limits<float>::epsilon(); if (mCurrentSpeed > tooSmall) { Vector3 velocity = direction * mCurrentSpeed; SO()->move(velocity * frameDelta); } }
void CAudioSource::update() { Vector3 worldPos = SO()->getWorldPosition(); mVelocity = (worldPos - mLastPosition) / gTime().getFrameDelta(); mLastPosition = worldPos; }
void DragAndDropManager::mouseCaptureChanged() { mCaptureActive.fetch_xor(1); // mCaptureActive = !mCaptureActive; mCaptureChanged.store(true); mCaptureChangeFrame.store(gTime().getFrameIdx()); }
float ScriptTime::internal_getRealElapsed() { return gTime().getTime(); }
void CameraFlyer::update() { // Check if any movement or rotation keys are being held bool goingForward = gVirtualInput().isButtonHeld(mMoveForward); bool goingBack = gVirtualInput().isButtonHeld(mMoveBack); bool goingLeft = gVirtualInput().isButtonHeld(mMoveLeft); bool goingRight = gVirtualInput().isButtonHeld(mMoveRight); bool fastMove = gVirtualInput().isButtonHeld(mFastMove); bool camRotating = gVirtualInput().isButtonHeld(mRotateCam); // If switch to or from rotation mode, hide or show the cursor if (camRotating != mLastButtonState) { if (camRotating) Cursor::instance().hide(); else Cursor::instance().show(); mLastButtonState = camRotating; } // If camera is rotating, apply new pitch/yaw rotation values depending on the amount of rotation from the // vertical/horizontal axes. float frameDelta = gTime().getFrameDelta(); if (camRotating) { mYaw += Degree(gVirtualInput().getAxisValue(mHorizontalAxis) * ROTATION_SPEED * frameDelta); mPitch += Degree(gVirtualInput().getAxisValue(mVerticalAxis) * ROTATION_SPEED * frameDelta); mYaw = wrapAngle(mYaw); mPitch = wrapAngle(mPitch); Quaternion yRot; yRot.fromAxisAngle(Vector3::UNIT_Y, Radian(mYaw)); Quaternion xRot; xRot.fromAxisAngle(Vector3::UNIT_X, Radian(mPitch)); Quaternion camRot = yRot * xRot; camRot.normalize(); SO()->setRotation(camRot); } // If the movement button is pressed, determine direction to move in Vector3 direction = Vector3::ZERO; if (goingForward) direction += SO()->getForward(); if (goingBack) direction -= SO()->getForward(); if (goingRight) direction += SO()->getRight(); if (goingLeft) direction -= SO()->getRight(); // If a direction is chosen, normalize it to determine final direction. if (direction.squaredLength() != 0) { direction.normalize(); // Apply fast move multiplier if the fast move button is held. float multiplier = 1.0f; if (fastMove) multiplier = FAST_MODE_MULTIPLIER; // Calculate current speed of the camera mCurrentSpeed = Math::clamp(mCurrentSpeed + ACCELERATION * frameDelta, START_SPEED, TOP_SPEED); mCurrentSpeed *= multiplier; } else { mCurrentSpeed = 0.0f; } // If the current speed isn't too small, move the camera in the wanted direction float tooSmall = std::numeric_limits<float>::epsilon(); if (mCurrentSpeed > tooSmall) { Vector3 velocity = direction * mCurrentSpeed; SO()->move(velocity * frameDelta); } }
float ScriptTime::internal_getFrameDelta() { return gTime().getFrameDelta(); }
UINT64 ScriptTime::internal_getPrecise() { return gTime().getTimePrecise(); }
UINT64 ScriptTime::internal_getFrameNumber() { return gTime().getFrameIdx(); }