still stick at chess game

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
ColeZero
Posts: 20
Joined: Wed Jul 27, 2005 2:33 pm

still stick at chess game

Post by ColeZero »

Maybe someone of you can help me.
I'm still stuck at the definition of the fields.
I have a chess-board, a simple cube-model, with a board texture.
The camera, and the sounds,etc are ready. but i dont know how to make fields.
My first idea was to create 64 cube for each field,apply an invisible texture and then use the getSceneNodefromScreenCoordinates method to get the field.
BUt this is not practicable.My next idea is to create an array[] with 4 position.
example:

Field A1
|*----------*|
|..................|
|..................|
|*----------*|
The Stars are the 4 positions and if the mouse is clicked and it is in between of those 4 position field A1 is checked.

Or there another better solution, could anyone help me, please? its very importend.
THX

And last, but not least...Sry for my english ^^.
Andreas
Posts: 166
Joined: Sun Oct 31, 2004 7:15 am
Location: Münster / Germany
Contact:

Post by Andreas »

Why is your "64 cubes idea" not practicable? I think it's the most simple solution!

Code: Select all

bool black = true;
vector<ISceneNode*> pieces;
IAnimatedMesh* blackMesh = smgr->getMesh("black_piece.x");
IAnimatedMesh* whiteMesh = smgr->getMesh("white_piece.x");

for (int i=0, x=4; i < 8; i++, x--) {
    for (int j=0, y=4; j < 8; j++, y--) {
        if (black) {
            ISceneNode* boxNode = smgr->addMeshSceneNode(blackMesh->getMesh(0));
                boxNode->setPosition(vector3df(16*x,2,16*y));
                boxNode->setScale(vector3df(2,1,2));
                boxNode->setMaterialFlag(EMF_LIGHTING, false);
            boxes.push_back(boxNode);
            black = !black;
        }
        else {
            ISceneNode* boxNode = smgr->addMeshSceneNode(whiteMesh->getMesh(0));
                boxNode->setPosition(vector3df(16*x,2,16*y));
                boxNode->setScale(vector3df(2,1,2));
                boxNode->setMaterialFlag(EMF_LIGHTING, false);
            boxes.push_back(boxNode);
            black = !black;
        }
}
You will of course have to adjust the setPosition() and setScale() values so the
pieces will fit together. This will construct a chessfield around (0,0,0).

In the next step, if the player clicks on a piece, you could get the ISceneNode*
of the box, compare it to the SceneNode of a piece and do a:

Code: Select all

if (pieces.at(i).hasFigureOnIt() && pieces.at(i).ownedBy() == white && player == white) {
    - select the FigureNode;
    - get the destination field;
    - play moving animation;
    - move it to destination;
}
I hope you understand what i mean :)
Andreas
[/code]
Guest

Post by Guest »

Yes this was my idea, but the fps goes down with so many cubes.
But think you are right. Maybe i use planes, instead of cubes.
Guest

Post by Guest »

i forgot:

thx.... :D :D
Andreas
Posts: 166
Joined: Sun Oct 31, 2004 7:15 am
Location: Münster / Germany
Contact:

Post by Andreas »

No need to thank if this was your idea all along! :)

And i think frames per second are not THAT important for a chess game, are they? ;)
specialtactics
Posts: 17
Joined: Tue Dec 09, 2003 9:03 am
Location: Germany

Post by specialtactics »

Hi,
i'm doing a game in which i have a map made out of squares (so pretty close to a chess board) and i also have to check at which square the mouse is pointing. so here is how i did it: my map is a plane at z=0 (makes the calculations simpler), i then create a ray from the eye through the screen at the position of the mouse (irrlichts getRayFromCoordinates(xy) function does that). then add some simple calculation and you get get the x and y coordinates (z=0) of the intersection of that ray with your board. to find out to which square this x,y corresponds should be very simple.

Code: Select all

position2d<s32> mpos = g_device->getCursorControl()->getPosition();
line3d<f32> line = g_smgr->getSceneCollisionManager()->getRayFromScreenCoordinates(mpos);
vector3df diff = line.end - line.start;
f32 x = (line.start.X*diff.Z-line.start.Z*diff.X)/diff.Z;
f32 y = (line.start.Y*diff.Z-line.start.Z*diff.Y)/diff.Z;
Guest

Post by Guest »

OK this is a good idea,
but may be i didn't understand this right.
does your method do the same as the getSceneNodeFromScreenCoordinatesBB()?

Or did i misunderstand your method?

Code: Select all

Example:

scene::ISceneNode* selectedSceneNode =  Smgr->getSceneCollisionManager()->getSceneNodeFromScreenCoordinatesBB(device->getCursorControl()->getPosition());

//position of the selectedSceneNode

selectedSceneNode->getPosition();

specialtactics
Posts: 17
Joined: Tue Dec 09, 2003 9:03 am
Location: Germany

Post by specialtactics »

I haven't looked at how getSceneNodeFromScreenCoordinatesBB() works but i reckon it must be checking if the ray intersects with any of the bounding boxes of all nodes in the scene and returns the one which is closest. So it's definetely doing more computations than my code. Using getSceneNodeFromScreenCoordinatesBB() for deciding which square the user clicked on might also be dangerous, since any other scenenode that interects the ray closer (e.g. a chesspiece or whatever) will be returned.
Post Reply