Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (741)
Games in Android Showcase (225)
games submitted by our members
Games in WIP (823)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Newbie & Debugging Questions / Re: 1D Perlin Noise on: 2015-05-02 10:56:30
I recently did something exactly like this! It had hills and a cave system (1D then 2D simplex noise respectively). I used OpenSimplex noise. I had a problem where the caves and hills were extremely rough (absolutely no pattern whatsoever). The kind folks here told me I was using an overly-large amplitude (the coefficient of the coordinates), so when I changed it to something small (times 0.15, for example) it looked perfect.

Some sample code here (very WIP): https://github.com/chrislo27/ProjectMP/blob/master/core/src/projectmp/common/world/World.java#L136-L182

For hills, I took the coordinates at X, -1 with an amplitude of 0.15. For caves, I took the X, Y coordinates (amplitude 0.1), reduced the float it gave me to a value between 0 and 1, and checked if it were in between two thresholds (in this case it was 0.56 and 0.825, these were just tuning over and over again until it looked good). If it were, it was empty. It gives really good results such as this one: http://i.imgur.com/iygn1B1.png

There's also a big cave near the surface to cover up the abrupt stop of the cave generation (it's kinda like the inverse of the hills).

Thank you for your detailed answer. Will check your job and maybe will fix my code.


Thanks will check that link.

Just a quick superficial guess, but I wouldn't be surprised if your freq is far too large. With the Perlin generators I've worked with, one is usually travelling through the generator at a much slower clip. Try 0.09 instead of 0.9 or even 0.01.

But also, only two types of terrain? Or will that be expanded later?


Thats just prototype. At the moment i want to generate simple terrain, so i know everything will be okay later. Thanks for your suggestion. I will play with my code right now.
2  Game Development / Newbie & Debugging Questions / Re: 1D Perlin Noise on: 2015-04-29 18:46:50
I guess it won't be that natural and it would be harder to generate caves.
3  Game Development / Newbie & Debugging Questions / Re: 1D Perlin Noise on: 2015-04-29 18:39:47
Well, this is the downside of trying to hamfist code you find on the internet. That noise1() function looks like it always returns 0.

You can try to debug it to figure out why, but why not just write your own instead, that way you know what you're dealing with?

I would love to write my own, but i am not that good at English and understanding Perlin Noise algorithm for me is pretty complicated. Tried already to understand documentation and almost cried..
4  Game Development / Newbie & Debugging Questions / Re: 1D Perlin Noise on: 2015-04-29 18:30:23
Where are you getting the PerlinNoiseGenerator class?

