I have this Lua CODE:
local oBoxA = {
{ x = cx + ((Ax1 - cx) * cosAngleA) - ((Ay1 - cy) * sinAngleA) - w, y = cy + ((Ay1 - cy) * cosAngleA) + ((Ax1 - cx) * sinAngleA) - h },
{ x = cx + ((Ax2 - cx) * cosAngleA) - ((Ay2 - cy) * sinAngleA) - w, y = cy + ((Ay2 - cy) * cosAngleA) + ((Ax2 - cx) * sinAngleA) - h },
{ x = cx + ((Ax3 - cx) * cosAngleA) - ((Ay3 - cy) * sinAngleA) - w, y = cy + ((Ay3 - cy) * cosAngleA) + ((Ax3 - cx) * sinAngleA) - h },
{ x = cx + ((Ax4 - cx) * cosAngleA) - ((Ay4 - cy) * sinAngleA) - w, y = cy + ((Ay4 - cy) * cosAngleA) + ((Ax4 - cx) * sinAngleA) - h },
} |
it simply calculate vertices of my Rotated Box by an angle and work fine...
with a Box 128x256 positioned at 100,100 Pixel and rotated by 1 degree
it return
x1 y1
38.243655533963, -29.097458992004
x2 y2
166.22416051398, -26.863550968032
x3 y3
161.75634446604, 229.097458992
x4 y4
33.775839486019, 226.86355096803,
now tha same code of my C++ plugin
is
oBoxA[0].x = cx + ((Ax1 - cx) * cosAngleA) - ((Ay1 - cy) * sinAngleA) - w; <---- RESULT IS NOT CORRECT
oBoxA[0].y = cy + ((Ay1 - cy) * cosAngleA) + ((Ax1 - cx) * sinAngleA) - h; <---- RESULT OK!
oBoxA[1].x = cx + ((Ax2 - cx) * cosAngleA) - ((Ay2 - cy) * sinAngleA) - w; <---- RESULT OK!
oBoxA[1].y = cy + ((Ay2 - cy) * cosAngleA) + ((Ax2 - cx) * sinAngleA) - h; <---- RESULT OK!
oBoxA[2].x = cx + ((Ax3 - cx) * cosAngleA) - ((Ay3 - cy) * sinAngleA) - w; <---- RESULT OK!
oBoxA[2].y = cy + ((Ay3 - cy) * cosAngleA) + ((Ax3 - cx) * sinAngleA) - h; <---- RESULT OK!
oBoxA[3].x = cx + ((Ax4 - cx) * cosAngleA) - ((Ay4 - cy) * sinAngleA) - w; <---- RESULT IS NOT CORRECT
oBoxA[3].y = cy + ((Ay4 - cy) * cosAngleA) + ((Ax4 - cx) * sinAngleA) - h; <---- RESULT OK! |
but the result is:
x1, y1
>>>226.86355102359<<< -29.097458940199
x2, y2
166.22416040756 -26.863551023585
x3, y3
161.75634457433 229.0974589402
x4, y4
>>>226.86355102359<<< 226.86355102359
has you can see the x1 and x4 are not correct!
why? really i can't see the error... but the result are not the same...
i have double checked the code... vars have the same values...
cy, cx, w, h, ax1... etc have the same values... (both in lua and C++ code)
if C++ all vars declared as "double" (in lua internally numbers are double)
can you help me?
i'm going mad!
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
(
Comments
It will be so much general but the problem seems:
Somehow Lua is overwriting the variable(maybe out of scope or redifined in other scope etc) but you are not passing the correct overwritten value to c++.
Are you sure that you are converting Lua objects to C++ values as soon as they are created?
Maybe print the values of variables (debug them) and check if they are the same in lua and c++?
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
damn!!!
I just could not see it ... I'm getting old ... yes ... yes ... yes ... 8-X
thanks at @all anyway!!!
Likes: MikeHart
www.tntengine.com