Sign in to follow this  
Followers 0
LibertyMan

Help me understand P-Rotation

9 posts in this topic

I know this subject might have been asked

and yes ive looked them over but theres things I still need to ask.

To make this easy, Heres this so called list of what I might do...

First we need to know:

CurrentRot( N: 0 , S -90 , W: -180 & or W: 179, N: 0 & or 90 )

X,Y and Z(If theres one)

Target/Targets X,Y and Z(If theres one)

- Im pretty sure with this info, we might start..

$radToDeg = -180 / $pi

$result = atan(($posy1-$posy2)/($posx2-$posx1)) * $radToDeg

we used this to find the direction, right..

I understand after CurrentRot = $result then

we can press W to walk forward till we reach

($CurrentLocX+$CurrentLocY),($ToposX+$ToposY)

; I have it for the most part or so I think, but

i dont understand how we know which way North East South & West.

Sorry if this post is wacked. Ive been trying to learn this for

weeks and I know it shouldnt be this hard.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

From what I understand, you want to rotate points in 2- or 3-D space.

You need to learn a bit about rotations first, especially in the 3-D case since there rotations aren't commutative any more: the result depends on the order used to apply them.

But I don't understand why you talk about N S E W. Rotation in 2-D is around a point or around an axis in 3-D. Cardinal points refer to "walking" on a plane or sphere and is something completely different.

Look here I've given some pointers.

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

From what I understand, you want to rotate points in 2- or 3-D space.

You need to learn a bit about rotations first, especially in the 3-D case since there rotations aren't commutative any more: the result depends on the order used to apply them.

But I don't understand why you talk about N S E W. Rotation in 2-D is around a point or around an axis in 3-D. Cardinal points refer to "walking" on a plane or sphere and is something completely different.

Look here I've given some pointers.

Im trying to rotate in my single player game,

Which will then walk to the destination after the rotation is done.

Thank you on some of the links, which im reading right now.

This Would be the last code ive seen which should work but I would

rather make my own learn and understand it. Heres the code anyways.

Link

Func DistAndDir( $Ax, $Ay, $CurHeading, $Bx, $By, $OutDistance, $OutHdgChange)
        ;assume X is positive-right, Y is positive-down
        ;heading is weird, see further down.

    ;distance is simple Pythagoras...
    ;Distance-squared = X-difference-squared + Y-difference-squared
    Local $XDiff = $Ax - $Bx
    Local $YDiff = $Ay - $By
    Local $DistanceSquared = ($XDiff * $XDiff) + ($YDiff * $YDiff)
    $OutDistance = Sqrt($DistanceSquared)
    
    ;now let's work out the bearing, which is based on ATan of the X- and Y-differences
    ;and then resolved into the appropriate quadrant
    Const $TO_DEGREES = 180 / (4 * ATan(1))
    Local $QuadrantBearing = ATan($XDiff / $YDiff) * $TO_DEGREES
    Local $RealBearing
    If $Bx > $Ax Then   ;we need to head east-ish
        If $By > $Ay Then   ;we need to head southeast
            $RealBearing = 180 - $QuadrantBearing
        ElseIf $By = $Ay    ;we need to head pure east
            $RealBearing = 090
        Else                ;we need to head northeast
            $RealBearing = $QuadrantBearing
        EndIf
    ElseIf $Bx = $Ax    ;we need to head pure north/south
        If $By > $Ay Then   ;we need to head south
            $RealBearing = 180
        Else                ;it's north
            $RealBearing = 000
        EndIf
    Else                ;we need to head west-ish
        If $By > $Ay Then   ;we need to head southwest
            $RealBearing = 180 + $QuadrantBearing
        ElseIf $By = $Ay    ;we need to head pure west
            $RealBearing = 270
        Else                ;we need to head northwest
            $RealBearing = 360 - $QuadrantBearing
        EndIf
    EndIf
    
    ;and finally work out the change in heading, in game-heading terms
    $OutHdgChange = $CurHeading - _dad_RealHeadingToGameHeading($RealBearing)
    ;ensure it's in +/-180
    While $OutHdgChange >= 180 Do $OutHdgChange = $OutHdgChange - 360
    While $OutHdgChange < -180 Do $OutHdgChange = $OutHdgChange + 360

EndFunc

;Real heading   game-heading
;   000             -90
;   090             +/-180
;   180             +90
;   270             000

Func _dad_GameHeadingToRealHeading( Const $GameHeading)
    Local $liResult
    $liResult = 270 - $GameHeading
    While $liResult >= 360 Do $liResult = $liResult - 360
    While $liResult < 0 Do $liResult = $liResult + 360
    Return $liResult
EndFunc
    
Func _dad_RealHeadingToGameHeading( Const $RealHeading)
    Local $liResult
    $liResult = -90 - $RealHeading
    While $liResult >= 180 Do $liResult = $liResult - 360
    While $liResult < -180 Do $liResult = $liResult + 360
    Return $liResult
EndFunc
Edited by LibertyMan

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

With none stop searching, I just cant find help on this.

As said, I understand or at least want to belive i can comprehend some of this.

If you can help me out on this, I could be just fine.

Ax = Current Pos

Bx = Targets Pos

If $Bx > $Ax Then ;we need to head east-ish.

