dudeabot

24-03-2009 00:18:26

i dunno if its posisble, but im trying to map the terrain to a sphere, using this equations:

i have modified createVertexData to this(tile.cpp from 2.31 ETM):

it would map just one of the 6 cube faces, but i just see a rather strange cone.

i am missing something?

` `

Vector3 Tile::mapCubeToUnitSphere(const Vector3 &cubeCoord)

{

Real x = cubeCoord.x;

Real y = cubeCoord.y;

Real z = cubeCoord.z;

assert(x >= -1 && x <= 1 && y >= -1 && y <= 1 && z >= -1 && z <= 1);

Vector3 sphereCoord;

const Real div3 = 1.0f / 3.0f;

sphereCoord.x = x * Math::Sqrt(1.0f - y * y * 0.5f - z * z * 0.5f + y * y * z * z * div3);

sphereCoord.y = y * Math::Sqrt(1.0f - z * z * 0.5f - x * x * 0.5f + z * z * x * x * div3);

sphereCoord.z = z * Math::Sqrt(1.0f - x * x * 0.5f - y * y * 0.5f + x * x * y * y * div3);

return sphereCoord;

}

i have modified createVertexData to this(tile.cpp from 2.31 ETM):

for (size_t j = startz; j < endz; ++j)

{

for (size_t i = startx; i < endx; ++i)

{

float* pPos, * pTex0;//, * pTex1;

posElem->baseVertexPointerToElement(pBase, &pPos);

texElem0->baseVertexPointerToElement(pBase, &pTex0);

Real height = mInfo.getOffset().y + mInfo.at(i, j) * mInfo.getScaling().y;

Vector3 face1Normalised(i,mInfo.at(i, j),j);

face1Normalised.normalise();

Vector3 finalVector=mapCubeToUnitSphere(face1Normalised);

*pPos++ = mInfo.getOffset().x + mInfo.getScaling().x * finalVector.x;

*pPos++ = mInfo.getOffset().y + mInfo.getScaling().y * finalVector.y;

*pPos++ = mInfo.getOffset().z + mInfo.getScaling().z * finalVector.z;

*pTex0++ = float(i) / (mInfo.getWidth() - 1);

*pTex0++ = float(j) / (mInfo.getHeight() - 1);

if (height < minHeight)

minHeight = height;

if (height > maxHeight)

maxHeight = height;

pBase += mMainBuffer->getVertexSize();

}

}

it would map just one of the 6 cube faces, but i just see a rather strange cone.

i am missing something?