/* MapPreviewCanvas::createImage
 * Draws the map in an image
 * TODO: Factorize code with normal draw() and showMap() functions.
 * TODO: Find a way to generate an arbitrary-sized image through
 * tiled rendering.
 *******************************************************************/
void MapPreviewCanvas::createImage(ArchiveEntry& ae, int width, int height)
{
	// Find extents of map
	mep_vertex_t m_min(999999.0, 999999.0);
	mep_vertex_t m_max(-999999.0, -999999.0);
	for (unsigned a = 0; a < verts.size(); a++)
	{
		if (verts[a].x < m_min.x)
			m_min.x = verts[a].x;
		if (verts[a].x > m_max.x)
			m_max.x = verts[a].x;
		if (verts[a].y < m_min.y)
			m_min.y = verts[a].y;
		if (verts[a].y > m_max.y)
			m_max.y = verts[a].y;
	}
	double mapwidth = m_max.x - m_min.x;
	double mapheight = m_max.y - m_min.y;

	if (width == 0) width = -5;
	if (height == 0) height = -5;
	if (width < 0)
		width = mapwidth / abs(width);
	if (height < 0)
		height = mapheight / abs(height);

	// Setup colours
	wxColour wxc;
	wxc.Set(map_image_col_background);	rgba_t col_save_background(wxc.Red(), wxc.Green(), wxc.Blue(), 255);
	wxc.Set(map_image_col_line_1s);		rgba_t col_save_line_1s(wxc.Red(), wxc.Green(), wxc.Blue(), 255);
	wxc.Set(map_image_col_line_2s);		rgba_t col_save_line_2s(wxc.Red(), wxc.Green(), wxc.Blue(), 255);
	wxc.Set(map_image_col_line_special); rgba_t col_save_line_special(wxc.Red(), wxc.Green(), wxc.Blue(), 255);
	wxc.Set(map_image_col_line_macro);	rgba_t col_save_line_macro(wxc.Red(), wxc.Green(), wxc.Blue(), 255);
	col_save_background.a = map_image_alpha_background;

	// Setup OpenGL rigmarole
	GLuint texID, fboID;
	if (GLEW_ARB_framebuffer_object)
	{
		glGenTextures(1, &texID);
		glBindTexture(GL_TEXTURE_2D, texID);
		// We don't use mipmaps, but OpenGL will refuse to attach
		// the texture to the framebuffer if they are not present
		glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
		glBindTexture(GL_TEXTURE_2D, 0);
		glGenFramebuffersEXT(1, &fboID);
		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboID);
		glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, texID, 0);
		GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
	}

	glViewport(0, 0, width, height);

	// Setup the screen projection
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0, width, 0, height, -1, 1);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	// Clear
	glClearColor(((double)col_save_background.r)/255.f, ((double)col_save_background.g)/255.f,
	             ((double)col_save_background.b)/255.f, ((double)col_save_background.a)/255.f);
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

	// Translate to inside of pixel (otherwise inaccuracies can occur on certain gl implementations)
	if (OpenGL::accuracyTweak())
		glTranslatef(0.375f, 0.375f, 0);

	// Zoom/offset to show full map
	// Offset to center of map
	offset_x = m_min.x + (mapwidth * 0.5);
	offset_y = m_min.y + (mapheight * 0.5);

	// Zoom to fit whole map
	double x_scale = ((double)width) / mapwidth;
	double y_scale = ((double)height) / mapheight;
	zoom = MIN(x_scale, y_scale);
	zoom *= 0.95;

	// Translate to middle of canvas
	glTranslated(width>>1, height>>1, 0);

	// Zoom
	glScaled(zoom, zoom, 1);

	// Translate to offset
	glTranslated(-offset_x, -offset_y, 0);

	// Setup drawing
	glDisable(GL_TEXTURE_2D);
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	glLineWidth(map_image_thickness);
	glEnable(GL_LINE_SMOOTH);

	// Draw lines
	for (unsigned a = 0; a < lines.size(); a++)
	{
		mep_line_t line = lines[a];

		// Check ends
		if (line.v1 >= verts.size() || line.v2 >= verts.size())
			continue;

		// Get vertices
		mep_vertex_t v1 = verts[lines[a].v1];
		mep_vertex_t v2 = verts[lines[a].v2];

		// Set colour
		if (line.special)
			OpenGL::setColour(col_save_line_special);
		else if (line.macro)
			OpenGL::setColour(col_save_line_macro);
		else if (line.twosided)
			OpenGL::setColour(col_save_line_2s);
		else
			OpenGL::setColour(col_save_line_1s);

		// Draw line
		glBegin(GL_LINES);
		glVertex2d(v1.x, v1.y);
		glVertex2d(v2.x, v2.y);
		glEnd();
	}

	glLineWidth(1.0f);
	glDisable(GL_LINE_SMOOTH);

	uint8_t* ImageBuffer = new uint8_t[width * height * 4];
	glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, ImageBuffer);

	if (GLEW_ARB_framebuffer_object)
	{
		glBindFramebuffer(GL_FRAMEBUFFER, 0);
		glDeleteTextures( 1, &texID );
		glDeleteFramebuffersEXT( 1, &fboID );
	}
	SImage img;
	img.setImageData(ImageBuffer, width, height, RGBA);
	img.mirror(true);
	MemChunk mc;
	SIFormat::getFormat("png")->saveImage(img, mc);
	ae.importMemChunk(mc);
}
Example #2
0
/* CTextureCanvas::drawTexture
 * Draws the currently opened composite texture
 *******************************************************************/
