Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, Ayumi), 1,405 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
terrain vertices square #449211
03/08/15 20:59
03/08/15 20:59
Joined: Dec 2010
Posts: 100
D
Dega Offline OP
Member
Dega  Offline OP
Member
D

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:
Code:
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 Offline
Serious User
Reconnoiter  Offline
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 blush

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
D
Dega Offline OP
Member
Dega  Offline OP
Member
D

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)

Code:
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
W
Wjbender Offline
User
Wjbender  Offline
User
W

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: Wjbender] #449226
03/09/15 10:18
03/09/15 10:18
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
You only need to calculate or know the distance between 2 vertices (in each dimension). Then you don't have to interact with any more vertex or terrain related stuff because of the regular terrain structure. You can do something as follows instead:

VECTOR terrain_min,terrain_max,mouse_terrain_pos;
var terrain_cell_size_x,terrain_cell_size_y,mouse_cell_x,mouse_cell_y;

fill terrain_min and terrain_max appropriately,
calculate terrain_cell_size_x/y via ent_getvertex or something like terrain_cell_size_x = (terrain_max.x-terrain_min.x)/(number of vertices in dimension x - 1);

then now calculate mouse_terrain_pos on the terrain (via c_trace or a line equation) and get the cell ids as follows:
mouse_cell_x = floor((mouse_terrain_pos.x-terrain_min.x)/terrain_cell_size_x); // same for y

You can now use mouse_cell_x/y to draw a quad on the terrain (or place a quad sprite there) and perform further calculations:
quad.x = (mouse_cell_x+0.5)*terrain_cell_size_x; // same for y. 0.5 because I assume quad is a sprite


"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] #449234
03/09/15 17:07
03/09/15 17:07
Joined: Dec 2010
Posts: 100
D
Dega Offline OP
Member
Dega  Offline OP
Member
D

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 Offline
Senior Expert
Superku  Offline
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
D
Dega Offline OP
Member
Dega  Offline OP
Member
D

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?

Code:
///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: Dega] #449311
03/13/15 11:37
03/13/15 11:37
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
you need to call c_updatehull to perform a collision update hull on the terrain


Visit my site: www.masterq32.de
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 Offline
Expert
sivan  Offline
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;


Free world editor for 3D Gamestudio: MapBuilder Editor

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