x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Can std::complex be used in C++ programming?

I'm building a shooting mechanic for my game in C++. I have included functionality for aiming to moving targets and this comes down to an grade 4 equation:

alt text

The only reliable and exact solution to solving this equation seems to be using complex numbers. My implementation is using std::complex to do much of the calculations.

Are there any compatibility / deployability issues with std::complex? I've seen people on the forums say that containers like std::vector or std::stack are not recommended.

Note: I intend to deploy on Windows, Android and maybe others. Definitely not on MacOS or iOS.

Product Version: UE 4.18
Tags:
more ▼

asked Jan 30 '18 at 07:37 PM in C++ Programming

avatar image

Waterlynx
3 1 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

I should be fine as long as it not using it with UPROPERTY() or UFUNCTION() or other things like that. you need to understand that not using those means that engine don't see them, but on other hand engine don't support that type so it really does not matter.

There 2 major reason why they using C++ std library as well as other types from elsewhere is not recommended:

-UE4 has set of own core implementations, some are just wrappers of std, platform, system, third party libraries and other APIs. Point of it is to make UE4 code and much as portable to supported platform as possible without you UE4 deweloper to even think about it. By using something else UE4 don't give you guaranty that it will work (or atleast inform that it does not work on specific platfrom) with any target platform case. Sadly UE4 indeed don't have any implementation of complex numbers, whole there is alternatives for std::vector and std::stack.

-UE4 code expects you to use only UE4 APIs, which means a) reflection system don't support them (mentioned U macros above) b) using it with UE4 APIs risks crashes as UE4 don't know what to do with them, UE4 also might be not prepared for what specific library doing as it was not design to cooperate with it. Other potantion compatibiliuty issues is advance UE4 memory manipulation might have potention issue dilling with object that use those types, epcially if you implement to asset type. But as long as you using external types and function with isolation from the engine it should be fine.

Best practice here is to do what UE4 is doing, make your own implementation of complex numbers in UE4 or try creating a wrapper from UE4 APIs, simply create FComplex struct, try to make std::complex to be operatable C++ primitive type that UE4 support, if oyu up to iyt you can even make custom UI for your property type and bluepritn nodes so you can it in Blueprints too. And as point 1 saying UE4 and Epic won't guaranty you that things will work out and work on every platform (you will need to implement specific platfrom support if needed on your own), you on your own in this journey.

Also look up how UE4 deals with third party libraries or find plugins that do so, those are best examples you can find to how to interact with things outside of UE4 APIs and how to make them work with UE4.

more ▼

answered Jan 31 '18 at 02:44 AM

avatar image

Shadowriver
36.7k 932 169 1111

avatar image Waterlynx Feb 01 '18 at 08:43 PM

Thanks for answering!

Before I posted this question i already created a FComplex struct with operators but i tried using and got horrible results. After a few days of debugging nothing has changed... Then a mathematician friend of mine pointed out that I was not calculating the complex argument correctly ( I was using atan(y/x) instead of atan2(y, x) ) and this solved all the issues.

I will post tomorrow my FComplex code in case this question comes up in any searches and someone might need it.

Update: Code can be found on Git. I also included my function for solving quartic equations.

avatar image Shadowriver Feb 02 '18 at 05:11 PM

If you can use UE4's FMath insted of math.h it will will integrate UE4 code even more and reduce risk of any compatibility issues

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

This might be a silly question but why would you be interested in complex zeroes of this polynomial - surely you're looking for real-valued solutions? You could also extend this implementation to 3D.

more ▼

answered Jan 31 '18 at 02:13 AM

avatar image

staticvoidlol
2.6k 95 41 111

avatar image Waterlynx Feb 01 '18 at 08:48 PM

I am only looking for real solutions, of course. I know it sounds weird, but calculating these requires the use of complex numbers (in rare cases, but they still show up).

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question