WIP: Minesweeper 3D - Contest entry

Hi all,

I am planning to make a Minesweeper 3d game, similar to this one:

http://weegen.home.xs4all.nl/Minesweeper3D/screenshot-cube.png



Not an innovative idea, but will be great for me to learn the basics in JME3.



My inspiration: http://weegen.home.xs4all.nl/Minesweeper3D/

5 Likes

hehe :D!

Good luck :slight_smile: If you need any help with the rules, just ask :slight_smile:

this sounds awesome, i love puzzle games, good luck with this

Nice one. :slight_smile: keep us posted.

Hi again,



Don’t know if I can ask here or I need a separate entry in the “Troubleshooting” section, but I need help with setting up a “good working” chase cam.

Here is a video of what currently happens:

http://www.youtube.com/watch?v=2wtwND1oahE



- Basically two issues with default chacecam
1) while dragging the cursor disappears (this is not apparent in the video, I guess the recording program sucks too), when I release the mouse button it appears again. How can I make it always visible?
2) cannot do a full rotation on the object while dragging the mouse along x or y axis - there is a strange limit (seen at the beginning of the video - 0:15 to 0:20 sec) and in the opposite direction when I exceed 180 degrees a flip occurs. Why?

How I set up cams:
[java]
// disable the fly cam
flyCam.setEnabled(false);
setPauseOnLostFocus(false);

//Chase camera
ChaseCamera chaseCam = new ChaseCamera(cam, inputManager);
rootNode.addControl(chaseCam);
chaseCam.setDragToRotate(true);
chaseCam.setMaxVerticalRotation(FastMath.TWO_PI);//Doesn't help much

//TODO can't get it to playnly rotate 360 degrees without junping
chaseCam.setSmoothMotion(true);
chaseCam.setChasingSensitivity(9);

chaseCam.setTrailingEnabled(true);
chaseCam.setTrailingRotationInertia(0.01f);
chaseCam.setTrailingSensitivity(0.2f);
[/java]

Here is the full code:
http://www.megaupload.com/?d=NZ28E52C


Any help is appreciated.

In the past I have used inputManager.setCursorVisible(true); to help with cursor visibility. If you simply can’t get it to work properly, you could hide the cursor at all times and add in your own which would give you full control.



If you’re having too much trouble with the ChaseCam, you could try switching to a fixed camera position / rotation and then controlling the rotation of your model instead, this might help simply the system and remove some buggy behaviour in the process… or it will be a huge headache :wink:



Good luck, sorry I can’t offer much more help on this one.

1 Like

Thanks, thetoucher.

Unfortunately it seems cursor visibility is poorly implemented in ChaseCamera, so i decided to implement my own rotation camera using the virtual trackball concept. As for the cursor I’ll use custom software cursor as shown in the TestSoftwareMouse.

Hi again, some updates and more problems to ask about.



Current state - Implemented a rotation camera, which allows rotating in any direction around the target at fixed distance using the virtual trackball concept listed here:

Trackball



Here is what I ended up with:

http://www.youtube.com/watch?v=lYgpLc7AFnI



Unfortunately it does not behave exactly as I expected - at the end of the video when I drag the mouse in lower left of the screen in form of "u" it rotates OK, but dragging the mouse in the form of "n" in the upper half (at end of video) it rotates the target in the opposite direction of the one expected.

Here is the code snippet to calculate rotation:
[java]
/**
* Mouse movement detection
* @param evt
*/
public void onMouseMotionEvent(MouseMotionEvent evt)
{
//is Start of dragging
boolean isStartDragging = toRotate;
//currently dragging?
toRotate = isButtonPressed && (evt.getDX() != 0 || evt.getDY() != 0);
isStartDragging = !isStartDragging && toRotate;

if (toRotate)
{
float[] xyzCoord;

//Start of dragging, need to calculate start trackball position at moment of
//start of dragging
if (isStartDragging)
{
xyzCoord = calculateTrackballCoordinates(evt.getX() - evt.getDX(), evt.getY() - evt.getDY());
startTrackballPos.set(xyzCoord[0], xyzCoord[1], xyzCoord[2]);
startTrackballPos = startTrackballPos.normalize();
}
else
{
startTrackballPos.set(trackballPos);
}

xyzCoord = calculateTrackballCoordinates(evt.getX(), evt.getY());
trackballPos.set(xyzCoord[0], xyzCoord[1], xyzCoord[2]);

//normalize new position
trackballPos = trackballPos.normalize();

//Axis of rotation = cross product of start and current trackball vectors
trackballPos.cross(startTrackballPos, targetRotationAxis);

//Angle of rotation - inverse, because the camera is moving in the opposite direction
targetRotationAngle = - trackballPos.angleBetween(startTrackballPos);
}
}

