raycasting and texture mapping

This is a discussion on raycasting and texture mapping within the Game Programming forums, part of the General Programming Boards category; Does anyone know of any good ways of (or tutorials on) texture mapping in a raycated environment. Recently I made ...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    46

    raycasting and texture mapping

    Does anyone know of any good ways of (or tutorials on) texture mapping in a raycated environment. Recently I made simple raycating engine in about 30 minutes and thought, wow, wolfenstein must have been easy, then I realized the walls in wolfenstein were texture mapped and mine were just vertical lines of different colors.

  2. #2
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    you can always download Wolfenstein's source code and see how John Carmack did it, although his methods are probably dated and slow. As soon as I can get a good handle of trigonometry I'm going to make a ray-caster. Just for the heck of it.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    I'll post it tomorrow if no one else answers. Its not hard to get the textures up but you have to do a few "tricks" to get them to be correctly aligned under certain circumstances. Also please note this is going to bring your frame rate way down.

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    46
    I doubt its that much slower, I mean, raycasting in general is very fast.
    mooooo@cooowwww.com

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    This code is sooo old. I just wanted to stress that first before anyone flamed me Anyways I think the variables are named so you will know what they represent. You should at least get an idea how to do it from this code. If you can't understand some of it I can help you. I just don't feel like explaining it out when I can just show you. I'm kind of out the door right now so , enjoy.

    Code:
        // Center wall
        yMin = (Height >> 1) - (WallHeight >> 1);
        yMax = yMin + WallHeight;
        vMod = MIN( 0, (Height >> 1) - (WallHeight >> 1) );
    
        // Clamp yMin and yMax
        if( yMin < 0 )
          yMin = 0;
        if( yMax >= pDest->GetHeight() )
          yMax = (pDest->GetHeight() - 1);
    
        // Get line pointer to desired index
        pLine = pDest->GetLinePtr( yMin );
        pLine += pDest->GetChannels() * ray;
    
        // Take care of texturing
        if( (bTextureEnable == true) && (bNotTextured == false) )
        {
          // Get a pointer to the bitmap for texture
          pTexture = GetMapTexture( pThis, CellValueX );
          
          if( (pTexture == NULL) || (!pTexture->isValidBitmap()) )
          {
            bNotTextured= true;
            break;
          }
    
          for( i = yMin; i < yMax; i++ )
          {
            // Find out index into textures
            fu = (XTextureOffset * pTexture->GetWidth());
            fv = (float)((i - yMin - vMod) * pTexture->GetHeight() / WallHeight);
            
            // Truncate to integers
            iu = ClampValue( (int)fu, 0, pTexture->GetWidth() - 1 );
            iv = ClampValue( (int)fv, 0, pTexture->GetHeight() - 1 );
    
            if( pTexture->GetChannels() == 1 )
              pTexture->GetPalette( *(pTexture->GetLinePtr(iv) + iu), 1, &rgbQuad );
            else
            {
              // Handle 24-bit case
              rgbQuad.rgbBlue = *(pTexture->GetLinePtr(iv) + (iu * pTexture->GetChannels()));
              rgbQuad.rgbGreen = *(pTexture->GetLinePtr(iv) + (iu * pTexture->GetChannels() + 1));
              rgbQuad.rgbRed = *(pTexture->GetLinePtr(iv) + (iu * pTexture->GetChannels() + 2));
            }
    
            // Write the pixel information to destination
            *pLine = rgbQuad.rgbBlue;
            *(pLine + 1) = rgbQuad.rgbGreen;
            *(pLine + 2) = rgbQuad.rgbRed;
            pLine += nStride;
          }
        }
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21