File: PortalManager.cpp

package info (click to toggle)
transcend 0.3.dfsg2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, jessie, jessie-kfreebsd, stretch
  • size: 5,796 kB
  • ctags: 3,074
  • sloc: cpp: 26,886; ansic: 693; sh: 210; makefile: 99; perl: 67
file content (164 lines) | stat: -rw-r--r-- 3,934 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
 * Modification History
 *
 * 2004-October-13   Jason Rohrer
 * Created.
 */



#include "PortalManager.h"



PortalManager::PortalManager( ParameterizedObject *inPortalTemplate,
                              double inPortalScale,
                              double inPortalFadeInTimeSeconds,
                              double inGridWidth )
    : mPortalTemplate( inPortalTemplate ),
      mPortalScale( inPortalScale ),
      mFadeInTimeSeconds( inPortalFadeInTimeSeconds ),
      mFadeFactor( 0 ),
      mGridWidth( inGridWidth ),
      mCurrentPosition( NULL ),
      mCurrentRadius( 0 ),
      mCurrentRotation( new Angle3D( 0, 0, 0 ) ) {

    }
  


PortalManager::~PortalManager() {
    delete mPortalTemplate;

    if( mCurrentPosition != NULL ) {
        delete mCurrentPosition;
        }
    delete mCurrentRotation;
    
    }



void PortalManager::showPortal( Vector3D *inPosition ) {
    mCurrentPosition = inPosition;
    }



char PortalManager::isPortalVisible() {
    if( mCurrentPosition != NULL ) {
        return true;
        }
    else {
        return false;
        }
    }



void PortalManager::passTime( double inTimeDeltaInSeconds,
                              Vector3D *inShipPosition ) {

    // if portal has been shown
    if( mCurrentPosition != NULL ) {
        
        double distanceToShip =
            mCurrentPosition->getDistance( inShipPosition );
    
        // 25 units, up to 20 units from target, is the range
        double compressedDistance =
            ( distanceToShip - 20 ) /
            ( 25 );
        
        // limit the range
        if( compressedDistance > 1 ) {
            compressedDistance = 1;
            }
        else if( compressedDistance < 0 ) {
            compressedDistance = 0;
            }

        // change shape based on ship distance
        mPortalShapeParameter = compressedDistance;
    

        // rotate
        mCurrentRotation->mZ += mCurrentRotationRate * inTimeDeltaInSeconds;

        // fade in
        if( mFadeFactor < 1 ) {
            mFadeFactor +=
                (double)inTimeDeltaInSeconds / (double) mFadeInTimeSeconds;

            if( mFadeFactor > 1 ) {
                mFadeFactor = 1;
                }
            }
        }
    }



char PortalManager::isShipInPortal( Vector3D *inShipPosition ) {

    if( mCurrentPosition != NULL ) {
        double distance = mCurrentPosition->getDistance( inShipPosition );

        if( distance < mCurrentRadius ) {
            return true;
            }
        else {
            return false;
            }
        }
    else {
        // portal not shown
        return false;
        }
    }


SimpleVector<DrawableObject *> *PortalManager::getDrawableObjects() {

    // if portal has been shown
    if( mCurrentPosition != NULL ) {
        
        SimpleVector<DrawableObject *> *objects =
            mPortalTemplate->getDrawableObjects(
                mPortalShapeParameter, &mCurrentRotationRate ); 

        // scale, rotate, position, and fade the objects
    
        int numObjects = objects->size();
    
        // compute the maximum radius of this enemy
        double maxRadius = 0;
        
        for( int j=0; j<numObjects; j++ ) {
            
            DrawableObject *currentObject =
                *( objects->getElement( j ) );

            currentObject->scale( mPortalScale );
            currentObject->rotate( mCurrentRotation );
            currentObject->move( mCurrentPosition );
            currentObject->fade( mFadeFactor );

            double radius = currentObject->getBorderMaxDistance(
                mCurrentPosition );

            if( radius > maxRadius ) {
                maxRadius = radius;
                }
            }

        mCurrentRadius = maxRadius;        

        return objects;
        }
    else {
        // return an empty vector
        return new SimpleVector<DrawableObject *>();
        }
    }