Results 1 to 7 of 7
  1. #1
    MSgt. Shooter Person
    Join Date
    Jul 2010
    Posts
    436

    Default getting world's bounds?

    Is there a way to get the largest bounding box containing all geometry in the world (light, skybox etc need not be contained in it)? I'd expect this to be obvious but haven't been able to find it in the code or on UDN. The max and min values of x and y would suffice.
    UnrealScript tutorial for non-programmers
    Must kill fast and bullets too slow...

  2. #2
    Redeemer
    Join Date
    Dec 2008
    Location
    Germany
    Posts
    1,562

    Default

    I don't think there is anything that can give you the desired result straight away, but you can iterate over allactors() yourself and GetComponentsBoundingBox() for every actor that is not a light, skybox, etc.
    Now all you need to do is find the "smallest" min and "biggest" max of the boundingboxes you get. The result is the boundingbox with min and max containing all others you just went over.


    Or alternatively just create a volume containing the area.
    Youtube - UnrealEverything

    2B || !(2B)

  3. #3
    MSgt. Shooter Person
    Join Date
    Jul 2010
    Posts
    436

    Default

    Too bad there's no fast way to get it. I'd expect this would be something simple.
    Regardless, that first suggestion works with a small adjustment (check actor.CollisionType != COLLIDE_NoCollision instead of checking if it's a light etc). Thanks for the tip.
    UnrealScript tutorial for non-programmers
    Must kill fast and bullets too slow...

  4. #4
    MSgt. Shooter Person
    Join Date
    Nov 2010
    Posts
    195

    Default

    In the past I have made a place-able object that held a few map properties for me. You could easily type in the size of your level and just read it from that object. Along with any other properties you wanted
    -cbfSoftware-

  5. #5
    MSgt. Shooter Person
    Join Date
    Jul 2010
    Posts
    436

    Default

    Yes but I'd rather have an automated method that doesn't require additional mapper input.

    I've run into a problem with this, it appears terrain is not an Actor. Or at least the bounds I get seem to be unaware of the terrain and depend on the location of the pawn.
    Code:
    function getWorldBounds(out Vector min, out Vector max) {
    	local Actor a;
    	local box aBox;
    	
    	max = vect(0,0,0);
    	min = vect(0,0,0);
    	foreach AllActors(class'Actor', a) {
    		if (a.CollisionType != COLLIDE_NoCollision) {
    			a.GetComponentsBoundingBox(aBox);
    			max.x = max(max.x, aBox.max.x);
    			max.y = max(max.y, aBox.max.y);
    			max.z = max(max.z, aBox.max.z);
    			min.x = min(min.x, aBox.min.x);
    			min.y = min(min.y, aBox.min.y);
    			min.z = min(min.z, aBox.min.z);
    		}
    	}
    }
    My current suspicion is that I need to convert the coordinates of the bounding box from local to global. I'll post back here when/if I find a solution.

    EDIT: Ok it's not coordinate conversion
    Last edited by Dr Bearhands; 02-23-2012 at 05:05 AM.
    UnrealScript tutorial for non-programmers
    Must kill fast and bullets too slow...

  6. #6
    MSgt. Shooter Person
    Join Date
    Jul 2010
    Posts
    436

    Default

    This seems to do the trick:
    Code:
    function getWorldBounds(out Vector min, out Vector max) {
    	local Actor a;
    	local box aBox;
    	local Terrain ter;
    	
    	max = vect(0,0,0);
    	min = vect(0,0,0);
    	foreach AllActors(class'Actor', a) {
    		if (a.isA('Terrain')) {
    			ter = Terrain(a);
    			min.x = fmin(min.x, ter.Location.x);
    			min.y = fmin(min.y, ter.Location.y);
    
    			max.x = fmax(max.x, ter.Location.x + ter.NumPatchesX*ter.drawScale3d.x);
    			max.y = fmax(max.y, ter.Location.y + ter.NumPatchesY*ter.drawScale3d.y);
    
    		}
    		else if (a.CollisionType != COLLIDE_NoCollision) {
    			a.GetComponentsBoundingBox(aBox);
    			max.x = fmax(max.x, aBox.max.x);
    			max.y = fmax(max.y, aBox.max.y);
    			max.z = fmax(max.z, aBox.max.z);
    			min.x = fmin(min.x, aBox.min.x);
    			min.y = fmin(min.y, aBox.min.y);
    			min.z = fmin(min.z, aBox.min.z);
    		}
    	}
    }
    It appears terrain has no bounding box, I suspect it uses a different way of rendering that doesn't use bounding boxes. Min and max in the z direction are missing, this is a little annoying for my purpose but not a deal breaker.
    UnrealScript tutorial for non-programmers
    Must kill fast and bullets too slow...

  7. #7
    Redeemer
    Join Date
    Dec 2008
    Location
    Germany
    Posts
    1,562

    Default

    Hm, Terrain consists of multiple TerrainComponents, those inherit a variable called Bounds from PrimitiveComponent. (Not sure if they work or not, GetComponentsBoundingBox might just return the maxiumum bounds of all components)

    You could get the min and max z from the CollisionVertices if necessary.

    And the default values for min and max should be
    Code:
    min = vect(HALF_WORLD_SIZE, HALF_WORLD_SIZE, HALF_WORLD_SIZE);
    max = -min;
    with HALF_WORLD_SIZE being
    Code:
    const HALF_WORLD_SIZE = 262144; //262144 = 2**18
    Youtube - UnrealEverything

    2B || !(2B)


 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Copyright ©2009-2011 Epic Games, Inc. All Rights Reserved.
Digital Point modules: Sphinx-based search vBulletin skin by CompletevB.com.