summaryrefslogtreecommitdiffstats
path: root/game/code/worldsim/redbrick/geometryvehicle.h
blob: 4da0a8b51e89babf0f42c6c3f4fcfbc08be4ae25 (plain) (blame)
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
/*===========================================================================
   geometryvehicle.h

   created Dec 7, 2001
   by Greg Mayer

   Copyright (c) 2001 Radical Entertainment, Inc.
   All rights reserved.


===========================================================================*/

#ifndef _GEOMETRYVEHICLE_HPP
#define _GEOMETRYVEHICLE_HPP

class tPose;
class tGeometry;
class tTexture;
class tShader;
class tPoseAnimationController;
class tParticleSystem;
class tAnimation;
class Vehicle;
class TrafficBodyDrawable;
class tBillboardQuadGroup;
class tFrameController;
class SkidmarkGenerator;
class tMultiController;
class StatePropCollectible;

#include <p3d/anim/compositedrawable.hpp>
#include <render/particles/vehicleparticleemitter.h>
#include <worldsim/SkidMarks/SkidMarkGenerator.h>
#include <constants/particleenum.h>
#include <vector>
#include <memory/stlallocators.h>

#define MAX_REFRACTION_SHADERS 16

struct BlobShadowParams;

struct HeadLightParams
{
    HeadLightParams( const rmt::Vector& Pos, const rmt::Vector& Normal, const rmt::Vector& Forward, const rmt::Vector& Up ) :
        GroundPos( Pos ), GroundNormal( Normal ), VehicleHeading( Forward ), VehicleUp( Up ) {};
    const rmt::Vector& GroundPos;
    const rmt::Vector& GroundNormal;
    const rmt::Vector& VehicleHeading;
    const rmt::Vector& VehicleUp;
    float LightReach; // A value of 1 is the light right at the car (i.e. car on the ground), a zero is light max reach from the car (i.e. car high in the air)
};

enum FCTrigger
{
    eNone,
    eBackfire
};

class GeometryVehicle
{
public:

    GeometryVehicle();
    ~GeometryVehicle();

    bool Init( const char* name, Vehicle* owner, int i);

    void Display();
    //void DisplaySkids();
    void UpdateSkids();
    void SetSkidValues(int wheel, float intensity, rmt::Vector& normal, eTerrainType terrainType );


    void Update(float dt);

    tPose* GetP3DPose();
    
    int  CastsShadow();
    void DisplayShadow( BlobShadowParams* BlobParams = 0 );

    // The additive lights. Headlights, etc.
    void DisplayLights( const HeadLightParams& LightParams );

    void ShowBrakeLights();
    void HideBrakeLights();  

    void ShowReverseLights();
    void HideReverseLights();

    void SetTrafficBodyColour( pddiColour colour );
    void SetShadowAdjustments( float Adjustments[ 4 ][ 2 ] );
    void SetShininess( unsigned char EnvRef ) { m_EnvRef = EnvRef; }

    void SetFadeAlpha( int fade );

    bool IsTrafficModel();

    void FadeRoof( bool fade );

    void EnableLights( bool enable );
    void SetLightsOffDueToDamage(bool lightsOffDueToDamage) {mLightsOffDueToDamage = lightsOffDueToDamage;}
    // Get the vehicle body colour, currently only valid for traffic vehicles
    tColour GetVehicleColour()const;
    bool HasVehicleColour()const { return (mTrafficBodyDrawable != NULL); }

    // Structure that holds data on how to manipulate frame controllers
    // that are tied to vehicle specific things like gas and velocity
    // The animation frame of such an object is determined by
    // frame = clamp( gasBias * currGas * brakeBias * brake + speedBias * currSpeed )
    // controller->SetFrame( frame );
    // note that brake values act as reverse gas and are in the range [0,1] like gas is
   

    struct VehicleFrameController
    {
        const char* name;
        tFrameController* frameController;
        bool frameSetter;
        FCTrigger trigger;
        float gasBias;
        float brakeBias;
        float speedBias;
        float timeBias;
    };    

    float GetHeadlightScale();
    void SetHeadlightScale( float scale );
    
    // Attach a tDrawable collectible to the vehicle
    // returns true if attached or false if not ( false happens
    // when a collectible is already attached to the vehicle)
    bool AttachCollectible( StatePropCollectible* );
    StatePropCollectible* GetAttachedCollectible();
    void DetachCollectible( const rmt::Vector& velocity, bool explode = true );

private:

    // TODO - keep like this?
    friend class Vehicle;
    
    Vehicle* mVehicleOwner;

    bool GetArt( const char* name);    // a bit obscure, but use return value to say true for localized damage textures and shaders present
    void FindAndTurnOffWheels();
    void FindAndTurnOffFrontWheelsOnly();   // for rocket car
    void FindBrakeLightBillboardJoints();
    void FindHeadLightBillboardJoints();
    void FindGhostGlowBillboards( const char* model );
    void FindRoofGeometry( const char* model );
    void FindNukeGlowBillboards( const char* model );

    void SetCollectibleHardpointPosition( const rmt::Vector& position );
    void SetCollectibleHardpointTransform( float rotx ,float roty ,float rotz, const rmt::Vector& position );

    tCompositeDrawable* mCompositeDrawable;

    // some debug shit to make the car change colour when you bottom out
    tGeometry* mChassisGeometry;
       
   
    tShader* mRefractionShader[ MAX_REFRACTION_SHADERS ];
   
