1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
2 | /* |
---|
3 | * Copyright (c) 2004-2013 HUBzero Foundation, LLC |
---|
4 | * |
---|
5 | * Authors: |
---|
6 | * Wei Qiao <qiaow@purdue.edu> |
---|
7 | * Insoo Woo <iwoo@purdue.edu> |
---|
8 | * George A. Howlett <gah@purdue.edu> |
---|
9 | * Leif Delgass <ldelgass@purdue.edu> |
---|
10 | */ |
---|
11 | |
---|
12 | #include <assert.h> |
---|
13 | |
---|
14 | #include <vrmath/Color4f.h> |
---|
15 | |
---|
16 | #include "nanovis.h" // For NMESH |
---|
17 | #include "FlowParticles.h" |
---|
18 | #include "Flow.h" |
---|
19 | #include "Trace.h" |
---|
20 | |
---|
21 | using namespace nv; |
---|
22 | using namespace vrmath; |
---|
23 | |
---|
24 | FlowParticles::FlowParticles(const char *name) : |
---|
25 | _name(name), |
---|
26 | _renderer(new ParticleRenderer(NMESH, NMESH)) |
---|
27 | { |
---|
28 | _sv.position.value = 0.0f; |
---|
29 | _sv.position.flags = RELPOS; |
---|
30 | _sv.position.axis = AXIS_Z; |
---|
31 | _sv.color.r = _sv.color.g = _sv.color.b = _sv.color.a = 1.0f; |
---|
32 | _sv.isHidden = false; |
---|
33 | _sv.particleSize = 1.2; |
---|
34 | } |
---|
35 | |
---|
36 | FlowParticles::~FlowParticles() |
---|
37 | { |
---|
38 | TRACE("Deleting renderer"); |
---|
39 | if (_renderer != NULL) { |
---|
40 | delete _renderer; |
---|
41 | } |
---|
42 | TRACE("Freeing switches"); |
---|
43 | FreeSwitches(_switches, &_sv, 0); |
---|
44 | } |
---|
45 | |
---|
46 | void |
---|
47 | FlowParticles::render() |
---|
48 | { |
---|
49 | TRACE("Particles '%s' axis: %d pos: %g rel pos: %g", |
---|
50 | _name.c_str(), _sv.position.axis, _sv.position.value, |
---|
51 | Flow::getRelativePosition(&_sv.position)); |
---|
52 | |
---|
53 | _renderer->setSlicePosition(Flow::getRelativePosition(&_sv.position)); |
---|
54 | _renderer->setSliceAxis(_sv.position.axis); |
---|
55 | assert(_renderer->active()); |
---|
56 | _renderer->render(); |
---|
57 | } |
---|
58 | |
---|
59 | bool |
---|
60 | FlowParticles::configure() |
---|
61 | { |
---|
62 | bool needReset = false; |
---|
63 | |
---|
64 | _renderer->setColor(Color4f(_sv.color.r, |
---|
65 | _sv.color.g, |
---|
66 | _sv.color.b, |
---|
67 | _sv.color.a)); |
---|
68 | _renderer->particleSize(_sv.particleSize); |
---|
69 | if (_renderer->getSliceAxis() != _sv.position.axis) { |
---|
70 | needReset = true; |
---|
71 | _renderer->setSliceAxis(_sv.position.axis); |
---|
72 | } |
---|
73 | float pos = Flow::getRelativePosition(&_sv.position); |
---|
74 | if (_renderer->getSlicePosition() != pos) { |
---|
75 | needReset = true; |
---|
76 | _renderer->setSlicePosition(pos); |
---|
77 | } |
---|
78 | _renderer->active(!_sv.isHidden); |
---|
79 | |
---|
80 | return needReset; |
---|
81 | } |
---|