CameraMovement

Started by graydsl, October 15, 2010, 10:26:53 AM

Previous topic - Next topic

graydsl

Hiho,

I'm developing a top secret app for my bachelor thesis. :D But I have some problems implementing camera movement. It's working, but for very small finger movement, it's not moving at all, because of slowCamMovement. But if i do it without slowCamMovement it's moving much to fast. So my question is, if there is a general strategy to implement this, which is much better than my approach? Thanks guys!



private void moveCamera(float pX, float pY) {
if (!mCameraMoving) {
mLastX = pX;
mLastY = pY;
mCameraMoving = true;
return;
} else {
if (mLastX == pX && mLastY == pY) {
return;
} else if (mLastY > pY) {
// downwards
Camera cam = mWorld.getCamera();
float speed = (mLastY - pY) / slowCamMovement; // slowCamMovement = 100f;
cam.moveCamera(Camera.CAMERA_MOVEDOWN, speed);
} else {
// upwards
Camera cam = mWorld.getCamera();
float speed = (mLastY - pY) / slowCamMovement;
cam.moveCamera(Camera.CAMERA_MOVEUP, -speed);
}
lastX = pX;
lastY = pY;
}
}


paulscode

What happens if you make slowCamMovement smaller, like say 5.0f?  Also, make sure all your variables are either floats or type-cast as floats in your "speed=" algorithm (so Java doesn't try to do integer division and round to zero).


graydsl

I figured it out. :) BTW it's an vertical scrolling camera. Works pretty nice right now. But I'm open for suggestions. ^^

onDrawFrame:

public void onDrawFrame(GL10 gl) {
if (mCameraSpeed < 0) {
mWorld.getCamera().moveCamera(Camera.CAMERA_MOVEUP, -mCameraSpeed);
} else {
mWorld.getCamera().moveCamera(Camera.CAMERA_MOVEDOWN, mCameraSpeed);
}

mCameraSpeed *= mCameraSlowing;

fb.clear(new RGBColor(220, 220, 220));
mWorld.renderScene(fb);
mWorld.draw(fb);
fb.display();
}


moveCamera:

private void moveCamera(float pX, float pY) {
if (!mCameraMoving) {
lastX = pX;
lastY = pY;
mCameraMoving = true;
return;
} else {
if (lastX == pX && lastY == pY) {
return;
} else {
mCameraSpeed += (lastY - pY) / 150f;
}
lastX = pX;
lastY = pY;
}
}