Vector 3D constructor accepting a sequence of vectors

For test results, bug reports, announcements of new builds etc.

Moderators: winston, another_commander, Getafix

Post Reply
dybal
---- E L I T E ----
---- E L I T E ----
Posts: 499
Joined: Mon Feb 10, 2020 12:47 pm

Vector 3D constructor accepting a sequence of vectors

Post by dybal »

I corrected a bug in an OXP yesterday that involved finding the final world-coordinates of a docking bay in a station.

The original code had something like this (I changed the variable names to make their roles clearer):

Code: Select all

Vector3D( _station.heading.direction().multiply( _subentity.position.z ), _station.vectorUp.direction().multiply( _subentity.position.y ), _station.vectorRight.direction().multiply( _subentity.position.x ) ) 
The trouble here is that:

_station.heading.direction().multiply( _subentity.position.z ) is a vector
_station.vectorUp.direction().multiply( _subentity.position.y ) is a vector
_station.vectorRight.direction().multiply( _subentity.position.x ) is a vector

So Vector3D constructor accepted a sequence of 3 vectors, which isn't a vector expression.

It should accept a sequence of operations over vectors (as each of the members of that sequence is), or a sequence of 3 scalars (which is what I think was what the bugged code was aiming at).
cag
Deadly
Deadly
Posts: 202
Joined: Fri Mar 17, 2017 1:49 am

Re: Vector 3D constructor accepting a sequence of vectors

Post by cag »

dybal wrote: Tue Jul 07, 2020 1:49 pm
I corrected a bug in an OXP
...
_station.heading.direction().multiply( _subentity.position.z ) is a vector
_station.vectorUp.direction().multiply( _subentity.position.y ) is a vector
_station.vectorRight.direction().multiply( _subentity.position.x ) is a vector
FYI, the .direction() calls are not necessary, as .heading, .vectorUp & .vectorRight are already unit vectors. Only matters if this code is in a Timer or a FrameCallback.
"Better to be thought a fool, boy, than to open your trap and remove all doubt." - Grandma [over time, just "Shut your trap... fool"]
"The only stupid questions are the ones you fail to ask." - Dad
How do I...? Nevermind.
dybal
---- E L I T E ----
---- E L I T E ----
Posts: 499
Joined: Mon Feb 10, 2020 12:47 pm

Re: Vector 3D constructor accepting a sequence of vectors

Post by dybal »

Thanks, cag!

Yes, it's in FB callback, I will adjust it (I agree with you, every little bit helps in high-freq code)
Post Reply