x-file mesh collision (tetris)

Started by
7 comments, last by sh0x 14 years, 8 months ago
hi im still pretty new to direct3d just for you to know ^^ what im currently working on is a tetris copy in 3d with direct3d and c++ what i got so far is my models, loading them and controlling them what i just couldnt figure out yet is how to do the collision detection i somehow need to get the single vertices of the loaded mesh which is currently controlled and compare them to the ones of the other objects or something like this, at least thats what i thought so far feel free to suggest other ways ^^ i loaded the meshes using D3DXLoadMeshFromX() hope thats enough info, if you need anything else feel free to scream :) thx very much
Advertisement
Well if you want it based on the mesh, you could create a list of bounding boxes.
In the case of tetris, being all 'cubes', there's a zero accuracy loss.

The other way is D3DXIntersect().
Go to "DirectX SDK" on the start menu and find the "DirectX Sample Browser".
Find "Picking" and install it.

Search for D3DXIntersect(), there's some sample code for both D3DXIntersect() and manual comparison.

You can ignore the rest of the code along with the creation of rays :)


However; If you were not doing this to learn new stuff, i'd say intersection based on the meshes in tetris is the wrong tool for the job, tetis` simplicity allows for much easier ways.

Goodluck! :)
ah, so it is possible to create a bounding box that exactly matches a T or any form of geometry built with only boxes ? i always imagined that as one big box surrounding the whole mesh

thx for your reply and help, ima go and try :)
I think what he meant was to use one boundind box per rectangular shape in a mesh. For example, in a T or a L there would be two bounding boxes required (one for the vertical part and one for the horizontal one). On the other hand a Square would require only one bounding box.
"Do, or do not. There is no try." - Yoda
makes sense to me, but how do i get those parts excluded from one single mesh, or the vertices ?

thx again
Lock the buffer and read :)

You know there are only two types of objects:
Lines/Cubes which has only two different height values.

L/T objects that has 3 different height values.

Determine what kind of object you're dealing with and create the bounding volumes :)

If you generalize it a bit, you could make it support any object type that's multiple rectangles. (Useful only if you're creating new shapes)

nice because of your help i learned what to look for exactly :)

now im at a lil problem with this:

        LPVOID *meshVertices;	MESHVERTEX *copyVertices;	DWORD pitch = D3DXGetFVFVertexSize(objectT->meshData->GetFVF());	objectT->meshData->LockVertexBuffer(D3DLOCK_READONLY, meshVertices);	for(DWORD i = 0; i < objectT->meshData->GetNumVertices(); i++)	{		copyVertices = (MESHVERTEX *) meshVertices;		meshVertices+=pitch;			}	objectT->meshData->UnlockVertexBuffer();


MESHVERTEX is my own structure that looks like this

typedef struct vertexStruct{	float x, y, z;}MESHVERTEX;


meshData is the ID3DXMesh.

it gives me a memory violation error at LockVertexBuffer,
i hope im somehow on the right way now, if so i hope you can explain me this a lil bit :)

EDIT: seems like its working now, changed LPVOID *meshVertices to D3DXVECTOR3 *meshVertices

[Edited by - sh0x on August 6, 2009 10:30:09 AM]
IMHO collision should not be a problem with tetris, cause i don't think you're doing a smooth movement with tetris, but a movement that goes from block to block istantly (otherwise you could make the pieces falls into strange formations that would block the game, it just doesn't make sense).

I'll try to explain my idea of tetris.

Imagine the tetris table like a table of blocks of static size (the mesh is only one, of a simple cube without color), the movements are from block to block, not on a point level.

I implemented it without actually moving any pieces, but just hiding/showing pieces on movements or timing events (after x ms the piece go down of a rank). In these two occasions I check if the movement would make the piece "collide" with another piece and make decisions with this data.

The tetris piece when controlled by the player is a class that have a type, a state and a position. The type is the type of piece (the macrocategory), the state is in which of the 4 direction it is facing. Each combo type-state has 4 basepositions for the 4 elements it is composed of, that is added to the position to get the position of the various blocks in the table.

After the player lose control of a piece (it falls on the floor or on another piece), the system spawns another piece and reset the tetris piece class.

I hope this will be of use for your game.
EDIT (to last post reply): nonono im not doing blockstyle movement, its a smooth falling from top to bottom in 3d space with smooth rotations, its a 3D tetris not the classic one :) i might change the rotations to 90 degrees only but, im not doing this for releasing a simple game or something, my goal is to learn about making games including accurate collision detection, best way to learn is by doing :)
---------
yay i can read all the stuff now :D thx very much!

one more problem hehe

is there any function to transform a vertex with a matrix or something ? the thing is im loading only the meshes once, and then creating instances of a object class using those meshes for displaying

inside that object class theres a position vector for the object, and a pointer to the vertices retrieved by locking and reading the buffer of the mesh used by the object.

now i somehow need to update the vertex pointer with the transform matrices

This topic is closed to new replies.

Advertisement