File: ParticleNode.cpp

package info (click to toggle)
darkradiant 3.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 41,080 kB
  • sloc: cpp: 264,743; ansic: 10,659; python: 1,852; xml: 1,650; sh: 92; makefile: 21
file content (123 lines) | stat: -rw-r--r-- 2,651 bytes parent folder | download | duplicates (3)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "ParticleNode.h"

#include "ivolumetest.h"
#include "itextstream.h"

namespace particles
{

ParticleNode::ParticleNode(const RenderableParticlePtr& particle) :
	_renderableParticle(particle),
	_local2Parent(Matrix4::getIdentity())
{}

std::string ParticleNode::name() const
{
	return "particle";
}

scene::INode::Type ParticleNode::getNodeType() const
{
	return Type::Particle;
}

IRenderableParticlePtr ParticleNode::getParticle() const
{
	return _renderableParticle;
}

const AABB& ParticleNode::localAABB() const
{
	return _renderableParticle->getBounds();
}

std::size_t ParticleNode::getHighlightFlags()
{
	return Highlight::NoHighlight;
}

Matrix4 ParticleNode::localToParent() const
{
	scene::INodePtr parent = getParent();

	if (parent == NULL)
	{
		_local2Parent = Matrix4::getIdentity();
	}
	else
	{
		_local2Parent = parent->localToWorld();

		// compensate the parent rotation only
		_local2Parent.tx() = 0;
		_local2Parent.ty() = 0;
		_local2Parent.tz() = 0;

		_local2Parent.invert();
	}

	return _local2Parent;
}

void ParticleNode::onPreRender(const VolumeTest& volume)
{
    if (!_renderableParticle) return;

    // Update the particle system before rendering
    update(volume);
}

void ParticleNode::renderHighlights(IRenderableCollector& collector, const VolumeTest& volume)
{
}

void ParticleNode::setRenderSystem(const RenderSystemPtr& renderSystem)
{
	Node::setRenderSystem(renderSystem);

	_renderableParticle->setRenderSystem(renderSystem);
}

void ParticleNode::update(const VolumeTest& viewVolume) const
{
    if (!viewVolume.fill())
    {
        return;
    }

	// Get the view rotation and cancel out the translation part
	Matrix4 viewRotation = viewVolume.GetModelview();
	viewRotation.tx() = 0;
	viewRotation.ty() = 0;
	viewRotation.tz() = 0;
	viewRotation.tw() = 1;

	// Get the main direction of our parent entity
	_renderableParticle->setMainDirection(_renderEntity->getDirection());

	// Set entity colour, might be needed
	_renderableParticle->setEntityColour(Vector3(
		_renderEntity->getShaderParm(0), _renderEntity->getShaderParm(1), _renderEntity->getShaderParm(2)));

	_renderableParticle->update(viewRotation, localToWorld(), _renderEntity);
}

void ParticleNode::onVisibilityChanged(bool isVisibleNow)
{
    Node::onVisibilityChanged(isVisibleNow);

    // Clear geometry when hidden. When shown, the particle will be updated every frame anyway
    if (!isVisibleNow)
    {
        _renderableParticle->clearRenderables();
    }
}

void ParticleNode::onRemoveFromScene(scene::IMapRootNode& root)
{
    _renderableParticle->clearRenderables();

    Node::onRemoveFromScene(root);
}

} // namespace