bool Camera::OnSpecialKeyboard(int Key) { bool Ret = false; switch(Key) { case GLUT_KEY_UP: { pitch(Radian(Degree(5))); Ret = true; } break; case GLUT_KEY_DOWN: { pitch(Radian(Degree(-5))); Ret = true; } break; case GLUT_KEY_LEFT: { yaw(Radian(Degree(-5))); Ret = true; } break; case GLUT_KEY_RIGHT: { yaw(Radian(Degree(5))); Ret = true; } break; } return Ret; }
void OnUpdate(float dt) { XINPUT_STATE inputState = { 0, }; if (XInputGetState(0, &inputState) == ERROR_SUCCESS) { if (inputState.Gamepad.sThumbLX < XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE && inputState.Gamepad.sThumbLX > -XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE) inputState.Gamepad.sThumbLX = 0; if (inputState.Gamepad.sThumbLY < XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE && inputState.Gamepad.sThumbLY > -XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE) inputState.Gamepad.sThumbLY = 0; if (inputState.Gamepad.sThumbRX < XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE && inputState.Gamepad.sThumbRX > -XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE) inputState.Gamepad.sThumbRX = 0; if (inputState.Gamepad.sThumbRY < XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE && inputState.Gamepad.sThumbRY > -XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE) inputState.Gamepad.sThumbRY = 0; if (inputState.Gamepad.sThumbLY > 0) walk(30 * dt); else if (inputState.Gamepad.sThumbLY < 0) walk(-30 * dt); if (inputState.Gamepad.sThumbLX > 0) strafe(30 * dt); else if (inputState.Gamepad.sThumbLX < 0) strafe(-30 * dt); if (inputState.Gamepad.sThumbRY > 0) pitch(0.5f * dt); else if (inputState.Gamepad.sThumbRY < 0) pitch(-0.5f * dt); if (inputState.Gamepad.sThumbRX > 0) yaw(0.5f * dt); else if (inputState.Gamepad.sThumbRX < 0) yaw(-0.5f * dt); } }
//////////////////////////////////////////////////////////////////////////////////////// // Convert From {Picth, Yaw, Roll} (RADIANS) //////////////////////////////////////////////////////////////////////////////////////// void CVec3::AngToVecRad(CVec3& Right, CVec3& Up) { float sr, sp, sy, cr, cp, cy; sy = sinf(yaw()); cy = cosf(yaw()); sp = sinf(pitch()); cp = cosf(pitch()); sr = sinf(roll()); cr = cosf(roll()); // Forward Vector Is Stored Here v[0] = cp * cy; v[1] = cp * sy; v[2] = -sp; // Calculate Right Right.v[0] = (-1 * sr * sp * cy + -1 * cr * -sy); Right.v[1] = (-1 * sr * sp * sy + -1 * cr * cy); Right.v[2] = -1 * sr * cp; // Calculate Up Up.v[0] = (cr * sp * cy + -sr * -sy); Up.v[1] = (cr * sp * sy + -sr * cy); Up.v[2] = cr * cp; }
//////////////////////////////////////////////////////////////////////////////////////// // Convert From {Picth, Yaw} (RADIANS) //////////////////////////////////////////////////////////////////////////////////////// void CVec3::AngToVecRad() { float sp, sy, cp, cy; sy = sinf(yaw()); cy = cosf(yaw()); sp = sinf(pitch()); cp = cosf(pitch()); v[0] = cp * cy; v[1] = cp * sy; v[2] = -sp; }
void Camera::update(float timeDelta) { if(EventDispatcher::Get()->keys[KEY_UP]) walk(10.0f * timeDelta); if(EventDispatcher::Get()->keys[KEY_DOWN]) walk(-10.0f * timeDelta); if(EventDispatcher::Get()->keys[KEY_LEFT]) strafe(-10.0f * timeDelta); if(EventDispatcher::Get()->keys[KEY_RIGHT]) strafe(10.0f * timeDelta); if(EventDispatcher::Get()->keys[KEY_N]) yaw(-1.0f * timeDelta); if(EventDispatcher::Get()->keys[KEY_M]) yaw(1.0f * timeDelta); if(EventDispatcher::Get()->keys[KEY_W]) pitch(-1.0f * timeDelta); if(EventDispatcher::Get()->keys[KEY_S]) pitch(1.0f * timeDelta); if(EventDispatcher::Get()->keys[KEY_Q]) roll(-1.0f * timeDelta); if(EventDispatcher::Get()->keys[KEY_E]) roll(1.0f * timeDelta); }
void OnUpdate(float dt) { if (IsKeyDown('W')) walk(30 * dt); else if (IsKeyDown('S')) walk(-30 * dt); if (IsKeyDown('A')) strafe(30 * dt); else if (IsKeyDown('D')) strafe(-30 * dt); float calcedX = GetMouseX() - lastMouseX, calcedY = GetMouseY() - lastMouseY; lastMouseX = GetMouseX(); lastMouseY = GetMouseY(); if (calcedY < 0) pitch(0.5f * dt * abs(calcedY)); else if (calcedY > 0) pitch(-0.5f * dt * abs(calcedY)); if (calcedX > 0) yaw(0.5f * dt * abs(calcedX)); else if (calcedX < 0) yaw(-0.5f * dt * abs(calcedX)); }
void PeripheralSetup::setup(Projector& _proj) { QMatrix4x4 _matrix; qreal _theta = yaw().radians(); qreal _ct = -cos(_theta), _st = -sin(_theta); QVector2D _shiftVec = QVector2D(-_st,_ct) * shift_; QVector2D _p = _shiftVec + distanceCenter_ * QVector2D(_ct,_st); QVector3D _pos = QVector3D(_p.x(),_p.y(),towerHeight_); _matrix.translate(_pos); _matrix.rotate(yaw().degrees() + deltaYaw_.degrees(),QVector3D(0.0,0.0,1.0)); _matrix.rotate(-pitch().degrees(),QVector3D(0.0,1.0,0.0)); _matrix.rotate(roll().degrees(),QVector3D(1.0,0.0,0.0)); _proj.setMatrix(_matrix); }
void Character::setYaw(const Ogre::Radian radians) { if (node) { node->setOrientation(node->getInitialOrientation()); } yaw(radians); }
// 시야 체크 void cMobKnight::SetLook( D3DXVECTOR3 Player_Pos ) { // 스테이터스가 DIE 상태일 경우 if( m_Status.m_Status == STATUS_DIE ) { m_cMobKnightController.SetRangeNoLoop(m_Status.StartFrame, m_Status.EndFrame, m_Status.StartFrame, m_Status.EndFrame, m_Status.PlayTime ); return; } D3DXVECTOR3 vCross, m_vMonster_NewDir; m_vMonster_dir = ( Player_Pos - m_vPos ); // 적이 플레이어를 바라보는 방향 D3DXVec3Normalize( &m_vMonster_NewDir, &m_vMonster_dir ); // 그 방향 정규화 D3DXVec3Normalize( &m_vLook, &m_vLook); // 현재 방향 정규화 D3DXVec3Cross( &vCross, &m_vMonster_NewDir, &m_vLook ); // 적이 플레이어 바라보는 방향과 원래 방향으로 외적 m_fDot = D3DXVec3Dot( &m_vMonster_NewDir, &m_vLook ); m_fLen = D3DXVec3Length( &vCross ); // 플레이어와 몬스터의 거리가 210.0f 안이고 몬스터가 현재 움직일 수 있는 상태일 경우 if( SetLength( Player_Pos ) < 210.0f && m_Status.ActionCansle == true ) { if( m_fDot < 0.99f ) { m_fangle -= vCross.y*0.2f; // 외적한 벡터의 y 마큼 회전 시킴 yaw( -vCross.y*0.2f ); } } }
void CCamera::ProcInput(GameInput *gameInput) { float fDelta = 0.005f; float x = gameInput->m_CurMState.pos.x - gameInput->m_OldMState.pos.x; float y = gameInput->m_CurMState.pos.y - gameInput->m_OldMState.pos.y; pitch(y * fDelta * 0.5); yaw(x * fDelta * 0.5); if(KEYDOWN('W')) { walk(5000.0f * fDelta); } if(KEYDOWN('S')) { walk(-5000.0f * fDelta); } if(KEYDOWN('A')) { strafe(-5000.0f * fDelta); } if(KEYDOWN('D')) { strafe(5000.0f * fDelta); } return; }
void WiimoteManager::update(float dt) { // dt average: 0.000574 std::lock_guard<std::mutex> lock(m_mutex); //std::cout << "Time: " << dt << std::endl; //if (glm::abs(m_accel_pitch) < 70.0f) { glm::quat qpitch(glm::vec3(m_accel_pitch, 0.0f, 0.0f)); glm::quat qroll(glm::vec3(0.0f, 0.0f, m_accel_roll)); glm::quat qaccel = /*qyaw */ qpitch * qroll; glm::quat yaw(glm::vec3(0.0f, m_gyro_yaw, 0.0f)); glm::quat qgyro = glm::inverse(yaw) * m_gyro_orientation; m_gyro_orientation = yaw * glm::normalize(glm::lerp(qgyro, qaccel, std::min(1.0f, 2.0f * dt))); //glm::quat yaw(glm::vec3(0.0f, m_gyro_yaw, 0.0f)); //m_gyro_orientation = glm::inverse(yaw) * m_gyro_orientation; //m_gyro_orientation = glm::lerp(m_gyro_orientation, m_orientation, std::min(1.0f, 1.0f * dt)); //m_gyro_orientation = glm::normalize(m_gyro_orientation); //m_gyro_orientation = yaw * m_gyro_orientation; } }
void Entity::SetRotation(ConstVec3fr rotation) { // assert(false); this->rotation = rotation; hasRotated = true; if (physics && physics->useQuaternions) { /// This assumes Euler angles, so construct an euler angle now! Quaternion pitch(Vector3f(1,0,0), -rotation.x), yaw(Vector3f(0,1,0), rotation.y), roll(Vector3f(0,0,1), rotation.z); Quaternion pitchYaw = pitch * yaw; pitchYaw.Normalize(); Quaternion newOrientation = pitch * yaw * roll; physics->orientation = newOrientation; physics->orientation.Normalize(); //physics->orientation = Quaternion(); //Quaternion rotationQuaternion = Quaternion(rotation, 1.0f); //rotationQuaternion.Normalize(); //physics->orientation = physics->orientation * rotationQuaternion; //physics->orientation.Normalize(); } RecalculateMatrix(); }
void kexCamera::SetupMatrices(void) { UpdateAspect(); // projection projMatrix.Identity(); projMatrix.SetViewProjection(aspect, (float)bFixedFOV ? fov : cvarClientFOV.GetFloat(), zNear, zFar); // scaling the camera object will affect the view projection projMatrix.vectors[0].x *= scale.x; projMatrix.vectors[1].y *= scale.y; // model modelMatrix.Identity(); kexQuat yaw(-(angles.yaw + offsetAngle.yaw) + M_PI, kexVec3::vecUp); kexQuat pitch(angles.pitch + offsetAngle.pitch, kexVec3::vecRight); kexQuat roll(angles.roll + offsetAngle.roll, kexVec3(0, kexMath::Sin(angles.pitch), kexMath::Cos(angles.pitch))); modelMatrix = kexMatrix((yaw * roll) * pitch); rotMatrix = modelMatrix; modelMatrix.AddTranslation(-(origin * modelMatrix)); // frustum viewFrustum.MakeClipPlanes(projMatrix, modelMatrix); viewFrustum.TransformPoints(origin, angles.ToForwardAxis(), fov, aspect, zNear, zFar); }
Quaternion Quaternion::FromEulerAngles(const vec3& angles) { Quaternion pitch(vec3(1.0, 0.0, 0.0), angles.x); Quaternion yaw(vec3(0.0, 1.0, 0.0), angles.y); Quaternion roll(vec3(0.0, 0.0, 1.0), angles.z); return pitch * yaw * roll; }
//////////////////////////////////////////////////////////////////////////////////////// // Convert From {Picth, Yaw, Roll} (DEGREES) //////////////////////////////////////////////////////////////////////////////////////// void CVec3::AngToVec(CVec3& Right, CVec3& Up) { float angle; float sr, sp, sy, cr, cp, cy; angle = yaw() * (RAVL_VEC_DEGTORADCONST); sy = sinf(angle); cy = cosf(angle); angle = pitch() * (RAVL_VEC_DEGTORADCONST); sp = sinf(angle); cp = cosf(angle); angle = roll() * (RAVL_VEC_DEGTORADCONST); sr = sinf(angle); cr = cosf(angle); // Forward Vector Is Stored Here v[0] = cp * cy; v[1] = cp * sy; v[2] = -sp; // Calculate Right Right.v[0] = (-1 * sr * sp * cy + -1 * cr * -sy); Right.v[1] = (-1 * sr * sp * sy + -1 * cr * cy); Right.v[2] = -1 * sr * cp; // Calculate Up Up.v[0] = (cr * sp * cy + -sr * -sy); Up.v[1] = (cr * sp * sy + -sr * cy); Up.v[2] = cr * cp; }
void GameObject::setYaw(const Ogre::Radian radians) { if (node) { node->setOrientation(node->getInitialOrientation()); } yaw(radians); }
void Camera::update(const GameTime& gameTime) { Vector2 mouseMovement = Mouse::getMovement(); yaw(mouseMovement.x * mouseSpeed); pitch(mouseMovement.y * mouseSpeed); Matrix m = Matrix::createFromAxisAngle(Vector3::up, rotationX); Vector3 forward = Vector3::transform(Vector3::forward, m); Vector3 right = Vector3::transform(Vector3::right, m); Vector3 direction; if (Keyboard::isKeyDown(buttonMoveForward)) direction += forward; if (Keyboard::isKeyDown(buttonMoveBackward)) direction -= forward; if (Keyboard::isKeyDown(buttonMoveRight)) direction += right; if (Keyboard::isKeyDown(buttonMoveLeft)) direction -= right; if (Keyboard::isKeyDown(buttonMoveUp)) direction += Vector3::up; if (Keyboard::isKeyDown(buttonMoveDown)) direction -= Vector3::up; float speed = rotationSpeed * gameTime.elapsed; //if (Keyboard::isKeyDown(buttonLookDown)) // pitch(speed); //if (Keyboard::isKeyDown(buttonLookUp)) // pitch(-speed); //if (Keyboard::isKeyDown(buttonLookRight)) // yaw(speed); //if (Keyboard::isKeyDown(buttonLookLeft)) // yaw(-speed); float modifier = 1.0f; if (Keyboard::isKeyDown(buttonMoveFast)) modifier *= moveFast; if (Keyboard::isKeyDown(buttonMoveSlow)) modifier *= moveSlow; position += Vector3::normalize(direction) * movementSpeed * modifier * gameTime.elapsed; updateRotation(); }
void FPSViewController::handleMouseEvent(ViewportMouseEvent& event) { if ( event.shift() ) { setStatus( "<b>Left-Click:</b> Move X/Y. <b>Right-Click:</b>: Move Z." ); } else { setStatus( "<b>Left-Click:</b> Rotate. <b>Middle-Click:</b> Move X/Y. <b>Right-Click:</b>: Zoom. <b>Shift</b>: More options." ); } bool moved = false; int32_t diff_x = 0; int32_t diff_y = 0; if( event.type == QEvent::MouseMove ) { diff_x = event.x - event.last_x; diff_y = event.y - event.last_y; moved = true; } if( event.left() && !event.shift() ) { setCursor( Rotate3D ); yaw( -diff_x*0.005 ); pitch( diff_y*0.005 ); } else if( event.middle() || ( event.shift() && event.left() )) { setCursor( MoveXY ); move( diff_x*0.01, -diff_y*0.01, 0.0f ); } else if( event.right() ) { setCursor( MoveZ ); move( 0.0f, 0.0f, diff_y*0.1 ); } else { setCursor( event.shift() ? MoveXY : Rotate3D ); } if ( event.wheel_delta != 0 ) { int diff = event.wheel_delta; move( 0.0f, 0.0f, -diff * 0.01 ); moved = true; } if (moved) { context_->queueRender(); } }
void CCameraFeedbackNotifier::walkEffect(unsigned int msecs) { Vector3 offset = _cameraComponent->getOffset(); _walkAnim.currentStrafingDir = _strafingDir; _strafingDir = _avatarc->getDisplacementDir().x; if(_strafingDir == 0) { Quaternion yaw( _entity->getYaw() ); Math::rotate( Vector3::UNIT_Y, Ogre::Radian(Math::HALF_PI), yaw); Vector3 horizontal = yaw * Vector3::NEGATIVE_UNIT_Z; _walkAnim.currentHorizontalPos += _walkAnim.horizontalSpeed * msecs; if(_walkAnim.currentHorizontalPos > ((2 * Math::PI) + Math::HALF_PI)) _walkAnim.currentHorizontalPos = Math::HALF_PI; // Multiplicamos el vector horizontal normalizado por el desplazamiento y lo sumamos al offset horizontal *= sin(_walkAnim.currentHorizontalPos) * _walkAnim.horizontalOffset; offset += horizontal; } else { // Reducimos el offset horizontal // Queda mas suave sin correccion offset = offset * Vector3(0.95f, 1.0f, 0.95f); // Si no estamos recuperando el offset por haber llegado al máximo // incrementamos el roll if(!_walkAnim.recoveringRoll) { _walkAnim.currentRoll += _strafingDir * _walkAnim.rollSpeed * msecs; if(abs(_walkAnim.currentRoll) >= _walkAnim.rollOffset) { _walkAnim.currentRoll = _walkAnim.rollOffset * _walkAnim.rollCoef * _strafingDir; _walkAnim.recoveringRoll = true; } } // Si cambiamos de direccion dejamos de recuperar el offset else if(_walkAnim.currentStrafingDir != _strafingDir) { _walkAnim.recoveringRoll = false; } } // Recuperamos la posicion inicial multiplicando por el coeficiente // de recuperacion if(_walkAnim.recoveringRoll && _walkAnim.currentRoll != 0) { _walkAnim.currentRoll *= _walkAnim.rollCoef; if(abs(_walkAnim.currentRoll) < 0.001) _walkAnim.currentRoll = 0; } _cameraComponent->rollCamera(_walkAnim.currentRoll); _walkAnim.currentVerticalPos += _walkAnim.verticalSpeed * msecs; if(_walkAnim.currentVerticalPos > ((2 * Math::PI) + Math::HALF_PI)) { _walkAnim.currentVerticalPos = Math::HALF_PI; } offset.y += sin(_walkAnim.currentVerticalPos) * _walkAnim.verticalOffset; _cameraComponent->setOffset(offset); }
void Controllable::trackMouse() { float deltaX, deltaY; input->getMouseDelta(deltaX, deltaY); // Adjust the deltas by the sensitivity. deltaX *= sensitivity / 100; deltaY *= sensitivity / 100; // DirectInput maps +y to down in screen coords. yaw(deltaX); pitch(deltaY); }
void PositionController::control(double t) { // Evaluate trajectory TrajectoryState s = this->getTargetState(t); ModelState cur = vehicle->arrival_state(); Vector3d eP = s.position - cur.position; Vector3d eV = s.velocity - cur.velocity; // At low altitudes, there's no room to rotate so we reduce the error effect // TODO: Have a better way of doing this: essentially we want a trajectory straight up followed if(s.position.z() < 0.1) { double factor = 0.8; for(unsigned i = 0; i < 2; i++) { eP(i) *= factor; eV(i) *= factor; } } Vector3d out; if(hoverMode) { // Do nothing if hovering on the ground if(point.z() < 0.1) { vehicle->setpoint_zero(); return; } out = hoverPid->compute(eP, eV, 0.01); } else { out = pid->compute(eP, eV, 0.01 /* TODO: Make this more dynamic */); } Vector3d a = out + s.acceleration; double yaw_angle = DEFAULT_YAW_ANGLE; if(directAttitudeControl) { vehicle->lastControlInput = a; a += Vector3d(0, 0, GRAVITY_MS); Quaterniond att = Quaterniond::FromTwoVectors(Vector3d(0,0,1), a.normalized()); Quaterniond yaw( AngleAxisd(yaw_angle, Vector3d::UnitZ()) ); vehicle->setpoint_attitude(att*yaw, a.norm()); } else { vehicle->setpoint_accel(a, yaw_angle); } }
void CameraComponent::onUpdate(float delta) { //Event_GetWindowResolution windowResolution; //SEND_EVENT(&windowResolution); //// Calculate split screen attribute //float aspectRatio = windowResolution.getAspectRatio(); // Update rotation while(itrPlayer.hasNext()) { AttributePtr<Attribute_Player> ptr_player = itrPlayer.getNext(); AttributePtr<Attribute_Health> ptr_health = ptr_player->ptr_health; AttributePtr<Attribute_Input> ptr_input = ptr_player->ptr_input; AttributePtr<Attribute_Camera> ptr_camera = ptr_player->ptr_camera; if(ptr_health->health <= 0) { //camera->aspectRatio += delta*100; //updateProj(camera); } else { yaw(ptr_input->rotation.x, ptr_camera); pitch(ptr_input->rotation.y, ptr_camera); } //Entity* entity = itrInput.owner(); //if(entity->hasAttribute(ATTRIBUTE_CAMERA)) //{ //std::vector<Attribute_Camera*> cameras = itrCamera.getMultiple(entity->getAttributes(ATTRIBUTE_CAMERA)); //for(int i=0; i<(int)cameras.size(); i++) //{ //Attribute_Camera* camera = itrCamera.at(player->ptr_camera);//cameras.at(i); //yaw(input->rotation.x, camera); //pitch(input->rotation.y, camera); //} //} } // Recalculate view while(itrCamera.hasNext()) { AttributePtr<Attribute_Camera> ptr_camera = itrCamera.getNext(); AttributePtr<Attribute_Spatial> ptr_spatial = ptr_camera->ptr_spatial; updateView(ptr_camera); updateProj(ptr_camera); } }
void FreeCamera::cursorPositionCallback(const double xpos, const double ypos) { int dx, dy; if (cursorLastPos.x != Utils::MAX_INT) { dx = int(cursorLastPos.x - float(xpos)); yaw(dx * 0.1f, WORLD); } if (cursorLastPos.y != Utils::MAX_INT) { dy = int(cursorLastPos.y - float(ypos)); pitch(dy * 0.1f, LOCAL); } cursorLastPos.x = static_cast<int>(xpos); cursorLastPos.y = static_cast<int>(ypos); }
//////////////////////////////////////////////////////////////////////////////////////// // Convert From {Picth, Yaw} (DEGREES) //////////////////////////////////////////////////////////////////////////////////////// void CVec3::AngToVec() { float angle; float sp, sy, cp, cy; angle = yaw() * (RAVL_VEC_DEGTORADCONST); sy = sinf(angle); cy = cosf(angle); angle = pitch() * (RAVL_VEC_DEGTORADCONST); sp = sinf(angle); cp = cosf(angle); v[0] = cp * cy; v[1] = cp * sy; v[2] = -sp; }
void IMU::UpdateData(IMU_DATA &data) { XsByteArray imuData; XsMessageArray msgs; while (msgs.empty()) { Aris::Core::Sleep(1); pDevice->readDataToBuffer(imuData); pDevice->processBufferedData(imuData, msgs); } //std::cout << "msg num:" << msgs.size()<<std::endl; for (XsMessageArray::iterator it = msgs.begin(); it != msgs.end(); ++it) { // Retrieve a packet XsDataPacket packet; if ((*it).getMessageId() == XMID_MtData2) { packet.setMessage((*it)); packet.setDeviceId(pDevice->mtPort.deviceId()); } // Get the all data auto eul = packet.orientationEuler(); auto sdi = packet.sdiData(); auto acc = packet.calibratedAcceleration(); data.yaw = eul.yaw()*PI / 180; data.pitch = eul.pitch()*PI / 180; data.roll = eul.roll()*PI / 180; data.va = sdi.orientationIncrement().x() * 2 * 100; data.vb = sdi.orientationIncrement().y() * 2 * 100; data.vc = sdi.orientationIncrement().z() * 2 * 100; std::copy_n(acc.data(), acc.size(), data.acc); data.time = packet.timeOfArrival().nowMs(); data.pmLhs = *pDevice->pmImuGround2BodyGround; data.pmRhs = *pDevice->pmBody2Imu; } msgs.clear(); }
Camera::Camera(unsigned int width, unsigned int height) : _mode(PERSPECTIVE), _fovy(75.0f), _width(width), _height(height), _eyePosition(glm::vec3(0.0f, 0.0f, 0.0f)), _latitude(0.0f), _longitude(0.0f) { _roll = glm::vec3(1.0f, 0.0f, 0.0f); _yaw = glm::vec3(0.0f, -1.0f, 0.0f); _pitch = glm::cross(_yaw, _roll); _yawAngle = 0.0f; _pitchAngle = 0.0f; _rollAngle = 0.0f; _projectionMatrix = glm::perspective(_fovy, (float)_width / (float)_height, 0.001f, 1000.0f); yaw(-60); }
void BgLoader::RotateSelected(const csVector2& pos) { if(selectedMesh.IsValid()) { float factor_h = 6 * PI * ((float)previousPosition.x - pos.x) / g2d->GetHeight(); float factor_v = 6 * PI * ((float)previousPosition.y - pos.y) / g2d->GetHeight(); origRot += factor_h*currRot_h + factor_v*currRot_v; csYRotMatrix3 pitch(origRot.x); csYRotMatrix3 roll(origRot.y); csZRotMatrix3 yaw(origRot.z); csReversibleTransform trans(roll*yaw, rotBase); trans *= csReversibleTransform(pitch, -rotBase+origTrans); selectedMesh->GetMovable()->SetTransform(trans); previousPosition = pos; } }
SoXipNeheBoxGenerator::SoXipNeheBoxGenerator() { SO_NODE_CONSTRUCTOR(SoXipNeheBoxGenerator); SbRotation pitch(SbVec3f(1, 0, 0), 0); // rotation around X SbMatrix pitchM; SbRotation yaw(SbVec3f(0, 1, 0), 0); // rotation around Y SbMatrix yawM; SbMatrix transM = SbMatrix::identity(); // translation SbMatrix compM = SbMatrix::identity(); float xrot = 0; float yrot = 0; for (int yloop = 1; yloop < 6 /* number of rows */ ; yloop++) { for (int xloop = 0; xloop < yloop; xloop++) { // another magic formula from Nehe for the translation... transM.setTranslate(SbVec3f(1.4f+(float(xloop)*2.8f)-(float(yloop)*1.4f),((6.0f-float(yloop))*2.4f)-7.0f,-20.0f)); pitch.setValue(SbVec3f(1, 0, 0), (M_PI/180) * (45.0f-(2.0f*yloop)+ xrot)); pitch.getValue(pitchM); yaw.setValue(SbVec3f(0,1,0), (M_PI/180) * (45.0f + yrot)); yaw.getValue(yawM); compM = yawM * pitchM * transM; SoXipNeheBox* neheBox = new SoXipNeheBox(); neheBox->transform.setValue(compM); neheBox->topColor.setValue(topCol[yloop - 1]); neheBox->boxColor.setValue(boxCol[yloop - 1]); this->addChild(neheBox); } } }
//----------------------------------------------------------------------------- //! @brief TODO enter a description //! @remark //----------------------------------------------------------------------------- void Camera::update( float elapsedTime, double time, const Input& input ) { const InputState* inputState = input.getInput(0); if (inputState) { InputActions::ActionType fowardAction; InputActions::ActionType backwardAction; InputActions::ActionType moveLeftAction; InputActions::ActionType moveRightAction; InputActions::ActionType yawLeftAction; InputActions::ActionType yawRightAction; InputActions::ActionType pitchUpAction; InputActions::ActionType pitchDownAction; InputActions::ActionType rollLeftAction; InputActions::ActionType rollRightAction; InputSystem::getInputActionFromName(moveForward.getHash(), fowardAction); InputSystem::getInputActionFromName(moveBackWards.getHash(), backwardAction); InputSystem::getInputActionFromName(moveLeft.getHash(), moveLeftAction); InputSystem::getInputActionFromName(moveRight.getHash(), moveRightAction); InputSystem::getInputActionFromName(yawLeft.getHash(), yawLeftAction); InputSystem::getInputActionFromName(yawRight.getHash(), yawRightAction); InputSystem::getInputActionFromName(pitchUp.getHash(), pitchUpAction); InputSystem::getInputActionFromName(pitchDown.getHash(), pitchDownAction); InputSystem::getInputActionFromName(rollLeft.getHash(), rollLeftAction); InputSystem::getInputActionFromName(rollRight.getHash(), rollRightAction); float moveAlongDirectionFactor = inputState->getActionValue(fowardAction) - inputState->getActionValue(backwardAction); moveAlongDirection(moveAlongDirectionFactor * m_movementSpeed * elapsedTime );//Move forwared, backward float strafeFactor = inputState->getActionValue(moveLeftAction) - inputState->getActionValue(moveRightAction); strafe(strafeFactor * m_movementSpeed * elapsedTime);//Move left/right float yawFactor = inputState->getActionValue(yawLeftAction) - inputState->getActionValue(yawRightAction); yaw(yawFactor * m_rotationSpeed * elapsedTime); float pitchFactor = inputState->getActionValue(pitchUpAction) - inputState->getActionValue(pitchDownAction); pitch(pitchFactor * m_rotationSpeed * elapsedTime); float zAxisDelta = inputState->getActionValue(rollLeftAction) - inputState->getActionValue(rollRightAction); roll(zAxisDelta * m_rotationSpeed * 0.05f); } //Use the varibles to avoid a warning and allows us to use them in the code above without change time = 0.0; elapsedTime = 0.0f; }
void FreeCameraController::handleMouseMoveEvent(int x, int y) { if (!isActive()) return; if (mNaviPrimary) { double scalar = getCameraSensitivity() * (getInverted() ? -1.0 : 1.0); yaw(x * scalar); pitch(y * scalar); } else if (mNaviSecondary) { osg::Vec3d movement; movement += LocalLeft * -x * getSecondaryMovementMultiplier(); movement += LocalUp * y * getSecondaryMovementMultiplier(); translate(movement); } }