2 * The 3D Studio File Format Library
3 * Copyright (C) 1996-2001 by J.E. Hoffmann <je-h@gmx.net>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or (at
9 * your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 * License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * $Id: tcb.c,v 1.9 2001/07/07 19:05:30 jeh Exp $
23 #include <lib3ds/tcb.h>
24 #include <lib3ds/io.h>
29 * \defgroup tcb Tension/Continuity/Bias Splines
31 * \author J.E. Hoffmann <je-h@gmx.net>
39 lib3ds_tcb(Lib3dsTcb *p, Lib3dsTcb *pc, Lib3dsTcb *c, Lib3dsTcb *nc, Lib3dsTcb *n,
40 Lib3dsFloat *ksm, Lib3dsFloat *ksp, Lib3dsFloat *kdm, Lib3dsFloat *kdp)
42 Lib3dsFloat tm,cm,cp,bm,bp,tmcm,tmcp,cc;
54 dt=0.5f*(Lib3dsFloat)(pc->frame-p->frame+n->frame-nc->frame);
55 fp=((Lib3dsFloat)(pc->frame-p->frame))/dt;
56 fn=((Lib3dsFloat)(n->frame-nc->frame))/dt;
57 cc=(Lib3dsFloat)fabs(c->cont);
63 tm=0.5f*(1.0f-c->tens);
80 lib3ds_tcb_read(Lib3dsTcb *tcb, Lib3dsIo *io)
84 tcb->frame=lib3ds_io_read_intd(io);
85 tcb->flags=flags=lib3ds_io_read_word(io);
86 if (flags&LIB3DS_USE_TENSION) {
87 tcb->tens=lib3ds_io_read_float(io);
89 if (flags&LIB3DS_USE_CONTINUITY) {
90 tcb->cont=lib3ds_io_read_float(io);
92 if (flags&LIB3DS_USE_BIAS) {
93 tcb->bias=lib3ds_io_read_float(io);
95 if (flags&LIB3DS_USE_EASE_TO) {
96 tcb->ease_to=lib3ds_io_read_float(io);
98 if (flags&LIB3DS_USE_EASE_FROM) {
99 tcb->ease_from=lib3ds_io_read_float(io);
101 if (lib3ds_io_error(io)) {
102 return(LIB3DS_FALSE);
112 lib3ds_tcb_write(Lib3dsTcb *tcb, Lib3dsIo *io)
114 lib3ds_io_write_intd(io, tcb->frame);
115 lib3ds_io_write_word(io, tcb->flags);
116 if (tcb->flags&LIB3DS_USE_TENSION) {
117 lib3ds_io_write_float(io, tcb->tens);
119 if (tcb->flags&LIB3DS_USE_CONTINUITY) {
120 lib3ds_io_write_float(io, tcb->cont);
122 if (tcb->flags&LIB3DS_USE_BIAS) {
123 lib3ds_io_write_float(io, tcb->bias);
125 if (tcb->flags&LIB3DS_USE_EASE_TO) {
126 lib3ds_io_write_float(io, tcb->ease_to);
128 if (tcb->flags&LIB3DS_USE_EASE_FROM) {
129 lib3ds_io_write_float(io, tcb->ease_from);
131 if (lib3ds_io_error(io)) {
132 return(LIB3DS_FALSE);