Sign in to follow this  

Simple 3D question

This topic is 4732 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm working on a map editor. The world is essentially 2D. The camera can zoom in and out on the world. It is looking directly downward toward the world "plane" Now, I want to be able to drag the camera. Regardless of how high the camera is, the camera must move so that the world moves the same number of pixels as the mouse cursor. Therefore, the camera will move slower the closer to the world plane. Given deltamousex, deltamousey, how do I calculate deltacamerax, deltacameraz? cameray is known, which is how high the camera is. Thanks!

Share this post


Link to post
Share on other sites
scale the camera movement by the height of the camera.

deltacamerax = deltamousex * camera.height * camera.speed_constant;
deltacameraz = deltamousey * camera.height * camera.speed_constant;

the speed constant depends how fast you want the camera to move in general.

you'd probably prefer to clamp the movement a bit or it could get silly. Usually, use some kind of graph, I use here a linear graph.


float speed_low_height = 1.0f; // 1 meter per second
float speed_high_height = 100.0f; // 100 meters per second
float low_height = 1.0f; // 1 m altitude
float high_height = 1000.0f; // 1 km altitude

float height_amount = (camera.height - low_height) / (high_height - low_height);
if (height_amount < 0.0f) height_amount = 0.0f; else if (height_amount > 1.0f) height_amount = 1.0f;
float speed_amount = speed_low_height + height_amount * (speed_high_height - speed_low_height);

deltacamerax = deltamousex * speed_amount;
deltacameraz = deltamousey * speed_amount;



Share this post


Link to post
Share on other sites

This topic is 4732 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this