Simulant  21.12-194
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
simplex.h
1 /* * Copyright (c) 2011-2017 Luke Benstead https://simulant-engine.appspot.com
2  *
3  * This file is part of Simulant.
4  *
5  * Simulant is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * Simulant is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with Simulant. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #pragma once
20 
21 #include <vector>
22 #include <ctime>
23 #include "../generic/managed.h"
24 
25 namespace smlt {
26 
27 class Simplex :
28  public RefCounted<Simplex> {
29 
30 public:
31  Simplex(int seed=time(NULL));
32  bool init();
33 
34  float noise(double x, double y);
35  float noise(double x, double y, double z);
36  float noise(double x, double y, double z, double w);
37 
38 private:
39  std::vector<int> p;
40 
41  const int simplex[64][4] = {
42  {0,1,2,3},{0,1,3,2},{0,0,0,0},{0,2,3,1},{0,0,0,0},{0,0,0,0},{0,0,0,0},{1,2,3,0},
43  {0,2,1,3},{0,0,0,0},{0,3,1,2},{0,3,2,1},{0,0,0,0},{0,0,0,0},{0,0,0,0},{1,3,2,0},
44  {0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},
45  {1,2,0,3},{0,0,0,0},{1,3,0,2},{0,0,0,0},{0,0,0,0},{0,0,0,0},{2,3,0,1},{2,3,1,0},
46  {1,0,2,3},{1,0,3,2},{0,0,0,0},{0,0,0,0},{0,0,0,0},{2,0,3,1},{0,0,0,0},{2,1,3,0},
47  {0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},
48  {2,0,1,3},{0,0,0,0},{0,0,0,0},{0,0,0,0},{3,0,1,2},{3,0,2,1},{0,0,0,0},{3,1,2,0},
49  {2,1,0,3},{0,0,0,0},{0,0,0,0},{0,0,0,0},{3,1,0,2},{0,0,0,0},{3,2,0,1},{3,2,1,0}
50  };
51 
52  int grad4[32][4]= {
53  {0,1,1,1}, {0,1,1,-1}, {0,1,-1,1}, {0,1,-1,-1},
54  {0,-1,1,1}, {0,-1,1,-1}, {0,-1,-1,1}, {0,-1,-1,-1},
55  {1,0,1,1}, {1,0,1,-1}, {1,0,-1,1}, {1,0,-1,-1},
56  {-1,0,1,1}, {-1,0,1,-1}, {-1,0,-1,1}, {-1,0,-1,-1},
57  {1,1,0,1}, {1,1,0,-1}, {1,-1,0,1}, {1,-1,0,-1},
58  {-1,1,0,1}, {-1,1,0,-1}, {-1,-1,0,1}, {-1,-1,0,-1},
59  {1,1,1,0}, {1,1,-1,0}, {1,-1,1,0}, {1,-1,-1,0},
60  {-1,1,1,0}, {-1,1,-1,0}, {-1,-1,1,0}, {-1,-1,-1,0}
61  };
62 
63  std::vector<int> perm;
64  int seed_;
65  bool initialized_ = false;
66 };
67 
68 }
69 
smlt::Simplex
Definition: simplex.h:28
smlt::RefCounted
Definition: managed.h:65
smlt
Definition: animation.cpp:25