Why would this be east,How would we know its not West or any other point?

Is it because X is left and right which equal West and East &

Y is up and down which equal North and South?

And now how would we go about knowing The Target is North-East or South-East?

Is it because If the Target is bigger it must be infront of us,

and if its small then it must be behind us which in are terms equal to smaller?

Please im new to this and trying to learn, If you want

to call me names please do so, just tell me what im missing.

Ill be here all night trying to learn this, Thanks.

Edited by LibertyMan

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Relax, I've no intention to call you names. What for?

Your firsts posts weren't very explicit about what you're after. Now things are much clearer.

First, forget about rotations. Your problem is not about rotation at all.

It is entirely in orientation. You're given a map (I suppose the game playground), you know were your avatar is on the map (i.e. you know his coordinates) and you're given the coordinates of his target. Now you want to determine how your avatar should move to reach the target.

Is that correct? From the program above, I guess it is.

Every planar map has an indication of the North direction. Most simple maps (e.g. road maps) place the North towards the top of the page. Say the map is your screen; then the map North is towards the top of your screen. By definition, the East is towards the right edge of your map / screen, the South towards the bottom and the West towards the left edge. OK so far?

Your screen / map / game use coordinates, called Cartesian coordinates. On your screen (or Excel document), the rows are in the horizontal direction or axis (generally denoted by X or x) and the columns are in the vertical direction or axis (generally denoted by Y or y). The origin is the name of the point (0, 0). The X and Y axis are given an orientation, that is a direction from 0 to 1, then 2, then 3 ... In your game, they say:

;assume X is positive-right, Y is positive-down

That is: say the game is your screen, then the origin is top-left corner, X increasing to the right and Y increasing down. Still there?

So a point is know by its coordinates (X, Y).

Don't forget your screen also have North (top) South (bottom), East (right) and West (left).

Say your avatar is at (0, 0): it is at the origin. Say it's told to go to the center of the screen. Can you see it needs to walk halfway down (toward the South) and then halfway right (towards the East)? You'll also notice that it could also get there by walking halfway right (towards the East) and then halfway down (toward the South). But it could as well step "a bit" South then "a bit" East and repeat until it reaches the center. Is that still clear? As mud?

Q) Now that your avatar has found its way to the center, what if I command you to lead it at target point (23, 17)?

A) You just can't! You're missing a vital information which is: the scale. You either need that I give you the position (X, Y) of your avatar, or that I give you the X and Y size of the screen (in whatever unit). Without knowing that, you're stuck.

Imagine your are told that the screen X size is 51 and Y size 29. Knowing your avatar is exactly at the center point, it must be at coordinates ((51-1)/2, (29-1)/2), which is (25, 14).

Not yet asleep?

How would you go from (25, 14) to (23, 17)? It needs to make 23 - 25 = -2 steps in the X direction, wich is the left side (remember X is going positive from the top-left) and walking to the left we called walking West. Then it also needs to make 17 - 14 = 3 steps in the Y direction, which is the bottom (remember Y is going positive from top-left) and walking towards the bottom we called walking South.

In this example, you need to move West 2 steps and South 3 steps, which we can note (-2, 3).

Also, the "bird" distance (shortest path) between two points is the square root of the sum of the square of each coordinate differences. For (25, 14) to (23, 17) that is:

Sqrt( (23 - 25)² + (17 - 14)² ) = Sqrt( (-2)² + 3²) = Sqrt (4 + 9) = Sqrt(13) ≈ 3.6 units

Is that clearer now?

BTW, you could have spared all this by buying a GPS to your avatar!

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Ill be honest, I dont understand this yet

but im reading. I understand what you have wrote

but not so much in AutoIt and math...

Heres something else im going by another code snip.

trying to understand this one as well...

$radToDeg = -180 / $pi
$result = atan(($posy1-$posy2)/($posx2-$posx1)) * $radToDeg



if $posx2 < $posx1 Then
    if $result < 0 Then
        $result = 270 + $result 
    Else
        $result = 270 + $result
    EndIf
EndIf
if $posx2 >= $posx1 Then
    if $result < 0 Then
        $result = 90 + $result  
    Else
        $result = 90 + $result  
    EndIf
EndIf
    $result = $result-360
    $result = floor(($result - $result) - $result)
    if $result = "360" Then $result = 0
EndFunc

Share this post


Link to post
Share on other sites

anybody?

Let me try and say better what im asking for.

Im trying to learn Rotations in-game,.

Say im facing Unknown or South -90, I want to turn North which is +90

then walk my distance to point B.

The walking part is easy i belive with CurrentLoc and Target Loc

i can watch this count down to zero which equals me being n that area, right?

Im just stumped how to turn your player to the known Rot/Direction...

Ive been using this:

$result = atan(($posy1-$posy2)/($posx2-$posx1))

But... Im just so lost,

Share this post


Link to post
Share on other sites

Are you using a plugin (irrlitch) for making your game? If so I had help with rotation and have a sample I can give.


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

na, im not making any game.

Im trying to learn new things by making

my own auto complete task thing.

After much tons of reading and still no sleep,

I found atan was wrong but atan2 was what I i needed.

* Still reading * and trying to learn so, Topic is

still open :D

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0