Exemplo n.º 1
0
void KnotsViewer::draw_curvature_mesh()
{
    if(surfacedata==NULL)
        return;
    if ((surfacedata->get_domain()).empty())
        return;
    Mesh *mesh = surfacedata->get_original_mesh();
    if (mesh==NULL)
        return;
    Mesh::ConstFaceIter        f_it(mesh->faces_begin()),f_end(mesh->faces_end());
    Mesh::ConstFaceVertexIter  fv_it;
    //glLineWidth(0.5);
    for (; f_it!=f_end; ++f_it)
    {

        glBegin(GL_TRIANGLES);
        fv_it = mesh->cfv_iter(*f_it);
        glColor3ubv(mesh->color(*fv_it).data());
        glVertex2dv(&mesh->texcoord2D(fv_it)[0]);
        ++fv_it;
        glColor3ubv(mesh->color(*fv_it).data());
        glVertex2dv(&mesh->texcoord2D(fv_it)[0]);
        ++fv_it;
        glColor3ubv(mesh->color(*fv_it).data());
        glVertex2dv(&mesh->texcoord2D(fv_it)[0]);
        glEnd();
    }



}
Exemplo n.º 2
0
void MakePolygon()
{
    glClear(GL_COLOR_BUFFER_BIT);
    glClearColor(1.0,1.0,1.0,1.0);
    for(int i=0;i<=VertInd;i++)
        MakeDot(ToDraw->LocalSpaceList[i]);
    glColor3dv(ToDraw->Color);
    glBegin(GL_POLYGON);
        for(int i=0;i<=VertInd;i++)
            glVertex2dv(ToDraw->LocalSpaceList[i]);
    glEnd();
    glLineWidth(2.0);
    glColor3d(0.0,0.0,0.0);
    glBegin(GL_LINE_LOOP);
        for(int i=0;i<=VertInd;i++)
            glVertex2dv(ToDraw->LocalSpaceList[i]);
    glEnd();


    MakeDot(0,0);


    no2[0]=(ToDraw->NumVertices-VertInd)/10+'0';
    no2[1]=(ToDraw->NumVertices-VertInd)%10+'0';
    strcpy(hello3,"Vertices Left:   ");
    strcat(hello3,no2);
    text(hello3,-0.22,-0.15,1);
    text(instructions,-0.2,-0.05,0);


    glutSwapBuffers();

}
Exemplo n.º 3
0
int
Impostor::draw_final(CVIEWptr&)
{
   if(_mesh){
     draw_start();
    
     // b-c
     // | | 
     // a-d
     mlib::NDCZpt a, c;
     _mesh->get_bb().ndcz_bounding_box(_mesh->obj_to_ndc(),a,c);
     mlib::NDCZpt b(a[0], c[1], 0);
     mlib::NDCZpt d(c[0], a[1], 0);
 
     
  //   cerr << "final draw impostor " << min_pt << " and " << max_pt << endl;

  //glBegin(GL_QUADS);
  glBegin(GL_LINE_STRIP);   
	      glVertex2dv(a.data());
         glVertex2dv(b.data());
	      glVertex2dv(c.data());
         glVertex2dv(d.data());
         glVertex2dv(a.data());
	glEnd();
    
	 
  draw_end();

   }  
   return 0;

}
Exemplo n.º 4
0
void KnotsViewer::draw_domain_mesh()
{

    if(surfacedata==NULL)
        return;
    if ((surfacedata->get_domain()).empty())
        return;
    Mesh *mesh = surfacedata->get_original_mesh();
    if (mesh==NULL)
        return;
    Mesh::ConstFaceIter        f_it(mesh->faces_begin()),f_end(mesh->faces_end());
    Mesh::ConstFaceVertexIter  fv_it;
    glColor3d(0.4, 0.4, 0.5);
    glLineWidth(0.5);

    for (; f_it!=f_end; ++f_it)
    {
        glBegin(GL_LINE_LOOP);
        fv_it = mesh->cfv_iter(*f_it);
        glVertex2dv(&mesh->texcoord2D(fv_it)[0]);
        ++fv_it;
        glVertex2dv(&mesh->texcoord2D(fv_it)[0]);
        ++fv_it;
        glVertex2dv(&mesh->texcoord2D(fv_it)[0]);
        glEnd();
    }


    //检测每个条形所包含的点
    /*glColor3d(1.0, 0.0, 0.0);
    glPointSize(2);
    vector<int>  h=surfacedata->test;
    glBegin(GL_POINTS);
    for (vector<int>::iterator p=h.begin();p!=h.end();++p)
    {
       Mesh::VertexHandle f=mesh->vertex_handle(*p);
       glVertex2dv(&mesh->texcoord2D(f)[0]);
    }
    glEnd();*/

    //检测每个条形所包含的三角形
    //glColor3d(1.0, 0.0, 0.0);
    //set<int>  h=surfacedata->test2;
    //Mesh::FaceVertexIter  fv_it2;
//  for (set<int>::iterator p=h.begin();p!=h.end();++p)
//  {
    //   Mesh::FaceHandle f_it=mesh->face_handle(*p);
    //   glBegin(GL_TRIANGLES);
    //   fv_it2 = mesh->fv_iter(f_it);
    //   glVertex2dv(&mesh->texcoord2D(fv_it2)[0]);
    //   ++fv_it2;
    //   glVertex2dv(&mesh->texcoord2D(fv_it2)[0]);
    //   ++fv_it2;
    //   glVertex2dv(&mesh->texcoord2D(fv_it2)[0]);
    //   glEnd();
//  }


}
Exemplo n.º 5
0
void Cell::renderCell()
{
	glBegin(GL_QUADS);
	if (color == White) glColor3d(0.8, 0.8, 0.8);
	else glColor3d(0.5, 0.5, 0.5);
	glVertex2dv(coords[0].v());
	glVertex2dv(coords[1].v());
	glVertex2dv(coords[2].v());
	glVertex2dv(coords[3].v());
	glEnd();
}
Exemplo n.º 6
0
void Cell::renderCheck()
{
	glEnable(GL_ALPHA);
	glEnable(GL_BLEND);
	glBegin(GL_QUADS);
	glColor4d(1, 0, 0, 0.5);
	glVertex2dv(coords[0].v());
	glVertex2dv(coords[1].v());
	glVertex2dv(coords[2].v());
	glVertex2dv(coords[3].v());
	glEnd();
	glDisable(GL_BLEND);
	glDisable(GL_ALPHA);
}
Exemplo n.º 7
0
void Board::renderFrame()
{
	glBegin(GL_QUADS);
	for (int i = 0; i < 4; ++i)
	{
		glColor3d(0, 0, 0);
		glVertex2dv(frameCoords[0 + i].v());
		glVertex2dv(frameCoords[(1 + i) % 4].v());
		glColor3d(0.3, 0.3, 0.3);
		glVertex2dv(frameCoords[4 + (1 + i) % 4].v());
		glVertex2dv(frameCoords[4 + i].v());
	}
	glEnd();
}
Exemplo n.º 8
0
void Cell::renderSelected(bool check)
{
	renderCell();
	glBegin(GL_QUADS);
	glColor3d(0.3, 0.3, 0.3);
	for (int i = 0; i < 4; ++i)
	{
		glVertex2dv(coords[0 + i].v());
		glVertex2dv(coords[(1 + i) % 4].v());
		glVertex2dv(coords[4 + (1 + i) % 4].v());
		glVertex2dv(coords[4 + i].v());
	}
	glEnd();
	renderPiece(check);
}
Exemplo n.º 9
0
// I thought about making a lookup table for this, but it would involve an STL map of STL vectors
// and some weird function casts, so I'm doing it the naive way instead.
void GeomRenderer::sendVertex(GLuint vertexIndex)
{
    assert(vertexData.size >= 2 && vertexData.size <= 4);

    switch(vertexData.type)
    {
        case GL_SHORT:
            if (vertexData.size == 2) glVertex2sv((const GLshort*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride));
            if (vertexData.size == 3) glVertex3sv((const GLshort*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride));
            if (vertexData.size == 4) glVertex4sv((const GLshort*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride));
            break;

        case GL_INT:
            if (vertexData.size == 2) glVertex2iv((const GLint*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride));
            if (vertexData.size == 3) glVertex3iv((const GLint*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride));
            if (vertexData.size == 4) glVertex4iv((const GLint*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride));
            break;

        case GL_FLOAT:
            if (vertexData.size == 2) glVertex2fv((const GLfloat*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride));
            if (vertexData.size == 3) glVertex3fv((const GLfloat*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride));
            if (vertexData.size == 4) glVertex4fv((const GLfloat*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride));
            break;

        case GL_DOUBLE:
            if (vertexData.size == 2) glVertex2dv((const GLdouble*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride));
            if (vertexData.size == 3) glVertex3dv((const GLdouble*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride));
            if (vertexData.size == 4) glVertex4dv((const GLdouble*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride));
            break;
    }
}
Exemplo n.º 10
0
static void displayPoint (pScene sc, pMesh mesh, Color *c) {
	unsigned int k;

	glPointSize(5);
	glBegin(GL_POINTS);

	for (k = 1; k <= mesh->np; k++) {
		pPoint ppt;
		unsigned int kk;

		ppt = &mesh->point[k];

		kk = 2 * k + 1;
		glColor4ub((kk & c->rMask) >> c->rShift << c->rBits,
		           (kk & c->gMask) >> c->gShift << c->gBits,
		           (kk & c->bMask) >> c->bShift << c->bBits,
		           (kk & c->aMask) << c->aBits);

		if (mesh->dim == 2)
			glVertex2dv(ppt->c);
		else
			glVertex3dv(ppt->c);
	}

	glEnd();
	glPointSize(1);
}
Exemplo n.º 11
0
void
drawAttractor (void)
{
    int i;

    glClear (GL_COLOR_BUFFER_BIT);
    glMatrixMode (GL_MODELVIEW);
    glLoadIdentity ();
    if (fset.dimension == 2) {
        glColor4f (1.0f, 1.0f, 1.0f, COLOR_ALPHA);
        glRotatef (dset.angle, 0.0, 0.0, 1.0);
    }
    else {
        glColor4f (1.0f, 1.0f, 1.0f, 1.0f);
        glEnable (GL_LIGHTING);
        positionLight ();
        glRotatef (dset.angle, 1.0, 1.0, 1.0);
    }
    glBegin (GL_POINTS);
    for (i = 0; i < at[frontBuffer]->numPoints; i++) {
        if (fset.dimension == 2)
            glVertex2dv (at[frontBuffer]->array[i]);
        else {
            glVertex3dv (at[frontBuffer]->array[i]);
            /* Normal equal to the vector -> vertex redirects light in the same direction */
            glNormal3dv (at[frontBuffer]->array[i]);
        }
    }
    glEnd ();
}
Exemplo n.º 12
0
void Graphics::HandleEventOnDisplay(void)
{
//draw bounding box
    const double *bbox = m_graphics->m_simulator.m_bbox;
    
    glColor3f(0, 0, 1);    
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    glBegin(GL_POLYGON);
    glVertex2d(bbox[0], bbox[1]);
    glVertex2d(bbox[2], bbox[1]);
    glVertex2d(bbox[2], bbox[3]);
    glVertex2d(bbox[0], bbox[3]);
    glEnd();
    
//draw robot, goal, and obstacles
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

    glColor3f(1, 0, 0);
    DrawCircle2D(m_simulator.GetRobotCenterX(), m_simulator.GetRobotCenterY(), m_simulator.GetRobotRadius());
    glColor3f(0, 1, 0);
    DrawCircle2D(m_simulator.GetGoalCenterX(), m_simulator.GetGoalCenterY(), m_simulator.GetGoalRadius());
    glColor3f(0, 0, 1);
    for(int i = 0; i < m_simulator.GetNrObstacles(); ++i)
	DrawCircle2D(m_simulator.GetObstacleCenterX(i),
		     m_simulator.GetObstacleCenterY(i),
		     m_simulator.GetObstacleRadius(i));

//draw planner vertices
    if(m_drawPlannerVertices)
    {
	glPointSize(4.0);
	
	const int n = m_planner->m_vertices.size();
	glColor3f(0.6, 0.8, 0.3);	
	glBegin(GL_POINTS);	
	for(int i = 0; i < n; ++i)
	    glVertex2dv(m_planner->m_vertices[i]->m_state);
	glEnd();
	glBegin(GL_LINES);	
	for(int i = 1; i < n; ++i)
	{
	    glVertex2dv(m_planner->m_vertices[i]->m_state);
	    glVertex2dv(m_planner->m_vertices[m_planner->m_vertices[i]->m_parent]->m_state);
	}
	glEnd();
    }
}
Exemplo n.º 13
0
static void draw(const Svg* svg)
{
    GLenum nextPrimType, primType = GL_LINE_STRIP;
    const SvgLine* lIt;
    uint i;

    DENG_ASSERT_IN_MAIN_THREAD();
    DENG_ASSERT_GL_CONTEXT_ACTIVE();

    lIt = svg->lines;
    for(i = 0; i < svg->lineCount; ++i, lIt++)
    {
        if(lIt->numPoints != 2)
        {
            nextPrimType = SvgLine_IsLoop(lIt)? GL_LINE_LOOP : GL_LINE_STRIP;

            // Do we need to end the current primitive?
            if(primType == GL_LINES)
            {
                glEnd(); // 2-vertex set ends.
            }

            // A new n-vertex primitive begins.
            glBegin(nextPrimType);
        }
        else
        {
            // Do we need to start a new 2-vertex primitive set?
            if(primType != GL_LINES)
            {
                primType = GL_LINES;
                glBegin(GL_LINES);
            }
        }

        // Write the vertex data.
        if(lIt->head)
        {
            const SvgLinePoint* pIt = lIt->head;
            do
            {
                /// @todo Use TexGen?
                glTexCoord2dv((const GLdouble*)pIt->coords.xy);
                glVertex2dv((const GLdouble*)pIt->coords.xy);
            } while(NULL != (pIt = pIt->next) && pIt != lIt->head);
        }

        if(lIt->numPoints != 2)
        {
            glEnd(); // N-vertex primitive ends.
        }
    }

    if(primType == GL_LINES)
    {
        // Close any remaining open 2-vertex set.
        glEnd();
    }
}
Exemplo n.º 14
0
  static void CALLBACK
  tessVertexPath(void* data)
  {
    double * d = reinterpret_cast<double*>(data);
#if 0
    if (tessdbg)
      std::cerr << d[0] << " " << d[1] << " " << data << std::endl;
#endif
    glVertex2dv(d);
  }