/**
* Calculate trackball coordinates according mouse coordinates
* @param mouseX
* @param mouseY
* @return array with x,y,z on trackball
*/
private float[] calculateTrackballCoordinates(int mouseX, int mouseY)
{
//trsanslate current mouse position to center of screen
//and relative to circle with diameter 2, which is centeed on screen
float x;
float y;
float z;

//If trackball is sphere
if (ignoreAspectRatio)
{
//shift mouse x to get into the rectangular area
if (screenWidth > screenHeight)
{
mouseX -= half_scr_width - half_scr_height;
if (mouseX < 0)
{
mouseX = 0;
}
else if (mouseX > screenHeight)
{
mouseX = screenHeight;
}
}
//shift mouse y to get into the rectangular area
else if (screenWidth < screenHeight)
{
mouseY -= half_scr_height - half_scr_width;
if (mouseY < 0)
{
mouseY = 0;
}
else if (mouseY > screenWidth)
{
mouseY = screenWidth;
}
}
x = mouseX/min_half_scr - 1;
y = 1 - mouseY/min_half_scr;
}
else //or is actually elipsoid based on screen resolution
{
x = mouseX/half_scr_width - 1;
y = 1 - mouseY/half_scr_height;
}

//Calculate square sum of x and y
float squareSum = x*x + y*y;
//If sum <= 0.5 use sphere to calculate Z, else use hyperbolic sheet
z = (squareSum <= 0.5f) ? (1f - squareSum): 0.25f/squareSum;
//Calculate z cooordiante of the point on the sphere beneath the mouse pointer.
z = FastMath.sqrt(z);

//x and z of virtual trackball are reversed for JME world
return new float[]{z, y, x};
}
[/java]

Then to rotate the camera, I do:
[java]
//Calculate quaternion, adding it to previous rotation
rotationQuat.fromAngleAxis(targetRotationAngle, targetRotationAxis);

//apply rotation
dummyTargetNode.rotate(rotationQuat);
[/java]

If someone can help we with this I'd really apreciate it, cause I simply can't wrap my brain around it.
Here is the whole code if anyone is interested in trying it out.
source

Regards,
n

I played around with your roration for ages comparing it to how Blender handles it: which I concider to be a perfect implimentation of trackball rotation.



I twiddled your source (which I must say looks excellent, very nice work) but gave up since its not my problem lol :slight_smile: … you will have more luck fixing it than I would anyway.



Now I dont have a fix but I did notice some odd behaviour that my help you track down the issue.



This is the most important thing I noticed: in Blender, after you press down the mouse and start rotating around (for this example, never releasing the mouse, always dragging), when ever you bring the cursur back to where you started dragging, the model view will be at the same rotation as when you started, regardless of how much you move aroud in the intrim, this goes for any other point on the screen, drag to that postition and the view rotation will always be the same at that point (it makes more sense if you simply have a play in Blender). Your impimentation doesnt appear to do this, your rotation keeps adding to itself which makes it feel off… you can see this if you drag small circles around the middle of the screen.





Some other observations, less important but may help:



If you dont invert the targetRotationAngle, horizontal rotation is fixed for the top half the screen (vert is obviously flipped).



When you drag starting from the middle of the left edge of the screen, diagonally towards to the middle of the bottom edge, once you go past half way (or an imaginary line from the middle of the screen to the bottom left hand corner of the screen) there is this a wierd shift in rotation axis, feels very unnatural.



I’m sorry if my explanations are unclear, I’m pretty hung over. Happy to reword or re-explain anything.



Also, have you considered shifting to a turntable style rotation? it’s so much simpler and I think its a lot more user friendly for the less experienced.



Good luck with fixing it, it feels very close.

1 Like