void CameraController::closeCursorPosition() { ICursorControl* cursor = _game->getDevice()->getCursorControl(); vector2df position = cursor->getRelativePosition(); if (closeCoordinate(position.X) || closeCoordinate(position.Y)) { cursor->setPosition(position); _previousMousePosition = position; } }
void PlayerInstance :: UpdateRotation() { ICursorControl* cursorControl = IRR->device->getCursorControl(); position2d<f32> cursorPos = cursorControl->getRelativePosition(); static float rotateSpeed = 4.0f; if(firstRot) // it checks if it is the first time camera rotates and than fill tables with proper values { rotX[0] = rotX[1] = 0.5f - cursorPos.X; rotY[0] = rotY[1] = 0.5f - cursorPos.Y; firstRot = false; } // puts values from this frame into table rotX[2] = 0.5f - cursorPos.X; rotY[2] = 0.5f - cursorPos.Y; // If any change in cursorPos this frame: if (cursorPos.X < 0.5 || cursorPos.X > 0.5 || cursorPos.Y < 0.5 || cursorPos.Y > 0.5 ) { // Rotate Y Axis: yRotation -= (rotX[0]+rotX[1]+rotX[2])/3 * rotateSpeed; // Rotate X Axis: xRotation -= (rotY[0]+rotY[1]+rotY[2])/3 * rotateSpeed; // Restrict X Axis: if(xRotation > PI/2.1f) xRotation = PI/2.1f; if(xRotation < -PI/2.1f) xRotation = -PI/2.1f; cursorControl->setPosition(0.5f, 0.5f); rotX[0] = rotX[1]; // finaly we move values to make room for a new ones rotX[1] = rotX[2]; rotY[0] = rotY[1]; rotY[1] = rotY[2]; } lookAtHeading = IRR->RotateVectorAboutVector(vector3df(1,0,0), vector3df(0,1,0), yRotation); vector3df newTangent = lookAtHeading.crossProduct(vector3df(0,-1,0)); newTangent.Y = 0; newTangent.normalize(); lookAtHeading = IRR->RotateVectorAboutVector(lookAtHeading, newTangent, xRotation); // + camRecoil.X camUp = lookAtHeading.crossProduct(newTangent); SetHeading(vector3df(lookAtHeading.X, 0, lookAtHeading.Z)); }