hallik

01-22-2011, 09:56 PM

I have been trying to throw together a chess game using a 3dsmax model. At this point, I have been able to import the model, highlight the selected game piece I am interested in moving, and choose a square I want to move to. Here is a screenshot of the current state:

http://img26.imageshack.us/img26/9555/chessk.png

The black circle represents where I clicked, and you can see where the pawn went. I haven't done specific calculations on where it should go. Whenever I click on the board with a selected piece, it always moves in the same direction. It's because just threw in this dummy code to start off:

if ( isObjectSelected && isSquareSelected && moveObject )

{

glPushMatrix();

glTranslatef(0.2f, 0.0f, 0.0f); //PLACEHOLDER-DUMMY CODE

}

glDrawElements( GL_TRIANGLES, pMaterial->triangleCount * 3, GL_UNSIGNED_INT, model.getIndexBuffer() + pMaterial->startIndex );

if ( isObjectSelected && isSquareSelected )

glPopMatrix();

What I was considering doing was after the model was done loading, is to somehow check which square on the board a game piece occupies. Then, when a piece is selected and a "move to" square is selected, find the x,y,z glTranslate3f to move to that center square.

Is this the best way? It seems as the game progresses, I will need to store the glTranslate of each piece individually. And when a piece goes from it's 2nd to 3rd spot, I should calculate the glTranslate from the original starting point to the 3rd spot, right?

But how would you figure out whether or not a game piece occupies a square, and how would you figure out glTranslate3f(X, Y, Z) between two squares? Here is an example of a square from my .OBJ file

#

# object Square58

#

v -37.1874 18.6313 80.7864

v -67.0955 18.6313 91.4436

v -56.4384 18.6313 121.3513

v -26.5306 18.6313 110.6938

# 4 vertices

vn 0.0000 1.0000 -0.0000

# 1 vertex normals

vt 0.0000 0.0000 0.0000

# 1 texture coords

I am assuming I would need to find the center of each square and say once the app knows this piece is in square1, and you clicked on sqaure4, calculate the translate & go. I am just not sure how to calculate the center of each square, and figure out what the translate coords should be from square1-->square4.

OR how I would determine which pieces occupies which square from the beginning. I can hard code this in during load, but it would help me more in understanding if there was a sound way to accomplish this.

All help is welcome. Thank you.

http://img26.imageshack.us/img26/9555/chessk.png

The black circle represents where I clicked, and you can see where the pawn went. I haven't done specific calculations on where it should go. Whenever I click on the board with a selected piece, it always moves in the same direction. It's because just threw in this dummy code to start off:

if ( isObjectSelected && isSquareSelected && moveObject )

{

glPushMatrix();

glTranslatef(0.2f, 0.0f, 0.0f); //PLACEHOLDER-DUMMY CODE

}

glDrawElements( GL_TRIANGLES, pMaterial->triangleCount * 3, GL_UNSIGNED_INT, model.getIndexBuffer() + pMaterial->startIndex );

if ( isObjectSelected && isSquareSelected )

glPopMatrix();

What I was considering doing was after the model was done loading, is to somehow check which square on the board a game piece occupies. Then, when a piece is selected and a "move to" square is selected, find the x,y,z glTranslate3f to move to that center square.

Is this the best way? It seems as the game progresses, I will need to store the glTranslate of each piece individually. And when a piece goes from it's 2nd to 3rd spot, I should calculate the glTranslate from the original starting point to the 3rd spot, right?

But how would you figure out whether or not a game piece occupies a square, and how would you figure out glTranslate3f(X, Y, Z) between two squares? Here is an example of a square from my .OBJ file

#

# object Square58

#

v -37.1874 18.6313 80.7864

v -67.0955 18.6313 91.4436

v -56.4384 18.6313 121.3513

v -26.5306 18.6313 110.6938

# 4 vertices

vn 0.0000 1.0000 -0.0000

# 1 vertex normals

vt 0.0000 0.0000 0.0000

# 1 texture coords

I am assuming I would need to find the center of each square and say once the app knows this piece is in square1, and you clicked on sqaure4, calculate the translate & go. I am just not sure how to calculate the center of each square, and figure out what the translate coords should be from square1-->square4.

OR how I would determine which pieces occupies which square from the beginning. I can hard code this in during load, but it would help me more in understanding if there was a sound way to accomplish this.

All help is welcome. Thank you.