void CTextureCanvas::drawTexture()
{
	// Push matrix
	glPushMatrix();

	// Calculate top-left position of texture (for glScissor, since it ignores the current translation/scale)
	double left = offset.x + (GetSize().x * 0.5) - (texture->getWidth() * 0.5 * scale);
	double top = -offset.y + (GetSize().y * 0.5) - (texture->getHeight() * 0.5 * scale);

	// Translate to middle of the canvas
	glTranslated(GetSize().x * 0.5, GetSize().y * 0.5, 0);

	// Zoom
	double yscale = (tx_arc ? scale * 1.2 : scale);
	glScaled(scale, yscale, 1);

	// Draw offset guides if needed
	drawOffsetLines();

	// Apply texture scale
	double tscalex = 1;
	double tscaley = 1;
	if (tex_scale)
	{
		tscalex = texture->getScaleX();
		if (tscalex == 0) tscalex = 1;
		tscaley = texture->getScaleY();
		if (tscaley == 0) tscaley = 1;
		glScaled(1.0 / tscalex, 1.0 / tscaley, 1);
	}

	// Translate by offsets if needed
	if (view_type == 0)
		glTranslated(texture->getWidth() * -0.5, texture->getHeight() * -0.5, 0);	// No offsets
	if (view_type >= 1)
		glTranslated(-texture->getOffsetX(), -texture->getOffsetY(), 0);			// Sprite offsets
	if (view_type == 2)
		glTranslated(-160*tscalex, -100*tscaley, 0);								// HUD offsets

	// Draw the texture border
	//if (gfx_show_border)
	drawTextureBorder();

	// Enable textures
	glEnable(GL_TEXTURE_2D);

	// First, draw patches semitransparently (for anything outside the texture)
	// But only if we are drawing stuff outside the texture area
	if (draw_outside)
	{
		for (uint32_t a = 0; a < texture->nPatches(); a++)
			drawPatch(a, true);
	}

	// Reset colouring
	OpenGL::setColour(COL_WHITE);

	// If we're currently dragging, draw a 'basic' preview of the texture using opengl
	if (dragging)
	{
		glEnable(GL_SCISSOR_TEST);
		glScissor(left, top, texture->getWidth() * scale, texture->getHeight() * scale);
		for (uint32_t a = 0; a < texture->nPatches(); a++)
			drawPatch(a);
		glDisable(GL_SCISSOR_TEST);
	}

	// Otherwise, draw the fully generated texture
	else
	{
		// Generate if needed
		if (!tex_preview.isLoaded())
		{
			// Determine image type
			SIType type = PALMASK;
			if (blend_rgba) type = RGBA;

			// CTexture -> temp Image -> GLTexture
			SImage temp(type);
			texture->toImage(temp, parent, &palette, blend_rgba);
			tex_preview.loadImage(&temp, &palette);
		}

		// Draw it
		tex_preview.draw2d();
	}

	// Disable textures
	glDisable(GL_TEXTURE_2D);

	// Now loop through selected patches and draw selection outlines
	OpenGL::setColour(70, 210, 220, 255, BLEND_NORMAL);
	glEnable(GL_LINE_SMOOTH);
	glLineWidth(1.5f);
	for (size_t a = 0; a < selected_patches.size(); a++)
	{
		// Skip if not selected
		if (!selected_patches[a])
			continue;

		// Get patch
		CTPatch* patch = texture->getPatch(a);
		CTPatchEx* epatch = (CTPatchEx*)patch;

		// Check for rotation
		if (texture->isExtended() && (epatch->getRotation() == 90 || epatch->getRotation() == -90))
		{
			// Draw outline, width/height swapped
			glBegin(GL_LINE_LOOP);
			glVertex2i(patch->xOffset(), patch->yOffset());
			glVertex2i(patch->xOffset(), patch->yOffset() + (int)patch_textures[a]->getWidth());
			glVertex2i(patch->xOffset() + (int)patch_textures[a]->getHeight(), patch->yOffset() + (int)patch_textures[a]->getWidth());
			glVertex2i(patch->xOffset() + (int)patch_textures[a]->getHeight(), patch->yOffset());
			glEnd();
		}
		else
		{
			// Draw outline
			glBegin(GL_LINE_LOOP);
			glVertex2i(patch->xOffset(), patch->yOffset());
			glVertex2i(patch->xOffset(), patch->yOffset() + (int)patch_textures[a]->getHeight());
			glVertex2i(patch->xOffset() + (int)patch_textures[a]->getWidth(), patch->yOffset() + (int)patch_textures[a]->getHeight());
			glVertex2i(patch->xOffset() + (int)patch_textures[a]->getWidth(), patch->yOffset());
			glEnd();
		}
	}

	// Finally, draw a hilight outline if anything is hilighted
	if (hilight_patch >= 0)
	{
		// Set colour
		OpenGL::setColour(255, 255, 255, 150, BLEND_ADDITIVE);

		// Get patch
		CTPatch* patch = texture->getPatch(hilight_patch);
		CTPatchEx* epatch = (CTPatchEx*)patch;
		GLTexture* patch_texture = patch_textures[hilight_patch];

		// Check for rotation
		if (texture->isExtended() && (epatch->getRotation() == 90 || epatch->getRotation() == -90))
		{
			// Draw outline, width/height swapped
			glBegin(GL_LINE_LOOP);
			glVertex2i(patch->xOffset(), patch->yOffset());
			glVertex2i(patch->xOffset(), patch->yOffset() + (int)patch_texture->getWidth());
			glVertex2i(patch->xOffset() + (int)patch_texture->getHeight(), patch->yOffset() + (int)patch_texture->getWidth());
			glVertex2i(patch->xOffset() + (int)patch_texture->getHeight(), patch->yOffset());
			glEnd();
		}
		else
		{
			// Draw outline
			glBegin(GL_LINE_LOOP);
			glVertex2i(patch->xOffset(), patch->yOffset());
			glVertex2i(patch->xOffset(), patch->yOffset() + (int)patch_texture->getHeight());
			glVertex2i(patch->xOffset() + (int)patch_texture->getWidth(), patch->yOffset() + (int)patch_texture->getHeight());
			glVertex2i(patch->xOffset() + (int)patch_texture->getWidth(), patch->yOffset());
			glEnd();
		}
	}
	glDisable(GL_LINE_SMOOTH);
	glLineWidth(1.0f);

	// Pop matrix
	glPopMatrix();
}
Example #3
0
// draws GPS path and co-ordinates near the centre of the window
void NavigationGUI::drawGPS() {
	glPushMatrix();
	glTranslated(currWinW-150, -currWinH*3.0/5.0, 0);

	if (GPSList.size() > 0) {
		// draws out the path so that the forward direction of the rover always faces up on the screen
		glPushMatrix();
		glRotated(pathRotation, 0, 0, 1);
		
		glScaled(scale, scale, 1);
		glColor3f(0, 0, 0);
		
		vector3D currentPos = *(*GPSList.begin());
		
		glBegin(GL_LINE_STRIP);
		for (std::list<ListNode>::iterator i = GPSList.begin(); i != GPSList.end(); ++i)
			glVertex2d((*i)->lon - currentPos.lon, (*i)->lat - currentPos.lat);
		glEnd();
		if (GPSList.size() > 1) {
			glPointSize(5);
			glBegin(GL_POINTS);
			for (std::list<ListNode>::iterator i = ++GPSList.begin(); i != GPSList.end(); ++i)
				glVertex2d((*i)->lon - currentPos.lon, (*i)->lat - currentPos.lat);
			glEnd();
			glPointSize(1);
		}
		glPopMatrix();
	}
	
	// draw a cursor to indicate current rover position
	glPushMatrix();
	glTranslated(0, 15, 0);
	glColor4f(0, 0, 1, ALPHA);	
	glBegin(GL_POLYGON);
	glVertex2d(0, 0);
	glVertex2d(-10*cos(cursorSpin), -30);
	glVertex2d(10*cos(cursorSpin), -30);
	glEnd();
	glPopMatrix();

	// draw text for GPS co-ordinates
	
	char GPSLat[30];
	char GPSLong[30];
	char GPSAlt[30];
	if (GPSList.size() == 0) {
		sprintf(GPSLat, "Lat: Unknown");
		sprintf(GPSLong, "Long: Unknown");
		sprintf(GPSAlt, "Alt: Unknown");
	} else {
		sprintf(GPSLat, "Lat: %.10f", (*GPSList.begin())->lat);
		sprintf(GPSLong, "Long: %.10f", (*GPSList.begin())->lon);	
		sprintf(GPSAlt, "Alt: %.10f", (*GPSList.begin())->alt);
	}
	
	glTranslated(-50, -currWinH/4.0, 0);
	
	glColor4f(0, 1, 0, TEXTBOX_ALPHA);
	glRecti(-20, 30, 250, -125);
	
	glColor4f(1, 0, 0, ALPHA);
	drawText(GPSLat, GLUT_BITMAP_TIMES_ROMAN_24, 0, 0);
	glTranslated(0, -20, 0);
	drawText(GPSLong, GLUT_BITMAP_TIMES_ROMAN_24, 0, 0);
	glTranslated(0, -20, 0);
	drawText(GPSAlt, GLUT_BITMAP_TIMES_ROMAN_24, 0, 0);

	// draw text to display OpenGL scale value
	char scaleValue[50];
	glTranslated(0, -40, 0);
	sprintf(scaleValue, "OpenGL Scale: %.0f", scale);
	drawText(scaleValue, GLUT_BITMAP_TIMES_ROMAN_24, 0, 0);
	glPopMatrix();
}
Example #4
0
void
ConsoleWindow::drawUILayer() {


    glLineWidth ( 3.0 );

//    _contentWindow.outlineRounded(0.05);
//    _cubeWindow.outlineRounded(0.05);

    Audicle* audi = Audicle::instance();

    double glomod =  fabs( -1.0 + 2.0 * ( m_time * 0.6  - floor(m_time * 0.6 ) ) );

    double xdiv = 0.5 * ( _cubeWindow.right() + _contentWindow.left() ) ;
    glBegin(GL_LINES);
    glColor4d ( 0.2,0.2, 0.2, 1.0 );
    glVertex2d ( xdiv, _cubeWindow.top() - _marginSize );
    glVertex2d ( xdiv, _cubeWindow.bottom() + _marginSize );
    glEnd();


    _sizeBox.outlineRounded();


    glLineWidth(1.5);

    _curLabel.draw( 0.75 );
    _curDisplay.draw( 0.75 );
    
    if ( _active ) { 
        _prevLabel.draw( 0.75 );
        _prevDisplay.draw( 0.75 );
    }

    static char buffer[256];
    double time = the()->shreduler()->now_system;
    int sr = Digitalio::sampling_rate(); //m_sampling_rate;

    int samp = (int) time;
    int sec = samp / sr;
    int min = ( sec / 60 ) ;
    int hr =  ( min / 60 ) ;
    int day = ( hr / 24 );

    samp = samp % sr;
    sec = sec % 60;
    min = min % 60;
    hr = hr % 24;

    if ( day ) sprintf(buffer, "%dd:%02d:%02d:%02d.%05d", day,  hr, min, sec, samp );
    else if ( hr ) sprintf(buffer, "%02d:%02d:%02d.%05d", hr, min, sec, samp );
    else if ( min ) sprintf(buffer, "%02d:%02d.%05d", min, sec, samp );
    else if ( sec ) sprintf(buffer, "%02d.%05d", sec, samp );
    else sprintf(buffer, "%05d", samp );

    _timeDisplay.setLabel( buffer ) ;
    _timeDisplay.fitLabel( 1 );
    _timeDisplay.setw( _timeDisplay.w() * 0.70 );
    _timeDisplay.filledRounded( 0.03f );
    _timeDisplay.drawLabel( 0.75, 1 );
    _timeDisplay.outlineRounded( 0.03f );

    glPushName( _timeLabel.id() );

    Color4D tdark = Color4D( 0.6, 0.9, 0.6, 1.0 );
    Color4D tglow = tdark.interp( _timeLabel.col(), glomod * 1.2  );
    tglow[3] = 1.0;

    _timeLabel.setCol( tglow );

    glBegin( GL_POLYGON );
    _timeLabel.roundVerts( );
    glEnd( );

    _timeLabel.drawLeadedLabel( 0.75f, 0.15f );
    _timeLabel.outlineRounded( ); 

    glPopName();

    if ( _active ) { 

        glLineWidth( 3.0 );
        glPushMatrix();
        
        double cubh = _cubeSides[0].h();
        
        glTranslated ( _cubeWindow.center()[0] - cubh * 3.5 , _cubeWindow.center()[1] + cubh * 1.5, 0 );
        
        if ( _cube_swapping )  { 

            double w = ( m_time - _cube_swap_start ) / _cube_swap_span ;
            if ( w > 1.0 ) { 
                _cube_swapping = false ;
                for ( int i = 0 ; i < 6 ; i++ ) 
                    _swapPos[i] = _cubeSides[i].pos();
            }
            else if ( w > 0 ) 
            {
                for ( int i = 0; i < 6 ; i++ ) { 
                    
                    glPushMatrix();
                    glPushName( _cubeSides[i].id() );
                    Point2D animp = _swapPos[i].interp ( _cubeSides[i].pos() , w );
                    
                    glTranslated( animp[0] - _cubeSides[i].pos()[0], \
                                  animp[1] - _cubeSides[i].pos()[1], 0 );
                    
                    _cubeSides[i].drawQuad( 0.75 );
                    
                    glPopName();
                    glPopMatrix();
                }
            }
        }
        
        if ( !_cube_swapping ) {  
            for ( int i = 0 ; i < 6; i++ ) { 
                glPushName( _cubeSides[i].id() );
                _cubeSides[i].drawQuad( 0.75 );
                glPopName();
            }
        }

        t_CKUINT cur = audi->look_here();
        
        Point2D _cube_spot( cubh * 6.0 , -cubh * 1.5 );
        
        glPushMatrix();
        glTranslated ( _cube_spot[0], _cube_spot[1], 0 );
        glScaled  ( 1.5, 1.5, 1.5 );
        glRotatef ( -30, 1.0, 0.0, 0.0 );
        glRotatef ( 30, 0.0, 1.0 ,0.0 );
        
        glPushMatrix();
        glTranslated( 0, 0, -0.5 * cubh );
        glTranslated(-_cubeSides[cur].center()[0], -_cubeSides[cur].center()[1], 0.0  );
        glPushName( _cubeSides[cur].id() );
        
        
        
        Color4D dark = _cubeSides[cur].col().scale(0.75);
        Color4D glow = dark.interp( _cubeSides[cur].col(), glomod * 1.1  );
        glow[3] = 1.0;
        _cubeSides[cur].setCol( glow );
        
        glBegin( GL_QUADS);
        _cubeSides[cur].quadVerts( );
        glEnd( );
        
        _cubeSides[cur].drawLabel( 0.75 );
        _cubeSides[cur].outlineQuad( );
        
//    _cubeSides[cur].drawQuad( 0.75 );
        
        
        glPopName();
        glPopMatrix();
        
        glPushMatrix();
        glRotatef ( 90, 1.0 , 0, 0 );
        t_CKUINT up = audi->look_from( cur, Audicle::UP ) ;
        glTranslated( 0, 0, -0.5 * cubh );
        glTranslated(-_cubeSides[up].center()[0], -_cubeSides[up].center()[1], 0.0  );
        glPushName( _cubeSides[up].id() );
        _cubeSides[up].drawQuad( 0.75 );
        glPopName();
        glPopMatrix();
        
        glPushMatrix();
        glRotatef ( -90, 0.0 , 1.0 , 0 );
        t_CKUINT rt = audi->look_from( cur, Audicle::RIGHT ); 
        glTranslated( 0, 0, -0.5 * cubh );
        glTranslated(-_cubeSides[rt].center()[0], -_cubeSides[rt].center()[1], 0.0  );
        glPushName( _cubeSides[rt].id() );
        _cubeSides[rt].drawQuad( 0.75 );
        glPopName();
        glPopMatrix();
        
        glPopMatrix();
        
        glPopMatrix();

    }


}
Example #5
0
void INode::renderTree(Context& ctx) const {
  for (size_t i = 0; i < _states.size(); i++) {
    // start point
    vec3 startpoint = ctx.getCurrentOrigin();

    // calculate end point of joint
    vec3 endpoint = _states[i]->getEndpoint(ctx);

    // draw the link
    //glBegin(GL_LINES);
    //  glColor3d(1.0, 1.0, 1.0);
    //  glVertex3d(startpoint[0], startpoint[1], startpoint[2]);
    //  glVertex3d(endpoint[0], endpoint[1], endpoint[2]);
    //glEnd();

    // calculate orthonormal basis for cylinder on joint
    vec3 u, v, n;
    _states[i]->getBasis(ctx, u, v, n);

    // check if basis is really orthonormal
    assert(double_equals(dot(u, v), 0));
    assert(double_equals(dot(u, n), 0));
    assert(double_equals(dot(v, n), 0));

    assert(double_equals(norm(u, 2), 1));
    assert(double_equals(norm(v, 2), 1));
    assert(double_equals(norm(n, 2), 1));

    //cout << "pos:" << endl << pos << endl;

    //cout << "u:" << endl << u << endl;
    //cout << "v:" << endl << v << endl;
    //cout << "n:" << endl << n << endl;

    vec3 x = makeVec3(1, 0, 0); 
    vec3 y = makeVec3(0, 1, 0);
    vec3 z = makeVec3(0, 0, 1);

    double ux = dot(x, u);
    double uy = dot(y, u);
    double uz = dot(z, u);

    double vx = dot(x, v);
    double vy = dot(y, v);
    double vz = dot(z, v);

    double nx = dot(x, n);
    double ny = dot(y, n);
    double nz = dot(z, n);

    // change of orthonormal basis from uvn -> xyz
    GLdouble m[16];
    m[0]  = ux;
    m[1]  = uy;
    m[2]  = uz;
    m[3]  = 0;
    
    m[4]  = vx; 
    m[5]  = vy;
    m[6]  = vz;
    m[7]  = 0;

    m[8]  = nx;
    m[9]  = ny;
    m[10] = nz;
    m[11] = 0;

    m[12] = 0; m[13] = 0; m[14] = 0; m[15] = 1;

    mat44 A; 
    A << ux << vx << nx << 0 << endr 
      << uy << vy << ny << 0 << endr
      << uz << vz << nz << 0 << endr 
      << 0  << 0  << 0  << 1 << endr;

    //if (!double_equals(det(A), 1))
    //  cout << "A is: " << endl << A << endl;

    //cout << "det(A): " << det(A) << endl;
    const double dA = det(A);
    if (!double_equals(dA, 1)) {
      cerr << "ERROR: det(A) = " << dA << endl; 
      throw runtime_error("determinant not 1 for rotation matrix");
    }


    //cout << "--" << endl;
    //for (int iii = 0; iii < 16; iii++) {
    //  cout << m[iii] << endl;
    //}
    //cout << "--" << endl;

    if (isRootNode())
      glColor3d(0.0, 0.0, 0.8);
    else if (isFixed())
      glColor3d(0.0, 1.0, 1.0); 
    else
      glColor3d(0.0, 0.0, 1.0);

    glPushMatrix();
      glTranslated(startpoint[0], startpoint[1], startpoint[2]);
      if (isRootNode())
        glutSolidSphere(0.1, 20, 20);
      else
        glutSolidSphere(0.08, 20, 20);
    glPopMatrix();

    GLUquadricObj *quadric = gluNewQuadric();

    glPushMatrix();
      glColor3d(0.0, 1.0, 0.0);
      glTranslated(startpoint[0], startpoint[1], startpoint[2]);
      glMultMatrixd(m);
      gluCylinder(quadric, 0.05, 0.05, _states[i]->getLength(), 32, 32);
    glPopMatrix();

    gluDeleteQuadric(quadric);

    // recurse into child
    _states[i]->pushContext(ctx);
      _kids[i]->renderTree(ctx);
    ctx.popContext();
  }
}
Example #6
0
/*******************************************************************************
Function that gets called by the event handler to draw the scene.
*******************************************************************************/
void display(void)
{
	//glClearColor (red, green, blue, alpha)
	glClearColor(1.0f, 1.0f, 1.0f, 1.0f);		//Set the background color.
	
	//OK, now clear the screen with the background color.
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	//Load initial matrix transformation.
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	//Locate the camera.
	gluLookAt (g_eye[X], g_eye[Y], g_eye[Z], g_ref[X], g_ref[Y], g_ref[Z], 0.0, 1.0, 0.0);

	HMatrix arcball_rot;
	Ball_Value(g_arcBall,arcball_rot);
	glMultMatrixf((float *)arcball_rot);

	//Scale the scene in response to mouse commands.
	glScalef(g_zoom, g_zoom, g_zoom); 

	////////////////////// Draw the geometries in World ////////////////////////

	//drawGeom( Object.Geom );
	//drawGeom( Rod.Geom );
	drawGeom(body.Geom);
	drawGeom(middleRightLeg.Geom);
	drawGeom(middleLeftLeg.Geom);
	drawGeom(middleLeftOuterLeg.Geom);
	drawGeom(middleRightOuterLeg.Geom);
	drawGeom(brLeg.Geom);
	drawGeom(backRightOuterLeg.Geom);
	drawGeom(blLeg.Geom);
	drawGeom(backLeftOuterLeg.Geom);
	drawGeom(frLeg.Geom);
	drawGeom(frontRightOuterLeg.Geom);
	drawGeom(flLeg.Geom);
	drawGeom(frontLeftOuterLeg.Geom);

	for (auto i = 0; i < animator.foodParticles.size(); ++i)
	{
		drawGeom(animator.foodParticles.at(i).odeObject.Geom, animator.foodParticles.at(i).colored );

	}

	drawGeom(target.Geom);

	glPushMatrix();						//Draw the collision plane.
	glTranslated( 0.0, -0.05, 0.0 );
	glScaled( 140.0, 0.1, 140.0 );
	GDrawing::setColor( 0.4, 0.4, 1.0 );
	GDrawing::drawCube();
	glPopMatrix();

	////////////////////////////////////////////////////////////////////////////

	glutSwapBuffers();
	if( g_recording == 1)
		g_frameSaver.DumpPPM(g_width,g_height);
}
Example #7
0
void CQOpenGL::GLDrawScene()
{
    CGL_Utils::CurContextID = MyID;
    glRenderMode(GL_RENDER);

    glMatrixMode(GL_PROJECTION); // Select the Projection Matrix
    glLoadIdentity();
    GLSetPersp(); //dynamic control over the perspective

    //move the view to follow something if this signal is hooked up to something that changes its value
    Vec3D<> CurTarget(m_Cam.TargetX, m_Cam.TargetY, m_Cam.TargetZ);
    emit FindCamTarget(&CurTarget);
    m_Cam.TargetX = CurTarget.x;
    m_Cam.TargetY = CurTarget.y;
    m_Cam.TargetZ = CurTarget.z;

    // Set camera view
    glMatrixMode(GL_MODELVIEW); //Back to model view
    glLoadIdentity();
    GLTranslateCam();

    GLSetLighting(); //Enable to have specular highlight in accurate place
    //End Bonuses


    glPushMatrix();
    switch (CurView){ //this makes sure the axes and bounds are out front of drawing...
    case VTOP: glTranslated(0, 0, CurEnv.z); break;
    case VBOTTOM: glTranslated(0, 0, -CurEnv.z); break;
    case VLEFT: glTranslated(0, -CurEnv.y, 0); break;
    case VRIGHT: glTranslated(0, CurEnv.y, 0); break;
    case VFRONT: glTranslated(CurEnv.x, 0, 0); break;
    case VBACK: glTranslated( -CurEnv.x, 0, 0); break;
    }

    if (bDrawAxes)
        GLDrawAxes();

    glPopMatrix();

    if (bDrawBounds)
        GLDrawBounds();

//	CGL_Utils::DrawSphere(LastPickedPoint, 0.0002, Vec3D<>(1,1,1), CColor(.5, .5, .5));

    QTime t;
    t.start();
    //draw geometry:
    emit DrawGL(FastMode); //Draw anything connected to this!

    int MStoDraw = t.elapsed();
    if (MStoDraw > 200 && !IsFastMode() && !AskedAboutFastMode){
        AskedAboutFastMode = true;
        if (QMessageBox::question(NULL, "Enter fast draw mode?", "Do you want to enter fast drawing mode?", QMessageBox::Yes | QMessageBox::No)==QMessageBox::Yes)
            EnterFastMode(true);
    }

//	glPushMatrix();
    //draw 2D overlay!


    glPushAttrib(GL_TRANSFORM_BIT | GL_VIEWPORT_BIT);
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
      glLoadIdentity();
      glOrtho(0, WindowSize.width(), WindowSize.height(), 0, -1, 1);
      glMatrixMode(GL_MODELVIEW);
      glPushMatrix();
        glLoadIdentity();
        glDisable(GL_LIGHTING);
        emit DrawGLOverlay(); //draw any 2D connected to this!
      glPopMatrix();
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glPopAttrib();

}
/* MapPreviewCanvas::draw
 * Draws the map
 *******************************************************************/
void MapPreviewCanvas::draw()
{
	// Setup colours
	wxColour wxc;
	wxc.Set(map_view_col_background);	rgba_t col_view_background(wxc.Red(), wxc.Green(), wxc.Blue(), 255);
	wxc.Set(map_view_col_line_1s);		rgba_t col_view_line_1s(wxc.Red(), wxc.Green(), wxc.Blue(), 255);
	wxc.Set(map_view_col_line_2s);		rgba_t col_view_line_2s(wxc.Red(), wxc.Green(), wxc.Blue(), 255);
	wxc.Set(map_view_col_line_special);	rgba_t col_view_line_special(wxc.Red(), wxc.Green(), wxc.Blue(), 255);
	wxc.Set(map_view_col_line_macro);	rgba_t col_view_line_macro(wxc.Red(), wxc.Green(), wxc.Blue(), 255);

	// Setup the viewport
	glViewport(0, 0, GetSize().x, GetSize().y);

	// Setup the screen projection
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0, GetSize().x, 0, GetSize().y, -1, 1);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	// Clear
	glClearColor(((double)col_view_background.r)/255.f, ((double)col_view_background.g)/255.f,
	             ((double)col_view_background.b)/255.f, ((double)col_view_background.a)/255.f);
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

	// Translate to inside of pixel (otherwise inaccuracies can occur on certain gl implementations)
	if (OpenGL::accuracyTweak())
		glTranslatef(0.375f, 0.375f, 0);

	// Zoom/offset to show full map
	showMap();

	// Translate to middle of canvas
	glTranslated(GetSize().x * 0.5, GetSize().y * 0.5, 0);

	// Zoom
	glScaled(zoom, zoom, 1);

	// Translate to offset
	glTranslated(-offset_x, -offset_y, 0);

	// Setup drawing
	glDisable(GL_TEXTURE_2D);
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	glLineWidth(1.5f);
	glEnable(GL_LINE_SMOOTH);

	// Draw lines
	for (unsigned a = 0; a < lines.size(); a++)
	{
		mep_line_t line = lines[a];

		// Check ends
		if (line.v1 >= verts.size() || line.v2 >= verts.size())
			continue;

		// Get vertices
		mep_vertex_t v1 = verts[lines[a].v1];
		mep_vertex_t v2 = verts[lines[a].v2];

		// Set colour
		if (line.special)
			OpenGL::setColour(col_view_line_special);
		else if (line.macro)
			OpenGL::setColour(col_view_line_macro);
		else if (line.twosided)
			OpenGL::setColour(col_view_line_2s);
		else
			OpenGL::setColour(col_view_line_1s);

		// Draw line
		glBegin(GL_LINES);
		glVertex2d(v1.x, v1.y);
		glVertex2d(v2.x, v2.y);
		glEnd();
	}

	glLineWidth(1.0f);
	glDisable(GL_LINE_SMOOTH);

	// Swap buffers (ie show what was drawn)
	SwapBuffers();
}
Example #9
0
void
GNELane::drawGL(const GUIVisualizationSettings& s) const {
    glPushMatrix();
    glPushName(getGlID());
    glTranslated(0, 0, getType());
    const bool selectedEdge = gSelected.isSelected(myParentEdge.getType(), myParentEdge.getGlID());
    const bool selected = gSelected.isSelected(getType(), getGlID());
    if (mySpecialColor != 0) {
        GLHelper::setColor(*mySpecialColor);
    } else if (selected) {
        GLHelper::setColor(GNENet::selectedLaneColor);
    } else if (selectedEdge) {
        GLHelper::setColor(GNENet::selectionColor);
    } else {
        const GUIColorer& c = s.laneColorer;
        if (!setFunctionalColor(c.getActive()) && !setMultiColor(c)) {
            GLHelper::setColor(c.getScheme().getColor(getColorValue(c.getActive())));
        }
    };

    // draw lane
    // check whether it is not too small
    const SUMOReal selectionScale = selected || selectedEdge ? s.selectionScale : 1;
    const SUMOReal exaggeration = selectionScale * s.laneWidthExaggeration; // * s.laneScaler.getScheme().getColor(getScaleValue(s.laneScaler.getActive()));
    if (s.scale * exaggeration < 1.) {
        if (myShapeColors.size() > 0) {
            GLHelper::drawLine(getShape(), myShapeColors);
        } else {
            GLHelper::drawLine(getShape());
        }
        glPopMatrix();
    } else {
        if (drawAsRailway(s)) {
            // draw as railway
            const SUMOReal halfRailWidth = 0.725 * exaggeration;
            if (myShapeColors.size() > 0) {
                GLHelper::drawBoxLines(getShape(), myShapeRotations, myShapeLengths, myShapeColors, halfRailWidth);
            } else {
                GLHelper::drawBoxLines(getShape(), myShapeRotations, myShapeLengths, halfRailWidth);
            }
            RGBColor current = GLHelper::getColor();
            glColor3d(1, 1, 1);
            glTranslated(0, 0, .1);
            GLHelper::drawBoxLines(getShape(), myShapeRotations, myShapeLengths, halfRailWidth - 0.2);
            GLHelper::setColor(current);
            drawCrossties(0.3 * exaggeration, 1 * exaggeration, 1 * exaggeration);
        } else {
            // the actual lane
            // reduce lane width to make sure that a selected edge can still be seen
            const SUMOReal halfWidth = selectionScale * (myParentEdge.getNBEdge()->getLaneWidth(myIndex) / 2 - (selectedEdge ? .3 : 0));
            if (myShapeColors.size() > 0) {
                GLHelper::drawBoxLines(getShape(), myShapeRotations, myShapeLengths, myShapeColors, halfWidth);
            } else {
                GLHelper::drawBoxLines(getShape(), myShapeRotations, myShapeLengths, halfWidth);
            }
        }
        glPopMatrix();
        if (exaggeration == 1) {
            drawMarkings(selectedEdge, exaggeration);
        }

        // draw ROWs only if target junction has a valid logic)
        if (myParentEdge.getDest()->isLogicValid() && s.scale > 3) {
            drawArrows();
        }
    }

    glPopName();
}
Example #10
0
void
GNELane::drawArrows() const {
    const Position& end = getShape().back();
    const Position& f = getShape()[-2];
    SUMOReal rot = (SUMOReal) atan2((end.x() - f.x()), (f.y() - end.y())) * (SUMOReal) 180.0 / (SUMOReal) PI;
    glPushMatrix();
    glPushName(0);
    glTranslated(0, 0, GLO_JUNCTION + .1); // must draw on top of junction shape
    glColor3d(1, 1, 1);
    glTranslated(end.x(), end.y(), 0);
    glRotated(rot, 0, 0, 1);

    // draw all links
    const std::vector<NBEdge::Connection>& edgeCons = myParentEdge.getNBEdge()->myConnections;
    NBNode* dest = myParentEdge.getNBEdge()->myTo;
    for (std::vector<NBEdge::Connection>::const_iterator i = edgeCons.begin(); i != edgeCons.end(); ++i) {
        if ((*i).fromLane == myIndex) {
            LinkDirection dir = dest->getDirection(myParentEdge.getNBEdge(), i->toEdge, OptionsCont::getOptions().getBool("lefthand"));
            switch (dir) {
                case LINKDIR_STRAIGHT:
                    GLHelper::drawBoxLine(Position(0, 4), 0, 2, .05);
                    GLHelper::drawTriangleAtEnd(Position(0, 4), Position(0, 1), (SUMOReal) 1, (SUMOReal) .25);
                    break;
                case LINKDIR_LEFT:
                    GLHelper::drawBoxLine(Position(0, 4), 0, 1.5, .05);
                    GLHelper::drawBoxLine(Position(0, 2.5), 90, 1, .05);
                    GLHelper::drawTriangleAtEnd(Position(0, 2.5), Position(1.5, 2.5), (SUMOReal) 1, (SUMOReal) .25);
                    break;
                case LINKDIR_RIGHT:
                    GLHelper::drawBoxLine(Position(0, 4), 0, 1.5, .05);
                    GLHelper::drawBoxLine(Position(0, 2.5), -90, 1, .05);
                    GLHelper::drawTriangleAtEnd(Position(0, 2.5), Position(-1.5, 2.5), (SUMOReal) 1, (SUMOReal) .25);
                    break;
                case LINKDIR_TURN:
                    GLHelper::drawBoxLine(Position(0, 4), 0, 1.5, .05);
                    GLHelper::drawBoxLine(Position(0, 2.5), 90, .5, .05);
                    GLHelper::drawBoxLine(Position(0.5, 2.5), 180, 1, .05);
                    GLHelper::drawTriangleAtEnd(Position(0.5, 2.5), Position(0.5, 4), (SUMOReal) 1, (SUMOReal) .25);
                    break;
                case LINKDIR_TURN_LEFTHAND:
                    GLHelper::drawBoxLine(Position(0, 4), 0, 1.5, .05);
                    GLHelper::drawBoxLine(Position(0, 2.5), -90, 1, .05);
                    GLHelper::drawBoxLine(Position(-0.5, 2.5), -180, 1, .05);
                    GLHelper::drawTriangleAtEnd(Position(-0.5, 2.5), Position(-0.5, 4), (SUMOReal) 1, (SUMOReal) .25);
                    break;
                case LINKDIR_PARTLEFT:
                    GLHelper::drawBoxLine(Position(0, 4), 0, 1.5, .05);
                    GLHelper::drawBoxLine(Position(0, 2.5), 45, .7, .05);
                    GLHelper::drawTriangleAtEnd(Position(0, 2.5), Position(1.2, 1.3), (SUMOReal) 1, (SUMOReal) .25);
                    break;
                case LINKDIR_PARTRIGHT:
                    GLHelper::drawBoxLine(Position(0, 4), 0, 1.5, .05);
                    GLHelper::drawBoxLine(Position(0, 2.5), -45, .7, .05);
                    GLHelper::drawTriangleAtEnd(Position(0, 2.5), Position(-1.2, 1.3), (SUMOReal) 1, (SUMOReal) .25);
                    break;
                case LINKDIR_NODIR:
                    GLHelper::drawBoxLine(Position(1, 5.8), 245, 2, .05);
                    GLHelper::drawBoxLine(Position(-1, 5.8), 115, 2, .05);
                    glTranslated(0, 5, 0);
                    GLHelper::drawOutlineCircle(0.9, 0.8, 32);
                    glTranslated(0, -5, 0);
                    break;
            }
        }
    }
    glPopName();
    glPopMatrix();
}
Example #11
0
static void MENUdraw(boxC& b)
{
 utypeC* u;

 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

 glLoadIdentity();
 glTranslated(.5, b.H/2, 0);
 glScaled(.5, .5, .5);
 glDisable(GL_DEPTH_TEST);

 glDisable(GL_ALPHA_TEST);
 glDisable(GL_BLEND);
 glDisable(GL_TEXTURE_2D);

 glPushMatrix();
    glTranslated(0.0, -0.35, 0.0);
    glScaled(0.7, 0.7, 0.7);
    glRotated(Ax, 1.0, 0.0, 0.0);
    glRotated(Az, 0.0, 0.0, 1.0);

    glColor4f(.0, .0, 1., 1.);
    screenLineWidth(2);
    glBegin(GL_LINE_LOOP);
	glVertex2f(-0.5, 1.0);
	glVertex2f(+0.5, 1.0);
	glVertex2f(+0.5, 0.0);
	glVertex2f(-0.5, 0.0);
    glEnd();

    glRotated(Ay, 0.0, 1.0, 0.0);

    if(race)
    {
	int id = unitID;

	for(u = race->Units;
	    u &&
	     u->Next
	      && id--;
		u = u->Next);
        BLODisplay(&u->Flesh, t, color);
    }
 glPopMatrix();

 glTranslated(-0.8, 0.0, 0.0);

 glPushMatrix();
    glScaled(0.15, 0.15, 0.15);
    glRotated(Ax, 1.0, 0.0, 0.0);
    glRotated(Az, 0.0, 0.0, 1.0);
    glRotated(Ay, 0.0, 1.0, 0.0);
    glTranslated(0.0, -0.5, 0.0);
    if(race) BLODisplay(&u->Flesh, t, color);
 glPopMatrix();


 t += sp;
 if(t > 1.0) t = 0.0;
 if(t < 0.0) t = 1.0;
}
Example #12
0
void DrawSVG::draw_zoom() {

  // size (in pixels) of region of interest
  const size_t regionSize = 32;

  // relative size of zoom window
  size_t zoomFactor = 16;

  // compute zoom factor---the zoom window should never cover
  // more than 40% of the framebuffer, horizontally or vertically
  size_t bufferSize = min( width, height );
  if( regionSize*zoomFactor > bufferSize * 0.4) {
    zoomFactor = (bufferSize * 0.4 )/regionSize;
  }
  size_t zoomSize = regionSize * zoomFactor;

  // adjust the cursor coordinates so that the region of
  // interest never goes outside the bounds of the framebuffer
  size_t cX = max( regionSize/2, min( width-regionSize/2-1, (size_t) cursor_x ));
  size_t cY = max( regionSize/2, min( height-regionSize/2-1, height - (size_t) cursor_y ));

  // grab pixels from the region of interest
  vector<unsigned char> windowPixels( 3*regionSize*regionSize );
  glReadPixels( cX - regionSize/2,
                cY - regionSize/2 + 1, // meh
                regionSize,
                regionSize,
                GL_RGB,
                GL_UNSIGNED_BYTE,
                &windowPixels[0] );

  // upsample by the zoom factor, highlighting pixel boundaries
  vector<unsigned char> zoomPixels( 3*zoomSize*zoomSize );
  unsigned char* wp = &windowPixels[0];
  // outer loop over pixels in region of interest
  for( int y = 0; y < regionSize; y++ ) {
   int y0 = y*zoomFactor;
   for( int x = 0; x < regionSize; x++ ) {
      int x0 = x*zoomFactor;
      unsigned char* zp = &zoomPixels[ ( x0 + y0*zoomSize )*3 ];
      // inner loop over upsampled block
      for( int j = 0; j < zoomFactor; j++ ) {
        for( int i = 0; i < zoomFactor; i++ ) {
          for( int k = 0; k < 3; k++ ) {
            // highlight pixel boundaries
            if( i == 0 || j == 0 ) {
              const float s = .3;
              zp[k] = (int)( (1.-2.*s)*wp[k] + s*255. );
            } else {
              zp[k] = wp[k];
            }
          }
          zp += 3;
        }
        zp += 3*( zoomSize - zoomFactor );
      }
      wp += 3;
    }
  }

  // copy pixels to the screen using OpenGL
  glMatrixMode( GL_PROJECTION ); glPushMatrix(); glLoadIdentity(); glOrtho( 0, width, 0, height, 0.01, 1000. );
  glMatrixMode( GL_MODELVIEW  ); glPushMatrix(); glLoadIdentity(); glTranslated( 0., 0., -1. );

  glRasterPos2i( width-zoomSize, height-zoomSize );
  glDrawPixels( zoomSize, zoomSize, GL_RGB, GL_UNSIGNED_BYTE, &zoomPixels[0] );
  glMatrixMode( GL_PROJECTION ); glPopMatrix();
  glMatrixMode( GL_MODELVIEW ); glPopMatrix();

}
	void draw() {
		glTranslated(-position.x_coord, -position.y_coord, -position.z_coord);
		gluSphere(gluNewQuadric(), radius, 100, 100);
		glTranslated(position.x_coord, position.y_coord, position.z_coord);
	}
