2 registered members (AndrewAMD, Ayumi),
1,405
guests, and 4
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
terrain deformation with a cursor
#447483
12/15/14 21:55
12/15/14 21:55
|
Joined: Dec 2010
Posts: 100
Dega
OP
Member
|
OP
Member
Joined: Dec 2010
Posts: 100
|
Howdy! I am trying to make a red dot move along the surface of this terrain while it's position is controlled by the mouse cursor. The player is in first person mode controlled by WASD keys but NOT the mouse. It's been a while since I used this engine and would appreciate some help. I am very glad to be back though! Is there maybe a template anyone has for this? So far here is what I got.(This is all in a while loop):
VECTOR mouse_trace;//vector that will glide along terrain's surface moved by mouse
c_trace();//what to do here?
draw_point3d(mouse_trace,COLOR_RED,100,3);//draw the vector to be drawn along trerrain surface
if (mouse_left && HIT_TARGET && you && ent_type(you) == 4) // click onto terrain
{
var vertex_num = ent_nextvertex(you,hit.x);
CONTACT* c = ent_getvertex(you,NULL,vertex_num);
c.z += 3; // increase the vertex height
c.v = NULL; // c.x,y,z was changed, instead of c.v
ent_setvertex(you,c,vertex_num); // update the mesh
wait(-0.5); // reload
}
boolean my.awesomeness = so true;
|
|
|
Re: terrain deformation with a cursor
[Re: Dega]
#447490
12/16/14 09:18
12/16/14 09:18
|
Joined: Mar 2011
Posts: 3,150 Budapest
sivan
Expert
|
Expert
Joined: Mar 2011
Posts: 3,150
Budapest
|
a little snippet, just call it where you put the c-trace (and instead of the mouse_trace vector you can read simply the hit.x vector what you should put after the if statements):
// get mouse position on terrain surface
void Camera_Mouse3D1()
{
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,15000) ); // should be a big value
vec_for_screen (pos2, camera);
c_trace (pos1.x, pos2.x, IGNORE_ME | IGNORE_CONTENT | IGNORE_SPRITES | IGNORE_PASSABLE | IGNORE_MODELS | IGNORE_MAPS | IGNORE_FLAG2);
// if there is a HIT_TARGET event, now "target" and "hit.x" hold the coordinates of the hit point
// ignoring tile sprites, models, map-entities and other passable entities including passable terrains (water)
}
moreover I would use a separate if for the ent_type, because >as I know< in lite-c all the AND-ed comparisons are checked, unlike in C/C++.
|
|
|
Re: terrain deformation with a cursor
[Re: sivan]
#447497
12/16/14 16:35
12/16/14 16:35
|
Joined: Dec 2010
Posts: 100
Dega
OP
Member
|
OP
Member
Joined: Dec 2010
Posts: 100
|
Just what I wanted. Although I am lowering the value because I don't want the player editing the terrain from far away but thanks. I appreciate those skills and effort. Much thanks friend!
boolean my.awesomeness = so true;
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|