Searched over the net for PerlinNoise classes, found like 3. The one i am using :

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
190  
191  
192  
193  
194  
195  
196  
197  
198  
199  
200  
201  
202  
203  
204  
205  
206  
207  
208  
209  
210  
211  
212  
213  
214  
215  
216  
217  
218  
219  
220  
221  
222  
223  
224  
225  
226  
227  
228  
229  
230  
231  
232  
233  
234  
235  
236  
237  
238  
239  
240  
241  
242  
243  
244  
245  
246  
247  
248  
249  
250  
251  
252  
253  
254  
255  
256  
257  
258  
259  
260  
261  
262  
263  
264  
265  
266  
267  
268  
269  
270  
271  
272  
273  
274  
275  
276  
277  
278  
279  
280  
281  
282  
283  
284  
285  
286  
287  
288  
289  
290  
291  
292  
293  
294  
295  
296  
297  
298  
299  
300  
301  
302  
303  
304  
305  
306  
307  
308  
309  
310  
311  
312  
313  
314  
315  
316  
317  
318  
319  
320  
321  
322  
323  
324  
325  
326  
327  
328  
329  
330  
331  
332  
333  
334  
335  
336  
337  
338  
339  
340  
341  
342  
343  
344  
345  
346  
347  
348  
349  
350  
351  
352  
353  
354  
355  
356  
357  
358  
359  
360  
361  
362  
363  
364  
365  
366  
367  
368  
369  
370  
371  
372  
373  
374  
375  
376  
377  
378  
379  
380  
381  
382  
383  
384  
385  
386  
387  
388  
389  
390  
391  
392  
393  
394  
395  
396  
397  
398  
399  
400  
401  
402  
403  
404  
405  
406  
407  
408  
409  
410  
411  
412  
413  
414  
415  
416  
417  
418  
419  
420  
421  
422  
423  
424  
425  
426  
427  
428  
429  
430  
431  
432  
433  
434  
435  
436  
437  
438  
439  
440  
441  
442  
443  
444  
445  
446  
447  
448  
449  
450  
451  
452  
453  
454  
455  
456  
457  
458  
459  
460  
461  
462  
463  
464  
465  
466  
467  
468  
469  
470  
471  
472  
473  
474  
475  
476  
477  
478  
479  
480  
481  
482  
483  
484  
485  
486  
487  
488  
489  
490  
491  
492  
493  
494  
495  
496  
497  
498  
499  
500  
501  
502  
503  
504  
505  
506  
507  
508  
509  
510  
511  
512  
513  
514  
515  
516  
517  
518  
519  
520  
521  
522  
523  
524  
525  
526  
527  
528  
529  
530  
531  
532  
533  
534  
535  
536  
537  
538  
539  
540  
541  
542  
543  
544  
545  
546  
547  
548  
549  
550  
551  
552  
553  
554  
555  
556  
557  
558  
559  
560  
561  
562  
563  
564  
565  
566  
567  
568  
569  
570  
571  
572  
573  
574  
575  
576  
577  
578  
579  
580  
581  
582  
583  
584  
585  
586  
587  
588  
589  
590  
591  
592  
593  
594  
595  
596  
597  
598  
599  
600  
601  
602  
603  
604  
605  
606  
607  
608  
609  
610  
611  
612  
613  
614  
615  
616  
617  
618  
619  
620  
621  
622  
623  
624  
625  
626  
627  
628  
629  
630  
631  
632  
/*****************************************************************************
 *                        J3D.org Copyright (c) 2000
 *                               Java Source
 *
 * This source is licensed under the GNU LGPL v2.1
 * Please read http://www.gnu.org/copyleft/lgpl.html for more information
 *
 * This software comes with the standard NO WARRANTY disclaimer for any
 * purpose. Use it at your own risk. If there's a problem you get to fix it.
 *
 ****************************************************************************/

package lv.planet.utils;

import java.util.Random;

/**
 * Computes Perlin Noise for three dimensions.
 * <p>
 *
 * The result is a continuous function that interpolates a smooth path
 * along a series random points. The function is consitent, so given
 * the same parameters, it will always return the same value. The smoothing
 * function is based on the Improving Noise paper presented at Siggraph 2002.
 * <p>
 * Computing noise for one and two dimensions can make use of the 3D problem
 * space by just setting the un-needed dimensions to a fixed value.
 *
 * @author Justin Couch
 * @version $Revision: 1.4 $
 */

public class PerlinNoiseGenerator
{
    // Constants for setting up the Perlin-1 noise functions
    private static final int B = 0x1000;
    private static final int BM = 0xff;

    private static final int N = 0x1000;
    private static final int NP = 12;   /* 2^N */
    private static final int NM = 0xfff;

    /** Default seed to use for the random number generation */
    private static final int DEFAULT_SEED = 100;

    /** Default sample size to work with */
    private static final int DEFAULT_SAMPLE_SIZE = 256;

    /** The log of 1/2 constant. Used Everywhere */
    private static final float LOG_HALF = (float)Math.log(0.5);

    /** Permutation array for the improved noise function */
    private int[] p_imp;

    /** P array for perline 1 noise */
    private int[] p;
    private float[][] g3;
    private float[][] g2;
    private float[] g1;


    /**
     * Create a new noise creator with the default seed value
     */

    public PerlinNoiseGenerator()
    {
        this(DEFAULT_SEED);
    }

    /**
     * Create a new noise creator with the given seed value for the randomness
     *
     * @param seed The seed value to use
     */

