1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-27 09:41:16 +00:00

small planet mapping

This commit is contained in:
Miloslav Číž 2017-11-08 12:58:27 +01:00
parent 5f36518181
commit 5698d70806

View File

@ -644,12 +644,12 @@ namespace MWRender
for (int j = 0; j < h; ++j) for (int j = 0; j < h; ++j)
for (int i = 0; i < w; ++i) for (int i = 0; i < w; ++i)
dest->setColor(getColorByDirection(sphericalCoords(i / ((float) w), j / ((float) h))),i,j); dest->setColor(getColorByDirection(smallPlanetCoords(i / ((float) w), j / ((float) h))),i,j);
} }
osg::Vec3d cylindricalCoords(double x, double y) osg::Vec3d cylindricalCoords(double x, double y)
{ {
osg::Vec3 result = osg::Vec3d(sin(x * 2 * osg::PI),cos(x * 2 * osg::PI),y * 2.0 - 1.0); osg::Vec3 result = osg::Vec3d(cos(x * 2 * osg::PI),sin(x * 2 * osg::PI),y * 2.0 - 1.0);
result.normalize(); result.normalize();
return result; return result;
} }
@ -665,6 +665,21 @@ namespace MWRender
return result; return result;
} }
osg::Vec3d smallPlanetCoords(double x, double y)
{
osg::Vec2d fromCenter = osg::Vec2d(x,y) - osg::Vec2d(0.5,0.5);
double magnitude = fromCenter.length();
fromCenter.normalize();
double dot = fromCenter * osg::Vec2d(0.0,1.0);
x = x > 0.5 ? 0.5 - (dot + 1) / 4.0 : 0.5 + (dot + 1) / 4.0;
y = pow(std::min(1.0,magnitude / 0.5),0.5);
return sphericalCoords(x,y);
}
osg::Vec4 getColorByDirection(osg::Vec3d d) osg::Vec4 getColorByDirection(osg::Vec3d d)
{ {
double x, y; double x, y;
@ -720,7 +735,7 @@ namespace MWRender
return mImages[side]->getColor( return mImages[side]->getColor(
std::min(std::max(int(x * mSize),0),mSize - 1), std::min(std::max(int(x * mSize),0),mSize - 1),
std::min(std::max(int(y * mSize),0),mSize - 1)); //osg::Vec4(d.x(),d.y(),d.z(),1); std::min(std::max(int(y * mSize),0),mSize - 1));
} }
protected: protected:
@ -762,7 +777,7 @@ namespace MWRender
if (mCamera->isFirstPerson()) if (mCamera->isFirstPerson())
mPlayerAnimation->getObjectRoot()->setNodeMask(1); mPlayerAnimation->getObjectRoot()->setNodeMask(1);
s.create(image,1600,768); s.create(image,1600,1600);
mFieldOfView = fovBackup; mFieldOfView = fovBackup;
} }