Results 1 to 2 of 2

Thread: Sky Sphere Problem - 1 half inverted?[RESOLVED]

Threaded View

  1. #1

    Thread Starter
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339

    Resolved 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 radiusfloat dthetafloat dphifloat hTilefloat vTile)
    {
        
    int theta=0phi=0;

        
    // Initialize our Vertex array
        
    m_NumVertices = (int)((360/dtheta)*(90/dphi)*4);
        
    m_Vertices = new D3DVERTEX[m_NumVertices];
        
    ZeroMemory(m_Verticessizeof(D3DVERTEX)*m_NumVertices);

        
    // Used to calculate the UV coordinates
        
    float vx=0vy=0vz=0mag=0;
        
    float x=0,y=0,z=0tu=0tv=0;

        
    // Generate the dome
        
    int n 0;
        for (
    phi=0phi <= 90 dphiphi += (int)dphi)
        {
            for (
    theta=0theta <= 360 dthetatheta += (int)dtheta)
            {
                
    //-----------------------
                // Calculate the vertex at phi, theta
                
    radius sinf(phi*DTOR) * cosf(DTOR*theta);
                
    radius sinf(phi*DTOR) * sinf(DTOR*theta);
                
    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(vxvz)/(PI*2)) + 0.5f;
                
    tv vTile * (float)(asinf(vy) / PI) + 0.5f;    
                
                
    // Add the D3DVERTEX
                
    m_Vertices[n] = D3DVERTEXD3DVECTOR(xyz), D3DVECTOR(000), tutv);
                
    n++;
                
    //-----------------------

                //-----------------------
                // Calculate the vertex at phi+dphi, theta
                
    radius sinf((phi+dphi)*DTOR) * cosf(theta*DTOR);
                
    radius sinf((phi+dphi)*DTOR) * sinf(theta*DTOR);
                
    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(vxvz)/(PI*2)) + 0.5f;
                
    tv vTile * (float)(asinf(vy) / PI) + 0.5f;
                
    m_Vertices[n] = D3DVERTEXD3DVECTOR(xyz), D3DVECTOR(000), tutv);
                
    n++;
                
    //-----------------------

                //-----------------------
                // Calculate the vertex at phi, theta+dtheta
                
    radius sinf(DTOR*phi) * cosf(DTOR*(theta+dtheta));
                
    radius sinf(DTOR*phi) * sinf(DTOR*(theta+dtheta));
                
    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(vxvz)/(PI*2)) + 0.5f;
                
    tv vTile * (float)(asinf(vy) / PI) + 0.5f;    
                
    m_Vertices[n] = D3DVERTEXD3DVECTOR(xyz), D3DVECTOR(000), tutv);
                
    n++;
                
    //-----------------------

                
    if (phi > -90 && phi 90)
                {
                    
    //-----------------------
                    // Calculate the vertex at phi+dphi, theta+dtheta
                    
    radius sinf((phi+dphi)*DTOR) * cosf(DTOR*(theta+dtheta));
                    
    radius sinf((phi+dphi)*DTOR) * sinf(DTOR*(theta+dtheta));
                    
    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(vxvz)/(PI*2)) + 0.5f;
                    
    tv vTile * (float)(asinf(vy) / PI) + 0.5f;    
                    
    m_Vertices[n] = D3DVERTEXD3DVECTOR(xyz), D3DVECTOR(0, -10), tutv);
                    
    n++;
                }
            }
        }

        
    // Fix the problem at the seam
        
    for (int i=0m_NumVertices-3i++)
        {
            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
  •  



Click Here to Expand Forum to Full Width