    public PerlinNoiseGenerator(int seed)
    {
        p_imp = new int[DEFAULT_SAMPLE_SIZE << 1];

        int i, j, k;
        Random rand = new Random(seed);

        // Calculate the table of psuedo-random coefficients.
        for(i = 0; i < DEFAULT_SAMPLE_SIZE; i++)
            p_imp[i] = i;

        // generate the psuedo-random permutation table.
        while(--i > 0)
        {
            k = p_imp[i];
            j = (int)(rand.nextLong() & DEFAULT_SAMPLE_SIZE);
            p_imp[i] = p_imp[j];
            p_imp[j] = k;
        }

        initPerlin1();
    }

    /**
     * Computes noise function for three dimensions at the point (x,y,z).
     *
     * @param x x dimension parameter
     * @param y y dimension parameter
     * @param z z dimension parameter
     * @return the noise value at the point (x, y, z)
     */

    public double improvedNoise(double x, double y, double z)
    {
        // Constraint the point to a unit cube
        int uc_x = (int)Math.floor(x) & 255;
        int uc_y = (int)Math.floor(y) & 255;
        int uc_z = (int)Math.floor(z) & 255;

        // Relative location of the point in the unit cube
        double xo = x - Math.floor(x);
        double yo = y - Math.floor(y);
        double zo = z - Math.floor(z);

        // Fade curves for x, y and z
        double u = fade(xo);
        double v = fade(yo);
        double w = fade(zo);

        // Generate a hash for each coordinate to find out where in the cube
        // it lies.
        int a =  p_imp[uc_x] + uc_y;
        int aa = p_imp[a] + uc_z;
        int ab = p_imp[a + 1] + uc_z;

        int b =  p_imp[uc_x + 1] + uc_y;
        int ba = p_imp[b] + uc_z;
        int bb = p_imp[b + 1] + uc_z;

        // blend results from the 8 corners based on the noise function
        double c1 = grad(p_imp[aa], xo, yo, zo);
        double c2 = grad(p_imp[ba], xo - 1, yo, zo);
        double c3 = grad(p_imp[ab], xo, yo - 1, zo);
        double c4 = grad(p_imp[bb], xo - 1, yo - 1, zo);
        double c5 = grad(p_imp[aa + 1], xo, yo, zo - 1);
        double c6 = grad(p_imp[ba + 1], xo - 1, yo, zo - 1);
        double c7 = grad(p_imp[ab + 1], xo, yo - 1, zo - 1);
        double c8 = grad(p_imp[bb + 1], xo - 1, yo - 1, zo - 1);

        return lerp(w, lerp(v, lerp(u, c1, c2), lerp(u, c3, c4)),
                       lerp(v, lerp(u, c5, c6), lerp(u, c7, c8)));
    }

    /**
     * 1-D noise generation function using the original perlin algorithm.
     *
     * @param x Seed for the noise function
     * @return The noisy output
     */

    public float noise1(float x)
    {
        float t = x + N;
        int bx0 = ((int) t) & BM;
        int bx1 = (bx0 + 1) & BM;
        float rx0 = t - (int) t;
        float rx1 = rx0 - 1;

        float sx = sCurve(rx0);

        float u = rx0 * g1[p[bx0]];
        float v = rx1 * g1[p[bx1]];

        return lerp(sx, u, v);
    }

    /**
     * Create noise in a 2D space using the orignal perlin noise algorithm.
     *
     * @param x The X coordinate of the location to sample
     * @param y The Y coordinate of the location to sample
     * @return A noisy value at the given position
     */

    public float noise2(float x, float y)
    {
        float t = x + N;
        int bx0 = ((int)t) & BM;
        int bx1 = (bx0 + 1) & BM;
        float rx0 = t - (int)t;
        float rx1 = rx0 - 1;

        t = y + N;
        int by0 = ((int)t) & BM;
        int by1 = (by0 + 1) & BM;
        float ry0 = t - (int)t;
        float ry1 = ry0 - 1;

        int i = p[bx0];
        int j = p[bx1];

        int b00 = p[i + by0];
        int b10 = p[j + by0];
        int b01 = p[i + by1];
        int b11 = p[j + by1];

        float sx = sCurve(rx0);
        float sy = sCurve(ry0);

        float[] q = g2[b00];
        float u = rx0 * q[0] + ry0 * q[1];
        q = g2[b10];
        float v = rx1 * q[0] + ry0 * q[1];
        float a = lerp(sx, u, v);

        q = g2[b01];
        u = rx0 * q[0] + ry1 * q[1];
        q = g2[b11];
        v = rx1 * q[0] + ry1 * q[1];
        float b = lerp(sx, u, v);

        return lerp(sy, a, b);
    }

