Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Not very neat math, but I hope it works for you:</p> <h2>Input</h2> <p>Suppose you are given a </p> <ul> <li>worldViewPerspectiveMatrix <code>M</code> (Transforms world space to perspective space, orthogonal matrices should work as well!)</li> <li>a constant velocity (more specifcally a distance per Frame) in screen space <code>v_screen</code></li> <li>a (normalized) direction vector <code>V_dir</code> in world space, this will give the direction your object moves. The actual length of the vector will be calculated.</li> <li>a position <code>X</code> where your Object is placed in world space.</li> </ul> <h2>Result</h2> <ul> <li>a scaling factor <code>a</code> for moving your object 'v_screen' units in screen space along <code>V_dir</code> in world space. Thus you want to move your object actually <code>X += a*V_dir</code>.</li> </ul> <p>First we use the formula of mapping the <em>world space</em> to <em>screen space</em> by using homogenous coordinates and w-clipping. The <code>.</code> denotes the matrix multiplication operator.</p> <pre><code>X_proj := M.(x,y,z,1); X_screen := (x_proj/w_proj,y_proj/w_proj); </code></pre> <p>From there we can specify the position of the object <code>X</code> in screen space and the position after appling the directional movement <code>X+(a*V_dir)</code>.</p> <p>The length in screenspace and therefore the desired distance (per frame) is simply </p> <pre><code>Length[(X+(a*dir))_screen - X_screen] == v_screen. </code></pre> <p>Let's solve this for <code>a</code>. I used my Mathematica to calculate <code>a</code> for you. If you want further details, I may elabourate the answer. Suppose <code>M</code>, <code>X</code>, and <code>V_dir</code> is</p> <pre><code> / xp \ / vx \ / vxp \ X_proj = | yp | V_dir = | vy | V_proj = M.V_dir = | vyp | | zp | | vz | | vzp | \ wp / \ 0 / \ vwp / </code></pre> <p>And <code>v_screen</code> is your desired screen space velocity. Then <code>a</code> is:</p> <pre><code>vlen = v_screen*v_screen; a = (-dwp*vlen*wp + dxp*xp + dyp*yp + 0.5*Sqrt( Power(-2*dwp*vlen*wp + 2*dxp*xp + 2*dyp*yp,2) - 4*(dxp*dxp + dyp*dyp - dwp*dwp*vlen)*(xp*xp + yp*yp - wp*wp*vlen) ) ) / (dxp*dxp + dyp*dyp - dwp*dwp*vlen); </code></pre> <p>Remember, <code>-a</code> is also a solution. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload