Jump to content
  • Advertisement
Sign in to follow this  

Simple 3D question

This topic is 5038 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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!