Showing the changes to interface/src/ParticleTreeRenderer.cpp (1 of 7 files). Show all
Unified · Split
| @@ -7,6 +7,8 @@ · 6 unmodified lines | ||
| 7 | 7 | // |
| 8 | 8 | // |
| 9 | 9 | |
| 10 | +#include <glm/gtx/quaternion.hpp> | |
| 11 | + | |
| 10 | 12 | #include "InterfaceConfig.h" |
| 11 | 13 | |
| 12 | 14 | #include "ParticleTreeRenderer.h" |
| @@ -16,8 +18,18 @@ ParticleTreeRenderer::ParticleTreeRenderer() : · 3 unmodified lines | ||
| 16 | 18 | } |
| 17 | 19 | |
| 18 | 20 | ParticleTreeRenderer::~ParticleTreeRenderer() { |
| 21 | + // delete the models in _particleModels | |
| 22 | + foreach(Model* model, _particleModels) { | |
| 23 | + delete model; | |
| 24 | + } | |
| 25 | + _particleModels.clear(); | |
| 26 | +} | |
| 27 | + | |
| 28 | +void ParticleTreeRenderer::init() { | |
| 29 | + OctreeRenderer::init(); | |
| 19 | 30 | } |
| 20 | 31 | |
| 32 | + | |
| 21 | 33 | void ParticleTreeRenderer::update() { |
| 22 | 34 | if (_tree) { |
| 23 | 35 | ParticleTree* tree = (ParticleTree*)_tree; |
| @@ -27,6 +39,39 @@ void ParticleTreeRenderer::update() { · 3 unmodified lines | ||
| 27 | 39 | } |
| 28 | 40 | } |
| 29 | 41 | |
| 42 | +void ParticleTreeRenderer::render() { | |
| 43 | + OctreeRenderer::render(); | |
| 44 | +} | |
| 45 | + | |
| 46 | +//_testModel->setURL(QUrl("http://highfidelity-public.s3-us-west-1.amazonaws.com/meshes/lotus.fbx")); | |
| 47 | +//_testModel->setURL(QUrl("http://www.fungibleinsight.com/faces/tie.fbx")); | |
| 48 | +//_testModel->setURL(QUrl("http://highfidelity-public.s3-us-west-1.amazonaws.com/meshes/Angie1.fbx")); | |
| 49 | +//_testModel->setURL(QUrl("http://public.highfidelity.io/meshes/orb_model.fbx")); | |
| 50 | +//_testModel->setURL(QUrl("http://public.highfidelity.io/meshes/space_frigate_6.FBX")); | |
| 51 | +//_testModel->setURL(QUrl("http://highfidelity-public.s3-us-west-1.amazonaws.com/meshes/soccer_ball.fbx")); | |
| 52 | +//_testModel->setURL(QUrl("http://highfidelity-public.s3-us-west-1.amazonaws.com/meshes/top%20fbx.FBX")); | |
| 53 | +//_testModel->setURL(QUrl("http://highfidelity-public.s3-us-west-1.amazonaws.com/meshes/golfball_FBX2010.fbx")); | |
| 54 | +//_testModel->setURL(QUrl("http://public.highfidelity.io/meshes/Combat_tank_V01.FBX")); | |
| 55 | + | |
| 56 | +//_testModel->setURL(QUrl("http://public.highfidelity.io/meshes/orc.fbx")); | |
| 57 | +//_testModel->setURL(QUrl("http://highfidelity-public.s3-us-west-1.amazonaws.com/meshes/Feisar_Ship.FBX")); | |
| 58 | + | |
| 59 | +Model* ParticleTreeRenderer::getModel(const QString& url) { | |
| 60 | + Model* model = NULL; | |
| 61 | + | |
| 62 | + // if we don't already have this model then create it and initialize it | |
| 63 | + if (_particleModels.find(url) == _particleModels.end()) { | |
| 64 | + model = new Model(); | |
| 65 | + model->init(); | |
| 66 | + qDebug() << "calling model->setURL()"; | |
| 67 | + model->setURL(QUrl(url)); | |
| 68 | + qDebug() << "after calling setURL()"; | |
| 69 | + } else { | |
| 70 | + model = _particleModels[url]; | |
| 71 | + } | |
| 72 | + return model; | |
| 73 | +} | |
| 74 | + | |
| 30 | 75 | void ParticleTreeRenderer::renderElement(OctreeElement* element, RenderArgs* args) { |
| 31 | 76 | // actually render it here... |
| 32 | 77 | // we need to iterate the actual particles of the element |
| @@ -36,8 +81,6 @@ void ParticleTreeRenderer::renderElement(OctreeElement* element, RenderArgs* arg · 3 unmodified lines | ||
| 36 | 81 | |
| 37 | 82 | uint16_t numberOfParticles = particles.size(); |
| 38 | 83 | |
| 39 | − bool drawAsSphere = true; | |
| 40 | − | |
| 41 | 84 | for (uint16_t i = 0; i < numberOfParticles; i++) { |
| 42 | 85 | const Particle& particle = particles[i]; |
| 43 | 86 | // render particle aspoints |
| @@ -45,18 +88,41 @@ void ParticleTreeRenderer::renderElement(OctreeElement* element, RenderArgs* arg · 1 unmodified line | ||
| 45 | 88 | glColor3ub(particle.getColor()[RED_INDEX],particle.getColor()[GREEN_INDEX],particle.getColor()[BLUE_INDEX]); |
| 46 | 89 | float sphereRadius = particle.getRadius() * (float)TREE_SCALE; |
| 47 | 90 | |
| 91 | + bool drawAsModel = particle.hasModel(); | |
| 92 | + | |
| 48 | 93 | args->_renderedItems++; |
| 49 | 94 | |
| 50 | − if (drawAsSphere) { | |
| 95 | + if (drawAsModel) { | |
| 96 | + glPushMatrix(); | |
| 97 | + const float alpha = 1.0f; | |
| 98 | + | |
| 99 | + Model* model = getModel(particle.getModelURL()); | |
| 100 | + | |
| 101 | + glm::vec3 translationAdjustment = particle.getModelTranslation(); | |
| 102 | + | |
| 103 | + // set the position | |
| 104 | + glm::vec3 translation(position.x, position.y, position.z); | |
| 105 | + model->setTranslation(translation + translationAdjustment); | |
| 106 | + | |
| 107 | + // glm::angleAxis(-90.0f, 1.0f, 0.0f, 0.0f) | |
| 108 | + // set the rotation | |
| 109 | + glm::quat rotation = particle.getModelRotation(); | |
| 110 | + model->setRotation(rotation); | |
| 111 | + | |
| 112 | + // scale | |
| 113 | + const float MODEL_SCALE = 0.0006f; // need to figure out correct scale adjust | |
| 114 | + glm::vec3 scale(1.0f,1.0f,1.0f); | |
| 115 | + model->setScale(scale * MODEL_SCALE); | |
| 116 | + | |
| 117 | + model->simulate(0.0f); | |
| 118 | + model->render(alpha); | |
| 119 | + //qDebug() << "called _testModel->render(alpha);"; | |
| 120 | + glPopMatrix(); | |
| 121 | + } else { | |
| 51 | 122 | glPushMatrix(); |
| 52 | 123 | glTranslatef(position.x, position.y, position.z); |
| 53 | 124 | glutSolidSphere(sphereRadius, 15, 15); |
| 54 | 125 | glPopMatrix(); |
| 55 | − } else { | |
| 56 | − glPointSize(sphereRadius); | |
| 57 | − glBegin(GL_POINTS); | |
| 58 | − glVertex3f(position.x, position.y, position.z); | |
| 59 | − glEnd(); | |
| 60 | 126 | } |
| 61 | 127 | } |
| 62 | 128 | } |