Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    Vector Question

    Beginners
    7
    8
    380
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • G
      gilman last edited by

      I am wondering about how different parts of vectors are accessed. What I mean is how does fuse know which piece of my vector I am asking about. Specifically, I have a vector called playerpos = {400,300}

      print(playerpos.x) prints 400. Is x always assigned to the first value? Does it continue indefinately through x,y,z....? If so what comes after z

      Thanks
      -Gil

      1 Reply Last reply Reply Quote 0
      • pianofire
        pianofire Fuze Team last edited by

        Believe it or not w! (I think it was for width)

        You can also access them using r,g,b and a or array indices [0] to [3]

        spikey 1 Reply Last reply Reply Quote 3
        • S
          Something last edited by

          I often wonder the same. There are times when I make something and don't understand how Fuze can understand, but it does. Or it doesn't understand something which I think it should.

          1 Reply Last reply Reply Quote 0
          • spikey
            spikey F @pianofire last edited by

            @pianofire I did not know about r,g,b. Now, I can improve some code, where i used x,yz, w on color vectors😂

            1 Reply Last reply Reply Quote 0
            • PB____
              PB____ last edited by

              I knew rgba and xyzw, but I wasn't aware of the array indices, which is good to know, because I sometimes use vectors in my own functions for other properties than color or position :) (for example, for padding, border and margin)

              1 Reply Last reply Reply Quote 2
              • S
                Something last edited by

                @pianofire Can the rotation of an object be stored in a vector, or is it only position?

                Gothon 1 Reply Last reply Reply Quote 0
                • Gothon
                  Gothon F @Something last edited by

                  @Something There are no built in functions to store a rotation in a 4 element Fuze vector. However I have had much success using a quaternion representation to store 3D rotations in Fuze's 4 element vectors.

                  I use the following code as a blackbox to store and manipulate rotations as vectors in all my shared programs:

                  // Concatenate 2 Quaternions (rotations)
                  Function QuatMult(a, b)
                      vector c = a.w * b + b.w * a + Cross(a, b)
                      c.w -= Dot(a, b)
                  Return c
                  // Rotate a vector v by a unit quaternion q
                  Function QuatRot(q, v) Return QuatMult(QuatMult(q, v), {-q.x, -q.y, -q.z, q.w})
                  
                  Function AxisAngleToQuat(Axis, Angle)
                      float Mag = Length(Axis)
                      If Mag > 0 Then
                          Axis *= Sin(Angle / 2) / Mag
                          Axis.w = Cos(Angle / 2)
                      Else
                          Axis = {0, 0, 0, 1}
                      EndIf
                  Return Axis
                  

                  You can create them from an axis-angle representation, combine them in any order and apply them to any point/vector.

                  To apply the rotation to a 3D model in Fuze, you can call ObjectPointAt() to reset the rotation followed by RotateObject() with an axis-angle representation.

                  I do this in my 'Rubik's Cube Toy' program, using the formula:

                  axis = {q.x, q.y, q.z}
                  mag = Length(axis)
                  angle = ATan2(mag, q.w) * 2
                  

                  while taking care to not call RotateObject() if mag is 0.

                  All of these formulas I obtained from Wikipedia:
                  https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation

                  DomDom 1 Reply Last reply Reply Quote 6
                  • DomDom
                    DomDom F @Gothon last edited by

                    This post is deleted!
                    1 Reply Last reply Reply Quote 3
                    • First post
                      Last post