History

first cut at particle meshes

ZappoMan committed 12 years ago

Commit 568d5bc1 parent 5e4813a7 files · +229 −52Browse files

Showing the changes to interface/src/ParticleTreeRenderer.cpp (1 of 7 files). Show all

Unified · Split

interface/src/ParticleTreeRenderer.cpp+74−8
@@ -7,6 +7,8 @@ · 6 unmodified lines
77 //
88 //
99
10+#include <glm/gtx/quaternion.hpp>
11+
1012 #include "InterfaceConfig.h"
1113
1214 #include "ParticleTreeRenderer.h"
@@ -16,8 +18,18 @@ ParticleTreeRenderer::ParticleTreeRenderer() : · 3 unmodified lines
1618 }
1719
1820 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();
1930 }
2031
32+
2133 void ParticleTreeRenderer::update() {
2234 if (_tree) {
2335 ParticleTree* tree = (ParticleTree*)_tree;
@@ -27,6 +39,39 @@ void ParticleTreeRenderer::update() { · 3 unmodified lines
2739 }
2840 }
2941
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+
3075 void ParticleTreeRenderer::renderElement(OctreeElement* element, RenderArgs* args) {
3176 // actually render it here...
3277 // we need to iterate the actual particles of the element
@@ -36,8 +81,6 @@ void ParticleTreeRenderer::renderElement(OctreeElement* element, RenderArgs* arg · 3 unmodified lines
3681
3782 uint16_t numberOfParticles = particles.size();
3883
39− bool drawAsSphere = true;
40−
4184 for (uint16_t i = 0; i < numberOfParticles; i++) {
4285 const Particle& particle = particles[i];
4386 // render particle aspoints
@@ -45,18 +88,41 @@ void ParticleTreeRenderer::renderElement(OctreeElement* element, RenderArgs* arg · 1 unmodified line
4588 glColor3ub(particle.getColor()[RED_INDEX],particle.getColor()[GREEN_INDEX],particle.getColor()[BLUE_INDEX]);
4689 float sphereRadius = particle.getRadius() * (float)TREE_SCALE;
4790
91+ bool drawAsModel = particle.hasModel();
92+
4893 args->_renderedItems++;
4994
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 {
51122 glPushMatrix();
52123 glTranslatef(position.x, position.y, position.z);
53124 glutSolidSphere(sphereRadius, 15, 15);
54125 glPopMatrix();
55− } else {
56− glPointSize(sphereRadius);
57− glBegin(GL_POINTS);
58− glVertex3f(position.x, position.y, position.z);
59− glEnd();
60126 }
61127 }
62128 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t