Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Limit the max derivate of 1D Perlin Noise


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 Makers_F   Members   -  Reputation: 815

Like
0Likes
Like

Posted 15 April 2012 - 07:15 AM

I've already wrote the code to produce a "cavern" like the one attached using 1 dimensional perlin noise.
I'll have an object fly through the tunnel, and this object has a maximum velocity along the Y axis.
I want to grant the possibility to travel all the tunnel, but i need to limit the derivate of both the upped and lower part of the cave to a specific maximum.
How can i do this?

Here the code i use to generate the noise

public class PerlinNoise {

private static final int X_NOISE_GEN = 1619;
private static final int SEED_NOISE_GEN = 1013;

private double mPersistence = 1/4;
private int mOctaves = 6;
private int mSeed;

public PerlinNoise() {
  mSeed = (int) System.currentTimeMillis();
}

PerlinNoise(double persistence, int octaves, int seed) {
  mPersistence = persistence;
  mOctaves = octaves;
  mSeed = seed;
}

private double IntNoise_1D(int x) {
  int n = (X_NOISE_GEN * x + SEED_NOISE_GEN * mSeed )& 0x7fffffff;
  n = (n<<13) ^ n;
  return ( 1.0 - ( (n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0);
}

private double SmoothedNoise_1D(double x) {
	 return IntNoise_1D((int) x)/2  +  IntNoise_1D((int) (x-1))/4  +  IntNoise_1D((int) (x+1))/4;
}

private double InterpolatedNoise_1D(double x) {
	 int integer_X    = (int) x;
	 double fractional_X = x - integer_X;

	 double v1 = SmoothedNoise_1D(integer_X);
	 double v2 = SmoothedNoise_1D(integer_X + 1);

	 return linearInterp(v1 , v2 , SCurve5(fractional_X));
}

public double Noise_1D(float x) {
  double total = 0;
	 for(int i = 0; i< mOctaves - 1; i++) {
	  int frequency = (int) Math.pow(2, i);
	  double amplitude = (int) Math.pow(mPersistence, i);
	  total = total + InterpolatedNoise_1D(x * frequency) * amplitude;
	 }
    return total;
}

private static double linearInterp (double n0, double n1, double a)
    {
	  return (((1.0 - a) * n0) + (a * n1));
    }

private static double SCurve5 (double a)
    {
	  double a3 = a * a * a;
	  double a4 = a3 * a;
	  double a5 = a4 * a;
	  return (6.0 * a5) - (15.0 * a4) + (10.0 * a3);
    }
}

Attached Thumbnails

  • Immagine.jpg


Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS