+ Reply to Thread
Page 11 of 16 FirstFirst ... 910111213 ... LastLast
Results 101 to 110 of 153

Thread: Jimlad's wire addons

  1. #101
    Bug Buster TomyLobo's Avatar
    Join Date
    Feb 2009
    Posts
    2,796

    Default Re: Jimlad's wire addons

    Jimlad, i just tested this LocalToWorld thing you mentioned with a few props and the results were the same for all objects i tested.
    Here's the E2 i used to test it. attach 2 GPS holos to it which have emitter-point beams deactivated but point-point beams activated

    [highlight=e2]@name Get Local Coords
    @inputs
    @outputs Pos1:vector Pos2:vector
    @persist E:entity Flag

    runOnTick(1)

    EN=entity()wner():aimEntity()
    if (EN) {
    E=EN
    }

    Flag=!Flag
    Pos1=E:toWorld(vec(100,100,100)*Flag)
    Pos2=Eos()+(E:forward()-E:right()+E:up())*100*Flag[/highlight]
    EDIT: those matrices need a left vector, not a right vector, that's where both our formulae were off.
    Last edited by TomyLobo; 05-01-2009 at 05:58 PM.
    "It's easy to win forgiveness for being wrong; being right is what gets you into real trouble." - Bjarne Stroustrup

    Lífið læðist lúmskt áfram

  2. #102
    Wire Sofaking Jimlad's Avatar
    Join Date
    Dec 2008
    Posts
    941

    Default Re: Jimlad's wire addons

    Cool, if they were all the same then no problem. To be honest though it didn't even occur to me they might be different, if that was the case then gmod would really have been written weirdly.

    I wouldn't worry about the inverse thing either, when I mentioned it I was just thinking off the top of my head like I said at the time. Thinking back, it's just that I was forgetting to take into account the fact that rotation also affects the direction of the translation. It's been a couple of weeks since I last checked what I did .There's no issue with the way I've actually written it.

  3. #103
    Bug Buster TomyLobo's Avatar
    Join Date
    Feb 2009
    Posts
    2,796

    Default Re: Jimlad's wire addons

    let's compare what we have. here is what i have: (just the headers)
    [highlight=Lua]--- Creates a 4x4 identity matrix
    e2function matrix4 identity4()

    --- Creates a 4x4 matrix with all elements set to 0
    e2function matrix4 matrix4()

    --- Creates a matrix with values in the following order (i.j): (1,1), (1,2), (1,3), (1,4), (2,1) etc.
    e2function matrix4 matrix4(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)

    --- Creates a matrix with vectors by columns
    e2function matrix4 matrix4(vector f, vector r, vector u)

    --- Converts a 3D matrix into a 4D matrix - all (i,4) and (4,j) are filled with 0's
    e2function matrix4 matrix4(matrix m)

    --- Swaps the two rows specified
    e2function matrix4 matrix4:swapRows(a, b)

    --- Swaps the two columns specified
    e2function matrix4 matrix4:swapColumns(a, b)

    --- Sets the values of a row. The first argument given specifies the row(j), the following arguments are the values 1j, 2j, 3j, 4j
    e2function matrix4 matrix4:setRow(row,x,y,z,w)

    --- Sets the values of a row. The first argument given specifies the row, the vector contains the first 3 values to set, the last argument is the 4th value.
    e2function matrix4 matrix4:setRow(row,vector v,w)

    --- Sets the values of a column. The first argument given specifies the column(i), the following arguments are the values i1, i2, i3, i4
    e2function matrix4 matrix4:setColumn(col,x,y,z,w)

    --- Sets the values of a column. The first argument given specifies the column, the vector contains the first 3 values to set, the last argument is the 4th value.
    e2function matrix4 matrix4:setColumn(col,vector v,w)

    --- Creates a reference frame matrix from an entity's direction and position vectors by rows in the following order: forward, right, up, pos. The remaining row is filled with (0, 0, 0, 1).
    e2function matrix4 matrix4(entity ent)

    --- Returns the forward vector from a 4x4 coordinate reference frame matrix ( same as M:col(1) )
    e2function vector matrix4:forward()

    --- Returns the right vector from a 4x4 coordinate reference frame matrix ( same as -M:col(2) )
    e2function vector matrix4:right()

    --- Returns the up vector from a 4x4 coordinate reference frame matrix ( same as M:col(3) )
    e2function vector matrix4:up()

    --- Returns the postion vector from a 4x4 coordinate reference frame matrix ( same as M:col(4) )
    e2function vector matrix4os()

    --- Returns the row as a vector (skips the 4th component)
    e2function vector matrix4:row(r)

    --- Returns the column as a vector (skips the 4th component)
    e2function vector matrix4:column(c)

    --- Returns the element with indices (i,j)
    e2function number matrix4:element(col, row)

    --- Sets an element's value. The first two arguments specify the indices (i,j), the third argument is the value to set it to
    e2function matrix4 matrix4:setElement(col, row, value)

    --- Swaps two elements, specified by indices (i1,j1,i2,j2)
    e2function matrix4 matrix4:swapElements(col1, row1, col2, row2, value)

    --- Returns a vector comprising the elements along the leading diagonal (skips the last element)
    e2function vector diagonal(matrix4 m)

    --- Returns the trace of a matrix
    e2function number diagonal(matrix4 m)

    --- Returns the transpose of a matrix
    e2function matrix4 transpose(matrix4 m)

    --- if(XM4)
    e2function matrix4 operator_is(matrix4 m)

    --- XM4+XM4
    e2function matrix4 operator+(matrix4 l, matrix4 r)

    --- XM4-XM4
    e2function matrix4 operator-(matrix4 l, matrix4 r)

    --- -XM4
    e2function matrix4 operator_neg(matrix4 m)

    --- XM4*XM4
    e2function matrix4 operator*(matrix4 l, matrix4 r)

    --- N*XM4
    e2function matrix4 operator*(n, matrix4 m)

    --- XM4*N
    e2function matrix4 operator*(matrix4 m, n)

    --- XM4*V
    e2function vector operator*(matrix4 m, vector v)

    --- XM4/N
    e2function matrix4 operator/(matrix4 m, n)

    --- XM4^N
    e2function matrix4 operator^(matrix4 m, n)

    --- XM4==XM4
    e2function matrix4 operator==(matrix4 l, matrix4 r)

    --- XM4!=XM4
    e2function matrix4 operator!=(matrix4 l, matrix4 r)

    --- generates a translation matrix
    e2function matrix4 mtranslate4(vector pos)

    --- generates a scaling matrix
    e2function matrix4 mscale4(vector fac)

    --- generates a rotation matrix
    e2function matrix4 mrotate4(angle ang)[/highlight]

    not in the list is the assignment operator as that's just boilerplate
    Last edited by TomyLobo; 05-02-2009 at 02:59 AM.
    "It's easy to win forgiveness for being wrong; being right is what gets you into real trouble." - Bjarne Stroustrup

    Lífið læðist lúmskt áfram

  4. #104
    Wire Sofaking Jimlad's Avatar
    Join Date
    Dec 2008
    Posts
    941

    Default Re: Jimlad's wire addons

    I've updated the OP with the new additions, please check them over before committing since there's quite a lot, so there's a greater chance I've made mistakes!

    Quote Originally Posted by TomyLobo View Post
    let's compare what we have. here is what i have: (just the headers)

    not in the list is the assignment operator as that's just boilerplate
    Whoa... I have no idea why you'd want to rewrite all of those, since I'd say pretty much all of it is basically boilerplate! To each his own I guess - although you might learn a bit more about matrices from doing it, if you aren't familiar with them already. It seems like you want to make them very specifically homogeneous transformation matrices, but you have to be aware they aren't the only type of matrix. If you look at what I've done so far, you'll see I've been careful to make these maths functions as general as possible.

    I won't be including anything like those last three - "generate a scaling/translation/rotation matrix", for several reasons. The first two can be generated very easily with just identity():setDiagonal(v) and identity():setcolumn(4,v) so they're completely redundant. In the case of a rotation matrix, I'm not sure how you've implemented it, but you have to be careful about what order you do the rotations in, and I'd much rather leave it up to the user to decide. The current system is versatile enough that building a rotation matrix along x/y/z is trivial anyway.

    The other reasons are that I want to keep the functions as general as I can, and if possible I'd like to avoid functions that mask what's going on underneath. I get the feeling that substituting something like mTranslate with the already simple "identity():setRow(4,v)" will remove any reason to understand what it's actually doing. It's better, and not much more effort, to just build matrices with the standard matrix functions. After all, that's basically what you have to do when you use matrices anywhere else. This is why I've included a fairly comprehensive list of matrix manipulation functions.

    I've already included an mRotation function but it's only in the form of (axis, angle) simple because it's a serious pain to write out, and it's much cheaper to construct it in lua rather than in E2.
    Last edited by Jimlad; 05-02-2009 at 01:18 PM.

  5. #105
    Bug Buster TomyLobo's Avatar
    Join Date
    Feb 2009
    Posts
    2,796

    Default Re: Jimlad's wire addons

    i didnt rewrite anything, i had most of it done when i got your first pm.
    i mostly kept it similar to the existing 3x3 matrix implementation

    if you aren't familiar with them already
    i wouldnt be writing a 4x4 matrix extension if i werent

    redundancy: you already have M:forward() and the likes, which is redundant as well.
    rotation matrix: it rotates in exactly the same way as V:rotate(), so people are used to the order.
    took me a couple of hours to figure out the order

    [...]will remove any reason to understand what it's actually doing
    that's exactly the reason for adding those functions. requiring university maths for E2 is not a good move.

    i attached my 4x4 matrix extension to this post.
    matrix4.lua is the un-preprocessed, more readable form, while preprocessed_matrix4.lua is preprocessed and works without my preprocessor patch.
    if you want the preprocessor patch, query me on irc
    Attached Files Attached Files
    Last edited by TomyLobo; 05-02-2009 at 10:30 AM.
    "It's easy to win forgiveness for being wrong; being right is what gets you into real trouble." - Bjarne Stroustrup

    Lífið læðist lúmskt áfram

  6. #106
    Wire Sofaking Jimlad's Avatar
    Join Date
    Dec 2008
    Posts
    941

    Default Re: Jimlad's wire addons

    Quote Originally Posted by TomyLobo View Post
    redundancy: you already have M:forward() and the likes, which is redundant as well.
    rotation matrix: it rotates in exactly the same way as V:rotate(), so people are used to the order.
    took me a couple of hours to figure out the order
    If you read the discussions from before in the thread, you'll see I added forward/up/right on Syranide's suggestion. I was reluctant to add them exactly because of the redundancy, but they don't do much so I'm not really bothered whether they get left in or not.

    One of the main advantages of using rotation matrices is that you can specify the order of the rotations. It's the versatility that makes them useful. If you take that away, as you already suggested, you might as well use V:rotate(A).

    Quote Originally Posted by TomyLobo View Post
    that's exactly the reason for adding those functions. requiring university maths for E2 is not a good move.
    It's not really university level, but regardless - that's the nature of using matrices. Whether it's a "good move" or not shouldn't be an issue. The same as with vectors, if people can use them then that's great, if they can't then it's not a massive deal, because everyone has to learn things at some point. There's really no purpose in appealing to the lowest common denominator.

    If you're looking for projects that genuinely need attention, I can suggest some fixes for the adv. duplicator. At the moment it doesn't duplicate certain properties like buoyancy and drag correctly, I think it'd be great if that was fixed.

  7. #107
    Bug Buster TomyLobo's Avatar
    Join Date
    Feb 2009
    Posts
    2,796

    Default Re: Jimlad's wire addons

    i edited after you read my post. mainly the attachment.

    adv duplicator doesnt need a fix, but a rewrite. tad agrees with me on that

    i mainly want to matrices to optimize static multi-level linear maps

    that means i calculate a certain expensive mapping when the E2 initializes and then apply it every frame or interval or whatever
    Last edited by TomyLobo; 05-02-2009 at 10:41 AM.
    "It's easy to win forgiveness for being wrong; being right is what gets you into real trouble." - Bjarne Stroustrup

    Lífið læðist lúmskt áfram

  8. #108
    Wire Sofaking Jimlad's Avatar
    Join Date
    Dec 2008
    Posts
    941

    Default Re: Jimlad's wire addons

    Quote Originally Posted by TomyLobo View Post
    i edited after you read my post. mainly the attachment.
    Good stuff, looks like it should work out just fine. What's with the crazy syntax though, does it run ok with E2? I found it a little hard to compare because it's so... different!

    Quote Originally Posted by TomyLobo View Post
    adv duplicator doesnt need a fix, but a rewrite. tad agrees with me on that
    No kidding, I don't think there's any argument it needs a rewrite, but the question is whether anyone's willing to do that. I can't see a full re-write happening any time soon, but I hope I'm wrong. In the mean time the only other option is to patch.

    Quote Originally Posted by TomyLobo View Post
    i mainly want to matrices to optimize static multi-level linear maps

    that means i calculate a certain expensive mapping when the E2 initializes and then apply it every frame or interval or whatever
    That's great, but I can only hope people will use it in the same way. This is the other reason why it's important for people to understand how the matrices actually work, because certain operations can be optimized a huge amount very easily if you actually understand the maths.

  9. #109
    Bug Buster TomyLobo's Avatar
    Join Date
    Feb 2009
    Posts
    2,796

    Default Re: Jimlad's wire addons

    syntax:
    i made a patch for the extension loader that runs everything through a preprocessor i made.
    it translates everything into real Lua and registers all the e2functions with either registerFunction or registerOperator.
    like i said it's still in development, but it's mostly finished. the only remaining problems are with the error reporting.
    "It's easy to win forgiveness for being wrong; being right is what gets you into real trouble." - Bjarne Stroustrup

    Lífið læðist lúmskt áfram

  10. #110
    Wire Sofaking Jimlad's Avatar
    Join Date
    Dec 2008
    Posts
    941

    Default Re: Jimlad's wire addons

    Quote Originally Posted by TomyLobo View Post
    syntax:
    i made a patch for the extension loader that runs everything through a preprocessor i made.
    it translates everything into real Lua and registers all the e2functions with either registerFunction or registerOperator.
    like i said it's still in development, but it's mostly finished. the only remaining problems are with the error reporting.
    Ohh yeah I remember your thread on it. It's a really nice idea, I agree the whole op1/rv1 thing is a real pain. Any idea what Syranide thought of it? It does make it read a bit nicer, but I wonder if it's a big enough change to be accepted. I read through the matrix4 stuff though and it there's a definite improvement in the formatting, so maybe that's a good example of how it could be a benefit.

+ Reply to Thread
Page 11 of 16 FirstFirst ... 910111213 ... LastLast

LinkBacks (?)

  1. 03-14-2010, 02:27 PM

Similar Threads

  1. Addons for Wire Mod, mods for Wire Addon
    By _Kilburn in forum Wiremod Addons & Coding
    Replies: 63
    Last Post: 01-02-2011, 10:27 AM
  2. A note on inclusion of addons into official wire.
    By Anticept in forum Wiremod Addons & Coding
    Replies: 0
    Last Post: 08-18-2008, 07:13 AM
  3. Addons for a Mac?
    By FOXDONUT in forum Wiremod General Chat
    Replies: 18
    Last Post: 06-11-2008, 03:43 PM
  4. The [Table] |Lots of Addons|PHX|SVN Wire|SVN Wire2|
    By LemmingsOwnYou in forum Servers
    Replies: 0
    Last Post: 09-14-2007, 07:16 AM
  5. Combining Wire Addons into the main package
    By Maximized in forum Ideas & Suggestions
    Replies: 1
    Last Post: 02-21-2007, 03:58 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
proceed-collector
proceed-collector
proceed-collector
proceed-collector
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots