Rise
The Vieneo Province
Toggle main menu visibility
Loading...
Searching...
No Matches
VehicleSoundSpatial.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "
Rendering/ClientMath.h
"
4
#include <algorithm>
5
#include <cmath>
6
7
namespace
VehicleSoundSpatial
8
{
9
struct
Mix
10
{
11
float
gain
= 1.f;
12
float
pan
= 0.f;
13
};
14
15
// Camera mounts are in km and use the same signed translation as matrixView.
16
// Keep close mounted cameras at full level; halve amplitude each time the
17
// distance doubles beyond the source's reference distance. Zoom does not move the ears.
18
inline
Mix
Calculate
(
const
RiseMath::Vector3
& cameraFromVehicle,
19
float
yaw,
float
pitch,
float
roll,
float
referenceDistanceKm = .005f)
20
{
21
const
float
distance =
RiseMath::Vec3Length
(&cameraFromVehicle);
22
if
(!std::isfinite(distance) || !std::isfinite(yaw) ||
23
!std::isfinite(pitch) || !std::isfinite(roll) ||
24
!std::isfinite(referenceDistanceKm) || referenceDistanceKm <= 0.f)
25
return
{0.f, 0.f};
26
if
(distance <= .000001f)
27
return
{};
28
29
RiseMath::Matrix
look;
30
RiseMath::MatrixRotationYawPitchRoll
(&look, yaw, pitch, roll);
31
RiseMath::MatrixInverse
(&look,
nullptr
, &look);
32
RiseMath::Vector3
sourceInView;
33
RiseMath::Vec3TransformNormal
(&sourceInView, &cameraFromVehicle, &look);
34
35
// Rise's projection rotates the view 180 degrees about Z, so negative
36
// view X is screen right. Include elevation to keep overhead sounds central.
37
const
float
pan = std::clamp(-sourceInView.x / distance, -1.f, 1.f);
38
return
{std::min(1.f, referenceDistanceKm / distance), pan};
39
}
40
}
ClientMath.h
RiseMath::Vec3Length
float Vec3Length(const Vector3 *a)
Definition
ClientMath.h:95
RiseMath::Vec3TransformNormal
Vector3 * Vec3TransformNormal(Vector3 *out, const Vector3 *a, const Matrix *m)
Definition
ClientMath.h:107
RiseMath::MatrixRotationYawPitchRoll
Matrix * MatrixRotationYawPitchRoll(Matrix *out, float yaw, float pitch, float roll)
Definition
ClientMath.h:137
RiseMath::MatrixInverse
Matrix * MatrixInverse(Matrix *out, float *determinant, const Matrix *a)
Definition
ClientMath.h:118
VehicleSoundSpatial
Definition
VehicleSoundSpatial.h:8
VehicleSoundSpatial::Calculate
Mix Calculate(const RiseMath::Vector3 &cameraFromVehicle, float yaw, float pitch, float roll, float referenceDistanceKm=.005f)
Definition
VehicleSoundSpatial.h:18
RiseMath::Matrix
Definition
ClientMath.h:80
RiseMath::Vector3
Definition
ClientMath.h:38
VehicleSoundSpatial::Mix
Definition
VehicleSoundSpatial.h:10
VehicleSoundSpatial::Mix::pan
float pan
Definition
VehicleSoundSpatial.h:12
VehicleSoundSpatial::Mix::gain
float gain
Definition
VehicleSoundSpatial.h:11
VehicleSoundSpatial.h
Generated on
for Rise by
1.18.0