Announcement

Collapse
No announcement yet.

How to apply a transformmatrix to a single vector

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to apply a transformmatrix to a single vector

    Hey there. Hope you are doing fine.

    Could you quickly show me how you can apply a transform matrix to a vector?
    I know you have to convert it to a Vector4f so you can multiply it with a matrix4f but
    Vector4f := Matrix4f * Vector4f;

    doesn't seem to be it
    Just missing the proper syntax here I guess.

    I want to be able to attach point like entities (lights, cameras) to a model, therefore transforming the point together with the model.

  • #2
    Click image for larger version

Name:	image.png
Views:	16
Size:	3.6 KB
ID:	639
    ah... ok that is simple. ^^

    Comment


    • #3
      You can just multiply vector directly by the matrix, e.g.:
      Code:
      var
        A, B: TVector3f;
        M: TMatrix4f;
      begin
        A := B * M; // Transforms 3D vector B by matrix M.
      end;
      TVector4f can also be directly multiplied by the matrix similarly to above, but it's only useful if you really need component W afterwards. TMatrix4f also has "Project" function to directly project 3D vector using projection matrix onto some surface.

      Comment


      • #4
        ​Got that to work.
        Similar question: Is there a helper function that gets the current min and max bounds of a transformed matrix? Basically a bounding box of a transformed bounding box. I need that for a reset pivot to middle button and also for determing the current "top Y" of a model. (So that I can use that height level as the base for new objects in build mode)

        I think I can use the original bounds and transform all 8 corners of them manually with the same matrices and then get the bounds from those transformed 8 points, but before I do that I thought I ask if there is already such a function

        Comment


        • #5
          As such, matrix doesn't have bounds, it's just a transformation that it describes. However, in context of the framework, there's a "volume" matrix, which defines how to transform a unity cube to describe a volume, or more precisely, an object-oriented bounding box (OOBB). This "volume" is retrieved using TObjectModel.Transform, e.g. by passing "GlobalVolume" as enumeration. Object selection and visibility testing uses such volumes quite extensively, using BVH (bounding volume hierarchy) and quad trees (from voxel representation).

          What you are asking, however, sounds more like an AABB (axis-aligned bounding box), which is defined in terms of min/max boundaries. In case of "TObjectModel", there is a function "GetAABB", which gets these boundaries in "world" coordinates.

          Currently, there's only "TVolume.NearFarPlanes" function, which takes a "volume" matrix and calculates near and far planes (basically, min/max Z). In a very recent build from last week, I've exposed an additional function "TVolume.CalculateVerticesOOBB", which actually gives you the 8 points that you mentioned, it is quite optimized (using SSE, AVX or Neon SIMD instructions). Internally, I also have a function that calculates min/max boundaries from that (again, optimized using SIMD) - I'll expose it as well.

          Comment


          • #6

            Figured out a working function to retrieve all 8 corners, here test rendered with blue stars.

            Everything seems stable now. I can alter pivots randomly, attach and detach models to each other in a hierarchy (directly in the treeview) and stuff keep its transformations. Each object has a pivot history and a parent history matrix. Since now all necessary functions for vector transformations are set too I can easily make all point like entities be part of the hierarchy too like cameras and later light sources or sounds.

            Comment


            • #7
              I'm glad you made it working, seems great! In either case I'll be exposing these additional helper functions to simplify the code.

              Comment

              Working...
              X