    /**
     * Create noise in a 3D space using the orignal perlin noise algorithm.
     *
     * @param x The X coordinate of the location to sample
     * @param y The Y coordinate of the location to sample
     * @param z The Z coordinate of the location to sample
     * @return A noisy value at the given position
     */

    public float noise3(float x, float y, float z)
    {
       float t = x + (float)N;
        int bx0 = ((int)t) & BM;
        int bx1 = (bx0 + 1) & BM;
        float rx0 = (float)(t - (int)t);
        float rx1 = rx0 - 1;

        t = y + (float)N;
        int by0 = ((int)t) & BM;
        int by1 = (by0 + 1) & BM;
        float ry0 = (float)(t - (int)t);
        float ry1 = ry0 - 1;

        t = z + (float)N;
        int bz0 = ((int)t) & BM;
        int bz1 = (bz0 + 1) & BM;
        float rz0 = (float)(t - (int)t);
        float rz1 = rz0 - 1;

        int i = p[bx0];
        int j = p[bx1];

        int b00 = p[i + by0];
        int b10 = p[j + by0];
        int b01 = p[i + by1];
        int b11 = p[j + by1];

        t  = sCurve(rx0);
        float sy = sCurve(ry0);
        float sz = sCurve(rz0);

        float[] q = g3[b00 + bz0];
        float u = (rx0 * q[0] + ry0 * q[1] + rz0 * q[2]);
        q = g3[b10 + bz0];
        float v = (rx1 * q[0] + ry0 * q[1] + rz0 * q[2]);
        float a = lerp(t, u, v);

        q = g3[b01 + bz0];
        u = (rx0 * q[0] + ry1 * q[1] + rz0 * q[2]);
        q = g3[b11 + bz0];
        v = (rx1 * q[0] + ry1 * q[1] + rz0 * q[2]);
        float b = lerp(t, u, v);

        float c = lerp(sy, a, b);

        q = g3[b00 + bz1];
        u = (rx0 * q[0] + ry0 * q[1] + rz1 * q[2]);
        q = g3[b10 + bz1];
        v = (rx1 * q[0] + ry0 * q[1] + rz1 * q[2]);
        a = lerp(t, u, v);

        q = g3[b01 + bz1];
        u = (rx0 * q[0] + ry1 * q[1] + rz1 * q[2]);
        q = g3[b11 + bz1];
        v = (rx1 * q[0] + ry1 * q[1] + rz1 * q[2]);
        b = lerp(t, u, v);

        float d = lerp(sy, a, b);

        return lerp(sz, c, d);
    }

    /**
     * Create a turbulent noise output based on the core noise function. This
     * uses the noise as a base function and is suitable for creating clouds,
     * marble and explosion effects. For example, a typical marble effect would
     * set the colour to be:
     * <pre>
     *    sin(point + turbulence(point) * point.x);
     * </pre>
     */

    public double imporvedTurbulence(double x,
                                     double y,
                                     double z,
                                     float loF,
                                     float hiF)
    {
        double p_x = x + 123.456f;
        double p_y = y;
        double p_z = z;
        double t = 0;
        double f;

        for(f = loF; f < hiF; f *= 2)
        {
            t += Math.abs(improvedNoise(p_x, p_y, p_z)) / f;

            p_x *= 2;
            p_y *= 2;
            p_z *= 2;
        }

        return t - 0.3;
    }

    /**
     * Create a turbulance function in 2D using the original perlin noise
     * function.
     *
     * @param x The X coordinate of the location to sample
     * @param y The Y coordinate of the location to sample
     * @param freq The frequency of the turbluance to create
     * @return The value at the given coordinates
     */

    public float turbulence2(float x, float y, float freq)
    {
        float t = 0;

        do
        {
            t += noise2(freq * x, freq * y) / freq;
            freq *= 0.5f;
        }
        while (freq >= 1);

        return t;
    }

