Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, dr_panther), 791 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Deforming terrain problem #417588
02/14/13 09:39
02/14/13 09:39
Joined: Feb 2009
Posts: 11
R
Racebert69 Offline OP
Newbie
Racebert69  Offline OP
Newbie
R

Joined: Feb 2009
Posts: 11
Hello folks,

I still have a problem with deforming terrain. After a long long time I started with gst again and my skills decreased massivly.

Here is the code (not mine):

void Terrain_Deform()
{
if (terrain_entity==NULL) {return;}

terrain_entity.emask |= DYNAMIC;
wait(1);

var closest_vertex = ent_nextvertex(terrain_entity , ActiveTileSquare.x);

CONTACT* c = ent_getvertex(terrain_entity,NULL,closest_vertex);
c.v.y += (float)32;
ent_setvertex(terrain_entity , c , closest_vertex);
wait(3);
c.vertex += (float)1; // nächster Vertex in x Richtung
ent_setvertex(terrain_entity , c , closest_vertex);
wait(3);
c.vertex += (float)32; // nächster Vertex in z Richtung
ent_setvertex(terrain_entity , c , closest_vertex);
wait(3);
c.vertex += (float)1; // nächster Vertex in x Richtung
ent_setvertex(terrain_entity , c , closest_vertex);
wait(3);
terrain_entity.emask &= ~DYNAMIC;
}

What I like to do is to raise a square on a terrain:

raise 4 vertexes in a square
(Sorry, can not upload pics)

What I got:

all 4 vertexes are at the same point
(Sorry, can not upload pics)

Some ideas?
Thanks in advance!

regards, Bert

Re: Deforming terrain problem [Re: Racebert69] #417604
02/14/13 12:37
02/14/13 12:37
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline
User
Carlos3DGS  Offline
User

Joined: Oct 2008
Posts: 513
The code already gets you the closest vertex. For the three left the calculations would be:
vert2=closest+1;
vert3=closest-verts_per_row;
vert4=closest-verts_per_row+1;

there are two special cases where this would not work so you need two "if" before the above calculations. one "if" in case you are in the first row of verts, and another "if" in case you are in the last column of verts.

if(closest<verts_per_row)
{
closest+=verts_per_row;
}

if(closest%verts_per_row==0)
{
closest--;
}

after that manipulate the verts as you do with closest_vert, but adding three extra lines to do the sam manipulation for vert2,vert3,vert4


"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Re: Deforming terrain problem [Re: Carlos3DGS] #417615
02/14/13 14:02
02/14/13 14:02
Joined: Feb 2009
Posts: 11
R
Racebert69 Offline OP
Newbie
Racebert69  Offline OP
Newbie
R

Joined: Feb 2009
Posts: 11
Thanks Carlos but it does not work.
all raised vertexes are at the same location (x,y,z). looks like a pyramid.

Here is the new code (Maybe I did not understand what you mean - sorry for my bad english):

void Terrain_Deform()
{
if (terrain_entity==NULL) {return;}

terrain_entity.emask |= DYNAMIC;
wait(1);

var closest_vertex = ent_nextvertex(terrain_entity , ActiveTileSquare.x);

CONTACT* c = ent_getvertex(terrain_entity,NULL,closest_vertex);
c.v.y += (float)32;

var verts_per_row = 25;
var vert2 = closest_vertex + 1;
var vert3 = closest_vertex - verts_per_row; // 500 vertexes per row!!
var vert4 = closest_vertex - (verts_per_row+1);
if(closest_vertex<verts_per_row)
{
closest_vertex+=verts_per_row;
}

if(closest_vertex%verts_per_row==0)
{
closest_vertex--;
}

// printf("Vertex1: %1f", (double)closest_vertex);
// printf("Vertex2: %1f", (double)vert2);
// printf("Vertex3: %1f", (double)vert3);
// printf("Vertex4: %1f", (double)vert4);


// c.y +=10;
ent_setvertex(terrain_entity , c , vert2);
wait(3);
// printf("Vertex: %3f", (double)closest_vertex);
// CONTACT* c = ent_getvertex(terrain_entity,NULL,(closest_vertex+32));

// closest_vertex += 25;
// printf("Vertex: %3f", (double)closest_vertex);


// c.vertex += (float)1; // nächster Vertex in x Richtung
// c.v.x -= (float)25;
// c.nx -= (float)25;
ent_setvertex(terrain_entity , c , vert3);
wait(3);


// c.vertex += (float)32; // nächster Vertex in z Richtung
// ent_setvertex(terrain_entity , c , closest_vertex);
wait(3);


// c.vertex += (float)1; // nächster Vertex in x Richtung
ent_setvertex(terrain_entity , c , vert4);
wait(3);
terrain_entity.emask &= ~DYNAMIC;
}

