1 registered members (AbrahamR),
717
guests, and 4
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
terrain vertices square
#449211
03/08/15 20:59
03/08/15 20:59
|
Joined: Dec 2010
Posts: 100
Dega
OP
Member
|
OP
Member
Joined: Dec 2010
Posts: 100
|
I'm trying to make a square appear on my terrain. The square is moved by the mouse but is always snapped to the grid on the terrain which is basically. The corners of the square are the terrains vertices. Really would appreciate any help. Here is what I got so far and as I predicted it was completely wrong:
void player_gui(){
VECTOR target_vertice;
target_vertice.x = mouse_pos.x;
target_vertice.y = mouse_pos.y;
target_vertice.z = 200;
//CURSOR
vec_for_screen(target_vertice,camera);
draw_line3d(target_vertice,vector(0,0,100),100);
draw_line3d(target_vertice.x + 3,vector(0,0,100),100);
}
boolean my.awesomeness = so true;
|
|
|
Re: terrain vertices square
[Re: Dega]
#449213
03/08/15 21:11
03/08/15 21:11
|
Joined: Dec 2011
Posts: 1,823 Netherlands
Reconnoiter
Serious User
|
Serious User
Joined: Dec 2011
Posts: 1,823
Netherlands
|
ent_getvertex is what you are looking for I think (see manual example too); 4x c_trace (for four corners) and ent_getvertex with vertex_num -edit; maybe using c_trace and hit.vertex alone is enough to get the terrain vertex positions, don't know exactly
Last edited by Reconnoiter; 03/08/15 21:21.
|
|
|
Re: terrain vertices square
[Re: Reconnoiter]
#449218
03/09/15 00:10
03/09/15 00:10
|
Joined: Dec 2010
Posts: 100
Dega
OP
Member
|
OP
Member
Joined: Dec 2010
Posts: 100
|
Here's what I got but it doesn't work. Any advice on what to do? (Used a example as a template)
function mole_gun()
{
while (1)
{
VECTOR trace_target, camera_target;
camera_target.x = mouse_pos.x;
camera_target.y = mouse_pos.y;
camera_target.z = 200;
vec_for_screen(camera_target,camera);
vec_rotate(camera_target,camera.pan);
if (c_trace(camera, camera_target, IGNORE_PASSABLE | USE_POLYGON| SCAN_TEXTURE) > 0){\
if (mouse_left && HIT_TARGET && you && ent_type(you) == 4) // fire onto terrain
{
var vertex_num = ent_nextvertex(you,hit.x);
CONTACT* c1 = ent_getvertex(you,NULL,vertex_num);
c1.z += 10;
c1.v = NULL;
ent_setvertex(you,c1,vertex_num);
wait(-0.5);
}
}
wait(1);
}
}
boolean my.awesomeness = so true;
|
|
|
Re: terrain vertices square
[Re: Dega]
#449224
03/09/15 08:17
03/09/15 08:17
|
Joined: Mar 2012
Posts: 927 cyberspace
Wjbender
User
|
User
Joined: Mar 2012
Posts: 927
cyberspace
|
I am not very good mathematical so how I would do it :
divide terrain in to 2d chunk rectangles, divide those boxes in to 2d rectangles based on the size of each cell in the chunk ..(quad tree like)
keep that data/list in memory.
to find the rectangle to draw where the mouse is inside , first determine which chunk rectangle the mouse position is inside , then determine which of the cells inside that chunk ,contains the mouse position.
retrieve the relevant information of that cell,like position/min/max , then draw it ..
jb
Compulsive compiler
|
|
|
Re: terrain vertices square
[Re: Superku]
#449234
03/09/15 17:07
03/09/15 17:07
|
Joined: Dec 2010
Posts: 100
Dega
OP
Member
|
OP
Member
Joined: Dec 2010
Posts: 100
|
@Superku
how to set VECTORS terrain_min and terrain_max. I'm trying to figure out what you're using them for? Also I have the terrain loaded in WED so I was wondering how to figure out how to reference the terrain entity.
boolean my.awesomeness = so true;
|
|
|
Re: terrain vertices square
[Re: Dega]
#449236
03/09/15 17:36
03/09/15 17:36
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
If you only have one terrain the easiest way to address it is to use an action with a pointer:
ENTITY* my_terrain = NULL;
action act_my_terrain() { my_terrain = me; }
############
terrain_min and terrain_max are meant to be the position of the lower left and the upper right corner of the terrain respectively. I am not 100% sure but I think terrain.min_x/max_x works:
vec_set(terrain_min,my_terrain.min_x); vec_add(terrain_min,my_terrain.x); // my_terrain.x may be 0 because I think the terrain gets converted to world coordinates vec_set(terrain_max,my_terrain.max_x); vec_add(terrain_max,my_terrain.x);
If this does not work you will have to figure out a way how to set those vectors up. You can do it.
Last edited by Superku; 03/09/15 17:38.
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
Re: terrain vertices square
[Re: Superku]
#449258
03/10/15 19:42
03/10/15 19:42
|
Joined: Dec 2010
Posts: 100
Dega
OP
Member
|
OP
Member
Joined: Dec 2010
Posts: 100
|
okay so I completely redid the code. I just need to figure out if there is something that returns the vector of a vertex. Also after the terrain is deformed the player can just move through the new part of the ground as if the old ground of the terrain was still there. Any suggestions?
///Change Terrain
VECTOR pos1,pos2;
vec_set( pos1 , vector(mouse_pos.x,mouse_pos.y,0) );
vec_for_screen (pos1, camera);
vec_set(pos2 , vector(mouse_pos.x,mouse_pos.y,10000));
vec_for_screen (pos2, camera);
c_trace (pos1.x, pos2.x, IGNORE_ME | IGNORE_CONTENT | IGNORE_SPRITES | IGNORE_MAPS | IGNORE_PASSABLE | IGNORE_MODELS | IGNORE_FLAG2 | SCAN_TEXTURE);
if (HIT_TARGET && you && ent_type(you) == 4) // click onto terrain
{
var vertex_num1 = ent_nextvertex(you,hit.x);
CONTACT* c1 = ent_getvertex(you,NULL,vertex_num1);
var vertex_num2 = ent_getvertex(you,NULL,vertex_num1 + 1);
var vertex_num3 = ent_getvertex(you,NULL,vertex_num1 + 66);
var vertex_num4 = ent_getvertex(you,NULL,vertex_num2 + 66);
draw_point3d(hit.x,COLOR_RED,100,5);
if(mouse_left){
c1.z = my.z + my.min_z; // increase the vertex height
c1.v = NULL; // c.x,y,z was changed, instead of c.v
ent_setvertex(you,c1,vertex_num1); // update the mesh
my.z = c1.z - my.min_z - 1;
wait(-1); // reload
}
}
boolean my.awesomeness = so true;
|
|
|
Re: terrain vertices square
[Re: MasterQ32]
#449313
03/13/15 12:45
03/13/15 12:45
|
Joined: Mar 2011
Posts: 3,150 Budapest
sivan
Expert
|
Expert
Joined: Mar 2011
Posts: 3,150
Budapest
|
I use normally c.v instead of c to avoid that NULL line:
CONTACT* c = ent_getvertex(terrain_entity,NULL,vertexnum); c.v.y += (float)increase; // float and y, because here we need to use DirectX coordinates, ent_setvertex(terrain_entity,c,vertexnum);
updatehull is not needed as hull is updated properly from A8.40.3
I would not hardcode vertex quantity, you can use var verticesx = ent_status(terrain_entity,2)+1;
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|