C:/jkyprian/devel/lib3ds/lib3ds/tcb.c

00001 /*
00002  * The 3D Studio File Format Library
00003  * Copyright (C) 1996-2007 by Jan Eric Kyprianidis <www.kyprianidis.com>
00004  * All rights reserved.
00005  *
00006  * This program is  free  software;  you can redistribute it and/or modify it
00007  * under the terms of the  GNU Lesser General Public License  as published by 
00008  * the  Free Software Foundation;  either version 2.1 of the License,  or (at 
00009  * your option) any later version.
00010  *
00011  * This  program  is  distributed in  the  hope that it will  be useful,  but
00012  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00013  * or  FITNESS FOR A  PARTICULAR PURPOSE.  See the  GNU Lesser General Public  
00014  * License for more details.
00015  *
00016  * You should  have received  a copy of the GNU Lesser General Public License
00017  * along with  this program;  if not, write to the  Free Software Foundation,
00018  * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  *
00020  * $Id: tcb.c,v 1.11 2007/06/15 09:33:19 jeh Exp $
00021  */
00022 #include <lib3ds/tcb.h>
00023 #include <lib3ds/io.h>
00024 #include <math.h>
00025 
00026 
00035 void
00036 lib3ds_tcb(Lib3dsTcb *p, Lib3dsTcb *pc, Lib3dsTcb *c, Lib3dsTcb *nc, Lib3dsTcb *n,
00037   Lib3dsFloat *ksm, Lib3dsFloat *ksp, Lib3dsFloat *kdm, Lib3dsFloat *kdp)
00038 {
00039   Lib3dsFloat tm,cm,cp,bm,bp,tmcm,tmcp,cc;
00040   Lib3dsFloat dt,fp,fn;
00041 
00042   if (!pc) {
00043     pc=c;
00044   }
00045   if (!nc) {
00046     nc=c;
00047   }
00048   
00049   fp=fn=1.0f;
00050   if (p&&n) {
00051     dt=0.5f*(Lib3dsFloat)(pc->frame-p->frame+n->frame-nc->frame);
00052     fp=((Lib3dsFloat)(pc->frame-p->frame))/dt;
00053     fn=((Lib3dsFloat)(n->frame-nc->frame))/dt;
00054     cc=(Lib3dsFloat)fabs(c->cont);
00055     fp=fp+cc-cc*fp;
00056     fn=fn+cc-cc*fn;
00057   }
00058 
00059   cm=1.0f-c->cont;
00060   tm=0.5f*(1.0f-c->tens);
00061   cp=2.0f-cm;
00062   bm=1.0f-c->bias;
00063   bp=2.0f-bm;      
00064   tmcm=tm*cm;
00065   tmcp=tm*cp;
00066   *ksm=tmcm*bp*fp;
00067   *ksp=tmcp*bm*fp;
00068   *kdm=tmcp*bp*fn;
00069   *kdp=tmcm*bm*fn;
00070 }
00071 
00072 
00076 Lib3dsBool
00077 lib3ds_tcb_read(Lib3dsTcb *tcb, Lib3dsIo *io)
00078 {
00079   Lib3dsWord flags;
00080   
00081   tcb->frame=lib3ds_io_read_intd(io);
00082   tcb->flags=flags=lib3ds_io_read_word(io);
00083   if (flags&LIB3DS_USE_TENSION) {
00084     tcb->tens=lib3ds_io_read_float(io);
00085   }
00086   if (flags&LIB3DS_USE_CONTINUITY) {
00087     tcb->cont=lib3ds_io_read_float(io);
00088   }
00089   if (flags&LIB3DS_USE_BIAS) {
00090     tcb->bias=lib3ds_io_read_float(io);
00091   }
00092   if (flags&LIB3DS_USE_EASE_TO) {
00093     tcb->ease_to=lib3ds_io_read_float(io);
00094   }
00095   if (flags&LIB3DS_USE_EASE_FROM) {
00096     tcb->ease_from=lib3ds_io_read_float(io);
00097   }
00098   if (lib3ds_io_error(io)) {
00099     return(LIB3DS_FALSE);
00100   }
00101   return(LIB3DS_TRUE);
00102 }
00103 
00104 
00108 Lib3dsBool
00109 lib3ds_tcb_write(Lib3dsTcb *tcb, Lib3dsIo *io)
00110 {
00111   lib3ds_io_write_intd(io, tcb->frame);
00112   lib3ds_io_write_word(io, tcb->flags);
00113   if (tcb->flags&LIB3DS_USE_TENSION) {
00114     lib3ds_io_write_float(io, tcb->tens);
00115   }
00116   if (tcb->flags&LIB3DS_USE_CONTINUITY) {
00117     lib3ds_io_write_float(io, tcb->cont);
00118   }
00119   if (tcb->flags&LIB3DS_USE_BIAS) {
00120     lib3ds_io_write_float(io, tcb->bias);
00121   }
00122   if (tcb->flags&LIB3DS_USE_EASE_TO) {
00123     lib3ds_io_write_float(io, tcb->ease_to);
00124   }
00125   if (tcb->flags&LIB3DS_USE_EASE_FROM) {
00126     lib3ds_io_write_float(io, tcb->ease_from);
00127   }
00128   if (lib3ds_io_error(io)) {
00129     return(LIB3DS_FALSE);
00130   }
00131   return(LIB3DS_TRUE);
00132 }
00133 
00134 
00135 
00136 

Hosted by
SourceForge.net Logo
Generated at Wed Jun 20 18:51:36 2007 by Doxygen 1.5.2