Example #14
0
static void fghTeapot( GLint grid, GLdouble scale, GLenum type )
{
#if defined(_WIN32_WCE)
		int i, numV=sizeof(strip_vertices)/4, numI=sizeof(strip_normals)/4;
#else
    double p[4][4][3], q[4][4][3], r[4][4][3], s[4][4][3];
    long i, j, k, l;
#endif

    glPushAttrib( GL_ENABLE_BIT | GL_EVAL_BIT );
    glEnable( GL_AUTO_NORMAL );
    glEnable( GL_NORMALIZE );
    glEnable( GL_MAP2_VERTEX_3 );
    glEnable( GL_MAP2_TEXTURE_COORD_2 );

    glPushMatrix();
    glRotated( 270.0, 1.0, 0.0, 0.0 );
    glScaled( 0.5 * scale, 0.5 * scale, 0.5 * scale );
    glTranslated( 0.0, 0.0, -1.5 );

#if defined(_WIN32_WCE)
    glRotated( 90.0, 1.0, 0.0, 0.0 );
    glBegin( GL_TRIANGLE_STRIP );

    for( i = 0; i < numV-1; i++ )
    {
        int vidx = strip_vertices[i],
            nidx = strip_normals[i];

        if( vidx != -1 )
        {
            glNormal3fv( normals[nidx]  );
            glVertex3fv( vertices[vidx] );
        }
        else
        {
            glEnd();
            glBegin( GL_TRIANGLE_STRIP );
        }
    }

    glEnd();
#else
    for (i = 0; i < 10; i++) {
      for (j = 0; j < 4; j++) {
        for (k = 0; k < 4; k++) {
          for (l = 0; l < 3; l++) {
            p[j][k][l] = cpdata[patchdata[i][j * 4 + k]][l];
            q[j][k][l] = cpdata[patchdata[i][j * 4 + (3 - k)]][l];
            if (l == 1)
              q[j][k][l] *= -1.0;
            if (i < 6) {
              r[j][k][l] =
                cpdata[patchdata[i][j * 4 + (3 - k)]][l];
              if (l == 0)
                r[j][k][l] *= -1.0;
              s[j][k][l] = cpdata[patchdata[i][j * 4 + k]][l];
              if (l == 0)
                s[j][k][l] *= -1.0;
              if (l == 1)
                s[j][k][l] *= -1.0;
            }
          }
        }
      }

      glMap2d(GL_MAP2_TEXTURE_COORD_2, 0.0, 1.0, 2, 2, 0.0, 1.0, 4, 2,
        &tex[0][0][0]);
      glMap2d(GL_MAP2_VERTEX_3, 0.0, 1.0, 3, 4, 0.0, 1.0, 12, 4,
        &p[0][0][0]);
      glMapGrid2d(grid, 0.0, 1.0, grid, 0.0, 1.0);
      glEvalMesh2(type, 0, grid, 0, grid);
      glMap2d(GL_MAP2_VERTEX_3, 0.0, 1.0, 3, 4, 0.0, 1.0, 12, 4,
        &q[0][0][0]);
      glEvalMesh2(type, 0, grid, 0, grid);
      if (i < 6) {
        glMap2d(GL_MAP2_VERTEX_3, 0.0, 1.0, 3, 4, 0.0, 1.0, 12, 4,
          &r[0][0][0]);
        glEvalMesh2(type, 0, grid, 0, grid);
        glMap2d(GL_MAP2_VERTEX_3, 0.0, 1.0, 3, 4, 0.0, 1.0, 12, 4,
          &s[0][0][0]);
        glEvalMesh2(type, 0, grid, 0, grid);
      }
    }
#endif  /* defined(_WIN32_WCE) */

    glPopMatrix();
    glPopAttrib();
}
Example #15
0
/* CTextureCanvas::drawPatch
 * Draws the patch at index [num] in the composite texture
 *******************************************************************/
void CTextureCanvas::drawPatch(int num, bool outside)
{
	// Get patch to draw
	CTPatch* patch = texture->getPatch(num);

	// Check it exists
	if (!patch)
		return;

	// Load the patch as an opengl texture if it isn't already
	if (!patch_textures[num]->isLoaded())
	{
		SImage temp(PALMASK);
		if (texture->loadPatchImage(num, temp, parent, &palette))
		{
			// Load the image as a texture
			patch_textures[num]->loadImage(&temp, &palette);
		}
		else
			patch_textures[num]->genChequeredTexture(8, COL_RED, COL_BLACK);
	}

	// Translate to position
	glPushMatrix();
	glTranslated(patch->xOffset(), patch->yOffset(), 0);

	// Setup rendering options
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	// Setup extended features
	bool flipx = false;
	bool flipy = false;
	double alpha = 1.0;
	bool shade_select = true;
	rgba_t col = COL_WHITE;
	if (texture->isExtended())
	{
		// Get extended patch
		CTPatchEx* epatch = (CTPatchEx*)patch;

		// Flips
		if (epatch->flipX())
			flipx = true;
		if (epatch->flipY())
			flipy = true;

		// Rotation
		if (epatch->getRotation() == 90)
		{
			glTranslated(patch_textures[num]->getHeight(), 0, 0);
			glRotated(90, 0, 0, 1);
		}
		else if (epatch->getRotation() == 180)
		{
			glTranslated(patch_textures[num]->getWidth(), patch_textures[num]->getHeight(), 0);
			glRotated(180, 0, 0, 1);
		}
		else if (epatch->getRotation() == -90)
		{
			glTranslated(0, patch_textures[num]->getWidth(), 0);
			glRotated(-90, 0, 0, 1);
		}
	}

	// Set colour
	if (outside)
		glColor4f(0.8f, 0.2f, 0.2f, 0.3f);
	else
		glColor4f(col.fr(), col.fg(), col.fb(), alpha);

	// Draw the patch
	patch_textures[num]->draw2d(0, 0, flipx, flipy);

	glPopMatrix();
}
Example #16
0
/* BrowserCanvas::draw
 * Handles drawing of the canvas content
 *******************************************************************/