    /**
     * Create a turbulance function in 3D using the original perlin noise
     * function.
     *
     * @param x The X coordinate of the location to sample
     * @param y The Y coordinate of the location to sample
     * @param z The Z coordinate of the location to sample
     * @param freq The frequency of the turbluance to create
     * @return The value at the given coordinates
     */

    public float turbulence3(float x, float y, float z, float freq)
    {
        float t = 0;

        do
        {
            t += noise3(freq * x, freq * y, freq * z) / freq;
            freq *= 0.5f;
        }
        while (freq >= 1);

        return t;
    }

    /**
     * Create a 1D tileable noise function for the given width.
     *
     * @param x The X coordinate to generate the noise for
     * @param w The width of the tiled block
     * @return The value of the noise at the given coordinate
     */

    public float tileableNoise1(float x, float w)
    {
        return (noise1(x)     * (w - x) +
                noise1(x - w) *      x) / w;
    }

    /**
     * Create a 2D tileable noise function for the given width and height.
     *
     * @param x The X coordinate to generate the noise for
     * @param y The Y coordinate to generate the noise for
     * @param w The width of the tiled block
     * @param h The height of the tiled block
     * @return The value of the noise at the given coordinate
     */

    public float tileableNoise2(float x, float y, float w, float h)
    {
        return (noise2(x,     y)     * (w - x) * (h - y) +
                noise2(x - w, y)     *      x  * (h - y) +
                noise2(x,     y - h) * (w - x) *      y  +
                noise2(x - w, y - h) *      x  *      y) / (w * h);
    }

    /**
     * Create a 3D tileable noise function for the given width, height and
     * depth.
     *
     * @param x The X coordinate to generate the noise for
     * @param y The Y coordinate to generate the noise for
     * @param z The Z coordinate to generate the noise for
     * @param w The width of the tiled block
     * @param h The height of the tiled block
     * @param d The depth of the tiled block
     * @return The value of the noise at the given coordinate
     */

    public float tileableNoise3(float x,
                                float y,
                                float z,
                                float w,
                                float h,
                                float d)
    {
        return (noise3(x,     y,     z)     * (w - x) * (h - y) * (d - z) +
                noise3(x - w, y,     z)     *      x  * (h - y) * (d - z) +
                noise3(x,     y - h, z)     * (w - x) *      y  * (d - z) +
                noise3(x - w, y - h, z)     *      x  *      y  * (d - z) +
                noise3(x,     y,     z - d) * (w - x) * (h - y) *      z  +
                noise3(x - w, y,     z - d) *      x  * (h - y) *      z  +
                noise3(x,     y - h, z - d) * (w - x) *      y  *      z  +
                noise3(x - w, y - h, z - d) *      x  *      y  *      z) /
                (w * h * d);
    }

    /**
     * Create a turbulance function that can be tiled across a surface in 2D.
     *
     * @param x The X coordinate of the location to sample
     * @param y The Y coordinate of the location to sample
     * @param w The width to tile over
     * @param h The height to tile over
     * @param freq The frequency of the turbluance to create
     * @return The value at the given coordinates
     */

    public float tileableTurbulence2(float x,
                                     float y,
                                     float w,
                                     float h,
                                     float freq)
    {
        float t = 0;

        do
        {
            t += tileableNoise2(freq * x, freq * y, w * freq, h * freq) / freq;
            freq *= 0.5f;
        }
        while (freq >= 1);

        return t;
    }

    /**
     * Create a turbulance function that can be tiled across a surface in 3D.
     *
     * @param x The X coordinate of the location to sample
     * @param y The Y coordinate of the location to sample
     * @param z The Z coordinate of the location to sample
     * @param w The width to tile over
     * @param h The height to tile over
     * @param d The depth to tile over
     * @param freq The frequency of the turbluance to create
     * @return The value at the given coordinates
     */

    public float tileableTurbulence3(float x,
                                     float y,
                                     float z,
                                     float w,
                                     float h,
                                     float d,
                                     float freq)
    {
        float t = 0;

        do
        {
            t += tileableNoise3(freq * x,
                                freq * y,
                                freq * z,
                                w * freq,
                                h * freq,
                                d * freq) / freq;
            freq *= 0.5f;
        }
        while (freq >= 1);

        return t;
    }


