jPCT-AE - a 3d engine for Android > Support

CameraMovement

(1/1)

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!



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

--- End code ---

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).

Thomas.:
This may help
http://www.jpct.net/wiki/index.php/Main_Page

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

onDrawFrame:

--- Code: --- 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();
}

--- End code ---

moveCamera:

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

--- End code ---

Navigation

[0] Message Index

Go to full version