void BrowserCanvas::draw()
{
	// Setup the viewport
	glViewport(0, 0, GetSize().x, GetSize().y);

	// Setup the screen projection
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0, GetSize().x, GetSize().y, 0, -1, 1);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	// Setup colours
	rgba_t col_bg, col_text;
	bool text_shadow = true;
	if (browser_bg_type == 1)
	{
		// Get system panel background colour
		wxColour bgcolwx = Drawing::getPanelBGColour();
		col_bg.set(bgcolwx.Red(), bgcolwx.Green(), bgcolwx.Blue());

		// Get system text colour
		wxColour textcol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
		col_text.set(textcol.Red(), textcol.Green(), textcol.Blue());

		// Check text colour brightness, if it's dark don't draw text shadow
		rgba_t col_temp = col_text;
		wxColor::MakeGrey(&col_temp.r, &col_temp.g, &col_temp.b);
		if (col_temp.r < 60)
			text_shadow = false;
	}
	else
	{
		// Otherwise use black background
		col_bg.set(0, 0, 0);

		// And white text
		col_text.set(255, 255, 255);
	}

	// Clear
	glClearColor(col_bg.fr(), col_bg.fg(), col_bg.fb(), 1.0f);
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

	// Translate to inside of pixel (otherwise inaccuracies can occur on certain gl implementations)
	if (OpenGL::accuracyTweak())
		glTranslatef(0.375f, 0.375f, 0);

	// Draw background if required
	if (browser_bg_type == 0)
		drawCheckeredBackground();

	// Init for texture drawing
	glEnable(GL_TEXTURE_2D);
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	glLineWidth(2.0f);

	// Draw items
	int x = item_border;
	int y = item_border;
	int col_width = GetSize().x / num_cols;
	int col = 0;
	top_index = -1;
	for (unsigned a = 0; a < items_filter.size(); a++)
	{
		// If we're not yet into the viewable area, skip
		if (y < yoff - fullItemSizeY())
		{
			col++;
			if (col >= num_cols)
			{
				col = 0;
				y += fullItemSizeY();

				// Canvas is filled, stop drawing
				if (y > yoff + GetSize().y)
					break;
			}
			continue;
		}

		// If we're drawing the first non-hidden item, save it
		if (top_index < 0)
		{
			top_index = a;
			top_y = y - yoff;
		}

		// Determine current x position
		int xgap = (col_width - fullItemSizeX()) * 0.5;
		x = item_border + xgap + (col * col_width);

		// Draw selection box if selected
		if (item_selected == items[items_filter[a]])
		{
			// Setup
			glDisable(GL_TEXTURE_2D);
			glColor4f(0.3f, 0.5f, 1.0f, 0.3f);
			glPushMatrix();
			glTranslated(x, y - yoff, 0);
			glTranslated(-item_border, -item_border, 0);

			// Selection background
			glBegin(GL_QUADS);
			glVertex2i(2, 2);
			glVertex2i(2, fullItemSizeY()-3);
			glVertex2i(fullItemSizeX()-3, fullItemSizeY()-3);
			glVertex2i(fullItemSizeX()-3, 2);
			glEnd();

			// Selection border
			glColor4f(0.6f, 0.8f, 1.0f, 1.0f);
			glBegin(GL_LINE_LOOP);
			glVertex2i(2, 2);
			glVertex2i(2, fullItemSizeY()-3);
			glVertex2i(fullItemSizeX()-3, fullItemSizeY()-3);
			glVertex2i(fullItemSizeX()-3, 2);
			glEnd();

			// Finish
			glPopMatrix();
			glEnable(GL_TEXTURE_2D);
			glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
		}

		// Draw item
		if (item_size <= 0)
			items[items_filter[a]]->draw(browser_item_size, x, y - yoff, font, show_names, item_type, col_text, text_shadow);
		else
			items[items_filter[a]]->draw(item_size, x, y - yoff, font, show_names, item_type, col_text, text_shadow);

		// Move over for next item
		col++;
		if (col >= num_cols)
		{
			col = 0;
			y += fullItemSizeY();

			// Canvas is filled, stop drawing
			if (y > yoff + GetSize().y)
				break;
		}
	}

	// Swap Buffers
	SwapBuffers();
}
Example #17
0
void MyGLWidget::paintGL(){

    //

    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glClearColor(0,0,0,1);



    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    gluPerspective(45,1,1,1000);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glTranslated(0,0,-5);

    glRotated(20,1,0,0);
    glRotated(45,0,1,0);


    glBegin(GL_QUADS);

            //vorne
            glNormal3f(normalen[0],normalen[1],normalen[2]);
            glColor3f(1,0,0);
            glVertex3f(-0.5,-0.5,0.5);
            glVertex3f(0.5,-0.5,0.5);
            glVertex3f(0.5,0.5,0.5);
            glVertex3f(-0.5,0.5,0.5);

            //hinten
            glNormal3f(normalen[3],normalen[4],normalen[5]);
            glColor3f(0,1,0);
            glVertex3f(-0.5,-0.5,-0.5);
            glVertex3f(-0.5,0.5,-0.5);
            glVertex3f(0.5,0.5,-0.5);
            glVertex3f(0.5,-0.5,-0.5);

            //rechts
            glNormal3f(normalen[6],normalen[7],normalen[8]);
            glColor3f(0,0,1);
            glVertex3f(0.5,-0.5,0.5);
            glVertex3f(0.5,-0.5,-0.5);
            glVertex3f(0.5,0.5,-0.5);
            glVertex3f(0.5,0.5,0.5);

            //links
            glNormal3f(normalen[9],normalen[10],normalen[11]);
            glColor3f(1,0,1);
            glVertex3f(-0.5,-0.5,-0.5);
            glVertex3f(-0.5,-0.5,0.5);
            glVertex3f(-0.5,0.5,0.5);
            glVertex3f(-0.5,0.5,-0.5);

            //oben
            glNormal3f(normalen[12],normalen[13],normalen[14]);
            glColor3f(1,1,0);
            glVertex3f(-0.5,0.5,0.5);
            glVertex3f(0.5,0.5,0.5);
            glVertex3f(0.5,0.5,-0.5);
            glVertex3f(-0.5,0.5,-0.5);

            //unten
            glNormal3f(normalen[15],normalen[16],normalen[17]);;
            glColor3f(0,1,1);
            glVertex3f(0.5,-0.5,-0.5);
            glVertex3f(0.5,-0.5,0.5);
            glVertex3f(-0.5,-0.5,0.5);
            glVertex3f(-0.5,-0.5,-0.5);

         glEnd();


}
Example #18
0
void 
dibujarTablero(GLfloat *x, GLfloat *y) 
{
  glColor3f(0.5,0.5,0.5); // Blanco
  /* Base del tablero */
  glBegin(GL_QUADS);
  glVertex3d(0.0,0.0,0.0); // vo
  glVertex3d(0.0,*y,0.0); // v2
  glVertex3d(*x,*y,0.0); // v3
  glVertex3d(*x,0.0,0.0); // v4
  glEnd();

  /* Banda Frontal */
  glPushMatrix();
  glColor3f(1.0,0.0,0.0);
  glTranslatef(0.0,*y,0.0);
  glBegin(GL_QUADS);
  glVertex3d(0.0,0.0,0.0); // vo
  glVertex3d(0.0,0.1,0.1); // v2
  glVertex3d(*x,0.1,0.1); // v3
  glVertex3d(*x,0.0,0.0); // v4
  glEnd();
  glPopMatrix();

  /* Contorno Banda Frontal */
  glPushMatrix();
  glColor3f(0.0,0.0,0.0);
  glLineWidth(3);
  glTranslatef(0.0,*y - 0.002,0.0);
  glBegin(GL_LINE_LOOP);
  glVertex3d(0.0,0.0,0.0); // vo
  glVertex3d(0.0,0.1,0.1); // v2
  glVertex3d(*x,0.1,0.1); // v3
  glVertex3d(*x,0.0,0.0); // v4
  glEnd();
  glPopMatrix();
  
  /* Banda Lateral Izquierda */
  glPushMatrix();
  glColor3f(1.0,0.0,0.0);
  glBegin(GL_QUADS);
  glVertex3f(0.0,0.0,0.0);
  glVertex3f(0.0,0.1,0.1);
  glVertex3f(0.0,*y,0.1);
  glVertex3f(0.0,*y,0.0);
  glEnd();
  glPopMatrix();

  /* Contorno Banda Lateral Izquierda */
  glPushMatrix();
  glColor3f(0.0,0.0,0.0);
  glLineWidth(5);
  glTranslatef(0.008,0.0,0.0);
  glBegin(GL_LINE_LOOP);
  glVertex3f(0.0,0.0,0.0);
  glVertex3f(0.0,0.0,0.1);
  glVertex3f(0.0,*y,0.1);
  glVertex3f(0.0,*y,0.0);
  glEnd();
  glPopMatrix();

  /* Banda Lateral Derecha */
  glPushMatrix();
  glColor3f(1.0,0.0,0.0);
  glTranslated(*x,0.0,0.0);
  glBegin(GL_QUADS);
  glVertex3f(0.0,0.0,0.0);
  glVertex3f(0.0,0.1,0.1);
  glVertex3f(0.0,*y,0.1);
  glVertex3f(0.0,*y,0.0);
  glEnd();
  glPopMatrix();

  /* Contorno Banda Lateral Izquierda */
  glPushMatrix();
  glColor3f(0.0,0.0,0.0);
  glLineWidth(5);
  glTranslatef(*x - 0.005,0.0,0.0);
  glBegin(GL_LINE_LOOP);
  glVertex3f(0.0,0.0,0.0);
  glVertex3f(0.0,0.1,0.1);
  glVertex3f(0.0,*y,0.1);
  glVertex3f(0.0,*y,0.0);
  glEnd();
  glPopMatrix();
}
void
GUILaneWrapper::drawLinkRules(const GUINet& net) const {
    unsigned int noLinks = getLinkNumber();
    const PositionVector& g = getShape();
    const Position& end = g.back();
    const Position& f = g[-2];
    const Position& s = end;
    SUMOReal rot = (SUMOReal) atan2((s.x() - f.x()), (f.y() - s.y())) * (SUMOReal) 180.0 / (SUMOReal) PI;
    if (noLinks == 0) {
        glPushName(getGlID());
        // draw a grey bar if no links are on the street
        glColor3d(0.5, 0.5, 0.5);
        glPushMatrix();
        glTranslated(end.x(), end.y(), 0);
        glRotated(rot, 0, 0, 1);
        glBegin(GL_QUADS);
        glVertex2d(-myHalfLaneWidth, 0.0);
        glVertex2d(-myHalfLaneWidth, 0.5);
        glVertex2d(myHalfLaneWidth, 0.5);
        glVertex2d(myHalfLaneWidth, 0.0);
        glEnd();
        glPopMatrix();
        glPopName();
        return;
    }
    // draw all links
    SUMOReal w = myLane.getWidth() / (SUMOReal) noLinks;
    SUMOReal x1 = 0;
    glPushMatrix();
    glTranslated(end.x(), end.y(), 0);
    glRotated(rot, 0, 0, 1);
    for (unsigned int i = 0; i < noLinks; ++i) {
        SUMOReal x2 = x1 + w;
        MSLink* link = getLane().getLinkCont()[i];
        // select glID
        switch (link->getState()) {
            case LINKSTATE_TL_GREEN_MAJOR:
            case LINKSTATE_TL_GREEN_MINOR:
            case LINKSTATE_TL_RED:
            case LINKSTATE_TL_YELLOW_MAJOR:
            case LINKSTATE_TL_YELLOW_MINOR:
            case LINKSTATE_TL_OFF_BLINKING:
                glPushName(net.getLinkTLID(link));
                break;
            case LINKSTATE_MAJOR:
            case LINKSTATE_MINOR:
            case LINKSTATE_EQUAL:
            case LINKSTATE_TL_OFF_NOSIGNAL:
            default:
                glPushName(getGlID());
                break;
        }
        // select color
        switch (link->getState()) {
            case LINKSTATE_TL_GREEN_MAJOR:
            case LINKSTATE_TL_GREEN_MINOR:
                glColor3d(0, 1, 0);
                break;
            case LINKSTATE_TL_RED:
                glColor3d(1, 0, 0);
                break;
            case LINKSTATE_TL_YELLOW_MAJOR:
            case LINKSTATE_TL_YELLOW_MINOR:
                glColor3d(1, 1, 0);
                break;
            case LINKSTATE_TL_OFF_BLINKING:
                glColor3d(.7, .7, 0);
                break;
            case LINKSTATE_TL_OFF_NOSIGNAL:
                glColor3d(0, 1, 1);
                break;
            case LINKSTATE_MAJOR:
                glColor3d(1, 1, 1);
                break;
            case LINKSTATE_MINOR:
                glColor3d(.2, .2, .2);
                break;
            case LINKSTATE_EQUAL:
                glColor3d(.5, .5, .5);
                break;
            case LINKSTATE_DEADEND:
                glColor3d(0, 0, 0);
                break;
        }
        glBegin(GL_QUADS);
        glVertex2d(x1 - myHalfLaneWidth, 0.0);
        glVertex2d(x1 - myHalfLaneWidth, 0.5);
        glVertex2d(x2 - myHalfLaneWidth, 0.5);
        glVertex2d(x2 - myHalfLaneWidth, 0.0);
        glEnd();
        glPopName();
        x1 = x2;
        x2 += w;
    }
    glPopMatrix();
}
void
GUILaneWrapper::drawGL(const GUIVisualizationSettings& s) const {
    glPushMatrix();
    const bool isInternal = getLane().getEdge().getPurpose() == MSEdge::EDGEFUNCTION_INTERNAL;
    bool mustDrawMarkings = false;
    const bool drawDetails =  s.scale * s.laneWidthExaggeration > 5;
    if (isInternal) {
        // draw internal lanes on top of junctions
        glTranslated(0, 0, GLO_JUNCTION + 0.1);
    } else {
        glTranslated(0, 0, getType());
    }
    // set lane color
    if (!MSGlobals::gUseMesoSim) {
        setColor(s);
        glPushName(getGlID()); // do not register for clicks in MESOSIM
    }
    // draw lane
    // check whether it is not too small
    if (s.scale * s.laneWidthExaggeration < 1.) {
        GLHelper::drawLine(myShape);
        if (!MSGlobals::gUseMesoSim) {
            glPopName();
        }
        glPopMatrix();
    } else if (isRailway(getLane().getPermissions())) {
        // draw as railway
        const SUMOReal halfRailWidth = 0.725;
        GLHelper::drawBoxLines(myShape, myShapeRotations, myShapeLengths, halfRailWidth * s.laneWidthExaggeration);
        glColor3d(1, 1, 1);
        glTranslated(0, 0, .1);
        GLHelper::drawBoxLines(myShape, myShapeRotations, myShapeLengths, (halfRailWidth - 0.2) * s.laneWidthExaggeration);
        drawCrossties(s);
        if (!MSGlobals::gUseMesoSim) {
            glPopName();
        }
        glPopMatrix();
    } else {
        const SUMOReal laneWidth = isInternal ? myQuarterLaneWidth : myHalfLaneWidth;
        mustDrawMarkings = !isInternal;
        GLHelper::drawBoxLines(myShape, myShapeRotations, myShapeLengths, laneWidth * s.laneWidthExaggeration);
        if (!MSGlobals::gUseMesoSim) {
            glPopName();
        }
        glPopMatrix();
        // draw ROWs (not for inner lanes)
        if (!isInternal && drawDetails) {
            glPushMatrix();
            glTranslated(0, 0, GLO_JUNCTION); // must draw on top of junction shape
            GUINet* net = (GUINet*) MSNet::getInstance();
            glTranslated(0, 0, .2);
            drawLinkRules(*net);
            if (s.showLinkDecals) {
                drawArrows();
            }
            if (s.showLane2Lane) {
                // this should be independent to the geometry:
                //  draw from end of first to the begin of second
                drawLane2LaneConnections();
            }
            glTranslated(0, 0, .1);
            if (s.drawLinkJunctionIndex) {
                drawLinkNo();
            }
            if (s.drawLinkTLIndex) {
                drawTLSLinkNo(*net);
            }
            glPopMatrix();
        }
    }
    if (mustDrawMarkings && drawDetails) { // needs matrix reset
        drawMarkings(s);
    }
    // draw vehicles
    if (s.scale > s.minVehicleSize) {
        // retrieve vehicles from lane; disallow simulation
        const MSLane::VehCont& vehicles = myLane.getVehiclesSecure();
        for (MSLane::VehCont::const_iterator v = vehicles.begin(); v != vehicles.end(); ++v) {
            static_cast<const GUIVehicle* const>(*v)->drawGL(s);
        }
        // allow lane simulation
        myLane.releaseVehicles();
    }
}
Example #21
0
/*
 *  OpenGL (GLUT) calls this routine to display the scene
 */
