GPWiki.org
GPWiki.org
It is currently Sun May 26, 2013 8:47 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Thu May 10, 2012 8:32 am 
Rookie

Joined: Thu May 10, 2012 7:59 am
Posts: 2
DirectX 11 3D
Let's say I have rendered a separate ground plane and a box on it or 1.0f higher than it.
The camera can navigate freely but cannot go lower than the ground plane Y axis.
How to make the camera cannot go through the box and while the camera position is above the box,it cannot go lower while being above it.
If I render the box around like 10.0f higher than the ground plane,how to make the camera can go through the gap but cannot go up through the box?

Sorry for the poor explanation.

Is it called as height map,collision detection or something else? :\
I'm trying to solve this part before I try render a stair model (bunch of blocks with large space under it) I've made with blender.
It looks like the below example.
[ ]
--[ ]
----[ ]
------[ ]

*edited*
I've found this link which somehow explained it but now I have another question..Do I have to create a bounding box for each object I have rendered? :\
I'm not using XNA and planning to do pure DirectX for a basic game engine.

*edited again*
Since there's still no reply yet,I'm trying the collision detection method.
I made a separate function of loading model file for creating a bounding box for the box model.
Since I'm doing DirectX11,I'm not using Directx9 library so I'm not sure I'm doing it correctly.
Can someone tell me if I did it right or not..
*added*
Forgot to inform that the code below are for OBB and I'll do OBB colission instead of AABB collision
because I'll render some long cuboids with different rotation.
I hope OBB is the right choice. :\

Code:
   //m_model is a struct for holding vertex, texture and normal data of loaded model data
   //minbound and maxbound is a struct for getting the 8 corners position
   //m_objectbound is an array of 8 D3DXVECTOR3 variable

   m_maxbound->x = m_model[0].x;
   m_maxbound->y = m_model[0].y;
   m_maxbound->z = m_model[0].z;
   m_maxbound->x = m_model[0].x;
   m_maxbound->y = m_model[0].y;
   m_maxbound->z = m_model[0].z;

   for(i=0; i<m_vertexCount; i++)
   {
      if(m_model[0].x < m_minbound->x)
         m_minbound->x = m_model[i].x;
      if(m_model[0].y < m_minbound->y)
         m_minbound->y = m_model[i].y;
      if(m_model[0].z < m_minbound->z)
         m_minbound->z = m_model[i].z;
      if(m_model[0].x > m_maxbound->x)
         m_maxbound->x = m_model[i].x;
      if(m_model[0].y > m_maxbound->y)
         m_maxbound->y = m_model[i].y;
      if(m_model[0].z > m_maxbound->z)
         m_maxbound->z = m_model[i].z;
   }

   m_objectbound[0] = D3DXVECTOR3( m_minbound->x , m_minbound->y , m_minbound->z);
   m_objectbound[1] = D3DXVECTOR3( m_maxbound->x , m_minbound->y , m_minbound->z);
   m_objectbound[2] = D3DXVECTOR3( m_minbound->x , m_maxbound->y , m_minbound->z);
   m_objectbound[3] = D3DXVECTOR3( m_maxbound->x , m_maxbound->y , m_minbound->z);
   m_objectbound[4] = D3DXVECTOR3( m_minbound->x , m_minbound->y , m_maxbound->z);
   m_objectbound[5] = D3DXVECTOR3( m_maxbound->x , m_minbound->y , m_maxbound->z);
   m_objectbound[6] = D3DXVECTOR3( m_minbound->x , m_maxbound->y , m_maxbound->z);
   m_objectbound[7] = D3DXVECTOR3( m_maxbound->x , m_maxbound->y , m_maxbound->z);


Top
 Profile  
 
PostPosted: Sat May 12, 2012 2:01 pm 
Dexterous Droid
User avatar

Joined: Wed Aug 18, 2004 7:40 pm
Posts: 3735
Location: South Africa
You might want to experiment with collision detection in 2D before jumping into 3D.

Camera control can be quite tricky, you'll want to do some ray casting if you want to have a truly robust system. If the ray between the camera and the player is obstructed, then either adjust the camera height or fade out the offending objects.

If you're dealing with more simple geometry, like box shaped rooms with only slight variations in ceiling height, it might be a good idea to rather base the camera height on it's proximity to things that jut down from the ceiling. You could keep track of the objects that do this in a list on a room by room basis.

_________________
Whatever the mind can conceive and believe, it can achieve


Top
 Profile  
 
PostPosted: Sun May 13, 2012 7:44 am 
Rookie

Joined: Thu May 10, 2012 7:59 am
Posts: 2
IGTHORN wrote:
You might want to experiment with collision detection in 2D before jumping into 3D.

I prefer doing the hard way because I'll be more motivated if I do it this way.

IGTHORN wrote:
Camera control can be quite tricky, you'll want to do some ray casting if you want to have a truly robust system. If the ray between the camera and the player is obstructed, then either adjust the camera height or fade out the offending objects.

I'll try it.

IGTHORN wrote:
If you're dealing with more simple geometry, like box shaped rooms with only slight variations in ceiling height, it might be a good idea to rather base the camera height on it's proximity to things that jut down from the ceiling. You could keep track of the objects that do this in a list on a room by room basis.

I didn't thought of that! :)
I was focusing too much on collision until I feel like something was missing.
Thanks for mentioning about box shaped rooms because I've remembered something when it comes to graphic performance.
When I was mentioning box shaped rooms to myself,it did not remind me of something but when you mentioned it,I've remembered it. :thumbs

If there is some people who feels like I didn't make any sense in my first post in this thread,I'm trying to grasp multiple concepts and techniques at once.
It is camera positioning and collision+3D character movement(I did not rendered it but I'm pretty sure I can get the concept while doing camera positioning and collision)+making steps of rendering graphic like terrain then object then character+making level file structure.
Sorry if it was confusing.. :\
I'm not good in English.


Top
 Profile  
 
PostPosted: Sun May 13, 2012 5:59 pm 
Dexterous Droid
User avatar

Joined: Wed Aug 18, 2004 7:40 pm
Posts: 3735
Location: South Africa
Glad you managed to figure it out. Sorry I couldn't give a better explanation but it's not really something I know a lot about :)

_________________
Whatever the mind can conceive and believe, it can achieve


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group