Hard Light Productions Forums

Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: Joey_21 on March 07, 2003, 04:21:40 pm

Title: Algorithm I find useful when FREDing...
Post by: Joey_21 on March 07, 2003, 04:21:40 pm
Let's suppose I placed a ship (a Deimos) at (8.1, -100, 4016) in FRED and a waypoint for it to travel to at (-9969, -766, 819) (to keep the mission from looking flat, these points make a nice 3rd dimensional mission). Then let's say I wanted to relieve the player's wing at 7000 meters from the first point on the way toward the second point with another waypoint set at that exact distance from the start. I don't have really good judgement when it comes to placing points like that so I found an algorithm and programmed it for C++. Do you SCP guys think you can put this feature under some menu in FRED2 for these kinds of calculations?

I would do it... but I haven't gotten that far in my programming course to be capable of doing something like that. ;)

What do you guys think? Good? Bad?

Code: [Select]

#include
#include
#include

void main()
{
// declaration of variables
double x, x2, y, y2, z, z2, nd, t;

cout << setprecision(10);

// get coodinates and new distance from user
cout << "Enter x1: ";
cin >> x;
cout << "Enter x2: ";
cin >> x2;
cout << "Enter y1: ";
cin >> y;
cout << "Enter y2: ";
cin >> y2;
cout << "Enter z1: ";
cin >> z;
cout << "Enter z2: ";
cin >> z2;
cout << "Enter a new distance: ";
cin >> nd;

// subtract x's, y's, and z's like in the distance formula
x2 = x2-x;
y2 = y2-y;
z2 = z2-z;

// get ratio for new point
t = sqrt((nd*nd)/(x2*x2 + y2*y2 + z2*z2));

// calculate new x, y, and z
x += (x2*t);
y += (y2*t);
z += (z2*t);

// give user new point
cout << "New point:\n" << x << ", " << y << ", " << z << "\n";

} // end main()
Title: Algorithm I find useful when FREDing...
Post by: Goober5000 on March 07, 2003, 04:28:23 pm
Okay, can you explain that again? :lol: That's great that you have a program to help with FRED, but I'm not exactly sure what it does. :)
Title: Algorithm I find useful when FREDing...
Post by: Joey_21 on March 07, 2003, 04:31:55 pm
Heh... ok...

go into FRED2 and place a Deimos at (8.1, -100, 4016). Place a waypoint at (-9969, -766, 819). Give the Deimos orders to travel to the waypoint. Suppose you wanted to relieve alpha wing 7000 meters from where the Deimos started. (-9969, -766, 819) is much farther than 7000 meters. Placing a waypoint at the point which this algorithm gives us will allow us to trigger an event to say something like "alpha wing is relieved, return to base" etc. etc.
Title: Algorithm I find useful when FREDing...
Post by: IceFire on March 07, 2003, 07:47:57 pm
What about doing a distance to waypoint check that is already present?  Am I missing something?
Title: Algorithm I find useful when FREDing...
Post by: diamondgeezer on March 07, 2003, 08:26:29 pm
So... you give the equation two points and a distance, and it works out a location at the given distance between the two points? Right?

If I have this right, then... I see no useful purpose, to be honest. We already have distance operators and guess work, which have always worked for me :)
Title: Algorithm I find useful when FREDing...
Post by: Goober5000 on March 07, 2003, 09:47:37 pm
Well, no, this has its uses.  There could be a button that automatically puts a waypoint at X distance from a ship, facing in the ship's direction.  You can't do this easily if the ship isn't perfectly aligned on one of the axes.

Another good function could be to position a waypoint at the location that the ship will be in X seconds, according to the speed specified in ships.tbl.
Title: Algorithm I find useful when FREDing...
Post by: Joey_21 on March 07, 2003, 11:53:40 pm
Quote
Originally posted by Goober5000
There could be a button that automatically puts a waypoint at X distance from a ship, facing in the ship's direction.  You can't do this easily if the ship isn't perfectly aligned on one of the axes.


:nod: Hence my post.
Title: Algorithm I find useful when FREDing...
Post by: ZylonBane on March 08, 2003, 12:23:35 am
Quote
Originally posted by Goober5000
Another good function could be to position a waypoint at the location that the ship will be in X seconds, according to the speed specified in ships.tbl.
Good for what?
Title: Algorithm I find useful when FREDing...
Post by: Bobboau on March 08, 2003, 12:26:22 am
for putting a point or something x meters in front of a ship, though we do have a function that does this already
Title: Algorithm I find useful when FREDing...
Post by: Goober5000 on March 08, 2003, 12:52:17 am
Quote
Originally posted by ZylonBane
Good for what?


:rolleyes: Suppose we want two ships to rendezvous with each other.  There are a few missions I've thought of where this could be helpful.

Quote
Originally posted by Bobboau
for putting a point or something x meters in front of a ship, though we do have a function that does this already


We do?  In FRED?  What is it?
Title: Algorithm I find useful when FREDing...
Post by: Bobboau on March 08, 2003, 01:41:02 am
I didn't mean in fred i meant in the code base it's called (I think, something like) vm_vec_scale_add, it's used a lot
Title: Algorithm I find useful when FREDing...
Post by: Goober5000 on March 08, 2003, 01:44:32 am
Oh, right.  But putting it in FRED would be A-1 SUPAR. :nod:
Title: Algorithm I find useful when FREDing...
Post by: kasperl on March 08, 2003, 10:11:55 am
ok, stupid, n00bish ideae here:

what about a macro like thingie for FRED, based on some easy programming languish, wich doesn't nead compiling. so basicly, FRED runs something from a ASCII file, containing the nesecary mathemetical operations and commands for placing ships. this should make things lot's easier for FREDders who have problems like this.

however, this is probably some stupid and n00bish ideae, also since i don't have any FRED experience at all.
Title: Algorithm I find useful when FREDing...
Post by: ZylonBane on March 09, 2003, 10:45:26 am
FS2 mission files are plain ASCII text. Probably be simpler to write a program to act directly on those.
Title: Algorithm I find useful when FREDing...
Post by: diamondgeezer on March 09, 2003, 12:34:15 pm
Hands up if you write missions in Wordpad instead of FREDII ;7
Title: Algorithm I find useful when FREDing...
Post by: karajorma on March 09, 2003, 12:35:20 pm
Quote
Originally posted by diamondgeezer
Hands up if you write missions in Wordpad instead of FREDII ;7


Suddenly all the posts with FRED problems become clear :p
Title: Algorithm I find useful when FREDing...
Post by: diamondgeezer on March 09, 2003, 12:41:49 pm
:nervous:

*runs*
Title: Algorithm I find useful when FREDing...
Post by: kasperl on March 09, 2003, 01:47:29 pm
Quote
Originally posted by ZylonBane
FS2 mission files are plain ASCII text. Probably be simpler to write a program to act directly on those.


perhaps it is, but it would be harder to use alongside FRED. it's just an idea tough, and i haven't got a clue how easy it would be to implement, but if it can be made. Things might get easier, since FREDders wouldn't need to do many used operations over and over again, they'd just use a macro, and get on with their mission. but since i don't use FRED nor have any programming experience aside QuickBasic and opening the Delphi editor, i geuss i'm just talking nosense here.