• Create Account

# Álvaro

Member Since 07 Mar 2002
Offline Last Active Today, 01:06 PM

### #5313276When should I use int32_t ranther than int

Posted by on Yesterday, 11:43 AM

Also correct:
for ( auto i = 0; i < someVec.size(); ++)

Unfortunately, that's not correct. That `auto' will have the same effect as `int', since that's the type of `0'.

### #5312885target selection strategies

Posted by on 27 September 2016 - 12:23 PM

The problem is that real humans and indeed real decisions don't work that way.

This is true. I have mostly dealt with situations where rational behavior is preferred, and imitating humans is irrelevant.

But I do have some experience in making utility systems that need to conform to rules. There are two ways of mixing them:
* Rules cannot be broken (e.g., you need to obey regulations in a trading system).
* Following rules is encouraged. I believe this is what applies to games.

So you can have a utility system where one of the terms in evaluating an action is whether this action is in accordance with a set of rules. The weight of this term can be adjusted so rules will be ignored at the right time. That way you may be able to get the best of both worlds: The utility mechanism will take care of emergency situations, and the designer still can describe how things should happen under normal circumstances.

For instance, a rule might say that the correct action to perform now is make tea, because a guest has requested it. But someone just started shooting. Ignoring the rules, the utility of taking cover is much higher than the utility of making tea, so even with the bonus for following rules making tea won't be selected.

### #53128162D circle and OBB moments of inertia

Posted by on 27 September 2016 - 06:51 AM

Integral of density is mass, integral of position times density divided by mass is center of mass, integral of density times the square of the distance to the center of mass is moment of inertia. [EDIT: I had forgotten about the square, sorry.]

I guess I just went to a good high school.

### #5312810target selection strategies

Posted by on 27 September 2016 - 06:38 AM

Incidentally this is probably the most significant problem that I have with utility systems - designers often have a mental model of the ranking or precedence that they want the actions to have, but trying to force the mathematics to produce that result consistently can be very difficult.

While this is indeed a problem, I think it's a problem with designers, not utility systems. The way designers often think about behavior (rankings of actions, if-then rules...) is brittle by nature and results in many absurd situations. Designers just need to get more sophisticated in their thinking and learn to describe their preferences as utility functions.

It is very important to give them tools to understand why an agent is behaving the way it's behaving, like a display of available actions, the contribution of each term in the utility function to the final assessment, etc.

### #5312355C++ Angle bracket function

Posted by on 24 September 2016 - 06:57 PM

Sorry for not replying for a while! I managed to get it all sorted out thanks to your help!

It would be nice if you could give us a brief description of what worked for you. That way this thread would be more helpful to people that find it in the future when they have a similar problem to yours.

### #5312352target selection strategies

Posted by on 24 September 2016 - 06:05 PM

The most robust strategy is to consider all targets and all interactions, and pick the best combination. Utility systems are great for this. It helps to mix in "non-targeted" actions as well (running away, healing, etc.) so you can always have something semi-reasonable to do regardless of situation.

This.

### #5312127Provide a quick code-review of c++ code?

Posted by on 23 September 2016 - 09:43 AM

I was reading Alberth's comments so I looked at the code starting at line 487:
```	int yPos = 0;

switch (barData.uEdge)
{
case ABE_LEFT:
case ABE_RIGHT:
{
yPos = btnDim.top - lbH - 10;
}
break;
case ABE_TOP:
{
yPos = btnDim.bottom + 10;
}
break;
//case ABE_BOTTOM:
default:
{
yPos = btnDim.top - lbH - 10;
}
break;
}
```

`	int yPos = (barData.uEdge == ABE_TOP) ? btnDim.bottom + 10 : btnDim.top - lbH - 10;`

### #5311534C++ Angle bracket function

Posted by on 19 September 2016 - 09:49 PM

Or just do addComponent(BaseComponent* baseComponent). No need to use templates.

I sometimes feel invisible.

### #5311459C++ Angle bracket function

Posted by on 19 September 2016 - 11:20 AM

```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.

### #5311188Game works when built in the IDE, but crashes when I run it from the .exe file.

Posted by on 17 September 2016 - 05:27 AM

Here's what to do in situations like this one: Make a copy of your code and boil it down to the smallest possible program that still shows the problem. Remove absolutely everything you can that doesn't have to do with the particular crash. Put all the code in a single file.

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.

### #5310841Find the domain of this function.

Posted by on 14 September 2016 - 03:33 PM

That's a second-degree inequality in v^2:

(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)))

### #5310621Why can't I print out my std::string vector?

Posted by on 13 September 2016 - 12:49 PM

A singleton is rarely a good solution. In a well-designed program you typically don't have that many dependencies, so perhaps you need to rethink your design. Sending the references everywhere at least makes the dependencies explicit. Otherwise you'll try to reuse some piece of code for a new project and you'll realize that the whole project has become one monolithic mess and you can't do it.

If you end up using global state of some sort, what is the advantage of using a singleton over using a global variable?

### #5310425Faster Sin and Cos

Posted by 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 Real-Time Programming" by Jack Crenshaw, which I don't own.

### #5310345Faster Sin and Cos

Posted by 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 higher-degree polynomial?

### #5310270Precision errors when calculating normal map for planet

Posted by on 10 September 2016 - 01:07 PM

With the parametrization you have used, the samples at the poles are very close together. Try using doubles for the computation, but even that might not fix the very last line, because all those points map to the same point on the pole and you are then looking at degenerate triangles.

A clean solution would be to use a cubemap instead of spherical coordinates.

PARTNERS