MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / DoRainEffect

Function DoRainEffect

Descent3/weather.cpp:47–169  ·  view source on GitHub ↗

Makes droplets appear on the windshield, plus makes rain fall in the distance

Source from the content-addressed store, hash-verified

45
46// Makes droplets appear on the windshield, plus makes rain fall in the distance
47void DoRainEffect() {
48 // See how many droplets to create on the windshield
49 // This is dependant on how fast the player is moving forward
50 int randval = 1 + ((1.0 - Weather.rain_intensity_scalar) * MAX_RAIN_INTENSITY);
51
52 if (randval < 20)
53 randval = 20;
54
55 vector vel = Viewer_object->mtype.phys_info.velocity;
56 float mag = vm_GetMagnitudeFast(&vel);
57 vel /= mag;
58
59 float scalar = vm_DotProduct(&vel, &Viewer_object->orient.fvec);
60
61 vector upvec = {0, 1.0, 0};
62
63 scalar *= (1 + (mag / 100));
64
65 randval -= scalar * 10;
66
67 if (randval < 2)
68 randval = 2;
69 else if (randval > 80)
70 randval = 80;
71
72 if ((upvec * Viewer_object->orient.uvec) < 0)
73 randval = 8000; // Make sure rain does fall upwards
74
75 if (Viewer_object->type == OBJ_PLAYER && OBJECT_OUTSIDE(Viewer_object) && (ps_rand() % randval) == 0) {
76 // Put some droplets on the windshield
77 vector pos = {0, 0, 0};
78
79 pos.x = ((ps_rand() % 1000) - 500) / 250.0;
80 pos.y = ((ps_rand() % 1000) - 500) / 350.0;
81 pos.z = 3.0;
82
83 int visnum = VisEffectCreate(VIS_FIREBALL, RAINDROP_INDEX, Viewer_object->roomnum, &pos);
84 if (visnum >= 0) {
85 vis_effect *vis = &VisEffects[visnum];
86 float life = .4 + ((ps_rand() % 500) / 1000.0);
87 vis->lifeleft = life;
88 vis->lifetime = life;
89 vis->size = .01 + ((ps_rand() % 500) / 3000.0);
90
91 if (vis->size > .05) {
92 Sound_system.Play2dSound(SOUND_RAINDROP);
93 }
94
95 vis->flags |= VF_WINDSHIELD_EFFECT;
96 }
97 }
98
99 // Create some rain in the distance
100
101 if (OBJECT_OUTSIDE(Viewer_object)) {
102 int num = 20 + (ps_rand() % 15);
103 angvec angs;
104 int i;

Callers 1

DoWeatherForFrameFunction · 0.85

Calls 9

ps_randFunction · 0.85
VisEffectCreateFunction · 0.85
GR_RGB16Function · 0.85
GetTerrainGroundPointFunction · 0.85
Play2dSoundMethod · 0.80
vm_GetMagnitudeFastFunction · 0.50
vm_DotProductFunction · 0.50
vm_AnglesToMatrixFunction · 0.50

Tested by

no test coverage detected