SOLVED: Re: Deforming terrain problem [Re: Racebert69] #417624
02/14/13 17:11
02/14/13 17:11
Joined: Feb 2009
Posts: 11
R
Racebert69 Offline OP
Newbie
Racebert69  Offline OP
Newbie
R

Joined: Feb 2009
Posts: 11
Ok, thanks Carlos I solved the problem

Code:

void Terrain_Deform()
{
if (terrain_entity==NULL) {return;}

terrain_entity.emask |= DYNAMIC;
wait(1);

var closest_vertex = ent_nextvertex(terrain_entity , ActiveTileSquare.x);

CONTACT* c = ent_getvertex(terrain_entity,NULL,closest_vertex);
c.v.y += (float)32;

var verts_per_row = 500;
var vert2 = closest_vertex + 1;
var vert3 = closest_vertex - verts_per_row; // 500 vertexes per row!!
var vert4 = closest_vertex - (verts_per_row-1);
if(closest_vertex<verts_per_row)
{
closest_vertex+=verts_per_row;
}

if(closest_vertex%verts_per_row==0)
{
closest_vertex--;
}

ent_setvertex(terrain_entity , c , closest_vertex);
wait(1);
CONTACT* c = ent_getvertex(terrain_entity,NULL,vert2);
c.v.y += (float)32;

ent_setvertex(terrain_entity , c , vert2);
wait(1);

CONTACT* c = ent_getvertex(terrain_entity,NULL,vert3);
c.v.y += (float)32;
ent_setvertex(terrain_entity , c , vert3);
wait(1);

CONTACT* c = ent_getvertex(terrain_entity,NULL,vert4);
c.v.y += (float)32;
ent_setvertex(terrain_entity , c , vert4);
wait(1);
terrain_entity.emask &= ~DYNAMIC;
}

Re: SOLVED: Re: Deforming terrain problem [Re: Racebert69] #417681
02/15/13 13:52
02/15/13 13:52
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline
User
Carlos3DGS  Offline
User

Joined: Oct 2008
Posts: 513
I found a problem in one of the if conditions that I gave you, it should be <= not just <
Also,your "if" have to go before the vert2,3,4 calculations like this:

Code:
var verts_per_row = 500;

if(closest_vertex<=verts_per_row)
{
   closest_vertex+=verts_per_row;
}

if(closest_vertex%verts_per_row==0)
{
   closest_vertex--;
}

var vert2 = closest_vertex + 1;
var vert3 = closest_vertex - verts_per_row; // 500 vertexes per row!!
var vert4 = closest_vertex - (verts_per_row-1);



"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Re: SOLVED: Re: Deforming terrain problem [Re: Carlos3DGS] #417690
02/15/13 15:07
02/15/13 15:07
Joined: Feb 2009
Posts: 11
R
Racebert69 Offline OP
Newbie
Racebert69  Offline OP
Newbie
R

Joined: Feb 2009
Posts: 11
Thanks alot, but I have to rewrite the edge-check because I will use more terrain tiles. So I have to check the Terrain skill and if the chosen Vertex an edge vertex but your commend helped alot for checking.

Thanks Carlos

Re: SOLVED: Re: Deforming terrain problem [Re: Racebert69] #417721
02/16/13 12:51
02/16/13 12:51
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline
User
Carlos3DGS  Offline
User

Joined: Oct 2008
Posts: 513
You will need 4 different pointers for terrains then (worst case scenario in the "top right" corner you would end up with all of the verts on different terrains).

Also you have to take into account that in this "worst case" you would actually have to manipulate 9 vertices if closest_vert is in the top right corner of a terrain!

