We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › smooth triangles edges
Pages: 1 2 
smooth triangles edges (Read 4201 times)
Re: smooth triangles edges
Reply #15 - Dec 11th, 2009, 11:56am
 
you need the proper normals for the curve that defines the hole. that's not going to be easy (especially as we haven't seen that code). i have no idea what those values of x, y and z are (but that looks like the code for working out a vector perpendicular to two others, the vector product, which is the generic solution, but you need specifics)
Re: smooth triangles edges
Reply #16 - Dec 11th, 2009, 11:58am
 
(actually that code is probably exactly what processing is using under the covers to calculate normals when the programmer doesn't supply them explicitly. so you'll end up with flat shading again. or worse)
Re: smooth triangles edges
Reply #17 - Dec 11th, 2009, 1:09pm
 
for the Z values visit this link:

http://maxtrix.com.pt/game/geography/ServerData.php?client=htmltable&dim=20&geo=...

for the X and Y theres no mystery, X = {0,5,10,15,20.......} and Y = {0,5,10,15,20.......} also.

X and Y are linear, Z are the result of my php function to change the heights of the points. must say that Z is inverted, -Z is going up.

sorry, those Z values are not from the original picture.... i changed the terrain, i'll make a print of the new terrain and replace the original, to match the values.

i'm not being capable of working with the normals.... sigh....

google told me that, to achieve good rendering i need to calculate the normal of the vertices, not the surfaces. calculating faces is not bad but edges normals gives better results than faces (more dificult to do though) and normal vertives is even better than edges normal (the hardest).

at this moment my brain is melting.........
Re: smooth triangles edges
Reply #18 - Dec 11th, 2009, 2:07pm
 
those values aren't enough i'm afraid - too much data has been lost. need to know the equation for the curve really.
Re: smooth triangles edges
Reply #19 - Dec 11th, 2009, 2:31pm
 
ready for some php?

don't know if this will help, because it's not an equation,
this function receives an X and Y position, a startind world Z, and final world Z and manipulates values from my data base.

but in a simple way it calculates the Z position for the surrouding points, making it look like a curve.

the nearest equation to this is the curve equation:

distance = 5;

for a random X,
Y = SQRT((distance*distance)-(X*X))
in order to draw a perfect circle.

PITAGORAS stuff.


Code:

function DrawHill($world_height,$x,$y,$z_height)
{
    $raio_xy = floor($total_x);

    for($xx = ($x-$raio_xy); $xx <= ($x+$raio_xy); $xx++)
    {
   for($yy = ($y-$raio_xy); $yy <= ($y+$raio_xy);$yy++)
   {
  $local_raio_xy = sqrt(pow($x - $xx,2)+pow($y - $yy,2));
  if($local_raio_xy<$raio_xy)
  {
 if($local_raio_xy<$middle_x)
 {
$p_dis = sqrt(pow($x - $xx,2)+pow($y - $yy,2));
$height = sqrt(abs((($p_dis*$p_dis)-($z_height)*($z_height))));

$array_name[$xx][$yy] = ($height*$z_sign)+$world_height.",0";
 }
 else
 {
$p_dis =$total_x - sqrt(pow($x - $xx,2)+pow($y - $yy,2));

$height =$z_height - sqrt(abs((($p_dis*$p_dis)-($z_height)*($z_height))));

$array_name[$xx][$yy] = ($height*$z_sign)+$world_height.",0";
 }
  }
   }
    }
}
Re: smooth triangles edges
Reply #20 - Dec 12th, 2009, 2:29am
 
