Here is a code that I wrote which will allow you to zoom in and out with the mouse wheel, also you can hold down the middle mouse and move the camera around. It is set up for an RPG, so the camera is third person, the mouse mode will automatically change back and forth for you between camera functions, and selection cursor. The camera rotates around the player, you can play with the camera arc. and z position to move it higher or lower. Have fun!
Code:
function default_camera()
{
camera.clip_near = 0;
camera.tilt = -15;
// distance_to_player = c_trace (camera.x, player.x, IGNORE_ME | IGNORE_SPRITES | IGNORE_PASSABLE);
while (1)
{
if (mickey.z > 1)
{
mouse_mode = 0;
camera.arc += 10 * time_step;
}
if (mickey.z < -1)
{
mouse_mode = 0;
camera.arc -= 10 * time_step; // play with "10"
}
if(mouse_middle == 1)
{
mouse_mode = 0;
key_a = 0;
key_d = 0;
camera.pan -= mouse_force.x * 5 * time_step; //turn left and right
camera.tilt += mouse_force.y * 5 * time_step;
camera.x = player.x - 200 * cos(camera.pan); // camera follows player
camera.y = player.y - 200 * sin(camera.pan); // same here
camera.z = player.z +200; // place the camera above the player
vec_set(mouse_pos,mouse_cursor); // gets the point of cursor
}
else
{
mouse_mode = 2;
camera.x = player.x - 200 * cos(player.pan); // camera follows player
camera.y = player.y - 200 * sin(player.pan); // same here
camera.z = player.z +200; // place the camera above the player
camera.pan = player.pan; // the camera and the player have the same pan angle
vec_set(mouse_pos,mouse_cursor);
}
camera.arc = minv (maxv (camera.arc, 10), 120);
wait (1);
}
}
be sure to include this in your main function in this order:
Code:
mouse_mode = 0;
wait(3);
// now load the level
level_load("your_level.wmb");
while (player == NULL) {wait (1);}
mouse_map = yourmousemap_pcx;
default_camera();