Beispiel #1
0
 void setTransform(const Transform* newTransform)
 {
     if (newTransform == transform)
         return;
     transform = newTransform;
     applyTransform();
 }
 void RenderableCylinder::render ()
 {
   applyTransform ();
   glTranslatef (0, 0, -length/2);
   //glutSolidCylinder(radius, length, 10, 10);
   unapplyTransform ();
 }
Beispiel #3
0
 // The cached values may have been messed with. Reset them again.
 void enforceAfterUntrustedGL() const
 {
     applyTexture();
     applyTransform();
     applyClipRect();
     applyAlphaMode();
 }
  void RenderableBox::render ()
  {
    applyTransform ();

    glColor3f (color.r, color.g, color.b);

    // Enable Pointers
    glEnableClientState (GL_VERTEX_ARRAY);
    glEnableClientState (GL_NORMAL_ARRAY);

    glBindBuffer (GL_ARRAY_BUFFER, vbo);
    glVertexPointer (3, GL_FLOAT, 6*sizeof(GLfloat), (char *) NULL);
    glNormalPointer (GL_FLOAT, 6*sizeof(GLfloat), ((char *) NULL) + (3 * sizeof(GLfloat)) );

    // Render
    glDrawArrays (GL_QUADS, 0, 24);

    // Disable Pointers
    glDisableClientState( GL_VERTEX_ARRAY );          // Disable Vertex Arrays
    glDisableClientState( GL_NORMAL_ARRAY );       // Disable Texture Coord Arrays

    //glScalef (dimx, dimy, dimz);
    //glutSolidCube (dimx);
    unapplyTransform ();
  }
  void RenderableMesh::render ()
  {
    applyTransform ();
    glScalef (scale_x, scale_y, scale_z);
    glEnableVertexAttribArray (0);
    glEnableVertexAttribArray (2);

    for (unsigned int i = 0 ; i < meshes.size() ; i++)
    {
      glBindBuffer (GL_ARRAY_BUFFER, meshes[i].vbo);
      glVertexAttribPointer (0, 3, GL_FLOAT, GL_FALSE, sizeof (Vertex), 0);
      glVertexAttribPointer (2, 3, GL_FLOAT, GL_FALSE, sizeof (Vertex), (const GLvoid*) (sizeof(float)*3));

      glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, meshes[i].ibo);

//      const unsigned int MaterialIndex = meshes[i].MaterialIndex;
//
//      if (MaterialIndex < textures.size() && textures[MaterialIndex])
//      {
//        textures[MaterialIndex]->Bind (GL_TEXTURE0);
//      }

      glDrawElements (GL_TRIANGLES, meshes[i].num_indices, GL_UNSIGNED_INT, 0);
    }

    glDisableVertexAttribArray (0);
    glDisableVertexAttribArray (2);
    unapplyTransform ();
  }
