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

## 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 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 secondfloat speed_high_height = 100.0f; // 100 meters per secondfloat low_height = 1.0f; // 1 m altitudefloat high_height = 1000.0f; // 1 km altitudefloat 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;

1. 1
2. 2
3. 3
4. 4
Rutin
17
5. 5

• 13
• 14
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
632927
• Total Posts
3009242
• ### Who's Online (See full list)

There are no registered users currently online

×