void SpaceStation::TimeStepUpdate(const float timeStep) { // rotate the thing double len = m_type->angVel * timeStep; if (!is_zero_exact(len)) { matrix3x3d r = matrix3x3d::RotateY(-len); // RotateY is backwards SetOrient(r * GetOrient()); } m_oldAngDisplacement = len; // reposition the ships that are docked or docking here for (int i=0; i<m_type->numDockingPorts; i++) { const shipDocking_t &dt = m_shipDocking[i]; if (!dt.ship) { //free m_navLights->SetColor(i+1, NavLights::NAVLIGHT_GREEN); continue; } if (dt.stage == 1) //reserved m_navLights->SetColor(i+1, NavLights::NAVLIGHT_YELLOW); if (dt.ship->GetFlightState() == Ship::FLYING) continue; PositionDockedShip(dt.ship, i); m_navLights->SetColor(i+1, NavLights::NAVLIGHT_RED); //docked } if (m_doorAnimation) GetModel()->UpdateAnimations(); }
void DynamicBody::TimeStepUpdate(const float timeStep) { m_oldPos = GetPosition(); if (m_isMoving) { m_force += m_externalForce; m_vel += double(timeStep) * m_force * (1.0 / m_mass); m_angVel += double(timeStep) * m_torque * (1.0 / m_angInertia); double len = m_angVel.Length(); if (len > 1e-16) { vector3d axis = m_angVel * (1.0 / len); matrix3x3d r = matrix3x3d::Rotate(len * timeStep, axis); SetOrient(r * GetOrient()); } m_oldAngDisplacement = m_angVel * timeStep; SetPosition(GetPosition() + m_vel * double(timeStep)); //if (this->IsType(Object::PLAYER)) //Output("pos = %.1f,%.1f,%.1f, vel = %.1f,%.1f,%.1f, force = %.1f,%.1f,%.1f, external = %.1f,%.1f,%.1f\n", // pos.x, pos.y, pos.z, m_vel.x, m_vel.y, m_vel.z, m_force.x, m_force.y, m_force.z, // m_externalForce.x, m_externalForce.y, m_externalForce.z); m_lastForce = m_force; m_lastTorque = m_torque; m_force = vector3d(0.0); m_torque = vector3d(0.0); CalcExternalForce(); // regenerate for new pos/vel } else { m_oldAngDisplacement = vector3d(0.0); } ModelBody::TimeStepUpdate(timeStep); }
void Ship::TestLanded() { m_testLanded = false; if (m_launchLockTimeout > 0.0f) return; if (m_wheelState < 1.0f) return; if (GetFrame()->GetBody()->IsType(Object::PLANET)) { double speed = GetVelocity().Length(); vector3d up = GetPosition().Normalized(); const double planetRadius = static_cast<Planet*>(GetFrame()->GetBody())->GetTerrainHeight(up); if (speed < MAX_LANDING_SPEED) { // check player is sortof sensibly oriented for landing if (GetOrient().VectorY().Dot(up) > 0.99) { // position at zero altitude SetPosition(up * (planetRadius - GetAabb().min.y)); // position facing in roughly the same direction vector3d right = up.Cross(GetOrient().VectorZ()).Normalized(); SetOrient(matrix3x3d::FromVectors(right, up)); SetVelocity(vector3d(0, 0, 0)); SetAngVelocity(vector3d(0, 0, 0)); ClearThrusterState(); SetFlightState(LANDED); Sound::BodyMakeNoise(this, "Rough_Landing", 1.0f); LuaEvent::Queue("onShipLanded", this, GetFrame()->GetBody()); onLanded.emit(); } } } }
void CWinsys::Init () { Uint32 sdl_flags = SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE | SDL_INIT_TIMER; if (SDL_Init (sdl_flags) < 0) Message ("Could not initialize SDL"); SDL_GL_SetAttribute(SDL_GL_CONTEXT_EGL, 1); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); #if defined (USE_STENCIL_BUFFER) SDL_GL_SetAttribute (SDL_GL_STENCIL_SIZE, 8); #endif #ifdef USE_GLES glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST); #endif SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SetupVideoMode (GetResolution (param.res_type)); context = SDL_GL_CreateContext(window); SetOrient(param.orient >= 0 ? param.orient : resolution.width < resolution.height); Reshape (resolution.width, resolution.height); //SDL_WM_SetCaption (WINDOW_TITLE, WINDOW_TITLE); KeyRepeat (false); if (USE_JOYSTICK) InitJoystick (); // SDL_EnableUNICODE (1); }
/***************************************************************************** * Startup the printing interface * Done at start of program *****************************************************************************/ void StartTextPrnt(void) { memset( &pd, 0, sizeof(PRINTDLG) ); pd.lStructSize = sizeof(PRINTDLG); memset( &lf, 0, sizeof(LOGFONT) ); strcpy( lf.lfFaceName, "LinePrinter BM" ); offsetx = 450; offsety = 200; savelpi = 8; savecpi = 16; SetCPI( MAKELONG(savecpi,savelpi) ); lf.lfWidth = lf.lfHeight = 1; lf.lfWeight = 400; lf.lfPitchAndFamily = FF_MODERN|FIXED_PITCH; // Get a DC handle to the system`s default printer. using // the PD_RETURNDEFAULT flag ensures that no dialog is opened. pd.Flags = PD_RETURNDC | PD_RETURNDEFAULT | PD_NOSELECTION; PrintDlg(&pd); if ( pd.hDevMode == NULL ) { display_error(78,"Unable to initialise default printer",FALSE); return; } SetOrient( DMORIENT_PORTRAIT ); }
void Body::OrientOnSurface(double radius, double latitude, double longitude) { vector3d up = vector3d(cos(latitude)*cos(longitude), sin(latitude)*cos(longitude), sin(longitude)); SetPosition(radius * up); vector3d right = up.Cross(vector3d(0,0,1)).Normalized(); SetOrient(matrix3x3d::FromVectors(right, up)); }
Projectile::Projectile(): Body() { if (!s_sideMat) BuildModel(); SetOrient(matrix3x3d::Identity()); m_type = 1; m_age = 0; m_parent = 0; m_flags |= FLAG_DRAW_LAST; }
void Body::SwitchToFrame(Frame *newFrame) { vector3d vel = GetVelocityRelTo(newFrame); // do this first because it uses position vector3d fpos = m_frame->GetPositionRelTo(newFrame); matrix3x3d forient = m_frame->GetOrientRelTo(newFrame); SetPosition(forient * GetPosition() + fpos); SetOrient(forient * GetOrient()); SetVelocity(vel + newFrame->GetStasisVelocity(GetPosition())); SetFrame(newFrame); LuaEvent::Queue("onFrameChanged", this); }
void SpaceStation::TimeStepUpdate(const float timeStep) { // rotate the thing double len = m_type->angVel * timeStep; if (!is_zero_exact(len)) { matrix3x3d r = matrix3x3d::RotateY(-len); // RotateY is backwards SetOrient(r * GetOrient()); } m_oldAngDisplacement = len; // reposition the ships that are docked or docking here for (int i=0; i<m_type->numDockingPorts; i++) { const shipDocking_t &dt = m_shipDocking[i]; if (!dt.ship || dt.stage == 1) continue; if (dt.ship->GetFlightState() == Ship::FLYING) continue; PositionDockedShip(dt.ship, i); } }
void Ship::SetLandedOn(Planet *p, float latitude, float longitude) { m_wheelTransition = 0; m_wheelState = 1.0f; Frame* f = p->GetFrame()->GetRotFrame(); SetFrame(f); vector3d up = vector3d(cos(latitude)*sin(longitude), sin(latitude), cos(latitude)*cos(longitude)); const double planetRadius = p->GetTerrainHeight(up); SetPosition(up * (planetRadius - GetAabb().min.y)); vector3d right = up.Cross(vector3d(0,0,1)).Normalized(); SetOrient(matrix3x3d::FromVectors(right, up)); SetVelocity(vector3d(0, 0, 0)); SetAngVelocity(vector3d(0, 0, 0)); ClearThrusterState(); SetFlightState(LANDED); LuaEvent::Queue("onShipLanded", this, p); onLanded.emit(); }
void CObject::Initialize (ubyte nType, ubyte nId, short nCreator, short nSegment, const CFixVector& vPos, const CFixMatrix& mOrient, fix xSize, ubyte cType, ubyte mType, ubyte rType) { SetSignature (gameData.objs.nNextSignature++); SetType (nType); SetId (nId); SetLastPos (vPos); SetSize (xSize); SetCreator ((sbyte) nCreator); SetOrient (&mOrient); SetControlType (cType); SetMovementType (mType); SetRenderType (rType); SetContainsType (-1); SetLifeLeft ( ((gameData.app.nGameMode & GM_ENTROPY) && (nType == OBJ_POWERUP) && (nId == POW_HOARD_ORB) && (extraGameInfo [1].entropy.nVirusLifespan > 0)) ? I2X (extraGameInfo [1].entropy.nVirusLifespan) : IMMORTAL_TIME); SetAttachedObj (-1); SetShields (I2X (20)); SetSegment (-1); //set to zero by memset, above LinkToSeg (nSegment); }
int CObject::Create (ubyte nType, ubyte nId, short nCreator, short nSegment, const CFixVector& vPos, const CFixMatrix& mOrient, fix xSize, ubyte cType, ubyte mType, ubyte rType) { #if DBG if (nType == OBJ_WEAPON) { nType = nType; if ((nCreator >= 0) && (OBJECTS [nCreator].info.nType == OBJ_ROBOT)) nType = nType; if (nId == FLARE_ID) nType = nType; if (gameData.objs.bIsMissile [(int) nId]) nType = nType; } else if (nType == OBJ_ROBOT) { #if 0 if (ROBOTINFO ((int) nId).bossFlag && (BOSS_COUNT >= MAX_BOSS_COUNT)) return -1; #endif } else if (nType == OBJ_HOSTAGE) nType = nType; else if (nType == OBJ_FIREBALL) nType = nType; else if (nType == OBJ_REACTOR) nType = nType; else if (nType == OBJ_DEBRIS) nType = nType; else if (nType == OBJ_MARKER) nType = nType; else if (nType == OBJ_PLAYER) nType = nType; else if (nType == OBJ_POWERUP) nType = nType; #endif SetSegment (FindSegByPos (vPos, nSegment, 1, 0)); if ((Segment () < 0) || (Segment () > gameData.segs.nLastSegment)) return -1; if (nType == OBJ_DEBRIS) { if (gameData.objs.nDebris >= gameStates.render.detail.nMaxDebrisObjects) return -1; } // Zero out object structure to keep weird bugs from happening in uninitialized fields. m_nId = OBJ_IDX (this); SetSignature (gameData.objs.nNextSignature++); SetType (nType); SetId (nId); SetLastPos (vPos); SetPos (&vPos); SetSize (xSize); SetCreator ((sbyte) nCreator); SetOrient (&mOrient); SetControlType (cType); SetMovementType (mType); SetRenderType (rType); SetContainsType (-1); SetLifeLeft ( ((gameData.app.nGameMode & GM_ENTROPY) && (nType == OBJ_POWERUP) && (nId == POW_HOARD_ORB) && (extraGameInfo [1].entropy.nVirusLifespan > 0)) ? I2X (extraGameInfo [1].entropy.nVirusLifespan) : IMMORTAL_TIME); SetAttachedObj (-1); m_xCreationTime = gameData.time.xGame; #if 0 if (GetControlType () == CT_POWERUP) CPowerupInfo::SetCount (1); // Init physics info for this CObject if (GetMovementType () == MT_PHYSICS) m_vStartVel.SetZero (); if (GetRenderType () == RT_POLYOBJ) CPolyObjInfo::SetTexOverride (-1); if (GetType () == OBJ_WEAPON) { CPhysicsInfo::SetFlags (CPhysInfo.GetFlags () | WI_persistent (m_info.nId) * PF_PERSISTENT); CLaserInfo::SetCreationTime (gameData.time.xGame); CLaserInfo::SetLastHitObj (0); CLaserInfo::SetScale (I2X (1)); } else if (GetType () == OBJ_DEBRIS) gameData.objs.nDebris++; if (GetControlType () == CT_POWERUP) CPowerupInfo::SetCreationTime (gameData.time.xGame); else if (GetControlType () == CT_EXPLOSION) { CAttachedInfo::SetPrev (-1); CAttachedInfo::SetNext (-1); CAttachedInfo::SetParent (-1); } #endif Link (); LinkToSeg (nSegment); return m_nId; }