Deltanic Posted October 16, 2010 Share Posted October 16, 2010 Simple question, difficuilt answer lol.. I know it's possible, because the Grapple recourse uses it too, but I can't figure out how to do the job. I want to calculate the face of some pointed wall, so I would be possible to place an object to it, perfectly iligned to the wall. Since the Grapple resource can do it (Your player will always be flat to some wall), and I don't know how Grapple did it (Well, a little bit. But there's no explanation in that script, so I don't know what to use and what not.) I wanna ask how I can do this myself. Anyone has a simple example for me? Or even a fully working math? Link to comment
dzek (varez) Posted October 16, 2010 Share Posted October 16, 2010 its probably getting world position of cursor on click (check this). you can also get player position, get his rotation, and find a point 10000 units away, and processLineOfSight to find first hit position Link to comment
Deltanic Posted October 16, 2010 Author Share Posted October 16, 2010 Well, the problem is that that's exactly the point I already know Now I need to get the rotation of some surface, so I can place an object perfectly aligned to it. Link to comment
dzek (varez) Posted October 16, 2010 Share Posted October 16, 2010 a lot of possibilities.. it will be hard one i think. you have to process two line of sight (1 and 2). you know the angle near player (point A) and you can count the length of 1 and 2. and you can count the green line too. having one angle and all three lengths should be enough to count missing angles (search wikipedia.org for trigonometry - should be not so hard). after you got these angles you are able to get the face angle of the wall. the problem is when the object is not so wide and your 2nd line will not hit the wall Link to comment
Deltanic Posted October 16, 2010 Author Share Posted October 16, 2010 my brains are dead Link to comment
dzek (varez) Posted October 16, 2010 Share Posted October 16, 2010 had the same when was creating driving bot - a lot of math o_O but near angles (turn angle, car angle, car-to-waypoint-angle) and distances i also need speed. my brain was burning about week after doing this anyway - good luck Link to comment
DiSaMe Posted October 16, 2010 Share Posted October 16, 2010 Something like this: local we1,wx1,wy1,wz1,e1 = processLineOfSight(sx,sy,sz,dx,dy,dz) local we2,wx2,wy2,wz2,e2 = processLineOfSight(sx,sy,sz,dnx,dny,dnz) local angle = -math.deg(math.atan2(wx1-wx2,wy1-wy2)) sx,sy,sz are source coordinates, dx,dy,dz are destination coordinates and dnx,dny,dnz are coordinates near the destination. If you get dx,dy,dz from screen (let's say pixels are sx,sy), you can get dnx,dny,dnz from the pixel which is right from the first (sx+1,sy). edit: this is for vertical surfaces. It would need some more work to get vertical angle. Link to comment
eAi Posted October 16, 2010 Share Posted October 16, 2010 I've submitted a bug to add support for this: http://bugs.mtasa.com/view.php?id=5601 You can imitate it though by doing three pLoS calls in a triangle, though bear in mind that this function is quite expensive. Link to comment
Deltanic Posted October 22, 2010 Author Share Posted October 22, 2010 Something like this: local we1,wx1,wy1,wz1,e1 = processLineOfSight(sx,sy,sz,dx,dy,dz) local we2,wx2,wy2,wz2,e2 = processLineOfSight(sx,sy,sz,dnx,dny,dnz) local angle = -math.deg(math.atan2(wx1-wx2,wy1-wy2)) local sx, sy, sz = getElementPosition ( getLocalPlayer ( ) ) local scx, scy = getScreenFromWorldPosition ( hitX, hitY, hitZ, 0, false ) local dnx, dny, dnz = getWorldFromScreenPosition ( scx+1, scy, depth ) local we1,wx1,wy1,wz1,e1 = processLineOfSight(sx,sy,sz,hitX,hitY,hitZ) local we2,wx2,wy2,wz2,e2 = processLineOfSight(sx,sy,sz,dnx,dny,dnz) local rotZ = -math.deg(math.atan2(wx1-wx2,wy1-wy2)) Now I need to get the depth. I do know a little bit about it, but that bit is not enough to know how to do it before my brains are getting crushed again. What I've did is this: local w, h = guiGetScreenSize () local tx, ty, tz = getWorldFromScreenPosition ( w/2, h/2, 500 ) local px, py, pz = getCameraMatrix() hit, x, y, z, elementHit = processLineOfSight ( px, py, pz, tx, ty, tz ) depth = math.sqrt ( px*x + py*y + pz*z ) But I don't think that's correct, is it? And @ eAi: I would love you if that's gonne be implemented in 1.1. Link to comment
Puma Posted October 24, 2010 Share Posted October 24, 2010 Ohai Remi, tijdje niet gesproken .. ------------------------------------------------- You'll have to procces two "LineOfSight"s so you get two positions on the same wall. Using the coördinates of those two positions, you can calculate the angle between it. I did it for my shells-script for Mario Kart and I'm still not sure if I have the right calculation (since the rotations in GTA are a bit weird (when you rotate a car 90 degrees, it is pointed WEST while it should be pointed to the EAST, so the Z-rotation works non-clockwise). You'll need some mathematical knowledge for this... It's not simple. Link to comment
Deltanic Posted October 24, 2010 Author Share Posted October 24, 2010 PUMBEER!! Maarehm, that isn't the distance between 2 points, which is my second question. I need the depth for getWorldFromScreenPosition, which should be able to get with 1 pLoS by using its start and hit point. Then I need the square root of those poins (mat.sqrt), but the fact is that I don't know how to work with square roots, and that my code is probably wrong either. I'm near it, I know that But I don't know how to do it working. Link to comment
Puma Posted October 24, 2010 Share Posted October 24, 2010 https://wiki.multitheftauto.com/wiki/Get ... enPoints3D Get the Distance Between two Points in 3D? Link to comment
Deltanic Posted October 29, 2010 Author Share Posted October 29, 2010 local sx, sy, sz = getElementPosition ( getLocalPlayer ( ) ) local scx, scy = getScreenFromWorldPosition ( hitX, hitY, hitZ, 0, false ) local w, h = guiGetScreenSize () local tx, ty, tz = getWorldFromScreenPosition ( w/2, h/2, 500 ) local px, py, pz = getCameraMatrix() local hit, dx, dy, dz, elementHit = processLineOfSight ( px, py, pz, tx, ty, tz ) local depth = getDistanceBetweenPoints3D ( px, py, pz, dx, dy, dz ) local dnx, dny, dnz = getWorldFromScreenPosition ( scx+1, scy, depth ) local we1, wx1, wy1, wz1, e1 = processLineOfSight ( sx, sy, sz, hitX, hitY, hitZ ) local we2, wx2, wy2, wz2, e2 = processLineOfSight ( sx, sy, sz, dnx, dny, dnz ) local rotZ = math.deg ( math.atan2 ( wx1-wx2, wy1-wy2 ) ) Does return angles, but not always. And it doesn't return the right angles. Every time the player has a different position, the angle will be different either. So, what to do now? Link to comment
Deltanic Posted November 2, 2010 Author Share Posted November 2, 2010 Damn, I feel so bad if I need to bump. Last time though, otherwise no-one just knows how to calculate the face of a wall like me. Anyone? Link to comment
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