Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (804)
Games in Android Showcase (239)
games submitted by our members
Games in WIP (868)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Generating water pool  (Read 3540 times)
0 Members and 1 Guest are viewing this topic.
Offline CopyableCougar4
« Posted 2014-10-26 03:48:57 »

I would like to generate a water pool like the below image (but smoother curves). Does anybody have any ideas on how to programmatically generate points along a border of a water pool? I have code to store the shape and know how to render it, I just need to generate it.



Any thoughts would be appreciated Smiley
CopyableCougar4

Either wandering the forum or programming. Most likely the latter Smiley

Github: http://github.com/CopyableCougar4
Offline thedanisaur

JGO Knight


Medals: 59



« Reply #1 - Posted 2014-10-26 04:04:18 »

If you're using openGL you create the shape using curves....

Anyway have you tried using an Alpha channel? You can create an algorithm to detect edges and then blend the image with the background or use alpha to blend the edges.

Every village needs an idiot Cool
Offline Riven
Administrator

« JGO Overlord »


Medals: 1371
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #2 - Posted 2014-10-26 08:49:40 »

If you're using openGL you create the shape using curves...
Hm... have you ever worked with OpenGL? Smiley It's not curvy at all.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline thedanisaur

JGO Knight


Medals: 59



« Reply #3 - Posted 2014-10-26 09:02:02 »

I have certainly made curves in openGL....3dbuzz even has a couple (old) vids on it?

quick youtube came up with this

https://www.youtube.com/watch?v=Cut3_A0Xm3Y

Every village needs an idiot Cool
Offline Riven
Administrator

« JGO Overlord »


Medals: 1371
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #4 - Posted 2014-10-26 09:28:55 »

I wasn't saying it's impossible, but it's not an inherent feature/property of OpenGL.

Advising the OP to use OpenGL to generate curves, is like sending him down the rabbit hole.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Offline thedanisaur

JGO Knight


Medals: 59



« Reply #5 - Posted 2014-10-26 19:11:02 »

True....idk thought they should know it's possible, yields nice results in most cases.

Every village needs an idiot Cool
Offline CopyableCougar4
« Reply #6 - Posted 2014-10-26 19:28:52 »

I had an idea, but
a. I don't know how to decide slope (see below)
b. I don't know if it would work

