void addComponent(std::unique_ptr<BaseComponent> component) { components.push_back(component); }Probably something like that, perhaps with a different type of pointer, depending on how exactly you handle ownership.
 Home
 » Viewing Profile: Reputation: Álvaro
Álvaro
Member Since 07 Mar 2002Online Last Active Today, 07:17 AM
Community Stats
 Group Crossbones+
 Active Posts 7,663
 Profile Views 32,424
 Submitted Links 0
 Member Title Member
 Age Age Unknown
 Birthday Birthday Unknown

Gender
Not Telling

Location
New York (USA)
User Tools
Latest Visitors
#5311459 C++ Angle bracket function
Posted by Álvaro on 19 September 2016  11:20 AM
#5311188 Game works when built in the IDE, but crashes when I run it from the .exe file.
Posted by Álvaro on 17 September 2016  05:27 AM
Now either of two things will happen:
(1) You discover the problem in the process of creating the small version of the program.
(2) You have a short program that you can post here, so we can all reproduce the problem and help you much better. If it turns out the short program is obviously correct and it's still breaking, you can include this code in a bug report.
Now, in the last 20 years of programming I have found a compiler bug exactly once. So the prior probability that you found one is very small, and the fact that your code has some issues (like not checking return values) leads me to lower my estimate in light of what I know about the situation.
#5310841 Find the domain of this function.
Posted by Álvaro on 14 September 2016  03:33 PM
(v^2)^2  2gy * v^2  g^2x^2 >= 0
The solutions are values of v for which
v^2 >= g * (y + sqrt(y^2 + x^2))
or
v^2 <= g * (y  sqrt(y^2 + x^2))
But (y  sqrt(y^2 + x^2)) is always negative, so the second condition never really happens.
Taking a square root on the first inequality, you get what I think is the final answer:
abs(v) >= sqrt(g * (y + sqrt(y^2 + x^2)))
#5310621 Why can't I print out my std::string vector?
Posted by Álvaro on 13 September 2016  12:49 PM
If you end up using global state of some sort, what is the advantage of using a singleton over using a global variable?
#5310425 Faster Sin and Cos
Posted by Álvaro on 12 September 2016  04:34 AM
I might include a note about your my_atan(), and possibly exp() and some others. Did you come up with the original code?
Yes, I did. I got the idea of using something like x/polynomial from this paper.
I just found a very interesting trick I hadn't thought about: You can reduce everything to computing atan(x) for x smaller than tan(pi/12) ~= 0.268, where it's really easy to approximate well. See here. The idea seems to come from "Math Toolkit for RealTime Programming" by Jack Crenshaw, which I don't own.
#5310345 Faster Sin and Cos
Posted by Álvaro on 11 September 2016  10:04 AM
Then you may find these constants more to your liking:
1.00022506713867187500f 0.324211299419403076172f 0.0511969886720180511475f
L. Spiro
That's great! The maximum difference is about .00074, which is really good for such a simple formula.
Here is the code with updated coefficients:
float atan_near_0(float x) { float x2 = x * x; return x / (1.00022506713867187500f + 0.324211299419403076172f*x2  0.0511969886720180511475f*x2*x2); } float my_atan(float x) { static const float pi_halves = float(std::atan(1.0)*2.0); if (std::abs(x) > 1.0f) return std::copysign(pi_halves, x)  atan_near_0(1.0f/x); return atan_near_0(x); }
Any chance we can get a version with a higherdegree polynomial?
#5310270 Precision errors when calculating normal map for planet
Posted by Álvaro on 10 September 2016  01:07 PM
A clean solution would be to use a cubemap instead of spherical coordinates.
#5310244 Faster Sin and Cos
Posted by Álvaro on 10 September 2016  08:06 AM
#5310108 Rotating in the direction of velocity
Posted by Álvaro on 09 September 2016  06:20 AM
In any case, you are better off ditching angles altogether if you can: Use normalized unit vectors instead. If you are not scared of math, think of them as unitmodulus complex numbers.
Whatever you are doing with the angle, at some point you are going to compute its cosine and its sine. But those are precisely the coordinates of the unitlength vector!
If you are using an API that requires you to specify an angle, use atan2.
#5310088 What is the Quaternion equivalent for multiplying two 3x3 rotation matrices t...
Posted by Álvaro on 09 September 2016  03:15 AM
#5310085 Computer understands your text and is able to speak back
Posted by Álvaro on 09 September 2016  03:03 AM
#5310015 Platformer style tutorial. How to import files from tiled etc?
Posted by Álvaro on 08 September 2016  02:49 PM
#5309960 C++ Going Beyond Basics
Posted by Álvaro on 08 September 2016  09:22 AM
It doesn't matter what language I learn because all of them have the same exact logic...the only difference are the way you type the code.
instead of: cout <<"hello, world" << endl
you type: print "hello, world"
Yes, those things look superficially similar. But then you need to worry about whether `cout' and `endl' are visible or if you need to specify the `std::' in front, what that `#include <iostream>' means, whether you should be using `endl' or "\n" or '\n', what the hell `std::ostream &operator<<(std::ostream &, MyType)' means when you are trying to print your own type, etc., etc.
C++ is very unfriendly to beginners, and trying to learn fundamental programming concepts using it is a handicap that you do not need.
#5309956 C++ Going Beyond Basics
Posted by Álvaro on 08 September 2016  08:57 AM
If you don't know programming, C++ is a terrible language to learn. I would start by learning a friendlier language first. Python is often suggested for this purpose, but I don't think there is anything wrong with learning C, for instance.
I think you have the right idea in trying to find projects that motivate the learning of different concepts.
Beyond input and output, try to learn:
* Loops (make a multiplication table)
* Fancier loops (test if a number is prime by trying to divide it by trial division)
* Functions (learn to organize your code in understandable chunks with a good name and a clean interface, provided by the parameters and the return value of the function)
* Data structures (things like arrays, lists and trees; but the details depend on the exact language you are working with)
* File I/O (process a text file and count how many characters, words and lines it contains)
#5309933 Faster Sin and Cos
Posted by Álvaro on 08 September 2016  05:15 AM
One thing that will make it faster and more accurate is to replace:
static const float pi_halves = float(std::atan(1.0)*2.0);with:const float pi_halves = 1.5707963267948966192313216916398f; // float(std::atan(1.0)*2.0)
Actually, my compiler produces the exact same binary with that modification. As usual when optimizing, even if you have a plausible argument for why a change should be an improvement, you just need to test.