void display()
{
   int i,j;
   const double len=2.0;  //  Length of axes
   //  Light position and colors
   float Ambient[]  = {0.3,0.3,0.3,1.0};
   float Diffuse[]  = {1.0,1.0,1.0,1.0};
   float Position[] = {Cos(zh),Ylight,Sin(zh),1.0};

   //  Erase the window and the depth buffer
   glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);

   //  Enable Z-buffering in OpenGL
   glEnable(GL_DEPTH_TEST);
   //  Undo previous transformations
   glLoadIdentity();
   //  Perspective - set eye position
   if (proj)
   {
      double Ex = -2*dim*Sin(th)*Cos(ph);
      double Ey = +2*dim        *Sin(ph);
      double Ez = +2*dim*Cos(th)*Cos(ph);
      gluLookAt(Ex,Ey,Ez , 0,0,0 , 0,Cos(ph),0);
   }
   //  Orthogonal - set world orientation
   else
   {
      glRotatef(ph,1,0,0);
      glRotatef(th,0,1,0);
   }

   //  Draw light position as sphere (still no lighting here)
   glColor3f(1,1,1);
   glPushMatrix();
   glTranslated(Position[0],Position[1],Position[2]);
   glutSolidSphere(0.03,10,10);
   glPopMatrix();
   //  OpenGL should normalize normal vectors
   glEnable(GL_NORMALIZE);
   //  Enable lighting
   glEnable(GL_LIGHTING);
   //  glColor sets ambient and diffuse color materials
   glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
   glEnable(GL_COLOR_MATERIAL);
   //  Enable light 0
   glEnable(GL_LIGHT0);
   //  Set ambient, diffuse, specular components and position of light 0
   glLightfv(GL_LIGHT0,GL_AMBIENT ,Ambient);
   glLightfv(GL_LIGHT0,GL_DIFFUSE ,Diffuse);
   glLightfv(GL_LIGHT0,GL_POSITION,Position);

   //  Draw floor
   glEnable(GL_TEXTURE_2D);
   glEnable(GL_POLYGON_OFFSET_FILL);
   glPolygonOffset(1,1);
   glColor3f(1,1,1);
   glNormal3f(0,1,0);
   for (j=-Dfloor;j<Dfloor;j++)
   {
      glBegin(GL_QUAD_STRIP);
      for (i=-Dfloor;i<=Dfloor;i++)
      {
         glTexCoord2f(i,j); glVertex3f(i,Yfloor,j);
         glTexCoord2f(i,j+1); glVertex3f(i,Yfloor,j+1);
      }
      glEnd();
   }
   glDisable(GL_POLYGON_OFFSET_FILL);
   glDisable(GL_TEXTURE_2D);

   //  Draw scene
   glColor3f(1,1,0);
   scene();

   //  Save what is glEnabled
   glPushAttrib(GL_ENABLE_BIT);
   //  Draw shadow
   switch (mode)
   {
      //  No shadow
      case 0:
         break;
      //  Draw flattened scene
      case 1:
         glPushMatrix();
         ShadowProjection(Position,E,N);
         scene();
         glPopMatrix();
         break;
      //  Transformation with lighting disabled
      case 2:
         glDisable(GL_LIGHTING);
         //  Draw flattened scene
         glPushMatrix();
         ShadowProjection(Position,E,N);
         scene();
         glPopMatrix();
         break;
      //  Set shadow color
      case 3:
         glDisable(GL_LIGHTING);
         glColor3f(0.3,0.3,0.3);
         //  Draw flattened scene
         glPushMatrix();
         ShadowProjection(Position,E,N);
         scene();
         glPopMatrix();
         break;
      //  Blended shadows
      case 4:
         glDisable(GL_LIGHTING);
         //  Blended color
         glEnable(GL_BLEND);
         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
         glColor4f(0,0,0,0.4);
         //  Draw flattened scene
         glPushMatrix();
         ShadowProjection(Position,E,N);
         scene();
         glPopMatrix();
         break;
      //  Blended shadows Z-buffer masked
      case 5:
         glDisable(GL_LIGHTING);
         //  Draw blended 
         glEnable(GL_BLEND);
         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
         glColor4f(0,0,0,0.4);
         //  Make Z-buffer read-only
         glDepthMask(0);
         //  Draw flattened scene
         glPushMatrix();
         ShadowProjection(Position,E,N);
         scene();
         glPopMatrix();
         //  Make Z-buffer read-write
         glDepthMask(1);
         break;
      //  Blended with stencil buffer
      case 6:
         glDisable(GL_LIGHTING);
         //  Enable stencil operations
         glEnable(GL_STENCIL_TEST);

         /*
          *  Step 1:  Set stencil buffer to 1 where there are shadows
          */
         //  Existing value of stencil buffer doesn't matter
         glStencilFunc(GL_ALWAYS,1,0xFFFFFFFF);
         //  Set the value to 1 (REF=1 in StencilFunc)
         //  only if Z-buffer would allow write
         glStencilOp(GL_KEEP,GL_KEEP,GL_REPLACE);
         //  Make Z-buffer and color buffer read-only
         glDepthMask(0);
         glColorMask(0,0,0,0);
         //  Draw flattened scene
         glPushMatrix();
         ShadowProjection(Position,E,N);
         scene();
         glPopMatrix();
         //  Make Z-buffer and color buffer read-write
         glDepthMask(1);
         glColorMask(1,1,1,1);

         /*
          *  Step 2:  Draw shadow masked by stencil buffer
          */
         //  Set the stencil test draw where stencil buffer is > 0
         glStencilFunc(GL_LESS,0,0xFFFFFFFF);
         //  Make the stencil buffer read-only
         glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP);
         //  Enable blending
         glEnable(GL_BLEND);
         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
         glColor4f(0,0,0,0.5);
         //  Draw the shadow over the entire floor
         glBegin(GL_QUADS);
         glVertex3f(-Dfloor,Yfloor,-Dfloor);
         glVertex3f(+Dfloor,Yfloor,-Dfloor);
         glVertex3f(+Dfloor,Yfloor,+Dfloor);
         glVertex3f(-Dfloor,Yfloor,+Dfloor);
         glEnd();
         break;
      default:
         break;
   }    
   //  Undo glEnables
   glPopAttrib();
   
   //  Draw axes - no lighting from here on
   glDisable(GL_LIGHTING);
   glColor3f(1,1,1);
   if (axes)
   {
      glBegin(GL_LINES);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(len,0.0,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,len,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,0.0,len);
      glEnd();
      //  Label axes
      glRasterPos3d(len,0.0,0.0);
      Print("X");
      glRasterPos3d(0.0,len,0.0);
      Print("Y");
      glRasterPos3d(0.0,0.0,len);
      Print("Z");
   }
   //  Display parameters
   glWindowPos2i(5,5);
   Print("Angle=%d,%d  Dim=%.1f Projection=%s Light Elevation=%.1f",
     th,ph,dim,proj?"Perpective":"Orthogonal",Ylight);
   glWindowPos2i(5,25);
   Print(text[mode]);
   //  Render the scene and make it visible
   ErrCheck("display");
   glFlush();
   glutSwapBuffers();
}
Example #22
0
void GamePaddle::walk_gl(bool texture) const
{
	glPushMatrix();

	// HACK: Matrix4x4 stores its values in row-major order, but openGL wants them in column-major order
	// A transpose performs this conversion. Begin will return a pointer to the beginning of the matrix array

	// Transform the origin first
	Matrix4x4 col_mjr = m_origin.transpose();
	const double * transform_array = col_mjr.begin();
	glMultMatrixd(transform_array);

	// Place the paddle in its current location
	col_mjr = m_transform.transpose();
	transform_array = col_mjr.begin();
	glMultMatrixd(transform_array);

	glPushMatrix();

	// Since the Box is size 2 and centred at (0,0,0)
	// make the box a PADDLE!
	glScaled(_scale[0], _scale[1], _scale[2]);

	// Crunch the stored colour value into float arrays
	GLfloat diffuse[4] = {1.0f, 1.0f, 1.0f, 1.0f};
	GLfloat specular[4] = {0.1f, 0.1f, 0.1f, 1.0f};
	GLfloat shiny = 10;

	// Pass material properties to openGL with glMaterial
	glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
	glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
	glMaterialfv(GL_FRONT, GL_SHININESS, &shiny);

	if (texture) _tex->apply();

	_primitive->walk_gl();

	glPopMatrix();

	if (_draw_vector)
	{

		Vector3D velocity = _paddle->get_velocity();

		glDisable(GL_TEXTURE_2D);
		glDisable(GL_LIGHTING);

		glTranslated(0, 0, -2);

		glColor3d(0, 0, 0);

		glBegin(GL_LINES);

		glVertex3d(0.0, 0.0, 0.0);
		glVertex3d(velocity[0], velocity[1], 0.0);

		glEnd();

		glEnable(GL_LIGHTING);
		glEnable(GL_TEXTURE_2D);
	}

	glPopMatrix();
}
Example #23
0
void GUI_Button::onRender()
{
	GUI& gui = GUI::inst();
	int offset = 0;

	if(useSkin())
	{
		if(style == 0)
		{
			// Button zeichnen
			gui.renderFrame(Vec2i(0, 0), size, pushed && mouseOver ? Vec2i(48, 96) : Vec2i(0, 96));
			offset = -1;
		}
		else
		{
			Vec2i t = positionOnTexture;
			if(pushed && mouseOver) t = clickedPositionOnTexture;

			glPushMatrix();
			glTranslated(size.x / 2, size.y / 2, 0.0);
			glScaled(currentScaling, currentScaling, 1.0);
			Engine::inst().renderSprite(p_image, -size / 2, t, size, currentColor);
			glPopMatrix();
		}
	}
	else
	{
		// Hintergrund zeichnen
		glBegin(GL_QUADS);
		if(pushed && mouseOver) glColor4d(0.9, 0.9, 0.9, 1.0);
		else glColor4d(0.75, 0.75, 0.75, 1.0);
		glVertex2i(0, 0);
		glVertex2i(size.x, 0);
		if(pushed && mouseOver) glColor4d(0.8, 0.8, 0.8, 1.0);
		else glColor4d(0.65, 0.65, 0.65, 1.0);
		glVertex2i(size.x, size.y);
		glVertex2i(0, size.y);
		glEnd();

		// Rahmen zeichnen
		glColor4d(0.0, 0.0, 0.0, 1.0);
		glBegin(GL_LINE_LOOP);
		glVertex2i(0, 0);
		glVertex2i(size.x, 0);
		glVertex2i(size.x, size.y);
		glVertex2i(0, size.y);
		glEnd();
	}

	// Titel schreiben
	Vec2i dim;
	std::string title = localizeString(this->title);
	p_font->measureText(title, &dim, 0);

	if(style == 0)
	{
		p_font->renderText(title, (size - dim) / 2 + Vec2i(0, offset), active ? Vec4d(1.0, 1.0, 1.0, 1.0) : Vec4d(0.5, 0.5, 0.5, 1.0));

		if(p_image)
		{
			// Bild rendern
			Engine::inst().renderSprite(p_image, Vec2i(0, offset), positionOnTexture, size, Vec4d(1.0));
		}
	}
	else
	{
		p_font->renderText(title, Vec2i((size.x - dim.x) / 2, size.y - 4), active ? currentColor : Vec4d(0.5, 0.5, 0.5, 1.0));
	}
}
Example #24
0
void PlotGl::paintGLThread()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	bool bEnabled = m_bEnabled.load();
	if(!bEnabled) return;

	glMatrixMode(GL_MODELVIEW);
	t_real_gl glmat[16];
	{
		std::lock_guard<QMutex> _lck(m_mutex);
		tl::to_gl_array(m_matView, glmat);
	}
	glLoadMatrixd(glmat);


	glPushMatrix();
		glDisable(GL_LIGHTING);
		glDisable(GL_BLEND);
		glDisable(GL_TEXTURE_2D);
		glLineWidth(2.);
		glColor3d(0., 0., 0.);

		const t_real_gl dAxisScale = 1.8;
		glBegin(GL_LINES);
			glVertex3d(m_dXMin*dAxisScale, 0., 0.);
			glVertex3d(m_dXMax*dAxisScale, 0., 0.);
			glVertex3d(0., m_dYMin*dAxisScale, 0.);
			glVertex3d(0., m_dYMax*dAxisScale, 0.);
			glVertex3d(0., 0., m_dZMin*dAxisScale);
			glVertex3d(0., 0., m_dZMax*dAxisScale);
		glEnd();
	glPopMatrix();

	glEnable(GL_BLEND);
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	glDisable(GL_TEXTURE_2D);

	std::unique_lock<QMutex> _lck(m_mutex);
	std::size_t iPltIdx = 0;
	for(const PlotObjGl& obj : m_vecObjs)
	{
		int iLOD = 0;

		bool bColorSet = 0;
		if(obj.bSelected)
		{
			SetColor(0.25, 0.25, 0.25, 0.9);
			bColorSet = 1;
		}

		glPushMatrix();
		if(obj.plttype == PLOT_SPHERE)
		{
			glTranslated(obj.vecParams[0], obj.vecParams[1], obj.vecParams[2]);
			glScaled(obj.vecParams[3], obj.vecParams[3], obj.vecParams[3]);
		}
		else if(obj.plttype == PLOT_ELLIPSOID)
		{
			glTranslated(obj.vecParams[3], obj.vecParams[4], obj.vecParams[5]);

			t_real_gl dMatRot[] = {obj.vecParams[6], obj.vecParams[7], obj.vecParams[8], 0.,
				obj.vecParams[9], obj.vecParams[10], obj.vecParams[11], 0.,
				obj.vecParams[12], obj.vecParams[13], obj.vecParams[14], 0.,
				0., 0., 0., 1. };
			glMultMatrixd(dMatRot);
			glScaled(obj.vecParams[0], obj.vecParams[1], obj.vecParams[2]);
		}
		else
			tl::log_warn("Unknown plot object.");

		if(obj.bUseLOD)
		{
			t_real_gl dLenDist = tl::gl_proj_sphere_size(/*dRadius*/1.);
			//std::cout << "proj sphere size: " << dLenDist << std::endl;
			iLOD = dLenDist * 50.;
			if(iLOD >= int(sizeof(m_iLstSphere)/sizeof(*m_iLstSphere)))
				iLOD = sizeof(m_iLstSphere)/sizeof(*m_iLstSphere)-1;
			if(iLOD < 0) iLOD = 0;
			iLOD = sizeof(m_iLstSphere)/sizeof(*m_iLstSphere) - iLOD - 1;
			//std::cout << "dist: " << dLenDist << ", lod: " << iLOD << std::endl;
		}

		if(!bColorSet)
		{
			if(obj.vecColor.size())
				SetColor(obj.vecColor[0], obj.vecColor[1], obj.vecColor[2], obj.vecColor[3]);
			else
				SetColor(iPltIdx);
		}
		glCallList(m_iLstSphere[iLOD]);

		if(obj.bSelected && obj.strLabel.length() && m_pFont && m_pFont->IsOk())
		{
			glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_LIGHTING_BIT);
			m_pFont->BindTexture();
			glColor4d(0., 0., 0., 1.);
			m_pFont->DrawText(0., 0., 0., obj.strLabel);
			glPopAttrib();
		}

		glPopMatrix();

		++iPltIdx;
	}
	_lck.unlock();

	glPushMatrix();
		if(m_pFont && m_pFont->IsOk())
		{
			m_pFont->BindTexture();

			glColor4d(0., 0., 1., 1.);
			m_pFont->DrawText(m_dXMax*dAxisScale, 0., 0., m_strLabels[0].toStdString());
			m_pFont->DrawText(0., m_dYMax*dAxisScale , 0., m_strLabels[1].toStdString());
			m_pFont->DrawText(0., 0., m_dZMax*dAxisScale , m_strLabels[2].toStdString());

			glColor4d(0., 0., 0., 1.);
			m_pFont->DrawText(m_dXMin, 0., 0., tl::var_to_str(m_dXMin+m_dXMinMaxOffs, m_iPrec));
			m_pFont->DrawText(m_dXMax, 0., 0., tl::var_to_str(m_dXMax+m_dXMinMaxOffs, m_iPrec));
			m_pFont->DrawText(0., m_dYMin, 0., tl::var_to_str(m_dYMin+m_dYMinMaxOffs, m_iPrec));
			m_pFont->DrawText(0., m_dYMax, 0., tl::var_to_str(m_dYMax+m_dYMinMaxOffs, m_iPrec));
			m_pFont->DrawText(0., 0., m_dZMin, tl::var_to_str(m_dZMin+m_dZMinMaxOffs, m_iPrec));
			m_pFont->DrawText(0., 0., m_dZMax, tl::var_to_str(m_dZMax+m_dZMinMaxOffs, m_iPrec));
		}
	glPopMatrix();

	swapBuffers();
}
Example #25
0
void translate2D(double dx, double dy)
{
    glMatrixMode(GL_MODELVIEW);
    glTranslated(dx,dy,0.0);
}
Example #26
0
void myUnitCube::drawTextures()
{
	glPushMatrix();
	glTranslated(-0.5,-0.5,-0.5);

	//face de tras
	glPushMatrix();
	glRotated(180,0,1,0);
	glTranslated(-1,0,0);
	glBegin(GL_QUADS);
		glNormal3d(0,0,1);
		glTexCoord2d(0,0);glVertex3d(0,0,0);
		glTexCoord2d(1,0);glVertex3d(1,0,0);
		glTexCoord2d(1,1);glVertex3d(1,1,0);
		glTexCoord2d(0,1);glVertex3d(0,1,0);
	glEnd();
	glPopMatrix();


	//face da frente
	glPushMatrix();
	glTranslated(0,0,1);
	glBegin(GL_QUADS);
		glNormal3d(0,0,1);
		glTexCoord2d(0,0);glVertex3d(0,0,0);
		glTexCoord2d(1,0);glVertex3d(1,0,0);
		glTexCoord2d(1,1);glVertex3d(1,1,0);
		glTexCoord2d(0,1);glVertex3d(0,1,0);
	glEnd();
	glPopMatrix();


	//face de baixo
	glPushMatrix();
	glRotated(90,1,0,0);
	glBegin(GL_QUADS);
		glNormal3d(0,0,1);
		glTexCoord2d(0,0);glVertex3d(0,0,0);
		glTexCoord2d(1,0);glVertex3d(1,0,0);
		glTexCoord2d(1,1);glVertex3d(1,1,0);
		glTexCoord2d(0,1);glVertex3d(0,1,0);
	glEnd();
	glPopMatrix();

	//face de cima
	glPushMatrix();
	glRotated(-90,1,0,0);
	glTranslated(0,-1,1);
	glBegin(GL_QUADS);
		glNormal3d(0,0,1);
		glTexCoord2d(0,0);glVertex3d(0,0,0);
		glTexCoord2d(1,0);glVertex3d(1,0,0);
		glTexCoord2d(1,1);glVertex3d(1,1,0);
		glTexCoord2d(0,1);glVertex3d(0,1,0);
	glEnd();
	glPopMatrix();



	//face da esquerda
	glPushMatrix();
	glRotated(-90,0,1,0);
	glBegin(GL_QUADS);
		glNormal3d(0,0,1);
		glTexCoord2d(0,0);glVertex3d(0,0,0);
		glTexCoord2d(1,0);glVertex3d(1,0,0);
		glTexCoord2d(1,1);glVertex3d(1,1,0);
		glTexCoord2d(0,1);glVertex3d(0,1,0);
	glEnd();
	glPopMatrix();

	//face da direita
	glPushMatrix();
	glRotated(90,0,1,0);
	glTranslated(-1,0,1);
	glBegin(GL_QUADS);
		glNormal3d(0,0,1);
		glTexCoord2d(0,0);glVertex3d(0,0,0);
		glTexCoord2d(1,0);glVertex3d(1,0,0);
		glTexCoord2d(1,1);glVertex3d(1,1,0);
		glTexCoord2d(0,1);glVertex3d(0,1,0);
	glEnd();
	glPopMatrix();
	glPopMatrix();


}
Example #27
0
void 
ShellContent::draw() { 

	if ( _console ) { 
		string s;
		_prompt = _console->prompt();
		while ( _console->has_output() ) { 
			_console->get_output(s);
			output( s );
		}
	}

    _fixCanvas();
    _fixView();

    bool blending = ( WindowManager::getRenderMode() == WINDOW_RENDER_BLEND );
             
    glPushMatrix();
       
    glPushMatrix();
    _viewport.setCols( UI_BASE, Color4D( 1.0,1.0,1.0, 0.8 ), Color4D(0.2, 0.5, 0.2, 0.8 ) );
    _viewport.viewTranslate();
    
    if ( blending ) _viewport.filledQuad();
    glPopMatrix();
    
    _viewport.scale();
    _viewport.viewTranslate();

    glColor4dv( _fontColor.data() );
    glLineWidth (2.0);

    glLineWidth ( _fontWeight );

    //translate to bottom to draw our input line
    glTranslated ( 0, - _viewport.vpH() + _leading * 0.333, 0 );

    //rogue colors!
    if ( blending ) { 
        glColor4d( 1.0,1.0,0.9,1.0);

        glBegin (GL_QUADS);
        glVertex2d (0.0, 0.0  );
        glVertex2d (0.0, _leading  );
        glVertex2d ( _viewport.vpW(), _leading  );
        glVertex2d ( _viewport.vpW(), 0.0  );
        glEnd();
    }
    //draw current entry
    
	drawEntry();

    if ( !_output->empty() ) { 
        int range = min ( _output->nlines(), 8 );
        glColor4dv( _fontColor.data() );
        glTranslated( 0, _leading * ( range ) , 0 );
        for ( t_CKUINT i = _output->nlines()-range ; i < _output->nlines() ; i++ ) { 
            glTranslated ( 0, -_leading, 0 );
            glPushMatrix();
            bufferFont->scale ( _fontScale, _fontAspect );
            bufferFont->draw_sub( _output->line(i).str() );
            glPopMatrix();
        }
    }

    glPopMatrix();

}
Example #28
0
void robot_graphics_t::renderJoints(BodyNode *_node, RenderInterface *_ri, int _depth) {
	if(!_node)
		return;

	// render self geometry
    Joint *_jointParent = _node->getParentJoint();
    int nt = _jointParent->getNumTransforms();

    if(_depth > 0) {
        // lines?
        glColor3d(1,1,1);
        glLineWidth(2.0);
        glDisable(GL_LIGHTING);
        glBegin(GL_LINES);

        glVertex3d(0, 0, 0);

        Matrix4d locTrans = _jointParent->getLocalTransform();

        // Lines?
        glVertex3d(locTrans(0,3), locTrans(1,3), locTrans(2,3));
        glEnd();

        glEnable(GL_LIGHTING);
    }

	_ri->pushMatrix();
	for(int i=0; i < _jointParent->getNumTransforms(); ++i) {
		_jointParent->getTransform(i)->applyGLTransform(_ri);

//		if(i == _jointParent->getNumTransforms()-1) {
//			// dof transform
//			cout << "BodyNode: " << _node->getName() << endl;
//			cout << "Trfm: " << _jointParent->getTransform(i)->getName() << endl;
//			cout << "Tfrm Type: " << _jointParent->getTransform(i)->getType() << endl;
//			cout << "= \n" << _jointParent->getTransform(i)->getTransform() << endl;
//			cout << "ParentJoint: " << _jointParent->getName() << endl;
//			for(int i=0; i < 3; i++) {
//				cout << "axis " << i << "= \n"
//					 << _jointParent->getAxis(i) << endl;
//			}
//		}
	}

	// axis 0 is joint axis of rotation (i think)
	Vector3d ax = _jointParent->getAxis(0).normalized();
	Vector3d zx = Vector3d::UnitZ();
	Vector3d perp = zx.cross(ax);
	double y = perp.norm();
	double x = zx.dot(ax);
	double ang = atan2(y,x) * 180.0 / M_PI;

	_ri->pushMatrix();

	double radius = 0.02;
	double height = 0.05;

	_ri->rotate(perp, ang);

		_ri->pushMatrix();
		glTranslated(0.0,0.0,-height/2);
		glColor3d(0.0, 0.3, 1.0);
		QUAD_OBJ_INIT;
		gluCylinder(quadObj, radius, radius, height, 8, 8);
		gluDisk(quadObj, 0, radius, 8, 8);
		glTranslated(0.0,0.0,height);
		gluDisk(quadObj, 0, radius, 8, 8);
		_ri->popMatrix();

	//glColor3d(0.0, 1.0, 0.0);
	//_ri->drawCylinder(radius, height);
	_ri->popMatrix();


	// render subtree
	for(int i=0; i < _node->getNumChildJoints(); ++i) {
		BodyNode *child = _node->getChildJoint(i)->getChildNode();
		renderJoints(child, _ri, _depth+1);
	}
	_ri->popMatrix();
}
Example #29
0
// draws the tilt angles for the left-right and front-back directions near the right of the screen
void NavigationGUI::drawTilt() {
	char text[30];
	glPushMatrix();

	glTranslated(currWinW/2.0, -currWinH*4.0/5.0, 0);
	
	glColor4f(0, 1, 0, TEXTBOX_ALPHA);
	glRecti(-100, 100, 100, -150);
	glPushMatrix();

	// draw horizon
	glTranslated(0, 100*tan(-tiltY*PI/180.0),0);
	glRotated(-tiltX,0,0,1);
	glBegin(GL_LINE_STRIP);
	glVertex2d(-70,0);
	glVertex2d(70,0);
	glEnd();

	// draw sky indicator lines
	glPushMatrix();
	glColor4f(0, 0, 1, ALPHA);
	glBegin(GL_QUADS);
	glVertex2d(-ARTIFICIAL_HORIZON_SKY_HALF_WIDTH,0);
	glVertex2d(ARTIFICIAL_HORIZON_SKY_HALF_WIDTH,0);
	glVertex2d(ARTIFICIAL_HORIZON_SKY_MIN_HALF_WIDTH,ARTIFICIAL_HORIZON_SKY_HEIGHT);
	glVertex2d(-ARTIFICIAL_HORIZON_SKY_MIN_HALF_WIDTH,ARTIFICIAL_HORIZON_SKY_HEIGHT);
	glEnd();
	glPopMatrix();

	// draw ground (ie below horizon) indicator lines
	glPushMatrix();
	glColor4f(0.1, 0.1, 0.1, ALPHA);
	glBegin(GL_QUADS);
	glVertex2d(-ARTIFICIAL_HORIZON_SKY_HALF_WIDTH,0);
	glVertex2d(ARTIFICIAL_HORIZON_SKY_HALF_WIDTH,0);
	glVertex2d(ARTIFICIAL_HORIZON_SKY_MIN_HALF_WIDTH,-ARTIFICIAL_HORIZON_SKY_HEIGHT);
	glVertex2d(-ARTIFICIAL_HORIZON_SKY_MIN_HALF_WIDTH,-ARTIFICIAL_HORIZON_SKY_HEIGHT);
	glEnd();
	glPopMatrix();
	glPopMatrix();

	//DRAW robot indicator
	glColor4f(1, 0, 0, ALPHA);
	glBegin(GL_LINE_STRIP);
	glVertex2d(-70,0);
	glVertex2d(70,0);
	glEnd();
	glBegin(GL_LINE_STRIP);
	glVertex2d(0,-70);
	glVertex2d(0,70);
	glEnd();

	// Draw Tilt-Text
	glTranslated(-50, -100, 0);
	glColor4f(1, 0, 0, ALPHA);
	sprintf(text, "Roll: %.2fdeg", tiltX);
	drawText(text, GLUT_BITMAP_TIMES_ROMAN_24, 0, 0);
	glTranslated(0, -20, 0);
	sprintf(text, "Pitch: %.2fdeg", tiltY);
	drawText(text, GLUT_BITMAP_TIMES_ROMAN_24, 0, 0);

	glPopMatrix();
}
Example #30
0
void Ariou::draw() {
	ModelerView::draw();

	ModelerApplication::Instance()->Swing(LEFT_UPPER_ARM_ROTATE_X, 3.1);
	//ModelerApplication::Instance()->Swing(LEFT_UPPER_ARM_ROTATE_Y, 2.5);

	ModelerApplication::Instance()->Swing(HEAD_ROTATE, 1);

	ModelerApplication::Instance()->Swing(RIGHT_UPPER_ARM_ROTATE_X, 1.1);
	ModelerApplication::Instance()->Swing(RIGHT_UPPER_ARM_ROTATE_Y, 4.5);

	ModelerApplication::Instance()->Swing(LEFT_LEG_ROTATE_X, 6.1);
	ModelerApplication::Instance()->Swing(RIGHT_LEG_ROTATE_X, 6.1);

	ModelerApplication::Instance()->Swing(LS_DEPTH, 0.02);
	ModelerApplication::Instance()->Swing(LS_ANGLE, 0.15);

	setAmbientColor(.1f, .1f, .1f);
	setDiffuseColor(COLOR_RED);
	glPushMatrix();
	glScaled(VAL(FLOOR_SIZE), VAL(FLOOR_SIZE), VAL(FLOOR_SIZE));
	drawSierpinskiTriangle(0, 0, 1,
		0.86602540378443864676372317075293618347140262690519, 0, -0.5,
		-0.86602540378443864676372317075293618347140262690519, 0, -0.5,
		VAL(FLOOR_DEPTH));

	glTranslated(0, -0.05, 0);
	setDiffuseColor(COLOR_WHITE);
	drawPolygon(16, 2);
	glPopMatrix();


	glPushMatrix();
		/*
		GLfloat maambient[] = { 0.79225f, 0.79225f, 0.79225f, 1.0f };
		GLfloat madiffuse[] = { 0.50754f, 0.50754f, 0.50754f, 1.0f };
		GLfloat maspecular[] = { 0.508273f, 0.508273f, 0.508273f, 0.508273f };
		GLfloat shininess = 51.2f;
		GLfloat maemi[] = { 0.0f, 0.0f, 0.0f, 1.0f };

		glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, maambient);
		glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, madiffuse);
		glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, maspecular);
		glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
		glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, maemi);
		*/

		glTranslated(VAL(XPOS), VAL(YPOS), VAL(ZPOS));
		glScaled(VAL(XSCALE), VAL(YSCALE), VAL(ZSCALE));
		glRotated(VAL(ROTATE), 0, 1, 0);
		setDiffuseColor(COLOR_YELLOW);

		// Torus
		if (VAL(DETAIL_LEVEL) > 1) {
			glPushMatrix();
				glTranslated(.0f, 6, .0f);
				drawTorus(VAL(TORUS_R), VAL(TORUS_r));
			glPopMatrix();
		}
		
		//head
		glPushMatrix();
			glTranslated(0, VAL(LEG_LENGTH) + 0.05 + VAL(HEIGHT) + 0.05 + VAL(HEAD_SIZE), 0);
			glRotated(VAL(HEAD_ROTATE), 0.0, 1.0, 0.0);
			drawSphere(VAL(HEAD_SIZE));
			if (VAL(DETAIL_LEVEL) > 2) {

				// Nose
				drawRoundCylinder(VAL(HEAD_SIZE) * 1.1, 0.2, 0.2);

				// Ear
				glPushMatrix();
				glTranslated(0.9 / sqrt(0.9*0.9 + 1.1*1.1) * VAL(HEAD_SIZE), 1.1 / sqrt(0.9*0.9 + 1.1*1.1) * VAL(HEAD_SIZE), 0);
				glRotated(-20, 0, 0, 1);
				drawPyramid(VAL(EAR_SIZE));
				glPopMatrix();

				glPushMatrix();
				glTranslated(-0.9 / sqrt(0.9*0.9 + 1.1*1.1) * VAL(HEAD_SIZE), 1.1 / sqrt(0.9*0.9 + 1.1*1.1) * VAL(HEAD_SIZE), 0);
				glRotated(20, 0, 0, 1);
				drawPyramid(VAL(EAR_SIZE));
				glPopMatrix();
				
				// Eyes
				glPushMatrix();
				setDiffuseColor(COLOR_RED);
				glTranslated(-0.5 / sqrt(0.5*0.5 * 2) * VAL(HEAD_SIZE) * 0.5, 0.5 / sqrt(0.5*0.5 * 2) * VAL(HEAD_SIZE) * 0.5, VAL(HEAD_SIZE) - 0.9);
					drawRoundCylinder( 0.9, 0.2, 0.2);
				glPopMatrix();
				glPushMatrix();
				setDiffuseColor(COLOR_RED);
				glTranslated( 0.5 / sqrt(0.5*0.5 * 2) * VAL(HEAD_SIZE) * 0.5, 0.5 / sqrt(0.5*0.5 * 2) * VAL(HEAD_SIZE) * 0.5, VAL(HEAD_SIZE) - 0.9);
					drawRoundCylinder( 0.9, 0.2, 0.2);
				glPopMatrix();
			}
		glPopMatrix();

		if (VAL(DETAIL_LEVEL) > 1) {
			//body
			// a.k.a. torso/trunk
			glPushMatrix();
			setDiffuseColor(COLOR_YELLOW);
			glTranslated(0, 0.05 + VAL(LEG_LENGTH), 0);
			glRotated(-90, 1.0, 0.0, 0.0);
			drawRoundCylinder(VAL(HEIGHT), 0.7, 0.6);
			glPushMatrix();
			glTranslated(-0.8, 0, VAL(HEIGHT) - 0.4);
			glRotated(90, 0, 1, 0);
			// the shoulder
			if (VAL(DETAIL_LEVEL) > 2) {
				drawRoundCylinder(1.6, 0.2, 0.2);
			}
			glPopMatrix();

			// the waist
			if (VAL(DETAIL_LEVEL) > 3) {
				glPushMatrix();
				glTranslated(0, 0, 0.5);
				glRotated(90, 1, 0, 0);
				drawTorus(0.7, 0.08);
				glPopMatrix();
			}

			glPopMatrix();

			if (VAL(DETAIL_LEVEL) > 2) {
				//right arm
				glPushMatrix();
				glTranslated(-0.7 - 0.20, VAL(LEG_LENGTH) + 0.05 + VAL(HEIGHT) * 0.9f, 0);
				glTranslated(0.15, 0, 0);
				glRotated(VAL(RIGHT_UPPER_ARM_ROTATE_X), 1.0, 0.0, 0.0);
				glRotated(VAL(RIGHT_UPPER_ARM_ROTATE_Y), 0.0, 1.0, 0.0);
				glTranslated(-0.15, 0, 0);
				drawRoundCylinder(VAL(UPPER_ARM_LENGTH), 0.22, 0.15);

				// lower arm
				glTranslated(0, 0, VAL(UPPER_ARM_LENGTH) - 0.1);
				glRotated(VAL(RIGHT_LOWER_ARM_ROTATE) - 180, 1, 0, 0);
				drawRoundCylinder(VAL(LOWER_ARM_LENGTH), 0.15, 0.20);

				// hand
				glPushMatrix();
				glTranslated(-0.03, -0.15, VAL(LOWER_ARM_LENGTH) - 0.1);
				glRotated(VAL(RIGHT_HAND_ANGLE), 0, 1, 0);
				drawCylinder(0.8, 0.15, 0.0001);
				glPopMatrix();

				glPushMatrix();
				glTranslated(0.03, -0.15, VAL(LOWER_ARM_LENGTH) - 0.1);
				glRotated(-VAL(RIGHT_HAND_ANGLE), 0, 1, 0);
				drawCylinder(0.8, 0.15, 0.0001);
				glPopMatrix();

				glPopMatrix();

				//left arm
				glPushMatrix();
				glTranslated(0.7 + 0.20, VAL(LEG_LENGTH) + 0.05 + VAL(HEIGHT) * 0.9f, 0);
				glTranslated(-0.15, 0, 0);
				glRotated(VAL(LEFT_UPPER_ARM_ROTATE_X), 1.0, 0.0, 0.0);
				glRotated(VAL(LEFT_UPPER_ARM_ROTATE_Y), 0.0, 1.0, 0.0);
				glTranslated(0.15, 0, 0);
				drawRoundCylinder(VAL(UPPER_ARM_LENGTH), 0.22, 0.15);

				glTranslated(0, 0, VAL(UPPER_ARM_LENGTH) - 0.1);
				glRotated(VAL(LEFT_LOWER_ARM_ROTATE) - 180, 1, 0, 0);
				drawRoundCylinder(VAL(LOWER_ARM_LENGTH), 0.15, 0.20);

				// hand
				glPushMatrix();
				glTranslated(-0.03, 0, VAL(LOWER_ARM_LENGTH) - 0.1);
				glRotated(VAL(LEFT_HAND_ANGLE), 0, 1, 0);
				drawBox(0.03, 0.25, 0.5);
				glPopMatrix();

				glPushMatrix();
				glTranslated(0.03, 0, VAL(LOWER_ARM_LENGTH) - 0.1);
				glRotated(-VAL(LEFT_HAND_ANGLE), 0, 1, 0);
				drawBox(0.03, 0.25, 0.5);
				if (VAL(DETAIL_LEVEL) > 3) {
					glRotated(90, 0, 0, 1);
					drawCylinder(5, 0.02, 0.02);
					if (VAL(DETAIL_LEVEL) > 4) {
						glTranslated(0, 0, 4);
						LS ls("X", VAL(LS_DEPTH), VAL(LS_ANGLE));
						ls.expand(0);

						glPushMatrix();
						setDiffuseColor(COLOR_GREEN);
						glTranslated(0, -0.5, 1);
						glPushMatrix();
						glRotated(90, 1.0, 0.0, 0.0);
						ls.drawLS();
						glPopMatrix();
						glPopMatrix();
					}
				}
				glPopMatrix();

				glPopMatrix();
			}

			//right leg
			glPushMatrix();
			setDiffuseColor(COLOR_YELLOW);
			glTranslated(-0.5, VAL(LEG_LENGTH), 0);
			glRotated(VAL(RIGHT_LEG_ROTATE_X), 1.0, 0.0, 0.0);
			glRotated(VAL(RIGHT_LEG_ROTATE_Y), 0.0, 1.0, 0.0);
			drawRoundCylinder(VAL(LEG_LENGTH) - 0.15, 0.3, 0.4);
			glTranslated(0, 0, VAL(LEG_LENGTH) * 0.85f);
			glRotated(70, 1, 0, 0);
			drawTorus(VAL(FEET_SIZE), VAL(FEET_SIZE) / 4);

			glPopMatrix();

			//left leg
			glPushMatrix();
			glTranslated(0.5, VAL(LEG_LENGTH), 0);
			glRotated(VAL(LEFT_LEG_ROTATE_X), 1.0, 0.0, 0.0);
			glRotated(VAL(LEFT_LEG_ROTATE_Y), 0.0, 1.0, 0.0);
			drawRoundCylinder(VAL(LEG_LENGTH) - 0.15, 0.3, 0.4);
			glTranslated(0, 0, VAL(LEG_LENGTH) * 0.85f);
			glRotated(70, 1, 0, 0);
			drawTorus(VAL(FEET_SIZE), VAL(FEET_SIZE) / 4);

			glPopMatrix();
		}
	glPopMatrix();
}