Code won't compile

Started by
13 comments, last by oliii 19 years, 6 months ago
I get many erros when compileing the following code:

#include <stdio.h>
#include <iostream>
#include <SDL/SDL.h>
using namespace std;

#define mapWidth 24
#define mapHeight 24

int worldMap[mapWidth][mapHeight]=
{
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
    1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
    1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
    1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
    1,0,0,0,0,0,2,2,2,2,2,0,0,0,0,3,0,3,0,3,0,0,0,1,
    1,0,0,0,0,0,2,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,1,
    1,0,0,0,0,0,2,0,0,0,2,0,0,0,0,3,0,0,0,3,0,0,0,1,
    1,0,0,0,0,0,2,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,1,
    1,0,0,0,0,0,2,2,0,2,2,0,0,0,0,3,0,3,0,3,0,0,0,1,
    1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
    1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
    1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
    1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
    1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
    1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
    1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
    1,4,4,4,4,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
    1,4,0,4,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
    1,4,0,0,0,0,5,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
    1,4,0,4,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
    1,4,0,4,4,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
    1,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
    1,4,4,4,4,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
};

Scalar posX = 22, posY = 12;  //x and y start position
Scalar dirX = -1, dirY = 0; //initial direction vector
Scalar planeX = 0, planeY = 0.66; //the 2d raycaster version of camera plane

Scalar time = 0; //time of current frame
Scalar oldTime = 0; //time of previous frame

