2 This file is part of the 3dengfx, realtime visualization system.
4 Copyright (c) 2004, 2005 John Tsiombikas <nuclear@siggraph.org>
6 3dengfx is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 3dengfx is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with 3dengfx; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * Author: John Tsiombikas 2005
26 #include "3denginefx.hpp"
27 #include "rend_curve.hpp"
29 RendCurve::RendCurve(Curve *curve) {
34 set_blending_mode(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
37 void RendCurve::set_curve(Curve *curve) {
41 Curve *RendCurve::get_curve() {
45 void RendCurve::set_width(scalar_t width) {
49 scalar_t RendCurve::get_width() const {
53 void RendCurve::set_blending_mode(BlendingFactor sblend, BlendingFactor dblend) {
58 void RendCurve::set_stroke(bool enable) {
62 void RendCurve::set_detail(int detail) {
63 this->detail = detail;
66 void RendCurve::set_material(const Material &mat) {
70 Material *RendCurve::get_material_ptr() {
74 Material RendCurve::get_material() const {
78 bool RendCurve::render(unsigned long time) {
79 if(!curve) return false;
81 set_matrix(XFORM_WORLD, get_prs(time).get_xform_matrix());
84 if(mat.tex[TEXTYPE_DIFFUSE]) {
85 set_texture(0, mat.tex[TEXTYPE_DIFFUSE]);
86 enable_texture_unit(0);
87 set_texture_coord_index(0, 0);
88 set_texture_unit_color(0, TOP_MODULATE, TARG_TEXTURE, TARG_PREV);
89 set_texture_unit_alpha(0, TOP_MODULATE, TARG_TEXTURE, TARG_PREV);
92 set_alpha_blending(true);
94 set_blend_func(src_blend, dst_blend);
96 int line_count = curve->get_segment_count() * detail;
97 scalar_t dx = 1.0 / (scalar_t)line_count;
99 Vector3 prev_pos = (*curve)(0.0);
100 for(int i=1; i<line_count; i++) {
101 Vector3 pos = (*curve)(t);
102 draw_line(Vertex(prev_pos, 0.0), Vertex(pos, 1.0), width, width);
107 set_alpha_blending(false);
109 disable_texture_unit(0);
114 bool RendCurve::render_segm(float start, float end, unsigned long time) {
115 if(!curve) return false;
117 set_matrix(XFORM_WORLD, get_prs(time).get_xform_matrix());
118 mat.set_glmaterial();
120 if(mat.tex[TEXTYPE_DIFFUSE]) {
121 set_texture(0, mat.tex[TEXTYPE_DIFFUSE]);
122 enable_texture_unit(0);
123 set_texture_coord_index(0, 0);
124 set_texture_unit_color(0, TOP_MODULATE, TARG_TEXTURE, TARG_PREV);
125 set_texture_unit_alpha(0, TOP_MODULATE, TARG_TEXTURE, TARG_PREV);
128 set_alpha_blending(true);
130 set_blend_func(src_blend, dst_blend);
132 int line_count = curve->get_segment_count() * detail;
133 scalar_t dx = (end - start) / (scalar_t)line_count;
134 scalar_t t = start + dx;
135 Vector3 prev_pos = (*curve)(start);
136 for(int i=1; i<line_count; i++) {
137 Vector3 pos = (*curve)(t);
138 draw_line(Vertex(prev_pos, (float)i / (float)line_count), Vertex(pos, (float)(i + 1) / line_count), width, width, mat.diffuse_color);
143 set_alpha_blending(false);
145 disable_texture_unit(0);