garrysmod icon indicating copy to clipboard operation
garrysmod copied to clipboard

Added: Function `GetOrthogonal` for easier othogonalization of a 2 ve…

Open dvdvideo1234 opened this issue 4 years ago • 29 comments

Utilize: vector/angle method Unpack in TypeToString finction

dvdvideo1234 avatar Nov 22 '19 07:11 dvdvideo1234

This date commit also reduces 6 string concatenations and one table extraction.

dvdvideo1234 avatar Nov 22 '19 08:11 dvdvideo1234

  1. You should not bundle unrelated changes together.
  2. You should mention that this PR is reliant on your other Vector PR.
  3. You should probably make the name GetOrghogonalVector or something.

Kefta avatar Nov 22 '19 13:11 Kefta

Garrysmod is not Matlab. Don't expect generic math function to be added to the library. They are just code bloat.

thegrb93 avatar Nov 22 '19 20:11 thegrb93

Garrysmod is not Matlab. Don't expect generic math function to be added to the library. They are just code bloat.

I mean, not really. The GMod Lua library has tons of "generic math functions"

Its a good change. Makes things easier, that is a fine update for me.

GrahamBest avatar Nov 23 '19 16:11 GrahamBest

generic was the wrong adjective. I meant very specific use case and won't be used often.

thegrb93 avatar Nov 24 '19 06:11 thegrb93

@thegrb93 @Kefta

Is the date change fine then ? I am just using OS.date and it is 6 tail concatenation less ;)

dvdvideo1234 avatar Nov 24 '19 08:11 dvdvideo1234

To me atleast orthogonalizing vectors happens quite often and I have to code stuff like this. instead of just calling a function :)

dvdvideo1234 avatar Nov 24 '19 08:11 dvdvideo1234

To me atleast orthogonalizing vectors happens quite often and I have to code stuff like this. instead of just calling a function :)

Some things I noticed that you should update:

Such as Returns hour, minute, secon in a formatted string.' fix secon to second

Also, I don't necessarily believe that GetOrthogonal should be in the util library, thats more of just misc functions. The math library would be better, in my opinion.

GrahamBest avatar Nov 24 '19 11:11 GrahamBest

generic was the wrong adjective. I meant very specific use case and won't be used often.

Yea, I figured that's what you meant. His push req isn't bloating code or anything (at least not to my eye). It seems fine.

GrahamBest avatar Nov 24 '19 11:11 GrahamBest

You still need to remove unrelated changes. This PR should only contain the GetOrthogonalVector addition, nothing else.

Kefta avatar Nov 24 '19 14:11 Kefta

Also, you need to fix the code styling to match the rest of the codebase.

Kefta avatar Nov 24 '19 14:11 Kefta

I'm not saying it's not useful. I'm saying its not useful enough to be a core function. If it is, then it still shouldn't be in the util lib.

thegrb93 avatar Nov 24 '19 16:11 thegrb93

The util library is the best place for it. math is currently for numbers, and it doesn't make sense in the Vector metatable since it modifies arguments and it's ambiguous which is the forward and up vector. Vector orthogonality is useful enough to be a core function.

Kefta avatar Nov 24 '19 18:11 Kefta

I am still going to let function util.TypeToString( v ) exist because currently this is the right way to do it using unpack being pushed to PROD.

dvdvideo1234 avatar Nov 29 '19 11:11 dvdvideo1234

Put it into a separate PR. Also, you still need to fix the style.

Kefta avatar Nov 29 '19 16:11 Kefta

@Kefta I am using Tabs. An I missing something else ?

dvdvideo1234 avatar Dec 02 '19 08:12 dvdvideo1234

Look around the file. There should be spaces surrounding parentheses (if ( bN ) then), and there should be empty lines surrounding control-statements, in this case, if and end.

Kefta avatar Dec 02 '19 08:12 Kefta

Others are requested in the PRs below: https://github.com/Facepunch/garrysmod/pull/1621 https://github.com/Facepunch/garrysmod/pull/1622

dvdvideo1234 avatar Dec 02 '19 09:12 dvdvideo1234

@Kefta Done, Found it. thank you!

dvdvideo1234 avatar Dec 03 '19 13:12 dvdvideo1234

You still need spaces around control statements, and a space between if and the parenthesis. Ex.

function foo()
   somefunc()

   if ( condition ) then
      someotherfunc()
   end

   evenmorefunc()
end

Notice the spaces surrounding the if-statement.

Kefta avatar Dec 03 '19 20:12 Kefta

You still need a space between if and the parenthesis...

Kefta avatar Dec 04 '19 13:12 Kefta

@Kefta Done, thank you !

dvdvideo1234 avatar Dec 05 '19 08:12 dvdvideo1234

I wonder is there a way for this to utilize VectorVectors?

dvdvideo1234 avatar Jan 06 '20 09:01 dvdvideo1234

Yes, I've requested it to be pushed.

Kefta avatar Jan 06 '20 11:01 Kefta

@Kefta

I see it includes the normalization of the right and up vectors when only forward Z != 0, but does not normalize the forward vector as it is a constant reference. It means that the normalization of the unit vectors is not optional.

dvdvideo1234 avatar Jan 09 '20 07:01 dvdvideo1234

The right and up vectors are the returns: they aren't provided to the function.

Kefta avatar Jan 09 '20 10:01 Kefta

But how does it decide which plane the second vector lays in. I mean if you try to create a three-unit vector coordinate system without an UP vector and only FORWARD one , this can have infinite solutions, which will result in a different output angle depending on the chosen UP direction.

dvdvideo1234 avatar Jan 14 '20 09:01 dvdvideo1234

0,0,1 is used as the absolute up vector.

Kefta avatar Jan 14 '20 13:01 Kefta

@Kefta

Is it good then for [0,0,1] to be a default fallback value when a dedicated up direction is not provided?

dvdvideo1234 avatar Jan 30 '20 09:01 dvdvideo1234

I think this is too niche to be included with the base game.

Not every math function you use in your addon(s) needs including in the base game.

robotboy655 avatar Oct 31 '23 19:10 robotboy655