aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8.1/source/Irrlicht/CParticleRotationAffector.cpp
blob: e59854a9ca1a3db5fafcc26c9a1508e0b3657f23 (plain)
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
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h

#include "CParticleRotationAffector.h"
#include "IAttributes.h"

namespace irr
{
namespace scene
{

//! constructor
CParticleRotationAffector::CParticleRotationAffector( const core::vector3df& speed, const core::vector3df& pivotPoint )
		: PivotPoint(pivotPoint), Speed(speed), LastTime(0)
{
	#ifdef _DEBUG
	setDebugName("CParticleRotationAffector");
	#endif
}


//! Affects an array of particles.
void CParticleRotationAffector::affect(u32 now, SParticle* particlearray, u32 count)
{
	if( LastTime == 0 )
	{
		LastTime = now;
		return;
	}

	f32 timeDelta = ( now - LastTime ) / 1000.0f;
	LastTime = now;

	if( !Enabled )
		return;

	for(u32 i=0; i<count; ++i)
	{
		if( Speed.X != 0.0f )
			particlearray[i].pos.rotateYZBy( timeDelta * Speed.X, PivotPoint );

		if( Speed.Y != 0.0f )
			particlearray[i].pos.rotateXZBy( timeDelta * Speed.Y, PivotPoint );

		if( Speed.Z != 0.0f )
			particlearray[i].pos.rotateXYBy( timeDelta * Speed.Z, PivotPoint );
	}
}

//! Writes attributes of the object.
void CParticleRotationAffector::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
{
	out->addVector3d("PivotPoint", PivotPoint);
	out->addVector3d("Speed", Speed);
}

//! Reads attributes of the object.
void CParticleRotationAffector::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
{
	PivotPoint = in->getAttributeAsVector3d("PivotPoint");
	Speed = in->getAttributeAsVector3d("Speed");
}

} // end namespace scene
} // end namespace irr