Jump to content

How to calculate the face of a wall?


botanist

Recommended Posts

Posted

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?

Posted

Well, the problem is that that's exactly the point I already know :P Now I need to get the rotation of some surface, so I can place an object perfectly aligned to it.

Posted

a lot of possibilities.. it will be hard one i think.

m.png

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

Posted

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 :D

anyway - good luck

Posted

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.

Posted
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.

Posted

Ohai Remi, tijdje niet gesproken :P..

-------------------------------------------------

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.

Posted

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 :P But I don't know how to do it working.

Posted
  
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?

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...