<p>I don't think you can simply use <code>TransformVector</code> when the matrix you're transforming by involves a projection matrix. To fully project to screen space, you have to divide by W, which <code>TransformVector</code> doesn't do (it simply multiplies by the matrix without translation).</p>

<p>Also, because of the divide by W, transforming <em>vectors</em> (as opposed to <em>points</em>) by a projection matrix is probably not what you actually want. If what you want is the screen-space vector between two points, you should transform and divide-by-W each point, then subtract them to get a screen-space vector. Otherwise the vector will likely be inaccurate.</p>

CC BY-SA 3.0
2015-12-03T11:30:33.810Z
Ok, thanks for this answer! I used `TransformVector` after reading the first paragraph of [this page about homogenous coordinates](http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/). I understood I should not worry about W when projecting a direction, but maybe I'm wrong.
arthur.sw
CC BY-SA 3.0
2015-12-03T11:34:06.963Z
I thought about projecting both points on my screen, but I changed my mind because I thought it was not necessary.
arthur.sw
CC BY-SA 3.0
2015-12-03T18:40:23.763Z
@arthur.sw That article is OK as far as affine transforms go, but when projections get involved, things are more complicated.
Nathan Reed
CC BY-SA 3.0
2015-12-05T15:34:24.700Z
Yes, I would like to have more details about this, maybe I should ask this question on [math.stackexchange](http://math.stackexchange.com/)?
arthur.sw
CC BY-SA 3.0
2015-12-05T21:12:09.347Z
@arthur.sw What details are you interested in? I could add a quick example showing how the divide-by-W affects vectors, if that would be helpful.
Nathan Reed
CC BY-SA 3.0
2015-12-06T19:26:40.830Z
Well I just wanted to make sure that projecting two points is the only or best way to do it.
arthur.sw
CC BY-SA 3.0
2015-12-02T22:52:08.860Z
2015-12-02T22:52:08.860Z
Nathan Reed
<p>I try to project a 3D vector (a direction, not a position) in screen space, but it does not return satisfying results:</p>

<pre><code> FVector LineDirectionOnScreen = 
   EdMode-&gt;ViewMatrices.GetViewProjMatrix().TransformVector(LineDirection);
 FVector2D LineDirectionOnScreen2D(
   LineDirectionOnScreen.X * 0.5f * (float)EdMode-&gt;ViewRect.Width(), 
   LineDirectionOnScreen.Y * 0.5f * (float)EdMode-&gt;ViewRect.Height());
</code></pre>

<p>When <code>LineDirection</code> is (0,0,1) it always returns a something like (0,Y) (Y can be anything), no matter how the camera is rotated.</p>

<p>What is wrong with my code?</p>

CC BY-SA 3.0
2015-12-02T09:58:10.617Z
[Please explain why you downvote](http://meta.stackexchange.com/questions/135/encouraging-people-to-explain-downvotes) when you do.
arthur.sw
CC BY-SA 3.0
2015-12-02T23:48:17.757Z
I dont know why it was downvoted. but this seems like a close dupllicate to your other question.
joojaa
<projections>
How to use GetViewProjMatrix().TransformVector(LineDirection) in UE4?
arthur.sw
# How to use GetViewProjMatrix().TransformVector(LineDirection) in UE4?

(Asked by: username_0 on 2015-11-30)

I try to project a 3D vector (a direction, not a position) in screen space, but it does not return satisfying results:

```
 FVector LineDirectionOnScreen = 
   EdMode->ViewMatrices.GetViewProjMatrix().TransformVector(LineDirection);
 FVector2D LineDirectionOnScreen2D(
   LineDirectionOnScreen.X * 0.5f * (float)EdMode->ViewRect.Width(), 
   LineDirectionOnScreen.Y * 0.5f * (float)EdMode->ViewRect.Height());

```

When `LineDirection` is (0,0,1) it always returns a something like (0,Y) (Y can be anything), no matter how the camera is rotated.

What is wrong with my code?

**Tags:** projections

> **Comments:**
> **username_0**: [Please explain why you downvote](http://meta.stackexchange.com/questions/135/encouraging-people-to-explain-downvotes) when you do.  
> **username_1**: I dont know why it was downvoted. but this seems like a close dupllicate to your other question.  

---

## 1 answers

### Answer by username_2 on 2015-12-02. Score: 3 | Accepted answer

I don't think you can simply use `TransformVector` when the matrix you're transforming by involves a projection matrix. To fully project to screen space, you have to divide by W, which `TransformVector` doesn't do (it simply multiplies by the matrix without translation).

Also, because of the divide by W, transforming *vectors* (as opposed to *points*) by a projection matrix is probably not what you actually want. If what you want is the screen-space vector between two points, you should transform and divide-by-W each point, then subtract them to get a screen-space vector. Otherwise the vector will likely be inaccurate.

> **Comments:**
> **username_0**: Ok, thanks for this answer! I used `TransformVector` after reading the first paragraph of [this page about homogenous coordinates](http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/). I understood I should not worry about W when projecting a direction, but maybe I'm wrong.  
> **username_0**: I thought about projecting both points on my screen, but I changed my mind because I thought it was not necessary.  
> **username_2**: @username_0 That article is OK as far as affine transforms go, but when projections get involved, things are more complicated.  
> **username_0**: Yes, I would like to have more details about this, maybe I should ask this question on [math.stackexchange](http://math.stackexchange.com/)?  
> **username_2**: @username_0 What details are you interested in? I could add a quick example showing how the divide-by-W affects vectors, if that would be helpful.  
> **username_0**: Well I just wanted to make sure that projecting two points is the only or best way to do it.  

---

