Quote: "I guess I could use it to create box same size as the screen and check"
yah, i think
kevin had it right the first time.
some useful functions for the rest (gathered from the forum/other users):
Function GetAngle2D(x1#,y1#,x2#,y2#)
angle# = atanfull(x2# - x1#, y2# - y1#)
EndFunction angle#
Function Distance2D(x1#,y1#,x2#,y2#)
distance# = sqrt((x1# - x2#)^2 + (y1# - y2#)^2)
EndFunction Distance#
Function WrapAngle(angle#)
angle# = angle# - floor(angle#/360) * 360
Endfunction angle#
i'm looking for previous code to position the points. bear with me
back with full code for positioning the points:
// Project: SpriteInScreen
// Created: 2020-05-08
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "SpriteInScreen" )
SetWindowSize( 1080, 720, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1080, 720 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
SetPrintSize(16)
This= CreateSprite(0) : SetSpriteSize(This,32,64) : SetSpritePosition(This,100,100) : SetSpriteColorAlpha(This,128)
SetSpriteShapePolygon(This,4,0,-16,-32)
SetSpriteShapePolygon(This,4,1,16, -32)
SetSpriteShapePolygon(This,4,2,16, 32)
SetSpriteShapePolygon(This,4,3,-16, 32)
Type VertData
Angle as Float
Distance as Float
EndType
Verts as VertData []
for x = 1 to GetSpriteShapeNumVertices(this,1)
ThisX# = GetSpriteShapeVertexX(This,1,x)
ThisY# = GetSpriteShapeVertexY(This,1,x)
ThisVert as VertData
ThisVert.Angle = GetAngle2D(0,0,ThisX#, ThisY#)
ThisVert.Distance = Distance2D(0,0,ThisX#, ThisY#)
Verts.Insert(ThisVert)
next x
Point as integer [] `sprite representations
for x = 0 to Verts.Length
p = CreateSprite(0)
SetSpriteSize(p,2,2)
point.Insert(p)
next x
do
PAngle# = GetSpriteAngle(this)
LR = GetRawKeyState(39) - GetRawKeyState(37)
If LR <> 0
PAngle# = WrapAngle(GetSpriteAngle(This) + LR*5.0)
SetSpriteAngle(this,PAngle#)
Endif
CX# = GetSpriteXByOffset(this)
CY# = GetSpriteYByOffset(this)
for x = 0 to Verts.Length
ThisAngle# = Verts[x].Angle
ThisDistance# = Verts[x].Distance
print( STR(ThisAngle#,2) + " @ " + STR(ThisDistance#,2) )
NewAngle# = WrapAngle(ThisAngle# + PAngle#)
SX# = CX# + SIN(NewAngle#) * ThisDistance#
SY# = CY# + -COS(NewAngle#) * ThisDistance#
SetSpritePositionByOffset(point[x],SX#,SY#)
next x
Print (GetSpriteAngle(This))
Sync()
loop
Function GetAngle2D(x1#,y1#,x2#,y2#)
angle# = atanfull(x2# - x1#, y2# - y1#)
EndFunction angle#
Function Distance2D(x1#,y1#,x2#,y2#)
distance# = sqrt((x1# - x2#)^2 + (y1# - y2#)^2)
EndFunction Distance#
Function WrapAngle(angle#)
angle# = angle# - floor(angle#/360) * 360
Endfunction angle#
since it's a rectangle, the distance to each is the same but the code leaves it a bit open for other shapes.
you can use those points to draw your lines, etc. and, i'll leave it there for you to continue working on where i've had enough exercise for now
add: you see where i created the box as a polygon vs just using a box where, disappointingly, GetSpriteShapeNumVertices doesn't work on true box shapes

added in case you were wondering.
we could still use a real box where computing the vertices manually wouldn't be too much of a chore (about the same as setting them in a polygon) but, that's another cat to skin at another time.