Angles in GLBasic

Previous topic - Next topic

XanthorXIII

In GLBasic is the Angle 270 Considered to be pointing up considering Point 0,0 is the starting coordinate in the upper left of the screen?
So would it be something like this for the angles?
(Excuse my poor diagram in Text)

                   270
         225            315
180                               0
         135              45
                   90

If I am calculating an Angle based on points using Atan(Y2-Y1, X2-1) and then ploting the X on Cos(Angle) and Y on Sin(Angle) is there anything additional I may need to do since the Angles are flipped?
Thanks!






Owlcat has wise

MrTAToad

If you want the angle the correct way around, you could always subtract 90.0

But aside from that, I dont think there is anything else you need to do.

XanthorXIII

Thanks for validation. I will give my method a try tonight and if I have to make any adjustments I will.
Owlcat has wise

Kitty Hello

your angles are fine. If you want the angles as I use them in GLBasic, just flip the vertical part (Y2-y1) goes (y1-y2).

XanthorXIII

#4
Just wanted to double check here but my method doesn't seem to be working.
Here is the code from my memory.

Code (glbasic) Select
startPosX = RND((459) + 10) // Choose an X point at top of the screen between 10 and 469
endPosX = RND(479) // Choose an X Point at the bottom of the screen between 0 and 479
startPosY = -32 // Above the screen
endPosY = 351 // Below the screen
movementAngle = atan(endPosy - startPosY,endPosX -startPosX) // Calculate the Angle
posX = COS(movementAngle)
posY = SIN(movementAngle)


What I find is that posX and posY are always positive and the object I am moving always moves left to right. Do I need to do something different with the atan call to get the correct angle to send my object down the screen from top to bottom?

Edit: The above works perfectly. I got back to a part of my code which was the object coordinates being updated.

Original:
Code (glbasic) Select
self.enemyPosX = self.enemyPosX + self.enemySpeed + self.updatePosX
self.enemyPosY = self.enemyPosY + self.enemySpeed + self.updatePosY


Updated - Works perfectly just had to multiply my update although I may re-order the math operation
Code (glbasic) Select
self.enemyPosX = self.enemyPosX + self.enemySpeed * self.updatePosX
self.enemyPosY = self.enemyPosY + self.enemySpeed * self.updatePosY




Owlcat has wise

matchy

Alternative syntax example:
Code (glbasic) Select

INC self.enemyPosX,  COS(self.enemyAngle)*self.enemySpeed
INC self.enemyPosY, -SIN(self.enemyAngle)*self.enemySpeed

;)

XanthorXIII

Quote from: matchy on 2010-Nov-03
Alternative syntax example:
Code (glbasic) Select

INC self.enemyPosX,  COS(self.enemyAngle)*self.enemySpeed
INC self.enemyPosY, -SIN(self.enemyAngle)*self.enemySpeed

;)

SHOW OFF! :P j/k I'm still learning and any information I get is great.
Thanks!
Owlcat has wise

matchy

It's standard code in the samples I believe.  :P

Also, to install simple collision, store the previous position;
Code (glbasic) Select
self.enemyPosX_last=self.enemyPosX and perform collision detection with a box or line distance, and reset back, after the trig calcs, to the last position for collided. Also side stepping can be created by differencing 90' from the trig calcs.

Sometimes, forcing the angle within 360, which helps for debugging spinning objects at least.  :)
Code (glbasic) Select


// angle_clean(540) --> 180

FUNCTION angle_clean: angle_raw
IF angle_raw   <0 THEN INC angle_raw,360.0
IF angle_raw>=360 THEN DEC angle_raw,360.0
RETURN angle_raw
ENDFUNCTION