0 Replies - 257 Views - Last Post: 02 January 2014 - 04:44 PM Rate Topic: -----

#1 Dragonstorm  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 35
  • Joined: 05-June 12

Spacial Partitioning for objects in open world game

Posted 02 January 2014 - 04:44 PM

Hello Everyone!


Unnecessary Info :offtopic:/> :
Spoiler


So basically I'm making a game engine and I'm busy with research so I can start things off correctly.

I'm right now thinking of the way to go organizing objects in an open world type game.

In my old Hack 'n Slash D3D renderer I just went through a list of every object loaded. (I was messing around that would be insane in a game) I then just found the objects in a radius to the camera and rendered only those.

As seen in the following code extract I had to go dig through my projects for:
(which is self explanatory code-wise)
bool DrawableObjectManager::IsObjectInRadius(Drawable* obj)
{

	if(( (/*right of*/obj->GetPosition().x>(CurrentRenderer->GetCurrentCam()->GetPositionF3().x+ViewRadius)) ||
		(/*above*/obj->GetPosition().y>(CurrentRenderer->GetCurrentCam()->GetPositionF3().y+ViewRadius))  ||
		(/*infront*/obj->GetPosition().z>(CurrentRenderer->GetCurrentCam()->GetPositionF3().z+ViewRadius)) )||

		(/*left of*/obj->GetPosition().x<(CurrentRenderer->GetCurrentCam()->GetPositionF3().x-ViewRadius))  ||
		(/*below*/obj->GetPosition().y<(CurrentRenderer->GetCurrentCam()->GetPositionF3().y-ViewRadius))  ||
		(/*behind*/obj->GetPosition().z<(CurrentRenderer->GetCurrentCam()->GetPositionF3().z-ViewRadius)) )
	{
		//Object out of radius
		
		    if(obj->IsObjInDrawList())
				CurrentRenderer->RemoveObjectFromRenderList(obj);


		return false;
	}
	else
	{//Object in radius
	
			if(!obj->IsObjInDrawList())
				CurrentRenderer->AddObjectToRenderList(obj);
		return true;

	}
		return false;
}



How should I go about this?

I'm expecting the answer to be Spacial partitioning by means of some k-d tree ( which I have little-to-no xp with :stupid: ).
But then how do I go about organizing the objects into said tree?
Do I have to group all objects in an area and only draw those objects when the player is there?

From what I understand it is a good idea ( performance wise) to partition space into blocks.

then I'm thinking I could draw all objects in the current 'Block' and any other block the camera/player is close to;
so if the camera is in the centre of a block draw all objects in that block and depending on block size and LOD options
also draw everything in adjacent blocks?

Then the terrain could also be drawn for the blocks adjacent to those?

How would I go about organizing the objects into a space? have each object have a variable as an ID to their home block?
Then if the object was carried to another location change it's parent block by some means?

:surrender:
Thanks for reading my rant and I hope the :helpsmilie: will comes flowing in :whistling:

Is This A Good Question/Topic? 1
  • +

Page 1 of 1