Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Why? Can't see the problem here! HELP! i'm going crazy! Lua to C++ :(( — Gideros Forum

Why? Can't see the problem here! HELP! i'm going crazy! Lua to C++ :((

GregBUGGregBUG Guru
edited August 2012 in General questions
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!

:(( :(( :(( :(( :(( :(( :(( :(( :(( :(( :(( :(( :(( :(( :(( :(( :(( :(( :(( :(( :((
TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
www.tntengine.com

Comments

Sign In or Register to comment.