/* * Copyright (C) Volition, Inc. 1999. All rights reserved. * * All source code herein is the property of Volition, Inc. You may not sell * or otherwise commercially exploit the source or things you created based on the * source. * */ #include "globalincs/alphacolors.h" #include "graphics/2d.h" #include "math/spline.h" #include "render/3d.h" // ------------------------------------------------------------------------------------------------- // SPLINE DEFINES/VARS // // ------------------------------------------------------------------------------------------------- // SPLINE FUNCTIONS // static float bez_fact_lookup[13] = { 1.0f, // 0! 1.0f, // 1! 2.0f, // 2! 6.0f, // 3! 24.0f, // 4! 120.0f, // 5! 720.0f, // 6! 5040.0f, // 7! 40320.0f, // 8! 362880.0f, // 9! 3628800.0f, // 10! 39916800.0f, // 11! 479001600.0f, // 12! }; // Limited Factorial static float bez_fact(int n) { Assert((n >= 0) && (n <= 12)); return bez_fact_lookup[n]; } // bez constructor bez_spline::bez_spline() { int idx; // zero all points for(idx=0; idxxyz.x = 0.0f; out->xyz.y = 0.0f; out->xyz.z = 0.0f; for(idx=0; idxxyz.x += pts[idx].xyz.x * bez_val; // y component out->xyz.y += pts[idx].xyz.y * bez_val; // z component out->xyz.z += pts[idx].xyz.z * bez_val; } } // render a bezier void bez_spline::bez_render(int divs, color *c) { float inc; int idx; vertex a, b; vec3d pt; // bleh if(divs <= 0){ return; } inc = 1.0f / (float)divs; // draw in red gr_set_color_fast(c); // draw that many divisions bez_get_point(&pt, 0.0f); g3_rotate_vertex(&a, &pt); for(idx=1; idx<=divs; idx++){ // second point bez_get_point(&pt, (float)idx * inc); g3_rotate_vertex(&b, &pt); // draw the line g3_draw_line(&a, &b); // store b a = b; } // draw the control points gr_set_color_fast(&Color_bright_green); for(idx=0; idx