root/OpenSceneGraph/trunk/src/osgPlugins/3ds/tcb.cpp @ 10076

Revision 10076, 3.1 kB (checked in by robert, 6 years ago)

From Neil Hughes, converted across to use istream for reading data from file to enable reading .3ds files over http (use OSG's libcurl plugin).

From Robert Osfield, ammendments of the above to better support reading of files from local directories.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
RevLine 
[8]1/*
2 * The 3D Studio File Format Library
3 * Copyright (C) 1996-2001 by J.E. Hoffmann <je-h@gmx.net>
4 * All rights reserved.
5 *
6 * This program is  free  software;  you can redistribute it and/or modify it
[151]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
[8]9 * your option) any later version.
10 *
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
[151]13 * or  FITNESS FOR A  PARTICULAR PURPOSE.  See the  GNU Lesser General Public 
[8]14 * License for more details.
15 *
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.
19 *
20 * $Id$
21 */
22#define LIB3DS_EXPORT
[1563]23#include "tcb.h"
24#include "readwrite.h"
[8]25#include <math.h>
26
[151]27
[8]28/*!
29 * \defgroup tcb Tension/Continuity/Bias Splines
30 *
31 * \author J.E. Hoffmann <je-h@gmx.net>
32 */
33
[151]34
[8]35/*!
[151]36 * \ingroup tcb
[8]37 */
38void
39lib3ds_tcb(Lib3dsTcb *p, Lib3dsTcb *pc, Lib3dsTcb *c, Lib3dsTcb *nc, Lib3dsTcb *n,
[151]40  Lib3dsFloat *ksm, Lib3dsFloat *ksp, Lib3dsFloat *kdm, Lib3dsFloat *kdp)
[8]41{
[151]42  Lib3dsFloat tm,cm,cp,bm,bp,tmcm,tmcp,cc;
43  Lib3dsFloat dt,fp,fn;
[8]44
[151]45  if (!pc) {
46    pc=c;
47  }
48  if (!nc) {
49    nc=c;
50  }
51 
52  fp=fn=1.0f;
53  if (p&&n) {
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);
58    fp=fp+cc-cc*fp;
59    fn=fn+cc-cc*fn;
60  }
[8]61
[151]62  cm=1.0f-c->cont;
63  tm=0.5f*(1.0f-c->tens);
64  cp=2.0f-cm;
65  bm=1.0f-c->bias;
66  bp=2.0f-bm;     
67  tmcm=tm*cm;
68  tmcp=tm*cp;
69  *ksm=tmcm*bp*fp;
70  *ksp=tmcp*bm*fp;
71  *kdm=tmcp*bp*fn;
72  *kdp=tmcm*bm*fn;
[8]73}
74
75
76/*!
[151]77 * \ingroup tcb
[8]78 */
79Lib3dsBool
[10076]80lib3ds_tcb_read(Lib3dsTcb *tcb, iostream *strm)
[8]81{
[151]82  Lib3dsWord flags;
83 
[10076]84  tcb->frame=lib3ds_intd_read(strm);
85  tcb->flags=flags=lib3ds_word_read(strm);
[151]86  if (flags&LIB3DS_USE_TENSION) {
[10076]87    tcb->tens=lib3ds_float_read(strm);
[151]88  }
89  if (flags&LIB3DS_USE_CONTINUITY) {
[10076]90    tcb->cont=lib3ds_float_read(strm);
[151]91  }
92  if (flags&LIB3DS_USE_BIAS) {
[10076]93    tcb->bias=lib3ds_float_read(strm);
[151]94  }
95  if (flags&LIB3DS_USE_EASE_TO) {
[10076]96    tcb->ease_to=lib3ds_float_read(strm);
[151]97  }
98  if (flags&LIB3DS_USE_EASE_FROM) {
[10076]99    tcb->ease_from=lib3ds_float_read(strm);
[151]100  }
[10076]101
102  if (strm->fail()){
[151]103    return(LIB3DS_FALSE);
104  }
105  return(LIB3DS_TRUE);
[8]106}
107
108
109/*!
[151]110 * \ingroup tcb
[8]111 */
112Lib3dsBool
[10076]113lib3ds_tcb_write(Lib3dsTcb *tcb, iostream *strm)
[8]114{
[10076]115  lib3ds_intd_write(tcb->frame,strm);
116  lib3ds_word_write(tcb->flags,strm);
[151]117  if (tcb->flags&LIB3DS_USE_TENSION) {
[10076]118    lib3ds_float_write(tcb->tens,strm);
[151]119  }
120  if (tcb->flags&LIB3DS_USE_CONTINUITY) {
[10076]121    lib3ds_float_write(tcb->cont,strm);
[151]122  }
123  if (tcb->flags&LIB3DS_USE_BIAS) {
[10076]124    lib3ds_float_write(tcb->bias,strm);
[151]125  }
126  if (tcb->flags&LIB3DS_USE_EASE_TO) {
[10076]127    lib3ds_float_write(tcb->ease_to,strm);
[151]128  }
129  if (tcb->flags&LIB3DS_USE_EASE_FROM) {
[10076]130    lib3ds_float_write(tcb->ease_from,strm);
[151]131  }
[10076]132  if (strm->fail()){
[151]133    return(LIB3DS_FALSE);
134  }
135  return(LIB3DS_TRUE);
[8]136}
[151]137
138
139
Note: See TracBrowser for help on using the browser.