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/Vector4f.h> |
---|
15 | |
---|
16 | #include "nanovis.h" // For NMESH |
---|
17 | #include "FlowParticles.h" |
---|
18 | #include "Flow.h" |
---|
19 | #include "Trace.h" |
---|
20 | |
---|
21 | using namespace vrmath; |
---|
22 | |
---|
23 | FlowParticles::FlowParticles(const char *name) : |
---|
24 | _name(name), |
---|
25 | _renderer(new NvParticleRenderer(NMESH, NMESH)) |
---|
26 | { |
---|
27 | _sv.position.value = 0.0f; |
---|
28 | _sv.position.flags = RELPOS; |
---|
29 | _sv.position.axis = 0; // X_AXIS |
---|
30 | _sv.color.r = _sv.color.g = _sv.color.b = _sv.color.a = 1.0f; |
---|
31 | _sv.isHidden = false; |
---|
32 | _sv.particleSize = 1.2; |
---|
33 | } |
---|
34 | |
---|
35 | FlowParticles::~FlowParticles() |
---|
36 | { |
---|
37 | TRACE("Deleting renderer"); |
---|
38 | if (_renderer != NULL) { |
---|
39 | delete _renderer; |
---|
40 | } |
---|
41 | TRACE("Freeing switches"); |
---|
42 | Rappture::FreeSwitches(_switches, &_sv, 0); |
---|
43 | } |
---|
44 | |
---|
45 | void |
---|
46 | FlowParticles::render() |
---|
47 | { |
---|
48 | TRACE("Particles '%s' axis: %d pos: %g rel pos: %g", |
---|
49 | _name.c_str(), _sv.position.axis, _sv.position.value, |
---|
50 | Flow::getRelativePosition(&_sv.position)); |
---|
51 | |
---|
52 | _renderer->setPos(Flow::getRelativePosition(&_sv.position)); |
---|
53 | _renderer->setAxis(_sv.position.axis); |
---|
54 | assert(_renderer->active()); |
---|
55 | _renderer->render(); |
---|
56 | } |
---|
57 | |
---|
58 | void |
---|
59 | FlowParticles::configure() |
---|
60 | { |
---|
61 | _renderer->setPos(Flow::getRelativePosition(&_sv.position)); |
---|
62 | _renderer->setColor(Vector4f(_sv.color.r, |
---|
63 | _sv.color.g, |
---|
64 | _sv.color.b, |
---|
65 | _sv.color.a)); |
---|
66 | _renderer->particleSize(_sv.particleSize); |
---|
67 | _renderer->setAxis(_sv.position.axis); |
---|
68 | _renderer->active(!_sv.isHidden); |
---|
69 | } |
---|