re3-wiiu/src/render/WindModifiers.cpp

52 lines
1.3 KiB
C++
Raw Normal View History

2020-05-19 20:56:42 +02:00
#include "common.h"
#include "WindModifiers.h"
2020-08-05 04:11:42 +02:00
#include "Camera.h"
#include "General.h"
#define MAX_HEIGHT_DIST 40.0f
#define MIN_FADE_DIST 20.0f
#define MAX_FADE_DIST 50.0f
CWindModifiers Array[16];
int32 CWindModifiers::Number;
2020-05-19 20:56:42 +02:00
2020-05-31 17:05:49 +02:00
void
2020-08-05 04:11:42 +02:00
CWindModifiers::RegisterOne(CVector pos, int32 type = 1)
2020-05-31 17:05:49 +02:00
{
2020-08-05 04:11:42 +02:00
if (CWindModifiers::Number < 16 && (pos - TheCamera.GetPosition()).Magnitude() < 100.0f) {
Array[Number].m_pos = pos;
Array[Number].m_type = type;
Number++;
}
2020-05-31 17:05:49 +02:00
}
2020-08-05 04:11:42 +02:00
bool
2020-05-19 20:56:42 +02:00
CWindModifiers::FindWindModifier(CVector pos, float *x, float *y)
{
2020-08-05 04:11:42 +02:00
bool bWasWindModifierFound = false;
CVector2D dir;
for (int i = 0; i < Number; i++) {
if (Array[i].m_type == 1) {
float zDist = Abs(15.0f + pos.z - Array[i].m_pos.z);
if (zDist < MAX_HEIGHT_DIST) {
float dist = (pos - Array[i].m_pos).Magnitude();
if (dist < MAX_FADE_DIST) {
float distFade = dist < MIN_FADE_DIST ? 1.0f : 1.0f - (dist - MIN_FADE_DIST) / (MAX_FADE_DIST - MIN_FADE_DIST);
2020-10-24 21:28:44 +02:00
float heightFade = distFade * ((1.0f - zDist / MAX_HEIGHT_DIST) / 2.0f);
2020-08-05 04:11:42 +02:00
dir = (pos - Array[i].m_pos) * heightFade / dist;
bWasWindModifierFound = true;
}
}
}
}
if (bWasWindModifierFound) {
float directionMult = ((CGeneral::GetRandomNumber() & 0x1F) - 16) * 0.0035f + 1.0f;
*x += dir.x * directionMult;
*y += dir.y * directionMult;
}
return bWasWindModifierFound;
2020-05-19 20:56:42 +02:00
}