File: ParticleVolume.h

package info (click to toggle)
freespace2 25.0.0~rc11%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 47,232 kB
  • sloc: cpp: 657,500; ansic: 22,305; sh: 293; python: 200; makefile: 198; xml: 181
file content (50 lines) | stat: -rw-r--r-- 1,396 bytes parent folder | download
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
#pragma once

#include "globalincs/pstypes.h"
#include "parse/parselo.h"

#include <optional>

namespace particle {
	class ParticleSource;
	class ParticleVolume {
	public:
		virtual vec3d sampleRandomPoint(const matrix &orientation, const std::tuple<const ParticleSource&, const size_t&, const vec3d&>& source, float particlesFraction) = 0;

		virtual void parse() = 0;

		virtual ~ParticleVolume() = default;

		std::optional<vec3d> posOffset;
		std::optional<vec3d> rotOffset;
	protected:
		void parseCommon() {
			if (optional_string("+Volume Position Offset:")) {
				stuff_vec3d(&posOffset.emplace());
			}
			if (optional_string("+Volume Point Towards:")) {
				stuff_vec3d(&rotOffset.emplace());
			}
		}

		vec3d pointCompensateForOffsetAndRotOffset(const vec3d& point, const matrix& orientation, float posOffsetRot, float rotOffsetRot) const {
			vec3d outpnt = point;

			if (rotOffset.has_value()) {
				vec3d rot = *rotOffset;
				vm_rot_point_around_line(&rot, &rot, rotOffsetRot, &vmd_zero_vector, &vmd_z_vector);
				matrix orientUse;
				vm_vector_2_matrix(&orientUse, &rot);
				vm_vec_unrotate(&outpnt, &outpnt, &orientUse);
			}
			if (posOffset.has_value()) {
				vec3d pos = *posOffset;
				vm_rot_point_around_line(&pos, &pos, posOffsetRot, &vmd_zero_vector, &vmd_z_vector);
				vm_vec_unrotate(&pos, &pos, &orientation);
				outpnt += pos;
			}

			return outpnt;
		}
	};
}