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

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?

• Please explain why you downvote when you do. – arthur.sw Dec 2 '15 at 9:58
• I dont know why it was downvoted. but this seems like a close dupllicate to your other question. – joojaa Dec 2 '15 at 23:48

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).
• Ok, thanks for this answer! I used TransformVector after reading the first paragraph of this page about homogenous coordinates. I understood I should not worry about W when projecting a direction, but maybe I'm wrong. – arthur.sw Dec 3 '15 at 11:30