php's fine, it's all code 8). (what's the extra ",0" for in each of those cells btw?)

what i don't have is any time today. exhibitions to see, birthday parties to attend...

i had a thought though, that you could possible interpolate the normals based on the neighbours.

for instance, at point (x, y, z) you could calculate the vector joining (x, y-1, z) to (x, y+1, z) and the vector joining (x-1, y, z) and (x+1, y, z) and then use the code you posted earlier to calculate the vector product. normalise that and store it as the normal for point (x, y, z). i'd try this first, see how it looks. there are probably better methods that also use the z of (x, y, z) but try the easy thing first...

the fundamental problem is that you're using flat tiles to represent a curved surface, it's never going to be perfect. there are methods (that i've never used) which adapt surfaces so that it uses more, smaller tiles where the curve is tighter. (like your water is a single flat surface)
Re: smooth triangles edges
Reply #21 - Dec 12th, 2009, 5:19am
 
well, my fight is not over yet, it's the first time i think about normals, i'm very "green" at this moment about this subject, but if i don't quit on this eventually i'll be abble to improve my drawing skils.

the extra '0' means nothing, but if it's a '1' means a small sample  'house' in those cooords, a '2' means a tree, etc.... i'm working on some simple but nice models in wings3D yet.

this is a massive 3D terrain i'm working on, with lots of candys (if i understood correctly, you english programers say 'candys' when talking about thinks that look beautifull or cool, right?).

by the way, the visible area is about 40x40 squares, and at this point it's not possible to navigate around all the terrain, but this terrain is an impressive (1 trilion) x (1 trilion) huge square.

you'll be able to see that later.

Re: smooth triangles edges
Reply #22 - Dec 13th, 2009, 5:35am
 
"eye-candy" i think is the phrase you're after 8)

anyway, have tried generating linearly interpolated normals and using them in the beginShape code and here (hopefully) are the results.

Here's the flat shaded original. (the coords you posted is giving me a 404 and the php snippet  is missing a few variables so i just made it sinusoidal)

...

and here it is with the linear normals shown

...

and here's the smoothed version

...

parts of which look better, parts of which still look terrible. would like to see it with your smoother landscape. am looking into using a higher order approximation in order to find the normal.

(these are all on my flickr stream: http://www.flickr.com/photos/31962137@N00 apparently i have to link all my 'photos' back there but can't post the urls they give in a format that the processing BB likes)

edit - messed up pictures

will post code below...
Re: smooth triangles edges
Reply #23 - Dec 13th, 2009, 5:47am
 
i calculate the normals like this:

Code:

// linear interpolation based
PVector[][] normals = new PVector[SIZE][SIZE];
void setNormals() {
 for (int y = 0 ; y < SIZE ; y++) {
   for (int x = 0 ; x < SIZE ; x++) {
     // edge normals point straight up
     if (x == 0 || y == 0 || x == SIZE - 1 || y == SIZE - 1) {
       normals[x][y] = new PVector(0, 0, 1);
       continue;
     }
     // cross product of neighbours
     PVector v1 = new PVector(2.0, 0.0, grid[x + 1][y] - grid[x - 1][y]);
     PVector v2 = new PVector(0.0, 2.0, grid[x][y + 1] - grid[x][y - 1]);
     normals[x][y] = v1.cross(v2);
     normals[x][y].normalize();
   }
 }
}


and added this to bottom of draw to show the normals (mostly for debugging, hence the condition at the top)

Code:

 if (showNormals) {
   for(int x = 0 ; x < (raio * 2) ; x++) {
     for(int y = 0 ; y < (raio * 2) ; y++) {
     int q = 5;
     stroke(255, 0, 0);
     line(
       x * q, y * q, -grid[x][y] * q,
       (x * q) + (10 * normals[x][y].x), (y * q) + (10 * normals[x][y].y), (-grid[x][y] * q) - (10 * normals[x][y].z));
   }
 }


and the main drawing beginShape() contents now looks like this with the normals added in
Code:

normal(normals[x][y].x, normals[x][y].y, normals[x][y].z);
vertex(x * q, y * q, -grid[x][y] * q);
normal(normals[x][y + 1].x, normals[x][y + 1].y, normals[x][y + 1].z);
vertex(x * q, (y + 1) * q, -grid[x][y + 1] * q);
normal(normals[x + 1][y].x, normals[x + 1][y].y, normals[x + 1][y].z);
vertex((x + 1) * q, y * q, -grid[x + 1][y] * q);
                         
normal(normals[x + 1][y].x, normals[x + 1][y].y, normals[x + 1][y].z);
vertex((x + 1) * q, y * q, -grid[x + 1][y] * q);
normal(normals[x][y + 1].x, normals[x][y + 1].y, normals[x][y + 1].z);
vertex(x * q, (y + 1) * q, -grid[x][y + 1] * q);
normal(normals[x + 1][y + 1].x, normals[x + 1][y + 1].y, normals[x + 1][y + 1].z);
vertex((x + 1) * q, (y + 1) * q, -grid[x + 1][y + 1] * q);
Re: smooth triangles edges
Reply #24 - Dec 13th, 2009, 5:53am
 
Jorge Alves wrote on Dec 12th, 2009, 5:19am:
by the way, the visible area is about 40x40 squares, and at this point it's not possible to navigate around all the terrain, but this terrain is an impressive (1 trilion) x (1 trilion) huge square.


this scares me 8)

the normals add a PVector (or 3 floats) for every point and you have a LOT of points. i guess it would be possible to only calculate them for the currently visible area on every frame but that'll have a performance hit.
Re: smooth triangles edges
Reply #25 - Dec 13th, 2009, 8:52am
 
koogy, now you've impressed me a lot with your modeling skils, very cool stuff  you have there. i think i'll be checking your work progress from now on.

about the coords, i've been remodling the folder from my server, probably the link connection was lost. i'll check your posts  and study what you got there.

the image with normals working is not so bad, is far better than mine. to be honest i'll loved it, it looks great to me.

thanks a lot koogy, i'll reply as soon i have more improvements.

i'll be posting a new topic about folder security, maybe you can help me.
Re: smooth triangles edges
Reply #26 - Dec 13th, 2009, 2:01pm
 
working on koogy's code.......
Re: smooth triangles edges
Reply #27 - Dec 13th, 2009, 2:22pm
 
almost there,
just checking some nullpointerexceptions here....
normals calculation are fine, after some adjustments has you can see in the picture.
something is going wrong when really using them. working on that.

by the way, how can i shrink images with BBcode here? they look too big.

...
Re: smooth triangles edges
Reply #28 - Dec 14th, 2009, 2:15am
 
> by the way, how can i shrink images with BBcode here? they look too big.

i let flickr do it - chose the 240x??? version of the images from the 'All Sizes' page. but you can use gimp and do it manually easily enough.

what might save space and time is leaving the normals null for the flat areas of the map and not storing or drawing them. i do like the fuzzy look they have though 8)
Pages: 1 2