-one vert for the terrain with current_vert
-two verts in the terrain above it (the overlapping corner vert and the vert above it)
-two verts in the terrain to the right (the overlapping vert and the vert to the right of it)
-four verts in the diagonal terrain! (the one in the bottom left corner overlapping all of the terrains, the vert above that and the one to the right becouse it overlaps for the two other terrains, and a fourth vert in diagonal that is exclusive for this last terrain)

For this I would first use 3 "if" to determine the possible cases, and afterwards do the actual vert manipulation inside either a 4 way switch/case instuction, or a chain of 4 if/else branches


"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Re: SOLVED: Re: Deforming terrain problem [Re: Racebert69] #417723
02/16/13 13:05
02/16/13 13:05
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline
User
Carlos3DGS  Offline
User

Joined: Oct 2008
Posts: 513
It would look like this:

Code:
//FIRST DETERMINE THE SITUATION
int situation=1;
if(closest_vertex<=verts_per_row)
{
   situation=2;
}

if(closest_vertex%verts_per_row==0)
{
   situation=3;
}

if(closest_vertex<=verts_per_row && closest_vertex%verts_per_row==0)
{
   situation=4;
}

//AFTER MANIPULATE THE VERTS DEPENDING ON THE SITUATION
if(situation==1)
{
   //manipulate four verts on current terrain as normal
}
else if(situation==2)
{
   //manipulate 2 verts on current terrain
   //manipulate 4 verts on terrain above
}
else if(situation==3)
{
   //manipulate 2 verts on current terrain
   //manipulate 4 verts on terrain to the right
}
else
{
   //manipulate one vert on current terrain
   //manipulate two verts on terrain above
   //manipulate two verts on terrain to the right
   //manipulate four verts on diagonal terrain
}







EDIT:
I just noticed there are 3 more cases I didn't account for!
-The inverse of case2
-The inverse of case3
-The inverse of case4
*These three inverted variations can be easily accounted for with an extra "if" inside the manipulation portion of the code, at the beginning of the three normal 2,3,4 situation "if"'s.

All of this will be much easier for you to program if you create your terrain pointers in an array, and use it's skills to reference their position in the array like this:
Code:
ENTITY* terrain_list[x][y];

void create_terrains()
{
   int x,y;
   for(x=0,x<terrains_count_horizontal;x++)
   {
      for(y=0,y<terrains_count_vertical;y++)
      {
         terrain_list[x][y]=ent_create("my_terrain.mdl",vector(x*terrain_width,y*terrain_depth,0),NULL);
         //to find the relative position later
         terrain_list[x][y].skill1=x;
         terrain_list[x][y].skill2=y;
      }
   }
}



NOTE:
The three extra "inverse cases" and array of terrain pointers will only be necessary if you have more than 4 terrains.

If you need further help on this I would need an example of how you calculate closest_vert and terrain_entity in your code to build the new code around that (and possibly modify how you calculate those if needed). It would also help to know if they are global, or if not, how you pass them in your function call. Also if you are using any defines or not, to make the new code more flexible.

Last edited by Carlos3DGS; 02/16/13 14:19. Reason: special cases and pointer reference

"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Re: SOLVED: Re: Deforming terrain problem [Re: Carlos3DGS] #417879
02/19/13 01:09
02/19/13 01:09
Joined: Feb 2009
Posts: 11
R
Racebert69 Offline OP
Newbie
Racebert69  Offline OP
Newbie
R

Joined: Feb 2009
Posts: 11
Hi Carlos,

I am still working on that problem but it is allmost solved. Hopefully I will solve it without further problems.
On the edges (row and column) it still working fine but I have to write the code for the points where 4 tiles have to be moved.
Unfortunatly I have a problem with my teeth. It is a inflammation under one tooth and it has to be removed. So will finish the code soon but first I have to go to the dentist and also work on my job.
I will tell you if my code is finished and working well.

See you soon on the forum und thank you for your help

best wishes, Bert

PS: It is very cool that you give me so much support!!!! I will post my project soon when I started to include invinite terrain with terrain-tiles, multiplayer and partial load of terrain-tiles (8 views) to save memory. I started to modify the include-file "terraindeform.c" with many new features. Hopefully the foru will like it!

Last edited by Racebert69; 02/19/13 01:31.

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1