mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 02:42:49 -04:00
stackedPerlinNoise
This commit is contained in:
parent
f3ca7417b0
commit
c207be10b9
@ -30,8 +30,10 @@
|
|||||||
perlinNoise2.h perlinNoise2.I \
|
perlinNoise2.h perlinNoise2.I \
|
||||||
perlinNoise3.h perlinNoise3.I \
|
perlinNoise3.h perlinNoise3.I \
|
||||||
plane.h plane_src.I plane_src.cxx \
|
plane.h plane_src.I plane_src.cxx \
|
||||||
plane_src.h rotate_to.h rotate_to_src.cxx
|
plane_src.h rotate_to.h rotate_to_src.cxx \
|
||||||
|
stackedPerlinNoise2.h stackedPerlinNoise2.I \
|
||||||
|
stackedPerlinNoise3.h stackedPerlinNoise3.I
|
||||||
|
|
||||||
#define INCLUDED_SOURCES \
|
#define INCLUDED_SOURCES \
|
||||||
boundingHexahedron.cxx boundingLine.cxx \
|
boundingHexahedron.cxx boundingLine.cxx \
|
||||||
boundingPlane.cxx \
|
boundingPlane.cxx \
|
||||||
@ -45,6 +47,8 @@
|
|||||||
perlinNoise.cxx \
|
perlinNoise.cxx \
|
||||||
perlinNoise2.cxx \
|
perlinNoise2.cxx \
|
||||||
perlinNoise3.cxx \
|
perlinNoise3.cxx \
|
||||||
|
stackedPerlinNoise2.cxx \
|
||||||
|
stackedPerlinNoise3.cxx \
|
||||||
plane.cxx rotate_to.cxx
|
plane.cxx rotate_to.cxx
|
||||||
|
|
||||||
#define INSTALL_HEADERS \
|
#define INSTALL_HEADERS \
|
||||||
@ -62,8 +66,11 @@
|
|||||||
perlinNoise.h perlinNoise.I \
|
perlinNoise.h perlinNoise.I \
|
||||||
perlinNoise2.h perlinNoise2.I \
|
perlinNoise2.h perlinNoise2.I \
|
||||||
perlinNoise3.h perlinNoise3.I \
|
perlinNoise3.h perlinNoise3.I \
|
||||||
plane.h plane_src.I \
|
plane.h plane_src.I plane_src.cxx \
|
||||||
plane_src.h rotate_to.h
|
plane_src.h rotate_to.h rotate_to_src.cxx \
|
||||||
|
stackedPerlinNoise2.h stackedPerlinNoise2.I \
|
||||||
|
stackedPerlinNoise3.h stackedPerlinNoise3.I
|
||||||
|
|
||||||
|
|
||||||
#define IGATESCAN all
|
#define IGATESCAN all
|
||||||
|
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
|
|
||||||
#include "boundingVolume.cxx"
|
|
||||||
#include "boundingHexahedron.cxx"
|
#include "boundingHexahedron.cxx"
|
||||||
#include "boundingLine.cxx"
|
#include "boundingLine.cxx"
|
||||||
#include "boundingPlane.cxx"
|
#include "boundingPlane.cxx"
|
||||||
#include "boundingSphere.cxx"
|
#include "boundingSphere.cxx"
|
||||||
|
#include "boundingVolume.cxx"
|
||||||
#include "finiteBoundingVolume.cxx"
|
#include "finiteBoundingVolume.cxx"
|
||||||
#include "geometricBoundingVolume.cxx"
|
#include "geometricBoundingVolume.cxx"
|
||||||
#include "omniBoundingVolume.cxx"
|
#include "omniBoundingVolume.cxx"
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
|
|
||||||
#include "config_mathutil.cxx"
|
#include "config_mathutil.cxx"
|
||||||
|
#include "fftCompressor.cxx"
|
||||||
|
#include "linmath_events.cxx"
|
||||||
|
#include "look_at.cxx"
|
||||||
|
#include "mersenne.cxx"
|
||||||
#include "perlinNoise.cxx"
|
#include "perlinNoise.cxx"
|
||||||
#include "perlinNoise2.cxx"
|
#include "perlinNoise2.cxx"
|
||||||
#include "perlinNoise3.cxx"
|
#include "perlinNoise3.cxx"
|
||||||
#include "plane.cxx"
|
#include "plane.cxx"
|
||||||
#include "rotate_to.cxx"
|
#include "rotate_to.cxx"
|
||||||
#include "look_at.cxx"
|
#include "stackedPerlinNoise2.cxx"
|
||||||
#include "linmath_events.cxx"
|
#include "stackedPerlinNoise3.cxx"
|
||||||
#include "mersenne.cxx"
|
|
||||||
#include "fftCompressor.cxx"
|
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ random_int(int range) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE double PerlinNoise::
|
INLINE double PerlinNoise::
|
||||||
random_real(double range) {
|
random_real(double range) {
|
||||||
return (range * _mersenne.get_uint31()) / ((double)0xffffffff + 1.0f);
|
return (range * _mersenne.get_uint31()) / ((double)0x80000000);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -71,7 +71,7 @@ random_real_unit() {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: PerlinNoise::get_next_seed
|
// Function: PerlinNoise::get_next_seed
|
||||||
// Access: Protected, Static
|
// Access: Protected, Static
|
||||||
// Description: Returns a random seed value for the next-in-sequence
|
// Description: Returns a random seed value for the next global
|
||||||
// PerlinNoise object.
|
// PerlinNoise object.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE unsigned long PerlinNoise::
|
INLINE unsigned long PerlinNoise::
|
||||||
@ -83,3 +83,14 @@ get_next_seed() {
|
|||||||
return _next_seed.get_uint31();
|
return _next_seed.get_uint31();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: PerlinNoise::get_seed
|
||||||
|
// Access: Published
|
||||||
|
// Description: Returns a unique seed value based on the seed value
|
||||||
|
// passed to this PerlinNoise object (and on its current
|
||||||
|
// state).
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
INLINE unsigned long PerlinNoise::
|
||||||
|
get_seed() {
|
||||||
|
return _mersenne.get_uint31();
|
||||||
|
}
|
||||||
|
@ -44,6 +44,9 @@ protected:
|
|||||||
|
|
||||||
INLINE static unsigned long get_next_seed();
|
INLINE static unsigned long get_next_seed();
|
||||||
|
|
||||||
|
PUBLISHED:
|
||||||
|
INLINE unsigned long get_seed();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int _table_size;
|
int _table_size;
|
||||||
|
|
||||||
|
38
panda/src/mathutil/stackedPerlinNoise2.I
Normal file
38
panda/src/mathutil/stackedPerlinNoise2.I
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
// Filename: stackedPerlinNoise2.I
|
||||||
|
// Created by: drose (05Oct05)
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// PANDA 3D SOFTWARE
|
||||||
|
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
|
||||||
|
//
|
||||||
|
// All use of this software is subject to the terms of the Panda 3d
|
||||||
|
// Software license. You should have received a copy of this license
|
||||||
|
// along with this source code; you will also find a current copy of
|
||||||
|
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
||||||
|
//
|
||||||
|
// To contact the maintainers of this program write to
|
||||||
|
// panda3d-general@lists.sourceforge.net .
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: StackedPerlinNoise2::noise
|
||||||
|
// Access: Published
|
||||||
|
// Description: Returns the noise function of the three inputs.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
INLINE double StackedPerlinNoise2::
|
||||||
|
noise(double x, double y) {
|
||||||
|
return noise(LVecBase2d(x, y));
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: StackedPerlinNoise2::noise
|
||||||
|
// Access: Published
|
||||||
|
// Description: Returns the noise function of the three inputs.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
INLINE float StackedPerlinNoise2::
|
||||||
|
noise(const LVecBase2f &value) {
|
||||||
|
return (float)noise(value[0], value[1]);
|
||||||
|
}
|
64
panda/src/mathutil/stackedPerlinNoise2.cxx
Normal file
64
panda/src/mathutil/stackedPerlinNoise2.cxx
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
// Filename: stackedPerlinNoise2.cxx
|
||||||
|
// Created by: drose (05Oct05)
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// PANDA 3D SOFTWARE
|
||||||
|
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
|
||||||
|
//
|
||||||
|
// All use of this software is subject to the terms of the Panda 3d
|
||||||
|
// Software license. You should have received a copy of this license
|
||||||
|
// along with this source code; you will also find a current copy of
|
||||||
|
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
||||||
|
//
|
||||||
|
// To contact the maintainers of this program write to
|
||||||
|
// panda3d-general@lists.sourceforge.net .
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "stackedPerlinNoise2.h"
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: StackedPerlinNoise2::Constructor
|
||||||
|
// Access: Published
|
||||||
|
// Description: Creates num_levels nested PerlinNoise2 objects. Each
|
||||||
|
// stacked Perlin object will have a scale of 1 /
|
||||||
|
// scale_factor times the previous object (so that it is
|
||||||
|
// higher-frequency, if scale_factor > 1), and an
|
||||||
|
// amplitude of amp_scale times the previous object (so
|
||||||
|
// that it is less important, if amp_scale < 1).
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
StackedPerlinNoise2::
|
||||||
|
StackedPerlinNoise2(double sx, double sy, int num_levels,
|
||||||
|
double scale_factor, double amp_scale,
|
||||||
|
int table_size, unsigned long seed) :
|
||||||
|
_amp_scale(amp_scale)
|
||||||
|
{
|
||||||
|
_noises.reserve(num_levels);
|
||||||
|
for (int i = 0; i < num_levels; ++i) {
|
||||||
|
PerlinNoise2 noise(sx, sy, table_size, seed);
|
||||||
|
_noises.push_back(noise);
|
||||||
|
seed = noise.get_seed();
|
||||||
|
sx /= scale_factor;
|
||||||
|
sy /= scale_factor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: StackedPerlinNoise2::noise
|
||||||
|
// Access: Published
|
||||||
|
// Description: Returns the noise function of the three inputs.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
double StackedPerlinNoise2::
|
||||||
|
noise(const LVecBase2d &value) {
|
||||||
|
double result = 0.0f;
|
||||||
|
double amp = 1.0f;
|
||||||
|
|
||||||
|
Noises::iterator ni;
|
||||||
|
for (ni = _noises.begin(); ni != _noises.end(); ++ni) {
|
||||||
|
result += (*ni).noise(value) * amp;
|
||||||
|
amp *= _amp_scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
52
panda/src/mathutil/stackedPerlinNoise2.h
Normal file
52
panda/src/mathutil/stackedPerlinNoise2.h
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
// Filename: stackedPerlinNoise2.h
|
||||||
|
// Created by: drose (05Oct05)
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// PANDA 3D SOFTWARE
|
||||||
|
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
|
||||||
|
//
|
||||||
|
// All use of this software is subject to the terms of the Panda 3d
|
||||||
|
// Software license. You should have received a copy of this license
|
||||||
|
// along with this source code; you will also find a current copy of
|
||||||
|
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
||||||
|
//
|
||||||
|
// To contact the maintainers of this program write to
|
||||||
|
// panda3d-general@lists.sourceforge.net .
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef STACKEDPERLINNOISE2_H
|
||||||
|
#define STACKEDPERLINNOISE2_H
|
||||||
|
|
||||||
|
#include "pandabase.h"
|
||||||
|
#include "perlinNoise2.h"
|
||||||
|
#include "pvector.h"
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Class : StackedPerlinNoise2
|
||||||
|
// Description : Implements a multi-layer PerlinNoise, with one or
|
||||||
|
// more high-frequency noise functions added to a
|
||||||
|
// lower-frequency base noise function.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
class EXPCL_PANDA StackedPerlinNoise2 {
|
||||||
|
PUBLISHED:
|
||||||
|
StackedPerlinNoise2(double sx, double sy, int num_levels = 3,
|
||||||
|
double scale_factor = 4.0f, double amp_scale = 0.5f,
|
||||||
|
int table_size = 256, unsigned long seed = 0);
|
||||||
|
|
||||||
|
INLINE double noise(double x, double y);
|
||||||
|
INLINE float noise(const LVecBase2f &value);
|
||||||
|
double noise(const LVecBase2d &value);
|
||||||
|
|
||||||
|
private:
|
||||||
|
double _amp_scale;
|
||||||
|
|
||||||
|
typedef pvector<PerlinNoise2> Noises;
|
||||||
|
Noises _noises;
|
||||||
|
};
|
||||||
|
|
||||||
|
#include "stackedPerlinNoise2.I"
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
38
panda/src/mathutil/stackedPerlinNoise3.I
Normal file
38
panda/src/mathutil/stackedPerlinNoise3.I
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
// Filename: stackedPerlinNoise3.I
|
||||||
|
// Created by: drose (05Oct05)
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// PANDA 3D SOFTWARE
|
||||||
|
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
|
||||||
|
//
|
||||||
|
// All use of this software is subject to the terms of the Panda 3d
|
||||||
|
// Software license. You should have received a copy of this license
|
||||||
|
// along with this source code; you will also find a current copy of
|
||||||
|
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
||||||
|
//
|
||||||
|
// To contact the maintainers of this program write to
|
||||||
|
// panda3d-general@lists.sourceforge.net .
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: StackedPerlinNoise3::noise
|
||||||
|
// Access: Published
|
||||||
|
// Description: Returns the noise function of the three inputs.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
INLINE double StackedPerlinNoise3::
|
||||||
|
noise(double x, double y, double z) {
|
||||||
|
return noise(LVecBase3d(x, y, z));
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: StackedPerlinNoise3::noise
|
||||||
|
// Access: Published
|
||||||
|
// Description: Returns the noise function of the three inputs.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
INLINE float StackedPerlinNoise3::
|
||||||
|
noise(const LVecBase3f &value) {
|
||||||
|
return (float)noise(value[0], value[1], value[2]);
|
||||||
|
}
|
65
panda/src/mathutil/stackedPerlinNoise3.cxx
Normal file
65
panda/src/mathutil/stackedPerlinNoise3.cxx
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
// Filename: stackedPerlinNoise3.cxx
|
||||||
|
// Created by: drose (05Oct05)
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// PANDA 3D SOFTWARE
|
||||||
|
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
|
||||||
|
//
|
||||||
|
// All use of this software is subject to the terms of the Panda 3d
|
||||||
|
// Software license. You should have received a copy of this license
|
||||||
|
// along with this source code; you will also find a current copy of
|
||||||
|
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
||||||
|
//
|
||||||
|
// To contact the maintainers of this program write to
|
||||||
|
// panda3d-general@lists.sourceforge.net .
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "stackedPerlinNoise3.h"
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: StackedPerlinNoise3::Constructor
|
||||||
|
// Access: Published
|
||||||
|
// Description: Creates num_levels nested PerlinNoise3 objects. Each
|
||||||
|
// stacked Perlin object will have a scale of 1 /
|
||||||
|
// scale_factor times the previous object (so that it is
|
||||||
|
// higher-frequency, if scale_factor > 1), and an
|
||||||
|
// amplitude of amp_scale times the previous object (so
|
||||||
|
// that it is less important, if amp_scale < 1).
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
StackedPerlinNoise3::
|
||||||
|
StackedPerlinNoise3(double sx, double sy, double sz, int num_levels,
|
||||||
|
double scale_factor, double amp_scale,
|
||||||
|
int table_size, unsigned long seed) :
|
||||||
|
_amp_scale(amp_scale)
|
||||||
|
{
|
||||||
|
_noises.reserve(num_levels);
|
||||||
|
for (int i = 0; i < num_levels; ++i) {
|
||||||
|
PerlinNoise3 noise(sx, sy, sz, table_size, seed);
|
||||||
|
_noises.push_back(noise);
|
||||||
|
seed = noise.get_seed();
|
||||||
|
sx /= scale_factor;
|
||||||
|
sy /= scale_factor;
|
||||||
|
sz /= scale_factor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: StackedPerlinNoise3::noise
|
||||||
|
// Access: Published
|
||||||
|
// Description: Returns the noise function of the three inputs.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
double StackedPerlinNoise3::
|
||||||
|
noise(const LVecBase3d &value) {
|
||||||
|
double result = 0.0f;
|
||||||
|
double amp = 1.0f;
|
||||||
|
|
||||||
|
Noises::iterator ni;
|
||||||
|
for (ni = _noises.begin(); ni != _noises.end(); ++ni) {
|
||||||
|
result += (*ni).noise(value) * amp;
|
||||||
|
amp *= _amp_scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
52
panda/src/mathutil/stackedPerlinNoise3.h
Normal file
52
panda/src/mathutil/stackedPerlinNoise3.h
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
// Filename: stackedPerlinNoise3.h
|
||||||
|
// Created by: drose (05Oct05)
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// PANDA 3D SOFTWARE
|
||||||
|
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
|
||||||
|
//
|
||||||
|
// All use of this software is subject to the terms of the Panda 3d
|
||||||
|
// Software license. You should have received a copy of this license
|
||||||
|
// along with this source code; you will also find a current copy of
|
||||||
|
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
||||||
|
//
|
||||||
|
// To contact the maintainers of this program write to
|
||||||
|
// panda3d-general@lists.sourceforge.net .
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef STACKEDPERLINNOISE3_H
|
||||||
|
#define STACKEDPERLINNOISE3_H
|
||||||
|
|
||||||
|
#include "pandabase.h"
|
||||||
|
#include "perlinNoise3.h"
|
||||||
|
#include "pvector.h"
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Class : StackedPerlinNoise3
|
||||||
|
// Description : Implements a multi-layer PerlinNoise, with one or
|
||||||
|
// more high-frequency noise functions added to a
|
||||||
|
// lower-frequency base noise function.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
class EXPCL_PANDA StackedPerlinNoise3 {
|
||||||
|
PUBLISHED:
|
||||||
|
StackedPerlinNoise3(double sx, double sy, double sz, int num_levels = 3,
|
||||||
|
double scale_factor = 4.0f, double amp_scale = 0.5f,
|
||||||
|
int table_size = 256, unsigned long seed = 0);
|
||||||
|
|
||||||
|
INLINE double noise(double x, double y, double z);
|
||||||
|
INLINE float noise(const LVecBase3f &value);
|
||||||
|
double noise(const LVecBase3d &value);
|
||||||
|
|
||||||
|
private:
|
||||||
|
double _amp_scale;
|
||||||
|
|
||||||
|
typedef pvector<PerlinNoise3> Noises;
|
||||||
|
Noises _noises;
|
||||||
|
};
|
||||||
|
|
||||||
|
#include "stackedPerlinNoise3.I"
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user