Beispiel #6
0
Shape::Shape()
{
    transformIndex = 0;
    mainBlock = sf::Vector2i(5,1);
    
    int randomBelowSeven = rand() % 7;
    
    switch (randomBelowSeven)
    {
        case 0:
            createI();
            break;
        case 1:
            createJ();
            break;
        case 2:
            createS();
            break;
        case 3:
            createO();
            break;
        case 4:
            createZ();
            break;
        case 5:
            createL();
            break;
        case 6:
            createT();
            break;
    }
    
    applyTransform(transformIndex);
}
Beispiel #7
0
void
TransformCommand::execute()
{
  if (!cloud_ptr_)
    return;
  applyTransform(selection_ptr_);
}
Beispiel #8
0
void RenderTarget::resetGLStates()
{
    if (activate(true))
    {
        // Make sure that GLEW is initialized
        priv::ensureGlewInit();

        // Define the default OpenGL states
        glCheck(glDisable(GL_CULL_FACE));
        glCheck(glDisable(GL_LIGHTING));
        glCheck(glDisable(GL_DEPTH_TEST));
        glCheck(glDisable(GL_ALPHA_TEST));
        glCheck(glEnable(GL_TEXTURE_2D));
        glCheck(glEnable(GL_BLEND));
        glCheck(glMatrixMode(GL_MODELVIEW));
        glCheck(glEnableClientState(GL_VERTEX_ARRAY));
        glCheck(glEnableClientState(GL_COLOR_ARRAY));
        glCheck(glEnableClientState(GL_TEXTURE_COORD_ARRAY));
        m_cache.glStatesSet = true;

        // Apply the default SFML states
        applyBlendMode(BlendAlpha);
        applyTransform(Transform::Identity);
        applyTexture(NULL);
        if (Shader::isAvailable())
            applyShader(NULL);
        m_cache.useVertexCache = false;

        // Set the default view
        setView(getView());
    }
}
Beispiel #9
0
// FIXME: We transform AffineTransform to TransformationMatrix. This is rather
// inefficient.
void TransformState::applyTransform(
    const AffineTransform& transformFromContainer,
    TransformAccumulation accumulate,
    bool* wasClamped) {
  applyTransform(transformFromContainer.toTransformationMatrix(), accumulate,
                 wasClamped);
}
void gkGameObjectInstance::notifyGameObjectEvent(gkGameObject* gobj, const gkGameObject::Notifier::Event& id)
{
	GK_ASSERT(gobj == m_owner);

	if (id == gkGameObject::Notifier::UPDATED)
		applyTransform(gobj->getTransformState());
}
void SiftMatcher::match()
{
  std::vector<std::vector<cv::KeyPoint>> keypoints = detect();
  std::vector<cv::Mat> descriptors = compute(keypoints);
  std::ofstream of(m_typeMap[m_type] + "SIFT/siftResults.txt");
  for (size_t i = 1; i < descriptors.size(); ++i)
  {

    const cv::Mat& desc1 = descriptors[0];
    const cv::Mat& desc2 = descriptors[i];
    cv::Mat transform = readTransform(transforms[i-1]);

    cv::BFMatcher matcher;
    std::vector<cv::DMatch> matches;
    matcher.match(desc1, desc2, matches);

    double max_dist = 0;
    double min_dist = 100;
    for (int i = 0; i < desc1.rows; ++i)
    {
      double dist = matches[i].distance;
      if (dist < min_dist) min_dist = dist;
      if (dist > max_dist) max_dist = dist;
    }

    std::cout << "Max dist: " << max_dist << std::endl;
    std::cout << "Min dist: " << min_dist << std::endl;

    std::vector<cv::DMatch> goodMatches;
    for (size_t i = 0; i < matches.size(); ++i)
    {
      if (matches[i].distance < 2 * min_dist)
        goodMatches.push_back(matches[i]);
    }

    const int total = goodMatches.size();
    int correct = 0;

    for (cv::DMatch match : goodMatches) {
      cv::KeyPoint p1 = keypoints[0][match.trainIdx];
      cv::KeyPoint p2 = keypoints[i][match.queryIdx];

      cv::Point orig = p1.pt;
      cv::Point rotated = p2.pt;
      cv::Point transformed = applyTransform(transform, orig, m_images[0]);
      if (std::abs(transformed.x - rotated.x) <= 5 && std::abs(transformed.y - rotated.y) <= 5)
        ++correct;
    }

    cv::Mat output;
    cv::drawMatches(m_images[0], keypoints[0], m_images[i], keypoints[i], goodMatches, output);
    cv::imwrite(m_typeMap[m_type] +  "SIFT/" + imagePaths[0] + "->" + imagePaths[i] + ".jpg", output);
    of << imagePaths[0] << "->" << imagePaths[i] << ":\n"
                        << "Total matches: " << total << '\n'
                        << "Good matches: " << correct << '\n'
                        << "Persentage: " << (int)ceil((double)correct / (double)total)
                        << std::endl;
  }
}
Beispiel #12
0
void Entity::translate(Vector2f offset)
{
	Transform transform;

	transform.translate(offset);

	applyTransform(transform);
}
Beispiel #13
0
void Entity::rotate(float angle, Vector2f center)
{
	Transform transform;

	transform.rotate(angle, center);

	applyTransform(transform);
}
Beispiel #14
0
void
TransformCommand::execute()
{
  pcl::console::print_info("Running Transform\n");
  if (!cloud_ptr_)
    return;
  applyTransform(selection_ptr_);
}
Beispiel #15
0
void Entity::scale(Vector2f factors, Vector2f center)
{
	Transform transform;

	transform.scale(factors, center);

	applyTransform(transform);
}
Beispiel #16
0
void RubberSheet::apply(shared_ptr<OsmMap>& map)
{
  shared_ptr<OGRSpatialReference> oldSrs = _projection;
  calculateTransform(map);
  _projection = oldSrs;

  applyTransform(map);
}
void
fxDodgeUpdateWindowTransform (CompWindow *w,
			      CompTransform *wTransform)
{
    ANIM_WINDOW(w);

    if (aw->isDodgeSubject)
	return;

    applyTransform (wTransform, &aw->com.transform);
}
Beispiel #18
0
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
  /* switchyard - apply appropriate action */
  int fail; char action[1024]; fail=mxGetString(prhs[0],action,1024);
  if(fail) mexErrMsgTxt("Failed to get action.");
  else if(!strcmp(action,"homogToFlow")) homogToFlow(nlhs,plhs,nrhs-1,prhs+1);
  else if(!strcmp(action,"homogsToFlow")) homogsToFlow(nlhs,plhs,nrhs-1,prhs+1);
  else if(!strcmp(action,"flowToInds")) flowToInds(nlhs,plhs,nrhs-1,prhs+1);
  else if(!strcmp(action,"homogToInds")) homogToInds(nlhs,plhs,nrhs-1,prhs+1);
  else if(!strcmp(action,"applyTransform")) applyTransform(nlhs,plhs,nrhs-1,prhs+1);
  else mexErrMsgTxt("Invalid action.");
}
Beispiel #19
0
void Map::setPosition(Vector2f position)
{
    Transform transform;
    Vector2f movement = position - this->position;

    this->position = position;

    transform.translate(movement);

    applyTransform(transform);
}
Beispiel #20
0
 void beginClipping(int x, int y, int width, int height, int screenHeight)
 {
     // Apply current transformation.
     
     double left = x, right = x + width;
     double top = y, bottom = y + height;
     
     applyTransform(currentTransform(), left, top);
     applyTransform(currentTransform(), right, bottom);
     
     int physX = std::min(left, right);
     int physY = std::min(top, bottom);
     int physWidth = std::abs(int(left - right));
     int physHeight = std::abs(int(top - bottom));
     
     // Adjust for OpenGL having the wrong idea of where y=0 is.
     // TODO: This should really happen *right before* setting up
     // the glScissor.
     physY = screenHeight - physY - physHeight;
     
     clipRectStack.beginClipping(physX, physY, physWidth, physHeight);
 }
