ROTOSPRITE not working properly

Previous topic - Next topic

graffix989

so im having a problem with ROTOSPRITE. My goal here is as follows:

identify the image (sprite) as being at an angle, or not straight
using the Tangent formula to find the angle needed to straighten
use ROTOSPRITE command to straighten
GRABSPRITE to grab the new "straight" image

my problem lies within the math result, my goal for this particular image is -1.71 deg.
opposite# = 64.5  // length of side
adjacent# = 660  // length of side
tan(opposite#/adjacent#) = result#  // tan formula for angle
result# = result# - (result# * 2)  // negate the result so ROTOsprite rotates the correct way...

this makes result# = -1.705664332e-003
ROTOSPRITE doesnt seem to be able to make that request so it does nothing, is there a way to trim everything in result beyond the one thousants place? -1.71xxxxxxxxxx delete the x's??

ive tried integer(), left$(), and converting from # to %

MrTAToad

The result is -0.001705664322, is which very near 0, hence not doing anything.  Do you need to take into account the current angle and then add/subtract from that ?

graffix989

#2
i need the half of the current angle in a negative form.

and it currently result# = -1.705xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
... dunno how u came up with that result?

so basicaly i need to know how to get the result from a tangent formula to only give me the result with 2 places past the decimal... or how to convert that long result to only -1.71

erico

I think you could use the INTEGER command for that:
a%=INTEGER(b#)

While on GLB editor, press f1 and check if that command suits your needs :good:

graffix989

"ive tried integer(), left$(), and converting from # to %"

integer() returns 1
left$() returns 1
converting # to % returns 1
:giveup:

MrTAToad

Try this :

Code (glbasic) Select
opposite#=54.5
adjacent#=660
result#=TAN(opposite/adjacent)
result#=result#-(result#*2)
DEBUG result#+"\n"
DEBUG INTEGER(result#)


You will get the correct integer value of 0.  I dont get -1.705664332e-003 though - I get -1.44121985e-003

graffix989

you used 54.5 not 64.5... but reguardless. now take your "result#" and use it with ROTOSPRITE. it will refuse the command?... atleast mine does... now try the rotosprite again just with manualy entering only the first 3 places of your result... ROTOSPRITE blah blah -1.44 and it will work.

so again if anyone can answer my question, it would be great :)

graffix989

 :booze: K so solved my own problem.. from what i could tell the large number was confusing the command ROTOSPRITE, and by large i mean the number of digets beyond the decimal. so my work around was as follows:
opposite# = 64.5
adjacent# = 660
result# = tan(opposite#/adjacent#)   // result# at this point 1.705664332e-003
temp$ = result#  // the string now reads 1.705664332e-003
temp$ = LEFT$(temp$,4)   // the string now reads 1.70
result# = temp$  // result# now reads 1.70

dunno why i didnt think of that before, but now divide by 2 and get my .85 then negate and use rotosprite with a -0.85 angle and my sprite is exactly where it needs to be... yay
I would assume there should be an easier way, and im like %90 sure that integer(result#) should give me 1.71 and drop all the rest, but it didn't... thanks for all that posted

MrTAToad

Quote from: graffix989 on 2013-Feb-07
you used 54.5 not 64.5... but reguardless. now take your "result#" and use it with ROTOSPRITE. it will refuse the command?... atleast mine does... now try the rotosprite again just with manualy entering only the first 3 places of your result... ROTOSPRITE blah blah -1.44 and it will work.

so again if anyone can answer my question, it would be great :)
Yes, should have used 64.5

However neither a variable nor an absolute value visible rotates my sprite because the value is too small.  It could be you do something else to the value too...

graffix989

#9
"However neither a variable nor an absolute value visible rotates my sprite because the value is too small.  It could be you do something else to the value too..."


?? what are you talking about, rotosprite command with 0.8 for an angle will move the sprite... even 0.01 for that matter. You seemed to miss my last post where i solved this problem, thx for the input tho.?.?.?

i think you might be miscalculating your tangent formula, your result of -0.001705664322 is from your calculation error... tan(opp/adj)  is not the same as opp/adj = ans, tan(ans) that would give you -0.001705664322, whereas tan(opp/adj) give -1.705664332e-003

but  anyways my problem was the number of didgets the rotosprite responds too, it seemed to work fine with lets say 5.55 angle, but do it again with 5.555555555555555555555555555555555555555555555555555555555555555555555555555555555555555
and it will ignore the command (not fail, but ignore) which i assume is an error in the compiler from basic to C or whatever native language the compiler drives from

Marmor

Hmm ,who need a rotozoomsprite with 5,55555555555x5  :puke:
Ill guess glb cut this number after some digits internaly.

Slydog

FYI - here's how you round a float to two decimal places:
Code (glbasic) Select
floatNumber = 12.345678
floatNumber = INTEGER(floatNumber * 100.0) / 100.0


I just found this function I made to round floats:
Code (glbasic) Select
FUNCTION Round: value#, decimals%
    LOCAL factor#
    factor = POW(10.0, decimals)
    value = INTEGER(value * factor) / factor
    RETURN value
ENDFUNCTION


Usage:
Code (glbasic) Select
floatNumber = Round(floatNumber, 2)
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]