raise vertices of terrain

Posted By: gri

raise vertices of terrain - 02/13/14 12:36

hi,

c_trace and ent_setvertex() works nice on a single terrain, created at nullvector position.

But as I ent_create() a terrain 100 quants ahead in y direction, only the very first vertex got raised correctly and after that between the traced vertices and the raised ones exists an offset in y direction.

So I convertet the world/entity coords with vec_for_ent(hit.x,you); and have now the effect that the very first hidden vertex is wrong, but all the following are correct now grin
complete opposite then before.

Without big code - does someone know this behaivior ?
Posted By: Superku

Re: raise vertices of terrain - 02/13/14 12:42

Can you please try to explain the problem again, if necessary in German (sorry non-German-speakers)?

Where is the problem, c_trace not hitting raised vertices or ent_setvertex not working correctly? If the latter is the issue remember there are two ways to do this, either with v.z or v.v.z (or whatever the DirectX vertex struct is called there).
Posted By: gri

Re: raise vertices of terrain - 02/13/14 13:13

I trace by mousemovement over a whole terrain.

tracing works correct - it hit the traced terrain... I set an entity at this position.

But the hit vertexnumber is wrong.
Code:
var vertex_num = ent_nextvertex(you,hit.x);



When using

Code:
vec_for_ent(hit.x,you);        
var vertex_num = ent_nextvertex(you,hit.x);


the vertexnumber is correct - except the very first hit vertex.

As I said, the terrain is created 100 quants ahead.
Posted By: Superku

Re: raise vertices of terrain - 02/13/14 15:16

I assume hit.vertex does not work with chunked terrain?
Have you tried calling c_updatehull (before first trace)?
Posted By: gri

Re: raise vertices of terrain - 02/13/14 18:32


Terrain is a single one and unchuncked.
But its createt not at nullposition, its 100 quants ahead
Code:
ENTITY* e = ent_create("terrain.hmp", vector(100,0,0),NULL);



now this code make the c_trace

Code:
if(mouse_right)
  {	   	
  
  	if(c_trace(from.x,to.x,IGNORE_PASSABLE|SCAN_TEXTURE)>0) // trace from camera into the world
  	{
  	  if(HIT_TARGET)	
  		{
  		  
  		 if((hitx!=hit.x)||(hity!=hit.y))  // hitposition changed since the last frame? 
  		   {
   		 // visualize the hitpoint
   		 if(arrow!=NULL){arrow.lifespan=0;}   		 
   		 BMAP* bm = bmap_create("down.bmp");
   		 arrow = ent_decal(you,bm,5,0);  		 
   		 vec_set(arrow.skill_x,normal.x);
   		 
   		 // backup the actual hitposition
   		 hitx=hit.x;
  		 hity=hit.y; 
  		    
  		 // raise the vertex
  		 vec_for_ent(hit.x,you);  // change world - entity coords    
                 var vertex_num = ent_nextvertex(you,hit.x);
  		 CONTACT* c = ent_getvertex(you,NULL,vertex_num);
                 c.v.y += 1;  // increase the vertex height
                 ent_setvertex(you,c,vertex_num);    // update the mesh	
  			
        }
      }  		
   }  	
  }



this makes the very first shot hit the terrain at a certain point BUT the raised vertex is an other!

all the following shots raises the correct vertices and works like it should.



if I comment out the line
Code:
vec_for_ent(hit.x,you);  // change world - entity coords



so I get the complete opposite behaivior.

The very first shot raises the correct vertex but all following traces raises diffrent vertices with an offset distance.
Posted By: Superku

Re: raise vertices of terrain - 02/13/14 18:45

Terrain is always chunked in A8 and thus normally in world coordinates if I'm not mistaken.
Again, three things:
Checked hit.vertex?
Tried c.z += 1; instead?
(c_updatehull for whatever reason?)

Additionally:
Have you checked the vertex number (displayed)?
You could try to calculate the vertex number manually, I think, should the previous be the problem.
EDIT: You could try to offset the hit position by the negative terrain creation position (terrain.xyz may always be 000, not sure but take care) and grab the closest vertex after that.

You can post a short and simple test project if you like to.
Posted By: gri

Re: raise vertices of terrain - 02/13/14 19:39

Quote:
You could try to offset the hit position by the negative terrain creation position (terrain.xyz may always be 000, not sure but take care) and grab the closest vertex after that.


yes sure.

I think the
Code:
vec_for_ent(hit.x,you);  // change world - entity coords

should handle this shiftet position of the terrain.

And it works with that like it should but not at the first shot.

Something must happen after the first fail contact.
c.z leads to the same result.

its
Code:
ent_nextvertex(you,hit.x);

that delivers the false vertex number at first shot.

I reduced the code and load an example up... one moment
Posted By: gri

Re: raise vertices of terrain - 02/13/14 19:42


here is the test

http://www.griller.org/stuff/deform_terrain.zip
Posted By: Superku

Re: raise vertices of terrain - 02/13/14 20:35

Originally Posted By: Superku
Have you tried calling c_updatehull (before first trace)?
...
(c_updatehull for whatever reason?)

Obviously you didn't try it...

EDIT: And hit.vertex alone works for me, too, no ent_nextvertex, no c_updatehull. I don't understand why you wouldn't test this...
Posted By: gri

Re: raise vertices of terrain - 02/14/14 07:14


hey Superku,

youre right ! It works when I call c_updatehull after creating.

Code:
ENTITY* e = ent_create("terrain.hmp", vector(100,0,0),NULL);
        set(e,POLYGON);
        c_updatehull(e,0);



I thought on object creation the engine does an intern c_updatehull.

Seems not to be. Wow! it works now.

Thank you Superku for your time and the golden hint.
Posted By: sivan

Re: raise vertices of terrain - 02/14/14 08:18

I know why earlier I got rendering and collision errors when placed a terrain over/under 0. thanks.
© 2024 lite-C Forums