//* This only mostly works float Camera::getScreenRadius( const Sphere &sphere, float screenWidth, float screenHeight ) const { vec2 screenCenter( worldToScreen( sphere.getCenter(), screenWidth, screenHeight ) ); vec3 orthog = normalize( orthogonal( mViewDirection ) ); vec2 screenPerimeter = worldToScreen( sphere.getCenter() + sphere.getRadius() * orthog, screenWidth, screenHeight ); return distance( screenPerimeter, screenCenter ); }
sf::Vector2f Math::reflect(sf::Vector2f first, sf::Vector2f second) { //Not useful in case both first and second are parallel sf::Vector2f normal=orthogonal(second); //cout << second.x << " " << second.y << " " << normal.x << " " << normal.y << endl; sf::Vector2f res=(first-2*(dot(first, normal))*normal); //cout << first.x << " " << first.y << " " << second.x << " " << second.y << " " << res.x << " " << res.y << endl; return res; }
int setupGL() { if(!glfwInit()) { printf("glfwInit failed \n"); return 1; } glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE); glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); window = glfwCreateWindow(800, 600, "bounce", NULL, NULL); if(!window) { glfwTerminate(); printf("window creation failed \n"); return 1; } glewExperimental = GL_TRUE; if(glewInit() != GLEW_OK) { glfwTerminate(); printf("glewInit failed \n"); return 1; } glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE); glfwSetWindowSizeCallback(window, cb_resize); glfwSetWindowCloseCallback(window, cb_close); glfwSwapInterval(1); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glEnable(GL_CULL_FACE); glFrontFace(GL_CCW); glCheck(glClearColor(0.06, 0.06, 0.06, 0.f)); // One check right at the end GLuint vao; glGenVertexArrays(1, &vao); glBindVertexArray(vao); if(createShader() != 0) { glfwTerminate(); printf("shader creation failed \n"); return 1; } projection_matrix = perspective(60.f, (float)800/600, 0.1f, 100.f); hud_projection_matrix = orthogonal(-40, 40, -30, 30); glCheck(glUniformMatrix4fv(prjMatUniLoc, 1, GL_FALSE, &(projection_matrix.m[0]))); view_matrix = IDENTITY_MATRIX; model_matrix = IDENTITY_MATRIX; glCheck(createCube()); return 0; }
void Foam::triad::orthogonalize() { // Hack for 2D z-slab cases // if (!set(2)) // { // operator[](2) = vector(0, 0, 1); // } // If only two of the axes are set, set the third if (set(0) && set(1) && !set(2)) { operator[](2) = orthogonal(operator[](0), operator[](1)); } else if (set(0) && set(2) && !set(1)) { operator[](1) = orthogonal(operator[](0), operator[](2)); } else if (set(1) && set(2) && !set(0)) { operator[](0) = orthogonal(operator[](1), operator[](2)); } // If all the axes are set if (set()) { for (int i=0; i<2; i++) { const scalar o01 ( (set(0) && set(1)) ? mag(operator[](0) & operator[](1)) : vGreat ); const scalar o02 ( (set(0) && set(2)) ? mag(operator[](0) & operator[](2)) : vGreat ); const scalar o12 ( (set(1) && set(2)) ? mag(operator[](1) & operator[](2)) : vGreat ); if (o01 < o02 && o01 < o12) { operator[](2) = orthogonal(operator[](0), operator[](1)); // if (o02 < o12) // { // operator[](1) = orthogonal(operator[](0), operator[](2)); // } // else // { // operator[](0) = orthogonal(operator[](1), operator[](2)); // } } else if (o02 < o12) { operator[](1) = orthogonal(operator[](0), operator[](2)); // if (o01 < o12) // { // operator[](2) = orthogonal(operator[](0), operator[](1)); // } // else // { // operator[](0) = orthogonal(operator[](1), operator[](2)); // } } else { operator[](0) = orthogonal(operator[](1), operator[](2)); // if (o02 < o01) // { // operator[](1) = orthogonal(operator[](0), operator[](2)); // } // else // { // operator[](2) = orthogonal(operator[](0), operator[](1)); // } } } } }
const Vec Mpoint::tangential() const { return (difference_vector() - orthogonal()); }
void TrackDrawable::updateVB() const { // Debug Stuff std::vector<sf::CircleShape> * trackPoints = const_cast<std::vector<sf::CircleShape>*>(&this->mTrackPoints); trackPoints->clear(); std::vector<sf::CircleShape> * trackDirPoints = const_cast<std::vector<sf::CircleShape>*>(&this->mTrackDirPoints); trackDirPoints->clear(); // create vertex array sf::VertexArray * vb = const_cast<sf::VertexArray*>(&this->mVertices); // get rid of const... vb->setPrimitiveType(sf::Quads); vb->resize(this->mSegements.size() * 4); // create line constructed out of connected quads float halfThickness = this->mThickness * 0.5f; sf::Vector2f point1, point2; size_t i = 0; sf::Vertex * currentQuad = NULL; sf::Vertex * lastQuad = NULL; for (auto & segment : this->mSegements) { currentQuad = &(*vb)[i++ * 4]; // get segement points point1 = this->mPoints[segment.mPoint1]; point2 = this->mPoints[segment.mPoint2]; // compute normalized direction sf::Vector2f dir = normalize(point2 - point1); // compute orthogonal vectors sf::Vector2f orth1 = sf::Vector2f(dir.y, -dir.x) * halfThickness; sf::Vector2f orth2 = sf::Vector2f(-dir.y, dir.x) * halfThickness; // compute quad edges // build connection to last quad if (lastQuad != NULL) { currentQuad[0].position = lastQuad[3].position; currentQuad[1].position = lastQuad[2].position; } else { currentQuad[0].position = point1 + orth2; currentQuad[1].position = point1 + orth1; } if (i < this->mSegements.size()) { currentQuad[2].position = point2 + orth1; currentQuad[3].position = point2 + orth2; } else { // connect to first sf::Vertex * firstQuad = &(*vb)[0]; currentQuad[3].position = firstQuad[0].position; currentQuad[2].position = firstQuad[1].position; } // set quad color currentQuad[0].color = this->mColor; currentQuad[1].color = this->mColor; currentQuad[2].color = this->mColor; currentQuad[3].color = this->mColor; // store last quad lastQuad = currentQuad; // Debug Stuff sf::CircleShape debugPoint(2); debugPoint.setPosition(point1); debugPoint.setOrigin(1, 1); debugPoint.setFillColor(sf::Color::White); trackPoints->push_back(debugPoint); // compute point othogonal sf::Vector2f orthDir = orthogonal(normalize(point1 - point2)) * 8.0f; sf::CircleShape debugDirPoint(2); debugDirPoint.setPosition(point1 + orthDir); debugDirPoint.setOrigin(1, 1); debugDirPoint.setFillColor(sf::Color::Green); trackDirPoints->push_back(debugDirPoint); } // get rid of const and set the flag bool * dirty = const_cast<bool*>(&this->mIsDirty); *dirty = false; }