Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


360 degrees for full rotation

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
AntonVit
Advanced Cheater
Reputation: 0

Joined: 25 Jan 2014
Posts: 73

PostPosted: Sat Dec 17, 2016 3:19 am    Post subject: 360 degrees for full rotation Reply with quote

Hi all.
I tryed to convert Cosinus and Sinus values to just degrees.
Cosinus and Sinus has value batween -1 to 1.
I need a values from 0 to 360 degrees, for rotat bgsprite in d3d on screen, but in game i have only cosinus and sinus. Need to convert it to degrees,
I tryed use many ways but not working

tryed:

Code:

a = MyCar_Sinus.Value
b = math.asin(a)
c = math.deg(b)

a1 = MyCar_Cosinus.Value
b1 = math.acos(a1)
c1 = math.deg(b1)

DegresesValue = c+c1


or

Code:

Tangens = MyCar_Sinus.Value / MyCar_Cosinus.Value
a = math.atan(Tangens)
a1 = math.deg(a)
DegresesValue = a1

Not work too

In net cant find way how to recolculate to just degreese.
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Sat Dec 17, 2016 5:09 am    Post subject: Reply with quote

math.deg , math.rad
Convert from radians to degrees and vice versa.

Use Cheat Engine 6.5.1 or higher (work with Lua 5.3)

Code:
x = math.sin(0.123)
a = math.deg(x)
s = string.char(39)

print(a)
print( string.format( "%6.2f", a )..s )
print( "or "..string.format( "%6.2f", a ).." ".."Degrees" )

-- Result
7.0296243464734
  7.03'
or   7.03 Degrees


from your code :

Code:
MyCar_Sinus = -0.234
MyCar_Cosin = 0.234
Sin_deg = math.deg(math.asin(MyCar_Sinus))
Cos_deg = math.deg(math.acos(MyCar_Cosin))
DegresesValue1 = Sin_deg + Cos_deg
print("Degrees Value : "..DegresesValue1)

Tangens = MyCar_Sinus / MyCar_Cosin
Tan_deg = math.deg(math.atan(Tangens))
print("Degrees Value From Tangens : "..Tan_deg)


Degrees Value : 62.934632926341
Degrees Value From Tangens : -45.0
Back to top
View user's profile Send private message
AntonVit
Advanced Cheater
Reputation: 0

Joined: 25 Jan 2014
Posts: 73

PostPosted: Sat Dec 17, 2016 6:23 am    Post subject: Reply with quote

Thank
Tryed now on last 6.6 CE

Code:
x = math.sin(0.123)
a = math.deg(x)
s = string.char(39)

print(a)
print( string.format( "%6.2f", a )..s )
print( "or "..string.format( "%6.2f", a ).." ".."Degrees" )

-- Result
7.0296243464734
  7.03'
or   7.03 Degrees


It get me not correct value, i mean can not give me value from 0 to 360



Code:
MyCar_Sinus = -0.234
MyCar_Cosin = 0.234
Sin_deg = math.deg(math.asin(MyCar_Sinus))
Cos_deg = math.deg(math.acos(MyCar_Cosin))
DegresesValue1 = Sin_deg + Cos_deg
print("Degrees Value : "..DegresesValue1)


Too can not get value from 0 to 360

Code:

Tangens = MyCar_Sinus / MyCar_Cosin
Tan_deg = math.deg(math.atan(Tangens))
print("Degrees Value From Tangens : "..Tan_deg)

Degrees Value : 62.934632926341
Degrees Value From Tangens : -45.0


And this script too can not get value from 0 to 360


With this script value can be form 0 to 180 (and back from 180 to 0)
Code:

MyCar_Cosin = -0.9983792901
Cos_deg = math.deg(math.acos(MyCar_Cosin))
DegresesValue1 = Cos_deg
print("Degrees Value : "..DegresesValue1)


So i have now 1 idea how recolculate to value from 0 - 360
Some later i try to test, and then write result
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Sat Dec 17, 2016 8:40 am    Post subject: Reply with quote

If you want the result as rounded floating number without decimal or point.

Code:
MyCar_Cosin = -0.9983792901
Cos_deg = math.deg(math.acos(MyCar_Cosin))
DegresesValue1 = Cos_deg
print("Degrees Value : "..string.format( "%6.f", DegresesValue1))


Degrees Value :    177
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Sat Dec 17, 2016 8:45 am    Post subject: Reply with quote

To convert from radians to degrees you simply multiply it by
57.295779513082320876798154814105

so:
Code:
rotFromSin = math.asin(sinvalue) * 57.29577951308232


or
Code:
rotFromCos = math.acos(cosvalue) * 57.29577951308232


math.asin and math.acos takes value between -1 and 1 as argument.

rotFromSin value is between -90° and 90° (is 180° wide)
rotFromCos value is between 0° and 180° (is 180° wide)




You want rot between 0° and 360°

