arctess.cc
来自「Mesa is an open-source implementation of」· CC 代码 · 共 612 行 · 第 1/2 页
CC
612 行
/*** License Applicability. Except to the extent portions of this file are** made subject to an alternative license as permitted in the SGI Free** Software License B, Version 1.1 (the "License"), the contents of this** file are subject only to the provisions of the License. You may not use** this file except in compliance with the License. You may obtain a copy** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:**** http://oss.sgi.com/projects/FreeB**** Note that, as provided in the License, the Software is distributed on an** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.**** Original Code. The Original Code is: OpenGL Sample Implementation,** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.** Copyright in any portions created by third parties is as indicated** elsewhere herein. All Rights Reserved.**** Additional Notice Provisions: The application programming interfaces** established by SGI in conjunction with the Original Code are The** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X** Window System(R) (Version 1.3), released October 19, 1998. This software** was created using the OpenGL(R) version 1.2.1 Sample Implementation** published by SGI, but has not been independently verified as being** compliant with the OpenGL(R) version 1.2.1 Specification.*//* * arctessellator.c++ * */#include "glimports.h"#include "mystdio.h"#include "myassert.h"#include "arctess.h"#include "bufpool.h"#include "simplemath.h"#include "bezierarc.h"#include "trimvertex.h"#include "trimvertpool.h"#define NOELIMINATION#define steps_function(large, small, rate) (max(1, 1+ (int) ((large-small)/rate)));/*----------------------------------------------------------------------------- * ArcTessellator - construct an ArcTessellator *----------------------------------------------------------------------------- */ArcTessellator::ArcTessellator( TrimVertexPool& t, Pool& p ) : pwlarcpool(p), trimvertexpool(t){}/*----------------------------------------------------------------------------- * ~ArcTessellator - destroy an ArcTessellator *----------------------------------------------------------------------------- */ArcTessellator::~ArcTessellator( void ){}/*----------------------------------------------------------------------------- * bezier - construct a bezier arc and attach it to an Arc *----------------------------------------------------------------------------- */voidArcTessellator::bezier( Arc *arc, REAL s1, REAL s2, REAL t1, REAL t2 ){ assert( arc != 0 ); assert( ! arc->isTessellated() );#ifndef NDEBUG switch( arc->getside() ) { case arc_left: assert( s1 == s2 ); assert( t2 < t1 ); break; case arc_right: assert( s1 == s2 ); assert( t1 < t2 ); break; case arc_top: assert( t1 == t2 ); assert( s2 < s1 ); break; case arc_bottom: assert( t1 == t2 ); assert( s1 < s2 ); break; case arc_none: (void) abort(); break; }#endif TrimVertex *p = trimvertexpool.get(2); arc->pwlArc = new(pwlarcpool) PwlArc( 2, p ); p[0].param[0] = s1; p[0].param[1] = t1; p[1].param[0] = s2; p[1].param[1] = t2; assert( (s1 == s2) || (t1 == t2) ); arc->setbezier();}/*----------------------------------------------------------------------------- * pwl_left - construct a left boundary pwl arc and attach it to an arc *----------------------------------------------------------------------------- */voidArcTessellator::pwl_left( Arc *arc, REAL s, REAL t1, REAL t2, REAL rate ){ assert( t2 < t1 );/* if(rate <= 0.06) rate = 0.06;*//* int nsteps = 1 + (int) ((t1 - t2) / rate ); */ int nsteps = steps_function(t1, t2, rate); REAL stepsize = (t1 - t2) / (REAL) nsteps; TrimVertex *newvert = trimvertexpool.get( nsteps+1 ); int i; for( i = nsteps; i > 0; i-- ) { newvert[i].param[0] = s; newvert[i].param[1] = t2; t2 += stepsize; } newvert[i].param[0] = s; newvert[i].param[1] = t1; arc->makeSide( new(pwlarcpool) PwlArc( nsteps+1, newvert ), arc_left );}/*----------------------------------------------------------------------------- * pwl_right - construct a right boundary pwl arc and attach it to an arc *----------------------------------------------------------------------------- */voidArcTessellator::pwl_right( Arc *arc, REAL s, REAL t1, REAL t2, REAL rate ){ assert( t1 < t2 );/* if(rate <= 0.06) rate = 0.06;*//* int nsteps = 1 + (int) ((t2 - t1) / rate ); */ int nsteps = steps_function(t2,t1,rate); REAL stepsize = (t2 - t1) / (REAL) nsteps; TrimVertex *newvert = trimvertexpool.get( nsteps+1 ); int i; for( i = 0; i < nsteps; i++ ) { newvert[i].param[0] = s; newvert[i].param[1] = t1; t1 += stepsize; } newvert[i].param[0] = s; newvert[i].param[1] = t2; arc->makeSide( new(pwlarcpool) PwlArc( nsteps+1, newvert ), arc_right );}/*----------------------------------------------------------------------------- * pwl_top - construct a top boundary pwl arc and attach it to an arc *----------------------------------------------------------------------------- */voidArcTessellator::pwl_top( Arc *arc, REAL t, REAL s1, REAL s2, REAL rate ){ assert( s2 < s1 );/* if(rate <= 0.06) rate = 0.06;*//* int nsteps = 1 + (int) ((s1 - s2) / rate ); */ int nsteps = steps_function(s1,s2,rate); REAL stepsize = (s1 - s2) / (REAL) nsteps; TrimVertex *newvert = trimvertexpool.get( nsteps+1 ); int i; for( i = nsteps; i > 0; i-- ) { newvert[i].param[0] = s2; newvert[i].param[1] = t; s2 += stepsize; } newvert[i].param[0] = s1; newvert[i].param[1] = t; arc->makeSide( new(pwlarcpool) PwlArc( nsteps+1, newvert ), arc_top );}/*----------------------------------------------------------------------------- * pwl_bottom - construct a bottom boundary pwl arc and attach it to an arc *----------------------------------------------------------------------------- */voidArcTessellator::pwl_bottom( Arc *arc, REAL t, REAL s1, REAL s2, REAL rate ){ assert( s1 < s2 );/* if(rate <= 0.06) rate = 0.06;*//* int nsteps = 1 + (int) ((s2 - s1) / rate ); */ int nsteps = steps_function(s2,s1,rate); REAL stepsize = (s2 - s1) / (REAL) nsteps; TrimVertex *newvert = trimvertexpool.get( nsteps+1 ); int i; for( i = 0; i < nsteps; i++ ) { newvert[i].param[0] = s1; newvert[i].param[1] = t; s1 += stepsize; } newvert[i].param[0] = s2; newvert[i].param[1] = t; arc->makeSide( new(pwlarcpool) PwlArc( nsteps+1, newvert ), arc_bottom );}/*----------------------------------------------------------------------------- * pwl - construct a pwl arc and attach it to an arc *----------------------------------------------------------------------------- */voidArcTessellator::pwl( Arc *arc, REAL s1, REAL s2, REAL t1, REAL t2, REAL rate ){/* if(rate <= 0.06) rate = 0.06;*/ int snsteps = 1 + (int) (glu_abs(s2 - s1) / rate ); int tnsteps = 1 + (int) (glu_abs(t2 - t1) / rate ); int nsteps = max(1,max( snsteps, tnsteps )); REAL sstepsize = (s2 - s1) / (REAL) nsteps; REAL tstepsize = (t2 - t1) / (REAL) nsteps; TrimVertex *newvert = trimvertexpool.get( nsteps+1 ); long i; for( i = 0; i < nsteps; i++ ) { newvert[i].param[0] = s1; newvert[i].param[1] = t1; s1 += sstepsize; t1 += tstepsize; } newvert[i].param[0] = s2; newvert[i].param[1] = t2; /* arc->makeSide( new(pwlarcpool) PwlArc( nsteps+1, newvert ), arc_bottom ); */ arc->pwlArc = new(pwlarcpool) PwlArc( nsteps+1, newvert ); arc->clearbezier(); arc->clearside( );}/*----------------------------------------------------------------------------- * tessellateLinear - constuct a linear pwl arc and attach it to an Arc *----------------------------------------------------------------------------- */voidArcTessellator::tessellateLinear( Arc *arc, REAL geo_stepsize, REAL arc_stepsize, int isrational ){ assert( arc->pwlArc == NULL ); REAL s1, s2, t1, t2; //we don't need to scale by arc_stepsize if the trim curve //is piecewise linear. Reason: In pwl_right, pwl_left, pwl_top, pwl_left, //and pwl, the nsteps is computed by deltaU (or V) /stepsize. //The quantity deltaU/arc_stepsize doesn't have any meaning. And //it causes problems: see bug 517641 REAL stepsize = geo_stepsize; /* * arc_stepsize*/; BezierArc *b = arc->bezierArc; if( isrational ) { s1 = b->cpts[0] / b->cpts[2]; t1 = b->cpts[1] / b->cpts[2]; s2 = b->cpts[b->stride+0] / b->cpts[b->stride+2]; t2 = b->cpts[b->stride+1] / b->cpts[b->stride+2]; } else { s1 = b->cpts[0]; t1 = b->cpts[1]; s2 = b->cpts[b->stride+0]; t2 = b->cpts[b->stride+1]; } if( s1 == s2 ) if( t1 < t2 ) pwl_right( arc, s1, t1, t2, stepsize );
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?