c++visual-studioperlin-noise

What does it mean to 'instantiate' a class?


I have found this code regarding 3D perlin noise: https://blog.kazade.co.uk/2014/05/a-public-domain-c11-1d2d3d-perlin-noise.html

I created a noise.h file from the first chunk of code. Then I added the second chunk to my C++ project, included the noise.h header file, and added it to my project via the solution explorer.

Everything is fine and I have no errors with the inserted code. The problem is that I don't really understand how to use it. He simply states:

It's pretty straightforward to use, just instantiate a Perlin, or PerlinOctave instance, and call noise(x, y, z); Simples.

I am not overly experienced with C++ so I don't know what he means by instantiating. But my attempts were:

float n = noise(x,y,z); (Where x,y,z are my float variables).

I also tried:

float n = PerlinOctave::noise(x,y,z); (Where x,y,z are my float variables).

Visual Studio reports an error saying: "A namespace name is not allowed"

He also doesn't give any instructions on how to use the octave function, which is separate from the noise function.

Does anyone have a better understanding of how to use this code?


Solution

  • Instantiation means creating an object. The author means you create a Perlin object as follows:

    uint32_t seed = 42;
    noise::Perlin perlin(seed);
    

    And then you can call the noise methods:

    for (double x = 0.0; x < 1.0; x += 0.1)
    {
        std::cout << perlin.noise(x) << "\n";
    }
    

    Similarly for the PerlinOctave class.

    It might pay to take a step back and learn the basics of C++ if you're going to continue with the language. Otherwise, you should prepare for a whole world of pain.