Collision detection with a mesh
What i have done is load up a map as a mesh in a very basic fps i am fiddling with.
what im wondering is if there is anyway to detect when the player(camera) hits the walls without going through and one by one entering each wall into the code.
im hoping there is because i want to be able to load in other maps and not have to enter in each wall individually.
cheers
Quote:Original post by kiwidrifterYou wouldn't enter the collision data into the code any more than you'd enter the mesh data itself into the code. In other words, the collision data should be loaded from a file (or whatever) in the same way that the mesh itself is. (Or, if the environment and collision representation is simple, you could just generate the collision data from the mesh data at run time when the mesh is loaded.)
What i have done is load up a map as a mesh in a very basic fps i am fiddling with.
what im wondering is if there is anyway to detect when the player(camera) hits the walls without going through and one by one entering each wall into the code.
im hoping there is because i want to be able to load in other maps and not have to enter in each wall individually.
cheers
are u able to explain a bit more.
i know i will be able to set up the code to detect collision by typing in the vertices of the walls but this would be ridicolous having to do this every time i load in a different map
i think what im trying to do is retrieve the vertices from the mesh into an array of vertices that i can then use in a function for collision
EDIT: ive managed to create an object for my 'player' which just happens to share its coordinates with my camera, ive figured it will be easier this way.
still need to figure out how to retrieve the vertices or planes from a mesh, once ive done this it should be easy enough to write some code to check for the players collision with any walls of my map and also the floor(so i can walk up stairs etc)
ive got no idea how though and i cant find any examples on google or here(id prefer and example code, easier for me to learn this way)
[Edited by - kiwidrifter on March 21, 2010 1:47:09 AM]
i know i will be able to set up the code to detect collision by typing in the vertices of the walls but this would be ridicolous having to do this every time i load in a different map
i think what im trying to do is retrieve the vertices from the mesh into an array of vertices that i can then use in a function for collision
EDIT: ive managed to create an object for my 'player' which just happens to share its coordinates with my camera, ive figured it will be easier this way.
still need to figure out how to retrieve the vertices or planes from a mesh, once ive done this it should be easy enough to write some code to check for the players collision with any walls of my map and also the floor(so i can walk up stairs etc)
ive got no idea how though and i cant find any examples on google or here(id prefer and example code, easier for me to learn this way)
[Edited by - kiwidrifter on March 21, 2010 1:47:09 AM]
I think you'll have to supply more information (e.g. how you're loading the mesh, what graphics API you're using, etc.). As is, it's not really clear (to me at least) what the problem is.
ok im using visual basic 2008 to write the code in c++, using directx
im not using anything to handle collision at the moment.
if i were to do it, they only way i can think of is do an if statement that checks to make sure the Xpos and Zpos of the player doesnt not equal the Xpos and Zpos of any walls.
but i would have to manually enter in each walls vertices and have an if statement for each one.
ie:
im trying to figure out how to retrieve the Xpos and Zpos of each wall(subset) from the mesh so i dont have to manually enter them.
im not using anything to handle collision at the moment.
if i were to do it, they only way i can think of is do an if statement that checks to make sure the Xpos and Zpos of the player doesnt not equal the Xpos and Zpos of any walls.
but i would have to manually enter in each walls vertices and have an if statement for each one.
ie:
//2 walls infinite widewall[0]->Xpos = 50;wall[1]->Xpos = -50;if(player->Xpos == wall[1]->Xpos + 1 && player->Xlook <= wall[1]->Xpos + 1) player->Xmove = false;
im trying to figure out how to retrieve the Xpos and Zpos of each wall(subset) from the mesh so i dont have to manually enter them.
Quote:im trying to figure out how to retrieve the Xpos and Zpos of each wall(subset) from the mesh so i dont have to manually enter them.As I mentioned earlier, I don't think we can answer this question unless we know what the problem is exactly. To restate my questions from earlier:
1. How are you loading the mesh?
2. What graphics API are you using?
im using D3DXLoadMeshFromX() to load the mesh.
here is the whole function:
im using directx 9.0
here is the whole function:
//Function to load a meshvoid LoadMesh(MESH* mesh, LPCTSTR file){ LPD3DXBUFFER bufMaterial; D3DXLoadMeshFromX(file, D3DXMESH_SYSTEMMEM, d3ddev, NULL, &bufMaterial, NULL, &mesh->numMaterials, &mesh->mesh); D3DXMATERIAL* tempMaterials = (D3DXMATERIAL*)bufMaterial->GetBufferPointer(); mesh->material = new D3DMATERIAL9[mesh->numMaterials]; mesh->texture = new LPDIRECT3DTEXTURE9[mesh->numMaterials]; for(DWORD index = 0; index < mesh->numMaterials; index++) { mesh->material[index] = tempMaterials[index].MatD3D; mesh->material[index].Ambient = mesh->material[index].Diffuse; if(FAILED(D3DXCreateTextureFromFileA(d3ddev, tempMaterials[index].pTextureFilename, &mesh->texture[index]))) { mesh->texture[index] = NULL; } } return;}
im using directx 9.0
Quote:im using D3DXLoadMeshFromX() to load the mesh.I found this using Google (first hit for 'directx get mesh data'). Look towards the end in the section titled, 'I want to access the vertex data in my .x file, how can I?', and see if that helps.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement