Esempio n. 1
0
void RenderScene()
{
	// Model matrix : being updated by idle
	// Our ModelViewProjection : multiplication of our 3 matrices
	MVP = Projection * View * Model; // Remember, matrix multiplication is the other way around

	// Use our shader
	glUseProgram(ShaderMainProgramId);

	// Send our transformation to the currently bound shader, in the "MVP" uniform

	glUniformMatrix4fv(MainShaderMvpId, 1, GL_FALSE, &MVP[0][0]);

	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

	// Bind texture to texture unit
	glActiveTexture(GL_TEXTURE0); // change active texture unit to number 0
	glBindTexture(GL_TEXTURE_2D, TextureId); // bind the texture to the active texture unit (which is now 0)

	// Bind shader variable "Texture" to texture unit
	glUniform1iARB(MainShaderTextureId, 0); // Notice the 0 to indicate you want to sample from the texture bound to Texture Unit GL_TEXTURE0.

	float imageRatio = (float)theTexMap.GetNumCols() / theTexMap.GetNumRows();
	if (imageRatio > 1)
	{
		imageRatio = 1.0 / imageRatio;
	}

	glBegin(GL_QUADS);

	glTexCoord2f(0.0, 1.0);
	glVertex3f(-1.0, 0.0, -1.0*imageRatio);

	glTexCoord2f(0.0, 0.0);
	glVertex3f(-1.0, 0.0, 1.0*imageRatio);

	glTexCoord2f(1.0, 0.0);
	glVertex3f(1.0, 0.0, 1.0*imageRatio);

	glTexCoord2f(1.0, 1.0);
	glVertex3f(1.0, 0.0, -1.0*imageRatio);

	glEnd();


	// Draw groups
	glUseProgram(ShaderModelProgramId);
	glUniformMatrix4fv(ModelShaderMvpId, 1, GL_FALSE, &MVP[0][0]);

	int modelNum = 0;
	for (std::vector<Group>::iterator it = (*Data).begin(); it != (*Data).end(); ++it)
	{
		RenderGroup(it->items, it->color, modelNum++);
		RenderGroupCount(it->items.size(), 0);
	}
	glutWarpPointer(g_iWindowWidth/2, g_iWindowHeight/2);
}
Esempio n. 2
0
void World::RenderInstance(SceneInstance *n, mat4 t)
{
	// vars for computing the transform
	mat4 nmatrix(vec4(1,0,0,0),vec4(0,1,0,0),vec4(0,0,1,0),vec4(0,0,0,1));
	
	// get this instance's transform matrix
	n->computeTransform(nmatrix,0);
	
	
	// render the group that this instance is
	RenderGroup(n->getChild(),t*nmatrix); 
}
Esempio n. 3
0
END_TEST

