Thread: a question about matrices

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    10

    a question about matrices

    hey all, i'm new here. i've been working on an rpg for a while and i've come across a problem. first of all i have a matrix for every screen of the game. for example,
    {2, 1, 3}
    {2, 5, 4}
    {3, 2, 2}

    would mean there are 9 squares in the screen, each number represents a different terrain, that I draw a square of on the screen.
    Now the first level has 11 screens and I have a function called Newscreen that draws each screen as well as a function that sets the matrix screen[][] to the values needed for that particular screen. My problem is that because I can't change every value of the matrix at once, I can't send the matrix to the function that defines them, and then define them. For example, C++ doesn't allow you to do this:

    int array[3];
    array = {4, 5, 6};

    You must initialize the array when you declare it. My question to all of you, is there a way to, in a sense, re-initialize an array, or change all of the values of it without fifty pages of array[0] = 4; array[1] = 5; ...

    in order to make it more clear to you, this is what it looks like.
    Code:
    void Screen0(...)
    { ...
       Newscreen(0);
       ....
    }
    
    void Newscreen(int screennum)
    { Getscreen(screennum);
       ...
    }
    
    Getscreen(int screennum)
    { if (screennum == 0)
          int screen0[20][20] = {...};
       ...
    }
    I can't access the matrix in other functions without passing it as an argument, and I can't declare it beforehand, because I need to be able to initialize it in the Getscreen function.

    Anything you can tell me would be helpful. Thanks.

  2. #2
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Maybe a for loop? This would clear your screen:
    Code:
    for(y=0; y<height; y++)
        for(x=0; x<width; x++)
            array[x][y]=0;
    If you want the initailized data set to specific values then you could either read from another area of RAM, from a file, of generate them within your prog.

    If you only want to modify a certain few pixels you may be able to avoid clearing the screen and just draw on top of your image, but if a lot of work needs doing then that can get messy very fast.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 12:14 PM
  2. adding matrices, help with switches
    By quiet_forever in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2007, 08:21 AM
  3. Multiplying matrices
    By Star Lancer in forum C++ Programming
    Replies: 7
    Last Post: 05-22-2003, 06:07 AM
  4. Problem multiplying rotation matrices together
    By Silvercord in forum A Brief History of Cprogramming.com
    Replies: 20
    Last Post: 03-04-2003, 09:20 AM
  5. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM