STColor4ub interpolatedColor(STPoint2 point, STImage *image) { point.x = fmax(0, fmin(point.x, image->GetWidth()-1)); point.y = fmax(0, fmin(point.y, image->GetHeight()-1)); if (point.x == floor(point.x) && point.y == floor(point.y)) return image->GetPixel(point.x, point.y); STPoint2 point1 = STPoint2(floor(point.x), floor(point.y)); STPoint2 point2 = STPoint2(floor(point.x), ceil(point.y)); STPoint2 point3 = STPoint2(ceil(point.x), ceil(point.y)); STPoint2 point4 = STPoint2(ceil(point.x), floor(point.y)); float weight1 = calculateColorWeight(point, point3); float weight2 = calculateColorWeight(point, point4); float weight3 = calculateColorWeight(point, point1); float weight4 = calculateColorWeight(point, point2); STColor4f color1 = STColor4f(image->GetPixel(point1.x, point1.y)) * weight1; STColor4f color2 = STColor4f(image->GetPixel(point2.x, point2.y)) * weight2; STColor4f color3 = STColor4f(image->GetPixel(point3.x, point3.y)) * weight3; STColor4f color4 = STColor4f(image->GetPixel(point4.x, point4.y)) * weight4; STColor4f colorTotal = color1 + color2 + color3 + color4; // colorTotal.a = 1; return STColor4ub(colorTotal); }
bool UICurvePoint::HitTest(const STPoint2& position) { UIRectangle r = UIRectangle(STPoint2(m_point->mCoordinates.x+-gPointSize, m_point->mCoordinates.y+-gPointSize), STPoint2(m_point->mCoordinates.x+ gPointSize, m_point->mCoordinates.y+ gPointSize)); if(r.Contains(position)) return true; return false; }
std::vector<Feature> interpolateFeatures(const std::vector<Feature> &sourceFeatures, const std::vector<Feature> &targetFeatures, float t) { std::vector<Feature> interpolatedFeatures; int numFeatures = sourceFeatures.size(); for (int i = 0; i < numFeatures; i++) { float newPx = sourceFeatures[i].P.x*(1-t) + targetFeatures[i].P.x*t; float newPy = sourceFeatures[i].P.y*(1-t) + targetFeatures[i].P.y*t; float newQx = sourceFeatures[i].Q.x*(1-t) + targetFeatures[i].Q.x*t; float newQy = sourceFeatures[i].Q.y*(1-t) + targetFeatures[i].Q.y*t; interpolatedFeatures.push_back(Feature(STPoint2(newPx, newPy), STPoint2(newQx, newQy))); } return interpolatedFeatures; }
void Note::DrawFlat() { glTranslatef(-radius*(8.0/25), 0.0, 0.0); // vertical line glLineWidth(.3*width_max); glBegin(GL_LINES); glVertex3f(-radius*.075, -radius*0.17, 0.0); glVertex3f(-radius*.075, radius*0.34, 0.0); glEnd(); float angle, angle2; int numVerts = 32; float radi = 0.0; float radMax = radius*0.232; STPoint2 cent = STPoint2(-radius*0.06, radius*0.075); for (int i = 0; i <= numVerts; i++) { glLineWidth(.2*width_max + .4*width_max*fabs(sin(i*M_PI/numVerts))); glBegin(GL_LINES); angle = (i-1)*M_PI/numVerts; glVertex3f(cent.x + (sin(angle) * (radi-(radMax/numVerts))), cent.y + (cos(angle) * (radi-(radMax/numVerts))), 0.0); angle2 = (i+1)*M_PI/numVerts; glVertex3f(cent.x + (sin(angle2) * (radi+(radMax/numVerts))), cent.y + (cos(angle2) * (radi+(radMax/numVerts))), 0.0); glEnd(); radi = i * (radMax/numVerts); } }
// // Generate a rectangle shape with the given width and height. The center // of the rectangle is at the origin. Width is in the x dimension and // height is in the y dimension. Normals are on the -z axis. // STShape* CreateRect(float width, float height) { STShape* result = new STShape(); STVector3 normal(0, 0, -1); float halfw = width/2.0f; float halfh = height/2.0f; result->AddVertex(STShape::Vertex( STPoint3(-halfw, -halfh, 0), normal, STPoint2(0, 0))); result->AddVertex(STShape::Vertex( STPoint3(halfw, -halfh, 0), normal, STPoint2(1, 0))); result->AddVertex(STShape::Vertex( STPoint3(halfw, halfh, 0), normal, STPoint2(1, 1))); result->AddVertex(STShape::Vertex( STPoint3(-halfw, halfh, 0), normal, STPoint2(0, 1))); result->AddFace(STShape::Face(0, 1, 2)); result->AddFace(STShape::Face(0, 2, 3)); return result; }
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; }
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; } } }
//const aiMesh* mesh; //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;