|
-
Dec 2nd, 2004, 12:03 AM
#1
Thread Starter
PowerPoster
Sky Sphere Problem - 1 half inverted?[RESOLVED]
I alright I am using this code to generate a hemisphere with a radius of -100000.
negetive so the sphere is inverted as in I can see while inside of it.
I am rendering using TRIANGLESTRIPS.
I am rotating the matrix 90 degree around the x to set it above the player properly.
Now, the texture is messed. 1 half of the dome has the proper texture and the other half is inverted. It does not match up at all.
Can anyone point out why?
I understand this code, but I cannot see where the wrong textures coords are being places.
I think I have to negetive some tu, tv values somewhere.
PHP Code:
void SkyEngine::GenerateDome(float radius, float dtheta, float dphi, float hTile, float vTile)
{
int theta=0, phi=0;
// Initialize our Vertex array
m_NumVertices = (int)((360/dtheta)*(90/dphi)*4);
m_Vertices = new D3DVERTEX[m_NumVertices];
ZeroMemory(m_Vertices, sizeof(D3DVERTEX)*m_NumVertices);
// Used to calculate the UV coordinates
float vx=0, vy=0, vz=0, mag=0;
float x=0,y=0,z=0, tu=0, tv=0;
// Generate the dome
int n = 0;
for (phi=0; phi <= 90 - dphi; phi += (int)dphi)
{
for (theta=0; theta <= 360 - dtheta; theta += (int)dtheta)
{
//-----------------------
// Calculate the vertex at phi, theta
x = radius * sinf(phi*DTOR) * cosf(DTOR*theta);
y = radius * sinf(phi*DTOR) * sinf(DTOR*theta);
z = radius * cosf(phi*DTOR);
// Create a vector from the origin to this vertex
vx = x;
vy = y;
vz = z;
// Normalize the vector
mag = (float)sqrt(SQR(vx)+SQR(vy)+SQR(vz));
vx /= mag;
vy /= mag;
vz /= mag;
// Calculate the spherical texture coordinates
tu = hTile * (float)(atan2(vx, vz)/(PI*2)) + 0.5f;
tv = vTile * (float)(asinf(vy) / PI) + 0.5f;
// Add the D3DVERTEX
m_Vertices[n] = D3DVERTEX( D3DVECTOR(x, y, z), D3DVECTOR(0, 0, 0), tu, tv);
n++;
//-----------------------
//-----------------------
// Calculate the vertex at phi+dphi, theta
x = radius * sinf((phi+dphi)*DTOR) * cosf(theta*DTOR);
y = radius * sinf((phi+dphi)*DTOR) * sinf(theta*DTOR);
z = radius * cosf((phi+dphi)*DTOR);
// Calculate the texture coordinates
vx = x;
vy = y;
vz = z;
mag = (float)sqrt(SQR(vx)+SQR(vy)+SQR(vz));
vx /= mag;
vy /= mag;
vz /= mag;
tu = hTile * (float)(atan2(vx, vz)/(PI*2)) + 0.5f;
tv = vTile * (float)(asinf(vy) / PI) + 0.5f;
m_Vertices[n] = D3DVERTEX( D3DVECTOR(x, y, z), D3DVECTOR(0, 0, 0), tu, tv);
n++;
//-----------------------
//-----------------------
// Calculate the vertex at phi, theta+dtheta
x = radius * sinf(DTOR*phi) * cosf(DTOR*(theta+dtheta));
y = radius * sinf(DTOR*phi) * sinf(DTOR*(theta+dtheta));
z = radius * cosf(DTOR*phi);
// Calculate the texture coordinates
vx = x;
vy = y;
vz = z;
mag = (float)sqrt(SQR(vx)+SQR(vy)+SQR(vz));
vx /= mag;
vy /= mag;
vz /= mag;
tu = hTile * (float)(atan2(vx, vz)/(PI*2)) + 0.5f;
tv = vTile * (float)(asinf(vy) / PI) + 0.5f;
m_Vertices[n] = D3DVERTEX( D3DVECTOR(x, y, z), D3DVECTOR(0, 0, 0), tu, tv);
n++;
//-----------------------
if (phi > -90 && phi < 90)
{
//-----------------------
// Calculate the vertex at phi+dphi, theta+dtheta
x = radius * sinf((phi+dphi)*DTOR) * cosf(DTOR*(theta+dtheta));
y = radius * sinf((phi+dphi)*DTOR) * sinf(DTOR*(theta+dtheta));
z = radius * cosf((phi+dphi)*DTOR);
// Calculate the texture coordinates
vx = x;
vy = y;
vz = z;
mag = (float)sqrt(SQR(vx)+SQR(vy)+SQR(vz));
vx /= mag;
vy /= mag;
vz /= mag;
tu = hTile * (float)(atan2(vx, vz)/(PI*2)) + 0.5f;
tv = vTile * (float)(asinf(vy) / PI) + 0.5f;
m_Vertices[n] = D3DVERTEX( D3DVECTOR(x, y, z), D3DVECTOR(0, -1, 0), tu, tv);
n++;
}
}
}
// Fix the problem at the seam
for (int i=0; i < m_NumVertices-3; i++)
{
if (m_Vertices[i].tu - m_Vertices[i+1].tu > 0.9f)
m_Vertices[i+1].tu += 1.0f;
if (m_Vertices[i+1].tu - m_Vertices[i].tu > 0.9f)
m_Vertices[i].tu += 1.0f;
if (m_Vertices[i].tu - m_Vertices[i+2].tu > 0.9f)
m_Vertices[i+2].tu += 1.0f;
if (m_Vertices[i+2].tu - m_Vertices[i].tu > 0.9f)
m_Vertices[i].tu += 1.0f;
if (m_Vertices[i+1].tu - m_Vertices[i+2].tu > 0.9f)
m_Vertices[i+2].tu += 1.0f;
if (m_Vertices[i+2].tu - m_Vertices[i+1].tu > 0.9f)
m_Vertices[i+1].tu += 1.0f;
if (m_Vertices[i].tv - m_Vertices[i+1].tv > 0.8f)
m_Vertices[i+1].tv += 1.0f;
if (m_Vertices[i+1].tv - m_Vertices[i].tv > 0.8f)
m_Vertices[i].tv += 1.0f;
if (m_Vertices[i].tv - m_Vertices[i+2].tv > 0.8f)
m_Vertices[i+2].tv += 1.0f;
if (m_Vertices[i+2].tv - m_Vertices[i].tv > 0.8f)
m_Vertices[i].tv += 1.0f;
if (m_Vertices[i+1].tv - m_Vertices[i+2].tv > 0.8f)
m_Vertices[i+2].tv += 1.0f;
if (m_Vertices[i+2].tv - m_Vertices[i+1].tv > 0.8f)
m_Vertices[i+1].tv += 1.0f;
}
}
Last edited by Electroman; Dec 3rd, 2004 at 09:11 AM.
"From what was there, and was meant to be, but not of that was faded away." - - Steve Damm
"The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm
"When you do things right, people won't be sure if you did anything at all." - - God from Futurama
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|