START_TEST ( test_RenderCurve_read_old_style )
{
  // we need to pack the curve in a group because the code to read "old style"
  // curves is in the Group class.
  std::string s = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
                  "<g xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"
                  "  <curve>\n"
                  "    <listOfCurveSegments>\n"
                  "      <curveSegment xsi:type=\"LineSegment\">\n"
                  "        <start x=\"0\" y=\"0\" />\n"
                  "        <end x=\"10\" y=\"3\" />\n"
                  "      </curveSegment>\n"
                  "      <curveSegment xsi:type=\"LineSegment\">\n"
                  "        <start x=\"10\" y=\"3\" />\n"
                  "        <end x=\"0\" y=\"6\" />\n"
                  "      </curveSegment>\n"
                  "    </listOfCurveSegments>\n"
                  "  </curve>\n"
                  "</g>\n"
                ;
      
  XMLInputStream* pStream= new XMLInputStream(s.c_str(),false);
  XMLNode* pNode = new XMLNode(*pStream);

  RenderGroup g = RenderGroup(*pNode);
  fail_unless(g.getNumElements() == 1);
  const Transformation2D* pElement=g.getElement(0);
  fail_unless(pElement != NULL);
  if (pElement == NULL) return;
  fail_unless(pElement->getTypeCode() == SBML_RENDER_CURVE);
  const RenderCurve* pC=dynamic_cast<const RenderCurve*>(pElement);
  fail_unless(!pC->isSetMatrix());
  fail_unless(!pC->isSetStroke());
  fail_unless(!pC->isSetStrokeWidth());
  fail_unless(!pC->isSetDashArray());
  fail_unless(pC->getNumElements() == 3);
  const RenderPoint* pP=pC->getElement(0);
  fail_unless( pP != NULL );
  fail_unless( pP->getTypeCode() == SBML_RENDER_POINT );
  fail_unless( dynamic_cast<const RenderCubicBezier*>(pP) == NULL);
  fail_unless( pP->x().getAbsoluteValue() < 1e-9);
  fail_unless( pP->x().getRelativeValue() < 1e-9);
  fail_unless( pP->y().getAbsoluteValue() < 1e-9);
  fail_unless( pP->y().getRelativeValue() < 1e-9);
  fail_unless( pP->z().getAbsoluteValue() < 1e-9);
  fail_unless( pP->z().getRelativeValue() < 1e-9);
  pP=pC->getElement(1);
  fail_unless( pP != NULL );
  fail_unless( pP->getTypeCode() == SBML_RENDER_POINT );
  fail_unless( dynamic_cast<const RenderCubicBezier*>(pP) == NULL);
  fail_unless( fabs((pP->x().getAbsoluteValue() - 10.0 ) / 10.0) < 1e-9);
  fail_unless( pP->x().getRelativeValue() < 1e-9);
  fail_unless( fabs((pP->y().getAbsoluteValue() - 3.0) / 3.0) < 1e-9);
  fail_unless( pP->y().getRelativeValue() < 1e-9);
  fail_unless( pP->z().getAbsoluteValue() < 1e-9);
  fail_unless( pP->z().getRelativeValue() < 1e-9);
  pP=pC->getElement(2);
  fail_unless( pP != NULL );
  fail_unless( pP->getTypeCode() == SBML_RENDER_POINT );
  fail_unless( dynamic_cast<const RenderCubicBezier*>(pP) == NULL);
  fail_unless( pP->x().getAbsoluteValue() < 1e-9);
  fail_unless( pP->x().getRelativeValue() < 1e-9);
  fail_unless( fabs((pP->y().getAbsoluteValue() - 6.0) / 6.0) < 1e-9);
  fail_unless( pP->y().getRelativeValue() < 1e-9);
  fail_unless( pP->z().getAbsoluteValue() < 1e-9);
  fail_unless( pP->z().getRelativeValue() < 1e-9);
  delete pNode;
  delete pStream;
      
      
  s = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
      "<g xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"
      " <curve xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"
      "    <listOfCurveSegments>\n"
      "      <curveSegment xsi:type=\"CubicBezier\">\n"
      "        <start x=\"2.0\" y=\"7.71428\"/>\n"
      "        <basePoint1 x=\"10.21428\" y=\"12.0\"/>\n"
      "        <basePoint2 x=\"15.21428\" y=\"17.04464\"/>\n"
      "        <end x=\"24.05357\" y=\"15.83928\"/>\n"
      "      </curveSegment>\n"
      "      <curveSegment xsi:type=\"CubicBezier\">\n"
      "        <start x=\"24.05357\" y=\"15.83928\"/>\n"
      "        <basePoint1 x=\"32.89285\" y=\"14.63392\"/>\n"
      "        <basePoint2 x=\"45.57142\" y=\"7.17856\"/>\n"
      "        <end x=\"45.57142\" y=\"7.17856\"/>\n"
      "      </curveSegment>\n"
      "      <curveSegment xsi:type=\"LineSegment\">\n"
      "        <start x=\"45.57142\" y=\"7.17856\"/>\n"
      "        <end x=\"41.46427\" y=\"2.0\"/>\n"
      "      </curveSegment>\n"
      "      <curveSegment xsi:type=\"CubicBezier\">\n"
      "        <start x=\"41.46427\" y=\"2.0\"/>\n"
      "        <basePoint1 x=\"41.46427\" y=\"2.0\"/>\n"
      "        <basePoint2 x=\"31.9107\" y=\"9.14285\"/>\n"
      "        <end x=\"23.42856\" y=\"9.32142\"/>\n"
      "      </curveSegment>\n"
      "      <curveSegment xsi:type=\"CubicBezier\">\n"
      "        <start x=\"23.42856\" y=\"9.32142\"/>\n"
      "        <basePoint1 x=\"14.94642\" y=\"9.49999\"/>\n"
      "        <basePoint2 x=\"7.5357\" y=\"2.71428\"/>\n"
      "        <end x=\"7.5357\" y=\"2.71428\"/>\n"
      "      </curveSegment>\n"
      "      <curveSegment xsi:type=\"LineSegment\">\n"
      "        <start x=\"7.5357\" y=\"2.71428\"/>\n"
      "        <end x=\"2.0\" y=\"7.71428\"/>\n"
      "      </curveSegment>\n"
      "    </listOfCurveSegments>\n"
      "  </curve>\n"
      "</g>\n"
    ;

  pStream= new XMLInputStream(s.c_str(),false);
  pNode = new XMLNode(*pStream);
  
  g = RenderGroup(*pNode);
  fail_unless(g.getNumElements() == 1);
  pElement=g.getElement(0);
  fail_unless(pElement != NULL);
  fail_unless(pElement->getTypeCode() == SBML_RENDER_CURVE);
  pC=dynamic_cast<const RenderCurve*>(pElement);
  fail_unless(!pC->isSetMatrix());
  fail_unless(!pC->isSetStroke());
  fail_unless(!pC->isSetStrokeWidth());
  fail_unless(!pC->isSetDashArray());
  fail_unless(pC->getNumElements() == 7);
  pP=pC->getElement(0);
  fail_unless( pP != NULL );
  fail_unless( pP->getTypeCode() == SBML_RENDER_POINT );
  fail_unless( dynamic_cast<const RenderCubicBezier*>(pP) == NULL);
  fail_unless( fabs((pP->x().getAbsoluteValue() - 2.0) / 2.0) < 1e-9);
  fail_unless( pP->x().getRelativeValue() < 1e-9);
  fail_unless( fabs((pP->y().getAbsoluteValue() - 7.71428) / 7.71428) < 1e-9);
  fail_unless( pP->y().getRelativeValue() < 1e-9);
  fail_unless( pP->z().getAbsoluteValue() < 1e-9);
  fail_unless( pP->z().getRelativeValue() < 1e-9);
  pP=pC->getElement(1);
  fail_unless( pP != NULL );
  fail_unless( pP->getTypeCode() == SBML_RENDER_CUBICBEZIER );
  const RenderCubicBezier* pCB = dynamic_cast<const RenderCubicBezier*>(pP);
  fail_unless( pCB != NULL);
  fail_unless( fabs((pCB->basePoint1_X().getAbsoluteValue() - 10.21428) / 10.21428) < 1e-9);
  fail_unless( pCB->basePoint1_X().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->basePoint1_Y().getAbsoluteValue() - 12.0) / 12.0) < 1e-9);
  fail_unless( pCB->basePoint1_Y().getRelativeValue() < 1e-9);
  fail_unless( pCB->basePoint1_Z().getAbsoluteValue() < 1e-9);
  fail_unless( pCB->basePoint1_Z().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->basePoint2_X().getAbsoluteValue() - 15.21428) / 15.21428) < 1e-9);
  fail_unless( pCB->basePoint2_X().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->basePoint2_Y().getAbsoluteValue() - 17.04464) / 17.04464) < 1e-9);
  fail_unless( pCB->basePoint2_Y().getRelativeValue() < 1e-9);
  fail_unless( pCB->basePoint2_Z().getAbsoluteValue() < 1e-9);
  fail_unless( pCB->basePoint2_Z().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->x().getAbsoluteValue() - 24.05357) / 24.05357) < 1e-9);
  fail_unless( pCB->x().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->y().getAbsoluteValue() - 15.83928) / 15.83928) < 1e-9);
  fail_unless( pCB->y().getRelativeValue() < 1e-9);
  fail_unless( pCB->z().getAbsoluteValue() < 1e-9);
  fail_unless( pCB->z().getRelativeValue() < 1e-9);
  pP=pC->getElement(2);
  fail_unless( pP != NULL );
  fail_unless( pP->getTypeCode() == SBML_RENDER_CUBICBEZIER );
  pCB = dynamic_cast<const RenderCubicBezier*>(pP);
  fail_unless( pCB != NULL);
  fail_unless( fabs((pCB->basePoint1_X().getAbsoluteValue() - 32.89285) / 32.89285) < 1e-9);
  fail_unless( pCB->basePoint1_X().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->basePoint1_Y().getAbsoluteValue() - 14.63392) / 14.63392) < 1e-9);
  fail_unless( pCB->basePoint1_Y().getRelativeValue() < 1e-9);
  fail_unless( pCB->basePoint1_Z().getAbsoluteValue() < 1e-9);
  fail_unless( pCB->basePoint1_Z().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->basePoint2_X().getAbsoluteValue() - 45.57142) / 45.57142) < 1e-9);
  fail_unless( pCB->basePoint2_X().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->basePoint2_Y().getAbsoluteValue() - 7.17856) / 7.17856) < 1e-9);
  fail_unless( pCB->basePoint2_Y().getRelativeValue() < 1e-9);
  fail_unless( pCB->basePoint2_Z().getAbsoluteValue() < 1e-9);
  fail_unless( pCB->basePoint2_Z().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->x().getAbsoluteValue() - 45.57142) / 45.57142) < 1e-9);
  fail_unless( pCB->x().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->y().getAbsoluteValue() - 7.17856) / 7.17856) < 1e-9);
  fail_unless( pCB->y().getRelativeValue() < 1e-9);
  fail_unless( pCB->z().getAbsoluteValue() < 1e-9);
  fail_unless( pCB->z().getRelativeValue() < 1e-9);
  pP=pC->getElement(3);
  fail_unless( pP != NULL );
  fail_unless( pP->getTypeCode() == SBML_RENDER_POINT );
  fail_unless( dynamic_cast<const RenderCubicBezier*>(pP) == NULL);
  fail_unless( fabs((pP->x().getAbsoluteValue() - 41.46427) / 41.46427) < 1e-9);
  fail_unless( pP->x().getRelativeValue() < 1e-9);
  fail_unless( fabs((pP->y().getAbsoluteValue() - 2.0) / 2.0) < 1e-9);
  fail_unless( pP->y().getRelativeValue() < 1e-9);
  fail_unless( pP->z().getAbsoluteValue() < 1e-9);
  fail_unless( pP->z().getRelativeValue() < 1e-9);
  pP=pC->getElement(4);
  fail_unless( pP != NULL );
  fail_unless( pP->getTypeCode() == SBML_RENDER_CUBICBEZIER );
  pCB = dynamic_cast<const RenderCubicBezier*>(pP);
  fail_unless( pCB != NULL);
  fail_unless( fabs((pCB->basePoint1_X().getAbsoluteValue() - 41.46427) / 41.46427) < 1e-9);
  fail_unless( pCB->basePoint1_X().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->basePoint1_Y().getAbsoluteValue() - 2.0) / 2.0) < 1e-9);
  fail_unless( pCB->basePoint1_Y().getRelativeValue() < 1e-9);
  fail_unless( pCB->basePoint1_Z().getAbsoluteValue() < 1e-9);
  fail_unless( pCB->basePoint1_Z().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->basePoint2_X().getAbsoluteValue() - 31.9107) / 31.9107) < 1e-9);
  fail_unless( pCB->basePoint2_X().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->basePoint2_Y().getAbsoluteValue() - 9.14285) / 9.14285) < 1e-9);
  fail_unless( pCB->basePoint2_Y().getRelativeValue() < 1e-9);
  fail_unless( pCB->basePoint2_Z().getAbsoluteValue() < 1e-9);
  fail_unless( pCB->basePoint2_Z().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->x().getAbsoluteValue() - 23.42856) / 23.42856) < 1e-9);
  fail_unless( pCB->x().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->y().getAbsoluteValue() - 9.32142) / 9.32142) < 1e-9);
  fail_unless( pCB->y().getRelativeValue() < 1e-9);
  fail_unless( pCB->z().getAbsoluteValue() < 1e-9);
  fail_unless( pCB->z().getRelativeValue() < 1e-9);
  pP=pC->getElement(5);
  fail_unless( pP != NULL );
  fail_unless( pP->getTypeCode() == SBML_RENDER_CUBICBEZIER );
  pCB = dynamic_cast<const RenderCubicBezier*>(pP);
  fail_unless( pCB != NULL);
  fail_unless( fabs((pCB->basePoint1_X().getAbsoluteValue() - 14.94642) / 14.94642) < 1e-9);
  fail_unless( pCB->basePoint1_X().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->basePoint1_Y().getAbsoluteValue() - 9.49999) / 9.49999) < 1e-9);
  fail_unless( pCB->basePoint1_Y().getRelativeValue() < 1e-9);
  fail_unless( pCB->basePoint1_Z().getAbsoluteValue() < 1e-9);
  fail_unless( pCB->basePoint1_Z().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->basePoint2_X().getAbsoluteValue() - 7.5357) / 7.5357) < 1e-9);
  fail_unless( pCB->basePoint2_X().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->basePoint2_Y().getAbsoluteValue() - 2.71428) / 2.71428) < 1e-9);
  fail_unless( pCB->basePoint2_Y().getRelativeValue() < 1e-9);
  fail_unless( pCB->basePoint2_Z().getAbsoluteValue() < 1e-9);
  fail_unless( pCB->basePoint2_Z().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->x().getAbsoluteValue() - 7.5357) / 7.5357) < 1e-9);
  fail_unless( pCB->x().getRelativeValue() < 1e-9);
  fail_unless( fabs((pCB->y().getAbsoluteValue() - 2.71428) / 2.71428) < 1e-9);
  fail_unless( pCB->y().getRelativeValue() < 1e-9);
  fail_unless( pCB->z().getAbsoluteValue() < 1e-9);
  fail_unless( pCB->z().getRelativeValue() < 1e-9);
  pP=pC->getElement(6);
  fail_unless( pP != NULL );
  fail_unless( pP->getTypeCode() == SBML_RENDER_POINT );
  fail_unless( dynamic_cast<const RenderCubicBezier*>(pP) == NULL);
  fail_unless( fabs((pP->x().getAbsoluteValue() - 2.0) / 2.0) < 1e-9);
  fail_unless( pP->x().getRelativeValue() < 1e-9);
  fail_unless( fabs((pP->y().getAbsoluteValue() - 7.71428) / 7.71428) < 1e-9);
  fail_unless( pP->y().getRelativeValue() < 1e-9);
  fail_unless( pP->z().getAbsoluteValue() < 1e-9);
  fail_unless( pP->z().getRelativeValue() < 1e-9);
  delete pNode;
  delete pStream;
} 
Esempio n. 4
0
/*
 * Creates a new Style object from the given XMLNode object.
 * The XMLNode object has to contain a valid XML representation of a 
 * Style object as defined in the render extension specification.
 * This method is normally called when render information is read from a file and 
 * should normally not have to be called explicitely.
 *
 * @param node the XMLNode object reference that describes the Style
 * object to be instantiated.
 */
