Author Topic: CameraMovement  (Read 1382 times)

Offline graydsl

  • byte
  • *
  • Posts: 3
    • View Profile
CameraMovement
« on: October 15, 2010, 10:26:53 am »
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!


Code: [Select]
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;
}
}

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: CameraMovement
« Reply #1 on: October 15, 2010, 11:27:55 am »
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).

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: CameraMovement
« Reply #2 on: October 15, 2010, 11:28:45 am »

Offline graydsl

  • byte
  • *
  • Posts: 3
    • View Profile
Re: CameraMovement
« Reply #3 on: October 15, 2010, 11:59:50 am »
I figured it out. :) BTW it's an vertical scrolling camera. Works pretty nice right now. But I'm open for suggestions. ^^

onDrawFrame:
Code: [Select]
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:
Code: [Select]
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;
}
}