📄 libfbx-3d.c
字号:
/* * libfbx-3d.c -- 3D Drawing and Calculation Functions * (C)opyright 2000-2001 U4X Labs * * Written by: Mike Bourgeous <nitrogen@u4x.org> * Sat Sep 2 17:51:53 EDT 2000 * * $Id: libfbx-3d.c,v 1.5 2001/01/01 08:46:17 lethal Exp $ * * Originally part of fbgraph.c, now separate. Responsible * for drawing 3D pixels, calculating 3D projections, and other * 3D drawing or calculation functions. * * See ChangeLog for modifications, CREDITS for credits. * * All source herein is copyright U4X Labs and its original author. * Any code modifications or additions are (C)opyright the original * author and U4X Labs respectively. * * libfbx 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 2.1 of * the License, or (at your option) any later version. * * libfbx 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 libfbx; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */#include <stdio.h>#include <errno.h>#include <fcntl.h>#include <unistd.h>#include <stdlib.h>#include <stdarg.h>#include <string.h>#include <signal.h>#include <time.h>#include <math.h>#include <linux/fb.h>#include <linux/kd.h>#include <sys/mman.h>#include <sys/ioctl.h>#include <sys/user.h>#include <termios.h>#include <ctype.h>#include <libfbx/libfbx.h>float view_angle, view_width, view_height, view_scalar_x, view_scalar_y;int view_offset_x, view_offset_y;/* * Function: fb_set_viewport() * Arguments: The viewing angle of the 3D camera in degrees. * Returns: None * Description: Sets the viewing angle used for projections done * by the 3D projection routines. */void fb_set_viewport(float angle, int width, int height){ view_angle = angle; view_width = width; view_height = height; view_scalar_x = (float)(width / 2); view_scalar_y = -(float)(height / 2); view_offset_x = width / 2; view_offset_y = height / 2;}/* * Function: fb_project_3d() * Arguments: * Returns: None * Description: */void fb_project_3d(float x, float y, float z, int *u, int *v){ /* * Hopefully two multiplications are less * expensive than one division. */ float invz = 1.0 / z; *u = (int)(view_scalar_x * x * invz) + view_offset_x; *v = (int)(view_scalar_y * y * invz) + view_offset_y;}/* * Function: fb_putpixel_3d() * Arguments: x, y, and z positioners, rgb values, * surface to work on. * Returns: None * Description: Plots a pixel in 3d space with rgb values * on surface. */void fb_putpixel_3d(float x, float y, float z, int r, int g, int b, fb_surface *surface){ int u, v; if (z <= 0) return; u = (int)((float)(surface->width / 2) * (x / z)) + surface->width / 2; v = (int)((float)(surface->height / -2) * (y / z)) + surface->height / 2; fb_putpixel(u, v, r, g, b, surface);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -