Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 07 Mar 2002
Offline Last Active Today, 08:29 PM

#5238098 Portal view

Posted by Álvaro on Yesterday, 06:57 PM

I assume you are talking about holes in the wall, like in the Portal video game. Each portal has an associated reference frame. There is an affine transformation that maps one reference frame to the other one. You need to transform the camera through that transformation (or its inverse, depending on how you label things).

#5238097 Help with MiniMax Algorithm for Tic Tac Toe

Posted by Álvaro on Yesterday, 06:52 PM

Well, a perfect opportunity for you to figure out how to debug recursive calls. smile.png

#5237765 How do I make this game I'm thinking about?

Posted by Álvaro on 30 June 2015 - 05:38 PM

Do you mean "Je ne regrette rien" ??

That's the song. I was quoting the first line of the lyrics.

#5237721 How do I make this game I'm thinking about?

Posted by Álvaro on 30 June 2015 - 01:22 PM

That wasn't what I meant, I meant how do I play a game within the same game, like recursion.

A game within a game? Be careful of going too deep. If time flies by when having fun with just 1 game, it flies by twice as fast in a game within a game. You’ll need a kick to get you out.

Non... rien de rien... smile.png

#5237600 Search Algorithm for fast key lookup?

Posted by Álvaro on 29 June 2015 - 07:40 PM

Look up spatial partitioning methods. That's probably what you need.

#5237519 orthonormal rotation and a quaternion bijection?

Posted by Álvaro on 29 June 2015 - 10:56 AM

So quaternions with a different sign will map to a different orthonormal matrix right?

No, quaternions that differ only in the sign will map to the same orthonormal matrix.

I didn't understand the rest.

#5237168 If-else coding style

Posted by Álvaro on 27 June 2015 - 04:51 PM

For code that looks exactly like what we are discussing, I like to use the ternary operator:
SomeType GetSomething 
        return somecondition ? something : null;
But I agree with Servant of the Lord's post above.

#5237031 what is best way to check a code is more effiecient and runs faster than others

Posted by Álvaro on 26 June 2015 - 11:20 PM

and there is a piece of code that starts a timer  runs a code in a N time loop and after the code ended stops the timer and gives you the average.

You should not trust too much the results of synthetic tests where you run your code in a tight loop, because the performance in those conditions and the performance as part of a larger program might be very different (for instance if the cache gets primed by the first iteration and the others are artificially cheap). You should test the performance of your code as part of the larger program, and feed it data that looks as much as possible like the actual data it's going to encounter in reality.

#5237029 orthonormal rotation and a quaternion bijection?

Posted by Álvaro on 26 June 2015 - 10:58 PM

Every rotation matrix (i.e., orthonormal and with determinant 1) corresponds to exactly two quaternions, which differ by a sign flip. Backwards it works better: Every unit quaternion maps to exactly one rotation matrix.

#5236768 sprintf

Posted by Álvaro on 25 June 2015 - 11:38 AM

I haven't encountered this problem recently, but stringstream can be notoriously slow. snprintf is perfectly safe(*) and allows greater flexibility than stringstream, particularly if you want to change the format string as a configuration option.

EDIT:(*)- OK, actually there is a lot wrong with this statement. I mean that it's not that hard to use snprintf in most situations without stomping past the end of the buffer. Of course you can still pass arguments of a type that doesn't match the format string.

MORE EDIT: You may want to look into the Boost Format library.

#5235945 Get object from std::function

Posted by Álvaro on 20 June 2015 - 07:00 PM

Then it sounds like you need to be passing a pointer to the object and a pointer to a member function.

#5235644 Problem with average calculator, help me out?

Posted by Álvaro on 19 June 2015 - 03:42 AM

My own version. The main differences are:
* No `using namespace std'. I prefer to let standard names stand out with their `std::'.
* Better variable names. This is important! Also, a variable's meaning never changes (unlike `quo' in the original code, which is the running sum for a while and then it's the average).
* Variables are introduced when needed, and never initialized with values that are never used.
* Nothing to stop the console window from closing. This is not your program's responsibility. Command line programs don't usually pause for input at the end of their run. If your IDE does this annoying thing of closing the window without giving you a chance to see the result, try to see if it can be configured to not do that. Or you can run the program from an existing window.
#include <iostream>

int main() {
  std::cout << "Enter the amount of numbers you are going to average: " << std::flush; // Without flush the output might be buffered
  int n;
  std::cin >> n;
  float sum = 0.0f;
  for (int i = 0; i < n; ++i) {
    std::cout << '[' << i << "] = " << std::flush;
    float value;
    std::cin >> value;
    sum  += value;
  float average = sum / n;
  std::cout << "Average = " << average << '\n';

#5235640 Problem with average calculator, help me out?

Posted by Álvaro on 19 June 2015 - 03:17 AM

If you declare the array as the variable input:

float avrg[a];
You will get an array that can hold a+1 floats.

No, it will not. The whole point of the convention that array indices are number from 0 has the advantage that there are never any "+1"s to think about. `float avrg[a]' will get you an array that can hold `a' floats.

#5235332 Substantial project

Posted by Álvaro on 17 June 2015 - 03:26 PM

I like the first two ideas much better than the third. Computing poker statistics is a fairly limited project. There might be some things you are not sure how to implement right now, but once you get the right ideas, it's probably doable in 200-400 lines of code.

What kind of game do you have in mind?

#5234487 float value increment in a loop?

Posted by Álvaro on 12 June 2015 - 11:49 AM

It works, just don't expect to hit any specific point in between, or think you'll know exactly how many times you'll go through the loop.

Well, if you know a bit about how floating-point numbers are implemented, there are cases where you know what you'll get.
  for (float x = -10.0f; x <= 10.0f; x += 0.125f) { ...
That will do exactly what you expect, because small multiples of 1/8 are exactly representable as floats.

[EDIT: Added the `f' at the end of the constants to avoid the error this thread is about.]