Advertisement

Question on Pinter's source code

Started by October 04, 2010 03:10 AM
7 comments, last by LorenzoGatti 13 years, 11 months ago
I didn't understand why in Pinter's source code, when determining where the unit is at, Pinter always adds or subtracts 90 degrees to the original theta, to my understanding, the unit might or might not turn a full left or right angle. Why is it the case? Does anybody know?
Thanks in advance
Jack
Pinter what? Do you expect us to guess what you are talking about? To search for a code example in a random book that only a few people own?

The standard of this forum is quoting code faithfully and completely, even if it's long and boring, so that it can be read and understood without guessing.

Omae Wa Mou Shindeiru

Advertisement
I was referring to Marco Pinter. Sorry.....Its in the resources section....I'll post some code snippets later....
Thanks
Jack
Off you go.....


Posting the whole lot would be overkilling....
// Find a direct route from Src to Dest (if one is possible), starting//  the circle at angle 'angleStart', in 'bClock' direction.//  Pass back the filled in LineSegment array.//  Return TRUE if successful.bool ComputeDirectRoute(FPOINT pGridSrc, FPOINT pGridDest, bool bClock,                        double angleStart, LineSegment *lineSeg){    lineSeg[0].bCircle = true;    lineSeg[0].bClockwise = bClock;    lineSeg[0].radStart = CapRadian(lineSeg[0].bClockwise ? angleStart + PI_VAL / 2                                                          : angleStart - PI_VAL / 2);    lineSeg[0].ptOrigin.x = pGridSrc.x - gTurnRadius * cos(lineSeg[0].radStart);    lineSeg[0].ptOrigin.y = pGridSrc.y - gTurnRadius * sin(lineSeg[0].radStart);    // if destination is inside origin circle, we can't get there with a straight line    double dx, dy;    dx = pGridDest.x - lineSeg[0].ptOrigin.x;    dy = pGridDest.y - lineSeg[0].ptOrigin.y;    double distToOrigin = sqrt(dx*dx + dy*dy);    if (distToOrigin < gTurnRadius)        return false;        // Figure out length of line from rt angle    lineSeg[1].length = sqrt(distToOrigin * distToOrigin - gTurnRadius * gTurnRadius);    // Figure out angle, also from rt triangle    double angleTriangle = acos (gTurnRadius / distToOrigin);    double angleFromOrigin = atan2(dy, dx);    double radStop = (bClock ? angleFromOrigin + angleTriangle : angleFromOrigin - angleTriangle);    lineSeg[0].radTotal = CapRadian(lineSeg[0].bClockwise ? lineSeg[0].radStart - radStop                                                           : radStop - lineSeg[0].radStart);    lineSeg[0].length = lineSeg[0].radTotal * gTurnRadius;    // Finish information on the straight line segment (length already set above)    lineSeg[1].bCircle = false;    lineSeg[1].ptStart.x = lineSeg[0].ptOrigin.x + gTurnRadius * cos(radStop);    lineSeg[1].ptStart.y = lineSeg[0].ptOrigin.y + gTurnRadius * sin(radStop);    lineSeg[1].radStart = CapRadian(lineSeg[0].bClockwise ? radStop - PI_VAL/2                                                           : radStop + PI_VAL/2);     lineSeg[1].radTotal = 0.0;    lineSeg[2].length = lineSeg[3].length = 0;    return true;}


Thanks
Jack
According to Google Books, to understand the computation you should meditate on the diagram on page 188 of "AI Game Programming Wisdom", draw all different cases (like turning less than 90°) you can think of, and figure out where point P goes.

Hint: those plus or minus PI_VAL/2 are a right angle in a geometric construction, not 90° of turning.

Two more posts, and you still haven't said what book you are referring to, I had to search for it.

Omae Wa Mou Shindeiru

A wild guess would be this via this index.
Of course, only the OP knows for sure.

To make it is hell. To fail is divine.

Advertisement
this forum helps me alot Really like this forum and suggest to my friends
Quote: Original post by Zao
A wild guess would be this via this index.
Of course, only the OP knows for sure.


Thank you Zao, Thats exactly the one I am referring to.
Jack
So it's figure 6 in the article, apparently the same one that is printed in "AI Game Programming Wisdom". Very nice ideas, by the way; I'll use them.

Omae Wa Mou Shindeiru

This topic is closed to new replies.

Advertisement