    /**
     * Simple lerp function using doubles.
     */

    private double lerp(double t, double a, double b)
    {
        return a + t * (b - a);
    }

    /**
     * Simple lerp function using floats.
     */

    private float lerp(float t, float a, float b)
    {
        return a + t * (b - a);
    }

    /**
     * Fade curve calculation which is 6t^5 - 15t^4 + 10t^3. This is the new
     * algorithm, where the old one used to be 3t^2 - 2t^3.
     *
     * @param t The t parameter to calculate the fade for
     * @return the drop-off amount.
     */

    private double fade(double t)
    {
        return t * t * t * (t * (t * 6 - 15) + 10);
    }

    /**
     * Calculate the gradient function based on the hash code.
     */

    private double grad(int hash, double x, double y, double z)
    {
        // Convert low 4 bits of hash code into 12 gradient directions.
        int h = hash & 15;
        double u = (h < 8 || h == 12 || h == 13) ? x : y;
        double v = (h < 4 || h == 12 || h == 13) ? y : z;

        return ((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v);
    }

    /**
     * Simple bias generator using exponents.
     */

    private float bias(float a, float b)
    {
        return (float)Math.pow(a, Math.log(b) / LOG_HALF);
    }


    /*
     * Gain generator that caps to the range of [0, 1].
     */

    private float gain(float a, float b)
    {
        if(a < 0.001f)
            return 0;
        else if (a > 0.999f)
            return 1.0f;

        double p = Math.log(1.0f - b) / LOG_HALF;

        if(a < 0.5f)
            return (float)(Math.pow(2 * a, p) / 2);
        else
            return 1 - (float)(Math.pow(2 * (1.0f - a), p) / 2);
    }

    /**
     * S-curve function for value distribution for Perlin-1 noise function.
     */

    private float sCurve(float t)
    {
        return (t * t * (3 - 2 * t));
    }

    /**
     * 2D-vector normalisation function.
     */

    private void normalize2(float[] v)
    {
        float s = (float)(1 / Math.sqrt(v[0] * v[0] + v[1] * v[1]));
        v[0] *= s;
        v[1] *= s;
    }

    /**
     * 3D-vector normalisation function.
     */

    private void normalize3(float[] v)
    {
        float s = (float)(1 / Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]));
        v[0] *= s;
        v[1] *= s;
        v[2] *= s;
    }

    /**
     * Initialise the lookup arrays used by Perlin 1 function.
     */

    private void initPerlin1()
    {
        p = new int[B + B + 2];
        g3 = new float[B + B + 2][3];
        g2 = new float[B + B + 2][2];
        g1 = new float[B + B + 2];
        int i, j, k;

        for(i = 0; i < B; i++)
        {
            p[i] = i;

            g1[i] = (float)(((Math.random() * Integer.MAX_VALUE) % (B + B)) - B) / B;

            for(j = 0; j < 2; j++)
                g2[i][j] = (float)(((Math.random() * Integer.MAX_VALUE) % (B + B)) - B) / B;
            normalize2(g2[i]);

            for(j = 0; j < 3; j++)
                g3[i][j] = (float)(((Math.random() * Integer.MAX_VALUE) % (B + B)) - B) / B;
            normalize3(g3[i]);
        }

        while(--i > 0)
        {
            k = p[i];
            j = (int)((Math.random() * Integer.MAX_VALUE) % B);
            p[i] = p[j];
            p[j] = k;
        }

        for(i = 0; i < B + 2; i++)
        {
            p[B + i] = p[i];
            g1[B + i] = g1[i];
            for(j = 0; j < 2; j++)
                g2[B + i][j] = g2[i][j];
            for(j = 0; j < 3; j++)
                g3[B + i][j] = g3[i][j];
        }
    }
}


I have some SimplexNoise code too, but it generates same results.
5  Game Development / Newbie & Debugging Questions / 1D Perlin Noise on: 2015-04-29 18:21:11
Hello, after 2 days of researching i am still struggling with 1D perlin noise. Tried to search over the network for some source code, so i understand how it works, but still no understanding from me.
The best i did with 1D perlin :

