Jump to content

  • Log In with Google      Sign In   
  • Create Account

Álvaro

Member Since 07 Mar 2002
Online Last Active Today, 05:38 AM

#5301514 How To Start Game Programming With C++

Posted by on 20 July 2016 - 06:10 AM

I would start by installing SFML and going through their tutorials.


#5301193 Move The Player Along The Direction It Is Facing

Posted by on 18 July 2016 - 06:07 AM

I would generally recommend against using quaternions unless you can explain in great detail why they are superior to matrices. There are cases where quaternions are the answer, but pitch, yaw, and roll (which are not Euler angles by the way) not being functional is not one of them.


Quaternions are more compact, much easier to renormalize and better for interpolating. Is that enough detail for you?

Regardless of how you are representing rotations internally, you should have a mechanism to apply a rotation to a vector, without worrying about the details. So your code should look something like this:
void InputPlayer::MoveForward(float dt) {
  player->SetPos(player->GetPos() + apply_rotation(player->GetAttitude(), glm::vec3(0, 0, 5)));
}



#5301116 Particle Lighting 101

Posted by on 17 July 2016 - 05:30 PM

It looks like HL2 does mean Half Life 2. They seem to use a particular orthonormal basis in their lighting computations. The slide "Resurrecting an old friend: HL2 basis" has the exact vectors. You can also find them here: http://www.valvesoftware.com/publications/2006/SIGGRAPH06_Course_ShadingInValvesSourceEngine.pdf


#5300002 Finding that balance between optimization and legibility.

Posted by on 10 July 2016 - 11:06 AM

I have no idea what Carmack or Abrash have to do with this thread. I also don't understand what those posts from Carmack have to do with my recommendation.

The supposed need to reach a balance between code speed and code readability is largely false. If you write clean code with a bit of common sense, chances are it will be fast enough.

Using quaternions or 3x3 orthogonal matrices to represent rotations, for instance, would get rid of practically every trigonometric function call in your code and make it run faster. And that's while making the code easier to read.


#5299965 Finding that balance between optimization and legibility.

Posted by on 10 July 2016 - 05:40 AM

You should have a class that represents rotations. Whether it's implemented as three axis rotations, as quaternions or as something else should be fairly opaque to most of the code.

The "footprint" of the change shouldn't matter too much. Don't be lazy.


#5299002 Hashing by key range

Posted by on 04 July 2016 - 06:35 AM

for (auto it = range.first; it != range.second; ++it) {
       return it->second;
}


That is some funny-looking code. It's a loop, but it immediately returns from the function. Are you sure that's what you want?


#5298824 Sticky power up?

Posted by on 02 July 2016 - 01:21 PM

You cannot add two positions and expect something good will happen. You can add a position and a vector, though. So something like
 

  float dx = however_you_figure_out_how_much_to_move_the_paddle();

Im guessing this however() is the speed I am adding to the paddle? Am i correct?


It's the speed of the paddle multiplied by the duration of a frame.


#5298821 Sticky power up?

Posted by on 02 July 2016 - 01:10 PM

You cannot add two positions and expect something good will happen. You can add a position and a vector, though. So something like

  float dx = however_you_figure_out_how_much_to_move_the_paddle();
  paddle.position.X += dx;
  
  if (ball_is_stuck())
    ball.position.x += dx;



#5298477 Seeding the random number generator in <cstdlib>

Posted by on 28 June 2016 - 05:53 PM

If you reseed it repeatedly you're making it less deterministic. This is a good thing if you want it to be unpredictable [...]


No, this is never a good thing. If you want things to be unpredictable, you use some source of entropy and fold it into your PRNG (see /dev/urandom in Linux). By seeding the PRNG repeatedly you might get ridiculously bad numbers, especially if you use some sort of clock to produce the seeds.


Note that the rand function in most c libraries isn't that good and doesn't produce a good spread of random figures, if this is important to you, e.g. for a card game look into marsienne twister or similar Instead.


C++11 provides very nice pseudo-random numbers. Learn how to use them. You can start here, for instance.


#5298184 what means these error?

Posted by on 26 June 2016 - 11:38 PM

You code like a beginner, you don't know what the call stack is, and you don't seem to understand segmentation faults. And yet you are writing a multi-threaded C++ program and you have your own hack to implement some sort of runtime type system, full of dangerous pointer casts.

 

It's just not going to work. You can stop trying now.




#5297391 Non-duplicating pairs from a set

Posted by on 20 June 2016 - 05:50 PM

I am late to the thread and I didn't read the whole thing, but I think I know a very easy way to do it. You basically have 14 volleyball teams (including "nowhere") and you want to organize a league, so over 13 rounds every team plays every other team. The traditional way to do it is having 7 courts and having team 1 fixed and everyone else rotate, like this:

 

Round 1:
 1   2   3   4   5   6   7
14  13  12  11  10   9   8
 
Round 2:
 1  14   2   3   4   5   6 
13  12  11  10   9   8   7
 
Round 3:
 1  13  14   2   3   4   5
12  11  10   9   8   7   6
 
...

 

Does that make sense?




#5297378 what means these error?

Posted by on 20 June 2016 - 04:06 PM

eis o meu Debugger Output:

 

Adoro a mistura of languages you did lá. :)




#5297357 what means these error?

Posted by on 20 June 2016 - 02:12 PM

Here: https://en.wikipedia.org/wiki/Segmentation_fault


#5297269 [Solved] Rotate towards a target angle

Posted by on 19 June 2016 - 08:52 PM

Use complex numbers with modulus 1 instead of angles. That would be z = cos(alpha) + i * sin(alpha).

if (imag(desired / current) > 0.0)
  current *= Complex(cos(0.1), sin(0.1));
else
  current *= Complex(cos(0.1), -sin(0.1));

It's not just this piece of code: Pretty much anything you want to do with angles is easier with complex numbers.




#5296162 Truncating a fraction when overflow occurs

Posted by on 11 June 2016 - 08:37 PM

You can use mpq_class from GNU MP to represent rational numbers exactly. It uses arbitrary-precision integers for the numerator and denominator.

But the operation you are asking about is interesting to think about regardless of its practical application. I would consider using the continued fraction expression of your number. See the section titled "Best rational approximations" for details.

Informally, in your example
62000000 / 30999998 = 1 / (2 + 1 / (7749999 + 1 / 2))

Whenever a large number pops up in the continued fraction expression of a number, one can find a good approximation using a fraction by substituting that number with infinity

1 / (2 + 1 / Infinity) = 1 / (2 + 0) = 1 / 2


You can do that with irrational numbers as well:

pi = 3 + 1 / (7 + 1 / (15 + 1 / (1 + 1 / (292 + 1 / (1 + ...)))))

If you replace 292 with infinity, you get

pi ~= 3 + 1 / (7 + 1 / (15 + 1 / (1 + 0))) = 355 / 113 = 3.14159292035398230088...




PARTNERS