Now look at this:
Code:
https://www.google.pl/search?q=sin(x)%2C+cos(x)


As you see we can not determine our rot by just using one.

Also executing this should convince you:
Code:
function test(realRot)
  local sinval = math.sin(realRot / 57.29577951308232)
  local cosval = math.cos(realRot / 57.29577951308232)

  -- let's pretend that sinval and cosval are taken from game process

  local rotFromSin = math.asin(sinval) * 57.29577951308232
  local rotFromCos = math.acos(cosval) * 57.29577951308232

  return string.format('sinval:%8.3f cosval%8.3f asin%8.3f acos%8.3f',sinval,cosval,rotFromSin,rotFromCos)
end

print(test(10))
print(test(80))
print(test(100))
print(test(170))
print(test(190))
print(test(250))
print(test(290))


Result:
Code:
sinval:   0.174 cosval   0.985 asin  10.000 acos  10.000
sinval:   0.985 cosval   0.174 asin  80.000 acos  80.000
sinval:   0.985 cosval  -0.174 asin  80.000 acos 100.000
sinval:   0.174 cosval  -0.985 asin  10.000 acos 170.000
sinval:  -0.174 cosval  -0.985 asin -10.000 acos 170.000
sinval:  -0.940 cosval  -0.342 asin -70.000 acos 110.000
sinval:  -0.940 cosval   0.342 asin -70.000 acos  70.000





You have to take into account both sinval and cosval.
Code:
function test(realRot)
  local sinval = math.sin(realRot / 57.29577951308232)
  local cosval = math.cos(realRot / 57.29577951308232)

  -- let's pretend that sinval and cosval are taken from game process

  local rotFromSin = math.asin(sinval) * 57.29577951308232
  local rotFromCos = math.acos(cosval) * 57.29577951308232

  local rot360 = rotFromCos
  if sinval < 0 then rot360=360-rot360 end

  return string.format('sinval:%8.3f cosval%8.3f asin%8.3f acos%8.3f rot360%8.3f',sinval,cosval,
                        rotFromSin,rotFromCos,rot360)
end

print(test(10))
print(test(80))
print(test(100))
print(test(170))
print(test(190))
print(test(250))
print(test(290))



Result:
Code:
sinval:   0.174 cosval   0.985 asin  10.000 acos  10.000 rot360  10.000
sinval:   0.985 cosval   0.174 asin  80.000 acos  80.000 rot360  80.000
sinval:   0.985 cosval  -0.174 asin  80.000 acos 100.000 rot360 100.000
sinval:   0.174 cosval  -0.985 asin  10.000 acos 170.000 rot360 170.000
sinval:  -0.174 cosval  -0.985 asin -10.000 acos 170.000 rot360 190.000
sinval:  -0.940 cosval  -0.342 asin -70.000 acos 110.000 rot360 250.000
sinval:  -0.940 cosval   0.342 asin -70.000 acos  70.000 rot360 290.000





So, taking most important thing, you have to use this:
Code:
  local rot360 = math.acos(cosval) * 57.29577951308232
  if sinval < 0 then rot360 = 360 - rot360 end




If you don't like above solution with additional "IF THEN", you can also use this one liner:
Code:
local rot360 = (math.atan(sinval,cosval) * 57.29577951308232) % 360

_________________
Back to top
View user's profile Send private message MSN Messenger
AntonVit
Advanced Cheater
Reputation: 0

Joined: 25 Jan 2014
Posts: 73

PostPosted: Sun Dec 18, 2016 1:35 am    Post subject: Reply with quote

Thank All fol Help
Thank mgr.inz.Player, it very helpfull


This get me value from 0-360 perfectly
Code:
local rot360 = (math.atan(sinval,cosval) * 57.29577951308232) % 360


But what mean this "%" - it is a persent? How calculate it code in assembler. In lua engine work perfectly, bur i want write it to instuction, for not using timer in lua.

Tryed like this, not know what next
Code:

globalalloc(SinValue,100)
globalalloc(CosValue,100)
globalalloc(Tangens,100)
globalalloc(Atan,100)
globalalloc(DegresesConverterValue,100)

DegresesConverterValue:
dd (float)57.29577951308232

fld dword ptr [esi+250]
fstp dword ptr [SinValue]
fld dword ptr [esi+258]
fstp dword ptr [CosValue]

fld dword ptr [SinValue]
fmul dword ptr [DegresesConverterValue]
fstp dword ptr [SinValue]

fld dword ptr [CosValue]
fmul dword ptr [DegresesConverterValue]
fstp dword ptr [CosValue]

fld dword ptr [SinValue]
fdiv dword ptr [CosValue]
fstp dword ptr [Tangens]

fld dword ptr [Tangens]
fpatan
fstp dword ptr [Atan]

// ?




Tryed test
Code:

a = sinval/cosval //tangens
b = math.atan(a)
UDF1.CEEdit1.Text=b