    //-------------------------------------------------------
    // damage texture stuff
    // 
    // get specific test working then make a general solution
    //
    //-------------------------------------------------------

    // need pointers to the tShaders so we can swap the texture they use
    // need pointers to the textures to swap in
    // need pointers to the textures to swap back?

    // we should find these for type 1 and 2 damage


    tShader* mHoodShader;
    tShader* mTrunkShader;
    tShader* mDoorPShader;
    tShader* mDoorDShader;

    tTexture* mHoodTextureDam;
    tTexture* mTrunkTextureDam;
    tTexture* mDoorPTextureDam;
    tTexture* mDoorDTextureDam;

    tTexture* mHoodTextureNorm;
    tTexture* mTrunkTextureNorm;
    tTexture* mDoorPTextureNorm;
    tTexture* mDoorDTextureNorm;

    bool FindDamageShadersAndTextures( const char* name);  // only returns true if localized damage textures and shaders are present
    //void TriggerDamage();

    void DamageTextureDoorD(bool on);
    void DamageTextureDoorP(bool on);
    void DamageTextureHood(bool on);
    void DamageTextureTrunk(bool on);

    void HideFlappingPiece(int jointindex, bool doit);
    
    void InitParticles();

    void SetEngineSmoke(ParticleEnum::ParticleID pid);
    void SetWheelSmoke( int wheel, ParticleEnum::ParticleID pid, float bias);
    
    tShader* mChassisShader;
    tTexture* mChassisTextureNorm;
    tTexture* mChassisTextureDam;
    void DamageTextureChassis(bool on);

   
    VehicleParticleEmitter* mParticleEmitter;

    ParticleAttributes mEngineParticleAttr;   // eNull
    ParticleAttributes mLeftWheelParticleAttr;
    ParticleAttributes mRightWheelParticleAttr;
    ParticleAttributes mTailPipeParticleAttr;   // eNull

    //eEngineSmokeLight,
    //eEngineSmokeHeavy,
    
    // Particle system with variable emission rate depending on speed
    tParticleSystem* mVariableEmissionParticleSystem; 


    SkidMarkGenerator* mSkidMarkGenerator;
    void InitSkidMarks();

    // ?
 //   tPoseAnimationController* mAnimController;
   
	//tPoseAnimation* mAnim;


    //tPoseAnimationController* mAnimController;
    tAnimation* mAnim;


    float mAnimRevPerSecondBase;

    float mRevMult;

	// Special particle effects (only present on a few vehicles, like Frink or 
	// the zombie car)
	ParticleEnum::ParticleID mSpecialEffect;

    // Cache the last position of the vehicle for
    //   spherical environment map rotation based on distance travelled
    //
    rmt::Vector mLastPosition;
    float mCurEnvMapRotation;
    
    int mBrakeLightJoints[4];
    int mReverseLightJoints[4];

    TrafficBodyDrawable* mTrafficBodyDrawable;
    TrafficBodyDrawable* mTrafficDoorDrawable;

    float mShadowPointAdjustments[ 4 ][ 2 ]; // Nudge around the shadow points. See notes in the shadow display.

    int mFadeAlpha;

    enum {
        NUM_BRAKELIGHT_BBQS = 4,
#ifdef RAD_WIN32 
        NUM_FRINKARC_BBQS = 3,
#endif
        NUM_GHOSTGLOW_BBQGS = 6,
        NUM_GHOSTGLOW_BBQS = 6,
        NUM_NUKEGLOW_BBQGS = 1,
        NUM_NUKEGLOW_BBQS = 3
    };

#ifdef RAD_WIN32
    tBillboardQuadGroup* mFrinkArc;
    tColour mOriginalFrinkArcColour[ NUM_FRINKARC_BBQS   ];
#endif

    tBillboardQuadGroup* mBrakeLights[NUM_BRAKELIGHT_BBQS];
    // This relies on each quadgroup containing only one quad
    // & will store color of that quad
    tColour mOriginalBrakeLightColours[NUM_BRAKELIGHT_BBQS]; 

    bool mUsingTrafficModel;

    bool mHasGhostGlow;
    tBillboardQuadGroup* mGhostGlows[NUM_GHOSTGLOW_BBQGS];
    tColour mOriginalGhostGlowColours[NUM_GHOSTGLOW_BBQS];

    bool mHasNukeGlow;
    tBillboardQuadGroup* mNukeGlows[NUM_NUKEGLOW_BBQGS];
    tColour mOriginalNukeGlowColours[NUM_NUKEGLOW_BBQS];


    bool mBrakeLightsOn;
    float mBrakeLightScale;
    float mHeadLightScale;
    bool mEnableLights;
    bool mLightsOffDueToDamage;

    tCompositeDrawable::DrawablePropElement* mRoofOpacShape;
    tCompositeDrawable::DrawablePropElement* mRoofAlphaShape;
    tShader* mRoofShader;
    int mRoofAlpha;
    int mRoofTargetAlpha;


    std::vector< VehicleFrameController, s2alloc< VehicleFrameController > > mFrameControllers;
    void FindAnimationControllers( const char* multicontrollername );
    bool GetSpecialController( tUID name, VehicleFrameController* outSpecialController );
    void AdvanceAnimationControllers( float deltaTime );

    // A collectible that can be attached to the car
    // Used for l7m5 mission
    StatePropCollectible* m_Collectible;
    rmt::Matrix m_CollectibleTransform;

    unsigned char m_EnvRef;
};

#endif  // _GEOMETRYVEHICLE_HPP