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"

How to create tight 2d bounding boxes for actors in player's view

Hi,

I need to get tight bounding boxes around actors in the player's view (2D). My current method is 1. getting capsule component bounding box in 3D. AND 2. project 8 vertices into 2D and calculate the min&max.

However, this box is too wide in 2D due to the projection . For example, the green box in the image below is the capsule component bounding box in 3D and it's tight. When projecting it to 2D, I get red box, which is too wide and the blue box is the box I want. Does anyone know how I can get the tight 2D bounding box?

alt text

Product Version: UE 4.21
Tags:
capture.png (114.1 kB)
more ▼

asked Mar 26 '19 at 01:23 PM in C++ Programming

avatar image

zzy8200
1

avatar image sonicnerd14 Jun 15 '19 at 10:06 PM

I'm still trying to figure out bounding boxes in UE4 myself, but maybe we can help each other out in some way. I'm sure since you have some sort of bounds for your actor working you at least know how to set them up. How exactly do you setup up the current bounding boxes that you have already?

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

2 answers: sort voted first

I already solved this by calculating bbox of each physical assets component. Due to license issue I can't release the code here. The box is not minimum due to physical assets are not perfectly aligned with real shape but it's good enogh. If you try this way, please be careful on the coordinate transformation!

more ▼

answered Jun 17 '19 at 05:49 PM

avatar image

zzy8200
1

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

The main problem is that when looking from different angles, the 3D bounding box looks a lot larger than the actual actor inside. A possible solution that I found, although not perfect, gets a much closer 2D box. Using a FOrientedBox object and set Center, Extents and Axis members to match your capsule's bounding box, then execute CalcVertices on the FOrientedBox object, that will calculate the 8 vertices of the bounding box as seen from that angle, and then project those to the screen. The function is an adapted version from this thread, and outputs the origin and size of the resulting 2D box.

 FOrientedBox oBox;
 oBox.Center = Origin;
 oBox.ExtentX = Extent.X;
 oBox.ExtentY = Extent.Y;
 oBox.ExtentZ = Extent.Z;
 oBox.AxisX = AxisX;
 oBox.AxisY = AxisY;
 oBox.AxisZ = AxisZ;

 FVector OutVertices[8];
 oBox.CalcVertices(OutVertices);


 const FVector BoundsPointMapping[8] =
 {
     FVector(1, 1, 1),
     FVector(1, 1, -1),
     FVector(1, -1, 1),
     FVector(1, -1, -1),
     FVector(-1, 1, 1),
     FVector(-1, 1, -1),
     FVector(-1, -1, 1),
     FVector(-1, -1, -1)
 };

 // Build 2D bounding box of actor in screen space
 FBox2D ActorBox2D(0);
 for (uint8 BoundsPointItr = 0; BoundsPointItr < 8; BoundsPointItr++)
 {
     FVector2D ScreenLocation;
     
     // Project vert into screen space.
     controller->ProjectWorldLocationToScreen(OutVertices[BoundsPointItr], ScreenLocation);
     // Add to 2D bounding box
     ActorBox2D += ScreenLocation;// FVector2D(ProjectedWorldLocation.X, ProjectedWorldLocation.Y);
 }
 outOrigin = ActorBox2D.Min;
 outSize = ActorBox2D.GetSize();

more ▼

answered Jun 21 '19 at 01:36 PM

avatar image

thetriponator
1

(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