x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Deproject SceneCaptureComponent2D

I currently have SceneCaptureComponent2D rendering to a texture that I'm using in a UMG widget. I want to deproject mouse clicks on that UMG widget to the 3D space in front of the SceneCaptureComponent2D. I've dug around the source to see if there's anything that I can use, but I couldn't quite find anything useful. And, unfortunately, I'm still trying to wrap my head around the math needed to make it work.

Any suggestions?

Thanks, Zach

Product Version: UE 4.11
Tags:
more ▼

asked Apr 15 '16 at 04:23 AM in C++ Programming

avatar image

zknet
16 1 4 9

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Answering my own question. This is what I did. (It involves editing UE4 source.)

First, I added two variables to USceneCaptureComponent.

 public:
     FIntRect ViewRect;
     FMatrix InvViewProjectionMatrix;

Then I populate those two variables at the end of FScene::CreateSceneRenderer (in SceneCaptureRendering.cpp)

 // Copy the data needed to do deprojection.
     SceneCaptureComponent->ViewRect = View->ViewRect;
     SceneCaptureComponent->InvViewProjectionMatrix = View->InvViewProjectionMatrix;
 
     return FSceneRenderer::CreateSceneRenderer(&ViewFamily, NULL);

With that in place, I can use the above and take the screen position of the click event (or whatever) and call FSceneView::DeprojectScreenToWorld.

 bool ADeprojectTest::Deproject(const FVector2D& ScreenPosition, FVector& Origin, FVector& Direction)
 {
     if (SceneCaptureComponent)
     {
         FSceneView::DeprojectScreenToWorld(ScreenPosition, SceneCaptureComponent->ViewRect, SceneCaptureComponent->InvViewProjectionMatrix, Origin, Direction);
         return true;
     }
     return false;
 }

That's it. It should return an origin and direction normal for your tracing needs.

more ▼

answered Apr 19 '16 at 02:52 AM

avatar image

zknet
16 1 4 9

avatar image antoinegloum May 08 '17 at 01:58 PM

It seems that InvViewProjectionMatrix is not in FSceneView anymore. Have you found a solution for Unreal 4.15 ?

avatar image antoinegloum May 08 '17 at 03:47 PM

I got it from View->ViewMatrices->GetInvViewProjectionMatrix(), but it seems broken.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question