|
2 registered members (Grant, AndrewAMD),
911
guests, and 9
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Need example and better help on terrainforming
#339020
08/23/10 21:17
08/23/10 21:17
|
Joined: Mar 2008
Posts: 2,247 Baden Württemberg, Germany
Espér
OP
Expert
|
OP
Expert
Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
|
hi there..
I´m working at a Map Editor, wich uses a terrain as base model. Now i want to make Planing, Digging or raising tools.
But i´ve a big problem getting the vertexes around the cursor (by a given range), and change their position...
Has someone a good example or manual (or something else) for me?
Last edited by Espér; 08/23/10 21:43.
|
|
|
Re: Need example and better help on terrainforming
[Re: Widi]
#339024
08/23/10 21:41
08/23/10 21:41
|
Joined: Mar 2008
Posts: 2,247 Baden Württemberg, Germany
Espér
OP
Expert
|
OP
Expert
Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
|
not really.. it shows me that it works.. but not HOW it works...
I need this for a real complex thing of editor, wich lets vertices stay where they are, when a model is in the way. And only for a raster (not circled range.. i need it square ranged).. Means i need to code it by myself..
So looking your demo or copy things out of it (didn´t really know WHAT to copy).. is not helping me ^^
Last edited by Espér; 08/23/10 21:45.
|
|
|
Re: Need example and better help on terrainforming
[Re: Espér]
#339027
08/23/10 22:00
08/23/10 22:00
|
Joined: Aug 2007
Posts: 1,922 Schweiz
Widi
Serious User
|
Serious User
Joined: Aug 2007
Posts: 1,922
Schweiz
|
I try to explain it (sorry for my english): Declare a var (here: var range) First make a trace from the mouse in the level. If the trace hits a terrain, then you have the middle position. Now you have to check every vertex of the terrain if x/y smaller or bigger the range:
if (vertex.x > hitpoint.x - range && vertex.x < hitpoint.x + range && vertex.y > hitpoint.y - range && vertex.y < hitpoint.y + range)
so you become a square around the given hitpoint. Now you can move all vertices in the if() loop by ent_getvertex and ent_setvertex.
Last edited by Widi; 08/23/10 22:02.
|
|
|
Re: Need example and better help on terrainforming
[Re: Espér]
#339028
08/23/10 22:01
08/23/10 22:01
|
Joined: Oct 2007
Posts: 5,209 İstanbul, Turkey
Quad
Senior Expert
|
Senior Expert
Joined: Oct 2007
Posts: 5,209
İstanbul, Turkey
|
tips:
terrain vertices are in a certain order, you can get closest vertex number to a c_trace hit (hit.vertex), then by adding numbers you can get the number of the vertices around that vertex. +1 is next vertex and -1 is previous, and depending on number your terrain vertices in x and y direction. you can get that number with ent_status in modes 2 and 3.
after you get find the vertices you need, you only need to trace up from each of them to see if there is something sitting on them before trying to raise them.(ent_setvertex)
Last edited by Quadraxas; 08/23/10 22:02.
3333333333
|
|
|
Re: Need example and better help on terrainforming
[Re: Espér]
#339031
08/23/10 22:05
08/23/10 22:05
|
Joined: Oct 2007
Posts: 5,209 İstanbul, Turkey
Quad
Senior Expert
|
Senior Expert
Joined: Oct 2007
Posts: 5,209
İstanbul, Turkey
|
move them all in same frame using ent_setvertex/ent_getvertex in a for loop.
3333333333
|
|
|
Re: Need example and better help on terrainforming
[Re: Espér]
#339035
08/23/10 23:05
08/23/10 23:05
|
Joined: Mar 2008
Posts: 2,247 Baden Württemberg, Germany
Espér
OP
Expert
|
OP
Expert
Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
|
ok.. i tried it (hope) like Quadraxas said...
void change_terrain()
{
traceposition.x = mouse_pos.x;
traceposition.y = mouse_pos.y;
traceposition.z = mouse_range;
vec_for_screen (traceposition,camera);
c_trace(camera.x,traceposition,IGNORE_ME | IGNORE_PASSABLE);
vec_set(traceziel.x, target.x);
if(you == ground && mouse_left == 1)
{
hitting = 1;
var vertice = ent_status(ground, 1); //Gesamtanzahl
var vert_nr = vertice;
var vertice_x = ent_status(ground, 2); //Anzahl in X_Richtung
var vertice_y = ent_status(ground, 3); //Anzahl in Y_Richtung
CONTACT* vertcontact;
VECTOR* vert_pos = nullvector;
for(;vert_nr > 0;vert_nr--)
{
vec_for_vertex(vert_pos, ground, vert_nr);
if(vec_dist(vert_pos.x, traceziel.x) <= range*32)
{
error("kleiner");
ent_getvertex(ground, vertcontact, vert_nr);
vertcontact.z += 5.0*time_step;
ent_setvertex(ground, vertcontact, vert_nr);
}
}
}
else
{
hitting = 0;
}
}
But nothing happens. the variable "hitting" is set to 1.. means it hits the ground... i always get a "Crash in CHANGE_TERRAIN SYS"
Last edited by Espér; 08/23/10 23:07.
|
|
|
|