Jump to content
NumbNutsJunior

GUI 3D Object Direction/Up Vectors (pls help)

Recommended Posts

I am trying to make a 3D object point to a position in GUI. I have the object at `z = 0.25`, I assume that the other 2D controls would be at `z = 0.00`. I have tested in the eden editor with the following code, and it works perfectly fine...

// ...
private _screw_driver_pos = position screwdriver;
private _can_pos = position can;

// ...
private _dir_vector = _screw_driver_pos vectorFromTo _can_pos;

// ...
private _random_direction = [random 100, random 100, random 100];
_random_direction = vectorNormalized _random_direction;

// ...
private _up_vector = _dir_vector vectorCrossProduct _random_direction;
_up_vector = vectorNormalized _up_vector;

// ...
screwdriver setVectorDirAndUp [_dir_vector, _up_vector];

This is the result of that:
HBqAV5L.png

This is the code when working with the gui controls...

// DEBUG
debug_control_01 ctrlSetPosition [_screw_driver_tip_position_x, _screw_driver_tip_position_y];
debug_control_01 ctrlCommit 0;

// DEBUG
debug_control_02 ctrlSetPosition [_screw_driver_position_x, _screw_driver_position_y];
debug_control_02 ctrlCommit 0;

// Get the screwdriver's current position and desired tip position
private _screw_driver_position = [_screw_driver_position_x, _screw_driver_position_z, _screw_driver_position_y];
private _screw_driver_tip_position = [_screw_driver_tip_position_x, _screw_driver_tip_position_z, _screw_driver_tip_position_y];

// Update the screwdriver's position
_screw_driver_object ctrlSetPosition _screw_driver_position;

// Calculate the screwdriver's direction based on the tip position
private _screw_driver_dir = _screw_driver_position vectorFromTo _screw_driver_tip_position;

// ...
private _random_direction = [random 100, random 100, random 100];
_random_direction = vectorNormalized _random_direction;

// ...
private _screw_driver_up = _screw_driver_dir vectorCrossProduct _random_direction;
_screw_driver_up = vectorNormalized _screw_driver_up;

// Update the screwdriver's direction
_screw_driver_object ctrlSetModelDirAndUp [_screw_driver_dir, _screw_driver_up];

This is the result of that:
yWaOYlD.png

If you understand why this happens or what I need to do to fix this, please help. The screwdriver's tip is supposed to be pointing at the red dot in the lock @Dedmen @killzone_kid

Added github branch for more context: https://github.com/NumbNutsJunior/Active-Lockpicking/blob/screwdriver/Lockpicking.VR/hud/functions/fn_hud_lockpick.sqf

  • Like 1

Share this post


Link to post
Share on other sites
9 hours ago, NumbNutsJunior said:

If you understand why this happens or what I need to do to fix this, please help.

 

Logically the only thing that differs is your position input right?

My vector math is a bit rusty so take this with a grain of salt but a couple of observations:

9 hours ago, NumbNutsJunior said:

// Get the screwdriver's current position and desired tip position private _screw_driver_position = [_screw_driver_position_x, _screw_driver_position_z, _screw_driver_position_y]; private _screw_driver_tip_position = [_screw_driver_tip_position_x, _screw_driver_tip_position_z, _screw_driver_tip_position_y];

1. I don't know what _position_x, _position_y and _position_z contains since you don't show them being computed but here you using the order XZY, are you sure this is the correct representation? In most cases A3 uses XYZ but sometimes it doesn't. Just worth double-checking.  Edit: checked the docs, XZY is correct.

 

2. The angle between the screw driver and the horizontal axis seem very similiar to the angle between same axis and the desired vector...

I'm gonna hazard a guess the resulting vector is incorrectly reflected around the horizontal. If that's the case you probably need to invert the input corresponding to the vertical axis, once you figure out whichever that is.

Edit: Nvm, was an illusion on a smaller screen.

 

As a debugging tool you can add the ability to move the screwdriver in a circle around the desired target so you can get a better feel for the problem.

Otherwise I'd say start printing out the variables and see where the numbers stop making sense.

 

Hope that helps!

Share this post


Link to post
Share on other sites
On 7/10/2024 at 5:27 AM, killzone_kid said:

my guess is because x,y,z vs x,z,y issue


Unfortunately, this guess didn't solve it, the screwdriver still points down, and out of the screen... I figured it would work similar to the results of my world object testing but which is not what I would expect when using vectorFromTo. I've added a github branch so you can get this context of what's being worked on. I did try to use your old GUI part 6 tutorial for some help initially, another annoying cavet was that the objects in a user defined display, always seem to be placed behind the 2d controls regardless of the order in which they are defined. I was curious how the avatar creator does it but my work around was just creating another gui since I'm using cutRsc and they can have different layers unlike dialog.

OKGzpdT.png

From more testing, it might be due to the x,y positions not being in the center of the lockpick but there are no commands to get the object bounding box for gui objects... id have to reference an object in the world using boundingBoxReal maybe?

4u3etpV.png

Github: https://github.com/NumbNutsJunior/Active-Lockpicking/blob/screwdriver/Lockpicking.VR/hud/functions/fn_hud_lockpick.sqf

Thanks again sorry it took so long to reply, I've been away from computer for a bit.

Share this post


Link to post
Share on other sites
On 7/9/2024 at 4:16 AM, mrcurry said:

As a debugging tool you can add the ability to move the screwdriver in a circle around the desired target so you can get a better feel for the problem.

Otherwise I'd say start printing out the variables and see where the numbers stop making sense.


Yeah, that does sound useful, this is my first time working with GUI objects so I probably should have started doing it that way lol

Added github link to post if you can see any other silly vector mistakes maybe (currently lines 189-266)

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×