Text::FontDescriptor FontConfig::GetDescriptor() { std::string filename(String("FontFile")); float pointSize = Float("PointSize"); if (!is_zero_general(pointSize)) return Text::FontDescriptor(filename, pointSize); int pixelWidth = Int("PixelWidth"); int pixelHeight = Int("PixelHeight"); bool outline = Int("Outline") ? true : false; float advanceXAdjustment = Float("AdvanceXAdjustment"); return Text::FontDescriptor(filename, pixelWidth, pixelHeight, outline, advanceXAdjustment); }
void DynamicBody::UpdateInterpolatedTransform(double alpha) { // interpolating matrices like this is a sure sign of madness vector3d outPos = alpha*vector3d(m_orient[12], m_orient[13], m_orient[14]) + (1.0-alpha)*vector3d(m_oldOrient[12], m_oldOrient[13], m_oldOrient[14]); m_interpolatedTransform = m_oldOrient; { double len = m_oldAngDisplacement.Length() * double(alpha); if (! is_zero_general(len)) { vector3d rotAxis = m_oldAngDisplacement.Normalized(); matrix4x4d rotMatrix = matrix4x4d::RotateMatrix(len, rotAxis.x, rotAxis.y, rotAxis.z); m_interpolatedTransform = rotMatrix * m_interpolatedTransform; } } m_interpolatedTransform[12] = outPos.x; m_interpolatedTransform[13] = outPos.y; m_interpolatedTransform[14] = outPos.z; }
FontDescriptor FontDescriptor::Load(FileSystem::FileSource &fs, const std::string &path, float scale_x, float scale_y) { IniConfig cfg; // set defaults cfg.SetInt("PixelWidth", 12); cfg.SetInt("PixelHeight", 12); cfg.SetInt("AdvanceXAdjustment", 0); cfg.Read(fs, path); const float pointSize = cfg.Float("PointSize"); if (!is_zero_general(pointSize)) return FontDescriptor(cfg.String("FontFile"), pointSize); return FontDescriptor( cfg.String("FontFile"), cfg.Int("PixelWidth") / scale_x, cfg.Int("PixelHeight") / scale_y, cfg.Int("Outline") ? true : false, cfg.Float("AdvanceXAdjustment") ); }
void PlayerShipController::PollControls(const float timeStep, const bool force_rotation_damping, int *mouseMotion) { static bool stickySpeedKey = false; CheckControlsLock(); if (m_controlsLocked) return; // if flying { m_ship->ClearThrusterState(); m_ship->SetGunState(0,0); m_ship->SetGunState(1,0); vector3d wantAngVel(0.0); double angThrustSoftness = 10.0; const float linearThrustPower = (KeyBindings::thrustLowPower.IsActive() ? m_lowThrustPower : 1.0f); // have to use this function. SDL mouse position event is bugged in windows if (Pi::MouseButtonState(SDL_BUTTON_RIGHT)) { const matrix3x3d &rot = m_ship->GetOrient(); if (!m_mouseActive) { m_mouseDir = -rot.VectorZ(); // in world space m_mouseX = m_mouseY = 0; m_mouseActive = true; } vector3d objDir = m_mouseDir * rot; const double radiansPerPixel = 0.00002 * m_fovY; const int maxMotion = std::max(abs(mouseMotion[0]), abs(mouseMotion[1])); const double accel = Clamp(maxMotion / 4.0, 0.0, 90.0 / m_fovY); m_mouseX += mouseMotion[0] * accel * radiansPerPixel; double modx = clipmouse(objDir.x, m_mouseX); m_mouseX -= modx; const bool invertY = (Pi::IsMouseYInvert() ? !m_invertMouse : m_invertMouse); m_mouseY += mouseMotion[1] * accel * radiansPerPixel * (invertY ? -1 : 1); double mody = clipmouse(objDir.y, m_mouseY); m_mouseY -= mody; if(!is_zero_general(modx) || !is_zero_general(mody)) { matrix3x3d mrot = matrix3x3d::RotateY(modx) * matrix3x3d::RotateX(mody); m_mouseDir = (rot * (mrot * objDir)).Normalized(); } } else m_mouseActive = false; if (m_flightControlState == CONTROL_FIXSPEED) { double oldSpeed = m_setSpeed; if (stickySpeedKey) { if (!(KeyBindings::increaseSpeed.IsActive() || KeyBindings::decreaseSpeed.IsActive())) { stickySpeedKey = false; } } if (!stickySpeedKey) { if (KeyBindings::increaseSpeed.IsActive()) m_setSpeed += std::max(fabs(m_setSpeed)*0.05, 1.0); if (KeyBindings::decreaseSpeed.IsActive()) m_setSpeed -= std::max(fabs(m_setSpeed)*0.05, 1.0); if ( ((oldSpeed < 0.0) && (m_setSpeed >= 0.0)) || ((oldSpeed > 0.0) && (m_setSpeed <= 0.0)) ) { // flipped from going forward to backwards. make the speed 'stick' at zero // until the player lets go of the key and presses it again stickySpeedKey = true; m_setSpeed = 0; } } } if (KeyBindings::thrustForward.IsActive()) m_ship->SetThrusterState(2, -linearThrustPower); if (KeyBindings::thrustBackwards.IsActive()) m_ship->SetThrusterState(2, linearThrustPower); if (KeyBindings::thrustUp.IsActive()) m_ship->SetThrusterState(1, linearThrustPower); if (KeyBindings::thrustDown.IsActive()) m_ship->SetThrusterState(1, -linearThrustPower); if (KeyBindings::thrustLeft.IsActive()) m_ship->SetThrusterState(0, -linearThrustPower); if (KeyBindings::thrustRight.IsActive()) m_ship->SetThrusterState(0, linearThrustPower); if (KeyBindings::fireLaser.IsActive() || (Pi::MouseButtonState(SDL_BUTTON_LEFT) && Pi::MouseButtonState(SDL_BUTTON_RIGHT))) { //XXX worldview? madness, ask from ship instead m_ship->SetGunState(Pi::worldView->GetActiveWeapon(), 1); } if (KeyBindings::yawLeft.IsActive()) wantAngVel.y += 1.0; if (KeyBindings::yawRight.IsActive()) wantAngVel.y += -1.0; if (KeyBindings::pitchDown.IsActive()) wantAngVel.x += -1.0; if (KeyBindings::pitchUp.IsActive()) wantAngVel.x += 1.0; if (KeyBindings::rollLeft.IsActive()) wantAngVel.z += 1.0; if (KeyBindings::rollRight.IsActive()) wantAngVel.z -= 1.0; if (KeyBindings::killRot.IsActive()) SetFlightControlState(CONTROL_FIXHEADING_KILLROT); if (KeyBindings::thrustLowPower.IsActive()) angThrustSoftness = 50.0; vector3d changeVec; changeVec.x = KeyBindings::pitchAxis.GetValue(); changeVec.y = KeyBindings::yawAxis.GetValue(); changeVec.z = KeyBindings::rollAxis.GetValue(); // Deadzone more accurate for (int axis=0; axis<3; axis++) { if (fabs(changeVec[axis]) < m_joystickDeadzone) changeVec[axis]=0.0; else changeVec[axis] = changeVec[axis] * 2.0; } wantAngVel += changeVec; if (wantAngVel.Length() >= 0.001 || force_rotation_damping || m_rotationDamping) { if (Pi::game->GetTimeAccel()!=Game::TIMEACCEL_1X) { for (int axis=0; axis<3; axis++) wantAngVel[axis] = wantAngVel[axis] * Pi::game->GetInvTimeAccelRate(); } m_ship->AIModelCoordsMatchAngVel(wantAngVel, angThrustSoftness); } if (m_mouseActive) m_ship->AIFaceDirection(m_mouseDir); } }
bool AICmdDock::TimeStepUpdate() { if (!ProcessChild()) return false; if (!m_target) return true; if (m_state == 1) m_state = 2; // finished moving into dock start pos if (m_ship->GetFlightState() != Ship::FLYING) { // todo: should probably launch if docked with something else m_ship->ClearThrusterState(); return true; // docked, hopefully } // if we're not close to target, do a flyto first double targdist = m_target->GetPositionRelTo(m_ship).Length(); if (targdist > m_target->GetBoundingRadius() * VICINITY_MUL * 1.5) { m_child = new AICmdFlyTo(m_ship, m_target); ProcessChild(); return false; } int port = m_target->GetMyDockingPort(m_ship); if (port == -1) { std::string msg; m_target->GetDockingClearance(m_ship, msg); port = m_target->GetMyDockingPort(m_ship); if (port == -1) { m_ship->AIMessage(Ship::AIERROR_REFUSED_PERM); return true; } } // state 0,2: Get docking data if (m_state == 0 || m_state == 2 || m_state == 4) { const SpaceStationType *type = m_target->GetSpaceStationType(); SpaceStationType::positionOrient_t dockpos; type->GetShipApproachWaypoints(port, (m_state==0)?1:2, dockpos); matrix4x4d trot; m_target->GetRotMatrix(trot); if (m_state != 2) m_dockpos = trot * dockpos.pos + m_target->GetPosition(); m_dockdir = (trot * dockpos.xaxis.Cross(dockpos.yaxis)).Normalized(); m_dockupdir = (trot * dockpos.yaxis).Normalized(); // don't trust these enough if (type->dockMethod == SpaceStationType::ORBITAL) m_dockupdir = -m_dockupdir; m_state++; } if (m_state == 1) { // fly to first docking waypoint m_child = new AICmdFlyTo(m_ship, m_target->GetFrame(), m_dockpos, 0.0, false); ProcessChild(); return false; } // second docking waypoint m_ship->SetWheelState(true); vector3d targpos = GetPosInFrame(m_ship->GetFrame(), m_target->GetFrame(), m_dockpos); vector3d relpos = targpos - m_ship->GetPosition(); vector3d reldir = relpos.NormalizedSafe(); vector3d relvel = m_ship->GetVelocityRelTo(m_target); double maxdecel = GetMaxDecel(m_ship, reldir, 0, 0); maxdecel -= GetGravityAtPos(m_target->GetFrame(), m_dockpos); m_ship->AIMatchPosVel2(reldir, relpos.Length(), relvel, 0.0, maxdecel); // massive pile of crap needed to get updir right outside the frame Frame *sframe = m_target->GetFrame(); double ang = sframe->GetAngVelocity().Length() * Pi::game->GetTimeStep(); matrix4x4d m; Frame::GetFrameTransform(sframe, m_ship->GetFrame(), m); if (!is_zero_general(ang) && sframe != m_ship->GetFrame()) { vector3d axis = sframe->GetAngVelocity().Normalized(); m = m * matrix4x4d::RotateMatrix(ang, axis.x, axis.y, axis.z); } vector3d updir = m.ApplyRotationOnly(m_dockupdir); bool fin = m_ship->AIFaceOrient(m_dockdir, updir); if (m_state < 5 && fin && m_ship->GetWheelState() >= 1.0f) m_state++; #ifdef DEBUG_AUTOPILOT printf("AICmdDock dist = %.1f, speed = %.1f, ythrust = %.2f, state = %i\n", targdist, relvel.Length(), m_ship->GetThrusterState().y, m_state); #endif return false; }
void Box::Layout() { if (m_children.size() == 0) return; PreferredSize(); const Point boxSize = GetSize(); Point::Component vc, fc; GetComponentsForOrient(m_orient == BOX_HORIZONTAL, vc, fc); float sizeRemaining = boxSize[vc] - (m_spacing * (m_children.size()-1)); Point childPos(0); // the largest equal share each child can have const float maxChildSize = boxSize[vc]/m_children.size(); for (std::list<Child>::iterator i = m_children.begin(); i != m_children.end(); ++i) { (*i).padding = 0; float childSize = 0; // if we have enough room to give _everyone_ what they want, do it if (boxSize[vc] >= m_preferredSize[vc]) childSize = (*i).preferredSize[vc]; // if this child wants less than their share, give it to them else if (maxChildSize >= (*i).preferredSize[vc]) childSize = (*i).preferredSize[vc]; // otherwise they get their share else childSize = maxChildSize; (*i).size[vc] = childSize; (*i).size[fc] = boxSize[fc]; sizeRemaining -= childSize; if (m_countExpanded == 0) { SetWidgetDimensions((*i).widget, childPos, (*i).size); childPos[vc] += childSize + m_spacing; } } if (m_countExpanded > 0) { int candidates = m_countExpanded; while (candidates > 0 && sizeRemaining > 0 && !is_zero_general(sizeRemaining)) { float allocation = sizeRemaining / candidates; for (std::list<Child>::iterator i = m_children.begin(); i != m_children.end(); ++i) { if (!((*i).flags & BOX_EXPAND)) continue; float amountAdded; if (!((*i).flags & BOX_FILL)) { (*i).padding += allocation * 0.5; amountAdded = allocation; } else { (*i).size[vc] += allocation; amountAdded = allocation; } sizeRemaining -= amountAdded; } } for (std::list<Child>::iterator i = m_children.begin(); i != m_children.end(); ++i) { Point pos = childPos; pos[vc] += (*i).padding; SetWidgetDimensions((*i).widget, pos, (*i).size); childPos[vc] = pos[vc] + (*i).size[vc] + (*i).padding + m_spacing; } } LayoutChildren(); }