Beispiel #21
0
void Gosu::Graphics::beginClipping(double x, double y, double width, double height)
{
    if (pimpl->queues.size() > 1)
        throw std::logic_error("Clipping not allowed while creating a macro");
    
    // Apply current transformation.
    
    double left = x, right = x + width;
    double top = y, bottom = y + height;
    
    applyTransform(pimpl->absoluteTransforms.back(), left, top);
    applyTransform(pimpl->absoluteTransforms.back(), right, bottom);
    
    int physX = std::min(left, right);
    int physY = std::min(top, bottom);
    int physWidth = std::abs(left - right);
    int physHeight = std::abs(top - bottom);
    
    // Apply OpenGL's counting from the wrong side ;)
    physY = pimpl->physHeight - physY - physHeight;
    
    pimpl->queues.back().beginClipping(physX, physY, physWidth, physHeight);
}
void ScenePlaneVis::render(bool ambientPass) {

  glPushAttrib(GL_ALL_ATTRIB_BITS);

  glPushMatrix();

  applyTransform();

  glEnable(GL_NORMALIZE);

  material->applyMaterial();


	// Use the vertex program and fragment program
	if (vertexProgram && fragmentProgram && !ambientPass) {

		glEnable(GL_VERTEX_PROGRAM_ARB);
		glEnable(GL_FRAGMENT_PROGRAM_ARB);

		glBindProgramARB(GL_VERTEX_PROGRAM_ARB, vertexProgram->vertexProgram);
		glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, fragmentProgram->fragmentProgram);

	}

	glScaled(scale, scale, scale);

  glBegin(GL_QUADS);
  glNormal3f(0, 1, 0); glVertex3f(-1.0, -0.0001,  1.0);
  glNormal3f(0, 1, 0); glVertex3f( 1.0, -0.0001,  1.0);
  glNormal3f(0, 1, 0); glVertex3f( 1.0, -0.0001, -1.0);
  glNormal3f(0, 1, 0); glVertex3f(-1.0, -0.0001, -1.0);
  glEnd();


	if (vertexProgram && fragmentProgram) {

		glDisable(GL_VERTEX_PROGRAM_ARB);
		glDisable(GL_FRAGMENT_PROGRAM_ARB);

		glBindProgramARB(GL_VERTEX_PROGRAM_ARB, 0);
		glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, 0);

	}

  glPopMatrix();

  glPopAttrib();

}
Beispiel #23
0
//Disegno il cannone
void Cannone::draw(void) {
	glPushMatrix();
		rotateX(xRot);
		rotateY(yRot);
		rotateZ(zRot);
		applyTransform();
		glColor3f(0.6, 0.6, 0.6);
		glutSolidSphere(0.35, 25, 43);
		switch (getCityPosition()) {
		case 0:
			glPushMatrix();
				glTranslatef(0, 0, -28);
				drawMirino();
			glPopMatrix();
			glTranslatef(0, 0, -0.6);
			glScalef(1, 1, 2.5);
			break;
		case 1:
			glPushMatrix();
				glTranslatef(28, 0, 0);
				glRotatef(90, 0, 1, 0);
				drawMirino();
			glPopMatrix();
			glTranslatef(0.6, 0, 0);
			glScalef(2.5, 1, 1);
			glRotatef(90, 0, 1, 0);
			break;
		case 2:
			glPushMatrix();
				glTranslatef(0, 0, 28);
				drawMirino();
			glPopMatrix();
			glTranslatef(0, 0, 0.6);
			glScalef(1, 1, 2.5);
			break;
		case 3:
			glPushMatrix();
				glTranslatef(-28, 0, 0);
				glRotatef(90, 0, 1, 0);
				drawMirino();
			glPopMatrix();
			glTranslatef(-0.6, 0, 0);
			glScalef(2.5, 1, 1);
			glRotatef(90, 0, 1, 0);
			break;
		}
		glutSolidTorus(0.25, 0.30, 25, 43);
	glPopMatrix();
}
int main(int ac, const char *av[])
{
    const cv::Mat input = useCommandLine(ac, av);
    if (!input.data) return 1;
    cv::namedWindow(av[1], cv::WINDOW_AUTOSIZE);
    cv::namedWindow("LinearTransform", cv::WINDOW_AUTOSIZE);
    cv::imshow(av[1], input); cv::waitKey(50);
    static LinearTransform lts[] = {
        &gainBiasMat, &gainBiasAt, &withConvertTo
    };
    static const int ltsCount = sizeof lts / sizeof lts[0];
    for (int i = 0; i < ltsCount; ++i) applyTransform(input, lts[i]);
    cv::waitKey(0);
    return 0;
}
Beispiel #25
0
void WRasterImage::Impl::setTransform(const WTransform& t)
{
  /*
  std::cout << "WRasterImage::setTransform "
	    << t.m11() << ", "
	    << t.m12() << ", "
	    << t.m21() << ", "
	    << t.m22() << ", "
	    << t.dx() << ", "
	    << t.dy() << ", "
	    << std::endl;
  */
  canvas_->resetMatrix();
  applyTransform(t);
}
Beispiel #26
0
//Disegno la citta e i palazzi
void Citta::draw(void) {
	glPushMatrix();
		//Ruoto la visuale per disegnare la citta nella posizione corretta
		rotateY(rotation);
		applyRotateTransform();
		setOrigin(0, 0, -distance);
		applyTransform();
		//Disegno i palazzi
		for (vector<Palazzo*>::iterator i = --palazzi.end(); i >= palazzi.begin(); i--) {
			glPushMatrix();
				(*i)->draw();
			glPopMatrix();
		}
	glPopMatrix();
}
Beispiel #27
0
std::shared_ptr<raytracer::Primitive> Surface::toRaytracer(raytracer::Scene* scene) const {
  auto primitive = toRaytracerPrimitive();
  if (!primitive) {
    return primitive;
  }
  
  if (material()) {
    primitive->setMaterial(material()->toRaytracerMaterial());
  }
  
  if (childElements().size() > 0) {
    auto composite = std::dynamic_pointer_cast<raytracer::Composite>(primitive);
    if (!composite) {
      composite = std::make_shared<raytracer::Composite>();
      composite->add(primitive);
    }
    
    for (const auto& child : childElements()) {
      if (Surface* surface = qobject_cast<Surface*>(child)) {
        if (surface->visible())
          composite->add(surface->toRaytracer(scene));
      } else if (Light* light = qobject_cast<Light*>(child)) {
        if (light->visible())
          scene->addLight(light->toRaytracer());
      }
    }
    
    if (auto grid = std::dynamic_pointer_cast<raytracer::Grid>(composite)) {
      grid->setup();
    }

    return applyTransform(composite);
  } else {
    return applyTransform(primitive);
  }
}
Beispiel #28
0
void DecalObject::updateFull() {
  TerrainChunk::PolishView& vx = chunk();

  if( !vx.needToUpdate )
    return;

  vx.geometry.hasIndex = true;

  glocation = vx.geometry.vertex.size();
  ilocation = vx.geometry.index.size();

  vx.geometry.vertex.resize( vx.geometry.vertex.size() + model->vertex.size() );
  vx.geometry.index .resize( vx.geometry.index .size() + model->index .size() );

  applyTransform();
  }
	void PrimitiveCube::Render(GLCamera3D* camera)
	{
		m_vBuffer->bind();
		m_iBuffer->bind();
		m_program->Bind();

		applyTransform(camera);

		//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
		PositionColor::Enable(true);
		PositionColor::RenderElements(COLOR_INDEX_COUNT, GL_QUADS);
		PositionColor::Enable(false);

		m_vBuffer->unbind();
		m_iBuffer->unbind();
		m_program->Unbind();
	}
