Esempio n. 1
0
float calculateV(STPoint2 X, STPoint2 P, STPoint2 Q)
{
    STVector2 PX = STVector2(X) - STVector2(P);
    STVector2 PQ = STVector2(Q) - STVector2(P);
    STVector2 PerpPQ = STVector2(PQ.y, -PQ.x);
    return STVector2::Dot(PX, PerpPQ) / sqrt(STVector2::Dot(PQ, PQ));
}
Esempio n. 2
0
STImage *FieldMorph(STImage *image,
                    const std::vector<Feature> &sourceFeatures,
                    const std::vector<Feature> &targetFeatures,
                    float t, float a, float b, float p)
{
    int width = image->GetWidth();
    int height = image->GetHeight();
    STImage *result = new STImage(width, height, STColor4ub(255,255,255,255));
    
    std::vector<Feature> interpolatedFeatures = interpolateFeatures(sourceFeatures, targetFeatures, t);
    
    for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
            STVector2 dispSum = STVector2(0, 0);
            float weightsum = 0;
            STPoint2 X = STPoint2(x, y);
            
            int numFeatures = sourceFeatures.size();
            for (int i = 0; i < numFeatures; i++) {
                STPoint2 Pp = sourceFeatures[i].P;
                STPoint2 Qp = sourceFeatures[i].Q;
                STPoint2 P = interpolatedFeatures[i].P;
                STPoint2 Q = interpolatedFeatures[i].Q;
                
                float u = calculateU(X, P, Q);
                float v = calculateV(X, P, Q);
                STPoint2 Xp = calculateXp(Pp, Qp, u, v);
                
                STVector2 displacement = STVector2(Xp) - STVector2(X);
                float dist = calculateDistance(X, P, Q, u, v);
                float weight = calculateWeight(Q, P, a, b, p, dist);
                dispSum += displacement * weight;
                weightsum += weight;
            }
            STPoint2 Xprime = X + dispSum/weightsum;
            
            result->SetPixel(x, y, interpolatedColor(Xprime, image));
        }
    }
    
    return result;
}
Esempio n. 3
0
void UICurvePoint::ForceContinuousTanget()
{
    if(m_point->mOnCurve)
    {
        int numPts = m_contour->NumPoints();
        
        // find index of this point in the contour
        int ptIndex = -1;
        for(int i = 0; i < numPts; i++)
        {
            if(m_point == m_contour->GetPoint(i))
            {
                ptIndex = i;
                break;
            }
        }
        
        // this point should exist in the contour
        // otherwise theres a problem!
        assert(ptIndex != -1);
        
        TTPoint * ptM1 = m_contour->GetPoint(wrapTo(ptIndex-1, numPts));
        TTPoint * ptP1 = m_contour->GetPoint(wrapTo(ptIndex+1, numPts));
        if(!ptM1->mOnCurve && !ptP1->mOnCurve)
        {
            // translate to origin
            STVector2 trM1 = ptM1->mCoordinates - m_point->mCoordinates;
            // translate to origin
            STVector2 trP1 = ptP1->mCoordinates - m_point->mCoordinates;
            // normalize
            trP1.Normalize();
            // point previous tangent in opposite direction with same length
            trM1 = STVector2(-trP1.x, -trP1.y) * trM1.Length();
            // translate back
            ptM1->mCoordinates = m_point->mCoordinates + trM1;
            
            // don't disturb tangents of other points
            TTPoint * ptM2 = m_contour->GetPoint(wrapTo(ptIndex-2, numPts));
            if(ptM2->mOnCurve)
            {
                TTPoint * ptM3 = m_contour->GetPoint(wrapTo(ptIndex-3, numPts));
                Intersection(m_point->mCoordinates, ptM1->mCoordinates,
                             ptM2->mCoordinates, ptM3->mCoordinates,
                             ptM1->mCoordinates);
            }
        }
    }
}
/**
 * Mouse active motion callback (when button is pressed)
 */
void MouseMotionCallback(int x, int y)
{
    if(dragging) {
      dragDiff = (STVector2(x,y)-start).Length();
      return;
    }
    
    if (gPreviousMouseX >= 0 && gPreviousMouseY >= 0)
    {
        //compute delta
        float deltaX = x-gPreviousMouseX;
        float deltaY = y-gPreviousMouseY;
        gPreviousMouseX = x;
        gPreviousMouseY = y;
        
        float zoomSensitivity = 0.2f;
        float rotateSensitivity = 0.5f;
        
        //orbit or zoom
        if (gMouseButton == GLUT_LEFT_BUTTON)
        {
            AdjustCameraAzimuthBy(-deltaX*rotateSensitivity);
            AdjustCameraElevationBy(-deltaY*rotateSensitivity);
            
        } else if (gMouseButton == GLUT_RIGHT_BUTTON)
        {
            STVector3 zoom(0,0,deltaX);
            AdjustCameraTranslationBy(zoom * zoomSensitivity);
        }
        
    } else
    {
        gPreviousMouseX = x;
        gPreviousMouseY = y;
    }
    
}
Esempio n. 5
0
//std::vector<unsigned> indexBuffer;

GLuint scene_list1 = 0;
GLuint scene_list2 = 0;

GLuint cubeMap;

// current rotation angle
static float h_angle = 0.0;
static float v_angle = MY_PI/2;

