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);