本文整理汇总了C++中ContentManager类的典型用法代码示例。如果您正苦于以下问题:C++ ContentManager类的具体用法?C++ ContentManager怎么用?C++ ContentManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ContentManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Test
void PerformanceTesting::Test(
const std::string & cardir,
const std::string & carname,
ContentManager & content,
std::ostream & info_output,
std::ostream & error_output)
{
info_output << "Beginning car performance test on " << carname << std::endl;
// init track
assert(!track);
assert(!plane);
btVector3 planeNormal(0, 0, 1);
btScalar planeConstant = 0;
plane = new btStaticPlaneShape(planeNormal, planeConstant);
plane->setUserPointer(static_cast<void*>(&surface));
track = new btCollisionObject();
track->setCollisionShape(plane);
track->setActivationState(DISABLE_SIMULATION);
track->setUserPointer(static_cast<void*>(&surface));
world.addCollisionObject(track);
//load the car dynamics
std::tr1::shared_ptr<PTree> cfg;
content.load(cfg, cardir, carname + ".car");
if (!cfg->size())
{
return;
}
// position is the center of a 2 x 4 x 1 meter box on track surface
btVector3 pos(0.0, -2.0, 0.5);
btQuaternion rot = btQuaternion::getIdentity();
const std::string tire = "";
const bool damage = false;
if (!car.Load(*cfg, cardir, tire, pos, rot, damage, world, content, error_output))
{
return;
}
info_output << "Car dynamics loaded" << std::endl;
info_output << carname << " Summary:\n" <<
"Mass (kg) including driver and fuel: " << 1 / car.GetInvMass() << "\n" <<
"Center of mass (m): " << car.GetCenterOfMass() << std::endl;
std::ostringstream statestream;
joeserialize::BinaryOutputSerializer serialize_output(statestream);
if (!car.Serialize(serialize_output))
{
error_output << "Serialization error" << std::endl;
}
//else info_output << "Car state: " << statestream.str();
carstate = statestream.str();
TestMaxSpeed(info_output, error_output);
TestStoppingDistance(false, info_output, error_output);
TestStoppingDistance(true, info_output, error_output);
info_output << "Car performance test complete." << std::endl;
}
示例2: GetDrawableFromNode
bool SPRITE2D::Load(
SCENENODE & parent,
const std::string & texturepath,
const std::string & texturename,
ContentManager & content,
float draworder)
{
Unload(parent);
assert(!draw.valid());
assert(!node.valid());
TEXTUREINFO texinfo;
texinfo.mipmap = false;
texinfo.repeatu = false;
texinfo.repeatv = false;
texinfo.npot = false;
std::tr1::shared_ptr<TEXTURE> texture;
if (!content.load(texturepath, texturename, texinfo, texture)) return false;
node = parent.AddNode();
SCENENODE & noderef = parent.GetNode(node);
draw = noderef.GetDrawlist().twodim.insert(DRAWABLE());
DRAWABLE & drawref = GetDrawableFromNode(noderef);
drawref.SetDiffuseMap(texture);
drawref.SetVertArray(&varray);
drawref.SetDrawOrder(draworder);
drawref.SetCull(false, false);
drawref.SetColor(r,g,b,a);
//std::cout << "Sprite draworder: " << draworder << std::endl;
return true;
}
示例3: LoadPhysics
bool CAR::LoadPhysics(
const PTree & cfg,
const std::string & carpath,
const MATHVECTOR <float, 3> & initial_position,
const QUATERNION <float> & initial_orientation,
const bool defaultabs,
const bool defaulttcs,
const bool damage,
ContentManager & content,
DynamicsWorld & world,
std::ostream & error_output)
{
std::string carmodel;
std::tr1::shared_ptr<MODEL> modelptr;
if (!cfg.get("body.mesh", carmodel, error_output)) return false;
if (!content.load(carpath, carmodel, modelptr)) return false;
btVector3 size = ToBulletVector(modelptr->GetSize());
btVector3 center = ToBulletVector(modelptr->GetCenter());
btVector3 position = ToBulletVector(initial_position);
btQuaternion rotation = ToBulletQuaternion(initial_orientation);
if (!dynamics.Load(cfg, size, center, position, rotation, damage, world, error_output)) return false;
dynamics.SetABS(defaultabs);
dynamics.SetTCS(defaulttcs);
mz_nominalmax = (GetTireMaxMz(FRONT_LEFT) + GetTireMaxMz(FRONT_RIGHT)) * 0.5;
return true;
}
示例4: LoadLight
bool CAR::LoadLight(
const PTree & cfg,
ContentManager & content,
std::ostream & error_output)
{
float radius;
std::string radiusstr;
MATHVECTOR<float, 3> pos(0), col(0);
if (!cfg.get("position", pos, error_output)) return false;
if (!cfg.get("color", col, error_output)) return false;
if (!cfg.get("radius", radius, error_output)) return false;
cfg.get("radius", radiusstr);
lights.push_back(LIGHT());
SCENENODE & bodynoderef = topnode.GetNode(bodynode);
lights.back().node = bodynoderef.AddNode();
SCENENODE & node = bodynoderef.GetNode(lights.back().node);
node.GetTransform().SetTranslation(MATHVECTOR<float,3>(pos[0], pos[1], pos[2]));
std::tr1::shared_ptr<MODEL> mesh;
if (!content.get("", "cube"+radiusstr, mesh))
{
VERTEXARRAY varray;
varray.SetToUnitCube();
varray.Scale(radius, radius, radius);
content.load("", "cube"+radiusstr, varray, mesh);
}
models.push_back(mesh);
keyed_container <DRAWABLE> & dlist = GetDrawlist(node, OMNI);
lights.back().draw = dlist.insert(DRAWABLE());
DRAWABLE & draw = dlist.get(lights.back().draw);
draw.SetColor(col[0], col[1], col[2]);
draw.SetModel(*mesh);
draw.SetCull(true, true);
draw.SetDrawEnable(false);
return true;
}
示例5: LoadLight
bool CarGraphics::LoadLight(
const PTree & cfg,
ContentManager & content,
std::ostream & error_output)
{
float radius;
std::string radiusstr;
Vec3 pos(0), col(0);
if (!cfg.get("position", pos, error_output)) return false;
if (!cfg.get("color", col, error_output)) return false;
if (!cfg.get("radius", radius, error_output)) return false;
cfg.get("radius", radiusstr);
lights.push_back(Light());
SceneNode & bodynoderef = topnode.GetNode(bodynode);
lights.back().node = bodynoderef.AddNode();
SceneNode & node = bodynoderef.GetNode(lights.back().node);
node.GetTransform().SetTranslation(Vec3(pos[0], pos[1], pos[2]));
std::shared_ptr<Model> mesh;
if (!content.get(mesh, "", "cube" + radiusstr))
{
VertexArray varray;
varray.SetToUnitCube();
varray.Scale(radius, radius, radius);
content.load(mesh, "", "cube" + radiusstr, varray);
}
models.insert(mesh);
keyed_container <Drawable> & dlist = node.GetDrawList().lights_omni;
lights.back().draw = dlist.insert(Drawable());
Drawable & draw = dlist.get(lights.back().draw);
draw.SetColor(col[0], col[1], col[2]);
draw.SetModel(*mesh);
draw.SetCull(true);
draw.SetDrawEnable(false);
return true;
}
示例6: Load
bool FONT::Load(
const std::string & fontinfopath,
const std::string & texpath,
const std::string & texname,
ContentManager & content,
std::ostream & error_output,
bool mipmap)
{
TEXTUREINFO texinfo;
texinfo.mipmap = mipmap;
texinfo.repeatu = false;
texinfo.repeatv = false;
if (!content.load(texpath, texname, texinfo, font_texture)) return false;
std::ifstream fontinfo(fontinfopath.c_str());
if (!fontinfo)
{
error_output << "Can't find font information file: " << fontinfopath << std::endl;
return false;
}
const std::string sizestr("size=");
const float sw = font_texture->GetScale() / font_texture->GetW();
const float sh = font_texture->GetScale() / font_texture->GetH();
while (fontinfo)
{
std::string curstr;
fontinfo >> curstr;
if (curstr == "char")
{
unsigned int cur_id(0);
if (!Parse("id=", cur_id, fontinfo, fontinfopath, error_output)) return false;
CHARINFO & info = charinfo[cur_id];
if (!Parse("x=", info.x, fontinfo, fontinfopath, error_output)) return false;
if (!Parse("y=", info.y, fontinfo, fontinfopath, error_output)) return false;
if (!Parse("width=", info.width, fontinfo, fontinfopath, error_output)) return false;
if (!Parse("height=", info.height, fontinfo, fontinfopath, error_output)) return false;
if (!Parse("xoffset=", info.xoffset, fontinfo, fontinfopath, error_output)) return false;
if (!Parse("yoffset=", info.yoffset, fontinfo, fontinfopath, error_output)) return false;
if (!Parse("xadvance=", info.xadvance, fontinfo, fontinfopath, error_output)) return false;
fontinfo >> curstr >> curstr; //don't care
info.x *= sw;
info.y *= sh;
info.width *= sw;
info.height *= sh;
info.xoffset *= sw;
info.yoffset *= sh;
info.xadvance *= sw;
info.loaded = true;
}
else if (curstr.compare(0, sizestr.size(), sizestr) == 0)
示例7: Test
void PERFORMANCE_TESTING::Test(
const std::string & cardir,
const std::string & carname,
ContentManager & content,
std::ostream & info_output,
std::ostream & error_output)
{
info_output << "Beginning car performance test on " << carname << std::endl;
//load the car dynamics
std::tr1::shared_ptr<PTree> cfg;
content.load(cfg, cardir, carname + ".car");
if (!cfg->size())
{
return;
}
btVector3 size(0, 0, 0), center(0, 0, 0), pos(0, 0, 0); // collision shape from wheel data
btQuaternion rot = btQuaternion::getIdentity();
bool damage = false;
if (!car.Load(*cfg, size, center, pos, rot, damage, world, error_output))
{
return;
}
info_output << "Car dynamics loaded" << std::endl;
info_output << carname << " Summary:\n" <<
"Mass (kg) including driver and fuel: " << 1 / car.GetInvMass() << "\n" <<
"Center of mass (m): " << car.GetCenterOfMass() << std::endl;
std::stringstream statestream;
joeserialize::BinaryOutputSerializer serialize_output(statestream);
if (!car.Serialize(serialize_output))
{
error_output << "Serialization error" << std::endl;
}
//else info_output << "Car state: " << statestream.str();
carstate = statestream.str();
// fixme
info_output << "Car performance test broken - exiting." << std::endl;
return;
TestMaxSpeed(info_output, error_output);
TestStoppingDistance(false, info_output, error_output);
TestStoppingDistance(true, info_output, error_output);
info_output << "Car performance test complete." << std::endl;
}
示例8: Load
void ParticleSystem::Load(
const std::string & texpath,
const std::string & texname,
int anisotropy,
ContentManager & content)
{
TextureInfo texinfo;
texinfo.anisotropy = anisotropy;
content.load(texture, texpath, texname, texinfo);
draw = GetDrawlist(node).insert(Drawable());
Drawable & drawref = GetDrawlist(node).get(draw);
drawref.SetDrawEnable(false);
drawref.SetVertArray(&varrays[cur_varray]);
drawref.SetTextures(texture->GetID());
drawref.SetCull(false, false);
}
示例9: Init
bool HUD::Init(
const std::string & texturepath,
ContentManager & content,
FONT & lcdfont,
FONT & sansfont,
FONT & sansfont_noshader,
float displaywidth,
float displayheight,
bool debugon,
std::ostream & error_output)
{
const float opacity = 0.8;
const float screenhwratio = displayheight / displaywidth;
const float barheight = 64.0 / displayheight;
const float barwidth = 256.0 / displaywidth;
TEXTUREINFO texinfo;
texinfo.mipmap = false;
texinfo.repeatu = false;
texinfo.repeatv = false;
float timerbox_lowery = 0;
{
timernode = hudroot.AddNode();
SCENENODE & timernoderef = hudroot.GetNode(timernode);
float timerboxdimx = 96.0 / displaywidth;
float timerboxdimy = 64.0 / displayheight;
timerboxdraw = AddDrawable(timernoderef);
DRAWABLE & timerboxdrawref = GetDrawable(timernoderef, timerboxdraw);
TEXTUREINFO timerboxtexinfo;
timerboxtexinfo.mipmap = false;
timerboxtexinfo.repeatu = true;
timerboxtexinfo.repeatv = false;
std::tr1::shared_ptr<TEXTURE> timerboxtex;
if (!content.load(texturepath, "timerbox.png", timerboxtexinfo, timerboxtex)) return false;
float totalsizex = timerboxdimx * 6.05;
float totalsizey = timerboxdimy * 2.0;
float x = totalsizex * 0.5 - timerboxdimx * 0.65;
float y = totalsizey * 0.5 - timerboxdimy * 0.25;
float w = totalsizex - timerboxdimx * 2;
float h = totalsizey - timerboxdimy * 2;
timerboxverts.SetTo2DBox(x, y, w, h, timerboxdimx, timerboxdimy);
timerbox_lowery = y + timerboxdimy * 0.5;
timerboxdrawref.SetDiffuseMap(timerboxtex);
timerboxdrawref.SetVertArray(&timerboxverts);
timerboxdrawref.SetCull(false, false);
timerboxdrawref.SetColor(1, 1, 1, opacity);
timerboxdrawref.SetDrawOrder(0.1);
float fontscaley = timerboxdimy * 0.4;
float fontscalex = fontscaley * screenhwratio;
float startx = timerboxdimx * 0.45 - timerboxdimx * 0.15;
float xinc = timerboxdimx * 1.5;
laptime_label.Init(timernoderef, sansfont, "Lap time:", startx, timerboxdimy*0.9-timerboxdimy*0.3, fontscalex, fontscaley);
laptime_label.SetDrawOrder(timernoderef, 0.2);
lastlaptime_label.Init(timernoderef, sansfont, "Last lap:", startx+xinc, timerboxdimy*.9-timerboxdimy*0.3, fontscalex, fontscaley);
lastlaptime_label.SetDrawOrder(timernoderef, 0.2);
bestlaptime_label.Init(timernoderef, sansfont, "Best lap:", startx+xinc*2.0, timerboxdimy*.9-timerboxdimy*0.3, fontscalex, fontscaley);
bestlaptime_label.SetDrawOrder(timernoderef, 0.2);
laptime.Init(timernoderef, lcdfont, "", startx, timerboxdimy*1.2-timerboxdimy*0.3, fontscalex, fontscaley);
laptime.SetDrawOrder(timernoderef, 0.2);
lastlaptime.Init(timernoderef, lcdfont, "", startx+xinc, timerboxdimy*1.2-timerboxdimy*0.3, fontscalex, fontscaley);
lastlaptime.SetDrawOrder(timernoderef, 0.2);
bestlaptime.Init(timernoderef, lcdfont, "", startx+xinc*2.0, timerboxdimy*1.2-timerboxdimy*0.3, fontscalex, fontscaley);
bestlaptime.SetDrawOrder(timernoderef, 0.2);
}
{
float fontscaley = barheight * 0.5;
float fontscalex = screenhwratio * fontscaley;
float x = fontscalex * 0.25;
float y = timerbox_lowery + fontscaley;
driftscoreindicator.Init(hudroot, sansfont, "", x, y, fontscalex, fontscaley);
driftscoreindicator.SetDrawOrder(hudroot, 0.2);
}
{
float fontscaley = barheight * 0.5;
float fontscalex = screenhwratio * fontscaley;
float x = fontscalex * 0.25;
float y = timerbox_lowery + fontscaley * 2;
lapindicator.Init(hudroot, sansfont, "", x, y, fontscalex, fontscaley);
lapindicator.SetDrawOrder(hudroot, 0.2);
}
{
float fontscaley = barheight * 0.5;
float fontscalex = screenhwratio * fontscaley;
float x = fontscalex * 0.25;
float y = timerbox_lowery + fontscaley * 3;
//.........这里部分代码省略.........
示例10: Load
bool CarSound::Load(
const std::string & carpath,
const std::string & carname,
Sound & sound,
ContentManager & content,
std::ostream & error_output)
{
assert(!psound);
// check for sound specification file
std::string path_aud = carpath + "/" + carname + ".aud";
std::ifstream file_aud(path_aud.c_str());
if (file_aud.good())
{
PTree aud;
read_ini(file_aud, aud);
enginesounds.reserve(aud.size());
for (const auto & i : aud)
{
const PTree & audi = i.second;
std::string filename;
std::shared_ptr<SoundBuffer> soundptr;
if (!audi.get("filename", filename, error_output)) return false;
enginesounds.push_back(EngineSoundInfo());
EngineSoundInfo & info = enginesounds.back();
if (!audi.get("MinimumRPM", info.minrpm, error_output)) return false;
if (!audi.get("MaximumRPM", info.maxrpm, error_output)) return false;
if (!audi.get("NaturalRPM", info.naturalrpm, error_output)) return false;
bool powersetting;
if (!audi.get("power", powersetting, error_output)) return false;
if (powersetting)
info.power = EngineSoundInfo::POWERON;
else if (!powersetting)
info.power = EngineSoundInfo::POWEROFF;
else
info.power = EngineSoundInfo::BOTH;
info.sound_source = sound.AddSource(soundptr, 0, true, true);
sound.SetSourceGain(info.sound_source, 0);
}
// set blend start and end locations -- requires multiple passes
std::map <EngineSoundInfo *, EngineSoundInfo *> temporary_to_actual_map;
std::list <EngineSoundInfo> poweron_sounds, poweroff_sounds;
for (auto & info : enginesounds)
{
if (info.power == EngineSoundInfo::POWERON)
{
poweron_sounds.push_back(info);
temporary_to_actual_map[&poweron_sounds.back()] = &info;
}
else if (info.power == EngineSoundInfo::POWEROFF)
{
poweroff_sounds.push_back(info);
temporary_to_actual_map[&poweroff_sounds.back()] = &info;
}
}
poweron_sounds.sort();
poweroff_sounds.sort();
// we only support 2 overlapping sounds at once each for poweron and poweroff; this
// algorithm fails for other cases (undefined behavior)
std::list <EngineSoundInfo> * cursounds = &poweron_sounds;
for (int n = 0; n < 2; n++)
{
if (n == 1)
cursounds = &poweroff_sounds;
for (auto i = (*cursounds).begin(); i != (*cursounds).end(); ++i)
{
// set start blend
if (i == (*cursounds).begin())
i->fullgainrpmstart = i->minrpm;
// set end blend
auto inext = i;
inext++;
if (inext == (*cursounds).end())
i->fullgainrpmend = i->maxrpm;
else
{
i->fullgainrpmend = inext->minrpm;
inext->fullgainrpmstart = i->maxrpm;
}
}
// now assign back to the actual infos
for (auto & info : *cursounds)
{
assert(temporary_to_actual_map.find(&info) != temporary_to_actual_map.end());
*temporary_to_actual_map[&info] = info;
}
}
}
else
//.........这里部分代码省略.........
示例11: loadContent
void Scene::loadContent(ContentManager & contentManager)
{
/**Model * solidBox = new Model();
contentManager.loadModel().loadAssimpScene(std::string("content/box.obj"),*solidBox);
Entity box1 (glm::vec3(10.0,0.0,-50.0),glm::vec3(1.0,1.0,1.0),glm::vec4(0.0,0.0,0.0,0.0));
Entity box2 (glm::vec3(10.0,0.0,-40.0),glm::vec3(1.0,1.0,1.0),glm::vec4(0.0,0.0,0.0,0.0));
Entity box3 (glm::vec3(0.0,0.0,-40.0),glm::vec3(1.0,1.0,1.0),glm::vec4(0.0,0.0,0.0,0.0));
Entity box4 (glm::vec3(0.0,0.0,-50.0),glm::vec3(1.0,1.0,1.0),glm::vec4(0.0,0.0,0.0,0.0));
solidBox->addEntity(box1);
solidBox->addEntity(box2);
solidBox->addEntity(box3);
solidBox->addEntity(box4);
GLuint difTex = contentManager.loadTexture().loadRAWRGBTexture("content/fieldstone-c.raw",512,512);
GLuint normTex = contentManager.loadTexture().loadRAWRGBTexture("content/fieldstone-n.raw",512,512);
solidBox->setDiffuseTexID(difTex);
solidBox->setNormalTexID(normTex);
solidBox->setCurrentMaterial(Material::materialId("lambert5SG"));
Material mat = solidBox->getMaterial("lambert5SG");
mat.setOpacity(1.0);
mat.setDiffuseColor(glm::vec3(0.5,0.5,0.5));
mat.setSpecularColor(glm::vec3(0.5,0.5,0.5));
solidBox->updateMaterial(mat);
modelVector.push_back(solidBox);**/
Model * transparentBox = new Model();
contentManager.loadModel().loadAssimpScene(std::string("content/box.obj"),*transparentBox);
for(unsigned int i = 0; i < 20; i += 10)
{
for(unsigned int j = 0; j < 20; j += 10)
{
Entity box (glm::vec3(i,0.0,j),glm::vec3(1.0,1.0,1.0),glm::vec4(0.0,0.0,0.0,0.0));
transparentBox->addEntity(box);
}
}
/**Entity box5 (glm::vec3(10.0,0.0,-30.0),glm::vec3(1.0,1.0,1.0),glm::vec4(0.0,0.0,0.0,0.0));
Entity box6 (glm::vec3(10.0,0.0,-20.0),glm::vec3(1.0,1.0,1.0),glm::vec4(0.0,0.0,0.0,0.0));
Entity box7 (glm::vec3(0.0,0.0,-20.0),glm::vec3(1.0,1.0,1.0),glm::vec4(0.0,0.0,0.0,0.0));
Entity box8 (glm::vec3(0.0,0.0,-30.0),glm::vec3(1.0,1.0,1.0),glm::vec4(0.0,0.0,0.0,0.0));
transparentBox->addEntity(box5);
transparentBox->addEntity(box6);
transparentBox->addEntity(box7);
transparentBox->addEntity(box8);**/
GLuint difTexO = contentManager.loadTexture().loadRAWRGBTexture("content/fieldstone-c.raw",512,512);
GLuint normTexO = contentManager.loadTexture().loadRAWRGBTexture("content/fieldstone-n.raw",512,512);
transparentBox->setDiffuseTexID(difTexO);
transparentBox->setNormalTexID(normTexO);
transparentBox->setCurrentMaterial(Material::materialId("lambert5SG"));
Material matO = transparentBox->getMaterial("lambert5SG");
matO.setOpacity(0.5);
matO.setDiffuseColor(glm::vec3(0.5,0.5,0.5));
matO.setAmbientColor(glm::vec3(0.1,0.1,0.1));
matO.setSpecularColor(glm::vec3(0.5,0.5,0.5));
transparentBox->updateMaterial(matO);
modelVector.push_back(transparentBox);
// Lights
Light * pointLight1 = new Light(glm::vec3(-10,0,0),glm::vec3(1.0,1.0,1.0),30.0);
Light * pointLight2 = new Light(glm::vec3(-10,0,0),glm::vec3(1.0,1.0,1.0),15.0);
Light * pointLight3 = new Light(glm::vec3(0,0,-10),glm::vec3(1.0,1.0,1.0),15.0);
lightVector.push_back(pointLight1);
lightVector.push_back(pointLight2);
lightVector.push_back(pointLight3);
}
示例12: BuildMap
bool TrackMap::BuildMap(
const std::list <RoadStrip> & roads,
int w, int h,
const std::string & trackname,
const std::string & texturepath,
ContentManager & content,
std::ostream & error_output)
{
Unload();
const int outsizex = MAP_WIDTH;
const int outsizey = MAP_HEIGHT;
//find the map width and height
map_w_min = +1E6;
map_w_max = -1E6;
map_h_min = +1E6;
map_h_max = -1E6;
for (list <RoadStrip>::const_iterator road = roads.begin(); road != roads.end(); road++)
{
for (vector<RoadPatch>::const_iterator curp = road->GetPatches().begin();
curp != road->GetPatches().end(); curp++)
{
const Bezier & b = curp->GetPatch();
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
const Vec3 & p = b[i + j * 4];
if (p[1] < map_w_min)
{
map_w_min = p[1];
}
if (p[1] > map_w_max)
{
map_w_max = p[1];
}
if (p[0] < map_h_min)
{
map_h_min = p[0];
}
if (p[0] > map_h_max)
{
map_h_max = p[0];
}
}
}
}
}
mapsize[0] = map_w_max - map_w_min;
mapsize[1] = map_h_max - map_h_min;
//determine the scaling factor
//we will leave a 1 pixel border
float scale_w = (outsizex - 2) / mapsize[0];
float scale_h = (outsizey - 2) / mapsize[1];
scale = (scale_w < scale_h) ? scale_w : scale_h;
std::vector<unsigned> pixels(outsizex * outsizey, 0);
const int stride = outsizex * sizeof(unsigned);
const unsigned color = 0xffffffff;
for (list <RoadStrip>::const_iterator road = roads.begin(); road != roads.end(); road++)
{
for (vector<RoadPatch>::const_iterator curp = road->GetPatches().begin();
curp != road->GetPatches().end(); curp++)
{
const Bezier & b = curp->GetPatch();
const Vec3 & bl = b.GetBL();
const Vec3 & br = b.GetBR();
const Vec3 & fl = b.GetFL();
const Vec3 & fr = b.GetFR();
float x[6], y[6];
x[2] = (bl[1] - map_w_min) * scale + 1;
y[2] = (bl[0] - map_h_min) * scale + 1;
x[1] = (fl[1] - map_w_min) * scale + 1;
y[1] = (fl[0] - map_h_min) * scale + 1;
x[0] = (fr[1] - map_w_min) * scale + 1;
y[0] = (fr[0] - map_h_min) * scale + 1;
x[3] = x[2];
y[3] = y[2];
x[4] = (br[1] - map_w_min) * scale + 1;
y[4] = (br[0] - map_h_min) * scale + 1;
x[5] = x[0];
y[5] = y[0];
RasterizeTriangle(x, y, color, &pixels[0], stride);
RasterizeTriangle(x + 3, y + 3, color, &pixels[0], stride);
}
}
/*
// should operate on alpha only or on each channel?
// horizontal blur 3x3
for (int y = 1; y < outsizey - 1; ++y)
{
unsigned * line = &pixels[0] + y * outsizex;
unsigned p = line[0];
//.........这里部分代码省略.........
示例13: Load
bool GuiPage::Load(
const std::string & path,
const std::string & texpath,
const float hwratio,
const GuiLanguage & lang,
const Font & font,
const StrSignalMap & vsignalmap,
const StrVecSlotMap & vnactionmap,
const StrSlotMap & vactionmap,
IntSlotMap nactionmap,
SlotMap actionmap,
ContentManager & content,
std::ostream & error_output)
{
Clear();
Config pagefile;
if (!pagefile.load(path))
{
error_output << "Couldn't find GUI page file: " << path << std::endl;
return false;
}
if (!pagefile.get("", "name", name, error_output))
return false;
//error_output << "Loading " << path << std::endl;
// load widgets and controls
active_control = 0;
std::map<std::string, GuiWidget*> widgetmap; // labels, images, sliders
std::map<std::string, GuiWidgetList*> widgetlistmap; // labels, images lists
std::vector<Config::const_iterator> controlit; // control iterator cache
std::vector<Config::const_iterator> controlnit; // control list iterator cache
std::vector<GuiControlList*> controllists; // control list cache
for (Config::const_iterator section = pagefile.begin(); section != pagefile.end(); ++section)
{
if (section->first.empty()) continue;
Rect r = LoadRect(pagefile, section, hwratio);
float x0 = r.x - r.w * 0.5;
float y0 = r.y - r.h * 0.5;
float x1 = r.x + r.w * 0.5;
float y1 = r.y + r.h * 0.5;
GuiWidget * widget = 0;
// load widget(list)
std::string value;
if (pagefile.get(section, "text", value))
{
std::string alignstr;
float fontsize = 0.03;
pagefile.get(section, "fontsize", fontsize);
pagefile.get(section, "align", alignstr);
int align = 0;
if (alignstr == "right") align = 1;
else if (alignstr == "left") align = -1;
float scaley = fontsize;
float scalex = fontsize * hwratio;
GuiLabelList * widget_list = 0;
if (LoadList(pagefile, section, x0, y0, x1, y1, hwratio, widget_list))
{
// connect with the value list
StrVecSlotMap::const_iterator vni = vnactionmap.find(value);
if (vni != vnactionmap.end())
{
StrSignalMap::const_iterator vsi = vsignalmap.find(value + ".update");
if (vsi != vsignalmap.end())
{
widget_list->update_list.connect(*vsi->second);
vni->second->connect(widget_list->get_values);
}
}
// init drawable
widget_list->SetupDrawable(node, font, align, scalex, scaley, r.z);
widgetlistmap[section->first] = widget_list;
widget = widget_list;
}
else
{
// none is reserved for empty text string
if (value == "none")
value.clear();
else
value = lang(value);
GuiLabel * new_widget = new GuiLabel();
new_widget->SetupDrawable(
node, font, align, scalex, scaley,
r.x, r.y, r.w, r.h, r.z);
ConnectAction(value, vsignalmap, new_widget->set_value);
std::string name;
//.........这里部分代码省略.........
示例14: BuildMap
bool TRACKMAP::BuildMap(
const std::list <ROADSTRIP> & roads,
int w, int h,
const std::string & trackname,
const std::string & texturepath,
ContentManager & content,
std::ostream & error_output)
{
Unload();
int outsizex = MAP_WIDTH;
int outsizey = MAP_HEIGHT;
int bpp = 32;
// SDL interprets each pixel as a 32-bit number, so our masks must depend
// on the endianness (byte order) of the machine
Uint32 rmask, gmask, bmask, amask;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xff000000;
gmask = 0x00ff0000;
bmask = 0x0000ff00;
amask = 0x000000ff;
#else
rmask = 0x000000ff;
gmask = 0x0000ff00;
bmask = 0x00ff0000;
amask = 0xff000000;
#endif
SDL_Surface * surface = SDL_CreateRGBSurface(SDL_SWSURFACE, outsizex, outsizey, bpp, rmask, gmask, bmask, amask);
//find the map width and height
mapsize.Set(0,0);
map_w_min = FLT_MAX;
map_w_max = FLT_MIN;
map_h_min = FLT_MAX;
map_h_max = FLT_MIN;
for (list <ROADSTRIP>::const_iterator road = roads.begin(); road != roads.end(); road++)
{
for (vector<ROADPATCH>::const_iterator curp = road->GetPatches().begin();
curp != road->GetPatches().end(); curp++)
{
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
MATHVECTOR <float, 3> p = curp->GetPatch()[i+j*4];
if (p[0] < map_w_min)
{
map_w_min = p[0];
}
if (p[0] > map_w_max)
{
map_w_max = p[0];
}
if (p[2] < map_h_min)
{
map_h_min = p[2];
}
if (p[2] > map_h_max)
{
map_h_max = p[2];
}
}
}
}
}
mapsize[0] = map_w_max - map_w_min;
mapsize[1] = map_h_max - map_h_min;
//determine the scaling factor
//we will leave a 1 pixel border
float scale_w = (outsizex-2) / mapsize[0];
float scale_h = (outsizey-2) / mapsize[1];
scale = (scale_w < scale_h)?scale_w:scale_h;
boxRGBA(surface, 0, 0, outsizex-1, outsizey-1, 0, 0, 0, 0);
for (list <ROADSTRIP>::const_iterator road = roads.begin(); road != roads.end(); road++)
{
for (vector<ROADPATCH>::const_iterator curp = road->GetPatches().begin();
curp != road->GetPatches().end(); curp++)
{
Sint16 x[4], y[4];
const BEZIER & b(curp->GetPatch());
MATHVECTOR <float, 3> back_l = b.GetBL();
MATHVECTOR <float, 3> back_r = b.GetBR();
MATHVECTOR <float, 3> front_l = b.GetFL();
MATHVECTOR <float, 3> front_r = b.GetFR();
x[0] = int((back_l[0] - map_w_min) * scale) + 1;
y[0] = int((back_l[2] - map_h_min) * scale) + 1;
x[1] = int((front_l[0] - map_w_min) * scale) + 1;
y[1] = int((front_l[2] - map_h_min) * scale) + 1;
x[2] = int((front_r[0] - map_w_min) * scale) + 1;
y[2] = int((front_r[2] - map_h_min) * scale) + 1;
x[3] = int((back_r[0] - map_w_min) * scale) + 1;
//.........这里部分代码省略.........
示例15: if
//.........这里部分代码省略.........
pExportThread_->filenameout = exporttempfilename;
pExportThread_->framefilepos = pPlayerThread_->curframefilepos;
pExportThread_->Start();
ExportProgressRefTimer_->Start(500);
if (exporttotype == EXPORTTYPE_VIDEO) {
pExportThread_->SendUserEvent(pExportThread_->THREAD_EXPORTMJPEG, null);
} else if (exporttotype == EXPORTTYPE_FRAME) {
pExportThread_->SendUserEvent(pExportThread_->THREAD_EXPORTFRAME, null);
}
} else if (actionId == THREADCALLBACK_EXPORTPROGRESSUPDATE) {
if (pExportThread_ != null) {
double progress = ((double)pExportThread_->TimeLapseClass_->exportfileframecurno / (double)pExportThread_->TimeLapseClass_->exportfileframescount);
if (progress > 1) progress = 1;
if (progress < 1) {
ExportProgressRefTimer_->Start(500);
}
int progressint = (int)(progress * 100.0f);
if (progressint < 0) progressint = 0;
if (progressint > 100) progressint = 100;
Osp::Ui::Controls::Progress * savingpopupprogressel_ = static_cast<Progress *>(savingpopup_->GetControl(L"IDC_PROGRESS1"));
savingpopupprogressel_->SetValue(progressint);
savingpopupprogressel_->Draw();
savingpopupprogressel_->Show();
}
} else if (actionId == THREADCALLBACK_EXPORTDONE) {
ExportProgressRefTimer_->Cancel();
Osp::Ui::Controls::Progress * savingpopupprogressel_ = static_cast<Progress *>(savingpopup_->GetControl(L"IDC_PROGRESS1"));
savingpopupprogressel_->SetValue(100);
savingpopupprogressel_->Draw();
savingpopupprogressel_->Show();
pExportThread_->Stop();
pExportThread_->Join();
delete pExportThread_;
pExportThread_ = null;
ContentId contentId;
ContentManager contentManager;
contentManager.Construct();
if (Osp::Content::ContentManagerUtil::CopyToMediaDirectory(exporttempfilename, exportfilename) != E_SUCCESS) {
savingpopup_->SetShowState(false);
this->RequestRedraw();
MessageBox msgbox;
int modalResult = 0;
msgbox.Construct("Error", "Error saving file! Maybe out of disk space.", MSGBOX_STYLE_OK, 10000);
msgbox.ShowAndWait(modalResult);
return;
}
if (Osp::Io::File::IsFileExist(exporttempfilename)) {
Osp::Io::File::Remove(exporttempfilename);
}
if (exporttotype == EXPORTTYPE_VIDEO) {
VideoContentInfo videoContentInfo;
videoContentInfo.Construct(exportfilename);
contentId = contentManager.CreateContent(videoContentInfo);
videoContentInfo.SetAuthor(L"Timelapse");
videoContentInfo.SetDescription(L"Timelapse app");
videoContentInfo.SetKeyword(L"Timelapse");
contentManager.UpdateContent(videoContentInfo);
} else if (exporttotype == EXPORTTYPE_FRAME) {
ImageContentInfo imageContentInfo;
imageContentInfo.Construct(exportfilename);
contentId = contentManager.CreateContent(imageContentInfo);
imageContentInfo.SetAuthor(L"Timelapse");
imageContentInfo.SetDescription(L"Timelapse app");
imageContentInfo.SetKeyword(L"Timelapse");
contentManager.UpdateContent(imageContentInfo);
}
savingpopup_->SetShowState(false);
this->RequestRedraw();
MessageBox msgbox;
int modalResult = 0;
msgbox.Construct("Saved", L"File saved to:\n" + exportfilename, MSGBOX_STYLE_OK, 10000);
msgbox.ShowAndWait(modalResult);
} else if (actionId == ASPEEDCHANGE) {
if ((int)pPlayerThread_->fileinfo_.playframerate == 10) {
pPlayerThread_->SetFrameRate(15);
} else if ((int)pPlayerThread_->fileinfo_.playframerate == 15) {
pPlayerThread_->SetFrameRate(20);
} else if ((int)pPlayerThread_->fileinfo_.playframerate == 20) {
pPlayerThread_->SetFrameRate(25);
} else if ((int)pPlayerThread_->fileinfo_.playframerate == 25) {
pPlayerThread_->SetFrameRate(30);
} else {
pPlayerThread_->SetFrameRate(10);
}
delete speedbtnbmpn_;
delete speedbtnbmps_;
speedbtnbmpn_ = CreateSpeedBtnBmp(164, Osp::Base::Integer::ToString((int)pPlayerThread_->fileinfo_.playframerate) + L" fps", false);
speedbtnbmps_ = CreateSpeedBtnBmp(164, Osp::Base::Integer::ToString((int)pPlayerThread_->fileinfo_.playframerate) + L" fps", true);
speedbtn->SetNormalBackgroundBitmap(*speedbtnbmpn_);
speedbtn->SetPressedBackgroundBitmap(*speedbtnbmps_);
this->RequestRedraw();
}
}