Newswire
Features
Connection
Job Search
Directories

by Rob Wyatt
Gamasutra
August 11, 2000

Printer Friendly Version
   
Discuss this Article

Features

Hardware Accelerated Spherical Environment Mapping using Texture Matrices

Listing 1. Mapping

// Get the current world-view matrix
D3DMATRIX matWorld, matView, matWV;
m_pd3dDevice->GetTransform( D3DTRANSFORMSTATE_VIEW,   &matView );
m_pd3dDevice->GetTransform( D3DTRANSFORMSTATE_WORLD,   &matWorld );
D3DMath_MatrixMultiply( matWV, matWorld, matView );

// Extract world-view matrix elements for speed
FLOAT m11 = matWV._11, m21 = matWV._21, m31 = matWV._31;
FLOAT m12 = matWV._12, m22 = matWV._22, m32 = matWV._32;
FLOAT m13 = matWV._13, m23 = matWV._23, m33 = matWV._33;

// Loop through the vertices, transforming each one and   calculating
// the correct texture coordinates.
for( WORD i = 0; i < dwNumVertices; i++ )
{
    FLOAT nx = pvVertices[i].nx;
    FLOAT ny = pvVertices[i].ny;
    FLOAT nz = pvVertices[i].nz;

    // Check the z-component, to skip any vertices that     face backwards
    if( nx*m13 + ny*m23 + nz*m33 > 0.0f )
        continue;

    // Assign the spheremap's texture coordinates
    pvVertices[i].tu = 0.5f * ( 1.0f + ( nx*m11 + ny*m21       + nz*m31 ) );
    pvVertices[i].tv = 0.5f * ( 1.0f - ( nx*m12 + ny*m22       + nz*m32 ) );

}

________________________________________________________

Back to Article

Home   JoinHelpContact UsShop
 


Home | Join | Help | Contact Us | Shop | Newswire | Site Map
Write for Us | Features | Connection | Job Search | Directories


Copyright © 1999-2000 Miller Freeman Inc. All rights reserved.
Privacy Policy

Miller Freeman Game Group: GDC, GDMag, IGF Independent Games Festival Game Developer Magazine Game Developers Conference