Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Use of vector4 to translate particles?
#1
Hi there,

I replied again to the thread about translation of particles but you may have not seen it pop up.

I'm trying to use the vector4 structure to move particles as your code suggested, but I'm not sure how to use it.

Please see my code below. Note: the platform is moved by IK, so the movement happens at the end of the frame. 
What did I do wrong there? 


public IEnumerator ParticlesFollowPlatform_IE()
    {
        float duration = 3;
        float i = 0;

        Vector3 translation = platform.position - platformLastPosition;
        platformLastPosition = platform.position;

        while (i < duration)
        {
            yield return new WaitForEndOfFrame();

            i += Time.deltaTime;

            Vector3 translation = platform.position - platformLastPosition;
            platformLastPosition = platform.position;

            for (int x = 0; x < myActor.solverIndices.Length; x++)
            {
                int solverIndex = myActor.solverIndices[x];

                myActor.solver.positions[solverIndex] += new Vector4 (translation.x, translation.y, translation.z, 0) ;
                myActor.solver.prevPositions[solverIndex] += new Vector4(translation.x, translation.y, translation.z, 0);
            }
        }
   }
Reply
#2
Hi there!

Vector4 is used for performance reasons. Vectorization works on 2,4,8 or 16 operands (depending on the exact instruction set used), so having positions laid out as tuples of 4 operands allows for faster arithmetic operations in certain cases without the need to move things around in memory. The last component of the Vector4 (w) should be set to zero. For more info see: https://www.sciencedirect.com/topics/com...tiple-data

At first glance, the code you posted seems fine. What are the results you're getting with it?

Edit: particle data (positions, velocities, etc) is expressed in solver space, so make sure that A) solver space and world space match (by placing the solver at zero position, zero rotation, unit scale) or B) convert the platform position to solver space before adding it to the particle positions. See:
http://obi.virtualmethodstudio.com/tutor...icles.html

Quote:All properties are expressed in the solver's local space.
Reply