bool circleEmitter::addParticle(){ particle *newParticle; float speed; //Particle pool exists and max num particles not exceeded if(e != NULL && *managerParticleList != NULL && e->particleCount < e->totalParticles && emitting){ newParticle = *managerParticleList; *managerParticleList = (*managerParticleList)->next; if(e->particleList != NULL){ e->particleList->prev = newParticle; } newParticle->next = e->particleList; newParticle->prev = NULL; e->particleList = newParticle; float angle = randomAngle(); float radScalar = randDist(); newParticle->rand = radScalar; newParticle->radius = radius * radScalar; STVector3 point = STVector3(radius*radScalar*cosf(angle), 0, radius*radScalar*sinf(angle)); STVector3 straightUp = STVector3(0,1,0); STVector3 circleDir = STVector3(e->dir.x, e->dir.y, e->dir.z); STVector3 a = STVector3::Cross(straightUp, circleDir); float w = sqrt(powf(straightUp.Length(), 2) * powf(circleDir.Length(), 2)) + STVector3::Dot(straightUp, circleDir); Quaternion rotateCircle = Quaternion(w, a.x, a.y, a.z); rotateCircle.Normalize(); STVector3 rotatedPoint = rotateCircle.rotate(point, rotateCircle); newParticle->pos.x = rotatedPoint.x + e->pos.x; newParticle->pos.y = rotatedPoint.y + e->pos.y; newParticle->pos.z = rotatedPoint.z + e->pos.z; /* newParticle->pos.x = e->pos.x + radius*sinf(angle); newParticle->pos.y = e->pos.y; newParticle->pos.z = e->pos.z + radius*cosf(angle); */ newParticle->prevPos.x = 0; newParticle->prevPos.y = 0; newParticle->prevPos.z = 0; newParticle->dir = e->dir + (e->dirVar*randDist()); speed = e->speed + (e->speed * randDist()); newParticle->dir.x *= speed; newParticle->dir.y *= speed; newParticle->dir.z *= speed; newParticle->life = e->life + (int)((float)e->lifeVar * randDist()); newParticle->side = randDist(); e->particleCount++; return true; } return false; }
void Note::AttractFromDissonance(Note *other, float diss_val) { STPoint3 me = centerPosition; STPoint3 him = *other->getLocation(); STVector3 path = him - me; float mag = path.Length(); STVector3 dir = path / mag; // determines at which point dissonance transfers from attract to repel float crossing_val = .1; float how_fast = .005; //* (1.0/(mag * mag * mag * mag * mag * mag * mag * mag * mag * mag * mag * mag + 1.0)); int note_distance = abs(mapped_midi - other->getMappedMidi()); float from_midi_diff = .1 * pow((float)note_distance,.5); float from_max_midi_num = .008 * min(mapped_midi, other->getMappedMidi()); float summed_diss = easeRamp(diss_val) - from_midi_diff + from_max_midi_num; STVector3 nudgeVec; float eps = .01; STPoint3 newPos = me + dir * (how_fast/*/(pow(mag,1)+eps)*/) * (crossing_val - summed_diss); nudgeVec = me - newPos; centerPosition = me - nudgeVec/2; other->Nudge(nudgeVec/2); }
void Note::MoveFromDissonance(Note *other, float diss_val) { STPoint3 me = centerPosition; STPoint3 him = *other->getLocation(); STVector3 path = him - me; float mag = path.Length(); STVector3 dir = path / mag; STVector3 nudgeVec; int note_distance = abs(mapped_midi - other->getMappedMidi()); float from_max_midi_num = 0; //.12 * min(mapped_midi, other->getMappedMidi()); float from_midi_diff = .1 * (float)note_distance; // .05 * pow((float)note_distance,2); float from_diss_val = 20.0 * easeRamp(diss_val) ;//(3.0 * log(diss_val+2.0)); //12.0 * pow(1-easeBump(diss_val),7.0); float speed_due_to_dist = 1.0; //1.0/(pow(mag,20)+ 1.0); // speed is inversely porportional to mag float how_fast = .0005 * speed_due_to_dist; //* (1.0/(mag * mag * mag * mag * mag * mag * mag * mag * mag * mag * mag * mag + 1.0)); STPoint3 newPos = me + ((him - me) * (mag - (from_max_midi_num + from_midi_diff + from_diss_val))) * how_fast; nudgeVec = me - newPos; centerPosition = me - nudgeVec/2; other->Nudge(nudgeVec/2); }
void ZoomCamera(float delta_y) { STVector3 direction = mLookAt - mPosition; float magnitude = direction.Length(); direction.Normalize(); float zoom_rate = 0.1f*magnitude < 0.5f ? .1f*magnitude : .5f; if(delta_y * zoom_rate + magnitude > 0) { mPosition += (delta_y * zoom_rate) * direction; } }
void Note::AttractToZ() { STPoint3 me = centerPosition; STPoint3 ground = STPoint3(me.x, me.y, 0.0); STVector3 path = ground - me; float mag = path.Length(); STVector3 dir = path / mag; // this parameter goes (~ exponentially) from 0.0 = 3D to 1.0 = 2D float dimensionality = 0.001; //.06; centerPosition = me + (ground - me) * dimensionality; }
/**Populates qMatrixes based on the planes surrounding each vertex in the mesh m - Ankit*/ void QuadricErrorSimplification::generateQMatrices(STTriangleMesh* mesh){ STVector3 i, j, k; STVector3 n; float d = 0; float area = 0; STFace* f; STVertex* vert; for (size_t v = 0; v < mesh->mVertices.size(); ++v) { qMatrixes.push_back(new STMatrix4()); } for (size_t v = 0; v < mesh->mVertices.size(); ++v) { //memset(m_vertices[v].m_Q, 0, 10 * sizeof(Float)); vert = mesh->mVertices[v]; //find all the faces that contain this vertex for (size_t itT = 0; itT < mesh->mFaces.size(); ++itT) { f = mesh->mFaces[itT]; if (vertexEquals(f->v[0], vert) || vertexEquals(f->v[1], vert) || vertexEquals(f->v[2], vert)){ i = vertex2Vector3(f->v[0]); j = vertex2Vector3(f->v[1]); k = vertex2Vector3(f->v[2]); n = STVector3::Cross(j - i, k - i); area = n.Length(); n.Normalize(); d = -(STVector3::Dot(vertex2Vector3(mesh->mVertices[v]), n)); qMatrixes[v]->table[0][0] += area * (n.x * n.x); qMatrixes[v]->table[0][1] += area * (n.x * n.y); qMatrixes[v]->table[0][2] += area * (n.x * n.z); qMatrixes[v]->table[0][3] += area * (n.x * d); qMatrixes[v]->table[1][0] += area * (n.y * n.x); qMatrixes[v]->table[1][1] += area * (n.y * n.y); qMatrixes[v]->table[1][2] += area * (n.y * n.z); qMatrixes[v]->table[1][3] += area * (n.y * d); qMatrixes[v]->table[2][0] += area * (n.z * n.x); qMatrixes[v]->table[2][1] += area * (n.z * n.y); qMatrixes[v]->table[2][2] += area * (n.z * n.z); qMatrixes[v]->table[2][3] += area * (n.z * d); qMatrixes[v]->table[3][0] += area * (d * n.x); qMatrixes[v]->table[3][1] += area * (d * n.y); qMatrixes[v]->table[3][2] += area * (d * n.z); qMatrixes[v]->table[3][3] += area * (d * d); } } } }
void Note::MoveFromConnections() { for (int i = 0; i < max_connections; i++) { if (connection_list[i] != NULL) { STPoint3 me = centerPosition; STPoint3 him = *connection_list[i]->next_note->getLocation(); STVector3 path = him - me; float mag = path.Length(); STVector3 dir = path / mag; STPoint3 newPos = me + ((him - me) * (mag - connection_list[i]->ideal_dist))*speed; centerPosition = newPos; } } }
void Note::DrawConnections() { glLineWidth(.8*width_max); glColor4f(0.0,0.0,0.0,1.0); glBegin(GL_LINES); for (int i = 0; i < max_connections; i++) { if (connection_list[i] != NULL) { STPoint3 orig = centerPosition; STPoint3 goal = *connection_list[i]->next_note->getLocation(); STVector3 path = goal - orig; STVector3 dir = path / path.Length(); STPoint3 start = orig + dir*radius; STPoint3 finish = goal - dir*radius; glVertex3f(start.x, start.y, start.z); glVertex3f(finish.x, finish.y, finish.z); } } glEnd(); }
void Note::RepelFrom(Note *other) { STPoint3 me = centerPosition; STPoint3 him = *other->getLocation(); STVector3 path = him - me; float mag = path.Length(); STVector3 dir = path / mag; //STPoint3 newPos = me + ((him - me) * (mag - ideal_dists[i]))*speed; STVector3 nudgeVec; float overlap = mag - 2*radius; // strong repulsion for radius collisions if (overlap < 0.0) { nudgeVec = -(overlap/2)*dir; } // general repulsion nudgeVec += (1.0 / (pow(mag,4) + .3)) * dir * .05; // repulsion diminishes with square of distance centerPosition = me - nudgeVec/2; other->Nudge(nudgeVec/2); }