1bf215546Sopenharmony_ci 2bf215546Sopenharmony_ci/* 3bf215546Sopenharmony_ci * Mesa 3-D graphics library 4bf215546Sopenharmony_ci * 5bf215546Sopenharmony_ci * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. 6bf215546Sopenharmony_ci * 7bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 8bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 9bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 10bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 12bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 13bf215546Sopenharmony_ci * 14bf215546Sopenharmony_ci * The above copyright notice and this permission notice shall be included 15bf215546Sopenharmony_ci * in all copies or substantial portions of the Software. 16bf215546Sopenharmony_ci * 17bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 21bf215546Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22bf215546Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23bf215546Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE. 24bf215546Sopenharmony_ci */ 25bf215546Sopenharmony_ci 26bf215546Sopenharmony_ci#ifndef _M_EVAL_H 27bf215546Sopenharmony_ci#define _M_EVAL_H 28bf215546Sopenharmony_ci 29bf215546Sopenharmony_ci#include "main/glheader.h" 30bf215546Sopenharmony_ci 31bf215546Sopenharmony_civoid _math_init_eval( void ); 32bf215546Sopenharmony_ci 33bf215546Sopenharmony_ci 34bf215546Sopenharmony_ci/* 35bf215546Sopenharmony_ci * Horner scheme for Bezier curves 36bf215546Sopenharmony_ci * 37bf215546Sopenharmony_ci * Bezier curves can be computed via a Horner scheme. 38bf215546Sopenharmony_ci * Horner is numerically less stable than the de Casteljau 39bf215546Sopenharmony_ci * algorithm, but it is faster. For curves of degree n 40bf215546Sopenharmony_ci * the complexity of Horner is O(n) and de Casteljau is O(n^2). 41bf215546Sopenharmony_ci * Since stability is not important for displaying curve 42bf215546Sopenharmony_ci * points I decided to use the Horner scheme. 43bf215546Sopenharmony_ci * 44bf215546Sopenharmony_ci * A cubic Bezier curve with control points b0, b1, b2, b3 can be 45bf215546Sopenharmony_ci * written as 46bf215546Sopenharmony_ci * 47bf215546Sopenharmony_ci * (([3] [3] ) [3] ) [3] 48bf215546Sopenharmony_ci * c(t) = (([0]*s*b0 + [1]*t*b1)*s + [2]*t^2*b2)*s + [3]*t^2*b3 49bf215546Sopenharmony_ci * 50bf215546Sopenharmony_ci * [n] 51bf215546Sopenharmony_ci * where s=1-t and the binomial coefficients [i]. These can 52bf215546Sopenharmony_ci * be computed iteratively using the identity: 53bf215546Sopenharmony_ci * 54bf215546Sopenharmony_ci * [n] [n ] [n] 55bf215546Sopenharmony_ci * [i] = (n-i+1)/i * [i-1] and [0] = 1 56bf215546Sopenharmony_ci */ 57bf215546Sopenharmony_ci 58bf215546Sopenharmony_ci 59bf215546Sopenharmony_civoid 60bf215546Sopenharmony_ci_math_horner_bezier_curve(const GLfloat *cp, GLfloat *out, GLfloat t, 61bf215546Sopenharmony_ci GLuint dim, GLuint order); 62bf215546Sopenharmony_ci 63bf215546Sopenharmony_ci 64bf215546Sopenharmony_ci/* 65bf215546Sopenharmony_ci * Tensor product Bezier surfaces 66bf215546Sopenharmony_ci * 67bf215546Sopenharmony_ci * Again the Horner scheme is used to compute a point on a 68bf215546Sopenharmony_ci * TP Bezier surface. First a control polygon for a curve 69bf215546Sopenharmony_ci * on the surface in one parameter direction is computed, 70bf215546Sopenharmony_ci * then the point on the curve for the other parameter 71bf215546Sopenharmony_ci * direction is evaluated. 72bf215546Sopenharmony_ci * 73bf215546Sopenharmony_ci * To store the curve control polygon additional storage 74bf215546Sopenharmony_ci * for max(uorder,vorder) points is needed in the 75bf215546Sopenharmony_ci * control net cn. 76bf215546Sopenharmony_ci */ 77bf215546Sopenharmony_ci 78bf215546Sopenharmony_civoid 79bf215546Sopenharmony_ci_math_horner_bezier_surf(GLfloat *cn, GLfloat *out, GLfloat u, GLfloat v, 80bf215546Sopenharmony_ci GLuint dim, GLuint uorder, GLuint vorder); 81bf215546Sopenharmony_ci 82bf215546Sopenharmony_ci 83bf215546Sopenharmony_ci/* 84bf215546Sopenharmony_ci * The direct de Casteljau algorithm is used when a point on the 85bf215546Sopenharmony_ci * surface and the tangent directions spanning the tangent plane 86bf215546Sopenharmony_ci * should be computed (this is needed to compute normals to the 87bf215546Sopenharmony_ci * surface). In this case the de Casteljau algorithm approach is 88bf215546Sopenharmony_ci * nicer because a point and the partial derivatives can be computed 89bf215546Sopenharmony_ci * at the same time. To get the correct tangent length du and dv 90bf215546Sopenharmony_ci * must be multiplied with the (u2-u1)/uorder-1 and (v2-v1)/vorder-1. 91bf215546Sopenharmony_ci * Since only the directions are needed, this scaling step is omitted. 92bf215546Sopenharmony_ci * 93bf215546Sopenharmony_ci * De Casteljau needs additional storage for uorder*vorder 94bf215546Sopenharmony_ci * values in the control net cn. 95bf215546Sopenharmony_ci */ 96bf215546Sopenharmony_ci 97bf215546Sopenharmony_civoid 98bf215546Sopenharmony_ci_math_de_casteljau_surf(GLfloat *cn, GLfloat *out, GLfloat *du, GLfloat *dv, 99bf215546Sopenharmony_ci GLfloat u, GLfloat v, GLuint dim, 100bf215546Sopenharmony_ci GLuint uorder, GLuint vorder); 101bf215546Sopenharmony_ci 102bf215546Sopenharmony_ci 103bf215546Sopenharmony_ci#endif 104