int main(int argc, char *argv[])
{
  screen(640, 480, 32, "Raycaster");

  while(!done())
    {
        SDL_Delay(5); //sacrifice 5 milliseconds per frame to free some CPU time
    }

    for(int x = 0; x < w; x++)
        {            
            //calculate ray position and direction
            Scalar cameraX = 2 * x / Scalar(w) - 1; //x-coordinate in camera space
            Scalar rayPosX = posX;
            Scalar rayPosY = posY;
            Scalar rayDirX = dirX + planeX * cameraX;
            Scalar rayDirY = dirY + planeY * cameraX;
         }

         //which box of the map we're in
            int mapX = int(rayPosX);
            int mapY = int(rayPosY);
            
            //length of ray from current position to next x or y-side
            Scalar sideDistX;
            Scalar sideDistY;
            
             //length of ray from one x or y-side to next x or y-side
            Scalar deltaDistX = sqrt(1 + (rayDirY * rayDirY) / (rayDirX * rayDirX));
            Scalar deltaDistY = sqrt(1 + (rayDirX * rayDirX) / (rayDirY * rayDirY));
            Scalar perpWallDist;
            
            //what direction to step in x or y-direction (either +1 or -1)
            int stepX;
            int stepY;
                       
            int hit = 0; //was there a wall hit?
            int side; //was a NS or a EW wall hit?

//calculate step and initial sideDist
            if (rayDirX < 0)
            {
                stepX = -1;
                sideDistX = (rayPosX - mapX) * deltaDistX;
            }
            else
            {
                stepX = 1;
                sideDistX = (mapX + 1.0 - rayPosX) * deltaDistX;
            }           
            if (rayDirY < 0)
            {
                stepY = -1;
                sideDistY = (rayPosY - mapY) * deltaDistY;
            }
            else
            {
                stepY = 1;
                sideDistY = (mapY + 1.0 - rayPosY) * deltaDistY;
            }

            //perform DDA
            while (hit == 0)
            {                   
                //jump to next map square, OR in x-direction, OR in y-direction
                if (sideDistX < sideDistY)
                {
                    sideDistX += deltaDistX;
                    mapX += stepX;
                    side = 0;
                }
                else
                {
                    sideDistY += deltaDistY;
                    mapY += stepY;
                    side = 1;
                }               
                //Check if ray has hit a wall
                if (worldMap[mapX][mapY] > 0) hit = 1;              
            } 

            //Calculate distance projected on camera direction (oblique distance will give fisheye effect!)
            if (side == 0)
            perpWallDist = fabs((mapX - rayPosX + (1 - stepX) / 2) / rayDirX);
            else
            perpWallDist = fabs((mapY - rayPosY + (1 - stepY) / 2) / rayDirY);

            //Calculate height of line to draw on screen
            int lineHeight = abs(int(h / perpWallDist));        
            
            //calculate lowest and highest pixel to fill in current stripe
            int drawStart = -lineHeight / 2 + h / 2;
            if(drawStart < 0)drawStart = 0;
            int drawEnd = lineHeight / 2 + h / 2;
            if(drawEnd >= h)drawEnd = h - 1;     

             //choose wall color
            ColorRGB color;
            switch(worldMap[mapX][mapY])
            {
                case 1:  color = RGB_Red;    break; //red
                case 2:  color = RGB_Green;  break; //green
                case 3:  color = RGB_Blue;   break; //blue
                case 4:  color = RGB_White;  break; //white
                default: color = RGB_Yellow; break; //yellow
            }
              
            //give x and y sides different brightness
            if (side == 1) {color = color / 2;}            
            
            //draw the pixels of the stripe as a vertical line
            verLine(x, drawStart, drawEnd, color);
        }

         //timing for input and FPS counter
        oldTime = time;
        time = getTime();
        Scalar frameTime = (time - oldTime) / 1000.0; //frameTime is the time this frame has taken, in seconds
        fprint(1.0 / frameTime); //FPS counter
        redraw();
        cls();

        //speed modifiers
        Scalar moveSpeed = frameTime * 5.0; //the constant value is in squares/second
        Scalar rotSpeed = frameTime * 3.0; //the constant value is in radians/second

        readKeys();
        //move forward if no wall in front of you
        if (inkeys[SDLK_UP])
        {
            if(worldMap[int(posX + dirX * moveSpeed)][int(posY)] == false) posX += dirX * moveSpeed;
            if(worldMap[int(posX)][int(posY + dirY * moveSpeed)] == false) posY += dirY * moveSpeed;
        }
        //move backwards if no wall behind you
        if (inkeys[SDLK_DOWN])
        {
            if(worldMap[int(posX - dirX * moveSpeed)][int(posY)] == false) posX -= dirX * moveSpeed;
            if(worldMap[int(posX)][int(posY - dirY * moveSpeed)] == false) posY -= dirY * moveSpeed;
        }    
        //rotate to the right
        if (inkeys[SDLK_RIGHT])
        {
            //both camera direction and camera plane must be rotated
            Scalar oldDirX = dirX;
            dirX = dirX * cos(-rotSpeed) - dirY * sin(-rotSpeed);
            dirY = oldDirX * sin(-rotSpeed) + dirY * cos(-rotSpeed);
            Scalar oldPlaneX = planeX;
            planeX = planeX * cos(-rotSpeed) - planeY * sin(-rotSpeed);
            planeY = oldPlaneX * sin(-rotSpeed) + planeY * cos(-rotSpeed);
        }
        //rotate to the left
        if (inkeys[SDLK_LEFT])
        {
            //both camera direction and camera plane must be rotated
            Scalar oldDirX = dirX;
            dirX = dirX * cos(rotSpeed) - dirY * sin(rotSpeed);
            dirY = oldDirX * sin(rotSpeed) + dirY * cos(rotSpeed);
            Scalar oldPlaneX = planeX;
            planeX = planeX * cos(rotSpeed) - planeY * sin(rotSpeed);
            planeY = oldPlaneX * sin(rotSpeed) + planeY * cos(rotSpeed);
        }        
    }       
}  


  return 0;
}



