/* ***************************************************************************** * update.c -- update the scene. * Copyright (C) 2017 Olivier "Ninestars" Lanneau * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey * * This file is part of libwindmill. * libwindmill is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3.0 of the License, * or (at your option) any later version. * * libwindmill is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with libwindmill; if not, see . * ************************************************************************** */ #include /** * wml_update_camera: * Update the camera. * * @arg scene the scene to update. */ void wml_update_camera(wml_scene_t *scene) { scene->camera_yaw = (int)(scene->camera_yaw + 360) % 360; float camera_yaw_rad = M_PI * scene->camera_yaw / 180.0; /* calculate intermediate value */ float camera_pitch_rad = M_PI * scene->camera_pitch / 180.0; float cos_yaw = cosf(camera_yaw_rad), sin_yaw = sinf(camera_yaw_rad); float cos_pitch = cosf(camera_pitch_rad); float sin_pitch = sinf(camera_pitch_rad); /* set final values */ scene->a1 = 128.0 * cos_yaw; scene->a2 = 128.0 * -sin_yaw; scene->a3 = 0.0; scene->a4 = 128.0 * cos_pitch * sin_yaw; scene->a5 = 128.0 * cos_pitch * cos_yaw; scene->a6 = 128.0 * -sin_pitch; scene->a7 = 128.0 * sin_pitch * sin_yaw; scene->a8 = 128.0 * sin_pitch * cos_yaw; scene->a9 = 128.0 * cos_pitch; } /** * wml_update_viewport: * Update the viewport. * * @arg scene the scene to update. */ void wml_update_viewport(wml_scene_t *scene) { free(scene->z_buffer); scene->shift_x = (scene->viewport_x1 + scene->viewport_x2 - 128) / 2; scene->shift_y = (scene->viewport_y1 + scene->viewport_y2 - 64) / 2; scene->z_buffer_size = (scene->viewport_x2 - scene->viewport_x1) * (scene->viewport_y2 -scene->viewport_y2); scene->z_buffer = (unsigned short*)calloc(scene->z_buffer_size, 2); scene->z_buffer_width = scene->viewport_x2 - scene->viewport_x1; scene->z_buffer_offset = 64 - scene->viewport_x1 + scene->z_buffer_width * (32 - scene->viewport_y1); memset(scene->z_buffer, 0xFF, scene->z_buffer_size * 2); }