Exemplo n.º 15
0
void Cell::renderPiece(bool check)
{
	if (check) renderCheck();
	glEnable(GL_BLEND);
	glEnable(GL_TEXTURE_2D);
	_piece->bindTex();
	glBegin(GL_QUADS);
	glColor3d(1, 1, 1);
	glTexCoord2d(0, 0);
	glVertex2dv(coords[0].v());
	glTexCoord2d(1, 0);
	glVertex2dv(coords[1].v());
	glTexCoord2d(1, 1);
	glVertex2dv(coords[2].v());
	glTexCoord2d(0, 1);
	glVertex2dv(coords[3].v());
	glEnd();
	glDisable(GL_BLEND);
	glDisable(GL_TEXTURE_2D);
}
Exemplo n.º 16
0
void Cell::renderPointed(bool check)
{
	renderCell();
	glBegin(GL_QUADS);
	for (int i = 0; i < 4; ++i)
	{
		if (color == White) glColor3d(0.5, 0.5, 0.5);
		else glColor3d(0.8, 0.8, 0.8);
		glVertex2dv(coords[0 + i].v());
		glVertex2dv(coords[(1 + i) % 4].v());
		if (color == White) glColor3d(0.8, 0.8, 0.8);
		else glColor3d(0.5, 0.5, 0.5);
		glVertex2dv(coords[4 + (1 + i) % 4].v());
		glVertex2dv(coords[4 + i].v());
	}
	glEnd();
	if (!empty())
	{
		renderPiece(check);
	}
}
Exemplo n.º 17
0
void draw_tex_font_char( tex_font_metrics_t *tfm, char c )
{
    tfm_char_data_t *cd;

    cd = find_char_data( tfm, c );

    glBegin( GL_QUADS );
    {
	glTexCoord2dv( (scalar_t*) &cd->tex_ll );
	glVertex2dv(   (scalar_t*) &cd->ll     );
	glTexCoord2dv( (scalar_t*) &cd->tex_lr );
	glVertex2dv(   (scalar_t*) &cd->lr     );
	glTexCoord2dv( (scalar_t*) &cd->tex_ur );
	glVertex2dv(   (scalar_t*) &cd->ur     );
	glTexCoord2dv( (scalar_t*) &cd->tex_ul );
	glVertex2dv(   (scalar_t*) &cd->ul     );
    }
    glEnd();

    glTranslatef( cd->kern_width, 0., 0. );
}
Exemplo n.º 18
0
Arquivo: g_render.c Projeto: aosm/X11
void __glXDisp_Vertex2dv(GLbyte *pc)
{

#ifdef __GLX_ALIGN64
	if ((unsigned long)(pc) & 7) {
	    __GLX_MEM_COPY(pc-4, pc, 16);
	    pc -= 4;
	}
#endif
	glVertex2dv( 
		(GLdouble *)(pc + 0)
	);
}
Exemplo n.º 19
0
void button::Render()
    {
        glColor3d(PresFlag,0.0,0.0);
        glLineWidth(2.0);
        glBegin(GL_LINE_LOOP);
            glVertex2dv(position);
            glVertex2d(position[0]+dimention[0],position[1]);
            glVertex2d(position[0]+dimention[0],position[1]+dimention[1]);
            glVertex2d(position[0],position[1]+dimention[1]);
        glEnd();
        text(ch,position[0]+0.01,position[1]+dimention[1]-0.02,0);

        glRasterPos2f(position[0]+0.02,position[1]+0.01);
        glBitmap(16, 15, 0, 0, 0.0, 0.0, pic);


    }
