Hard Light Productions Forums

Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: Shivan Hunter on November 02, 2011, 11:09:21 pm

Title: sin(x) and cos(x) SEXPs in FRED
Post by: Shivan Hunter on November 02, 2011, 11:09:21 pm
I was amazed they weren't in there already, and I think they'd be incredibly useful. It's not essential (I'm implementing a Taylor series now), but it would be nice.
Title: Re: sin(x) and cos(x) SEXPs in FRED
Post by: Nuke on November 02, 2011, 11:26:44 pm
yay! trig functions!

really just call a script eval and run math.cos(x)
Title: Re: sin(x) and cos(x) SEXPs in FRED
Post by: Black Wolf on November 02, 2011, 11:54:02 pm
What would you use them for?
Title: Re: sin(x) and cos(x) SEXPs in FRED
Post by: Cyborg17 on November 03, 2011, 10:19:32 am
You can use them to simplify calculations checking whether an object is facing another object (though there's a simpler way to do it).  IIRC, only the player has a check to see if it's pointing at something, and you can try to use trig functions to evaluate angles and stuff.

It would probably be better if you added either Sin or Cos since there are so many ways to transfer between them.  Tan (x) and one of the others would probably be more useful than having both Sin and Cos.

EDIT: clarifications.
Title: Re: sin(x) and cos(x) SEXPs in FRED
Post by: The E on November 03, 2011, 10:22:24 am
I thought we had the "facing" sexp (in the "training" category) for that.
Title: Re: sin(x) and cos(x) SEXPs in FRED
Post by: Cyborg17 on November 03, 2011, 10:24:13 am
Last time I tried it, it worked only for the player. But I wasn't thorough.  I'll test it again tonight.
Title: Re: sin(x) and cos(x) SEXPs in FRED
Post by: The E on November 03, 2011, 10:25:57 am
Ah, sorry. Yes, "facing" only checks from the player perspective. "is-facing" (found under ship status) however can be used to check arbitrary objects.
Title: Re: sin(x) and cos(x) SEXPs in FRED
Post by: Cyborg17 on November 03, 2011, 10:30:58 am
I missed it when I was looking for one then.  Scratch one possible use.  I can't think of any others unless you want to measure angles between ships, and that probably is only useful in scripting a Capital ship battle.  There's probably ways to work around it, too.
Title: Re: sin(x) and cos(x) SEXPs in FRED
Post by: Qent on November 03, 2011, 11:05:30 am
Use a SEXP to spawn a weapon pointing in a particular direction.
Title: Re: sin(x) and cos(x) SEXPs in FRED
Post by: Goober5000 on November 03, 2011, 11:10:08 am
The problem is that sexps can only work with integers.  So this would have to be either a discrete function cycling between 0, -1, and 1, or a modified function like sin(x)*1000.

EDIT:
Use a SEXP to spawn a weapon pointing in a particular direction.
You can already do this by specifying target coordinates.
Title: Re: sin(x) and cos(x) SEXPs in FRED
Post by: Qent on November 03, 2011, 11:17:00 am
Er, I worded that wrong. I meant to spawn a weapon at some position, but pointing at an arbitrary ship somewhere else. Is that already possible? But I guess you'd want inverse trig functions for that anyway.
Title: Re: sin(x) and cos(x) SEXPs in FRED
Post by: Shivan Hunter on November 03, 2011, 12:01:45 pm
really just call a script eval and run math.cos(x)

ಠ_ಠ

The problem is that sexps can only work with integers.  So this would have to be either a discrete function cycling between 0, -1, and 1, or a modified function like sin(x)*1000.

:(

Oh well. What I was working on didn't turn out all that well anyway, in part for this exact reason.
Title: Re: sin(x) and cos(x) SEXPs in FRED
Post by: Cyborg17 on November 03, 2011, 04:04:22 pm
I've been able to hack decimals before.  If you want to represent .389 for example just use:

Code: [Select]
/
389
1000

I haven't tried it for every sexp, but it seemed to work with no problem when I wanted it to place cameras for cut scenes.
Title: Re: sin(x) and cos(x) SEXPs in FRED
Post by: Nuke on November 03, 2011, 04:36:16 pm
really just call a script eval and run math.cos(x)

ಠ_ಠ

dont give me that i cant script crap its only one line of code!
Title: Re: sin(x) and cos(x) SEXPs in FRED
Post by: Goober5000 on November 03, 2011, 10:58:43 pm
Er, I worded that wrong. I meant to spawn a weapon at some position, but pointing at an arbitrary ship somewhere else. Is that already possible? But I guess you'd want inverse trig functions for that anyway.
Definitely possible -- and you can even point it at nothing in particular.  For one example, take a look at the second version of DEM: Interlude.


I've been able to hack decimals before.  If you want to represent .389 for example just use:

Code: [Select]
/
389
1000

I haven't tried it for every sexp, but it seemed to work with no problem when I wanted it to place cameras for cut scenes.
Do enlighten us with an example mission.
Title: Re: sin(x) and cos(x) SEXPs in FRED
Post by: Cyborg17 on November 03, 2011, 11:33:49 pm
Ok.  It's really rather simple.....

 I was making an example mission, and then I discovered that it's not good to put parentheses in Event names, especially when they are referenced by is-event-true-delay.  Let me just correct a few mistakes and I'll have it up.
Title: Re: sin(x) and cos(x) SEXPs in FRED
Post by: Shivan Hunter on November 03, 2011, 11:42:06 pm
Cyborg17: That would certainly be useful!

really just call a script eval and run math.cos(x)

ಠ_ಠ

dont give me that i cant script crap its only one line of code!

yes, I should make a script to execute a single line of code

hmm
Title: Re: sin(x) and cos(x) SEXPs in FRED
Post by: Cyborg17 on November 04, 2011, 12:33:06 am
Nevermind.  I was completely wrong.  I thought it seemed too obvious for you guys to miss.  Camera skips forward one unit instead of half a unit.  Time also rounds up and down.
Title: Re: sin(x) and cos(x) SEXPs in FRED
Post by: Qent on November 04, 2011, 12:50:51 am
Er, I worded that wrong. I meant to spawn a weapon at some position, but pointing at an arbitrary ship somewhere else. Is that already possible? But I guess you'd want inverse trig functions for that anyway.
Definitely possible -- and you can even point it at nothing in particular.  For one example, take a look at the second version of DEM: Interlude.
The Beta spazzout? That seems to use a constant angle of 90. Am I looking at the right thing? I'm talking about get-angle-to-ship or somesuch, so that a mine can spawn a missile pointed in whichever direction the ship is in.
Title: Re: sin(x) and cos(x) SEXPs in FRED
Post by: Goober5000 on November 04, 2011, 10:22:43 am
Oh, I see what you mean.  Yes, that would require a get-[pitch/bank/heading]-to-location sexp, which is definitely doable, but not in SCP yet.
Title: Re: sin(x) and cos(x) SEXPs in FRED
Post by: Polpolion on November 05, 2011, 02:42:44 pm
Quote
(I'm implementing a Taylor series now)

WHY

incidentally this seems as good a place as any to say taht I've been toying with the idea of trying to create SEXP libraries for FRED. You can do ****tons with SEXPs alone but last time I checked (to be fair it has been a while) there really aren't very many good mechanisms for SEXP abstraction. What you would do is define a bunch of generic SEXPs to do something (eg a minefield) and save it as, I dunno, a `.fred' file and then there would be an options screen in the mission editor for including libraries. Then whenever you wanted a minefield (or whatever) all you would have to do is include your appropriate library and use your custom SEXP. Then when you save the mission a text processor would run through your mission events and expand your custom sexp with its arguments to the actual implementation defined in the library.

only problem is that I haven't had the time to work on it any more than thinking about doing it.
Title: Re: sin(x) and cos(x) SEXPs in FRED
Post by: Droid803 on November 05, 2011, 11:52:53 pm
Time to SEXP up some danmakku...
Title: Re: sin(x) and cos(x) SEXPs in FRED
Post by: Goober5000 on November 07, 2011, 01:54:13 am
Oh, I see what you mean.  Yes, that would require a get-[pitch/bank/heading]-to-location sexp, which is definitely doable, but not in SCP yet.
Bah, it looks like it's necessarily to make the problem more specific.  It's not possible to get a single pitch/bank/heading from an object to a given set of coordinates, because that problem has multiple solutions.

However, getting the orientation angle of a particular ship, disregarding any external points or destinations, can be done.  Use the get-object-[pitch/bank/heading] sexps.
Title: Re: sin(x) and cos(x) SEXPs in FRED
Post by: Shivan Hunter on November 07, 2011, 01:41:16 pm
Quote
(I'm implementing a Taylor series now)
WHY
I saw where a trig function was not, and said, "no. This will not do."

Besides, it didn't work anyway because of the aforementioned decimal problem.

Quote
incidentally this seems as good a place as any to say taht I've been toying with the idea of trying to create SEXP libraries for FRED. You can do ****tons with SEXPs alone but last time I checked (to be fair it has been a while) there really aren't very many good mechanisms for SEXP abstraction. What you would do is define a bunch of generic SEXPs to do something (eg a minefield) and save it as, I dunno, a `.fred' file and then there would be an options screen in the mission editor for including libraries. Then whenever you wanted a minefield (or whatever) all you would have to do is include your appropriate library and use your custom SEXP. Then when you save the mission a text processor would run through your mission events and expand your custom sexp with its arguments to the actual implementation defined in the library.

only problem is that I haven't had the time to work on it any more than thinking about doing it.

That sounds awesome