Jump to content

  • Log In with Google      Sign In   
  • Create Account

Gamedev.net will be down tonight at approximately 9pm EST for site maintenance

Paradigm Shifter

Member Since 09 Aug 2002
Offline Last Active Today, 05:10 AM

#5241179 Whats the preferred method of storing a "rotation segment/area/field/rang...

Posted by Paradigm Shifter on 18 July 2015 - 02:12 AM

Use an axis and an angle, then check whether the proposed orientation dot axis is within the angle, it's a cone check, if both axes are normalised the dot product will be > cos(angle) if it is within the cone


EDIT: > not <

#5187736 point & Octahedron relationship

Posted by Paradigm Shifter on 17 October 2014 - 04:53 PM

In 2d, shoot a ray out in any direction. If it crosses the lines of the shape an even number of times (0 is even here), you are outside. If it crosses odd number of times you are inside.

#5187387 Maclaurin series for reciprocal function

Posted by Paradigm Shifter on 16 October 2014 - 07:01 AM

The interval of convergence is too small.


Are you using floating point or fixed point, I don't understand what you mean by this: of floating range from 24 bit to like 16 bit.


Using 1/x is going to be a lot more accurate than a (poor) approximation which is what the Taylor Series expansion about 1 will give you. Some functions aren't approximated very well at all by Taylor Series (of which McLaurin series is just a special case), e.g. sqrt(x).


Or you could use the Laurent Series, f(x) = x-1  biggrin.png

#5187376 Maclaurin series for reciprocal function

Posted by Paradigm Shifter on 16 October 2014 - 06:37 AM

That's not defined at x = 0 ;)


You'll have to use the Taylor series approximation around a suitable point (probably x = 1).


What's wrong with just using 1/x? It's going to be a lot more efficient than calculating a power series expansion...


EDIT: It also has a very narrow radius of convergence ( abs(1-x) < 1 when centred on 1). So it's pretty much useless... See http://www.wolframalpha.com/input/?i=taylor+series+1%2Fx+a%3D1&lk=4

#5186236 calculate the determinant

Posted by Paradigm Shifter on 10 October 2014 - 01:44 PM

You can only take the determinant of square matrices.

#5186233 calculate the determinant

Posted by Paradigm Shifter on 10 October 2014 - 01:39 PM

Absolute value of dot product is 1 edit: if normalised, product of lengths otherwise. Cross product will have length zero. Up to accuracy limits of course.

#5185601 Funniest line of code ever ?

Posted by Paradigm Shifter on 07 October 2014 - 01:34 PM

I saw this about a year ago in a graphics engine, and I've kept a screenshot to remind me of it:

float PI = 57.29578f; // (7/22)*180
I love this on two levels. First, this number isn't the universal constant pi. That should be enough, but... the number isn't the result of the calculation in the comment, either.
7/22 is approximately pi. The number be assigned here is actually pi/180, and it was used in the code to convert radians to degrees.

Actually pi/180? Hmm

#5185530 Dropping a not guided bomb

Posted by Paradigm Shifter on 07 October 2014 - 08:17 AM

I thought that (in the real world), non-guided bombs fall straight down. smile.png


Nope, they start off with the velocity the craft had when the bomb was released, then that initial velocity is influenced by gravity (and drag if you factor that in). Otherwise, dropping a cup whilst inside an aeroplane would mean it would shoot to the back of the plane with remarkable speed ;)

#5185475 How to implement curved boomerang ?

Posted by Paradigm Shifter on 07 October 2014 - 01:58 AM

The easy (cheating) way is to make the bezier curve centred on the player, If they aren't moving too fast that looks ok.


Othwerwise you have to update the control points as the boomerang is in flight, again you can centre it on the player but keep updating the control points as the player moves, with the final point always on the player.


You could also make the boomerang miss and wait until it is picked up again/destroyed before letting the player use it again, I think 2d zelda did this, not sure. However that was just a back and forward along a straight line boomerang not on a bezier.

#5176176 Mapping Poker-Starting Hands to 0..1325

Posted by Paradigm Shifter on 26 August 2014 - 05:45 AM

You need to use 52 instead of 51 (since x % 51 gives a number from 0 to 50, not 0 to 51).


You also want to use (h - j) / 52 since division has higher precedence than subtraction.


You probably don't need all combinations either the only thing you care about is card value and whether they are the same suit or off suit.


EDIT: And what Bacterius said.

#5175203 Beginner Tutorial Issue

Posted by Paradigm Shifter on 21 August 2014 - 03:03 AM

You need to add std:: before each use of cout, cin and endl.


Otherwise add


using namespace std;


after the #includes.


Your book must be rather old...


EDIT: Oh you have that already... didn't see that.


As L. Spiro says, you need to do a full rebuild.


EDIT2: You keep editing the code, making my replies seem foolish.


EDIT3: Nope, my mistake, there are 2 programs not just 1, one of them has using namespace std in each function and the other has using namespace std.


I'll get my coat ;)

#5173557 3D Line Equation?

Posted by Paradigm Shifter on 14 August 2014 - 05:57 AM

It's the same equation,


p = a + (b-a) * t


where a and b are the endpoints of the line and t ranges from 0 to 1 (unless you want the infinite line through the points, where t can be any real number).


Just set a = (2, 0, -1) and b = (3, 4, 5) and you are good to go... isn't that what you did in the 2d case?

#5173552 Best way to traverse a 2d array to dertermine the winner in Tic-Tac-Toe

Posted by Paradigm Shifter on 14 August 2014 - 05:25 AM

Do it in the way that is easiest for you, the reader of the code, to understand.


Although a good idea would be to have +1 for O and -1 for X instead of 1 and 2, in that way you can sum up all 3 rows (in a loop), all 3 columns (in a loop) and both diagonals and if they sum to +3 O has a winning line, -3 means X has a winning line. You can exit the test early if you find a win for either player.


More sophisticated would be to use a bitboard but Alvaro will probably be along in a minute to boggle your mind with that idea ;)

#5169379 Segfault upon exiting application

Posted by Paradigm Shifter on 26 July 2014 - 03:58 PM

Deleting something twice, accessing objects that have been destroyed, that kind of thing

#5169367 Segfault upon exiting application

Posted by Paradigm Shifter on 26 July 2014 - 02:34 PM

C++? Check your destructors of global objects, they run after main returns.