Skip to content

Commit

Permalink
Gloom: Added a "meters per map unit" 3D scaling factor
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent 486c58b commit 90e4a80
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 15 deletions.
26 changes: 13 additions & 13 deletions doomsday/apps/gloom/gloom/render/mapbuild.cpp
Expand Up @@ -178,7 +178,7 @@ DENG2_PIMPL_NOREF(MapBuild)
{
const ID pointID = cv.key();

f.pos = cv.value();
f.pos = cv.value() * map.metersPerUnit();
f.texCoord = Vec4f(0, 0, 0, 0); // fixed offset
f.expander = expanders[pointID];

Expand Down Expand Up @@ -327,10 +327,10 @@ DENG2_PIMPL_NOREF(MapBuild)
expanders[end],
planeIndex,
MapVertex::WorldSpaceYToTexCoord,
floor[start],
floor[end],
ceiling[start],
ceiling[end],
floor[start] * map.metersPerUnit(),
floor[end] * map.metersPerUnit(),
ceiling[start] * map.metersPerUnit(),
ceiling[end] * map.metersPerUnit(),
length,
0);
}
Expand All @@ -352,10 +352,10 @@ DENG2_PIMPL_NOREF(MapBuild)
expanders[end],
botIndex,
MapVertex::WorldSpaceYToTexCoord | MapVertex::AnchorTopPlane,
floor[start],
floor[end],
backPlaneVerts.front()[start],
backPlaneVerts.front()[end],
floor[start] * map.metersPerUnit(),
floor[end] * map.metersPerUnit(),
backPlaneVerts.front()[start] * map.metersPerUnit(),
backPlaneVerts.front()[end] * map.metersPerUnit(),
length,
0);

Expand All @@ -366,10 +366,10 @@ DENG2_PIMPL_NOREF(MapBuild)
expanders[end],
topIndex,
MapVertex::WorldSpaceYToTexCoord,
backPlaneVerts.back()[start],
backPlaneVerts.back()[end],
ceiling[start],
ceiling[end],
backPlaneVerts.back()[start] * map.metersPerUnit(),
backPlaneVerts.back()[end] * map.metersPerUnit(),
ceiling[start] * map.metersPerUnit(),
ceiling[end] * map.metersPerUnit(),
length,
0);
}
Expand Down
6 changes: 4 additions & 2 deletions doomsday/apps/gloom/gloom/render/maprender.cpp
Expand Up @@ -214,12 +214,14 @@ void MapRender::advanceTime(TimeSpan elapsed)

// Update plane heights.
{
const Vec3d metersPerUnit = context().map->metersPerUnit();

for (auto i = d->planeMapper.begin(), end = d->planeMapper.end(); i != end; ++i)
{
const float planeY = float(context().map->plane(i.key()).point.y); // +
const double planeY = context().map->plane(i.key()).point.y; // +
//std::sin(i.value() + now * .1f);

d->planes.setData(i.value(), planeY);
d->planes.setData(i.value(), float(planeY * metersPerUnit.y));
}
}

Expand Down
27 changes: 27 additions & 0 deletions doomsday/apps/gloom/gloom/world/map.cpp
Expand Up @@ -32,6 +32,7 @@ namespace gloom {
DENG2_PIMPL(Map)
{
ID idGen{0};
Vec3d metersPerUnit{1.0, 1.0, 1.0};
Points points;
Lines lines;
Planes planes;
Expand All @@ -45,6 +46,7 @@ DENG2_PIMPL(Map)
Impl(Public *i, const Impl &other)
: Base(i)
, idGen(other.idGen)
, metersPerUnit(other.metersPerUnit)
, points(other.points)
, lines(other.lines)
, planes(other.planes)
Expand Down Expand Up @@ -177,6 +179,16 @@ gloom::ID Map::newID()
return ++d->idGen;
}

void Map::setMetersPerUnit(const Vec3d &metersPerUnit)
{
d->metersPerUnit = metersPerUnit;
}

Vec3d Map::metersPerUnit() const
{
return d->metersPerUnit;
}

Points &Map::points()
{
return d->points;
Expand Down Expand Up @@ -735,6 +747,12 @@ Block Map::serialize() const
const Impl *_d = d;
QJsonObject obj;

// Metadata.
{
obj.insert("metersPerUnit",
QJsonArray({_d->metersPerUnit.x, _d->metersPerUnit.y, _d->metersPerUnit.z}));
}

// Points.
{
QJsonObject points;
Expand Down Expand Up @@ -852,6 +870,15 @@ void Map::deserialize(const Block &data)
return id;
};

// Metadata.
{
if (map.contains("metersPerUnit"))
{
const auto mpu = map["metersPerUnit"].toList();
d->metersPerUnit = {mpu[0].toDouble(), mpu[1].toDouble(), mpu[2].toDouble()};
}
}

// Points.
{
const auto points = map["points"].toHash();
Expand Down
3 changes: 3 additions & 0 deletions doomsday/apps/gloom/gloom/world/map.h
Expand Up @@ -137,6 +137,9 @@ class Map
void removeInvalid();
ID newID();

void setMetersPerUnit(const Vec3d &metersPerUnit);
Vec3d metersPerUnit() const;

template <typename H, typename T>
ID append(H &hash, const T& value)
{
Expand Down
1 change: 1 addition & 0 deletions doomsday/apps/gloom/gloom/world/mapimport.cpp
Expand Up @@ -150,6 +150,7 @@ DENG2_PIMPL_NOREF(MapImport)
const double mapUnit = humanEyeHeight / (levelFormat == DoomFormat ? 41.0 : 48.0);

worldScale = {mapUnit, mapUnit * 1.2, mapUnit}; // VGA aspect ratio for vertical
map.setMetersPerUnit(worldScale);

const auto linedefData = lumps.read(headerPos + 2);

Expand Down
1 change: 1 addition & 0 deletions doomsday/apps/gloom/src/gloomapp.cpp
Expand Up @@ -111,6 +111,7 @@ void GloomApp::initialize()
{
const auto &asset = App::asset(d->editWin->editor().mapId());
loadedMap.deserialize(FS::locate<const File>(asset.absolutePath("path")));
//loadedMap.setMetersPerUnit(vectorFromValue<Vec3d>(asset.get("metersPerUnit"));
}

d->world->setMap(loadedMap);
Expand Down

0 comments on commit 90e4a80

Please sign in to comment.