I get the following errors: 37 raycasterc.cpp syntax error before `=' 38 raycasterc.cpp syntax error before `=' 39 raycasterc.cpp syntax error before `=' 41 raycasterc.cpp syntax error before `=' 42 raycasterc.cpp syntax error before `=' 46 raycasterc.cpp implicit declaration of function `int screen(...)' 48 raycasterc.cpp implicit declaration of function `int done(...)' 53 raycasterc.cpp `w' undeclared (first use this function) 56 raycasterc.cpp `Scalar' undeclared (first use this function) 56 raycasterc.cpp parse error before `=' 64 raycasterc.cpp `rayPosX' undeclared (first use this function) 65 raycasterc.cpp `rayPosY' undeclared (first use this function) 68 raycasterc.cpp parse error before `;' 84 raycasterc.cpp `rayDirX' undeclared (first use this function) 87 raycasterc.cpp `sideDistX' undeclared (first use this function) 87 raycasterc.cpp `deltaDistX' undeclared (first use this function) 94 raycasterc.cpp `rayDirY' undeclared (first use this function) 94 raycasterc.cpp `rayDirY' undeclared (first use this function) 97 raycasterc.cpp `sideDistY' undeclared (first use this function) 97 raycasterc.cpp `deltaDistY' undeclared (first use this function) 127 raycasterc.cpp `perpWallDist' undeclared (first use this function) 132 raycasterc.cpp `h' undeclared (first use this function) 141 raycasterc.cpp `ColorRGB' undeclared (first use this function) 141 raycasterc.cpp parse error before `;' 144 raycasterc.cpp `color' undeclared (first use this function) 144 raycasterc.cpp `RGB_Red' undeclared (first use this function) 145 raycasterc.cpp `RGB_Green' undeclared (first use this function) 146 raycasterc.cpp `RGB_Blue' undeclared (first use this function) 147 raycasterc.cpp `RGB_White' undeclared (first use this function) 148 raycasterc.cpp `RGB_Yellow' undeclared (first use this function) I am trying to make a raycaster, and this is basically it. can someone tell me whats wrong? also, the raycaster tutorial im using from http://www.student.kuleuven.ac.be/~m0216922/CG/raycasting.html uses a codebase called quickCG, and when I download it to use it, there is no code present in the file at all. I have downloaded it several times, thinking that perhpas it downloaded wrong, but that isnt the problem. any help on this? and last, could someone possibly just send me a dev c++ project file with working code for this if I cant get it working? Hope someone can help! [Edited by - jakpandora on September 29, 2004 5:08:04 PM]
______________________________My website: Quest Networks
Advertisement
Hmm I'm not too sure if Scalar is defined in SDL, but I doubt it is. That's your problem, the compiler doesn't know where this Scalar type came from. You'll either have to make your own equivilant type, or get that library working.
--------------------------<modena> - Comfortably Nub
int worldMap[mapWidth][mapHeight]={    {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},    {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};


Rearrange your data like this, see if that works.


#define Scalar float

???
I believe the problem is that you dont have the quickCG files since that is where things like Scalar are defined. Not having that defined would give you the type of error you are getting on line 37. I tried downloading and unzipping the quickCG files and it worked fine for me.
"Pfft, Facts! Facts can be used to prove anything!" -- Homer J. Simpson
I thought that was my problem, too. I download the file, but for some reason, there is no code in the source files at all. could someone send this to me please? my email is above.
______________________________My website: Quest Networks
I still cant get it to work! whenever I try to download the codebase, none of the source files have any code in them. can someone please send me the codebase? it only takes a minute, and ill rate you up.(hopefully that will entice you)
______________________________My website: Quest Networks
I uploaded it to my webspace, and even downloaded it from there and checked the contents to make sure that the code was there. So if you download this and it doesnt contain any files then there is something wrong with your computer.

Download me baby!

I dont know how legit it is to host the code on my site so I will only keep it there a couple of days. Let me know if you have any problems.
"Pfft, Facts! Facts can be used to prove anything!" -- Homer J. Simpson
Thanks! ill rate you up! unfortunatly, there is still no code present in the c++ file, despite the fact that they are several kilobytes large.(its like the codes there, but I cant see it)every other file downloads perfectly, I dont know why this one doesnt. Sorry for causing you all the trouble. Could someone please post the code that goes in these files so I can put it in manally?
______________________________My website: Quest Networks
could somebody please post the code thats in these files please! it will only take a second! you can post them here, or E-mail them to me.

*EDIT* fixed the problem. for some reason, when I open up the *.dev file, no code shows up. however, when I open up each .cpp file individually, the code appears. weird. anyways, im sure ill make some other type of mistake along the way, so be ready for me :)

[Edited by - jakpandora on September 29, 2004 5:42:03 PM]
______________________________My website: Quest Networks

This topic is closed to new replies.

Advertisement