Moderators IIYAMA Posted December 20, 2013 Moderators Posted December 20, 2013 I am looking for findRotation math, but one that is also returning X and Y rotation. https://wiki.multitheftauto.com/wiki/FindRotation function findRotation(x1,y1,x2,y2) local t = -math.deg(math.atan2(x2-x1,y2-y1)) if t < 0 then t = t + 360 end; return t; end
K4stic Posted December 20, 2013 Posted December 20, 2013 use this: ( 360 - math.deg ( math.atan2 ( ( x - px ), ( y - py ) ) ) ) % 360 example: x, y, z = getElementPosition( player ) px, py, pz = getElementPosition( player2 ) local rotation = ( 360 - math.deg ( math.atan2 ( ( x - px ), ( y - py ) ) ) ) % 360
Moderators IIYAMA Posted December 20, 2013 Author Moderators Posted December 20, 2013 use this: ( 360 - math.deg ( math.atan2 ( ( x - px ), ( y - py ) ) ) ) % 360 example: x, y, z = getElementPosition( player ) px, py, pz = getElementPosition( player2 ) local rotation = ( 360 - math.deg ( math.atan2 ( ( x - px ), ( y - py ) ) ) ) % 360 and how do I get the X and Y rotation? Because now I also only have the Z rotation.
K4stic Posted December 20, 2013 Posted December 20, 2013 z it's just up or down they not used as rotation thing
Moderators IIYAMA Posted December 20, 2013 Author Moderators Posted December 20, 2013 z it's just up or down they not used as rotation thing It is.
K4stic Posted December 20, 2013 Posted December 20, 2013 1 think we talk about MTA physics not Real life so try my code to get rotation you can use SetElementRotation( blabla, rotation ) or return rotation
Moderators IIYAMA Posted December 20, 2013 Author Moderators Posted December 20, 2013 1 think we talk about MTA physics not Real life so try my codeto get rotation you can use SetElementRotation( blabla, rotation ) or return rotation @ CastielRecords I didn't make this topic for things I already know, I asked about getting the X and Y rotation based on finding rotation. Next to that I have lots lua experience with lua, but I don't have with 3D math. Thanks for trying to help me, but I need somebody with high math skills. Is there anybody who can help me with this?
arezu Posted December 21, 2013 Posted December 21, 2013 What exactly are you going to use it for? depending on what, you cant get X rotation, only Z and Y.
myonlake Posted December 21, 2013 Posted December 21, 2013 What exactly are you going to use it for? depending on what, you cant get X rotation, only Z and Y. If you can get the Z rotation, you can also get the X and Y rotation. It's just math with sins, cons and tans.
Moderators IIYAMA Posted December 21, 2013 Author Moderators Posted December 21, 2013 What exactly are you going to use it for? depending on what, you cant get X rotation, only Z and Y. If you can get the Z rotation, you can also get the X and Y rotation. It's just math with sins, cons and tans. sins, cos and tan isn't JUST this math. I know how they work, but I don't know how to use them with this. Since my brain can't merge the ordinary math with 3D math...... Pls give me a sample, if it is just sin cos and tan.
arezu Posted December 21, 2013 Posted December 21, 2013 What exactly are you going to use it for? depending on what, you cant get X rotation, only Z and Y. If you can get the Z rotation, you can also get the X and Y rotation. It's just math with sins, cons and tans. For example if you are using two points as reference, like in the 'findRotation' function that IIYAMA provided, then you can only get Z and Y rotation. You need at least three points to get roll (X rotation) also, otherwise roll can only be 0.
bandi94 Posted December 21, 2013 Posted December 21, 2013 Pitch / Yaw ( Y , Z ) roation is prity simple to calculate It's not coded in LUA , it's C++ , i just C+P it from my old aimbot used in some FPS game's , but the math is the same just need to be recoded to LUA. D3DXVECTOR3 NewVector; NewVector.x = pClientInfo->g_pLocal->Pos.x - g_pESP.pPlayers[AimAt].Aimcords.x; NewVector.y = pClientInfo->g_pLocal->Pos.y - g_pESP.pPlayers[AimAt].Aimcords.y; NewVector.z = pClientInfo->g_pLocal->Pos.z - g_pESP.pPlayers[AimAt].Aimcords.z; float CamYaw = (float)atanf(NewVector.x/NewVector.z); if(NewVector.z > 0.0f && NewVector.x < 0.0f && CamYaw < 0.0f) CamYaw += D3DX_PI; else if(NewVector.z > 0.0f && NewVector.x > 0.0f) CamYaw += D3DX_PI; DWORD tempKey = 0; switch(AimbotKey) { default: tempKey = VK_LBUTTON; break; case 1: tempKey = VK_RBUTTON; break; case 2: tempKey = VK_SHIFT; break; } if((GetAsyncKeyState(tempKey) && !Aimbotkeyon) || (Aimbotkeyon)) { pClientInfo->g_pLocal->pitch = (float)atan2f(NewVector.y,(float)sqrt(pow(NewVector.z,2) + pow(NewVector.x,2))); pClientInfo->g_pLocal->yaw = CamYaw;
Moderators IIYAMA Posted December 22, 2013 Author Moderators Posted December 22, 2013 what is Pitch and Yaw in lua? Can you explain a bit more, because I sorry but I have no idea how this is working.
bandi94 Posted December 22, 2013 Posted December 22, 2013 what is Pitch and Yaw in lua?Can you explain a bit more, because I sorry but I have no idea how this is working. In 3D world / plan is Pitch / Yaw / Roll. They are the 3 axis rotation. Pitch = Y rot , Yaw = Z rot , Roll = X rot. In MTA for a better understanding they call'd them X,Y,Z rot , but in game coding they are call'd Pitch / Yaw / Roll and most of the time they are used on the Camera , Pitch / Yaw is look up-down , left-right , and Roll is used to tilt the camera in MTA one exemple would be the "drunk camera" where it get shake'd. And even now i can't imagine where you wanna use them.
denny199 Posted January 2, 2014 Posted January 2, 2014 function findPitch(camerax,cameray,cameraz,pointx,pointy,pointz) local dX=camerax-pointx local dY=cameraz-pointz local dZ=cameray-pointy local pitch=math.atan2(dY,math.sqrt(math.pow(dZ,2) + math.pow(dX,2))); return pitch end Converted from bandi's code, already sended to IIYAMA via skype, I just felt of sharing it. And I don't think that Roll is needed. Also it's returned in radians here's the code for converting it to degrees: local degree = pitchReturn*(180/math.pi) pitchReturn = the return of the function "findPitch", it was just a simple google
Moderators IIYAMA Posted January 3, 2014 Author Moderators Posted January 3, 2014 Danny, thank you very much! It works great! Bandi thanks for explaining about the camera rotation. It seems it didn't needed the Y rotation after all. Also thanks to everybody that replied on this topic.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now