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

Function to get relative position and orientation of one object to another. #1353

Open
Tinter opened this issue Jul 6, 2020 · 2 comments
Open
Labels

Comments

@Tinter
Copy link
Contributor

Tinter commented Jul 6, 2020

As per the other issue, this is something I stumbled upon working on my own project, which involves placing furniture in buildings.
Getting the position and orientation of one object, could be a piece of furniture called A, to another, could be a house called B, is not trivial, at least I spent a long time figuring this out. Neither is setting the world position and orientation of A so that it is the correct position and orientation relative to B.

The following functions are what I and Nigel, who was an immense help, have found to be the most consistent way of doing this.

tint_fnc_getRelPosAndOrientation = {
  param["_objA", "_objB"];
  _pos = getPosWorld _objA;
  if (!(surfaceIsWater _pos)) then {
    _pos = ASLToATL _pos;
  };
  _relativePos = _objB worldToModel _pos;
  _relativeOrientation = ([_objA, _objB] call BIS_fnc_vectorDirAndUpRelative);

  [_relativePos, _relativeOrientation]
};

tint_fnc_setRelPosAndOrientation = {
  param["_objA", "_objB", "_relPosAndOrientation"];
  _relPos = _relPosAndOrientation#0;
  _relOrientation = _relPosAndOrientation#1;
  _relDir = _relOrientation#0;
  _relUp = _relOrientation#1;
  
  _objA setVectorDirAndUp [_objB vectorModelToWorld _relDir, _objB vectorModelToWorld _relUp];
  _objA setPosWorld (_objB modelToWorldWorld _relPos);
};

These are just for clarification's sake, I don't know whether the return type is good or if these should be split up into separate functions, but the point of confusion is that there are many different commands to set and get positions and it is only this combination of them that seems to work.

@Tinter Tinter added the Feature label Jul 6, 2020
@commy2
Copy link
Contributor

commy2 commented Jul 6, 2020

getPos and getDir have alt syntaxes that do this, no?

@Tinter
Copy link
Contributor Author

Tinter commented Jul 7, 2020

The specific application is when working in model space and rotation not just in the Z axis, but the X and Y axis as well.

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

No branches or pull requests

2 participants