bool mouseInit = false;
float lastTime = 0.0;
STPoint2 cur_mouse = STPoint2(0.0,0.0);
STPoint2 last_mouse = STPoint2(0.0,0.0);
STVector2 mouse_move = STVector2(0.0,0.0);

STPoint3 current_location = STPoint3(-10,2,0);
STPoint3 statue_location = STPoint3(0,2.92,0);

STVector3 Up = STVector3(0.0,1.0,0.0);
STVector3 current_forward = STVector3(sin(v_angle)*cos(h_angle),cos(v_angle),sin(v_angle)*sin(h_angle));
STVector3 current_right = STVector3::Cross(current_forward, Up);

// globals for keyboard control
bool go_forward = false;
bool go_backward = false;
bool go_left = false;
bool go_right = false;
bool go_up = false;
bool go_down = false;
Esempio n. 6
0
float calculateU(STPoint2 X, STPoint2 P, STPoint2 Q)
{
    STVector2 PX = STVector2(X) - STVector2(P);
    STVector2 PQ = STVector2(Q) - STVector2(P);
    return STVector2::Dot(PX, PQ) / STVector2::Dot(PQ, PQ);
}
Esempio n. 7
0
STPoint2 calculateXp(STPoint2 P, STPoint2 Q, float u, float v)
{
    STVector2 PQ = STVector2(Q) - STVector2(P);
    STVector2 PerpPQ = STVector2(PQ.y, -PQ.x);
    return P + (u * PQ) + ((v * PerpPQ) / sqrt(STVector2::Dot(PQ, PQ)));
}
int gPreviousMouseX = -1;
int gPreviousMouseY = -1;
int gMouseButton = -1;
STVector3 mCameraTranslation;
float mCameraAzimuth;
float mCameraElevation;

bool teapot = false;
bool lake = true;
bool ocean = false;

bool trampoline = false;
bool dragging = false;
bool bounce = false;
float dragDiff = 0.;
STVector2 start = STVector2(0.,0.);

float t = 0.0;

struct wave {
  float A, L, S, x, y,threshold;
  bool forward;
};

int numwaves = 10;
wave waves[10];

void resetCamera()
{
    mCameraTranslation = STVector3(0.f, 1.f, 1.5f);
    mCameraAzimuth = 0.f;
Esempio n. 9
0
void UICurvePoint::HandleMouseMove(const STPoint2& position, int modifiers)
{
    if(m_mouseDown)
    {
        if(modifiers & GLUT_ACTIVE_CTRL)
        {
            if(m_point->mOnCurve)
            {
                int numPts = m_contour->NumPoints();
                
                // find index of this point in the contour
                int ptIndex = -1;
                for(int i = 0; i < numPts; i++)
                {
                    if(m_point == m_contour->GetPoint(i))
                    {
                        ptIndex = i;
                        break;
                    }
                }
                
                // this point should exist in the contour
                // otherwise theres a problem!
                assert(ptIndex != -1);
                
                float theta = (position.y - m_lastMouseLocation.y)/180.0*M_PI;
                
                TTPoint * ptM1 = m_contour->GetPoint(wrapTo(ptIndex-1, numPts));
                if(!ptM1->mOnCurve)
                {
                    // translate to origin
                    STVector2 trM1 = ptM1->mCoordinates - m_point->mCoordinates;
                    // rotate about origin
                    trM1 = STVector2(STVector2::Dot(trM1, STVector2(cosf(theta), sinf(theta))),
                                     STVector2::Dot(trM1, STVector2(-sinf(theta), cosf(theta))));
                    // translate back
                    ptM1->mCoordinates = m_point->mCoordinates + trM1;

                    TTPoint * ptM2 = m_contour->GetPoint(wrapTo(ptIndex-2, numPts));
                    if(ptM2->mOnCurve)
                    {
                        TTPoint * ptM3 = m_contour->GetPoint(wrapTo(ptIndex-3, numPts));
                        Intersection(m_point->mCoordinates, ptM1->mCoordinates,
                                     ptM2->mCoordinates, ptM3->mCoordinates,
                                     ptM1->mCoordinates);
                    }
                }
                
                TTPoint * ptP1 = m_contour->GetPoint(wrapTo(ptIndex+1, numPts));
                if(!ptP1->mOnCurve)
                {
                    // translate to origin
                    STVector2 trP1 = ptP1->mCoordinates - m_point->mCoordinates;
                    // rotate about origin
                    trP1 = STVector2(STVector2::Dot(trP1, STVector2(cosf(theta), sinf(theta))),
                                     STVector2::Dot(trP1, STVector2(-sinf(theta), cosf(theta))));
                    // translate back
                    ptP1->mCoordinates = m_point->mCoordinates + trP1;
                    
                    TTPoint * ptP2 = m_contour->GetPoint(wrapTo(ptIndex+2, numPts));
                    if(ptP2->mOnCurve)
                    {
                        TTPoint * ptP3 = m_contour->GetPoint(wrapTo(ptIndex+3, numPts));
                        Intersection(m_point->mCoordinates, ptP1->mCoordinates,
                                     ptP2->mCoordinates, ptP3->mCoordinates,
                                     ptP1->mCoordinates);
                    }
                }
            }
        }
        else
        {
            m_point->mCoordinates = position;
            if(m_moveCallback)
                m_moveCallback(this);
        }
    }
    
    m_lastMouseLocation = position;
}