Style::Style(const XMLNode& node, unsigned int l2version) :
    SBase(2,l2version), 
    mGroup(2,l2version)
{
    mURI = RenderExtension::getXmlnsL3V1V1();
    
    const XMLNode* child;
    const XMLAttributes& attributes=node.getAttributes();
    ExpectedAttributes ea;
    addExpectedAttributes(ea);
    this->readAttributes(attributes, ea);
    unsigned int n=0,nMax = node.getNumChildren();
    while(n<nMax)
    {
        child=&node.getChild(n);
        const std::string& childName=child->getName();
        if(childName=="g")
        {
            this->mGroup=RenderGroup(*child);
            // set the unset values to the defaults
            if(!this->mGroup.isSetStroke())
            {
                this->mGroup.setStroke("none");
            }
            if(!this->mGroup.isSetStrokeWidth())
            {
                this->mGroup.setStrokeWidth(0.0);
            }
            if(!this->mGroup.isSetDashArray())
            {
                this->mGroup.setDashArray(std::vector<unsigned int>());
            }
            if(!this->mGroup.isSetFillColor())
            {
                this->mGroup.setFillColor("none");
            }
            if(!this->mGroup.isSetFillRule())
            {
                this->mGroup.setFillRule(GraphicalPrimitive2D::NONZERO);
            }
            if(!this->mGroup.isSetFontFamily())
            {
                this->mGroup.setFontFamily("sans-serif");
            }
            if(!this->mGroup.isSetFontSize())
            {
                this->mGroup.setFontSize(0);
            }
            if(!this->mGroup.isSetFontWeight())
            {
                this->mGroup.setFontWeight(Text::WEIGHT_NORMAL);
            }
            if(!this->mGroup.isSetFontStyle())
            {
                this->mGroup.setFontStyle(Text::STYLE_NORMAL);
            }
            if(!this->mGroup.isSetStartHead())
            {
                this->mGroup.setStartHead("none");
            }
            if(!this->mGroup.isSetEndHead())
            {
                this->mGroup.setEndHead("none");
            }
        }
        else if(childName=="annotation")
        {
            this->mAnnotation=new XMLNode(*child);
        }
        else if(childName=="notes")
        {
            this->mNotes=new XMLNode(*child);
        }
        ++n;
    }

    
  setSBMLNamespacesAndOwn(new RenderPkgNamespaces(2,l2version));  

  connectToChild();
}