e05-03.cpp

来自「游戏开发数据结构Data Structures for Game Program」· C++ 代码 · 共 48 行

CPP
48
字号
// =======================================================
//  Chapter 5, Example 3
//  Demonstrating the Array3D Class
// =======================================================
#include "Array3D.h"



void main()
{
    // declare the arrays.
    Array3D<int> iarray( 2, 5, 3 );
    Array3D<float> farray( 3, 4, 5 );

    int i, x, y, z;
    float f;

    // set a few cells
    iarray.Get( 1, 4, 0) = 10;
    farray.Get( 3, 2, 3 ) = 0.5f;
    
    // retrieve the cells that we just set.
    i = iarray.Get( 1, 4, 0 );
    f = farray.Get( 3, 2, 3 );

    // get the size of each array.
    i = iarray.Size();
    i = farray.Size();

    // fill the integer array with consecutive numbers
    for( z = 0; z < 3; z++ )
    {
        for( y = 0; y < 5; y++ )
        {
            for( x = 0; x < 2; x++ )
            {
                iarray.Get( x, y, z ) = (z * 2 * 5) + (y * 2) + (x);
            }
        }
    }

    // resize the array to make it larger:
    iarray.Resize( 3, 6, 4 );

    // resize the array to make is smaller:
    iarray.Resize( 2, 2, 2 );

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?