Dad72 Posted February 21, 2014 Author Share Posted February 21, 2014 I have a beginning of result which smooths the edge, but the problem is that it also widening the lower edge. Me, i would like that does not dig into the sand part. By and large the smoothing, must flatten the bumps on the flat (here, this digs), elevate on the hollow (here, this digs also) and round off the corners on the edge (here, ok).I have modify a can your previous code:// Smooth vertices for (var selectedVertice in this._selectedVertices) { var position = this._groundPositions[selectedVertice]; var distance = this._selectedVertices[selectedVertice]; var fullHeight = height * this._invertDirection; if (distance < radius * 0.3) { position.y += 0; } else { position.y -= 0.5 * fullHeight * (1.0 - (distance - radius * 0.1) / (radius * 0.9)); } this._groundVerticesPositions[selectedVertice * 3 + 1] = position.y; this._updateSubdivisions(selectedVertice); }Here is the image for that you can see what I want to say: Thanks Quote Link to comment Share on other sites More sharing options...
Dad72 Posted February 25, 2014 Author Share Posted February 25, 2014 Nobody as of ideas? Quote Link to comment Share on other sites More sharing options...
Dad72 Posted February 26, 2014 Author Share Posted February 26, 2014 I don't manage to solve this problem here. Someone can help me? Thanks Quote Link to comment Share on other sites More sharing options...
Dad72 Posted February 26, 2014 Author Share Posted February 26, 2014 I have managed to find the solution with :if (position.y < distance) { position.y += 0;}else { position.y -= 0.5 * (fullHeight / 2) * (1.0 - (distance - radius * 0.1) / (radius * 0.9));}It appears to work correctly. Quote Link to comment Share on other sites More sharing options...
gwenael Posted February 26, 2014 Share Posted February 26, 2014 Cool.A little improvementif (position.y >= distance) { position.y -= fullHeight / 4 * (10/9 - distance / (radius * 0.9));} Quote Link to comment Share on other sites More sharing options...
Dad72 Posted February 26, 2014 Author Share Posted February 26, 2014 Thank You Gwenaël. But in made, with your improvement, this regrooved in the ground. with what I have done it works exactly as expected. Quote Link to comment Share on other sites More sharing options...
gwenael Posted February 26, 2014 Share Posted February 26, 2014 Oops I was too fast and I must have done a mistake when simplifying it. First simplification:if (position.y >= distance) { position.y -= 0.5 * (fullHeight / 2) * (1.0 - (distance - radius * 0.1) / (radius * 0.9));}Second simplification:if (position.y >= distance) { position.y -= (fullHeight / 4) * (1.0 - (distance - radius * 0.1) / (radius * 0.9));}Third one:if (position.y >= distance) { position.y -= (fullHeight / 4) * (1.0 + (radius *0.1 - distance) / (radius * 0.9));}Fourth one:if (position.y >= distance) { position.y -= (fullHeight / 4) * (1.0 + (radius *0.1 / (radius * 0.9) - distance / (radius * 0.9)));}Fifth one:if (position.y >= distance) { position.y -= (fullHeight / 4) * (1.0 + (1/9 - distance / (radius * 0.9)));}Sixth one:if (position.y >= distance) { position.y -= (fullHeight / 4) * (10/9 - distance / (radius * 0.9));}Argh, I don't get where I'm wrong. Sorry gotta go. Will check that later Quote Link to comment Share on other sites More sharing options...
Dad72 Posted February 26, 2014 Author Share Posted February 26, 2014 Guenael sorry, but all your solutions hollow ground. Quote Link to comment Share on other sites More sharing options...
gwenael Posted February 26, 2014 Share Posted February 26, 2014 Even the first one? It's the same asif (position.y < distance) { position.y += 0;}else { position.y -= 0.5 * (fullHeight / 2) * (1.0 - (distance - radius * 0.1) / (radius * 0.9));}except if position.y is undefined. In your solution, it will set it and in my suggestion it will ignore it. In your code, is it really position.y += 0 or is it position.y = 0 (no plus sign)? Quote Link to comment Share on other sites More sharing options...
Dad72 Posted February 26, 2014 Author Share Posted February 26, 2014 Yes, it is position.y += 0; the vertices does not rise and not fall.if I made position.y -= 0; it also works. But 0 is required. Quote Link to comment Share on other sites More sharing options...
gwenael Posted February 26, 2014 Share Posted February 26, 2014 I really don't understand why you have to do that. y += 0 means y = y + 0 which also means y = y. So this instruction is needless. Thus if (position.y < distance) { position.y += 0;}else { position.y -= 0.5 * (fullHeight / 2) * (1.0 - (distance - radius * 0.1) / (radius * 0.9));}is the same thing asif (position.y < distance) { // nothing to do}else { position.y -= 0.5 * (fullHeight / 2) * (1.0 - (distance - radius * 0.1) / (radius * 0.9));}orif (position.y >= distance) {{ position.y -= 0.5 * (fullHeight / 2) * (1.0 - (distance - radius * 0.1) / (radius * 0.9));} Quote Link to comment Share on other sites More sharing options...
Dad72 Posted February 26, 2014 Author Share Posted February 26, 2014 Yes. true. is good:if (position.y >= distance) {{ position.y -= 0.5 * (fullHeight / 2) * (1.0 - (distance - radius * 0.1) / (radius * 0.9));} Quote Link to comment Share on other sites More sharing options...
gwenael Posted February 26, 2014 Share Posted February 26, 2014 I was being nuts. I couldn't understand why it didn't work. It works! So my first simplification (http://www.html5gamedevs.com/topic/4005-rough-terrain-smooth/?p=26454) worked. Could you try with the second one and then with the third one, up to the last one? Don't forget to empty your cache between tests. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted February 26, 2014 Author Share Posted February 26, 2014 In made when I tested your various simplification, I do not remove the 'else{ ... } '. I had not understood. I am tired ...I test again tomorrow any your simplifications Quote Link to comment Share on other sites More sharing options...
gwenael Posted February 27, 2014 Share Posted February 27, 2014 Yeap the else statment is not needed anymore since !(position.y >= distance) equals to (position.y < distance) and for this case, there is nothing to do. Replace your code:if (position.y < distance) { position.y += 0;}else { position.y -= 0.5 * (fullHeight / 2) * (1.0 - (distance - radius * 0.1) / (radius * 0.9));}by what I suggested in my first reply (http://www.html5gamedevs.com/topic/4005-rough-terrain-smooth/?p=26450)if (position.y >= distance) { position.y -= fullHeight / 4 * (10/9 - distance / (radius * 0.9)); // 0.5 * (fullHeight / 2) * (1.0 - (distance - radius * 0.1) / (radius * 0.9))} Quote Link to comment Share on other sites More sharing options...
Dad72 Posted February 27, 2014 Author Share Posted February 27, 2014 I quickly test. All the solutions works well but the solution 5 is i find the better. if (position.y >= distance) { position.y -= (fullHeight / 4) * (1.0 + (1/9 - distance / (radius * 0.9)));}Thank you Gwenael Quote Link to comment Share on other sites More sharing options...
gwenael Posted February 27, 2014 Share Posted February 27, 2014 You're welcome.It's up to you. The last suggestion only avoids an extra addition, it's not really what will speed up your application Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.