Пример #1
0
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);
}
Пример #2
0
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);
}
Пример #3
0
void SetUpAndRight()
{
    mRight = STVector3::Cross(mLookAt - mPosition, mUp);
    mRight.Normalize();
    mUp = STVector3::Cross(mRight, mLookAt - mPosition);
    mUp.Normalize();
}
Пример #4
0
void resetUp()
{
    mUp = STVector3(0.f,1.f,0.f);
    mRight = STVector3::Cross(mLookAt - mPosition, mUp);
    mRight.Normalize();
    mUp = STVector3::Cross(mRight, mLookAt - mPosition);
    mUp.Normalize();
}
Пример #5
0
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;
}
Пример #6
0
bool Triangle::findPointHit(Ray r, Intersection& intersect, STTransform4 transform) const{
   
    //Transform points according to the scene object transformation
    STPoint3 v11 = transform * v1;
    STPoint3 v21 = transform * v2;
    STPoint3 v31 = transform * v3;
    
    // Using Cramer's rule
    float a = v11.x - v21.x;
    float b = v11.y - v21.y;
    float c = v11.z - v21.z;
    float d = v11.x - v31.x;
    float e = v11.y - v31.y;
    float f = v11.z - v31.z;
    float g = r.getD().x;
    float h = r.getD().y;
    float i = r.getD().z;
    float j = v11.x - r.getE().x;
    float k = v11.y - r.getE().y;
    float l = v11.z - r.getE().z;
    
    float ei_minus_hf = e * i - h * f;
    float gf_minus_di = g * f - d * i;
    float dh_minus_eg = d * h - e * g;
    float ak_minus_jb = a * k - j * b;
    float jc_minus_al = j * c - a * l;
    float bl_minus_kc = b * l - k * c;
    
    float M = a*ei_minus_hf + b*gf_minus_di + c*dh_minus_eg;
    float t = -(f*ak_minus_jb + e*jc_minus_al + d*bl_minus_kc) / M;
    if(t < r.getMinT() || t > r.getMaxT()) return false;
    float gamma = (i*ak_minus_jb + h*jc_minus_al + g*bl_minus_kc) / M;
    if(gamma < 0 || gamma > 1) return false;
    float beta = (j*ei_minus_hf + k*gf_minus_di + l*dh_minus_eg) / M;
    if(beta < 0 || beta > 1 - gamma) return false;
    
    intersect.t = t;
    intersect.intersectionPt = r.getE() + t * r.getD();
    
    //We are getting the (untransformed normal here!)
    STVector3 normal = STVector3::Cross(v2-v1,v3-v2);
    
    //Transform normal into world coordinates according to "transoform"
    // new normal = M^(-T)(normal, 0) (where normal,0 is the normal in 4D
    normal = transform.Inverse().Transpose() * normal;
    normal.Normalize();
    
    intersect.intersectionNormal = normal;
   
    //Shadow bias
    if(t < r.getMinT() || t > r.getMaxT()) return false;
    
    return true;

}
Пример #7
0
STColor3f DirectionalLight::sumTerm(Intersection inter, Material *material, Ray *viewingRay){
    STVector3 incomingLight = -*direction;
    incomingLight.Normalize();
    STVector3 normal = inter.normal;
    STVector3 view = -viewingRay->direction;
    
    STColor3f diffuse = material->diff * (*color) * fmax(0.0, STVector3::Dot(incomingLight, normal));
    STColor3f specular = material->spec * (*color) * pow(fmax(0, STVector3::Dot(view, Utils::reflectVector(normal, incomingLight))), material->shine);
    
    return diffuse + specular;
}
STVector3 distance(STVector3 A, STVector3 B, const STVector3 P, double *t) 
{ 
    STVector3 AB = B - A; 
    double ab_square = AB.Dot(AB, AB); 
    STVector3 AP = P - A; 
    double ap_dot_ab = AP.Dot(AP, AB); 
    *t = ap_dot_ab / ab_square; 
    STVector3 Q;
    Q = A + AB * (*t); 
    return Q; 
}  
Пример #9
0
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;
    }
}
Пример #10
0
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);
			}
		}
	}
}
Пример #12
0
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;
        }
    }
}
Пример #13
0
void Camera::createOrthonormalBasis(const STPoint3& eye, const STVector3& up, const STPoint3& lookAt)
{
    position = eye;
    
    // Create orthonormal basis
    STVector3 a = lookAt - eye;
    STVector3 b = up;
    
    a.Normalize();
    w = a;
    
    u = STVector3::Cross(b, w);
    u.Normalize();
    
    v = STVector3::Cross(w, u);
}
Пример #14
0
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();
}
Пример #15
0
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);
}
Пример #16
0
void DrawManipulator(void)
{

    // color
    RGBR_f colorRed(1, 0, 0, 1);
    RGBR_f colorGreen(0, 1, 0, 1);
    RGBR_f colorBlue(0, 0, 1, 1);
    RGBR_f colorWhite(1,1,1,1);
    RGBR_f colorMagenta(1.0f,0.3f,1.0f, 1.0f);
    RGBR_f colorGrey(0.2f,0.2f,0.2f, 1.0f);

    // a, y and z axis
    STVector3 xaxis = STVector3::eX;
    STVector3 yaxis = STVector3::eY;
    STVector3 zaxis = STVector3::eZ;

    // camera basis
    STVector3 up = pScene->GetCamera()->Up();
    STVector3 right = pScene->GetCamera()->Right();
    STVector3 dir = pScene->GetCamera()->LookAt();
    STVector3 front;
    front = front.Cross(right, xaxis);
    front.Normalize();

    // camera plane
    float colx[4] = {1, 0, 0, 1};
    float coly[4] = {0, 1, 0, 1};
    float colz[4] = {0, 0, 1, 1};
    float colall[4] = {1, 1, 1, 1};

    float fct = 0.05f;
    float fct2 = 0.83f;

    STMatrix4 curModelMatrix;
    curModelMatrix.EncodeI();

    //------------------------------------------------------------------------------
    // TO DO: Proj3_4 OpenGL
    // Update the matrix transformation for the manipulator geometry
    // Update curModelMatrix
    //------------------------------------------------------------------------------
    curModelMatrix.EncodeS(0.1, 0.1, 0.1);
    //-------------------------------------------------------------------------------

    // screen projection
    ViewProjectionScreenSpace(curModelMatrix);

    STVector3 origin(0,0,0);
    curModelMatrix.GetT(&origin.x, &origin.y, &origin.z);

    if(pScene->CurrentManipMode() == LOCAL) {
        xaxis.Transform(curModelMatrix);
        yaxis.Transform(curModelMatrix);
        zaxis.Transform(curModelMatrix);
        xaxis.Normalize();
        yaxis.Normalize();
        zaxis.Normalize();
    }


    // Rotations
    if((pScene->CurrentManipGeometryState() == AXIS_ALL) || 
        (pScene->CurrentManipGeometryState() == AXIS_ROTATIONALL)) {


        STVector3 X_UP;
        STVector3 X_RIGHT;
        STVector3 X_FRONT;
        STVector3 X_UP_sc;
        STVector3 X_RIGHT_sc;
        STVector3 X_FRONT_sc;


        STVector3 planenorm(pScene->GetCamera()->Position() - origin);
        planenorm.Normalize();
        STVector4 camplane = vector4(planenorm,0);
        
        // duplicate
        X_RIGHT   =   right    * ScreenFactor();
        X_UP      =   up       * ScreenFactor();
        if(pScene->CurrentManipMotion() == ROTATE_DUPLICATE)
            DrawCircle(origin, colorWhite, X_RIGHT, X_UP);
        else
            DrawCircle(origin, colorGrey, X_RIGHT, X_UP);


        // screen rot
        X_UP_sc    =  up * 1.2f       * ScreenFactor();
        X_RIGHT_sc =  right * 1.2f    * ScreenFactor();
        if(pScene->CurrentManipMotion() == ROTATE_SCREEN) 
            DrawCircle(origin, colorWhite, X_UP_sc, X_RIGHT_sc);
        else 
            DrawCircle(origin, colorMagenta, X_UP_sc, X_RIGHT_sc);


        // x rot
        right.Cross(dir, xaxis);
        right.Normalize();
        front.Cross(right, xaxis);
        front.Normalize();
        X_RIGHT   =   right    * ScreenFactor();
        X_FRONT   =   front    * ScreenFactor();
        if(pScene->CurrentManipMotion() == ROTATE_Y)
            DrawCircleHalf(origin, colorWhite, X_RIGHT, X_FRONT, camplane);
        else
            DrawCircleHalf(origin, colorRed, X_RIGHT, X_FRONT, camplane);


        // y rot
        right.Cross(dir, yaxis);
        right.Normalize();
        front.Cross(right, yaxis);
        front.Normalize();
        X_RIGHT   =   right    * ScreenFactor();
        X_FRONT   =   front    * ScreenFactor();
        if(pScene->CurrentManipMotion() == ROTATE_Y)
            DrawCircleHalf(origin, colorWhite, X_RIGHT, X_FRONT, camplane);
        else
            DrawCircleHalf(origin, colorGreen, X_RIGHT, X_FRONT, camplane);

        // z rot
        right.Cross(dir, zaxis);
        right.Normalize();
        front.Cross(right, zaxis);
        front.Normalize();
        X_RIGHT   =   right    * ScreenFactor();
        X_FRONT   =   front    * ScreenFactor();
        if(pScene->CurrentManipMotion() == ROTATE_Z)
            DrawCircleHalf(origin, colorWhite, X_RIGHT, X_FRONT, camplane);
        else
            DrawCircleHalf(origin, colorBlue, X_RIGHT, X_FRONT, camplane);
    }


    // cam
    if ((pScene->CurrentManipMotion() !=  MANIP_NONE) && ((pScene->CurrentManipMotion() != ROTATE_DUPLICATE)))
        DrawCam(origin, gblXVert*ScreenFactor(), gblYVert *ScreenFactor(), -Ng2);



    // draw translation manupulator
    //-----------------------------------------------
 
    // Translations
    if((pScene->CurrentManipGeometryState() == AXIS_ALL) ||
        (pScene->CurrentManipGeometryState() == AXIS_TRANSXYZ)) {

        DrawQuadrant(origin, 0.5f*ScreenFactor(), (pScene->CurrentManipMotion() == TRANS_XZ), xaxis, zaxis);
        DrawQuadrant(origin, 0.5f*ScreenFactor(), (pScene->CurrentManipMotion() == TRANS_XY), xaxis, yaxis);
        DrawQuadrant(origin, 0.5f*ScreenFactor(), (pScene->CurrentManipMotion() == TRANS_YZ), yaxis, zaxis);

        xaxis *= ScreenFactor();
        yaxis *= ScreenFactor();
        zaxis *= ScreenFactor();


        if(pScene->CurrentManipMotion() == TRANS_X)
            DrawAxis(origin, colorRed, xaxis, yaxis, zaxis, fct, fct2, colall);
        else
            DrawAxis(origin, colorRed, xaxis, yaxis, zaxis, fct, fct2, colx);


        // y axis
        if(pScene->CurrentManipMotion() == TRANS_Y) 
            DrawAxis(origin, colorGreen, yaxis, xaxis, zaxis, fct, fct2, colall);
        else
            DrawAxis(origin, colorGreen, yaxis, xaxis, zaxis, fct, fct2, coly);

    
        // z axis
        if(pScene->CurrentManipMotion() == TRANS_Z) 
            DrawAxis(origin, colorBlue, zaxis, xaxis, yaxis, fct, fct2, colall);
        else
            DrawAxis(origin, colorBlue, zaxis, xaxis, yaxis, fct, fct2, colz);
    }


}
Пример #17
0
void handleInput() {
    
    // this handles setting keyboard booleans for motion
    go_forward = Input.IsKeyDown(sf::Key::W);
    go_backward = Input.IsKeyDown(sf::Key::S);
    go_left = Input.IsKeyDown(sf::Key::A);
    go_right = Input.IsKeyDown(sf::Key::D);
    go_up = Input.IsKeyDown(sf::Key::Space);
    go_down = Input.IsKeyDown(sf::Key::C);
    
    
    // Event loop, for processing user input, etc.  For more info, see:
    // http://www.sfml-dev.org/tutorials/1.6/window-events.php
    sf::Event evt;
    while (window.GetEvent(evt)) {
        
        switch (evt.Type) {
            case sf::Event::Closed: 
                // Close the window.  This will cause the game loop to exit,
                // because the IsOpened() function will no longer return true.
                window.Close(); 
                break;
            case sf::Event::Resized: 
                // If the window is resized, then we need to change the perspective
                // transformation and viewport
                glViewport(0, 0, evt.Size.Width, evt.Size.Height);
                break;
                
                // Mouse Movement
            case sf::Event::MouseMoved:
                if (!mouseInit) {
                    cur_mouse = STPoint2(evt.MouseMove.X, evt.MouseMove.Y);
                    last_mouse = cur_mouse;
                    mouseInit = true;
                }
                else {
                    cur_mouse = STPoint2(evt.MouseMove.X, evt.MouseMove.Y);
                }
                mouse_move = cur_mouse - last_mouse;
                
                h_angle += .01 * mouse_move.x;
                v_angle += .01 * mouse_move.y;
                if (v_angle < 0) {
                    v_angle = 0.01;
                }
                else if (v_angle > MY_PI) {
                    v_angle = MY_PI-.01;
                }
                
                current_forward = STVector3(sin(v_angle)*cos(h_angle),cos(v_angle),sin(v_angle)*sin(h_angle));
                current_forward.Normalize();
                current_right = STVector3::Cross(current_forward, Up);
                current_right.Normalize();
                
                last_mouse = cur_mouse;
                break;
                
                // Key presses
            case sf::Event::KeyPressed:
                switch (evt.Key.Code) {
                    case sf::Key::Escape:
                        window.Close();
                        break;
                        
                    default:
                        break;
                }
                
            default: 
                break;
        }
    }
}
Пример #18
0
STVector3 Sphere::CalcNormal(STVector3 surface_pt, Ray unused){
    STVector3 v = surface_pt - center;
    v.Normalize();
    return v;
}