File: ParameterizedObject.cpp

package info (click to toggle)
transcend 0.3.dfsg1-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 5,816 kB
  • ctags: 2,912
  • sloc: cpp: 26,890; ansic: 693; sh: 210; makefile: 131; perl: 67
file content (113 lines) | stat: -rw-r--r-- 2,913 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
 * Modification History
 *
 * 2004-June-14   Jason Rohrer
 * Created.
 *
 * 2004-June-15   Jason Rohrer
 * Added a function for getting a blended control point.
 *
 * 2004-June-22   Jason Rohrer
 * Fixed algorithmic errors in linear blend function.
 */



#include "ParameterizedObject.h"



ParameterizedObject::ParameterizedObject( FILE *inFILE, char *outError ) {

    SimpleVector<ParameterSpaceControlPoint *> *controlPoints =
        new SimpleVector<ParameterSpaceControlPoint*>();
    SimpleVector<double> *controlPointParameterAnchors =
        new SimpleVector<double>();

    // keep reading parameter anchors and control points until we
    // can read no more
    
    char readError = false;

    while( !readError ) {
        
        // read the parameter space anchor
        double anchor = 0;
        int numRead = fscanf( inFILE, "%lf", &anchor );

        if( numRead != 1 ) {
            readError = true;
            }
        else {

            // read the control point
            ObjectParameterSpaceControlPoint *point =
                new ObjectParameterSpaceControlPoint( inFILE,
                                                      &readError );

            if( !readError ) {
                controlPointParameterAnchors->push_back( anchor );
                controlPoints->push_back( point );
                }
            else {
                delete point;
                }
            }
        }

    mNumControlPoints = controlPoints->size();
    mControlPoints = controlPoints->getElementArray();
    mControlPointParameterAnchors =
        controlPointParameterAnchors->getElementArray();

    delete controlPoints;
    delete controlPointParameterAnchors;

    if( mNumControlPoints >= 2 ) {
        *outError = false;
        }
    else {
        // we didn't read enough control points
        *outError = true;
        }
    }



SimpleVector<DrawableObject *> *ParameterizedObject::getDrawableObjects(
    double inParameter, double *outRotationRate ) {

    // blend the two points, using the distance to weight them
    ObjectParameterSpaceControlPoint *blendedPoint =
        getBlendedControlPoint( inParameter );
    
    if( blendedPoint != NULL ) {
        SimpleVector<DrawableObject*> *drawableObjects =
            blendedPoint->getDrawableObjects();
        
        *outRotationRate = blendedPoint->getRotationRate();
        
        delete blendedPoint;
        
        return drawableObjects;
        }
    else {
        printf( "Error:  no control points in object space.\n" );

        *outRotationRate = 0;

        return NULL;
        }

    }



ObjectParameterSpaceControlPoint *ParameterizedObject::getBlendedControlPoint(
    double inParameter ) {

    // cast result of super-class function call and return it
    return (ObjectParameterSpaceControlPoint*)
        ParameterizedSpace::getBlendedControlPoint( inParameter );

    }