Exemplo n.º 20
0
void SeedGLWidget::drawPenTrack()
{
	glViewport(0, 0, _widgetWidth-_planeWidth, _widgetHeight);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(0, _widgetWidth-_planeWidth, _widgetHeight, 0);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	glDisable(GL_DEPTH_TEST);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	if (_bAddRegion)
	{

		glColor4ub(_currentSeedColor[0], _currentSeedColor[1], _currentSeedColor[2], 128);

		gluTessBeginPolygon(tessObj, NULL);
		gluTessBeginContour(tessObj);
		for (int i=0; i<_penTrack.size(); ++i)
		{
			gluTessVertex(tessObj, _penTrack[i], _penTrack[i]);
		}
		gluTessEndContour(tessObj);
		gluTessEndPolygon(tessObj);

		glColor4ub(_currentSeedColor[0], _currentSeedColor[1], _currentSeedColor[2], 255);
	} else
	{
		glColor3f(1, 1, 1);
	}

	glEnable(GL_LINE_STIPPLE);
	glLineStipple(1, 0xF0F0); 
	glLineWidth(3);
	glBegin(GL_LINE_STRIP);
	for (int i=0; i<_penTrack.size(); ++i)
	{
		glVertex2dv(_penTrack[i]);
	}
	glEnd();

	glDisable(GL_LINE_STIPPLE);
	glEnable(GL_DEPTH_TEST);
	glDisable(GL_BLEND);
}
void mitk::ContourModelSetGLMapper2D::InternalDrawContour(mitk::ContourModel *renderingContour,
                                                          mitk::BaseRenderer *renderer)
{
  if (!renderingContour)
    return;

  mitk::DataNode *dataNode = this->GetDataNode();

  renderingContour->UpdateOutputInformation();

  unsigned int timestep = renderer->GetTimeStep();

  if (!renderingContour->IsEmptyTimeStep(timestep))
  {
    // apply color and opacity read from the PropertyList
    ApplyColorAndOpacityProperties(renderer);

    mitk::ColorProperty::Pointer colorprop =
      dynamic_cast<mitk::ColorProperty *>(dataNode->GetProperty("contour.color", renderer));
    float opacity = 0.5;
    dataNode->GetFloatProperty("opacity", opacity, renderer);

    if (colorprop)
    {
      // set the color of the contour
      double red = colorprop->GetColor().GetRed();
      double green = colorprop->GetColor().GetGreen();
      double blue = colorprop->GetColor().GetBlue();
      glColor4f(red, green, blue, opacity);
    }

    mitk::ColorProperty::Pointer selectedcolor =
      dynamic_cast<mitk::ColorProperty *>(dataNode->GetProperty("contour.points.color", renderer));
    if (!selectedcolor)
    {
      selectedcolor = mitk::ColorProperty::New(1.0, 0.0, 0.1);
    }

    vtkLinearTransform *transform = dataNode->GetVtkTransform();

    //    ContourModel::OutputType point;
    mitk::Point3D point;

    mitk::Point3D p;
    float vtkp[3];
    float lineWidth = 3.0;

    bool drawit = false;

    bool isHovering = false;
    dataNode->GetBoolProperty("contour.hovering", isHovering);

    if (isHovering)
      dataNode->GetFloatProperty("contour.hovering.width", lineWidth);
    else
      dataNode->GetFloatProperty("contour.width", lineWidth);

    bool showSegments = false;
    dataNode->GetBoolProperty("contour.segments.show", showSegments);

    bool showControlPoints = false;
    dataNode->GetBoolProperty("contour.controlpoints.show", showControlPoints);

    bool showPoints = false;
    dataNode->GetBoolProperty("contour.points.show", showPoints);

    bool showPointsNumbers = false;
    dataNode->GetBoolProperty("contour.points.text", showPointsNumbers);

    bool showControlPointsNumbers = false;
    dataNode->GetBoolProperty("contour.controlpoints.text", showControlPointsNumbers);

    bool projectmode = false;
    dataNode->GetVisibility(projectmode, renderer, "contour.project-onto-plane");

    mitk::ContourModel::VertexIterator pointsIt = renderingContour->IteratorBegin(timestep);

    Point2D pt2d; // projected_p in display coordinates
    Point2D lastPt2d;

    int index = 0;

    mitk::ScalarType maxDiff = 0.25;

    while (pointsIt != renderingContour->IteratorEnd(timestep))
    {
      lastPt2d = pt2d;

      point = (*pointsIt)->Coordinates;

      itk2vtk(point, vtkp);
      transform->TransformPoint(vtkp, vtkp);
      vtk2itk(vtkp, p);

      renderer->WorldToDisplay(p, pt2d);

      ScalarType scalardiff = fabs(renderer->GetCurrentWorldPlaneGeometry()->SignedDistance(p));

      // project to plane
      if (projectmode)
      {
        drawit = true;
      }
      else if (scalardiff < maxDiff) // point is close enough to be drawn
      {
        drawit = true;
      }
      else
      {
        drawit = false;
      }

      // draw line
      if (drawit)
      {
        if (showSegments)
        {
          // lastPt2d is not valid in first step
          if (!(pointsIt == renderingContour->IteratorBegin(timestep)))
          {
            glLineWidth(lineWidth);
            glBegin(GL_LINES);
            glVertex2f(pt2d[0], pt2d[1]);
            glVertex2f(lastPt2d[0], lastPt2d[1]);
            glEnd();
            glLineWidth(1);
          }
        }

        if (showControlPoints)
        {
          // draw ontrol points
          if ((*pointsIt)->IsControlPoint)
          {
            float pointsize = 4;
            Point2D tmp;

            Vector2D horz, vert;
            horz[1] = 0;
            vert[0] = 0;
            horz[0] = pointsize;
            vert[1] = pointsize;
            glColor3f(selectedcolor->GetColor().GetRed(),
                      selectedcolor->GetColor().GetBlue(),
                      selectedcolor->GetColor().GetGreen());
            glLineWidth(1);
            // a rectangle around the point with the selected color
            glBegin(GL_LINE_LOOP);
            tmp = pt2d - horz;
            glVertex2dv(&tmp[0]);
            tmp = pt2d + vert;
            glVertex2dv(&tmp[0]);
            tmp = pt2d + horz;
            glVertex2dv(&tmp[0]);
            tmp = pt2d - vert;
            glVertex2dv(&tmp[0]);
            glEnd();
            glLineWidth(1);
            // the actual point in the specified color to see the usual color of the point
            glColor3f(
              colorprop->GetColor().GetRed(), colorprop->GetColor().GetGreen(), colorprop->GetColor().GetBlue());
            glPointSize(1);
            glBegin(GL_POINTS);
            tmp = pt2d;
            glVertex2dv(&tmp[0]);
            glEnd();
          }
        }

        if (showPoints)
        {
          float pointsize = 3;
          Point2D tmp;

          Vector2D horz, vert;
          horz[1] = 0;
          vert[0] = 0;
          horz[0] = pointsize;
          vert[1] = pointsize;
          glColor3f(0.0, 0.0, 0.0);
          glLineWidth(1);
          // a rectangle around the point with the selected color
          glBegin(GL_LINE_LOOP);
          tmp = pt2d - horz;
          glVertex2dv(&tmp[0]);
          tmp = pt2d + vert;
          glVertex2dv(&tmp[0]);
          tmp = pt2d + horz;
          glVertex2dv(&tmp[0]);
          tmp = pt2d - vert;
          glVertex2dv(&tmp[0]);
          glEnd();
          glLineWidth(1);
          // the actual point in the specified color to see the usual color of the point
          glColor3f(colorprop->GetColor().GetRed(), colorprop->GetColor().GetGreen(), colorprop->GetColor().GetBlue());
          glPointSize(1);
          glBegin(GL_POINTS);
          tmp = pt2d;
          glVertex2dv(&tmp[0]);
          glEnd();
        }

        if (showPointsNumbers)
        {
          std::string l;
          std::stringstream ss;
          ss << index;
          l.append(ss.str());

          float rgb[3];
          rgb[0] = 0.0;
          rgb[1] = 0.0;
          rgb[2] = 0.0;

          WriteTextWithAnnotation(m_PointNumbersAnnotation, l.c_str(), rgb, pt2d, renderer);
        }

        if (showControlPointsNumbers && (*pointsIt)->IsControlPoint)
        {
          std::string l;
          std::stringstream ss;
          ss << index;
          l.append(ss.str());

          float rgb[3];
          rgb[0] = 1.0;
          rgb[1] = 1.0;
          rgb[2] = 0.0;

          WriteTextWithAnnotation(m_ControlPointNumbersAnnotation, l.c_str(), rgb, pt2d, renderer);
        }

        index++;
      }

      pointsIt++;
    } // end while iterate over controlpoints

    // close contour if necessary
    if (renderingContour->IsClosed(timestep) && drawit && showSegments)
    {
      lastPt2d = pt2d;
      point = renderingContour->GetVertexAt(0, timestep)->Coordinates;
      itk2vtk(point, vtkp);
      transform->TransformPoint(vtkp, vtkp);
      vtk2itk(vtkp, p);
      renderer->WorldToDisplay(p, pt2d);

      glLineWidth(lineWidth);
      glBegin(GL_LINES);
      glVertex2f(lastPt2d[0], lastPt2d[1]);
      glVertex2f(pt2d[0], pt2d[1]);
      glEnd();
      glLineWidth(1);
    }

    // draw selected vertex if exists
    if (renderingContour->GetSelectedVertex())
    {
      // transform selected vertex
      point = renderingContour->GetSelectedVertex()->Coordinates;

      itk2vtk(point, vtkp);
      transform->TransformPoint(vtkp, vtkp);
      vtk2itk(vtkp, p);

      renderer->WorldToDisplay(p, pt2d);

      ScalarType scalardiff = fabs(renderer->GetCurrentWorldPlaneGeometry()->SignedDistance(p));
      //----------------------------------

      // draw point if close to plane
      if (scalardiff < maxDiff)
      {
        float pointsize = 5;
        Point2D tmp;
        glColor3f(0.0, 1.0, 0.0);
        glLineWidth(1);
        // a diamond around the point
        glBegin(GL_LINE_LOOP);
        // begin from upper left corner and paint clockwise
        tmp[0] = pt2d[0] - pointsize;
        tmp[1] = pt2d[1] + pointsize;
        glVertex2dv(&tmp[0]);
        tmp[0] = pt2d[0] + pointsize;
        tmp[1] = pt2d[1] + pointsize;
        glVertex2dv(&tmp[0]);
        tmp[0] = pt2d[0] + pointsize;
        tmp[1] = pt2d[1] - pointsize;
        glVertex2dv(&tmp[0]);
        tmp[0] = pt2d[0] - pointsize;
        tmp[1] = pt2d[1] - pointsize;
        glVertex2dv(&tmp[0]);
        glEnd();
      }
      //------------------------------------
    }
  }
}
Exemplo n.º 22
0
void mitk::MeshMapper2D::Paint(mitk::BaseRenderer *renderer)
{
  bool visible = true;

  GetDataNode()->GetVisibility(visible, renderer, "visible");

  if (!visible)
    return;

  //  @FIXME: Logik fuer update
  bool updateNeccesary = true;

  if (updateNeccesary)
  {
    // aus GenerateData
    mitk::Mesh::Pointer input = const_cast<mitk::Mesh *>(this->GetInput());

    // Get the TimeGeometry of the input object
    const TimeGeometry *inputTimeGeometry = input->GetTimeGeometry();
    if ((inputTimeGeometry == NULL) || (inputTimeGeometry->CountTimeSteps() == 0))
    {
      return;
    }

    //
    // get the world time
    //
    ScalarType time = renderer->GetTime();

    //
    // convert the world time in time steps of the input object
    //
    int timeStep = 0;
    if (time > itk::NumericTraits<mitk::ScalarType>::NonpositiveMin())
      timeStep = inputTimeGeometry->TimePointToTimeStep(time);
    if (inputTimeGeometry->IsValidTimeStep(timeStep) == false)
    {
      return;
    }

    mitk::Mesh::MeshType::Pointer itkMesh = input->GetMesh(timeStep);

    if (itkMesh.GetPointer() == NULL)
    {
      return;
    }

    const PlaneGeometry *worldplanegeometry = (renderer->GetCurrentWorldPlaneGeometry());

    // apply color and opacity read from the PropertyList
    ApplyColorAndOpacityProperties(renderer);

    vtkLinearTransform *transform = GetDataNode()->GetVtkTransform();

    // List of the Points
    Mesh::DataType::PointsContainerConstIterator it, end;
    it = itkMesh->GetPoints()->Begin();
    end = itkMesh->GetPoints()->End();

    // iterator on the additional data of each point
    Mesh::PointDataIterator dataIt; //, dataEnd;
    dataIt = itkMesh->GetPointData()->Begin();

    // for switching back to old color after using selected color
    float unselectedColor[4];
    glGetFloatv(GL_CURRENT_COLOR, unselectedColor);

    while (it != end)
    {
      mitk::Point3D p, projected_p;
      float vtkp[3];

      itk2vtk(it->Value(), vtkp);
      transform->TransformPoint(vtkp, vtkp);
      vtk2itk(vtkp, p);

      renderer->GetCurrentWorldPlaneGeometry()->Project(p, projected_p);
      Vector3D diff = p - projected_p;
      if (diff.GetSquaredNorm() < 4.0)
      {
        Point2D pt2d, tmp;
        renderer->WorldToDisplay(p, pt2d);

        Vector2D horz, vert;
        horz[0] = 5;
        horz[1] = 0;
        vert[0] = 0;
        vert[1] = 5;

        // check if the point is to be marked as selected
        if (dataIt->Value().selected)
        {
          horz[0] = 8;
          vert[1] = 8;
          glColor3f(selectedColor[0], selectedColor[1], selectedColor[2]); // red

          switch (dataIt->Value().pointSpec)
          {
            case PTSTART:
            {
              // a quad
              glBegin(GL_LINE_LOOP);
              tmp = pt2d - horz + vert;
              glVertex2dv(&tmp[0]);
              tmp = pt2d + horz + vert;
              glVertex2dv(&tmp[0]);
              tmp = pt2d + horz - vert;
              glVertex2dv(&tmp[0]);
              tmp = pt2d - horz - vert;
              glVertex2dv(&tmp[0]);
              glEnd();
            }
            break;
            case PTUNDEFINED:
            {
              // a diamond around the point
              glBegin(GL_LINE_LOOP);
              tmp = pt2d - horz;
              glVertex2dv(&tmp[0]);
              tmp = pt2d + vert;
              glVertex2dv(&tmp[0]);
              tmp = pt2d + horz;
              glVertex2dv(&tmp[0]);
              tmp = pt2d - vert;
              glVertex2dv(&tmp[0]);
              glEnd();
            }
            break;
            default:
              break;
          } // switch

          // the actual point
          glBegin(GL_POINTS);
          tmp = pt2d;
          glVertex2dv(&tmp[0]);
          glEnd();
        }
        else // if not selected
        {
          glColor3f(unselectedColor[0], unselectedColor[1], unselectedColor[2]);
          switch (dataIt->Value().pointSpec)
          {
            case PTSTART:
            {
              // a quad
              glBegin(GL_LINE_LOOP);
              tmp = pt2d - horz + vert;
              glVertex2dv(&tmp[0]);
              tmp = pt2d + horz + vert;
              glVertex2dv(&tmp[0]);
              tmp = pt2d + horz - vert;
              glVertex2dv(&tmp[0]);
              tmp = pt2d - horz - vert;
              glVertex2dv(&tmp[0]);
              glEnd();
            }
            case PTUNDEFINED:
            {
              // drawing crosses
              glBegin(GL_LINES);
              tmp = pt2d - horz;
              glVertex2dv(&tmp[0]);
              tmp = pt2d + horz;
              glVertex2dv(&tmp[0]);
              tmp = pt2d - vert;
              glVertex2dv(&tmp[0]);
              tmp = pt2d + vert;
              glVertex2dv(&tmp[0]);
              glEnd();
            }
            default:
            {
              break;
            }
          } // switch
        }   // else
      }
      ++it;
      ++dataIt;
    }

    // now connect the lines inbetween
    mitk::Mesh::PointType thisPoint;
    thisPoint.Fill(0);
    Point2D *firstOfCell = NULL;
    Point2D *lastPoint = NULL;
    unsigned int lastPointId = 0;
    bool lineSelected = false;

    Point3D firstOfCell3D;
    Point3D lastPoint3D;
    bool first;
    mitk::Line<mitk::ScalarType> line;
    std::vector<mitk::Point3D> intersectionPoints;
    double t;

    // iterate through all cells and then iterate through all indexes of points in that cell
    Mesh::CellIterator cellIt, cellEnd;
    Mesh::CellDataIterator cellDataIt; //, cellDataEnd;
    Mesh::PointIdIterator cellIdIt, cellIdEnd;

    cellIt = itkMesh->GetCells()->Begin();
    cellEnd = itkMesh->GetCells()->End();
    cellDataIt = itkMesh->GetCellData()->Begin();

    while (cellIt != cellEnd)
    {
      unsigned int numOfPointsInCell = cellIt->Value()->GetNumberOfPoints();
      if (numOfPointsInCell > 1)
      {
        // iterate through all id's in the cell
        cellIdIt = cellIt->Value()->PointIdsBegin();
        cellIdEnd = cellIt->Value()->PointIdsEnd();

        firstOfCell3D = input->GetPoint(*cellIdIt, timeStep);

        intersectionPoints.clear();
        intersectionPoints.reserve(numOfPointsInCell);

        first = true;

        while (cellIdIt != cellIdEnd)
        {
          lastPoint3D = thisPoint;

          thisPoint = input->GetPoint(*cellIdIt, timeStep);

          // search in data (vector<> selectedLines) if the index of the point is set. if so, then the line is selected.
          lineSelected = false;
          Mesh::SelectedLinesType selectedLines = cellDataIt->Value().selectedLines;

          // a line between 1(lastPoint) and 2(pt2d) has the Id 1, so look for the Id of lastPoint
          // since we only start, if we have more than one point in the cell, lastPointId is initiated with 0
          Mesh::SelectedLinesIter position = std::find(selectedLines.begin(), selectedLines.end(), lastPointId);
          if (position != selectedLines.end())
          {
            lineSelected = true;
          }

          mitk::Point3D p, projected_p;
          float vtkp[3];
          itk2vtk(thisPoint, vtkp);
          transform->TransformPoint(vtkp, vtkp);
          vtk2itk(vtkp, p);
          renderer->GetCurrentWorldPlaneGeometry()->Project(p, projected_p);
          Vector3D diff = p - projected_p;
          if (diff.GetSquaredNorm() < 4.0)
          {
            Point2D pt2d, tmp;
            renderer->WorldToDisplay(p, pt2d);

            if (lastPoint == NULL)
            {
              // set the first point in the cell. This point in needed to close the polygon
              firstOfCell = new Point2D;
              *firstOfCell = pt2d;
              lastPoint = new Point2D;
              *lastPoint = pt2d;
              lastPointId = *cellIdIt;
            }
            else
            {
              if (lineSelected)
              {
                glColor3f(selectedColor[0], selectedColor[1], selectedColor[2]); // red
                // a line from lastPoint to thisPoint
                glBegin(GL_LINES);
                glVertex2dv(&(*lastPoint)[0]);
                glVertex2dv(&pt2d[0]);
                glEnd();
              }
              else // if not selected
              {
                glColor3f(unselectedColor[0], unselectedColor[1], unselectedColor[2]);
                // drawing crosses
                glBegin(GL_LINES);
                glVertex2dv(&(*lastPoint)[0]);
                glVertex2dv(&pt2d[0]);
                glEnd();
              }
              // to draw the line to the next in iteration step
              *lastPoint = pt2d;
              // and to search for the selection state of the line
              lastPointId = *cellIdIt;
            } // if..else
          }   // if <4.0

          // fill off-plane polygon part 1
          if ((!first) && (worldplanegeometry != NULL))
          {
            line.SetPoints(lastPoint3D, thisPoint);
            if (worldplanegeometry->IntersectionPointParam(line, t) && ((t >= 0) && (t <= 1)))
            {
              intersectionPoints.push_back(line.GetPoint(t));
            }
          }
          ++cellIdIt;
          first = false;
        } // while cellIdIter

        // closed polygon?
        if (cellDataIt->Value().closed)
        {
          // close the polygon if needed
          if (firstOfCell != NULL)
          {
            lineSelected = false;
            Mesh::SelectedLinesType selectedLines = cellDataIt->Value().selectedLines;
            Mesh::SelectedLinesIter position = std::find(selectedLines.begin(), selectedLines.end(), lastPointId);
            if (position != selectedLines.end()) // found the index
            {
              glColor3f(selectedColor[0], selectedColor[1], selectedColor[2]); // red
              // a line from lastPoint to firstPoint
              glBegin(GL_LINES);
              glVertex2dv(&(*lastPoint)[0]);
              glVertex2dv(&(*firstOfCell)[0]);
              glEnd();
            }
            else
            {
              glColor3f(unselectedColor[0], unselectedColor[1], unselectedColor[2]);
              glBegin(GL_LINES);
              glVertex2dv(&(*lastPoint)[0]);
              glVertex2dv(&(*firstOfCell)[0]);
              glEnd();
            }
          }
        } // if closed

        // Axis-aligned bounding box(AABB) around the cell if selected and set in Property
        bool showBoundingBox;
        if (dynamic_cast<mitk::BoolProperty *>(this->GetDataNode()->GetProperty("showBoundingBox")) == NULL)
          showBoundingBox = false;
        else
          showBoundingBox =
            dynamic_cast<mitk::BoolProperty *>(this->GetDataNode()->GetProperty("showBoundingBox"))->GetValue();

        if (showBoundingBox)
        {
          if (cellDataIt->Value().selected)
          {
            mitk::Mesh::DataType::BoundingBoxPointer aABB = input->GetBoundingBoxFromCell(cellIt->Index());
            if (aABB.IsNotNull())
            {
              mitk::Mesh::PointType min, max;
              min = aABB->GetMinimum();
              max = aABB->GetMaximum();

              // project to the displayed geometry
              Point2D min2D, max2D;
              Point3D p, projected_p;
              float vtkp[3];
              itk2vtk(min, vtkp);
              transform->TransformPoint(vtkp, vtkp);
              vtk2itk(vtkp, p);
              renderer->WorldToDisplay(p, min2D);

              itk2vtk(max, vtkp);
              transform->TransformPoint(vtkp, vtkp);
              vtk2itk(vtkp, p);
              renderer->GetCurrentWorldPlaneGeometry()->Project(p, projected_p);
              Vector3D diff = p - projected_p;
              if (diff.GetSquaredNorm() < 4.0)
              {
                renderer->WorldToDisplay(p, max2D);

                // draw the BoundingBox
                glColor3f(selectedColor[0], selectedColor[1], selectedColor[2]); // red
                // a line from lastPoint to firstPoint
                glBegin(GL_LINE_LOOP);
                glVertex2f(min2D[0], min2D[1]);
                glVertex2f(min2D[0], max2D[1]);
                glVertex2f(max2D[0], max2D[1]);
                glVertex2f(max2D[0], min2D[1]);
                glEnd();
              } // draw bounding-box
            }   // bounding-box exists
          }     // cell selected
        }       // show bounding-box

        // fill off-plane polygon part 2
        if (worldplanegeometry != NULL)
        {
          // consider line from last to first
          line.SetPoints(thisPoint, firstOfCell3D);
          if (worldplanegeometry->IntersectionPointParam(line, t) && ((t >= 0) && (t <= 1)))
          {
            intersectionPoints.push_back(line.GetPoint(t));
          }
          std::sort(intersectionPoints.begin(), intersectionPoints.end(), point3DSmaller);
          std::vector<mitk::Point3D>::iterator it, end;
          end = intersectionPoints.end();
          if ((intersectionPoints.size() % 2) != 0)
          {
            --end; // ensure even number of intersection-points
          }
          Point2D pt2d;
          for (it = intersectionPoints.begin(); it != end; ++it)
          {
            glBegin(GL_LINES);
            renderer->WorldToDisplay(*it, pt2d);
            glVertex2dv(pt2d.GetDataPointer());
            ++it;
            renderer->WorldToDisplay(*it, pt2d);
            glVertex2dv(pt2d.GetDataPointer());
            glEnd();
          }
          if (it != intersectionPoints.end())
          {
            glBegin(GL_LINES);
            renderer->WorldToDisplay(*it, pt2d);
            glVertex2dv(pt2d.GetDataPointer());
            glVertex2dv(pt2d.GetDataPointer());
            glEnd();
          }
        } // fill off-plane polygon part 2
      }   // if numOfPointsInCell>1
      delete firstOfCell;
      delete lastPoint;
      lastPoint = NULL;
      firstOfCell = NULL;
      lastPointId = 0;
      ++cellIt;
      ++cellDataIt;
    }
  }
}
void RocketStatusPanel::Render()
{
    //
    // Determine our rocket status

    EscapeRocket *rocket = GetMyRocket();
    if( !rocket ) return;

    Team *team = g_app->m_location->m_teams[ m_teamId ];
    if( !team ) return;

    float fuelPercent = rocket->m_fuel / 100.0f;
    int darwiniansInside = rocket->m_passengers;

    if( rocket->m_damage > m_lastDamage )
    {
        m_damageTimer = GetHighResTime();
    }
    m_lastDamage = rocket->m_damage;

    if( fuelPercent > 1.0f ) fuelPercent = 1.0f;

    double refuelRate = rocket->m_fuel - m_previousFuelLevel;
    m_previousFuelLevel = rocket->m_fuel;

    float h = m_w * 1.5f;
    glShadeModel( GL_SMOOTH );


    //
    // Background team colour

    glColor4ub( team->m_colour.r*0.2f, team->m_colour.g*0.2f, team->m_colour.b*0.2f, 200 );

    glBegin( GL_QUADS );
        glVertex2f( m_x, m_y );
        glVertex2f( m_x + m_w, m_y );
        glVertex2f( m_x + m_w, m_y + h );
        glVertex2f( m_x, m_y + h );
    glEnd();


    //
    // Refueling effect

    float fuelBase = m_y + h * 0.97f;
    float fuelFullH = h * 0.95f;
    float fuelH = fuelFullH * fuelPercent;
    int refuelAlpha = 128;

    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

    glEnable        ( GL_TEXTURE_2D );
    glBindTexture   ( GL_TEXTURE_2D, g_app->m_resource->GetTexture( "textures/laser.bmp" ) );
    glTexParameterf ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
    glTexParameterf ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    glTexParameterf ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
    glTexParameterf ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );


    if( fuelPercent < 1.0f )
    {
        glColor4ub( team->m_colour.r, team->m_colour.g, team->m_colour.b, refuelAlpha );

        float texY = fuelPercent * -100 + 0.5f;
        float texH = 1.0f;

        glBegin( GL_QUADS );
            glTexCoord2f(0,texY);       glVertex2f( m_x, fuelBase );
            glTexCoord2f(1,texY);       glVertex2f( m_x + m_w, fuelBase );
            glTexCoord2f(1,texY+texH);  glVertex2f( m_x + m_w, fuelBase - fuelFullH );
            glTexCoord2f(0,texY+texH);  glVertex2f( m_x, fuelBase - fuelFullH );
        glEnd();

    }


    //
    // Fuel level

    glBindTexture   ( GL_TEXTURE_2D, g_app->m_resource->GetTexture( "textures/laser-long.bmp" ) );
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
    int fuelAlpha = 200;

    glBegin( GL_QUADS );
        glColor4ub( 0,0,0, fuelAlpha );
        glTexCoord2f( 0, 0.3f );       glVertex2f( m_x, fuelBase );
        glTexCoord2f( 0, 0.7f );       glVertex2f( m_x + m_w, fuelBase );
        
        glColor4ub( team->m_colour.r, team->m_colour.g, team->m_colour.b, fuelAlpha );
        glTexCoord2f( 1, 0.7f );       glVertex2f( m_x + m_w, fuelBase - fuelH );
        glTexCoord2f( 1, 0.3f );       glVertex2f( m_x, fuelBase - fuelH );
    glEnd();

    glDisable( GL_TEXTURE_2D );


    //
    // Shadow above fuel level

    glBegin( GL_QUADS );
        glColor4ub( 0,0,0, fuelAlpha*0.5f );
        glVertex2f( m_x, fuelBase - fuelH );
        glVertex2f( m_x + m_w, fuelBase - fuelH );
        glColor4ub( 0,0,0, 0 );
        glVertex2f( m_x + m_w, fuelBase - fuelH - h * 0.05f );
        glVertex2f( m_x, fuelBase - fuelH - 10 - h * 0.05f );
    glEnd();


    //
    // Rocket bitmap overlay

    glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );

    glBlendFunc     ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
    glEnable        ( GL_TEXTURE_2D );
    glBindTexture   ( GL_TEXTURE_2D, g_app->m_resource->GetTexture( "icons/rocketstatuspanel.bmp" ) );
    
    glBegin( GL_QUADS );
        glTexCoord2i(0,1);      glVertex2f( m_x, m_y );
        glTexCoord2i(1,1);      glVertex2f( m_x + m_w, m_y );
        glTexCoord2i(1,0);      glVertex2f( m_x + m_w, m_y + h );
        glTexCoord2i(0,0);      glVertex2f( m_x, m_y + h );
    glEnd();
    
    glDisable       ( GL_TEXTURE_2D );



    //
    // Damage effect

    glColor4f( 1.0f, 1.0f, 1.0f, rocket->m_damage/100.0f );

    glBlendFunc     ( GL_SRC_ALPHA, GL_ONE );
    glEnable        ( GL_TEXTURE_2D );
    glBindTexture   ( GL_TEXTURE_2D, g_app->m_resource->GetTexture( "icons/rocketcracked.bmp" ) );

    glBegin( GL_QUADS );
    glTexCoord2i(0,1);      glVertex2f( m_x, m_y );
    glTexCoord2i(1,1);      glVertex2f( m_x + m_w, m_y );
    glTexCoord2i(1,0);      glVertex2f( m_x + m_w, m_y + h );
    glTexCoord2i(0,0);      glVertex2f( m_x, m_y + h );
    glEnd();

    glDisable       ( GL_TEXTURE_2D );



    //
    // Darwinians inside
    
    glBlendFunc     ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

    if( fuelPercent >= 1.0f || darwiniansInside > 0 )
    {
        float dwX = m_x + m_w * 0.25f;
        float dwW = m_w * 0.45f;
        float dwY = m_y + h * 0.225f;
        float dwH = h * 0.55f;
        float s = h * 0.04f;
        int astronautAlpha = 255;

        glEnable        ( GL_TEXTURE_2D );
        glBindTexture   ( GL_TEXTURE_2D, g_app->m_resource->GetTexture( "sprites/darwinian.bmp" ) );

        for( int i = 99; i >= 0; i-- )
        {
            int xIndex = ( i % 10 );
            int yIndex = 9 - int( i / 10 );
            float xPos = dwX + dwW * xIndex/10;
            float yPos = dwY + dwH * yIndex/10;

            if( yIndex % 2 == 0 ) xPos += dwW/20.0f;

            RGBAColour astronautCol = team->m_colour;
            astronautCol.AddWithClamp( RGBAColour(50,50,50,255) );
            astronautCol.a = astronautAlpha;

            if( i <  darwiniansInside )     glColor4ub( team->m_colour.r, team->m_colour.g, team->m_colour.b, astronautAlpha );
            else                            glColor4ub( team->m_colour.r*0.3f, team->m_colour.g*0.3f, team->m_colour.b*0.3f, astronautAlpha*0.2f );

            Vector3 pos( xPos+s/2.0f, yPos+s/2.0f, 0 );
            pos.x += sinf(i + GetHighResTime()) * 1.0f;
            pos.y += cosf(i + i + GetHighResTime()) * 1.0f;

            Vector3 offset( -s/2.0f, -s, 0 );
            
            glBegin( GL_QUADS );
                glTexCoord2f(0,1);      glVertex2dv( (pos+offset).GetData() );      offset.RotateAroundZ(0.5f * M_PI);
                glTexCoord2f(1,1);      glVertex2dv( (pos+offset).GetData() );      offset.RotateAroundZ(0.5f * M_PI);
                glTexCoord2f(1,0);      glVertex2dv( (pos+offset).GetData() );      offset.RotateAroundZ(0.5f * M_PI);
                glTexCoord2f(0,0);      glVertex2dv( (pos+offset).GetData() );      offset.RotateAroundZ(0.5f * M_PI);
            glEnd();
        }

        glDisable( GL_TEXTURE_2D );
    }


    //
    // Engine effect

    if( rocket->m_state == EscapeRocket::StateReady ||
        rocket->m_state == EscapeRocket::StateCountdown ||
        rocket->m_state == EscapeRocket::StateFlight)
    {
        float flameX = m_x + m_w * 0.35f;
        float flameY = m_y + h * 0.8f;
        float flameW = m_w * 0.3f;
        float flameH = m_w * 0.3f;

        glBlendFunc     ( GL_SRC_ALPHA, GL_ONE );

        glEnable( GL_TEXTURE_2D );
        glBindTexture( GL_TEXTURE_2D, g_app->m_resource->GetTexture("textures/muzzleflash.bmp" ) );

        if( fmodf( GetHighResTime()*30, 1.0f ) < 0.5f ) glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
        else                                             glColor4f( 1.0f, 1.0f, 1.0f, 0.2f );

        glBegin( GL_QUADS );
            glTexCoord2i(0,0);      glVertex2f( flameX, flameY );
            glTexCoord2i(0,1);      glVertex2f( flameX+flameW, flameY );
            glTexCoord2i(1,1);      glVertex2f( flameX+flameW, flameY+flameH );
            glTexCoord2i(1,0);      glVertex2f( flameX, flameY+flameH );
        glEnd();

        glDisable( GL_TEXTURE_2D );
    }


    //
    // Captions at the bottom
    // Determine our caption

    float mainCaptionY = m_y + h * 0.6f;
    float mainCaptionH = h * 0.05f;
    float mainCaptionG = mainCaptionH * 0.1f;

    bool timeFlashEffect = (fmodf( GetHighResTime() * 2, 1.0f ) > 0.55f);

    UnicodeString caption;
    RGBAColour captionColour(255,255,255,255);

    if( GetHighResTime() - m_damageTimer < 10.0f && 
        rocket->m_state != EscapeRocket::StateExploding )
    {
        char damage[256];
        sprintf( damage, "%d%%", int(rocket->m_damage) );
        caption = LANGUAGEPHRASE("multiwinia_rr_status_c");
        caption.ReplaceStringFlag( L'T', damage );

        captionColour.Set(255,0,0,255);  
        if( timeFlashEffect ) captionColour.a *= 0.5f;
    }
    else if( rocket->m_state == EscapeRocket::StateCountdown )
    {        
        char captionC[256];
        sprintf( captionC, "%d", (int)rocket->m_countdown + 1 );
        caption = captionC;
        mainCaptionH *= 4;
    }
    else if( rocket->m_state == EscapeRocket::StateFlight )
    {
        caption = LANGUAGEPHRASE("multiwinia_rr_status_d" );
        mainCaptionH *= 1.5f;
        if( timeFlashEffect ) captionColour.a *= 0.25f;
    }
    else if( rocket->m_state == EscapeRocket::StateExploding )
    {
        caption = LANGUAGEPHRASE("multiwinia_rr_status_e" );
        if( timeFlashEffect ) captionColour.a *= 0.25f;
    }
    else if( fuelPercent >= 1.0f && darwiniansInside < 5 )
    {
        caption = LANGUAGEPHRASE("multiwinia_rr_status_b");
        if( timeFlashEffect ) captionColour.a *= 0.25f;
    } 
    else if( rocket->m_refuelRate < 0.05f && fuelPercent < 0.01f )
    {
        caption = LANGUAGEPHRASE("multiwinia_rr_status_a");        
        if( timeFlashEffect ) captionColour.a *= 0.25f;
    }
    else if( fuelPercent < 1.0f )
    {
        char captionC[256];
        sprintf( captionC, "%2.1f%%", fuelPercent * 100 );
        
        caption = LANGUAGEPHRASE("multiwinia_rr_status_f");
        caption.ReplaceStringFlag( L'T', captionC );

        captionColour.a *= 0.75f;
    }
       


    //
    // Render our caption

    if( caption.Length() )
    {
        LList<UnicodeString *> *wrapped = WordWrapText( caption, 1000, mainCaptionH, false, false );

        for( int i = 0; i < wrapped->Size(); ++i )
        {
            UnicodeString *thisString = wrapped->GetData(i);

            glColor4ub( captionColour.a, captionColour.a, captionColour.a, 0 );
            g_titleFont.SetRenderOutline(true);
            g_titleFont.DrawText2DCentre( m_x + m_w/2, mainCaptionY, mainCaptionH, *thisString );

            glColor4ubv( captionColour.GetData() );
            g_titleFont.SetRenderOutline(false);
            g_titleFont.DrawText2DCentre( m_x + m_w/2, mainCaptionY, mainCaptionH, *thisString );

            mainCaptionY += mainCaptionH;
            mainCaptionY += mainCaptionG;
        }

        wrapped->EmptyAndDelete();
        delete wrapped;
    }


    //
    // White border

    glColor4f( 1.0f, 1.0f, 1.0f, 0.2f );

    glBegin( GL_LINE_LOOP );
        glVertex2f( m_x, m_y );
        glVertex2f( m_x + m_w, m_y );
        glVertex2f( m_x + m_w, m_y + h );
        glVertex2f( m_x, m_y + h );
    glEnd();

    glShadeModel( GL_FLAT );
}
Exemplo n.º 24
0
/////////////////////////////////////////////////////////
// Render
//
void GEMglVertex2dv :: render(GemState *state) {
    glVertex2dv (v);
}
Exemplo n.º 25
0
inline void glVertex(Vector2d const &v)
{
  glVertex2dv(v.c);
}
Exemplo n.º 26
0
void vertex2(const Point &p)
{
    glVertex2dv(p.v);
}
Exemplo n.º 27
0
// :%s/\(void \)\(gl[A-Z,a-z,0-9]\+\)\(f\)( GLfloat \([a-z]\), GLfloat \([a-z]\), GLfloat \([a-z]\) );/template< > inline \1\2< float >			( float \4,float \5,float \6 )	{	\2\3(\4,\5,\6);	};/
template< > inline void glVertex2v< Vector3r >		( const Vector3r v )		{	glVertex2dv((double*)&v);		};
Exemplo n.º 28
0
void Graphics::HandleEventOnDisplay(void)
{
    char str[100];
    
    if(m_motionPlannerDraw)
	m_motionPlanner->Draw();
    
//draw robot
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);	
    glColor3f(1, 0, 0);
    glBegin(GL_POLYGON);
    glVertex2dv(&(m_motionPlanner->m_simulator->m_robotCurr[0]));
    glVertex2dv(&(m_motionPlanner->m_simulator->m_robotCurr[2]));
    glVertex2dv(&(m_motionPlanner->m_simulator->m_robotCurr[4]));
    glVertex2dv(&(m_motionPlanner->m_simulator->m_robotCurr[6]));
    glEnd();

    glColor3f(0, 0, 0);
    DrawPoint2D(m_motionPlanner->m_simulator->GetRobotCenterX(),
		m_motionPlanner->m_simulator->GetRobotCenterY());

    if(m_bestPathAnimate && m_bestPath.size() > 0)
    {
	sprintf(str, "%d", m_bestPathCurrReward);
	glColor3f(0, 0, 0);	
	DrawString2D(m_motionPlanner->m_simulator->GetRobotCenterX(),
		     m_motionPlanner->m_simulator->GetRobotCenterY(), str);
    }
    
    
    
