Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update trace ray start vector #25

Closed
szapp opened this issue Aug 19, 2016 · 6 comments
Closed

Update trace ray start vector #25

szapp opened this issue Aug 19, 2016 · 6 comments

Comments

@szapp
Copy link
Owner

szapp commented Aug 19, 2016

By means of Pythagoras, shift the start vector to be aligned with the distance between camera and player model to be more consistent and allow different camera-model-distances.

targetVector.png

@szapp
Copy link
Owner Author

szapp commented Aug 19, 2016

cam.pos[3] + (cam.out[3] * x) = model.pos[3] - (cam.right[3] * y)

Solve for x.

cam.pos[3] + (cam.out[3] * x) is the new start vector.

@szapp
Copy link
Owner Author

szapp commented Aug 21, 2016

Simpler approach:

d = model.pos - cam.pos

d[x] = 0

d = model.pos + d

@szapp
Copy link
Owner Author

szapp commented Aug 21, 2016

This does not work, because d[x] is the world coordinate. The local coordinate of cam must be considered instead.

@szapp
Copy link
Owner Author

szapp commented Aug 21, 2016

Another failed attempt (just copying it here because it made it into no commit):

d[0] = subf(MEM_ReadInt(_@(her)+72), MEM_ReadInt(MEM_Camera.connectedVob+72));
d[1] = subf(MEM_ReadInt(_@(her)+88), MEM_ReadInt(MEM_Camera.connectedVob+88));
d[2] = subf(MEM_ReadInt(_@(her)+104), MEM_ReadInt(MEM_Camera.connectedVob+104));
const int zMAT4__Rotate = 5542544; //0x549290
CALL_PtrParam(_@(d));
CALL_RetValIsStruct(12);
CALL__thiscall(MEM_Camera.connectedVob+60, zMAT4__Rotate);
var int dPtr; dPtr = CALL_RetValAsInt();
MEM_CopyWords(dPtr, _@(d), 3);
MEM_Free(dPtr);

d[0] = FLOATNULL;
var int dist; dist = sqrtf(addf(addf(sqrf(d[0]), sqrf(d[1])), sqrf(d[2])));

d[0] = addf(MEM_ReadInt(MEM_Camera.connectedVob+72),  mulf(MEM_ReadInt(MEM_Camera.connectedVob+68),  dist));
d[1] = addf(MEM_ReadInt(MEM_Camera.connectedVob+88),  mulf(MEM_ReadInt(MEM_Camera.connectedVob+84),  dist));
d[2] = addf(MEM_ReadInt(MEM_Camera.connectedVob+104), mulf(MEM_ReadInt(MEM_Camera.connectedVob+100), dist));

@szapp
Copy link
Owner Author

szapp commented Aug 21, 2016

Now trying this: Point-Line Distance, where x0 is the point, and x1 and x2 make up the line.

  • x0 = camera
  • x1 = player model
  • x2 = help point (left/right of player model along the right-vector of the camera)
|(x0 - x1) X (x0 - x2)|      <- *
-----------------------
       |x2 - x1|

*) u X v = ((uy*vz - uz*vy), (uz*vx - ux*vz), (ux*vy - uy*vx))

@szapp
Copy link
Owner Author

szapp commented Oct 13, 2016

Fix #25 correct ray start vector

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant