X-O style game...how would you do it?

Hey again people…

OK I want to write a small tic-tac-toe style game (also known as X/O game) but there is this one little problem I’m having and I can’t seem to figure out an efficient way to go about it.Here’s my problem:

OK you guys know what the X/O grid looks like,right? Well,it’s going to be rotating along it’s y and x axis (but not the z) and only at small angles.Now,when the user clicks inside the grid to place an X or an O,how do I detect where he’s trying to place it? If the grid was totally static,then I can just keep checking screen coordinates and tell where to position the X or the O.But when the grid is rotating (at small angles),how do I keep track of where the user is clicking?(This grid is never going to rotate more that 60 degrees on either axis)

The way I initially though of solving this problem is by having an invisible cube at each part of the grid and then using the OpenGL selection buffer to detect which one of these cubes the user has hit.Then replace the invisible cude with an X or an O depending on what the player is.Any ideas?

Thanx guys.

just an idea, i still haven’t coded it.

get the screen coords of your mouse. convert it into the near plane system of the view frustum P = (x’,y’,-near)T.
build a lineequation from eyepoint E and P. calculate the point of collision of this line with your (transformed) X/O playfield plane. transform this point by inverted playfield plane orientation and now you can check, whether the point lies inside (and in which part) or outside your playfield.


I like your idea with the invisible cubes. Maybe just a transparent quad would do as well.

If the selection buffer isn’t giving the best results, you might want to try casting a ray from the mouse position to infinite ( well, not really ) z and just perform a simple collision detection.

Curious to know what other solutions might be out there.


I would do it using bounding boxes for each cell. As the grid rotates, you also rotate the bounding boxes. Then when the user clicks on the screen, you can project a sufficiently long line segment into the scene from that point. You could then intersect the line segment with the bounding boxes and see which one is the first to be intersected as traced from the screen end.

Cast ray,check collision.Gotcha! Anything else I should be aware of or any other ideas as to how I can make a game like this more visually pleasing? I was thinking of having a background that has this kind of “Warp” texture (Like you’re traveling through a tunnel or something

IMHO most easy-to-code is VirtualCursor. I mean an 3d arrow that flies in the paralel to game board plane(just above the grid). And an hot-track highlight on the board. All the math to do is to map screen coords to 3d coords(planar!).
Take a look at http://www.geocities.com/udodenko/spotsrul.html
It’s not an X-0 game(its Spots/Lines), but it also has a grid and cursor.


Hey Randy,thanx for that link man.I’ll check it out.