a1 = math.atan(sinval,cosval)
UDF1.CEEdit2.Text=a1

And CEEdit1.Text ~= CEEdit2.Text
How work math.atan(sinval,cosval)?
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Sun Dec 18, 2016 6:36 am    Post subject: Reply with quote

If I am not wrong,

Code:
% is a modulo.
In computing, the modulo operation finds the remainder after division of one number by another (sometimes called modulus).

5 % 2 = 1
It's mean 5 divide by 2 will give 1 as remainder
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Sun Dec 18, 2016 7:38 am    Post subject: Reply with quote

Code:
local rot360 = (math.atan(sinval,cosval) * 57.29577951308232) % 360

math.atan returns value between -𝛑 and 𝛑 (-180° and 180° after conversion)

From Lua 5.3 manual
Quote:
math.atan (y [, x])

Returns the arc tangent of y/x (in radians), but uses the signs of both parameters to find the quadrant of the result. (It also handles correctly the case of x being zero.)

The default value for x is 1, so that the call math.atan(y) returns the arc tangent of y.


That percent sign, e.g. "x % y" is the same as this "math.fmod (x, y)"
From Lua 5.3 manual
Quote:
math.fmod (x, y)

Returns the remainder of the division of x by y that rounds the quotient towards zero. (integer/float)






AntonVit wrote:
How calculate it code in assembler

The question is, do you really need 0° - 360°?
I think sprite in d3d should also accept this range: -180° - 180°


Code:
fld dword ptr [esi+250]
fld dword ptr [esi+258]
fpatan
fmul dword ptr [DegresesConverterValue]
fstp dword ptr [Atan]







EDIT:
this doesn't make any sense:
Code:
fld dword ptr [SinValue]
fmul dword ptr [DegresesConverterValue]
fstp dword ptr [SinValue]

Why did you multiply sin value?

_________________
Back to top
View user's profile Send private message MSN Messenger
AntonVit
Advanced Cheater
Reputation: 0

Joined: 25 Jan 2014
Posts: 73

PostPosted: Sun Dec 18, 2016 7:53 am    Post subject: Reply with quote

Quote:

EDIT:
this doesn't make any sense:
Code:
fld dword ptr [SinValue]
fmul dword ptr [DegresesConverterValue]
fstp dword ptr [SinValue]

Why did you multiply sin value?



Couse i thinked that for convert to degresse need to multiply (from this code)
Code:

local rot360 = (math.atan(sinval,cosval) * 57.29577951308232) % 360


So, i tested and sprite realy can rotate with this values (-180 and 180). And can 500 and more.
So now all fine, dont need anymore use assembler for calculate 0-360
i use now in lua
Code:

if sinval < 0 then rot360 = 360 - rot360 end


Thank you, and all for help.
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Sun Dec 18, 2016 8:09 am    Post subject: Reply with quote

If it accepts -180° - 180°

just use this in asm:
Code:
fld dword ptr [esi+250]
fld dword ptr [esi+258]
fpatan
fmul dword ptr [DegresesConverterValue]
fstp dword ptr [Atan]

_________________
Back to top
View user's profile Send private message MSN Messenger
AntonVit
Advanced Cheater
Reputation: 0

Joined: 25 Jan 2014
Posts: 73

PostPosted: Sun Dec 18, 2016 9:25 am    Post subject: Reply with quote

mgr.inz.Player wrote:
If it accepts -180° - 180°

just use this in asm:
Code:
fld dword ptr [esi+250]
fld dword ptr [esi+258]
fpatan
fmul dword ptr [DegresesConverterValue]
fstp dword ptr [Atan]


Ok, understand. Thank mgr.inz.Player.
Back to top
View user's profile Send private message
AntonVit
Advanced Cheater
Reputation: 0

Joined: 25 Jan 2014
Posts: 73

PostPosted: Mon Dec 19, 2016 3:55 am    Post subject: Reply with quote

mgr.inz.Player wrote:
If it accepts -180° - 180°

just use this in asm:
Code:
fld dword ptr [esi+250]
fld dword ptr [esi+258]
fpatan
fmul dword ptr [DegresesConverterValue]
fstp dword ptr [Atan]



Hi mgr.inz.Player.
Thank for asm script again. I tryed add 180 and now asm get me value from 0 - 360. But i already create racalculation on lua. But it asm too very interesting.
I used in first cosinus,sinus from car, now from camera, it more batter,
Code:

PLACEcamcossin:
fld dword ptr [ecx+00000180]
fld dword ptr [ecx+00000188]
fpatan
fmul dword ptr [DegresesConverterValue]
fadd dword ptr [Adds_180_Float]
fstp dword ptr [Full_360_Value]
movaps [ecx+00000190],xmm0
jmp BACKcamcossin


///////////////////////////
DegresesConverterValue:
dd (float)57.29577951308232
Adds_180_Float:
dd (float)180
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites