Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Perlin.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2010, The Barbarian Group
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without modification, are permitted provided that
6  the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright notice, this list of conditions and
9  the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
11  the following disclaimer in the documentation and/or other materials provided with the distribution.
12 
13  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
14  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
15  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
16  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
17  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
18  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
19  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
20  POSSIBILITY OF SUCH DAMAGE.
21 */
22 
23 #pragma once
24 
25 #include "cinder/Cinder.h"
26 #include "cinder/Vector.h"
27 
28 namespace cinder {
29 
30 class Perlin
31 {
32  public:
33  Perlin( uint8_t aOctaves = 4 );
34  Perlin( uint8_t aOctaves, int32_t aSeed );
35 
36  void setSeed( int32_t aSeed );
37  uint8_t getOctaves() const { return mOctaves; }
38  void setOctaves( uint8_t aOctaves ) { mOctaves = aOctaves; }
39 
41  float fBm( float v ) const;
42  float fBm( const Vec2f &v ) const;
43  float fBm( float x, float y ) const { return fBm( Vec2f( x, y ) ); }
44  float fBm( const Vec3f &v ) const;
45  float fBm( float x, float y, float z ) const { return fBm( Vec3f( x, y, z ) ); }
46 
48 // float dfBm( float v ) const;
49  Vec2f dfBm( const Vec2f &v ) const;
50  Vec2f dfBm( float x, float y ) const { return dfBm( Vec2f( x, y ) ); }
51  Vec3f dfBm( const Vec3f &v ) const;
52  Vec3f dfBm( float x, float y, float z ) const { return dfBm( Vec3f( x, y, z ) ); }
53 
55  float noise( float x ) const;
56  float noise( float x, float y ) const;
57  float noise( float x, float y, float z ) const;
58 
60 // float dnoise( float x ) const;
61  Vec2f dnoise( float x, float y ) const;
62  Vec3f dnoise( float x, float y, float z ) const;
63 
64  private:
65  void initPermutationTable();
66 
67  float grad( int32_t hash, float x ) const;
68  float grad( int32_t hash, float x, float y ) const;
69  float grad( int32_t hash, float x, float y, float z ) const;
70 
71  uint8_t mOctaves;
72  int32_t mSeed;
73 
74  uint8_t mPerms[512];
75 };
76 
77 } // namespace cinder
uint8_t getOctaves() const
Definition: Perlin.h:37
GLenum GLint GLint y
Definition: GLee.h:987
Vec2< float > Vec2f
Definition: Vector.h:1314
Vec2f dfBm(const Vec2f &v) const
Derivative of fractal Brownian motion, corresponding with the values returned by fBm() ...
Definition: Perlin.cpp:125
void setOctaves(uint8_t aOctaves)
Definition: Perlin.h:38
float noise(float x) const
Calculates a single octave of noise.
Definition: Perlin.cpp:158
Vec3< float > Vec3f
Definition: Vector.h:1317
Vec2f dnoise(float x, float y) const
Calculates the derivative of a single octave of noise.
Definition: Perlin.cpp:223
float fBm(float v) const
Class Perlin look: fractal Brownian motion by summing 'mOctaves' worth of noise.
Definition: Perlin.cpp:64
float fBm(float x, float y, float z) const
Definition: Perlin.h:45
Definition: Perlin.h:30
GLenum GLint x
Definition: GLee.h:987
const GLdouble * v
Definition: GLee.h:1384
float fBm(float x, float y) const
Definition: Perlin.h:43
GLdouble GLdouble z
Definition: GLee.h:1911
Vec2f dfBm(float x, float y) const
Definition: Perlin.h:50
Vec3f dfBm(float x, float y, float z) const
Definition: Perlin.h:52
Perlin(uint8_t aOctaves=4)
Definition: Perlin.cpp:42
void setSeed(int32_t aSeed)
Definition: Perlin.cpp:56