|
0 registered members (),
3,176
guests, and 11
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
easy...but not for me
#164399
10/30/07 13:19
10/30/07 13:19
|
Joined: Mar 2005
Posts: 969 ch
Loopix
OP
User
|
OP
User
Joined: Mar 2005
Posts: 969
ch
|
Hello I know I'm a prick...but can somebody help me with this (it takes too long for me to translate into c-script  ) : I have a river and would like to calculate the stream-force direction according to the rivers vertices (the vertices are setup like 1,3,5,7,9...). Now when my boat is at vertex#1 position, the stream-force direction should point towards vertex#3 position...and so on. I'd be very glad for a snippet that manages this  Thanks!
|
|
|
Re: easy...but not for me
[Re: Loopix]
#164400
10/30/07 13:31
10/30/07 13:31
|
Joined: Jan 2004
Posts: 3,023 The Netherlands
Helghast
Expert
|
Expert
Joined: Jan 2004
Posts: 3,023
The Netherlands
|
ok, here's an idea...
If it indeed is all in the correct order (1-2, 3-4, 5-6, 7-8 etc etc), you could calculate the distance and rotation.
first you set a temp variable at the current vertex. then you calculate the distance from the boat to the next vertex, and check if that distance is shorter then the current one, if so, the next is the current one.
then you can use the current and next one to calculate a rotation angle. after doing that, you can also speed up / slow down the boat using the distance between these 2 vertices...
i am at work atm, cant test/write any code, but it's a general idea. I'll check later what i can do, can you upload the river model somewhere?
regards,
|
|
|
Re: easy...but not for me
[Re: Helghast]
#164401
10/30/07 13:40
10/30/07 13:40
|
Joined: Mar 2005
Posts: 969 ch
Loopix
OP
User
|
OP
User
Joined: Mar 2005
Posts: 969
ch
|
Hey thanks for your fast input...your idea sounds cool! Here's the river model
|
|
|
Re: easy...but not for me
[Re: Loopix]
#164402
10/31/07 09:22
10/31/07 09:22
|
Joined: Jan 2007
Posts: 221
Fenriswolf
Member
|
Member
Joined: Jan 2007
Posts: 221
|
Hi,
you can use c_trace to get the closest vertex to your boat. 'hitvertex' will be set to its number.
Then you could determine if the vertex number is even or uneven to get the correct vertex pair. However you only need this, if the broadness of your river varies. In this case you need to get a direction vector from one vertex pair to the following vertex pair. A 'vertex-to-vertex' direction vector could result in a inapplicable direction. You can determine if a number is even by using something like the following function:
function even(_n) { // returns 1 if _n is even, otherwise 0 return(_n % 2 == 0); }
To get the direction vector from one pair to the next pair you would have something like this:
------ // get the position of the closest vertex pair
vec_for_vertex(temp, river, closest_vertex); // get the vector of the closest vertex vec_for_vertex(temp2, river, closest_vertex - (2 * even(closest_vertex) - 1); // get the vector of the adjacent vertex
vec_add(temp, temp2); vec_scale(temp, 0.5); vec_set(pair1, temp); // pair1 = origin of the vertex pair
// get the position of the next vertex pair
vec_for_vertex(temp, river, closest_vertex + 2); // get the vector of the next vertex vec_for_vertex(temp2, river, closest_vertex - (2 * even(closest_vertex + 2) - 1); // get the vector of the adjacent vertex
vec_add(temp, temp2); vec_scale(temp, 0.5); vec_set(pair2, temp); // pair2 = origin of the vertex pair
// finally get the direction vector
vec_diff(speed_vector, pair2, pair1); ------
This is a sloppy written code and I don't know if it actually works. ;-)
|
|
|
|