void quadsquare::tri( unsigned int aa, unsigned short ta, unsigned int bb, unsigned short tb, unsigned int cc, unsigned short tc ) { assert( 0 ); //see below #if VERTEX_LIST functions... this whole contraption sorely needs a rewrite #ifdef DONOTDRAWBLENDEDQUADS if (ta == tb && tb == tc) { indices[ta]->q.push_back( aa, bb, cc ); return; } else { return; } #endif if ( !(ta == tb && tb == tc) ) { if ( ( (*textures)[ta].blendDst == ZERO ) && ( (*textures)[tb].blendDst != ZERO ) ) RotateTriRight( aa, ta, bb, tb, cc, tc ); else if ( ( (*textures)[ta].blendDst == ZERO ) && ( (*textures)[tc].blendDst != ZERO ) ) RotateTriLeft( aa, ta, bb, tb, cc, tc ); GFXColorVertex cv[3]; #ifdef VERTEX_LIST cv[0].SetVtx( *vertices->GetVertex( aa ) ); cv[1].SetVtx( *vertices->GetVertex( bb ) ); cv[2].SetVtx( *vertices->GetVertex( cc ) ); #endif cv[0].SetColor( GFXColor( 1, 1, 1, 1 ) ); cv[1].SetColor( GFXColor( 1, 1, 1, 1 ) ); cv[2].SetColor( GFXColor( 1, 1, 1, 1 ) ); if (tb == tc) { cv[0].a = 0; cv[1].a = 1; cv[2].a = 1; indices[tb].c.push_back3( cv ); } else { if (tb != ta) { cv[0].a = 0; cv[1].a = 1; cv[2].a = 0; indices[tb].c.push_back3( cv ); } if (tc != ta) { cv[0].a = 0; cv[1].a = 0; cv[2].a = 1; indices[tc].c.push_back3( cv ); } } } indices[ta].q.push_back( aa, bb, cc ); }
GFXColor SaturatedColor(float r, float g, float b, float a) { static float Saturation=XMLSupport::parse_float(vs_config->getVariable("graphics","base_saturation","1.0")); return GFXColor((r*Saturation*3+(r+b+g)*(1-Saturation))/3, (g*Saturation*3+(r+b+g)*(1-Saturation))/3, (b*Saturation*3+(r+b+g)*(1-Saturation))/3,a); }
void Terrain::ApplyForce( Unit *un, const Vector &normal, float dist ) { un->ApplyForce( normal*.4*un->GetMass() *fabs( normal.Dot( (un->GetVelocity()/SIMULATION_ATOM) )+fabs( dist )/(SIMULATION_ATOM) ) ); un->ApplyDamage( un->Position().Cast()-normal*un->rSize(), -normal, .5*fabs( normal.Dot( un->GetVelocity() ) )*mass*SIMULATION_ATOM, un, GFXColor( 1, 1, 1, 1 ), NULL ); }
GFXColor getConfigColor(const char * name, GFXColor defaul) { float color[4]; color[0]=defaul.r; color[1]=defaul.g; color[2]=defaul.b; color[3]=defaul.a; vs_config->getColor(std::string("default"), std::string(name), color, true); return GFXColor(color[0], color[1], color[2], color[3]); }
void GFXQuadList::Draw() { if (!numQuads) return; if (isColor) glInterleavedArrays( GL_T2F_C4F_N3F_V3F, sizeof (GFXColorVertex), &data.colors[0] ); else glInterleavedArrays( GL_T2F_N3F_V3F, sizeof (GFXVertex), &data.vertices[0] ); glDrawArrays( GL_QUADS, 0, numQuads*4 ); if (isColor) GFXColor( 1, 1, 1, 1 ); }
void Core::FieldReactionSystem::DrawDebugField() { float cellHalfSize = FIELD_CELL_SIDE_SIZE * 0.5f; float fieldStart = -FIELD_SIDE_LENGTH * 0.5f - cellHalfSize; float yPos = 0.5f; for (int i = 0; i < FIELD_SIDE_CELL_COUNT; ++i) { for (int j = 0; j < FIELD_SIDE_CELL_COUNT; ++j) { GFXColor colour = GFXColor(1.0f, 1.0f, 1.0f, 1.0f); if (m_field[i][j] > 0.0f) colour = GFXColor(0.0f, 0.3f - m_field[i][j], m_field[i][j], 1.0f); else colour = GFXColor(-m_field[i][j], 0.3f + m_field[i][j], 0.0f, 1.0f); GFX::Debug::DrawBox(GetPositionFromFieldIndex(i, j, yPos), GFXVec3(FIELD_CELL_SIDE_SIZE + 0.1f, 0.1f, FIELD_CELL_SIDE_SIZE + 0.1f), true, colour, true); } } }
void Mesh::AddDamageFX(const Vector & pnt, const Vector &norm, const float damage, const GFXColor &col) { Vector loc(pnt+norm); /*if (!(norm.i||norm.j||norm.k)) */{ loc = pnt; loc.Normalize(); loc*=(1+rSize()); } GFXColor tmp (col.r,col.g,col.b,col.a); float numsec = flickertime*(damage < mindamage)?mindamage:damage;; MeshFX newFX (numsec, (startpotency-endpotency)/(numsec*rSize()*rSize()) ,true,GFXColor(loc.i,loc.j,loc.k,1),tmp,GFXColor (0,0,0,1),tmp,GFXColor (1,0,startpotency/(rSize()*rSize()))); if (LocalFX.size()>=MAXLOCALFX) { LocalFX[(rand()%(LocalFX.size()))].MergeLights (newFX); } else { LocalFX.push_back (newFX); } }
GFXColor Sensor::GetColor(const Track& track) const { assert(player); static GFXColor friendColor = RetrColor("friend", GFXColor(-1, -1, -1, -1)); static GFXColor enemyColor = RetrColor("enemy", GFXColor(-1, -1, -1, -1)); static GFXColor neutralColor = RetrColor("neutral", GFXColor(-1, -1, -1, -1)); static GFXColor baseColor = RetrColor("base", GFXColor( -1, -1, -1, -1 )); static GFXColor planetColor = RetrColor("planet", GFXColor( -1, -1, -1, -1 )); static GFXColor jumpColor = RetrColor("jump", GFXColor( 0, 1, 1, .8 )); static GFXColor navColor = RetrColor("nav", GFXColor( 1, 1, 1, 1 )); static GFXColor starColor = RetrColor("star", GFXColor( 1, 1, 1, 1 )); static GFXColor missileColor = RetrColor("missile", GFXColor( .25, 0, .5, 1 )); static GFXColor cargoColor = RetrColor("cargo", GFXColor( .6, .2, 0, 1 )); static GFXColor noColor = RetrColor("black_and_white", GFXColor( .5, .5, .5 )); Track::Type::Value trackType = track.GetType(); ThreatLevel::Value threatLevel = IdentifyThreat(track); if (UseThreatAssessment()) { switch (trackType) { case Track::Type::Missile: return missileColor; default: break; } } if (UseObjectRecognition()) { switch (trackType) { case Track::Type::Nebula: case Track::Type::Star: return starColor; case Track::Type::Planet: case Track::Type::DeadPlanet: return planetColor; case Track::Type::Base: if (track.HasLock()) return enemyColor; return baseColor; case Track::Type::JumpPoint: return jumpColor; default: break; } } if (UseFriendFoe()) { switch (trackType) { case Track::Type::CapitalShip: case Track::Type::Ship: { if (track.HasLock()) return enemyColor; switch (track.GetRelation()) { case Track::Relation::Friend: return friendColor; case Track::Relation::Enemy: if (UseThreatAssessment() && (threatLevel == ThreatLevel::None)) return neutralColor; return enemyColor; default: return neutralColor; } } case Track::Type::Cargo: return cargoColor; default: break; } } return noColor; }
void Stars::Draw() { static bool stars_dont_move = XMLSupport::parse_bool (vs_config->getVariable("graphics","stars_dont_move","false")); if (stars_dont_move)return; const QVector cp (_Universe->AccessCamera()->GetPosition()); UpdatePosition(cp); // GFXLightContextAmbient(GFXColor(0,0,0,1)); GFXColor (1,1,1,1); GFXLoadIdentity(MODEL); GFXDisable(DEPTHWRITE); GFXDisable (TEXTURE0); GFXDisable (TEXTURE1); GFXEnable (DEPTHTEST); static bool near_stars_alpha=XMLSupport::parse_bool(vs_config->getVariable("graphics","near_stars_alpha","false")); static bool near_stars_alpha_blend=XMLSupport::parse_bool(vs_config->getVariable("graphics","near_stars_alpha_blend","false")); static float AlphaTestingCutoff =XMLSupport::parse_float(vs_config->getVariable("graphics","stars_alpha_test_cutoff",".2")); if (near_stars_alpha) { GFXAlphaTest (GREATER,AlphaTestingCutoff); if (!near_stars_alpha_blend) { GFXBlendMode(ONE,ZERO); } else { GFXBlendMode(SRCALPHA,INVSRCALPHA); } GFXEnable(DEPTHWRITE); } else { if (blend) { GFXBlendMode (ONE,ONE); } else { GFXBlendMode (ONE,ZERO); } } int ligh; GFXSelectMaterial (0); if (fade) { static float star_spread_attenuation = XMLSupport::parse_float(vs_config->getVariable("graphics","star_spread_attenuation",".2")); GFXPushGlobalEffects(); GFXLight FadeLight (true, GFXColor (cp.i,cp.j,cp.k), GFXColor (0,0,0,1), GFXColor (0,0,0,1), GFXColor (1,1,1,1), GFXColor (.01,0,1/(star_spread_attenuation*star_spread_attenuation*spread*spread))); GFXCreateLight (ligh,FadeLight,true); GFXEnable (LIGHTING); } else { GFXDisable (LIGHTING); } _Universe->AccessCamera()->UpdateGFX(GFXFALSE,GFXFALSE,GFXFALSE); int LC=0,LN=vlist->NumTextures(); for (LC=0; LC<LN; ++LC) { bool stretch=vlist->BeginDrawState(_Universe->AccessCamera()->GetR().Scale(-spread).Cast(),_Universe->AccessCamera()->GetVelocity(),_Universe->AccessCamera()->GetAngularVelocity(),false,false,LC); int i; for (i=0; i<STARnumvlist; i++) { if (i>=1) GFXTranslateModel (pos[i]-pos[i-1]); else GFXTranslateModel (pos[i]); vlist->Draw(stretch,LC); } GFXTranslateModel(-pos[i-1]); vlist->EndDrawState(stretch,LC); } if (near_stars_alpha) { GFXAlphaTest(ALWAYS,0); } else { GFXEnable(DEPTHWRITE); } GFXBlendMode(ONE,ZERO); _Universe->AccessCamera()->UpdateGFX(GFXTRUE,GFXFALSE,GFXFALSE) ; GFXEnable (TEXTURE0); GFXEnable (TEXTURE1); if (fade) { GFXDeleteLight (ligh); GFXPopGlobalEffects(); } GFXLoadIdentity(MODEL); }
/* GameStarSystem::GameStarSystem(): StarSystem() { _Universe->pushActiveStarSystem (this); GFXCreateLightContext (lightcontext); bolts = new bolt_draw; collidetable = new CollideTable(this); } */ GameStarSystem::GameStarSystem(const char * filename, const Vector & centr,const float timeofyear) { no_collision_time=0; //(int)(1+2.000/SIMULATION_ATOM); ///adds to jumping table; name = NULL; _Universe->pushActiveStarSystem (this); GFXCreateLightContext (lightcontext); bolts = new bolt_draw; collidetable = new CollideTable(this); // cout << "origin: " << centr.i << " " << centr.j << " " << centr.k << " " << planetname << endl; current_stage=MISSION_SIMULATION; systemInputDFA = new InputDFA (this); LoadXML(filename,centr,timeofyear); if (!name) name =strdup (filename); AddStarsystemToUniverse(filename); // primaries[0]->SetPosition(0,0,0); //iter = primaries->createIterator(); //iter->advance(); //earth=iter->current(); //delete iter; // Calculate movement arcs; set behavior of primaries to follow these arcs //Iterator *primary_iterator = primaries->createIterator(); //primaries->SetPosition(0,0,5); //foo = new SphereMesh(1,5,5,"moon.image"); //cam[1].SetProjectionType(Camera::PARALLEL); //cam[1].SetZoom(1); //cam[1].SetPosition(Vector(0,0,0)); //cam[1].LookAt(Vector(0,0,0), Vector(0,0,1)); //cam[1].SetPosition(Vector(0,5,-2.5)); //cam[1].SetSubwindow(0,0,1,1); //cam[2].SetProjectionType(Camera::PARALLEL); //cam[2].SetZoom(10.0); //cam[2].SetPosition(Vector(5,0,0)); //cam[2].LookAt(Vector(0,0,0), Vector(0,-1,0)); //cam[2].SetPosition(Vector(5,0,-2.5)); //cam[2].SetSubwindow(0.10,0,0.10,0.10); UpdateTime(); time = 0; Atmosphere::Parameters params; params.radius = 40000; params.low_color[0] = GFXColor(0,0.5,0.0); params.low_color[1] = GFXColor(0,1.0,0.0); params.low_ambient_color[0] = GFXColor(0.0/255.0,0.0/255.0,0.0/255.0); params.low_ambient_color[1] = GFXColor(0.0/255.0,0.0/255.0,0.0/255.0); params.high_color[0] = GFXColor(0.5,0.0,0.0); params.high_color[1] = GFXColor(1.0,0.0,0.0); params.high_ambient_color[0] = GFXColor(0,0,0); params.high_ambient_color[1] = GFXColor(0,0,0); /* params.low_color[0] = GFXColor(241.0/255.0,123.0/255.0,67.0/255.0); params.low_color[1] = GFXColor(253.0/255.0,65.0/255.0,55.0/255.0); params.low_ambient_color[0] = GFXColor(0.0/255.0,0.0/255.0,0.0/255.0); params.low_ambient_color[1] = GFXColor(0.0/255.0,0.0/255.0,0.0/255.0); params.high_color[0] = GFXColor(60.0/255.0,102.0/255.0,249.0/255.0); params.high_color[1] = GFXColor(57.0/255.0,188.0/255.0,251.0/255.0); params.high_ambient_color[0] = GFXColor(0,0,0); params.high_ambient_color[1] = GFXColor(0,0,0); */ params.scattering = 5; _Universe->popActiveStarSystem (); }
GFXColor GUI_OPAQUE_MEDIUM_GRAY() { static GFXColor gui_gray = vs_config->getColor( "base_gray", GFXColor( .5, .5, .5, 1 ) ); return gui_gray; }
GFXColor GUI_OPAQUE_WHITE() { static GFXColor gui_white = vs_config->getColor( "base_white", GFXColor( 1, 1, 1, 1 ) ); return gui_white; }
void Box::ProcessDrawQueue( int ) { if ( !draw_queue[0].size() ) return; GFXBlendMode( SRCALPHA, INVSRCALPHA ); GFXColor( 0.0, .90, .3, .4 ); GFXDisable( LIGHTING ); GFXDisable( TEXTURE0 ); GFXDisable( TEXTURE1 ); GFXDisable( DEPTHWRITE ); GFXDisable( CULLFACE ); //GFXBlendMode(ONE, ONE); while ( draw_queue[0].size() ) { GFXLoadMatrixModel( draw_queue[0].back().mat ); draw_queue[0].pop_back(); GFXBegin( GFXQUAD ); GFXColor4f( 0.0, 1.0, 0.0, 0.2 ); GFXVertex3f( corner_max.i, corner_min.j, corner_max.k ); GFXVertex3f( corner_max.i, corner_max.j, corner_max.k ); GFXVertex3f( corner_min.i, corner_max.j, corner_max.k ); GFXVertex3f( corner_min.i, corner_min.j, corner_max.k ); GFXColor4f( 0.0, 1.0, 0.0, 0.2 ); GFXVertex3f( corner_min.i, corner_min.j, corner_min.k ); GFXVertex3f( corner_min.i, corner_max.j, corner_min.k ); GFXVertex3f( corner_max.i, corner_max.j, corner_min.k ); GFXVertex3f( corner_max.i, corner_min.j, corner_min.k ); GFXColor4f( 0.0, .70, 0.0, 0.2 ); GFXVertex3f( corner_max.i, corner_min.j, corner_max.k ); GFXVertex3f( corner_min.i, corner_min.j, corner_max.k ); GFXVertex3f( corner_min.i, corner_min.j, corner_min.k ); GFXVertex3f( corner_max.i, corner_min.j, corner_min.k ); GFXColor4f( 0.0, .70, 0.0, 0.2 ); GFXVertex3f( corner_max.i, corner_max.j, corner_min.k ); GFXVertex3f( corner_min.i, corner_max.j, corner_min.k ); GFXVertex3f( corner_min.i, corner_max.j, corner_max.k ); GFXVertex3f( corner_max.i, corner_max.j, corner_max.k ); GFXColor4f( 0.0, .90, .3, 0.2 ); GFXVertex3f( corner_max.i, corner_max.j, corner_max.k ); GFXVertex3f( corner_max.i, corner_min.j, corner_max.k ); GFXVertex3f( corner_max.i, corner_min.j, corner_min.k ); GFXVertex3f( corner_max.i, corner_max.j, corner_min.k ); GFXColor4f( 0.0, .90, .3, 0.2 ); GFXVertex3f( corner_min.i, corner_max.j, corner_min.k ); GFXVertex3f( corner_min.i, corner_min.j, corner_min.k ); GFXVertex3f( corner_min.i, corner_min.j, corner_max.k ); GFXVertex3f( corner_min.i, corner_max.j, corner_max.k ); GFXEnd(); /* * vlist->Draw(); * if(quadstrips!=NULL) { * for(int a=0; a<numQuadstrips; a++) * quadstrips[a]->Draw() * ; * } */ } GFXEnable( DEPTHWRITE ); }
void Core::FieldReactionSystem::UpdateAgents() { /* 1. foreach agent a 2. if a is rioter 3. for -1:1 4. for -1:1 5. foreach agent b 6. if a != b 7. sum += b:getChargeAt(a.position) 8. highestSumPos: Position with highest sum [-1:1] [-1:1] 9. a:direction = highestSumPos */ for (std::vector<Entity>::iterator it = m_entities.begin(); it != m_entities.end(); it++) // 1. { WorldPositionComponent* wpc = WGETC<WorldPositionComponent>(*it); MovementComponent* mc = WGETC<MovementComponent>(*it); UnitTypeComponent* utc = WGETC<UnitTypeComponent>(*it); AttributeComponent* ac = WGETC<AttributeComponent>(*it); if (utc->type == UnitType::Rioter) // 2. { WorldPositionComponent wpcOffset(wpc->position[0] + mc->newDirection[0] / 2.0f, wpc->position[1] + mc->newDirection[1] / 2.0f, wpc->position[2] + mc->newDirection[2] / 2.0f); glm::vec2 bestIndex = glm::vec2(0.0f, 0.0f); // Calculate which index is closest to the flow field direction. float highestSum = GetEffectOnAgentAt(*it, &wpcOffset, ac->rioter.groupID); float staySum = highestSum; //float ffDirectionCharge = 0.0f; //float ffDot = std::numeric_limits<float>::min(); /*for (int i = -1; i < 2; ++i) // 3. { for (int j = -1; j < 2; ++j) // 4. { if (i == 0 && j == 0) continue; WorldPositionComponent wpct(wpcOffset.position[0] + i, wpcOffset.position[1], wpcOffset.position[2] + j); float chargeSum = GetEffectOnAgentAt(*it, &wpct, ac->rioter.groupID); if (chargeSum > highestSum) { highestSum = chargeSum; bestIndex.x = i; bestIndex.y = j; } glm::vec2 ijNormalised = glm::normalize(glm::vec2(i, j)); float indexDot = glm::dot(glm::vec2(mc->newDirection[0], mc->newDirection[2]), ijNormalised); if (indexDot > ffDot) { ffDot = indexDot; ffDirectionCharge = chargeSum; } } }*/ // ---------------------------------------- -1, 0 ---------------------------------------- WorldPositionComponent wpct(wpcOffset.position[0] - 1, wpcOffset.position[1], wpcOffset.position[2] + 0); float chargeSum = GetEffectOnAgentAt(*it, &wpct, ac->rioter.groupID); if (chargeSum > highestSum) { highestSum = chargeSum; bestIndex.x = -1; bestIndex.y = 0; } // ---------------------------------------- 1, 0 ---------------------------------------- wpct = WorldPositionComponent(wpcOffset.position[0] + 1, wpcOffset.position[1], wpcOffset.position[2] + 0); chargeSum = GetEffectOnAgentAt(*it, &wpct, ac->rioter.groupID); if (chargeSum > highestSum) { highestSum = chargeSum; bestIndex.x = 1; bestIndex.y = 0; } // ---------------------------------------- 0, -1 ---------------------------------------- wpct = WorldPositionComponent(wpcOffset.position[0] + 0, wpcOffset.position[1], wpcOffset.position[2] -1); chargeSum = GetEffectOnAgentAt(*it, &wpct, ac->rioter.groupID); if (chargeSum > highestSum) { highestSum = chargeSum; bestIndex.x = 0; bestIndex.y = -1; } // ---------------------------------------- 0, 1 ---------------------------------------- wpct = WorldPositionComponent(wpcOffset.position[0] + 0, wpcOffset.position[1], wpcOffset.position[2] + 1); chargeSum = GetEffectOnAgentAt(*it, &wpct, ac->rioter.groupID); if (chargeSum > highestSum) { highestSum = chargeSum; bestIndex.x = 0; bestIndex.y = 1; } // ---------------------------------------- -1, -1 ---------------------------------------- wpct = WorldPositionComponent(wpcOffset.position[0] - 1, wpcOffset.position[1], wpcOffset.position[2] - 1); chargeSum = GetEffectOnAgentAt(*it, &wpct, ac->rioter.groupID); if (chargeSum > highestSum) { highestSum = chargeSum; bestIndex.x = -1; bestIndex.y = -1; } // ---------------------------------------- 1, -1 ---------------------------------------- wpct = WorldPositionComponent(wpcOffset.position[0] + 1, wpcOffset.position[1], wpcOffset.position[2] - 1); chargeSum = GetEffectOnAgentAt(*it, &wpct, ac->rioter.groupID); if (chargeSum > highestSum) { highestSum = chargeSum; bestIndex.x = 1; bestIndex.y = -1; } // ---------------------------------------- -1, 1 ---------------------------------------- wpct = WorldPositionComponent(wpcOffset.position[0] - 1, wpcOffset.position[1], wpcOffset.position[2] + 1); chargeSum = GetEffectOnAgentAt(*it, &wpct, ac->rioter.groupID); if (chargeSum > highestSum) { highestSum = chargeSum; bestIndex.x = -1; bestIndex.y = 1; } // ---------------------------------------- 1, 1 ---------------------------------------- wpct = WorldPositionComponent(wpcOffset.position[0] + 1, wpcOffset.position[1], wpcOffset.position[2] + 1); chargeSum = GetEffectOnAgentAt(*it, &wpct, ac->rioter.groupID); if (chargeSum > highestSum) { highestSum = chargeSum; bestIndex.x = 1; bestIndex.y = 1; } glm::vec3 pfVector; if (highestSum - staySum > STAY_LIMIT) { if (bestIndex.x == 0.0f || bestIndex.y == 0.0f) pfVector = glm::vec3(bestIndex.x, 0.0f, bestIndex.y); else pfVector = glm::normalize(glm::vec3(bestIndex.x, 0, bestIndex.y)); } else pfVector = glm::vec3(0.0f); float dot = glm::dot(glm::vec2(mc->newDirection[0], mc->newDirection[2]), glm::vec2(pfVector.x, pfVector.z)); if (dot < 0.0f /*|| (ffDirectionCharge < 0.0f && ffDirectionCharge < highestSum)*/) { //float factor = 1.0 / (-ffDirectionCharge * 1000.0f); //mc->newDirection[0] *= factor; //mc->newDirection[1] *= factor; //mc->newDirection[2] *= factor; MovementComponent::SetDirection(mc, 0.0f, 0.0f, 0.0f); } // Draw a yellow PF direction line and a black ff direction line for each rioter. GFX::Debug::DrawLine(Core::WorldPositionComponent::GetVec3(*wpc), glm::vec3(wpc->position[0] + pfVector.x, wpc->position[1] + pfVector.y, wpc->position[2] + pfVector.z), GFXColor(1.0f, 1.0f, 0.0f, 1.0f), 1, false); GFX::Debug::DrawLine(Core::WorldPositionComponent::GetVec3(*wpc), glm::vec3(wpc->position[0] + mc->newDirection[0], wpc->position[1] + mc->newDirection[1], wpc->position[2] + mc->newDirection[2]), GFXColor(0.0f, 0.0f, 0.0f, 1.0f), 1, false); // Update the direction, making sure it is normalised (if not zero). glm::vec3 newDir = glm::vec3(mc->newDirection[0] * FF_FACTOR + pfVector.x * PF_FACTOR, mc->newDirection[1] * FF_FACTOR + pfVector.y * PF_FACTOR, mc->newDirection[2] * FF_FACTOR + pfVector.z * PF_FACTOR); if ((std::abs(newDir.x) + std::abs(newDir.y) + std::abs(newDir.z)) > 0.1f) newDir = glm::normalize(newDir); MovementComponent::SetDirection(mc, newDir.x, newDir.y, newDir.z); //MovementComponent::SetDirection(mc, 0.0f, 0.0f, 0.0f); } } }
int TextPlane::Draw(const string & newText, int offset,bool startlower, bool force_highquality, bool automatte) { int retval=1; bool drawbg = (bgcol.a!=0); static unsigned int * display_lists=CreateLists (); // some stuff to draw the text stuff string::const_iterator text_it = newText.begin(); static bool use_bit = force_highquality||XMLSupport::parse_bool(vs_config->getVariable ("graphics","high_quality_font","false")); static float font_point = XMLSupport::parse_float (vs_config->getVariable ("graphics","font_point","16")); static bool font_antialias = XMLSupport::parse_bool (vs_config->getVariable ("graphics","font_antialias","true")); void * fnt = getFont(); static float std_wid=glutStrokeWidth (GLUT_STROKE_ROMAN,'W'); myFontMetrics.i=font_point*std_wid/(119.05+33.33); if (use_bit) myFontMetrics.i=glutBitmapWidth(fnt,'W'); myFontMetrics.j=font_point; myFontMetrics.i/=.5*g_game.x_resolution; myFontMetrics.j/=.5*g_game.y_resolution; float tmp,row, col; float origcol,origrow; GetPos (row,col); GetPos(row,origcol); float rowheight=use_bit?getFontHeight():myFontMetrics.j; myFontMetrics.j=rowheight; if (startlower) { row -= rowheight; } GFXPushBlendMode(); glLineWidth (1); if (!use_bit&&font_antialias) { GFXBlendMode (SRCALPHA,INVSRCALPHA); if(gl_options.smooth_lines) { glEnable(GL_LINE_SMOOTH); } }else { GFXBlendMode (SRCALPHA,INVSRCALPHA); if(gl_options.smooth_lines) { glDisable(GL_LINE_SMOOTH); } } GFXColorf(this->col); GFXDisable (DEPTHTEST); GFXDisable (CULLFACE); GFXDisable (LIGHTING); GFXDisable (TEXTURE0); GFXDisable (TEXTURE1); glPushMatrix(); glLoadIdentity(); if (!automatte&&drawbg) { GFXColorf(this->bgcol); DrawSquare(col,this->myDims.i,row-rowheight*.25,row+rowheight); } GFXColorf(this->col); int entercount=0; for (;entercount<offset&&text_it!=newText.end();text_it++) { if (*text_it=='\n') entercount++; } glTranslatef(col,row,0); // glRasterPos2f (g_game.x_resolution*(1-(col+1)/2),g_game.y_resolution*(row+1)/2); glRasterPos2f (0,0); float scalex=1; float scaley=1; int potentialincrease=0; if (!use_bit) { int numplayers=1; if (_Universe) // _Universe can be NULL during bootstrap. numplayers = (_Universe->numPlayers()>3?_Universe->numPlayers()/2: _Universe->numPlayers()); scalex=numplayers*myFontMetrics.i/std_wid; scaley=myFontMetrics.j/(119.05+33.33); } glScalef (scalex,scaley,1); bool firstThroughLoop=true; GFXColor currentCol (this->col); while(text_it != newText.end() && (firstThroughLoop||row>myDims.j-rowheight*.25)) { unsigned char myc = *text_it; if (myc=='_') { myc = ' '; } float shadowlen = 0; if(myc=='\t') { shadowlen=glutBitmapWidth(fnt,' ')*5./(.5*g_game.x_resolution); } else { if (use_bit) { shadowlen = glutBitmapWidth (fnt,myc)/(float)(.5*g_game.x_resolution); // need to use myc -- could have transformed '_' to ' ' } else { shadowlen = myFontMetrics.i*glutStrokeWidth(GLUT_STROKE_ROMAN,myc)/std_wid; } } if (*text_it=='#') { if (newText.end()-text_it>6) { float r,g,b; r = TwoCharToFloat (*(text_it+1),*(text_it+2)); g = TwoCharToFloat (*(text_it+3),*(text_it+4)); b = TwoCharToFloat (*(text_it+5),*(text_it+6)); if (r==0&&g==0&&b==0) { currentCol = this->col; }else { currentCol = GFXColor(r, g, b, this->col.a); } GFXColorf(currentCol); static bool setRasterPos= XMLSupport::parse_bool(vs_config->getVariable("graphics","set_raster_text_color","true")); if (use_bit&&setRasterPos) glRasterPos2f(col-origcol,0); text_it = text_it+6; } else { break; } text_it++; continue; }else if(*text_it>=32) {//always true if(automatte){ GFXColorf(this->bgcol); DrawSquare(col-origcol,col-origcol+shadowlen/scalex,-rowheight*.25/scaley,rowheight*.75/scaley); GFXColorf(currentCol); } //glutStrokeCharacter (GLUT_STROKE_ROMAN,*text_it); retval+=potentialincrease; potentialincrease=0; int lists = display_lists[myc+(isInside()?128:0)]; if (lists) { GFXCallList(lists); }else{ if (use_bit){ glutBitmapCharacter (fnt,myc); } else{ glutStrokeCharacter (GLUT_STROKE_ROMAN,myc); } } } if(*text_it=='\t') { if(automatte){ GFXColorf(this->bgcol); DrawSquare(col-origcol,col-origcol+shadowlen*5/(.5*g_game.x_resolution),-rowheight*.25/scaley,rowheight*.75/scaley); GFXColorf(currentCol); } col+=shadowlen; glutBitmapCharacter (fnt,' '); glutBitmapCharacter (fnt,' '); glutBitmapCharacter (fnt,' '); glutBitmapCharacter (fnt,' '); glutBitmapCharacter (fnt,' '); } else { col+=shadowlen; } if(doNewLine(text_it,newText.end(),col,myDims.i, myFontMetrics.i,row-rowheight<=myDims.j)){ GetPos (tmp,col); firstThroughLoop=false; row -= rowheight; glPopMatrix(); glPushMatrix (); glLoadIdentity(); if (!automatte&&drawbg) { GFXColorf(this->bgcol); DrawSquare(col,this->myDims.i,row-rowheight*.25,row+rowheight*.75); } if (*text_it=='\n') { currentCol = this->col; } GFXColorf(currentCol); glTranslatef (col,row,0); glScalef(scalex,scaley,1); glRasterPos2f(0,0); potentialincrease++; } text_it++; } if(gl_options.smooth_lines) { glDisable(GL_LINE_SMOOTH); } glPopMatrix(); GFXPopBlendMode(); GFXColorf(this->col); return retval; }
GFXColor GUI_OPAQUE_BLACK() { static GFXColor gui_black = vs_config->getColor( "base_black", GFXColor( 0, 0, 0, 1 ) ); return gui_black; }
static GFXColor getTerrainColor() { float col[4] = {.1f, .1f, .1f, 1.0f}; return GFXColor( col[0], col[1], col[2], col[3] ); }
GFXColor GUI_OPAQUE_LIGHT_GRAY() { static GFXColor gui_light_gray = vs_config->getColor( "base_light_gray", GFXColor( .25, .25, .25, 1 ) ); return gui_light_gray; }
void TextBox (int room, std::string ind, std::string text, float x, float y, Vector widheimult, Vector backcol, float backalp, Vector forecol) { BaseInterface::Room *newroom=CheckRoom(room); if (!newroom) return; newroom->objs.push_back(new BaseInterface::Room::BaseText(text, x, y, widheimult.i, widheimult.j, widheimult.k, GFXColor(backcol, backalp), GFXColor(forecol), ind)); }
GFXColor GUI_OPAQUE_DARK_GRAY() { static GFXColor gui_dark_gray = vs_config->getColor( "base_dark_gray", GFXColor( .75, .75, .75, 1 ) ); return gui_dark_gray; }
void NavigationSystem::DrawSystem() { UniverseUtil::PythonUnitIter bleh = UniverseUtil::getUnitList(); if ( !(*bleh) ) return; //string mystr ("3d "+XMLSupport::tostring (system_view)); //UniverseUtil::IOmessage (0,"game","all",mystr); //what's my name //*************************** TextPlane systemname; //will be used to display shits names int faction = FactionUtil::GetFactionIndex( UniverseUtil::GetGalaxyFaction( _Universe->activeStarSystem()->getFileName() ) ); //GFXColor factioncolor = factioncolours[faction]; string systemnamestring = "#ff0000Sector: #ffff00"+getStarSystemSector( _Universe->activeStarSystem()->getFileName() ) +" #ff0000Current System: #ffff00"+_Universe->activeStarSystem()->getName()+" (" +FactionUtil::GetFactionName( faction ) +"#ffff00)"; //int length = systemnamestring.size(); //float offset = (float(length)*0.001); //systemname.SetPos( (((screenskipby4[0]+screenskipby4[1])/2)-offset) , screenskipby4[3]); // middle position systemname.SetPos( screenskipby4[0]+0.03, screenskipby4[3]+0.02 ); //left position systemname.col = GFXColor( 1, 1, .7, 1 ); systemname.SetText( systemnamestring ); //systemname.SetCharSize(1, 1); static float background_alpha = XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud", "text_background_alpha", "0.0625" ) ); GFXColor tpbg = systemname.bgcol; bool automatte = (0 == tpbg.a); if (automatte) systemname.bgcol = GFXColor( 0, 0, 0, background_alpha ); systemname.Draw( systemnamestring, 0, true, false, automatte ); systemname.bgcol = tpbg; //*************************** //navdrawlist mainlist(0, screenoccupation, factioncolours); // lists of items to draw //mainlist.unselectedalpha = unselectedalpha; navdrawlist mouselist( 1, screenoccupation, factioncolours ); //lists of items to draw that are in mouse range QVector pos; //item position QVector pos_flat; //item position flat on plane float zdistance = 0.0; float zscale = 0.0; Adjust3dTransformation( system_view == VIEW_3D, 1 ); //Set up first item to compare to + centres //********************************** while ( (*bleh) && ( _Universe->AccessCockpit()->GetParent() != (*bleh) ) && ( UnitUtil::isSun( *bleh ) || !UnitUtil::isSignificant( *bleh ) ) ) //no sun's in initial setup ++bleh; if ( !(*bleh) ) //nothing there that's significant, just do it all bleh = UniverseUtil::getUnitList(); //GET THE POSITION //************************* pos = (*bleh)->Position(); ReplaceAxes( pos ); //************************* //Modify by old rotation amount //************************* //if(system_view==VIEW_3D) //{ //pos = dxyz(pos, 0, ry_s, 0); //pos = dxyz(pos, rx_s, 0, 0); //} //************************* float max_x = (float) pos.i; float min_x = (float) pos.i; float max_y = (float) pos.j; float min_y = (float) pos.j; float max_z = (float) pos.k; float min_z = (float) pos.k; //float themaxvalue = fabs(pos.i); themaxvalue = 0.0; float center_nav_x = ( (screenskipby4[0]+screenskipby4[1])/2 ); float center_nav_y = ( (screenskipby4[2]+screenskipby4[3])/2 ); //********************************** //Retrieve unit data min/max //********************************** while (*bleh) { //this goes through one time to get the major components locations, and scales its output appropriately if ( UnitUtil::isSun( *bleh ) ) { ++bleh; continue; } string temp = (*bleh)->name; pos = (*bleh)->Position(); ReplaceAxes( pos ); //Modify by old rotation amount //************************* //if(system_view==VIEW_3D) //{ //pos = dxyz(pos, 0, ry_s, 0); //pos = dxyz(pos, rx_s, 0, 0); //} //************************* //************************* if ( ( UnitUtil::isSignificant( *bleh ) ) || ( _Universe->AccessCockpit()->GetParent() == (*bleh) ) ) RecordMinAndMax( pos, min_x, max_x, min_y, max_y, min_z, max_z, themaxvalue ); ++bleh; } //********************************** //Find Centers //********************************** center_x = (min_x+max_x)/2; center_y = (min_y+max_y)/2; center_z = (min_z+max_z)/2; //********************************** max_x = 2*max_x-center_x; max_y = 2*max_y-center_y; max_z = 2*max_z-center_z; min_x = 2*min_x-center_x; min_y = 2*min_y-center_y; min_z = 2*min_z-center_z; themaxvalue *= 2; //#define SQRT3 1.7320508 //themaxvalue = sqrt(themaxvalue*themaxvalue + themaxvalue*themaxvalue + themaxvalue*themaxvalue); //themaxvalue = SQRT3*themaxvalue; //Set Camera Distance //********************************** //{ float half_x = (max_x-min_x); float half_y = (max_y-min_y); float half_z = (max_z-min_z); camera_z = sqrt( (half_x*half_x)+(half_y*half_y)+(half_z*half_z) ); //float halfmax = 0.5*themaxvalue; //camera_z = sqrt( (halfmax*halfmax) + (halfmax*halfmax) + (halfmax*halfmax) ); //camera_z = 4.0*themaxvalue; //} //********************************** DrawOriginOrientationTri( center_nav_x, center_nav_y, 1 ); /* * string mystr ("max x "+XMLSupport::tostring (max_x)); * UniverseUtil::IOmessage (0,"game","all",mystr); * * string mystr2 ("min x "+XMLSupport::tostring (min_x)); * UniverseUtil::IOmessage (0,"game","all",mystr2); * * string mystr3 ("max y "+XMLSupport::tostring (max_y)); * UniverseUtil::IOmessage (0,"game","all",mystr3); * * string mystr4 ("min y "+XMLSupport::tostring (min_y)); * UniverseUtil::IOmessage (0,"game","all",mystr4); * * string mystrcx ("center x "+XMLSupport::tostring (center_x)); * UniverseUtil::IOmessage (0,"game","all",mystrcx); * * string mystrcy ("center y "+XMLSupport::tostring (center_y)); * UniverseUtil::IOmessage (0,"game","all",mystrcy); */ Unit *ThePlayer = ( UniverseUtil::getPlayerX( UniverseUtil::getCurrentPlayer() ) ); //Enlist the items and attributes //********************************** un_iter blah = UniverseUtil::getUnitList(); while (*blah) { //this draws the points //Retrieve unit data //********************************** string temp = (*blah)->name; pos = (*blah)->Position(); ReplaceAxes( pos ); float the_x, the_y, the_x_flat, the_y_flat, system_item_scale_temp; TranslateCoordinates( pos, pos_flat, center_nav_x, center_nav_y, themaxvalue, zscale, zdistance, the_x, the_y, the_x_flat, the_y_flat, system_item_scale_temp, 1 ); //IGNORE OFF SCREEN //********************************** if ( !TestIfInRange( screenskipby4[0], screenskipby4[1], screenskipby4[2], screenskipby4[3], the_x, the_y ) ) { ++blah; continue; } //********************************** //Now starts the test that determines the type of things and inserts //| //| //\/ float insert_size = 0.0; int insert_type = navambiguous; if ( (*blah)->isUnit() == UNITPTR ) { //unit /*if(UnitUtil::isPlayerStarship(*blah) > -1) // is a PLAYER SHIP * { * if (UnitUtil::isPlayerStarship (*blah)==UniverseUtil::getCurrentPlayer()) // is THE PLAYER * { * insert_type = navcurrentplayer; * insert_size = navcurrentplayersize; * } * else // is A PLAYER * { * insert_type = navplayer; * insert_size = navplayersize; * } * } * else // is a non player ship * {*/ if ( UnitUtil::isSignificant( *blah ) ) { //capship or station if ( (*blah)->GetComputerData().max_speed() == 0 ) { //is this item STATIONARY? insert_type = navstation; insert_size = navstationsize; } else { //it moves = capship if ( ThePlayer->InRange( (*blah), false, false ) ) { //only insert if in range insert_type = navcapship; insert_size = navcapshipsize; } else { //skip unit completely if not in range ++blah; continue; } } } else { //fighter /*if(ThePlayer->InRange((*blah),false,false)) // only insert if in range * { * insert_type = navfighter; * insert_size = navfightersize; * } * else // skip unit completely if not in range * { * ++blah; * continue; * }*/ if (UnitUtil::isPlayerStarship( *blah ) > -1) { //is THE PLAYER insert_type = navfighter; insert_size = navfightersize; } else { //skip unit completely if not in range ++blah; continue; } } //} } else if ( (*blah)->isUnit() == PLANETPTR ) { //is it a PLANET? if ( UnitUtil::isSun( *blah ) ) { //is this a SUN? insert_type = navsun; insert_size = navsunsize; } else if ( !( (*blah)->GetDestinations().empty() ) ) { //is a jump point (has destinations) insert_type = navjump; insert_size = navjumpsize; } else { //its a planet insert_type = navplanet; insert_size = navplanetsize; } } else if ( (*blah)->isUnit() == MISSILEPTR ) { //a missile insert_type = navmissile; insert_size = navmissilesize; } else if ( (*blah)->isUnit() == ASTEROIDPTR ) { //an asteroid insert_type = navasteroid; insert_size = navasteroidsize; } else if ( (*blah)->isUnit() == NEBULAPTR ) { //a nebula insert_type = navnebula; insert_size = navnebulasize; } else { //undefined non unit insert_type = navambiguous; insert_size = navambiguoussize; } if ( system_item_scale_temp > (system_item_scale*3) ) system_item_scale_temp = (system_item_scale*3); insert_size *= system_item_scale_temp; if ( _Universe->AccessCockpit()->GetParent()->Target() == (*blah) ) { //Get a color from the config static GFXColor col = vs_config->getColor( "nav", "targetted_unit", GFXColor(1, 0.3, 0.3, 0.8) ); DrawTargetCorners( the_x, the_y, insert_size, col ); } bool tests_in_range = 0; if (insert_type == navstation) tests_in_range = TestIfInRangeBlk( the_x, the_y, insert_size, mouse_x_current, mouse_y_current ); else tests_in_range = TestIfInRangeRad( the_x, the_y, insert_size, mouse_x_current, mouse_y_current ); Unit *myunit = (*blah); ++blah; DisplayOrientationLines( the_x, the_y, the_x_flat, the_y_flat, 1 ); if (tests_in_range) { mouselist.insert( insert_type, insert_size, the_x, the_y, myunit ); } else { drawlistitem( insert_type, insert_size, the_x, the_y, myunit, screenoccupation, false, (*blah) ? true : false, unselectedalpha, factioncolours ); } } //********************************** // done enlisting items and attributes //Adjust mouse list for 'n' kliks //********************************** //STANDARD : (1 3 2) ~ [0] [2] [1] //VS : (1 2 3) ~ [0] [1] [2] <-- use this if (mouselist.get_n_contents() > 0) { //mouse is over a target when this is > 0 if (mouse_wentdown[2] == 1) //mouse button went down for mouse button 2(standard) rotations += 1; } if ( rotations >= mouselist.get_n_contents() ) //dont rotate more than there is rotations = 0; int r = 0; while (r < rotations) { //rotate whatver rotations, leaving n rotated items, tail on top mouselist.rotate(); r += 1; } //********************************** //Draw the damn shit //********************************** //mainlist.draw(); // draw the items //mainlist.wipe(); // whipe the list //********************************** //Check for selection query //give back the selected tail IF there is one //IF given back, undo the selection state //********************************** if ( 1 || checkbit( buttonstates, 1 ) ) { //button #2 is down, wanting a (selection) if (mouselist.get_n_contents() > 0) { //mouse is over a target when this is > 0 if (mouse_wentdown[0] == 1) { //mouse button went down for mouse button 1 currentselection = mouselist.gettailunit(); unsetbit( buttonstates, 1 ); //JUST FOR NOW, target == current selection. later it'll be used for other shit, that will then set target. if ( currentselection.GetUnit() ) { ( UniverseUtil::getPlayerX( UniverseUtil::getCurrentPlayer() ) )->Target( currentselection.GetUnit() ); ( UniverseUtil::getPlayerX( UniverseUtil::getCurrentPlayer() ) )->LockTarget( currentselection.GetUnit() ); } } } } //********************************** //Clear the lists //********************************** mouselist.draw(); //draw mouse over'd items mouselist.wipe(); //whipe mouse over'd list //********************************** }