Beispiel #30
0
void RenderTarget::resetGLStates()
{
    // Check here to make sure a context change does not happen after activate(true)
    bool shaderAvailable = Shader::isAvailable();

    if (setActive(true))
    {
        // Make sure that extensions are initialized
        priv::ensureExtensionsInit();

        // Make sure that the texture unit which is active is the number 0
        if (GLEXT_multitexture)
        {
            glCheck(GLEXT_glClientActiveTexture(GLEXT_GL_TEXTURE0));
            glCheck(GLEXT_glActiveTexture(GLEXT_GL_TEXTURE0));
        }

        // Define the default OpenGL states
        glCheck(glDisable(GL_CULL_FACE));
        glCheck(glDisable(GL_LIGHTING));
        glCheck(glDisable(GL_DEPTH_TEST));
        glCheck(glDisable(GL_ALPHA_TEST));
        glCheck(glEnable(GL_TEXTURE_2D));
        glCheck(glEnable(GL_BLEND));
        glCheck(glMatrixMode(GL_MODELVIEW));
        glCheck(glEnableClientState(GL_VERTEX_ARRAY));
        glCheck(glEnableClientState(GL_COLOR_ARRAY));
        glCheck(glEnableClientState(GL_TEXTURE_COORD_ARRAY));
        m_cache.glStatesSet = true;

        // Apply the default SFML states
        applyBlendMode(BlendAlpha);
        applyTransform(Transform::Identity);
        applyTexture(NULL);
        if (shaderAvailable)
            applyShader(NULL);

        m_cache.texCoordsArrayEnabled = true;

        m_cache.useVertexCache = false;

        // Set the default view
        setView(getView());
    }
}