And it doesn't look like terrain to be honest, haha..
2D perlin does not do my job, because i am doing sidescroller and it does top-down style terrain..

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
PerlinNoiseGenerator noise = new PerlinNoiseGenerator(111);
      float freq = 0.9f;
      for(int i = 1; i <= planetSize; i++) {
         Chunk chunky = new Chunk(Constants.CHUNK_SIZE);
         c[i - 1] = chunky;
         for(int x = 0; x < Constants.CHUNK_SIZE; x++) {
            float height = noise.noise1((float)((x * i) * freq));
            for(float y = 0 + height; y < Constants.CHUNK_SIZE; y++) {
               if(y >= -0.0f) {
                  c[i - 1].getTilesInChunk()[x][(int) y] = new Tile(x * i,(int) y, TileType.DIRT);
               } else {
                  c[i - 1].getTilesInChunk()[x][(int) y] = new Tile(x * i, (int)y, TileType.NONE);
               }
            }
         }
6  Discussions / Miscellaneous Topics / Re: What I did today on: 2015-01-11 22:46:10
New Texture

Ahahaha, man. You are so funny.

Haven't coded in a while, because of exams.
7  Discussions / General Discussions / Re: Client/Server Library Discussion on: 2015-01-07 16:56:35
I am using KryoNet for a while and I really like it. At the moment I can't say anything bad and it's easy to understand.
8  Game Development / Newbie & Debugging Questions / Re: (LibGdx)Tile placement on: 2014-12-13 18:13:46
Give us your code and we will fix it Smiley
9  Game Development / Newbie & Debugging Questions / Re: Could someone explain this snippet of code i found? on: 2014-10-22 09:04:38
Just show us the place where you found it, because it's just basic Java you need to learn. I guess you don't understand bitwise and bit shift operators - http://docs.oracle.com/javase/tutorial/java/nutsandbolts/op3.html
10  Game Development / Newbie & Debugging Questions / Re: [LibGdx] Massive fps drop when loading more than 1 texture. on: 2014-09-16 21:10:33
Thanks, fixed. You can close this. Smiley
11  Game Development / Newbie & Debugging Questions / Re: [LibGdx] Massive fps drop when loading more than 1 texture. on: 2014-09-16 19:43:33
mind if I see the batch code?

Sorry, you want to see SpriteBatch.java or what?
I think it's not batching problem. It might be something with tile creating or anything else.
12  Game Development / Newbie & Debugging Questions / Re: [LibGdx] Massive fps drop when loading more than 1 texture. on: 2014-09-16 18:17:58

Tile rendering.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
/**
    * Checks every tile -> Gets tile id -> Draws correct texture.
    * If Tile is empty, ignore it.
    * @param batch
    */

   public void drawTiles(SpriteBatch batch) {
      for(int x = 0; x < WORLD_X; x++) {
         for(int y = 0; y < WORLD_Y; y++) {
            if(getTileId(x, y) != 0) {
               batch.draw(Tiles.getTile(getTileId(x, y)).getTileImg(), 16 * x, 16 * y);
            }
         }
      }
   }



Generating world
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
//Contains map information
   private Tile[][] map = new Tile[WORLD_X][WORLD_Y];
   
   /**
    * Generates new map
    */

   public TerrainGenerator() {
      for(int x = 0; x < WORLD_X; x++) {
         for(int y = 0; y < WORLD_Y; y++) {
            map[x][y] = new Tile(Misc.random(0, 2));
         }
      }
    }


Tile class
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
public class Tile {
   
   private int id;
   private int durability;
   
   public Tile(int tileId) {
      this.id = tileId;
      this.durability = Tiles.getTile(tileId).getDurability();
   }
   
   public int getId() {
      return this.id;
   }
   
   public int setId(int tileId) {
      return this.id = tileId;
   }
   
   
   public int getDurability() {
      return this.durability;
   }
}


Contains tile information.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
public enum Tiles {
   
   EMPTY(0, null, -1),
   DIRT(1, new Texture("tiles/sand.png"), 5),
   ROCK(2, new Texture("tiles/rock.png"), 2);
   
   //Tile id
   private int id;
   //Tile image
   private Texture tileImg;
   //Tile durability
   private int durability;
   
   Tiles(int id, Texture tileImg, int durability) {
      this.id = id;
      this.tileImg = tileImg;
      this.durability = durability;
   }
   
   /**
    * Returns Specified Tile data.
    * @param tileId
    * @return
    */

   public static Tiles getTile(int tileId) {
      for(Tiles t : Tiles.values()) {
         if(t.getId() == tileId) {
            return t;
         }
      }
      return null;
   }
   
   /**
    * Returns Tile id
    * @return
    */

   public int getId() {
      return id;
   }
   
   /**
    * Returns Tiles image
    * @return
    */

   public Texture getTileImg() {
      return tileImg;
   }
   
   public int getDurability() {
      return durability;
   }

}
13  Game Development / Newbie & Debugging Questions / [LibGdx] Massive fps drop when loading more than 1 texture. on: 2014-09-16 17:38:21
Hello, JGO!
I have created world. World size is 250 * 250 tiles and tile information is stored in 2D object array.
At first i was generating randomly 2 tiles - dirt and empty tile. There was no problems and had like 60fps without culling.
After that i created another tile(stone) and then it started to lag(~5fps). If i generate 250x250 with only dirt tile/stone tile then fps is normal.

Writing this up i remembered that it might lag, because there is 2 different Tile objects now, but why would it lag?

If you need any code, say it. And if you don't understand me, i will try to tell this differently.
14  Discussions / Miscellaneous Topics / Re: Any way to improve my logo? on: 2014-06-05 23:36:01
Add gears some shadows, so it looks more beautiful. At the moment it's just plain. Looks like tractor wheel.
15  Discussions / General Discussions / Great programming book offer. on: 2014-03-24 19:39:47
Quote
Packt Publishing are launching an exciting campaign to coincide with the release of our 2000th title. During this offer Packt is giving its reader a chance to dive into their comprehensive catalogue and avail a Buy One, Get One Free offer across their entire range of eBooks.
The campaign will continue up until 26th-Mar-2014. Following are the benefits readers can avail during this campaign.

I have history with Packt publish, because i got free copy of book "Learning Libgdx game development". They are very supportive and helpful, always send me good opportunities to earn free ebooks, books.
If anyone is interested - [removed_link_with_affiliate_tracking]

Sorry if you think this is spam or waste of time for you, but maybe someone will be interested.
Thank you for your time!
16  Game Development / Newbie & Debugging Questions / Re: Is it easy to make games through pure java? on: 2014-02-09 22:12:37
Thank you guys by the way do you guys suggest from me to order this book?
http://www.packtpub.com/learning-libgdx-game-development/book

It's an great book. It involves some basic stuff to make game with libGDX. Collision, box2d, main menu creating, asset dealing...
Read it and got some useful information for me. So when you will start with libGDX, buy it.. You won't regret it. Smiley

About topic:
I started with pure Java2D. Watched some tutorials, learned how everything works. Then i started with lwjgl and slick2d, but i read some articles, that slick2d is dead project. Tried to search something similar and then i found libGDX. It's very stable and easy to understandable. So i suggest you to start with Java2D and then when you feel ready, go with libGDX.
17  Games Center / WIP games, tools & toy projects / Re: Renoria - Java MMORPG on: 2014-02-06 12:19:42
Hey! I really love your project and i am checking it out every day.
I am a big MMORPG fan especially 2D MMORPG's.
Can you, please, share some information about how is working your networking? Maybe some samples, if that's not a problem.
I really want to learn a MMORPG networking and gather some useful information for future game developments.
Thank you!

I wish you the best and hope to play Renoria someday.
Pages: [1]
 
Ecumene (110 views)
2017-09-30 02:57:34

theagentd (136 views)
2017-09-26 18:23:31

cybrmynd (245 views)
2017-08-02 12:28:51

cybrmynd (241 views)
2017-08-02 12:19:43

cybrmynd (240 views)
2017-08-02 12:18:09

Sralse (254 views)
2017-07-25 17:13:48

Archive (864 views)
2017-04-27 17:45:51

buddyBro (1008 views)
2017-04-05 03:38:00

CopyableCougar4 (1569 views)
2017-03-24 15:39:42

theagentd (1373 views)
2017-03-24 15:32:08
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!