# How to use GetViewProjMatrix().TransformVector(LineDirection) in UE4?

**URL:** <https://forums.unrealengine.com/t/how-to-use-getviewprojmatrix-transformvector-linedirection-in-ue4/340194>\
**Category:** C++\
**Tags:** screen-space, projection, projection-matrix, unreal-engine, UE4, CPP, question\
**Created:** [December 1, 2015, 8:15am UTC](https://forums.unrealengine.com/t/how-to-use-getviewprojmatrix-transformvector-linedirection-in-ue4/340194 "2015-12-01T08:15:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_08c2fdfc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_08c2fdfc](https://forums.unrealengine.com/u/anonymous_user_08c2fdfc)\
**Post date:** [December 1, 2015, 8:15am UTC](https://forums.unrealengine.com/t/how-to-use-getviewprojmatrix-transformvector-linedirection-in-ue4/340194/1 "2015-12-01T08:15:30Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_4bed5914](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_4bed5914](https://forums.unrealengine.com/u/anonymous_user_4bed5914)\
**Post date:** [December 5, 2015, 9:52am UTC](https://forums.unrealengine.com/t/how-to-use-getviewprojmatrix-transformvector-linedirection-in-ue4/340194/2 "2015-12-05T09:52:28Z")

</div>

Hi, EdMode what type of object is it ?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_08c2fdfc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_08c2fdfc](https://forums.unrealengine.com/u/anonymous_user_08c2fdfc)\
**Post date:** [December 5, 2015, 12:22pm UTC](https://forums.unrealengine.com/t/how-to-use-getviewprojmatrix-transformvector-linedirection-in-ue4/340194/3 "2015-12-05T12:22:29Z")

</div>

Hi, `EdMode` is my custom `FEdMode` object, but `ViewMatrices` are [matrices](https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/FViewMatrices/index.html) of the [FSceneView](https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/FSceneView/index.html).