Anyways, here's my idea:
- Generate several points around a center, with randomized radii and offsets from the center.
- Do the following per point:
  - find it's relative location to the two nearest points
  - if the other point is above it (y value), then that segment is concave up, otherwise it's concave down
  - determine slopes of selected points between two points (this is where I don't know what to do)
  - add all points to my shape object.
and then I know how to render it from there.

Illustration:


CopyableCougar4

Either wandering the forum or programming. Most likely the latter Smiley

Github: http://github.com/CopyableCougar4
Offline Drenius
« Reply #7 - Posted 2014-10-26 19:30:19 »

You could try your luck at splines for that...
Offline CopyableCougar4
« Reply #8 - Posted 2014-10-26 19:43:52 »

I will certainly try Smiley I found a javascript file that is supposed to create the curves, now to translate it...

Flaws noticed.
  • only designed for a function where all the x values only have one possible y value
  • it's in javascript, so I have to figure out types and sizes for all variables

Off to translate it!

For anybody interested, here's the JavaScript:
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  
function CSPL(){};
   
   CSPL._gaussJ = {};
   CSPL._gaussJ.solve = function(A, x)   // in Matrix, out solutions
   {
      var m = A.length;
      for(var k=0; k<m; k++)   // column
      {
         // pivot for column
         var i_max = 0; var vali = Number.NEGATIVE_INFINITY;
         for(var i=k; i<m; i++) if(A[i][k]>vali) { i_max = i; vali = A[i][k];}
         CSPL._gaussJ.swapRows(A, k, i_max);
         
         if(A[i_max][i] == 0) console.log("matrix is singular!");
         
         // for all rows below pivot
         for(var i=k+1; i<m; i++)
         {
            for(var j=k+1; j<m+1; j++)
               A[i][j] = A[i][j] - A[k][j] * (A[i][k] / A[k][k]);
            A[i][k] = 0;
         }
      }
     
      for(var i=m-1; i>=0; i--)   // rows = columns
      {
         var v = A[i][m] / A[i][i];
         x[i] = v;
         for(var j=i-1; j>=0; j--)   // rows
         {
            A[j][m] -= A[j][i] * v;
            A[j][i] = 0;
         }
      }
   }
   CSPL._gaussJ.zerosMat = function(r,c) {var A = []; for(var i=0; i<r; i++) {A.push([]); for(var j=0; j<c; j++) A[i].push(0);} return A;}
   CSPL._gaussJ.printMat = function(A){ for(var i=0; i<A.length; i++) console.log(A[i]); }
   CSPL._gaussJ.swapRows = function(m, k, l) {var p = m[k]; m[k] = m[l]; m[l] = p;}
     
     
   CSPL.getNaturalKs = function(xs, ys, ks)   // in x values, in y values, out k values
   {
      var n = xs.length-1;
      var A = CSPL._gaussJ.zerosMat(n+1, n+2);
         
      for(var i=1; i<n; i++)   // rows
      {
         A[i][i-1] = 1/(xs[i] - xs[i-1]);
         
         A[i][i  ] = 2 * (1/(xs[i] - xs[i-1]) + 1/(xs[i+1] - xs[i])) ;
         
         A[i][i+1] = 1/(xs[i+1] - xs[i]);
         
         A[i][n+1] = 3*( (ys[i]-ys[i-1])/((xs[i] - xs[i-1])*(xs[i] - xs[i-1]))  +  (ys[i+1]-ys[i])/ ((xs[i+1] - xs[i])*(xs[i+1] - xs[i])) );
      }
     
      A[0][0  ] = 2/(xs[1] - xs[0]);
      A[0][1  ] = 1/(xs[1] - xs[0]);
      A[0][n+1] = 3 * (ys[1] - ys[0]) / ((xs[1]-xs[0])*(xs[1]-xs[0]));
     
      A[n][n-1] = 1/(xs[n] - xs[n-1]);
      A[n][n  ] = 2/(xs[n] - xs[n-1]);
      A[n][n+1] = 3 * (ys[n] - ys[n-1]) / ((xs[n]-xs[n-1])*(xs[n]-xs[n-1]));
         
      CSPL._gaussJ.solve(A, ks);      
   }
     
   CSPL.evalSpline = function(x, xs, ys, ks)
   {
      var i = 1;
      while(xs[i]<x) i++;
     
      var t = (x - xs[i-1]) / (xs[i] - xs[i-1]);
     
      var a =  ks[i-1]*(xs[i]-xs[i-1]) - (ys[i]-ys[i-1]);
      var b = -ks[i  ]*(xs[i]-xs[i-1]) + (ys[i]-ys[i-1]);
     
      var q = (1-t)*ys[i-1] + t*ys[i] + t*(1-t)*(a*(1-t)+b*t);
      return q;
   }


CopyableCougar4

Either wandering the forum or programming. Most likely the latter Smiley

Github: http://github.com/CopyableCougar4
Offline lcass
« Reply #9 - Posted 2014-10-29 22:48:35 »

I had an idea, but
a. I don't know how to decide slope (see below)
b. I don't know if it would work

Anyways, here's my idea:
- Generate several points around a center, with randomized radii and offsets from the center.
- Do the following per point:
  - find it's relative location to the two nearest points
  - if the other point is above it (y value), then that segment is concave up, otherwise it's concave down
  - determine slopes of selected points between two points (this is where I don't know what to do)
  - add all points to my shape object.
and then I know how to render it from there.

Illustration:


CopyableCougar4
ugh whats the name for that oh yer it is a bezier curve , infact they look really nice and (nicely) are pretty efficient to create , you can do it with a series of points and iteration. Check out the wikipedia article BAM->http://en.wikipedia.org/wiki/B%C3%A9zier_curve
Pages: [1]
  ignore  |  Print  
 
 

 
Riven (579 views)
2019-09-04 15:33:17

hadezbladez (5501 views)
2018-11-16 13:46:03

hadezbladez (2398 views)
2018-11-16 13:41:33

hadezbladez (5761 views)
2018-11-16 13:35:35

hadezbladez (1220 views)
2018-11-16 13:32:03

EgonOlsen (4660 views)
2018-06-10 19:43:48

EgonOlsen (5681 views)
2018-06-10 19:43:44

EgonOlsen (3196 views)
2018-06-10 19:43:20

DesertCoockie (4094 views)
2018-05-13 18:23:11

nelsongames (5113 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08
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!