//draw obstacles
    glColor3f(0.45, 0.34, 0.76);
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);	
    glBegin(GL_TRIANGLES);

    const int no = m_motionPlanner->m_simulator->GetNrObstacles();    
    for(int i = 0; i < no; ++i)
    {
	Simulator::Obstacle *obst = m_motionPlanner->m_simulator->m_obstacles[i];
	const int            ntri = obst->m_triangles.size();
    
	for(int j = 0; j < ntri; j += 3)
	{
	    glVertex2dv(&obst->m_vertices[2 * obst->m_triangles[j + 0]]);
	    glVertex2dv(&obst->m_vertices[2 * obst->m_triangles[j + 1]]);
	    glVertex2dv(&obst->m_vertices[2 * obst->m_triangles[j + 2]]);
	}
    }
    glEnd();

//draw reward regions
    if(m_bestPathAnimate && m_bestPath.size() > 0)
    {
	for(int i = 0; i < m_bestPathCurrRemainingRewards.size(); ++i)
	{
	    const int id = m_bestPathCurrRemainingRewards[i];	    

	    glColor3f(0, 1, 0);	    
	    DrawCircle2D(m_motionPlanner->m_simulator->GetRewardRegionCenterX(id),
			 m_motionPlanner->m_simulator->GetRewardRegionCenterY(id),
			 m_motionPlanner->m_simulator->GetRewardRegionRadius(id));
	    sprintf(str, "%d", m_motionPlanner->m_simulator->GetRewardRegionValue(id));	    
	    glColor3f(0, 0, 0);	    
	    DrawString2D(m_motionPlanner->m_simulator->GetRewardRegionCenterX(id),
			 m_motionPlanner->m_simulator->GetRewardRegionCenterY(id),
			 str);
	}	
    }
    else
    {
	for(int i = 0; i < m_motionPlanner->m_simulator->GetNrRewardRegions(); ++i)
	{
	    const int id = i;	    

	    glColor3f(0, 1, 0);	    
	    DrawCircle2D(m_motionPlanner->m_simulator->GetRewardRegionCenterX(id),
			 m_motionPlanner->m_simulator->GetRewardRegionCenterY(id),
			 m_motionPlanner->m_simulator->GetRewardRegionRadius(id));
	    sprintf(str, "%d", m_motionPlanner->m_simulator->GetRewardRegionValue(id));	    
	    glColor3f(0, 0, 0);	    
	    DrawString2D(m_motionPlanner->m_simulator->GetRewardRegionCenterX(id),
			 m_motionPlanner->m_simulator->GetRewardRegionCenterY(id),
			 str);
	}	
    }    
}
Exemplo n.º 29
0
void GOpenGLBoard::DrawGrabbedRect(const GLGrabbedRect& GrabbedRect, const GBool TexUnit0, const GBool SubPixel0,
								   const GBool TexUnit1, const GBool SubPixel1) {

	GReal u, v;
	GReal subX0 = 0, subY0 = 0, subX1 = 0, subY1 = 0;

	#define ENLARGE_OFFSET (GReal)0.5

	if (GrabbedRect.Target == GL_TEXTURE_2D) {
		u = (GReal)((GDouble)GrabbedRect.Width / (GDouble)GrabbedRect.TexWidth);
		v = (GReal)((GDouble)GrabbedRect.Height / (GDouble)GrabbedRect.TexHeight);
		if (SubPixel0) {
			subX0 = ENLARGE_OFFSET / (GrabbedRect.TexWidth);
			subY0 = ENLARGE_OFFSET / (GrabbedRect.TexHeight);
		}
		if (SubPixel1) {
			subX1 = ENLARGE_OFFSET / (GrabbedRect.TexWidth);
			subY1 = ENLARGE_OFFSET / (GrabbedRect.TexHeight);
		}
	}
	else {
		u = (GReal)GrabbedRect.Width;
		v = (GReal)GrabbedRect.Height;
		if (SubPixel0) {
			subX0 = ENLARGE_OFFSET;
			subY0 = ENLARGE_OFFSET;
		}
		if (SubPixel1) {
			subX1 = ENLARGE_OFFSET;
			subY1 = ENLARGE_OFFSET;
		}
	}

	GPoint2 p0(GrabbedRect.gExpandedLogicBox.Min());
	GPoint2 p2(GrabbedRect.gExpandedLogicBox.Max());
	GPoint2 p1(p0[G_X], p2[G_Y]);
	GPoint2 p3(p2[G_X], p0[G_Y]);

	glBegin(GL_POLYGON);
		if (TexUnit0)
			SetTextureVertex(0, 0 + subX0, v - subY0);
		if (TexUnit1)
			SetTextureVertex(1, 0 + subX1, v - subY1);
		#ifdef DOUBLE_REAL_TYPE
			glVertex2dv(p1.Data());
		#else
			glVertex2fv(p1.Data());
		#endif

		if (TexUnit0)
			SetTextureVertex(0, u - subX0, v - subY0);
		if (TexUnit1)
			SetTextureVertex(1, u - subX1, v - subY1);
		#ifdef DOUBLE_REAL_TYPE
			glVertex2dv(p2.Data());
		#else
			glVertex2fv(p2.Data());
		#endif

		if (TexUnit0)
			SetTextureVertex(0, u - subX0, 0 + subY0);
		if (TexUnit1)
			SetTextureVertex(1, u - subX1, 0 + subY1);
		#ifdef DOUBLE_REAL_TYPE
			glVertex2dv(p3.Data());
		#else
			glVertex2fv(p3.Data());
		#endif

		if (TexUnit0)
			SetTextureVertex(0, 0 + subX0, 0 + subY0);
		if (TexUnit1)
			SetTextureVertex(1, 0 + subX1, 0 + subY1);
		#ifdef DOUBLE_REAL_TYPE
			glVertex2dv(p0.Data());
		#else
			glVertex2fv(p0.Data());
		#endif
	glEnd();
}
PsychError SCREENDontCopyWindow(void) 
{
	PsychRectType			sourceRect, targetRect, targetRectInverted;
	PsychWindowRecordType	*sourceWin, *targetWin;
	GLdouble				sourceVertex[2], targetVertex[2]; 
	double  t1,t2;
	double					sourceRectWidth, sourceRectHeight;
        
    
    
	//all sub functions should have these two lines
	PsychPushHelp(useString, synopsisString, seeAlsoString);
	if(PsychIsGiveHelp()){PsychGiveHelp();return(PsychError_none);};

	//cap the number of inputs
	PsychErrorExit(PsychCapNumInputArgs(5));   //The maximum number of inputs
	PsychErrorExit(PsychCapNumOutputArgs(0));  //The maximum number of outputs
        
	//get parameters for the source window:
	PsychAllocInWindowRecordArg(1, TRUE, &sourceWin);
	PsychCopyRect(sourceRect, sourceWin->rect);
	PsychCopyInRectArg(3, FALSE, sourceRect);

	//get paramters for the target window:
	PsychAllocInWindowRecordArg(2, TRUE, &targetWin);
	PsychCopyRect(targetRect, targetWin->rect);
	PsychCopyInRectArg(4, FALSE, targetRect);

	//Check that the windows agree in depth.  They don't have to agree in format because we convert to the correct format for the target when we 
	//create the texture.
	if(sourceWin->depth != targetWin->depth)
		PsychErrorExitMsg(PsychError_user, "Source and target windows must have the same bit depth");
            
	//We need to unbind the source window texture from any previous target contexts if it is bound.  There can be only one binding at a time.
	//We could augment the Psychtoolbox to support shared contexts and multiple bindings.
	PsychRetargetWindowToWindow(sourceWin, targetWin);
		
		
	//each of these next three commands makes changes only when neccessary, they can be called generously 
	//when there is a possibility that any are necessary.
	  
	//PsychGetPrecisionTimerSeconds(&t1);
	PsychAllocateTexture(sourceWin);
	PsychBindTexture(sourceWin);
	PsychUpdateTexture(sourceWin);
	//PsychGetPrecisionTimerSeconds(&t2);
	//mexPrintf("texture checking copywindow took %f seconds\n", t2-t1);

	//PsychGetPrecisionTimerSeconds(&t1);
	PsychGetPrecisionTimerSeconds(&t1);
	PsychSetGLContext(targetWin);
	
	glBindTexture(GL_TEXTURE_RECTANGLE_EXT, sourceWin->glTexture);
	sourceRectWidth= PsychGetWidthFromRect(sourceWin->rect);
	sourceRectHeight= PsychGetHeightFromRect(sourceWin->rect);
	glTexSubImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, 0, 0, (GLsizei)sourceRectWidth, (GLsizei)sourceRectHeight, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, sourceWin->textureMemory);
	
	PsychInvertRectY(targetRectInverted, targetRect, targetWin->rect);
	//PsychGetPrecisionTimerSeconds(&t1);
	targetVertex[0]=0;
	targetVertex[1]=0;
    glBegin(GL_QUADS);
		glTexCoord2dv(PsychExtractQuadVertexFromRect(sourceRect, 0, sourceVertex));
		glVertex2dv(targetVertex);
		
		glTexCoord2dv(PsychExtractQuadVertexFromRect(sourceRect, 1, sourceVertex));
		glVertex2dv(targetVertex);

		glTexCoord2dv(PsychExtractQuadVertexFromRect(sourceRect, 2, sourceVertex));
		glVertex2dv(targetVertex);

		glTexCoord2dv(PsychExtractQuadVertexFromRect(sourceRect, 3, sourceVertex));
		glVertex2dv(targetVertex);
    glEnd();
    glFinish();
	//PsychGetPrecisionTimerSeconds(&t2);
	//mexPrintf("copywindow took %f seconds\n", t2-t1);



	return(PsychError_none);
}