コード例 #1
0
void Storm3D_Scene::renderRealScene(bool flip, bool render_mirrored, Storm3D_Texture *target) {
	glDisable(GL_SCISSOR_TEST);

	if(!flip && !render_mirrored)
	{
		int clearFlag = GL_DEPTH_BUFFER_BIT;
		if(Storm3D2->support_stencil)
			clearFlag |= GL_STENCIL_BUFFER_BIT;

		// Clear screen and depth buffer
		glClearColor(bgcolor.r, bgcolor.g, bgcolor.b, 1.0f);
		glClearDepth(1.0f);
		glClearStencil(0);
		glClear(clearFlag | GL_COLOR_BUFFER_BIT);
	}
	else
	{
		Storm3D2->getProceduralManagerImp().update(time_dif);
		// Clear screen
		glClearColor(bgcolor.r, bgcolor.g, bgcolor.b, 1.0f);
		glClearDepth(1.0f);
		glClearStencil(0);
		glClear(GL_COLOR_BUFFER_BIT);
	}

	// Update terrain render targets
	{
		for(set<IStorm3D_Terrain*>::iterator itr=terrains.begin();itr!=terrains.end();++itr)
		{
			// Typecast (to simplify code)
			Storm3D_Terrain *terra=(Storm3D_Terrain*)*itr;
			Storm3D_TerrainRenderer &renderer = static_cast<Storm3D_TerrainRenderer &> (terra->getRenderer());

			// Render it!
			renderer.updateVisibility(*this, time_dif);
			renderer.renderTargets(*this);
		}
	}

	// Apply the camera
	camera.Apply();

	if (target)
	{
		Storm3D2->SetRenderTarget(target);

		glClearColor(bgcolor.r, bgcolor.g, bgcolor.b, 1.0f);
		glClearDepth(1.0f);
		glClearStencil(0);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
	}

	// Render terrains
	for(set<IStorm3D_Terrain*>::iterator itr=terrains.begin();itr!=terrains.end();++itr)
	{
		// Typecast (to simplify code)
		Storm3D_Terrain *terra=(Storm3D_Terrain*)*itr;
		Storm3D_TerrainRenderer &renderer = static_cast<Storm3D_TerrainRenderer &> (terra->getRenderer());

		// Render it!
		renderer.renderBase(*this);
	}

	// Fix flickering (random stuff as textures)
	Storm3D2->active_material=0;

	// Set fog
	if (fog_active)
	{
		// psd: no pixel fog for shaders
		// psd: disable fog table
		GLfloat fogc[4];
		fogc[0] = fog_color.r;
		fogc[1] = fog_color.g;
		fogc[2] = fog_color.b;
		fogc[3] = 0;
		glFogfv(GL_FOG_COLOR, fogc);
	}

	Storm3D_ShaderManager::GetSingleton()->ResetShader();
	Storm3D_ShaderManager::GetSingleton()->ClearCache();
	Storm3D_ShaderManager::GetSingleton()->setLightingShaders();

	// Render objects in list (to screen)
	for (int i=0;renderlist_obj[i];i++)
	{
		if(i == 0)
		{
			glActiveTexture(GL_TEXTURE0);
			glClientActiveTexture(GL_TEXTURE0);
			glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
			glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE);
			glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PRIMARY_COLOR);
			glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
			glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE);
			glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_PRIMARY_COLOR);
			glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE);
			glActiveTexture(GL_TEXTURE1);
			glClientActiveTexture(GL_TEXTURE1);
			glDisable(GL_TEXTURE_2D);
			glDisable(GL_TEXTURE_3D);
			glDisable(GL_TEXTURE_CUBE_MAP);
			glDisable(GL_ALPHA_TEST);
			glDisable(GL_BLEND);

			this->camera.Apply();
		}

		// Set shader constants
		Storm3D_Material *m = static_cast<Storm3D_Material *> (renderlist_obj[i]->mesh->GetMaterial());
		Storm3D_Model *mod = renderlist_obj[i]->parent_model;

		if(m)
		{
			Storm3D_ShaderManager::GetSingleton()->SetObjectAmbient(m->GetSelfIllumination());
			Storm3D_ShaderManager::GetSingleton()->SetObjectDiffuse(m->GetColor());
			Storm3D_Texture *t = (Storm3D_Texture *) m->GetBaseTexture();
		
			if(t)
			{
				t->Apply(0);
				glActiveTexture(GL_TEXTURE0);
				glClientActiveTexture(GL_TEXTURE0);
				glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
				glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
				glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE);
			}
			else
			{
				glActiveTexture(GL_TEXTURE0);
				glClientActiveTexture(GL_TEXTURE0);
				glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
				glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
				glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
			}

			int alphaType = m->GetAlphaType();
			if(alphaType == IStorm3D_Material::ATYPE_NONE)
			{
				glDisable(GL_BLEND);
			}
			else
			{
				glEnable(GL_BLEND);

				if(alphaType == IStorm3D_Material::ATYPE_ADD)
				{
					glBlendFunc(GL_SRC_ALPHA, GL_ONE);
				}
				else if(alphaType == IStorm3D_Material::ATYPE_MUL)
				{
					glBlendFunc(GL_ZERO, GL_SRC_COLOR);
				}
				else if(alphaType == IStorm3D_Material::ATYPE_USE_TRANSPARENCY)
				{
					glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
				}
				else if(alphaType == IStorm3D_Material::ATYPE_USE_TEXTRANSPARENCY || renderlist_obj[i]->force_alpha > 0.0001f)
				{
					glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
				}
			}

			Storm3D_ShaderManager::GetSingleton()->SetTextureOffset(m->getScrollOffset1());

		}
		else
		{
			Storm3D_ShaderManager::GetSingleton()->SetObjectAmbient(Color(1.f,1.f,1.f));
			Storm3D_ShaderManager::GetSingleton()->SetObjectDiffuse(Color(1.f,1.f,1.f));
		}

		Storm3D_ShaderManager::GetSingleton()->SetModelAmbient(mod->self_illumination + ambient);
		
		// Horrible ...
		{
			Storm3D_ShaderManager::GetSingleton()->setLightingParameters(false, false, 1);

			if(mod->type_flag == 0)
				Storm3D_ShaderManager::GetSingleton()->SetLight(0, VC3(-2.5f, 5.f, -10.f), COL(0.03f, 0.03f, 0.03f), 20.f);
			else
				Storm3D_ShaderManager::GetSingleton()->SetLight(0, VC3( 2.5f, 5.f, -10.f), COL(0.03f, 0.03f, 0.03f), 20.f);

			for(int i = 1; i < LIGHT_MAX_AMOUNT; ++i)
				Storm3D_ShaderManager::GetSingleton()->SetLight(i, VC3(), COL(), 1.f);
		}

		Storm3D_ShaderManager::GetSingleton()->SetSun(VC3(), 0.f);

		// Set correct shader
		Storm3D_ShaderManager::GetSingleton()->SetShader(renderlist_obj[i]);
		basic_shader.apply();

		if(!renderlist_obj[i]->parent_model->bones.empty())
		{
			renderlist_obj[i]->mesh->ReBuild();
			renderlist_obj[i]->mesh->RenderBuffers(renderlist_obj[i]);
		}

		glDisable(GL_BLEND);
	}

	glActiveTexture(GL_TEXTURE0);
	glClientActiveTexture(GL_TEXTURE0);
	glDisable(GL_TEXTURE_2D);
	glDisable(GL_TEXTURE_3D);
	glDisable(GL_TEXTURE_CUBE_MAP);
	glBindTexture(GL_TEXTURE_2D, 0);
	frozenbyte::storm::VertexShader::disable();

	// Set renderstates (for shadows/particles/sprites)
	//SPECULARENABLE OFF?
	glDisable(GL_FOG);
	//GL_NORMALIZE OFF?
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

	// Apply the original camera back!
	camera.Apply();

	// Render particles
	glEnable(GL_SCISSOR_TEST);
	if(terrains.empty())
		particlesystem->Render(this);
	glDisable(GL_SCISSOR_TEST);

	// Set renderstates for sprite rendering
	glActiveTexture(GL_TEXTURE0);
	glClientActiveTexture(GL_TEXTURE0);
	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
	glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE);
	glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PRIMARY_COLOR);
	glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
	glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE);
	glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_PRIMARY_COLOR);
	glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE);
	glActiveTexture(GL_TEXTURE1);
	glClientActiveTexture(GL_TEXTURE1);
	glDisable(GL_TEXTURE_2D);
	glDisable(GL_TEXTURE_3D);
	glDisable(GL_TEXTURE_CUBE_MAP);

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	// Renderstate for lines
	glDisable(GL_ALPHA_TEST);
	glEnable(GL_DEPTH_TEST);
	glDepthMask(GL_FALSE);

	// Textures off
	for (int i=0;i<3;i++)
	{
		glActiveTexture(GL_TEXTURE0 + i);
		glClientActiveTexture(GL_TEXTURE0 + i);
		glDisable(GL_TEXTURE_2D);
		glDisable(GL_TEXTURE_3D);
		glDisable(GL_TEXTURE_CUBE_MAP);
		glBindTexture(GL_TEXTURE_2D, 0);
	}

	// Render lines
	{
		frozenbyte::storm::setCulling(CULL_NONE);

		D3DXMATRIX dm;
		D3DXMatrixIdentity(dm);
		Storm3D_ShaderManager::GetSingleton()->SetWorldTransform(dm);

		if(!depth_lines.empty())
		{
			for(unsigned int i = 0; i < depth_lines.size(); ++i)
				depth_lines[i]->Render();
		}

		if(!no_depth_lines.empty())
		{
			glDisable(GL_DEPTH_TEST);

			for(unsigned int i = 0; i < no_depth_lines.size(); ++i)
				no_depth_lines[i]->Render();
			
			glEnable(GL_DEPTH_TEST);
		}

		frozenbyte::storm::setCulling(CULL_CCW);
	}

	// Debug rendering
	if(!debugTriangles.empty() || !debugLines.empty() || !debugPoints.empty())
	{
		D3DXMATRIX dm;
		D3DXMatrixIdentity(dm);
		Storm3D_ShaderManager::GetSingleton()->SetWorldTransform(dm);

		int vertexAmount = (debugTriangles.size() * 3) + (debugLines.size() * 2) + (debugPoints.size());

		frozenbyte::storm::VertexBuffer vertexBuffer;
		vertexBuffer.create(vertexAmount, sizeof(VXFORMAT_PSD), true);
		VXFORMAT_PSD *buffer = static_cast<VXFORMAT_PSD *> (vertexBuffer.lock());

		for(unsigned int i = 0; i < debugTriangles.size(); ++i)
		{
			const Debug3 &d = debugTriangles[i];
			DWORD color = d.color.GetAsD3DCompatibleARGB();
			
			buffer->color = color;
			buffer->position = d.p1;
			++buffer;
			buffer->color = color;
			buffer->position = d.p2;
			++buffer;
			buffer->color = color;
			buffer->position = d.p3;
			++buffer;
		}

		int lineOffset = debugTriangles.size() * 3;
		for(unsigned int i = 0; i < debugLines.size(); ++i)
		{
			const Debug2 &d = debugLines[i];
			DWORD color = d.color.GetAsD3DCompatibleARGB();
			
			buffer->color = color;
			buffer->position = d.p1;
			++buffer;
			buffer->color = color;
			buffer->position = d.p2;
			++buffer;
		}

		int pointOffset = lineOffset + (debugLines.size() * 2);
		for(unsigned int i = 0; i < debugPoints.size(); ++i)
		{
			const Debug1 &d = debugPoints[i];
			DWORD color = d.color.GetAsD3DCompatibleARGB();
			
			buffer->color = color;
			buffer->position = d.p1;
			++buffer;
		}

		vertexBuffer.unlock();
		applyFVF(FVF_VXFORMAT_PSD, sizeof(VXFORMAT_PSD));
		vertexBuffer.apply(0);

		frozenbyte::storm::VertexShader::disable();

		glActiveTexture(GL_TEXTURE0);
		glClientActiveTexture(GL_TEXTURE0);
		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
		glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE);
		glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PRIMARY_COLOR);
		glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
		glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_TEXTURE);
		glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PRIMARY_COLOR);
		glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
		glDisable(GL_BLEND);

		if(!debugTriangles.empty())
			glDrawArrays(GL_TRIANGLES, 0, 3 * debugTriangles.size());
		if(!debugLines.empty())
			glDrawArrays(GL_LINES, lineOffset, 2 * debugLines.size());
		if(!debugPoints.empty())
			glDrawArrays(GL_POINTS, pointOffset, debugPoints.size());

		glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE);
		glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PRIMARY_COLOR);
		glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
		glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE);
		glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_PRIMARY_COLOR);
		glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE);
		glEnable(GL_BLEND);
	}

	// Render bones. SLOOOOOOOOW!
	//draw_bones = true;

	// Ugly hack anyway
	//		-- psd
	if(draw_bones)
	{
		D3DXMATRIX dm;
		D3DXMatrixIdentity(dm);
		Storm3D_ShaderManager::GetSingleton()->SetWorldTransform(dm);

		for(set<IStorm3D_Model *>::iterator mit=models.begin();mit!=models.end();++mit)
		{
			// Typecast (to simplify code)
			Storm3D_Model *mod=(Storm3D_Model*)*mit;

			if(mod->bones.size() > 0)
			{
				glDisable(GL_DEPTH_TEST);
				glColor3f(1.0, 1.0, 1.0);

				if(true)
				{
					// applyFVF(D3DFVF_XYZ|D3DFVF_NORMAL, sizeof(VXFORMAT_PSD));
					glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

					for(unsigned int i = 0; i < mod->bones.size(); ++i)
					{
						Storm3D_Bone *b = mod->bones[i];
						float thickness = b->GetThickness();
						thickness = 0.01f;

						GLUquadric* mesh;
						mesh = gluNewQuadric();

						Matrix global_tm = b->GetTM();
						D3DXMATRIX tm;
						global_tm.GetAsD3DCompatible4x4(&tm.m[0][0]);
						tm._41 += (-thickness + (0.5f * b->GetLenght())) * tm._31;
						tm._42 += (-thickness + (0.5f * b->GetLenght())) * tm._32;
						tm._43 += (-thickness + (0.5f * b->GetLenght())) * tm._33;

						Storm3D_ShaderManager::GetSingleton()->SetWorldTransform(tm);
						gluCylinder(mesh, thickness, thickness, b->GetLenght() + 2*thickness, 4, 4);
					}

					glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
				}
			}
		}

		Storm3D_ShaderManager::GetSingleton()->SetWorldTransform(dm);
	}

	glDepthMask(GL_FALSE);
	glDisable(GL_DEPTH_TEST);
	glDisable(GL_ALPHA_TEST);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	Storm3D_SurfaceInfo screen = Storm3D2->GetScreenSize();
	glOrtho(0, screen.width, screen.height, 0, -1, 1);

	glBindBuffer(GL_ARRAY_BUFFER, 0);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

	// Render picturelist
	if(!render_mirrored)
	{
		for (list<Storm3D_Scene_PicList*>::iterator ip=piclist.begin();ip!=piclist.end();++ip)
		{
			// Typecast to simplify code
			Storm3D_Scene_PicList *pl=*ip;

			// Render it
			pl->Render();

			// Delete it
			delete pl;
		}
	}

	// Clear picturelist
	if(!render_mirrored)
	{
		piclist.clear();
		debugTriangles.clear();
		debugLines.clear();
		debugPoints.clear();
	}

	glEnable(GL_DEPTH_TEST);
	glDepthMask(GL_TRUE);
	glActiveTexture(GL_TEXTURE0);
	glDisable(GL_TEXTURE_2D);

	// End REAL scene rendering

	// Present the scene (flip)
	if (target)
		Storm3D2->SetRenderTarget(NULL);
	else if (flip)
		SDL_GL_SwapBuffers();
	//else if(!render_mirrored)
		//Storm3D2->D3DDevice->SetDepthStencilSurface(originalDepthBuffer);
}
コード例 #2
0
ファイル: main.cpp プロジェクト: cole1911/ImperialShuttle
void display()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();
    gluLookAt(2*cos(pi*alfa/180.0), Y, 2*sin(pi*alfa/180.0), 0.0, Y_look_at, 0.0, 0.0, 1.0, 0.0);

	mat_specular[0] = 0.0;
	mat_specular[1] = 0.0;
    mat_specular[2] = 0.0;
	   
	mat_diffuse[0] = 0.6;
	mat_diffuse[1] = 0.6;
    mat_diffuse[2] = 0.6;
	
	mat_shininess = 100.0;

	mat_ambient[0] = 1.0;
	mat_ambient[1] = 1.0;
	mat_ambient[2] = 1.0;
	
	light0_position[0] = 1.0;
	light0_position[1] = 1.0;
	light0_position[2] = 1.0;
	
	light0_specular[0] = 0.728;
	light0_specular[1] = 0.728;
	light0_specular[2] = 0.728;
		
	light0_diffuse[0] = 0.728;
	light0_diffuse[1] = 0.728;
	light0_diffuse[2] = 0.728;
	
    scene_ambient[0] = 0.728;
	scene_ambient[1] = 0.728;
	scene_ambient[2] = 0.728;

    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);

    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, scene_ambient);

	glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);

	glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1); //ustawienie œledzenie wektora obserwatora
	
	glLightfv(GL_LIGHT0, GL_POSITION, light0_position);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
    glLightfv(GL_LIGHT0, GL_SPECULAR, light0_specular);

	glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);	
	glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
	glMaterialf(GL_FRONT, GL_SHININESS, mat_shininess );

	lines();

	glPushMatrix();
	glTranslatef(-0.2, 0.0, 1.0);

	glEnable(GL_TEXTURE_2D);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

	// kokpit
	glInterleavedArrays(GL_C3F_V3F, 0, kokpit_przod),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, kokpit_tyl),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, kokpit_dol),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, kokpit_prawy),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, kokpit_lewy),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, kokpit_gora),
	rectangle();

	// korpus górny
	glInterleavedArrays(GL_C3F_V3F, 0, korpusGorny_dol),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, korpusGorny_gora),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, korpusGorny_przod),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, korpusGorny_tyl),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, korpusGorny_lewy),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, korpusGorny_prawy),
	rectangle();

	// korpus dolny
	glInterleavedArrays(GL_C3F_V3F, 0, korpusDolny_gora),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, korpusDolny_dol),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, korpusDolny_przod),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, korpusDolny_tyl),
	rectangle();
	glColor3f(0.728, 0.728, 0.728);
	glPushMatrix();
	glTranslatef(-0.25, 0.033, -1.35);
	gluCylinder(gluNewQuadric(), 0.068, 0.068, 0.85, 100, 100);
	glTranslatef(0.92, 0.0, 0.0);
	gluCylinder(gluNewQuadric(), 0.068, 0.068, 0.85, 100, 100);
	glPopMatrix();

	// mocowanie górnego skrzyd³a
	glInterleavedArrays(GL_C3F_V3F, 0, mocowanie_dol),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, mocowanie_gora),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, mocowanie_przod),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, mocowanie_tyl),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, mocowanie_prawy),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, mocowanie_lewy),
	rectangle();

	// górne skrzyd³o
	glInterleavedArrays(GL_C3F_V3F, 0, gorneSkrzydlo_prawy),
	pentagon();
	glInterleavedArrays(GL_C3F_V3F, 0, gorneSkrzydlo_lewy),
	pentagon();
	glInterleavedArrays(GL_C3F_V3F, 0, gorneSkrzydlo_5),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, gorneSkrzydlo_4),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, gorneSkrzydlo_3),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, gorneSkrzydlo_2),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, gorneSkrzydlo_1),
	rectangle();
	
	if(linie)
		siatka();

	// boczne skrzyd³a

	// lewe
	glPushMatrix();
	glTranslatef(0.707, 0.05, 0);
	glRotatef(-alfa2, 0, 0, 1);
	glTranslatef(-0.707, -0.05, 0);
	glInterleavedArrays(GL_C3F_V3F, 0, skrzydloDol_gora),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, skrzydloDol_dol),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, skrzydloDol_2),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, skrzydloDol_1),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, skrzydloGora_gora),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, skrzydloGora_dol),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, skrzydloGora_3),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, skrzydloGora_2),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, skrzydloGora_1),
	rectangle();
	if(linie)
	{
		glInterleavedArrays(GL_C3F_V3F, 0, skrzydloDol_gora_linie),
		rectangle_lines();
		glInterleavedArrays(GL_C3F_V3F, 0, skrzydloDol_dol_linie),
		rectangle_lines();
		glInterleavedArrays(GL_C3F_V3F, 0, skrzydloGora_gora_linie),
		rectangle_lines();
		glInterleavedArrays(GL_C3F_V3F, 0, skrzydloGora_dol_linie),
		rectangle_lines();
	}
	glPopMatrix();
	
	// prawe
	glPushMatrix();
	glTranslatef(-0.29, 0.05, 0);
	glRotatef(alfa2, 0, 0, 1);
	glTranslatef(0.29, -0.05, 0);
	glInterleavedArrays(GL_C3F_V3F, 0, skrzydloDol_gora2),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, skrzydloDol_dol2),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, skrzydloDol_4),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, skrzydloDol_3),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, skrzydloGora_gora2),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, skrzydloGora_dol2),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, skrzydloGora_6),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, skrzydloGora_5),
	rectangle();
	glInterleavedArrays(GL_C3F_V3F, 0, skrzydloGora_4),
	rectangle();
	if(linie)
	{
		glInterleavedArrays(GL_C3F_V3F, 0, skrzydloDol_gora_linie2),
		rectangle_lines();
		glInterleavedArrays(GL_C3F_V3F, 0, skrzydloDol_dol_linie2),
		rectangle_lines();
		glInterleavedArrays(GL_C3F_V3F, 0, skrzydloGora_gora_linie2),
		rectangle_lines();
		glInterleavedArrays(GL_C3F_V3F, 0, skrzydloGora_dol_linie2),
		rectangle_lines();
	}
	glPopMatrix();
	glPopMatrix();

	glFlush();
	glutSwapBuffers();
} 
コード例 #3
0
ファイル: mech.c プロジェクト: lain-dono/TinyGL
void
UpperLeg(char solid) {
	int i;
	GLUquadricObj *Hamstring = gluNewQuadric();
	GLUquadricObj *Knee = gluNewQuadric();
	GLUquadricObj *joint[2];

	glNewList(SOLID_MECH_UPPER_LEG, GL_COMPILE);
#ifdef LIGHT
	SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
#endif
	glColor3f(1.0, 1.0, 0.0);

	if (!solid) {
		gluQuadricDrawStyle(Hamstring, GLU_LINE);
		gluQuadricDrawStyle(Knee, GLU_LINE);
	}

	glTranslatef(0.0, -1.0, 0.0);
	Box(0.4, 1.0, 0.7, solid);
	glTranslatef(0.0, -0.65, 0.0);

	for (i = 0; i < 5; i++) {
		Box(1.2, 0.3, 1.2, solid);
		glTranslatef(0.0, -0.2, 0.0);
		Box(1.0, 0.1, 1.0, solid);
		glTranslatef(0.0, -0.2, 0.0);
	}

	glTranslatef(0.0, -0.15, -0.4);
	Box(2.0, 0.5, 2.0, solid);
	glTranslatef(0.0, -0.3, -0.2);
	glRotatef(90.0, 1.0, 0.0, 0.0);
#ifdef LIGHT
	SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
#endif
	glColor3f(0.5, 0.5, 0.5);
	gluCylinder(Hamstring, 0.6, 0.6, 3.0, 16, 10);
#ifdef LIGHT
	SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
#endif
	glColor3f(1.0, 1.0, 0.0);
	glRotatef(-90.0, 1.0, 0.0, 0.0);
	glTranslatef(0.0, -1.5, 1.0);
	Box(1.5, 3.0, 0.5, solid);
	glTranslatef(0.0, -1.75, -0.8);
	Box(2.0, 0.5, 2.0, solid);
	glTranslatef(0.0, -0.9, -0.85);
#ifdef LIGHT
	SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
#endif
	glColor3f(0.5, 0.5, 0.5);
	gluCylinder(Knee, 0.8, 0.8, 1.8, 16, 10);

	for (i = 0; i < 2; i++) {
		if (i) {
			glScalef(-1.0, 1.0, 1.0);
		}

		joint[i] = gluNewQuadric();

		if (!solid) {
			gluQuadricDrawStyle(joint[i], GLU_LINE);
		}

		if (i) {
			glTranslatef(0.0, 0.0, 1.8);
		}

		gluDisk(joint[i], 0.0, 0.8, 16, 10);

		if (i) {
			glTranslatef(0.0, 0.0, -1.8);
		}
	}

	glScalef(-1.0, 1.0, 1.0);
	glEndList();
}
コード例 #4
0
ファイル: mech.c プロジェクト: lain-dono/TinyGL
void
LowerLeg(char solid) {
	float k, l;
	GLUquadricObj *ankle = gluNewQuadric();
	GLUquadricObj *ankle_face[2], *joints;

#ifdef LIGHT
	SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
#endif
	glColor3f(1.0, 1.0, 0.0);

	for (k = 0.0; k < 2.0; k++) {
		for (l = 0.0; l < 2.0; l++) {
			glPushMatrix();
			glTranslatef(k, 0.0, l);
#ifdef LIGHT
			SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
#endif
			glColor3f(1.0, 1.0, 0.0);
			Box(1.0, 0.5, 1.0, solid);
			glTranslatef(0.0, -0.45, 0.0);
#ifdef LIGHT
			SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
#endif
			glColor3f(0.5, 0.5, 0.5);
#ifdef SPHERE
			joints = gluNewQuadric();

			if (!solid) {
				gluQuadricDrawStyle(joints, GLU_LINE);
			}

			gluSphere(joints, 0.2, 16, 16);
			free(joints);
#endif

			if (leg) {
				glRotatef((GLfloat) heel1, 1.0, 0.0, 0.0);
			} else {
				glRotatef((GLfloat) heel2, 1.0, 0.0, 0.0);
			}

			/* glTranslatef(0.0, -0.2, 0.0); */
			glTranslatef(0.0, -1.7, 0.0);
#ifdef LIGHT
			SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
#endif
			glColor3f(1.0, 1.0, 0.0);
			Box(0.25, 3.0, 0.25, solid);
			glTranslatef(0.0, -1.7, 0.0);
#ifdef LIGHT
			SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
#endif
			glColor3f(0.5, 0.5, 0.5);
#ifdef SPHERE
			joints = gluNewQuadric();

			if (!solid) {
				gluQuadricDrawStyle(joints, GLU_LINE);
			}

			gluSphere(joints, 0.2, 16, 16);
#endif

			if (leg) {
				glRotatef((GLfloat) - heel1, 1.0, 0.0, 0.0);
			} else {
				glRotatef((GLfloat) - heel2, 1.0, 0.0, 0.0);
			}

			glTranslatef(0.0, -0.45, 0.0);
#ifdef LIGHT
			SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
#endif
			glColor3f(1.0, 1.0, 0.0);
			Box(1.0, 0.5, 1.0, solid);

			if (!k && !l) {
				int j;

				glTranslatef(-0.4, -0.8, 0.5);

				if (leg) {
					glRotatef((GLfloat) ankle1, 1.0, 0.0, 0.0);
				} else {
					glRotatef((GLfloat) ankle2, 1.0, 0.0, 0.0);
				}

				glRotatef(90.0, 0.0, 1.0, 0.0);

				if (!solid) {
					gluQuadricDrawStyle(ankle, GLU_LINE);
				}

				gluCylinder(ankle, 0.8, 0.8, 1.8, 16, 10);

				for (j = 0; j < 2; j++) {
					ankle_face[j] = gluNewQuadric();

					if (!solid) {
						gluQuadricDrawStyle(ankle_face[j], GLU_LINE);
					}

					if (j) {
						glScalef(-1.0, 1.0, 1.0);
						glTranslatef(0.0, 0.0, 1.8);
					}

					gluDisk(ankle_face[j], 0.0, 0.8, 16, 10);

					if (j) {
						glTranslatef(0.0, 0.0, -1.8);
					}
				}

				glScalef(-1.0, 1.0, 1.0);
				glRotatef(-90.0, 0.0, 1.0, 0.0);
				glTranslatef(0.95, -0.8, 0.0);
				glCallList(SOLID_MECH_FOOT);
			}

			glPopMatrix();
		}
	}
}
コード例 #5
0
ファイル: mipmap.c プロジェクト: ened/glues
void render_scene()
{
   /* material properties for objects in scene */
   static GLfloat wall_mat[4]={1.0f, 1.0f, 1.0f, 1.0f};
   static GLfloat sphere_mat[4]={1.0f, 0.7f, 0.2f, 1.0f};
   static GLfloat sphere2_mat[4]={0.2f, 0.7f, 0.2f, 1.0f};
   static GLfloat sphere3_mat[4]={0.2f, 0.2f, 0.7f, 1.0f};
   static GLfloat cone_mat[4]={1.0f, 0.2f, 0.2f, 1.0f};
   GLfloat texcoords[4][2];
   GLfloat vertices[4][3];

   glVertexPointer(3, GL_FLOAT, 0, vertices);
   glTexCoordPointer(2, GL_FLOAT, 0, texcoords);

   /* Enable vertices and texcoords arrays */
   glEnableClientState(GL_VERTEX_ARRAY);
   glEnableClientState(GL_TEXTURE_COORD_ARRAY);

   glGetError();
   glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

   /* Note: wall verticies are ordered so they are all front facing this lets
      me do back face culling to speed things up.  */
   glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, wall_mat);

   /* floor */
   glEnable(GL_TEXTURE_2D);

   glNormal3f(0.f, 1.f, 0.f);

   /* Fill texture coordinates and vertices arrays */
   texcoords[0][0]=0;
   texcoords[0][1]=0;
   vertices[0][0]=-200.f;
   vertices[0][1]=-100.f;
   vertices[0][2]=-320.f;

   texcoords[1][0]=1;
   texcoords[1][1]=0;
   vertices[1][0]=200.f;
   vertices[1][1]=-100.f;
   vertices[1][2]=-320.f;

   texcoords[3][0]=1;
   texcoords[3][1]=1;
   vertices[3][0]=200.f;
   vertices[3][1]=400.f;
   vertices[3][2]=-2000.f;

   texcoords[2][0]=0;
   texcoords[2][1]=1;
   vertices[2][0]=-200.f;
   vertices[2][1]=400.f;
   vertices[2][2]=-2000.f;

   glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

   /* Draw Sphere */
   glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, sphere_mat);
   glPushMatrix();
   glTranslatef(0.0f, 0.0f, -400.f);
   glRotatef(-90.f, 1.f, 0.f, 0.f);
   glRotatef(rotate, 1.f, 0.0f, 0.0f);
   gluSphere(sphere, 24.0f, 30, 30);
   glPopMatrix();

   /* Draw Sphere 2 */
   glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, sphere2_mat);
   glPushMatrix();
   glTranslatef(-50.0f, 50.0f, -550.f);
   glRotatef(-90.f, 0.f, 1.f, 0.f);
   glRotatef(rotate, 1.f, 0.0f, 0.0f);
   gluSphere(sphere, 24.0f, 30, 30);
   glPopMatrix();

   /* Draw Sphere 3 */
   glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, sphere3_mat);
   glPushMatrix();
   glTranslatef(50.0f, 100.0f, -700.f);
   glRotatef(-90.f, 0.f, 0.f, 1.f);
   glRotatef(rotate, 1.f, 0.0f, 0.0f);
   gluSphere(sphere, 24.0f, 30, 30);
   glPopMatrix();

   /* Draw Cone */
   glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, cone_mat);
   glPushMatrix();
   glTranslatef(0.0f, 150.0f, -850.f);
   glRotatef(-90.f, 1.f, 0.f, 0.f);
   glRotatef(rotate, 0.0f, 0.0f, 1.0f);
   gluCylinder(cone, 20.0f, 0.0f, 60.0f, 40, 40);
   glPopMatrix();

   rotate+=1.0f;

   glDisable(GL_TEXTURE_2D);
   glDisableClientState(GL_TEXTURE_COORD_ARRAY);
   glDisableClientState(GL_VERTEX_ARRAY);

   if (glGetError())
   {
      printf("Oops! I screwed up my OpenGL ES calls somewhere\n");
   }
}
コード例 #6
0
ファイル: mech.c プロジェクト: lain-dono/TinyGL
void
UpperArm(char solid) {
	GLUquadricObj *upper = gluNewQuadric();
	GLUquadricObj *joint[2];
	GLUquadricObj *joint1[2];
	int i;

	glNewList(SOLID_MECH_UPPER_ARM, GL_COMPILE);
#ifdef LIGHT
	SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
#endif
	glColor3f(1.0, 1.0, 0.0);
	Box(1.0, 2.0, 1.0, solid);
	glTranslatef(0.0, -0.95, 0.0);
	glRotatef(90.0, 1.0, 0.0, 0.0);
#ifdef LIGHT
	SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2);
#endif
	glColor3f(0.5, 0.5, 0.5);

	if (!solid) {
		gluQuadricDrawStyle(upper, GLU_LINE);
	}

	gluCylinder(upper, 0.4, 0.4, 1.5, 16, 10);
#ifdef LIGHT
	SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess);
#endif
	glColor3f(1.0, 1.0, 0.0);
	glRotatef(-90.0, 1.0, 0.0, 0.0);
	glTranslatef(-0.4, -1.85, 0.0);
	glRotatef(90.0, 0.0, 1.0, 0.0);

	for (i = 0; i < 2; i++) {
		joint[i] = gluNewQuadric();

		if (!solid) {
			gluQuadricDrawStyle(joint[i], GLU_LINE);
		}

		if (i) {
			gluCylinder(joint[i], 0.5, 0.5, 0.8, 16, 10);
		} else {
			gluCylinder(joint[i], 0.2, 0.2, 0.8, 16, 10);
		}
	}

	for (i = 0; i < 2; i++) {
		if (i) {
			glScalef(-1.0, 1.0, 1.0);
		}

		joint1[i] = gluNewQuadric();

		if (!solid) {
			gluQuadricDrawStyle(joint1[i], GLU_LINE);
		}

		if (i) {
			glTranslatef(0.0, 0.0, 0.8);
		}

		gluDisk(joint1[i], 0.2, 0.5, 16, 10);

		if (i) {
			glTranslatef(0.0, 0.0, -0.8);
		}
	}

	glScalef(-1.0, 1.0, 1.0);
	glRotatef(-90.0, 0.0, 1.0, 0.0);
	glTranslatef(0.4, 2.9, 0.0);
	glEndList();
}
コード例 #7
0
void display(void){
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	gluLookAt(xView,yView,zView,0.0,0.0,0.0,0.0,1.0,0.0);

	glMaterialfv(GL_FRONT,GL_DIFFUSE,cylindar[0]);
	glMaterialfv(GL_FRONT,GL_SPECULAR,cylindar[1]);
	glMaterialfv(GL_FRONT,GL_AMBIENT,cylindar[2]);
	glMaterialf(GL_FRONT,GL_SHININESS,shininess);
	
	glDisable(GL_LIGHTING);
	glLineWidth(1.0);
	glColor3f(0,0,0);
	drawAxe(axeCenter2,translateSpeed2);
	drawAxe(axeCenter1,translateSpeed1);
	print(10,20,"Press F1 to increase I1",0);
	glLineWidth(2.7);
	glColor3f(0,0.8,0);
	print(screenWidth/2,screenHeight*0.2,"I2",2);
	print(screenWidth/2,screenHeight*0.2,"I1",1);
	drawArrowCurrent(axeCenter1-cylindarRadius,6,sameDirection,translateSpeed1,translateSpeedAxe1);			//CRTANJE 1. STRUJE!
	drawArrowCurrent(axeCenter2+cylindarRadius,6,true,translateSpeed2,translateSpeedAxe2);			//necemo mijenjati smijer druge strelice!	crtanje 2. struje!
	if(sameDirection){
		if(translateSpeedAxe1>-yView)
			translateSpeedAxe1=translateSpeedAxe1-0.0005;
		else 
			translateSpeedAxe1=0;
		if(translateSpeedAxe2>-yView)
			translateSpeedAxe2=translateSpeedAxe2-0.0005;
		else
			translateSpeedAxe2=0;
		}
	else{
		if(translateSpeedAxe1<0) 
			translateSpeedAxe1=translateSpeedAxe1+0.0005;
		else
			translateSpeedAxe1=-yView;
		if(translateSpeedAxe2>-yView)
			translateSpeedAxe2=translateSpeedAxe2-0.0005;
		else
			translateSpeedAxe2=0;
	}
		
///------------------------------------------CRTANJE SILE---------------------------------------------------------
	glColor3f(1,0,0);
	if(!sameDirection){  //OVAJ DIO JE TESKO GENERALIZOVATI!
	glPushMatrix();
		glTranslatef(translateSpeed1,0,0);
		glBegin(GL_LINES);
			glVertex2f(axeCenter1-cylindarRadius,-5);
			glVertex2f(axeCenter1-cylindarRadius-lengthArrow,-5);
		glEnd();
	glPopMatrix();
	glPushMatrix(); 
	glTranslatef(translateSpeed1,0,0);
		glBegin(GL_TRIANGLES);
			glVertex2f(axeCenter1-cylindarRadius-lengthArrow-triangleSize,-5);
			glVertex2f(axeCenter1-cylindarRadius-lengthArrow,-4.5);
			glVertex2f(axeCenter1-cylindarRadius-lengthArrow,-5.5);
		glEnd();
	glPopMatrix();

	glPushMatrix();
		glTranslatef(translateSpeed2,0,0);
		glBegin(GL_LINES);
			glVertex2f(axeCenter2+cylindarRadius,-5);
			glVertex2f(axeCenter2+cylindarRadius+lengthArrow,-5);
		glEnd();
	glPopMatrix();
	glPushMatrix(); 
	glTranslatef(translateSpeed2,0,0);
		glBegin(GL_TRIANGLES);
		glVertex2f(axeCenter2+cylindarRadius+lengthArrow+triangleSize,-5);
			glVertex2f(axeCenter2+cylindarRadius+lengthArrow,-4.5);
			glVertex2f(axeCenter2+cylindarRadius+lengthArrow,-5.5);
		glEnd();
	glPopMatrix();
	}
	else {
		glPushMatrix();
		glTranslatef(translateSpeed1,0,0);
		glBegin(GL_LINES);
			glVertex2f(axeCenter1+cylindarRadius,-5);
			glVertex2f(axeCenter1+cylindarRadius+lengthArrow,-5);
		glEnd();
	glPopMatrix();
	glPushMatrix(); 
	glTranslatef(translateSpeed1,0,0);
		glBegin(GL_TRIANGLES);
			glVertex2f(axeCenter1+cylindarRadius+lengthArrow+triangleSize,-5);
			glVertex2f(axeCenter1+cylindarRadius+lengthArrow,-4.5);
			glVertex2f(axeCenter1+cylindarRadius+lengthArrow,-5.5);
		glEnd();
	glPopMatrix();

	glPushMatrix();
		glTranslatef(translateSpeed2,0,0);
		glBegin(GL_LINES);
				glVertex2f(axeCenter2-cylindarRadius,-5);
				glVertex2f(axeCenter2-cylindarRadius-lengthArrow,-5);
		glEnd();
	glPopMatrix();
	glPushMatrix(); 
	glTranslatef(translateSpeed2,0,0);
		glBegin(GL_TRIANGLES);
		glVertex2f(axeCenter2-cylindarRadius-lengthArrow-triangleSize,-5);
			glVertex2f(axeCenter2-cylindarRadius-lengthArrow,-4.5);
			glVertex2f(axeCenter2-cylindarRadius-lengthArrow,-5.5);
		glEnd();
	glPopMatrix();
	}
	print(screenWidth/2,screenHeight*0.84,"F1",2);
	print(screenWidth/2,screenHeight*0.84,"F2",1);
//-----------------------------CRTANJE VEKTORA MAGNETNE INDUKCIJE------------------------------------------------------------
	glColor3f(0,0,1);
	glPushMatrix();
		glTranslatef(translateSpeed1,0,0);
		glBegin(GL_LINES);
			glVertex3f(0,-5,-cylindarRadius);
			glVertex3f(0,-5,-(cylindarRadius+lengthArrow));
		glEnd();
	glPopMatrix();
	glPushMatrix(); 
	glTranslatef(translateSpeed1,0,0);
		glBegin(GL_TRIANGLES);
			glVertex3f(0,-5,-(cylindarRadius+lengthArrow+triangleSize));
			glVertex3f(0,-4.5,-(cylindarRadius+lengthArrow));
			glVertex3f(0,-5.5,-(cylindarRadius+lengthArrow));
		glEnd();
	glPopMatrix();

	if(sameDirection){ 
		glPushMatrix();
		glTranslatef(translateSpeed2,0,0);
		glBegin(GL_LINES);
			glVertex3f(5,-5,+cylindarRadius);
			glVertex3f(5,-5,cylindarRadius+lengthArrow);
		glEnd();
	glPopMatrix();
	glPushMatrix(); 
	glTranslatef(translateSpeed2,0,0);
		glBegin(GL_TRIANGLES);
			glVertex3f(5,-5,cylindarRadius+lengthArrow+triangleSize);
			glVertex3f(5,-4.5,cylindarRadius+lengthArrow);
			glVertex3f(5,-5.5,cylindarRadius+lengthArrow);
		glEnd();
	glPopMatrix();
	}
else {	
	glPushMatrix();
		glTranslatef(translateSpeed2,0,0);
		glBegin(GL_LINES);
			glVertex3f(5,-5,-cylindarRadius);
			glVertex3f(5,-5,-(cylindarRadius+lengthArrow));
		glEnd();
	glPopMatrix();
	glPushMatrix(); 
	glTranslatef(translateSpeed2,0,0);
		glBegin(GL_TRIANGLES);
			glVertex3f(5,-5,-(cylindarRadius+lengthArrow+triangleSize));
			glVertex3f(5,-4.5,-(cylindarRadius+lengthArrow));
			glVertex3f(5,-5.5,-(cylindarRadius+lengthArrow));
		glEnd();
	glPopMatrix();
	}

	glEnable(GL_LIGHTING);
	glRotatef(90,1,0,0);			//po defaultu cilindri orijentisani duz z ose!

	glPushMatrix();      //--------------------------------------------CRTANJE 1.CILINDRA------------------
		glTranslatef(translateSpeed1,0,0);
		gluCylinder(qobj, 0.5, 0.5, 10, 16, 20);
	glPopMatrix();
	if(sameDirection){	
		if(translateSpeed1<0.01)
			translateSpeed1=translateSpeed1+0.001;
		}
	else{
		if(translateSpeed1>-5.0)
			translateSpeed1=translateSpeed1-0.001; 
		}
	glDisable(GL_LIGHTING);				//-------------------------CRTANJE ELIPSI---------------
	glPushMatrix();
		glTranslatef(5,0,3);
		glColor3f(0,0,1);
		glLineWidth(1.0);
		for(int i=0;i<4;i++)
			spinEllipse(translateSpeed2,idEllipse[i]);
	glPopMatrix();
	glEnable(GL_LIGHTING);
	glPushMatrix();				//---------------------------------------------------------------------------CRTANJE 2. CILINDRA-
	glTranslatef(5, 0.0, 0.0);   
	glTranslatef(translateSpeed2,0,0);
    gluCylinder(qobj,0.5,0.5, 10, 16, 20);   //drugi cilindar pomijeren u odnosu na prethodni!
	if(sameDirection){
		if(translateSpeed2>-0.01)
			translateSpeed2=(translateSpeed2-0.001)*ratio;	//TREBA PROMIJENITI USLOV ZA RATIO!
	}
	else{
		if(translateSpeed2<5.0*ratio)
			translateSpeed2=(translateSpeed2+0.001)*ratio;  //povecava se, ide u desno!
	}
	glPopMatrix();
	glDisable(GL_LIGHTING);
	glTranslatef(0,0,3);
	glColor3f(0,0,1);
	for(int i=0;i<4;i++)
			spinEllipse(translateSpeed1,idEllipse[i]);
	glEnable(GL_LIGHTING);

	glFlush();
	glutSwapBuffers();
	glutPostRedisplay();
}
コード例 #8
0
ファイル: ltransgl.c プロジェクト: anyelacamargo/transsys
static int ltgl_graphics_primitive(const GRAPHICS_PRIMITIVE *gp, const TRANSSYS_INSTANCE *transsys_instance, TURTLE_STATE **ts, const RENDER_PARAMETERS *rp)
{
  double arg[GRAPHICS_PRIMITIVE_ARGMAX];
  int i;

  for (i = 0; i < gp->num_arguments; i++)
    arg[i] = evaluate_expression(gp->argument[i], &transsys_instance);
  switch (gp->type)
  {
  case GRAPHICS_PUSH:
    *ts = push_turtle_state(*ts);
    break;
  case GRAPHICS_POP:
    *ts = pop_turtle_state(*ts);
    ltgl_setcolor(*ts, rp);
    break;
  case GRAPHICS_MOVE:
    turtle_move(*ts, arg[0]);
    break;
  case GRAPHICS_TURN:
    turtle_turn(*ts, arg[0]);
    break;
  case GRAPHICS_ROLL:
    turtle_roll(*ts, arg[0]);
    break;
  case GRAPHICS_BANK:
    turtle_bank(*ts, arg[0]);
    break;
  case GRAPHICS_SPHERE:
    glPushMatrix();
    glTranslatef((*ts)->position.x, (*ts)->position.y, (*ts)->position.z);
    /* fprintf(stderr, "ltgl_graphics_primitive: sphere at (%f, %f, %f)\n", (*ts)->position.x, (*ts)->position.y, (*ts)->position.z); */
    ltgl_rotate_q(&((*ts)->orientation));
    gluSphere(glu_quadric_object, arg[0], 10, 7);
    glPopMatrix();
    break;
  case GRAPHICS_CYLINDER:
    glPushMatrix();
    glTranslatef((*ts)->position.x, (*ts)->position.y, (*ts)->position.z);
    ltgl_rotate_q(&((*ts)->orientation));
    glTranslatef(0.0, 0.0, -0.5 * arg[1]);
    gluQuadricOrientation(glu_quadric_object, GLU_INSIDE);
    gluDisk(glu_quadric_object, 0.0, arg[0], 10, 1);
    gluQuadricOrientation(glu_quadric_object, GLU_OUTSIDE);
    if (arg[1] > 0.0)
    {
      gluCylinder(glu_quadric_object, arg[0], arg[0], arg[1], 10, 1);
    }
    glTranslatef(0.0, 0.0, arg[1]);
    gluDisk(glu_quadric_object, 0.0, arg[0], 10, 1);
    glPopMatrix();
    break;
  case GRAPHICS_BOX:
    glPushMatrix();
    glTranslatef((*ts)->position.x, (*ts)->position.y, (*ts)->position.z);
    ltgl_rotate_q(&((*ts)->orientation));
    ltgl_box(arg[0], arg[1], arg[2]);
    glPopMatrix();
    break;
  case GRAPHICS_COLOR:
    (*ts)->red = arg[0];
    (*ts)->green = arg[1];
    (*ts)->blue = arg[2];
    ltgl_setcolor(*ts, rp);
    break;
  default:
    fprintf(stderr, "postscript_graphics_primitive: primitive type %d not implemented\n", (int) gp->type);
    return (-1);
  }
  return (0);
}
コード例 #9
0
ファイル: EntGhost.cpp プロジェクト: er1/c371pacmanglut
void EntGhost::draw() {
	// display logic goes here
	// draw the object at 0,0,0
	// x,y are the gameboard, z is 0 for the level
	// remember Z is up now

	//Draw ghosts
	GLUquadric *myQuad = TextureHandler::getInstance()->getQuadric();

	double red = color.x;
	double green = color.y;
	double blue = color.z;
	double alpha = 0.8;

	// color me
	glColor4d(red,green,blue,alpha);
	
	// texture me
	if (TextureHandler::getInstance()->getTexture()) {
		TextureHandler::getInstance()->use("ghost");
		glColor4d(red * 0.5 + 0.5, green * 0.5 + 0.5, blue * 0.5 + 0.5,alpha); // looks better for texturing
	} 

	if (scattering) {
		TextureHandler::getInstance()->use("pellet");
		glColor4d(0.3, 0.3, 1.0, 0.9); // looks better for texturing
	}

	if (!homebound) {
	glPushMatrix();
		// middle
		glTranslatef (0,0, -9);
		gluCylinder(myQuad, 6, 6, 9, 16, 16);
		glTranslatef (0,0, 9);
		
		// top
		glRotatef (90, 1, 0, 0.0);
		gluSphere(myQuad, 6, 16, 16);
		glRotatef (90,1, 0,0);
		glTranslatef (0,0, 9);
		gluDisk(myQuad, 0, 6, 16, 16);

		// bottom
		for (int angle = 0; angle < 360; angle += 40) {
			glPushMatrix();
				glRotatef (angle + roto, 0,0,1); // animate the bottom (:
				glTranslatef (4.5,0,0);
				gluCylinder(myQuad, 1.5,  0, 3, 16, 16);
			glPopMatrix();
		}
	glPopMatrix();
	
	// shadow
	glPushMatrix();
	TextureHandler::getInstance()->use("none");
	glColor4d(0,0,0,0.5);
	glTranslated(0,0,-14);
	gluDisk(myQuad, 0, 6, 16, 16);
	glPopMatrix();
	}

	TextureHandler::getInstance()->use("none");

	// eyes
	glPushMatrix();
		glColor3f(1,1,1);
		glTranslated(4,4,1);
		gluSphere(myQuad, 2, 8, 8);

		glColor3f(0,0,0);
		glTranslated(0,2,0);
		gluSphere(myQuad, 1, 8, 8);
	glPopMatrix();
	glPushMatrix();
		glColor3f(1,1,1);
		glTranslated(-4,4,1);
		gluSphere(myQuad, 2, 8, 8);

		glColor3f(0,0,0);
		glTranslated(0,2,0);
		gluSphere(myQuad, 1, 8, 8);
	glPopMatrix();

	// shadow
	// here is the best example to show how shadows are handled
	// everywhere else they ar assuming the model is a sphere which in most cases is correct

	glPushMatrix();
		TextureHandler::getInstance()->use("none"); // use a white texture
		glColor4d(0,0,0,0.5); // set it to show black with half opacity
		glTranslated(0,0,-14); // move it to our ground plane which we are using -14 for this
		glScaled(1,1,0); // flatten Z (orthographic projection to the ground plane)
		// draw again (same as above code minus color above)
		glPushMatrix();
			glTranslated(4,4,1);
			gluSphere(myQuad, 2, 8, 8);
			glTranslated(0,2,0);
			gluSphere(myQuad, 1, 8, 8);
		glPopMatrix();
		glPushMatrix();
			glTranslated(-4,4,1);
			gluSphere(myQuad, 2, 8, 8);
			glTranslated(0,2,0);
			gluSphere(myQuad, 1, 8, 8);
		glPopMatrix();
	glPopMatrix();

	glColor3d(0.4,1,0);

	vect s( 0.25 ); // scale
	vect d( 0, 0, 8 ); // translation

	// put our number on top of the ghost
	quad( vect(-4,5)  * s + d , vect(4,7)   * s + d );
	quad( vect(-4,-1) * s + d , vect(4,1)   * s + d );
	quad( vect(-4,-7) * s + d , vect(4,-5)  * s + d );
	quad( vect(-6,1)  * s + d , vect(-4,5)  * s + d );
	quad( vect(-6,-5) * s + d , vect(-4,-1) * s + d );
	quad( vect(4,-5)  * s + d , vect(6,-1)  * s + d );

}
コード例 #10
0
ファイル: submit.cpp プロジェクト: phileung/3280
void display(void) // Here's Where We Do All The Drawing
{	

	glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
	//srand( time(NULL) );
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	//glFrustum(-FRUSTDIM, FRUSTDIM, -FRUSTDIM, FRUSTDIM, 320., 640.);
	gluPerspective(45,1,1,600);
	//glTranslated(0,0,-320);
	gluLookAt( 0.0, 0, 242.0+pos_z,pos_x , pos_y, pos_z, 0, 1.0, 0.0);
	
	//light
	/* Initialize Lighting */
	//light1
	GLfloat light_pos1[] = {-FRUSTDIM-1,FRUSTDIM+1,-depth/2,1};
	GLfloat spot_dir1[] = {1,-1, 0};
	GLfloat light_amb1[] = {0.0, 0.0, 0.0, 1.0};
	GLfloat light_dif1[] = {1.0, 1.0, 1.0, 1.0};
	GLfloat light_spc1[] = {1.0, 1.0, 1.0, 1.0};
	glLightfv(GL_LIGHT1, GL_POSITION, light_pos1);
	glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 180.0);
	glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, spot_dir1);
	glLightfv(GL_LIGHT1, GL_AMBIENT, light_amb1);
	glLightfv(GL_LIGHT1, GL_DIFFUSE, light_dif1);
	glLightfv(GL_LIGHT1, GL_SPECULAR, light_spc1);
	//glEnable(GL_LIGHT1); // disabled by glDisable(GL_LIGHT0)
	//light2
	GLfloat light_pos2[] = {-FRUSTDIM+10,FRUSTDIM-10,-depth/2,1};
	GLfloat spot_dir2[] = {-1,1, 0};
	GLfloat light_amb2[] = {1.0, 1.0, 1.0, 1.0};
	GLfloat light_dif2[] = {1.0, 1.0, 1.0, 1.0};
	GLfloat light_spc2[] = {1.0, 1.0, 1.0, 1.0};
	glLightfv(GL_LIGHT2, GL_POSITION, light_pos2);
	glLightf(GL_LIGHT2, GL_SPOT_CUTOFF, 90.0);
	glLightfv(GL_LIGHT2, GL_SPOT_DIRECTION, spot_dir2);
	glLightfv(GL_LIGHT2, GL_AMBIENT, light_amb2);
	glLightfv(GL_LIGHT2, GL_DIFFUSE, light_dif2);
	glLightfv(GL_LIGHT2, GL_SPECULAR, light_spc2);
	if(light_s){
	glEnable(GL_LIGHT2); // disabled by glDisable(GL_LIGHT0)
	}
	else{
		glDisable(GL_LIGHT2);
	}
	glMatrixMode(GL_MODELVIEW);
	//
	//materials
	/* Initialize material properties */
	GLfloat no_mat[] = {0.0,0.0,0.0,1.0};
	GLfloat mat_diffuse[] = {1,1,1,0};
	GLfloat mat_specular[] = {1.0,1.0,1.0,1.0};
	GLfloat high_shininess[] = {100.0};
	glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_diffuse);
	glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
	glMaterialfv(GL_FRONT,GL_SHININESS,high_shininess);
	glMaterialfv(GL_FRONT,GL_EMISSION,no_mat);
	glEnable(GL_COLOR_MATERIAL);	
		
	// TODO:
	// Draw walls and objects here
		glPushMatrix();
			//glTranslated(-100/2, 100/2, 0.0);
			//left
			glBegin(GL_POLYGON);
				glColor3f(0.6, 0.6, 0.4); // white
				glVertex3f( -FRUSTDIM, FRUSTDIM, 0.0);
				glVertex3f( -FRUSTDIM, FRUSTDIM, -depth);
				glVertex3f(-FRUSTDIM, -FRUSTDIM, -depth);
				glVertex3f(-FRUSTDIM, -FRUSTDIM, 0.0);
			glEnd();
		glPopMatrix();
		glPushMatrix();
		//back
			glBegin(GL_POLYGON);
				glColor3f(0.6, 0.6, 0.4); // white
				glVertex3f( -FRUSTDIM, FRUSTDIM, -depth);
				glVertex3f(-FRUSTDIM, -FRUSTDIM, -depth);
				glVertex3f(FRUSTDIM,-FRUSTDIM,-depth);
				glVertex3f(FRUSTDIM,FRUSTDIM,-depth);
			glEnd();
		glPopMatrix();
		glPushMatrix();
		//right
			glBegin(GL_POLYGON);
				glColor3f(0.6, 0.6, 0.4); // white
				glVertex3f(FRUSTDIM,-FRUSTDIM,-depth);
				glVertex3f(FRUSTDIM,FRUSTDIM,-depth);
				glVertex3f(FRUSTDIM,FRUSTDIM,0);
				glVertex3f(FRUSTDIM,-FRUSTDIM,0);
			glEnd();			
		glPopMatrix();	
		glPushMatrix();
		//ceiling
			glBegin(GL_POLYGON);
				glColor3f(0.4, 0.4, 0.6); // white
				glVertex3f( -FRUSTDIM, FRUSTDIM, 0.0);
				glVertex3f( -FRUSTDIM, FRUSTDIM, -depth);
				glVertex3f(FRUSTDIM,FRUSTDIM,-depth);
				glVertex3f(FRUSTDIM,FRUSTDIM,0);
			glEnd();			
		glPopMatrix();
		glPushMatrix();
		//floor
			glBegin(GL_POLYGON);
				glColor3f(1.0, 0.5, 0); // white
				glVertex3f(-FRUSTDIM, -FRUSTDIM, -depth);
				glVertex3f(-FRUSTDIM, -FRUSTDIM, 0.0);
				glVertex3f(FRUSTDIM,-FRUSTDIM,0);
				glVertex3f(FRUSTDIM,-FRUSTDIM,-depth);
			glEnd();			
		glPopMatrix();
		//bed
		glPushMatrix();
			glTranslated(FRUSTDIM-FRUSTDIM/4,-FRUSTDIM+7.5,-depth+depth/4);
			//bed base
			glPushMatrix();
				glScalef( FRUSTDIM*0.5, 15.0, depth/2 );
				glutSolidCube(1.0);
			glPopMatrix();
			glPushMatrix();
				glTranslated(0,0,-depth/4);
				glScalef( FRUSTDIM*0.5, 50.0, 10 );
				glutSolidCube(1.0);
			glPopMatrix();			
			glTranslated(0,7.5,0);
			//sleep place
			glPushMatrix();
				glScalef( FRUSTDIM*0.5, 5.0, depth/2 );
				glColor3f(0, 1, 1.0);
				glutSolidCube(1.0);
			glPopMatrix();
			//pillow
			glTranslated(0,5,-depth/8+2);
			glPushMatrix();
				glScalef( FRUSTDIM*0.25, 2.0, 20 );
				glColor3f(1, 1, 0);
				glutSolidCube(1.0);
			glPopMatrix();
			//cover
			glTranslated(0,0,depth/4);
			glPushMatrix();
				glScalef( FRUSTDIM*0.4, 2.0, 50 );
				glColor3f(1, 0, 0);
				glutSolidCube(1.0);
			glPopMatrix();			
		glPopMatrix();
		//DESK
		glPushMatrix();
			glTranslated(-FRUSTDIM+30,-FRUSTDIM,-depth/2);
			//desk broad
			glPushMatrix();
			glTranslated(0,40,0);
				glScalef( 60, 3.0, 80 );
				//glColor3f(1, 0, 0);
				glutSolidCube(1.0);			
			glPopMatrix();
			//leg 1
			glPushMatrix();
			glTranslated(-25,20,35);
				glScalef( 5, 40.0, 5 );
				//glColor3f(1, 0, 0);
				glutSolidCube(1.0);			
			glPopMatrix();		
			//leg 2
			glPushMatrix();
			glTranslated(25,20,35);
				glScalef( 5, 40.0, 5 );
				//glColor3f(1, 0, 0);
				glutSolidCube(1.0);			
			glPopMatrix();
			//leg 3
			glPushMatrix();
			glTranslated(-25,20,-35);
				glScalef( 5, 40.0, 5 );
				//glColor3f(1, 0, 0);
				glutSolidCube(1.0);			
			glPopMatrix();
			//leg 4
			glPushMatrix();
			glTranslated(25,20,-35);
				glScalef( 5, 40.0, 5 );
				//glColor3f(1, 0, 0);
				glutSolidCube(1.0);			
			glPopMatrix();			
		glPopMatrix();
		//Chair
		glPushMatrix();
			
			glTranslated(-FRUSTDIM+CHAIR_dis,-FRUSTDIM,-depth/2);
			glRotatef(CHAIR_angle,0,1,0);
			//seat
			glPushMatrix();
			glTranslated(0,20,0);
				glScalef( 30, 3.0, 30 );
				//glColor3f(1, 0, 0);
				glutSolidCube(1.0);			
			glPopMatrix();
			//leg 1
			glPushMatrix();
			glTranslated(-12.5,10,12.5);
				glScalef( 4, 20.0, 4 );
				//glColor3f(1, 0, 0);
				glutSolidCube(1.0);			
			glPopMatrix();		
			//leg 2
			glPushMatrix();
			glTranslated(12.5,10,12.5);
				glScalef( 4, 20.0, 4 );
				//glColor3f(1, 0, 0);
				glutSolidCube(1.0);			
			glPopMatrix();
			//leg 3
			glPushMatrix();
			glTranslated(-12.5,10,-12.5);
				glScalef( 4, 20.0, 4 );
				//glColor3f(1, 0, 0);
				glutSolidCube(1.0);			
			glPopMatrix();
			//leg 4
			glPushMatrix();
			glTranslated(12.5,10,-12.5);
				glScalef( 4, 20.0, 4 );
				//glColor3f(1, 0, 0);
				glutSolidCube(1.0);			
			glPopMatrix();
			//chair back
			glPushMatrix();
			glTranslated(14,35,0);
				glScalef( 3, 30.0, 30 );
				//glColor3f(1, 0, 0);
				glutSolidCube(1.0);			
			glPopMatrix();			
		glPopMatrix();		
		//Fan
		//Fan base
		glPushMatrix();
			//glColor3f(1.0, 1, 1);
			glTranslated(0.0,FRUSTDIM-FRUSTDIM/16,-depth/4);
			glScalef( FRUSTDIM/4, FRUSTDIM/16, FRUSTDIM/4 );
			glColor3f(1.0, 1.0, 1.0);
			glutSolidCube(1.0);
		glPopMatrix();
		//Fan cylinder
		glPushMatrix();
			glColor3f(0.5, 0.5, 0.5);
			glTranslated(0.0,FRUSTDIM-FRUSTDIM/16,-depth/4);
			glRotatef(90,1,0,0);
			gluCylinder(qobj,2,2,16,16,16);
			glRotatef(-90,1,0,0);
			glTranslated(0.0,-16,0);
			glRotatef(90,1,0,0);
			gluCylinder(qobj,8,8,4,16,16);
		glPopMatrix();
		//Fan leave
		glPushMatrix();
			glTranslated(0.0,FRUSTDIM-FRUSTDIM/16-18,-depth/4);
			if (fan_s!=0){
				fan_angle = fan_angle + 1;
				
			}
			glRotatef(fan_angle,0,1,0);
			glScalef( FRUSTDIM/5, FRUSTDIM/5, FRUSTDIM/5 );
			glBegin(GL_TRIANGLE_FAN);
			glVertex3f(0.0, 0.0, 0.0);//y keep 0
			glVertex3f(2,0,0.5);
			glVertex3f(2,-0.0625,-0.5);
			glVertex3f(0.0, 0.0, 0.0);
			glVertex3f(0.5,0,-2);
			glVertex3f(-0.5,-0.0625,-2);
			glVertex3f(0.0, 0.0, 0.0);
			glVertex3f(-2,0,-0.5);
			glVertex3f(-2,-0.0625,0.5);		
			glVertex3f(0.0, 0.0, 0.0);
			glVertex3f(-0.5,0,2);
			glVertex3f(0.5,-0.0625,2);		
			glEnd();
		glPopMatrix();
		//light pipe
		glPushMatrix();
			glTranslated(-FRUSTDIM,FRUSTDIM,-depth/2);
			glPushMatrix();
				glScalef( 16, 16.0, 40 );
				glColor3f(1, 1, 1);
				glutSolidCube(1.0);	
			glPopMatrix();
			glPushMatrix();
				glTranslated(0,0,24);
				glScalef( 16, 16.0, 8 );
				glColor3f(0, 1, 1);
				glutSolidCube(1.0);	
			glPopMatrix();			
			glPushMatrix();
				glTranslated(0,0,-24);
				glScalef( 16, 16.0, 8 );
				glColor3f(0, 1, 1);
				glutSolidCube(1.0);	
			glPopMatrix();				
		glPopMatrix();
		//car 
		glPushMatrix();
			glTranslated(-FRUSTDIM+20+CAR_pos_x,-FRUSTDIM+10,-depth+10+CAR_pos_z);
			glRotatef(180+CAR_angle,0,1,0);		
			glScalef(2,2,2);
			glPushMatrix();
				//glTranslated(0,)
				glScalef( 10, 3.0, 5 );
				glColor3f(0, 1, 0);
				glutSolidCube(1.0);				
			glPopMatrix();
			//window
			glPushMatrix();
				glTranslated(0,0,2.51);
				glBegin(GL_POLYGON);
				glColor3f(1, 1, 1);
				glVertex3f(-3,0.9,0);
				glVertex3f(1,0.9,0);
				glVertex3f(1,-0.9,0);
				glVertex3f(-4,-0.9,0);
				glEnd();
			glPopMatrix();
			//window2
			glPushMatrix();
				glTranslated(0,0,-2.51);
				glBegin(GL_POLYGON);
				glColor3f(1, 1, 1);
				glVertex3f(-3,0.9,0);
				glVertex3f(1,0.9,0);
				glVertex3f(1,-0.9,0);
				glVertex3f(-4,-0.9,0);
				glEnd();
			glPopMatrix();
			//window3
			glPushMatrix();
				glTranslated(5.01,0,0);
				glBegin(GL_POLYGON);
				glColor3f(1, 1, 1);
				glVertex3f(0,0.9,-2);
				glVertex3f(0,0.9,2);
				glVertex3f(0,-0.9,2);
				glVertex3f(0,-0.9,-2);
				glEnd();
			glPopMatrix();
			//window4
			glPushMatrix();
				glTranslated(-5.01,0,0);
				glBegin(GL_POLYGON);
				glColor3f(1, 1, 1);
				glVertex3f(0,0.9,-2);
				glVertex3f(0,0.9,2);
				glVertex3f(0,-0.9,2);
				glVertex3f(0,-0.9,-2);
				glEnd();
			glPopMatrix();				
			glTranslated(-1,-3,0);
			glPushMatrix();
				glScalef( 18, 3.0, 5 );
				glColor3f(0, 1, 0);
				glutSolidCube(1.0);				
			glPopMatrix();
			//wheel
			glColor3f(0.2, 0.2, 0.2);
			glPushMatrix();
			glTranslated(-4,-1,-3);
			gluCylinder(qobj,RADIUS,RADIUS,6,16,16);
			
			glPopMatrix();
			glPushMatrix();
			glTranslated(4,-1,-3);
			gluCylinder(qobj,RADIUS,RADIUS,6,16,16);
			
			glPopMatrix();			
			//wheel1
			glPushMatrix();
				glTranslated(-4,-1,3);
				glBegin(GL_TRIANGLE_FAN);
				glVertex3f(0,0,0); // center of circle
				for (int i = 0; i <= 20; i++)   {
					glVertex2f (
						(0 + (RADIUS * cos(i * 2*PI / 20))), (0 + (RADIUS * sin(i * 2*PI / 20)))
						);
				}
				glEnd(); //END			
			glPopMatrix();			
			//wheel2
			glPushMatrix();
				glTranslated(4,-1,3);
				glBegin(GL_TRIANGLE_FAN);
				glVertex3f(0,0,0); // center of circle
				for (int i = 0; i <= 20; i++)   {
					glVertex2f (
						(0 + (RADIUS * cos(i * 2*PI / 20))), (0 + (RADIUS * sin(i * 2*PI / 20)))
						);
				}
				glEnd(); //END			
			glPopMatrix();	
			//wheel3
			glPushMatrix();
				glTranslated(4,-1,-3);
				glBegin(GL_TRIANGLE_FAN);
				glVertex3f(0,0,0); // center of circle
				for (int i = 0; i <= 20; i++)   {
					glVertex2f (
						(0 + (RADIUS * cos(i * 2*PI / 20))), (0 + (RADIUS * sin(i * 2*PI / 20)))
						);
				}
				glEnd(); //END			
			glPopMatrix();	
			//wheel4
			glPushMatrix();
				glTranslated(-4,-1,-3);
				glBegin(GL_TRIANGLE_FAN);
				glVertex3f(0,0,0); // center of circle
				for (int i = 0; i <= 20; i++)   {
					glVertex2f (
						(0 + (RADIUS * cos(i * 2*PI / 20))), (0 + (RADIUS * sin(i * 2*PI / 20)))
						);
				}
				glEnd(); //END			
			glPopMatrix();
			
		glPopMatrix();
		
	// TODO:
	// Add animation here
	glutSwapBuffers();
	glFlush();
	
	
}
コード例 #11
0
    void criaListas(){
        
        // modelagem hierarquica
        canhao.criaListas();

        id = glGenLists(1);

        idFundo = glGenLists(1);
        idConves = glGenLists(1);
        idLados = glGenLists(1);
        idPontas = glGenLists(1);
        idCabines = glGenLists(1);
        idBaseCanhao = glGenLists(1);
        idColetores = glGenLists(1);

        glNewList(id,GL_COMPILE); 
            glPushMatrix();
            glColor3f(1,1,0);
            glCallList(idFundo);
            glCallList(idConves);
            glColor3f(0.2,0,0);
            glCallList(idLados);
            glCallList(idPontas);
            glColor3f(0.2,0,0);
            glCallList(idCabines);
            glColor3f(0.15,0.15,0.15);
            glCallList(idBaseCanhao);
            glColor3f(0.2,0,0);
            glCallList(idColetores);
            glPopMatrix();
        glEndList();    

        // ----------------------------------------------------------------------------------------------

        glNewList(idFundo, GL_COMPILE);
            glPushMatrix();
            glRotatef(90,1,0,0);
            glBegin(GL_QUADS);
                glVertex3i(-TAM_DESTROIER/2,LARGURA_DESTROIER/2,0);
                glVertex3i(TAM_DESTROIER/2,LARGURA_DESTROIER/2,0);
                glVertex3i(TAM_DESTROIER/2,-LARGURA_DESTROIER/2,0);
                glVertex3i(-TAM_DESTROIER/2,-LARGURA_DESTROIER/2,0);
            glEnd();
            glPopMatrix();

            //triangulo fundo
            glPushMatrix();
            glRotatef(90,1,0,0);
            glBegin(GL_TRIANGLES);
                glVertex3i(-TAM_DESTROIER/2,LARGURA_DESTROIER/2,0);
                glVertex3i(-TAM_DESTROIER/2,-LARGURA_DESTROIER/2,0);
                glVertex3i(-TAM_DESTROIER/2-30,0,0);
            glEnd();
            glPopMatrix();

            //triangulo fundo
            glPushMatrix();
            glRotatef(90,1,0,0);
            glBegin(GL_TRIANGLES);
                glVertex3i(TAM_DESTROIER/2,LARGURA_DESTROIER/2,0);
                glVertex3i(TAM_DESTROIER/2,-LARGURA_DESTROIER/2,0);
                glVertex3i(TAM_DESTROIER/2+30,0,0);
            glEnd();
            glPopMatrix();

        glEndList();

        glNewList(idConves, GL_COMPILE);
            // conves
            glPushMatrix();
            glRotatef(90,1,0,0);
            glTranslatef(0,0,-LARGURA_DESTROIER);
            glBegin(GL_QUADS);
                glVertex3i(-TAM_DESTROIER/2,LARGURA_DESTROIER/2,0);
                glVertex3i(TAM_DESTROIER/2,LARGURA_DESTROIER/2,0);
                glVertex3i(TAM_DESTROIER/2,-LARGURA_DESTROIER/2,0);
                glVertex3i(-TAM_DESTROIER/2,-LARGURA_DESTROIER/2,0);
            glEnd();
            glPopMatrix();

            //triangulo conves
            glPushMatrix();
            glRotatef(90,1,0,0);
            glTranslatef(0,0,-LARGURA_DESTROIER);
            glBegin(GL_TRIANGLES);
                glVertex3i(-TAM_DESTROIER/2,LARGURA_DESTROIER/2,0);
                glVertex3i(-TAM_DESTROIER/2,-LARGURA_DESTROIER/2,0);
                glVertex3i(-TAM_DESTROIER/2-30,0,0);
            glEnd();
            glPopMatrix();

            //triangulo conves
            glPushMatrix();
            glRotatef(90,1,0,0);
            glTranslatef(0,0,-LARGURA_DESTROIER);
            glBegin(GL_TRIANGLES);
                glVertex3i(TAM_DESTROIER/2,LARGURA_DESTROIER/2,0);
                glVertex3i(TAM_DESTROIER/2,-LARGURA_DESTROIER/2,0);
                glVertex3i(TAM_DESTROIER/2+30,0,0);
            glEnd();
            glPopMatrix();
        glEndList();

        glNewList(idLados, GL_COMPILE);
            // lado 1
            glPushMatrix();
            glTranslatef(0,LARGURA_DESTROIER/2,LARGURA_DESTROIER/2);
            glBegin(GL_QUADS);
                glVertex3i(-TAM_DESTROIER/2,LARGURA_DESTROIER/2+5,0);
                glVertex3i(TAM_DESTROIER/2,LARGURA_DESTROIER/2+5,0);
                glVertex3i(TAM_DESTROIER/2,-LARGURA_DESTROIER/2-5,0);
                glVertex3i(-TAM_DESTROIER/2,-LARGURA_DESTROIER/2-5,0);
            glEnd();
            glPopMatrix();

            // lado 2
            glPushMatrix();
            glTranslatef(0,LARGURA_DESTROIER/2,-LARGURA_DESTROIER/2);
            glBegin(GL_QUADS);
                glVertex3i(-TAM_DESTROIER/2,LARGURA_DESTROIER/2+5,0);
                glVertex3i(TAM_DESTROIER/2,LARGURA_DESTROIER/2+5,0);
                glVertex3i(TAM_DESTROIER/2,-LARGURA_DESTROIER/2-5,0);
                glVertex3i(-TAM_DESTROIER/2,-LARGURA_DESTROIER/2-5,0);
            glEnd();
            glPopMatrix();
        glEndList();

        glNewList(idPontas, GL_COMPILE);
            // frente
            glPushMatrix();
            glTranslatef(0,LARGURA_DESTROIER/2,-LARGURA_DESTROIER/2);
            glBegin(GL_QUADS);
                glVertex3i(TAM_DESTROIER/2,LARGURA_DESTROIER/2+5,0);
                glVertex3i(TAM_DESTROIER/2+30,LARGURA_DESTROIER/2+5,20);
                glVertex3i(TAM_DESTROIER/2+30,-LARGURA_DESTROIER/2-5,20);
                glVertex3i(TAM_DESTROIER/2,-LARGURA_DESTROIER/2-5,0);
            glEnd();
            glPopMatrix();

            // frente
            glPushMatrix();
            glTranslatef(0,LARGURA_DESTROIER/2,LARGURA_DESTROIER/2);
            glBegin(GL_QUADS);
                glVertex3i(TAM_DESTROIER/2,LARGURA_DESTROIER/2+5,0);
                glVertex3i(TAM_DESTROIER/2+30,LARGURA_DESTROIER/2+5,-20);
                glVertex3i(TAM_DESTROIER/2+30,-LARGURA_DESTROIER/2-5,-20);
                glVertex3i(TAM_DESTROIER/2,-LARGURA_DESTROIER/2-5,0);
            glEnd();
            glPopMatrix();

            // frente
            glPushMatrix();
            glTranslatef(0,LARGURA_DESTROIER/2,-LARGURA_DESTROIER/2);
            glBegin(GL_QUADS);
                glVertex3i(-TAM_DESTROIER/2,LARGURA_DESTROIER/2+5,0);
                glVertex3i(-TAM_DESTROIER/2-30,LARGURA_DESTROIER/2+5,20);
                glVertex3i(-TAM_DESTROIER/2-30,-LARGURA_DESTROIER/2-5,20);
                glVertex3i(-TAM_DESTROIER/2,-LARGURA_DESTROIER/2-5,0);
            glEnd();
            glPopMatrix();

            glPushMatrix();
            glTranslatef(0,LARGURA_DESTROIER/2,LARGURA_DESTROIER/2);
            glBegin(GL_QUADS);
                glVertex3i(-TAM_DESTROIER/2,LARGURA_DESTROIER/2+5,0);
                glVertex3i(-TAM_DESTROIER/2-30,LARGURA_DESTROIER/2+5,-20);
                glVertex3i(-TAM_DESTROIER/2-30,-LARGURA_DESTROIER/2-5,-20);
                glVertex3i(-TAM_DESTROIER/2,-LARGURA_DESTROIER/2-5,0);
            glEnd();
            glPopMatrix();
        glEndList();


        glNewList(idCabines, GL_COMPILE);
            glPushMatrix();
            glTranslatef(0,45,0);
            glutSolidCube(25);
            glPopMatrix();
        glEndList();

        glNewList(idBaseCanhao, GL_COMPILE);
            glPushMatrix();
            glTranslatef(TAM_DESTROIER/2-60,55,0);
            glutSolidSphere(LARGURA_DESTROIER-30,20,20);
            glPopMatrix();
        glEndList();

        glNewList(idColetores, GL_COMPILE);
            glPushMatrix();
            glRotatef(90,90,0,0);
            glTranslatef(40,0,-60);
            gluCylinder(gluNewQuadric(), 2, 2, 30, 10, 10);
            glPopMatrix();

            glPushMatrix();
            glRotatef(90,90,0,0);
            glTranslatef(-40,0,-60);
            gluCylinder(gluNewQuadric(), 2, 2, 30, 10, 10);
            glPopMatrix();

        glEndList();


    }
コード例 #12
0
ファイル: snowman.cpp プロジェクト: reima/ogl-docs-mirror
// Called to draw scene
void RenderScene(void)
    {
    GLUquadricObj *pObj;	// Quadric Object
    
    // Clear the window with current clearing color
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Save the matrix state and do the rotations
    glPushMatrix();
        // Move object back and do in place rotation
        glTranslatef(0.0f, -1.0f, -5.0f);
        glRotatef(xRot, 1.0f, 0.0f, 0.0f);
        glRotatef(yRot, 0.0f, 1.0f, 0.0f);

        // Draw something
        pObj = gluNewQuadric();
        gluQuadricNormals(pObj, GLU_SMOOTH);
        
        // Main Body
        glPushMatrix();
            glColor3f(1.0f, 1.0f, 1.0f);
            gluSphere(pObj, .40f, 26, 13);  // Bottom
        
            glTranslatef(0.0f, .550f, 0.0f); // Mid section
            gluSphere(pObj, .3f, 26, 13);
        
            glTranslatef(0.0f, 0.45f, 0.0f); // Head
            gluSphere(pObj, 0.24f, 26, 13);
        
            // Eyes
            glColor3f(0.0f, 0.0f, 0.0f);
            glTranslatef(0.1f, 0.1f, 0.21f);
            gluSphere(pObj, 0.02f, 26, 13);
        
            glTranslatef(-0.2f, 0.0f, 0.0f);
            gluSphere(pObj, 0.02f, 26, 13);
        
            // Nose
            glColor3f(1.0f, 0.3f, 0.3f);
            glTranslatef(0.1f, -0.12f, 0.0f);
            gluCylinder(pObj, 0.04f, 0.0f, 0.3f, 26, 13);
        glPopMatrix();
        
        // Hat
        glPushMatrix();
            glColor3f(0.0f, 0.0f, 0.0f);
            glTranslatef(0.0f, 1.17f, 0.0f);
            glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
            gluCylinder(pObj, 0.17f, 0.17f, 0.4f, 26, 13);
            
            // Hat brim
            glDisable(GL_CULL_FACE);
            gluDisk(pObj, 0.17f, 0.28f, 26, 13);
            glEnable(GL_CULL_FACE);
            
            glTranslatef(0.0f, 0.0f, 0.40f);
            gluDisk(pObj, 0.0f, 0.17f, 26, 13);
        glPopMatrix();
        
    // Restore the matrix state
    glPopMatrix();

    // Buffer swap
    glutSwapBuffers();
    }
コード例 #13
0
/***************************************************************************
 DrawProt
 ****************************************************************************/
static void DrawProt(int snum){
    size_t i;
    float m[16];
    float *xaxis = &m[0],
	*up = &m[4],
	*at = &m[8];
    float comx = 0.0,
	comy = 0.0,
	comz = 0.0;
    struct coord *c = state->coords[snum];
    for (i=0; i<c->size; i++){
        comx += c->rp_ca[i].x;
        comy += c->rp_ca[i].y;
        comz += c->rp_ca[i].z;
    }
    comx /= c->size;
    comy /= c->size;
    comz /= c->size;
	
    
    GLUquadricObj *qobj;
    
    qobj = gluNewQuadric();
    gluQuadricDrawStyle(qobj, GLU_FILL);
    gluQuadricNormals(qobj, GLU_SMOOTH);
    
    gluQuadricTexture(qobj, GL_TRUE);
    
    glColor3f(0.0, 0.0, 1.0);
    for (i=0; i<c->size; i++){ 
        glPushMatrix();
        glTranslatef(c->rp_ca[i].x - comx, c->rp_ca[i].y - comy, c->rp_ca[i].z - comz);
        gluSphere(qobj, 0.5, 8, 8);
        glPopMatrix();
    }
    
    
    glColor4f(0.8, 0.8, 0.8, 1.0);
    
    if(snum%3 == 1){
        glColor3f(1.0, 0.0, 0.0);
    }
    else if(snum%3 == 2){
        glColor3f(0.0, 1.0, 0.0);
        
    }
    else{
        glColor3f(0.0, 1.0, 0.0);
    }
    
    for (i=1; i<c->size; i++){
        float dx, dy, dz;
        float mx, my, mz;
        float len;
		
        mx = c->rp_ca[i].x - comx;
        my = c->rp_ca[i].y - comy;
        mz = c->rp_ca[i].z - comz;
        glPushMatrix();
        glTranslatef(mx, my, mz);
        
        dx = c->rp_ca[i].x - c->rp_ca[i-1].x;
        dy = c->rp_ca[i].y - c->rp_ca[i-1].y;
        dz = c->rp_ca[i].z - c->rp_ca[i-1].z;
        len = sqrt(dx*dx + dy*dy + dz*dz);
        if(len < 4.9){
            at[0]= dx;
            at[1]= dy;
            at[2]= dz;
            normalize (at);
            // Make a useable copy of the current up vector.
            up[0] = 0.0; up[1] = 1.0; up[2] = 0.0;
            
            // Cross product of the new look at vector and the current
            //   up vector will produce a vector which is the new
            //   positive X axis of our transformed object.
            cross (xaxis, at, up);
            normalize (xaxis);
            
            // Calculate the new up vector, which will be the
            //   positive Y axis of our transformed object. Note
            //   that it will lie in the same plane as the new
            //   look at vector and the old up vector.
            cross (up, xaxis, at);
            
            // Account for the fact that the geometry will be defined to
            //   point along the negative Z axis.
            scale (at, -1.f);
            
            // Fill out the rest of the 4x4 matrix
            m[3] = 0.f;     // xaxis is m[0..2]
            m[7] = 0.f;     // up is m[4..6]
            m[11] = 0.f;    // -at is m[8..10]
            m[12] = 0.0; m[13] = 0.0; m[14] = 0.0;
            m[15] = 1.f;
            
            // Multiply onto current matrix stack.
            glPushMatrix();
            glMultMatrixf(m);
            gluCylinder(qobj, 0.5, 0.5, len, 8, 1);
            glPopMatrix();
        }
        glPopMatrix();
    }
    
}
コード例 #14
0
ファイル: Simulator.cpp プロジェクト: basson86/ASBR-CPP-2010
void Simulator::DrawGeometry(dGeomID geom)
{
    if(dGeomGetData(geom) == ((void *) &TYPE_OBSTACLE))
	glColor3d(0.8, 0.2, 0.2);
    else if(dGeomGetData(geom) == ((void *) &TYPE_TERRAIN))
	glColor3d(0.4, 0.5, 0.7);
    else //type robot
	glColor3d(0.0, 0, 1.0);
    
    
    const int    type = dGeomGetClass(geom);    
    const dReal *pos  = dGeomGetPosition(geom);
    const dReal *rot  = dGeomGetRotation(geom);
    double       m[16];
    
    glPushMatrix();
 
//transform position and orientation into an OpenGL matrix   
    m[0]  = rot[0];
    m[1]  = rot[4];
    m[2]  = rot[8];
    m[4]  = rot[1];
    m[5]  = rot[5];
    m[6]  = rot[9];
    m[8]  = rot[2];
    m[9]  = rot[6];
    m[10] = rot[10];
    m[3]  = m[7] = m[11] =  0;
    m[15] = 1;
    m[12] = pos[0];
    m[13] = pos[1];
    m[14] = pos[2];
    
    glMultMatrixd(m);
    
    if(type == dBoxClass)
    {
	dVector3 lengths;
	dGeomBoxGetLengths(geom, lengths);

	glPushMatrix();
	glScaled(lengths[0], lengths[1], lengths[2]);
	glutSolidCube(1.0);
	glPopMatrix();

    }
    else if(type == dSphereClass)
	glutSolidSphere(dGeomSphereGetRadius(geom), 20, 20);
    else if(type == dCylinderClass)
    {
	dReal r, length;
	dGeomCylinderGetParams(geom, &r, &length);
	glTranslated(0, 0, -0.5 * length);
	
	static GLUquadric *gluQuadric = NULL;
	if(gluQuadric == NULL)
	    gluQuadric = gluNewQuadric();
	gluCylinder(gluQuadric, r, r, length, 20, 20);
    }
    
    glPopMatrix();
}
コード例 #15
0
ファイル: gloss.c プロジェクト: MttDs/new-rexeno-tindpe
static void Init( int argc, char *argv[] )
{
   GLboolean convolve = GL_FALSE;
   GLboolean fullscreen = GL_FALSE;
   int i;

   for (i = 1; i < argc; i++) {
      if (strcmp(argv[i], "-info")==0) {
         printf("GL_RENDERER   = %s\n", (char *) glGetString(GL_RENDERER));
         printf("GL_VERSION    = %s\n", (char *) glGetString(GL_VERSION));
         printf("GL_VENDOR     = %s\n", (char *) glGetString(GL_VENDOR));
         printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
      }
      else if (strcmp(argv[i], "-c")==0) {
         convolve = GL_TRUE;
      }
      else if (strcmp(argv[i], "-f")==0) {
         fullscreen = GL_TRUE;
      }
   }

   if (fullscreen)
      glutFullScreen();

   /* Cylinder object */
   {
      static GLfloat height = 100.0;
      static GLfloat radius = 40.0;
      static GLint slices = 24;  /* pie slices around Z axis */
      static GLint stacks = 10;  /* subdivisions along length of cylinder */
      static GLint rings = 4;    /* rings in the end disks */
      GLUquadricObj *q = gluNewQuadric();
      assert(q);
      gluQuadricTexture(q, GL_TRUE);

      CylinderObj = glGenLists(1);
      glNewList(CylinderObj, GL_COMPILE);

      glPushMatrix();
      glTranslatef(0.0, 0.0, -0.5 * height);

      glMatrixMode(GL_TEXTURE);
      glLoadIdentity();
      /*glScalef(8.0, 4.0, 2.0);*/
      glMatrixMode(GL_MODELVIEW);

      /* cylinder */
      gluQuadricNormals(q, GL_SMOOTH);
      gluQuadricTexture(q, GL_TRUE);
      gluCylinder(q, radius, radius, height, slices, stacks);

      /* end cap */
      glMatrixMode(GL_TEXTURE);
      glLoadIdentity();
      glScalef(3.0, 3.0, 1.0);
      glMatrixMode(GL_MODELVIEW);

      glTranslatef(0.0, 0.0, height);
      gluDisk(q, 0.0, radius, slices, rings);

      /* other end cap */
      glTranslatef(0.0, 0.0, -height);
      gluQuadricOrientation(q, GLU_INSIDE);
      gluDisk(q, 0.0, radius, slices, rings);

      glPopMatrix();

      glMatrixMode(GL_TEXTURE);
      glLoadIdentity();
      glMatrixMode(GL_MODELVIEW);

      glEndList();
      gluDeleteQuadric(q);
   }

   /* Teapot */
   {
      TeapotObj = glGenLists(1);
      glNewList(TeapotObj, GL_COMPILE);

      glFrontFace(GL_CW);
      glutSolidTeapot(40.0);
      glFrontFace(GL_CCW);

      glEndList();
   }

   /* show cylinder by default */
   Object = CylinderObj;


   /* lighting */
   glEnable(GL_LIGHTING);
   {
      GLfloat pos[4] = { 3, 3, 3, 1 };
      glLightfv(GL_LIGHT0, GL_AMBIENT, Black);
      glLightfv(GL_LIGHT0, GL_DIFFUSE, White);
      glLightfv(GL_LIGHT0, GL_SPECULAR, White);
      glLightfv(GL_LIGHT0, GL_POSITION, pos);
      glEnable(GL_LIGHT0);
      glMaterialfv(GL_FRONT, GL_AMBIENT, Black);
      glMaterialf(GL_FRONT, GL_SHININESS, Shininess);
      glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
   }

   /* Base texture */
   glGenTextures(1, &BaseTexture);
   glBindTexture(GL_TEXTURE_2D, BaseTexture);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   if (!LoadRGBMipmaps(BASE_TEXTURE_FILE, GL_RGB)) {
      printf("Error: couldn't load texture image file %s\n", BASE_TEXTURE_FILE);
      exit(1);
   }

   /* Specular texture */
   glGenTextures(1, &SpecularTexture);
   glBindTexture(GL_TEXTURE_2D, SpecularTexture);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
   glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
   if (convolve) {
      /* use convolution to blur the texture to simulate a dull finish
       * on the object.
       */
      GLubyte *img;
      GLenum format;
      GLint w, h;
      GLfloat filter[FILTER_SIZE][FILTER_SIZE][4];

      for (h = 0; h < FILTER_SIZE; h++) {
         for (w = 0; w < FILTER_SIZE; w++) {
            const GLfloat k = 1.0 / (FILTER_SIZE * FILTER_SIZE);
            filter[h][w][0] = k;
            filter[h][w][1] = k;
            filter[h][w][2] = k;
            filter[h][w][3] = k;
         }
      }

      glEnable(GL_CONVOLUTION_2D);
      glConvolutionParameteri(GL_CONVOLUTION_2D,
                              GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
      glConvolutionFilter2D(GL_CONVOLUTION_2D, GL_RGBA,
                            FILTER_SIZE, FILTER_SIZE,
                            GL_RGBA, GL_FLOAT, filter);

      img = LoadRGBImage(SPECULAR_TEXTURE_FILE, &w, &h, &format);
      if (!img) {
         printf("Error: couldn't load texture image file %s\n",
                SPECULAR_TEXTURE_FILE);
         exit(1);
      }

      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0,
                   format, GL_UNSIGNED_BYTE, img);
      free(img);
   }
   else {
      /* regular path */
      if (!LoadRGBMipmaps(SPECULAR_TEXTURE_FILE, GL_RGB)) {
         printf("Error: couldn't load texture image file %s\n",
                SPECULAR_TEXTURE_FILE);
         exit(1);
      }
   }

   /* misc */
   glEnable(GL_CULL_FACE);
   glEnable(GL_TEXTURE_2D);
   glEnable(GL_DEPTH_TEST);
   glEnable(GL_NORMALIZE);

   glPolygonOffset( -1, -1 );
}
コード例 #16
0
ファイル: main.cpp プロジェクト: SamArmand/FlyingHelicopter
void drawHelicopter(void) {
    
    glRotatef(180, 0.0f, 1.0f, 0.0f);
    
    if (lightingEnabled) {
    
    if (headlight) {
        
        setHeadlight();
        
    }
    
    else {
        glDisable(GL_LIGHT1);
    }
        
    }
    
    
    glClearColor(0.49f, 0.75f, 0.93f, 1.0f);
    
    drawBody();
    
    //Tail
    glPushMatrix();
    
    glTranslatef(0.0f, 1.5f, -16.0f);
    glScalef(0.25f, 1.0f, 2.0f);
    glBegin(GL_POLYGON);
    gluCylinder(obj, 1.5, 1.5, 6, 100, 100);
    glEnd();
    glPopMatrix();
    
    //Back Body
    glPushMatrix();
    glScalef(1.33f, 1.0f, 1.0f);
    glTranslatef(0.0f, 0.0f, -6.0f);
    glutSolidSphere(3, 100, 100);
    glPopMatrix();
    
    drawCockpit();
    
    glColor3f(0.50f, 0.50f, 0.50f);
    //Front Left Leg
    glPushMatrix();
    glTranslatef(2.5f, -3.0f, 2.5f);
    glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
    glBegin(GL_POLYGON);
    gluCylinder(obj, 0.25, 0.25, 1, 100, 100);
    glEnd();
    glPopMatrix();
    
    //Back Left Leg
    glPushMatrix();
    glTranslatef(2.5f, -3.0f, -2.5f);
    glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
    glBegin(GL_POLYGON);
    gluCylinder(obj, 0.25, 0.25, 1, 100, 100);
    glEnd();
    
    glPopMatrix();
    
    //Front Right Leg
    glPushMatrix();
    glTranslatef(-2.5f, -3.0f, 2.5f);
    glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
    glBegin(GL_POLYGON);
    gluCylinder(obj, 0.25, 0.25, 1, 100, 100);
    glEnd();
    glPopMatrix();
    
    //Back Right Leg
    glPushMatrix();
    glTranslatef(-2.5f, -3.0f, -2.5f);
    glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
    glBegin(GL_POLYGON);
    gluCylinder(obj, 0.25, 0.25, 1, 100, 100);
    glEnd();
    glPopMatrix();
    
    glColor3f(0.25f, 0.25f, 0.25f);
    //Landing Ski Left
    glPushMatrix();
    glTranslatef(2.5f, -4.25f, 0.0f);
    glScalef(1.0f, 0.5f, 10.0f);
    glutSolidCube(1.0f);
    glPopMatrix();
    
    //Landing Ski Right
    glPushMatrix();
    glTranslatef(-2.5f, -4.25f, 0.0f);
    glScalef(1.0f, 0.5f, 10.0f);
    glutSolidCube(1.0f);
    glPopMatrix();
    
    glColor3f(0.33f, 0.42f, 0.18f);
    //Tail Fin
    glPushMatrix();
    glTranslatef(0.0f, 3.0f, -15.0f);
    glScalef(0.5f, 6.0f, 3.0f);
    glutSolidCube(1.0f);
    glPopMatrix();
    
    /*Rotors drawn in separate methods in case we want to rotate them at some point.
     It would be easier to modify the code that way. */
    
    // Draw top rotor
    glColor3f(0.50f, 0.50f, 0.50f);
    glPushMatrix();
    glTranslatef(0.0, 4.0, 0.0);
    glRotatef(bladeAngle, 0.0, 1.0, 0.0);
    drawBladeCap();
    glTranslatef(0.0, 1.0, 0.0);
    drawBlade();
    glRotatef(120.0, 0.0, 1.0, 0.0);
    drawBlade();
    glRotatef(120.0, 0.0, 1.0, 0.0);
    drawBlade();
    glPopMatrix();
    
    // Draw tail rotor
    glPushMatrix();
    glTranslatef(0.5, 4.5, -15.0);
    glScalef(0.3, 0.3, 0.3);
    glRotatef(-90.0, 0.0, 0.0, 1.0);
    glRotatef(bladeAngle, 0.0, 1.0, 0.0);
    drawBladeCap();
    glTranslatef(0.0, 0.5, 0.0);
    drawBlade();
    glRotatef(120.0, 0.0, 1.0, 0.0);
    drawBlade();
    glRotatef(120.0, 0.0, 1.0, 0.0);
    drawBlade();
    glPopMatrix();
    
    glColor3f(0.24f, 0.32f, 0.16f);
    //Left Wing
    glPushMatrix();
    glTranslatef(6.5f, 0.5f, -2.0f);
    glRotatef(-30.0f, 0.0f, 0.0f, 1.0f);
    glScalef(1.0f, 0.075f, 0.60f);
    glutSolidCube(8.0f);
    glPopMatrix();
    
    //Right Wing
    glPushMatrix();
    glTranslatef(-6.5f, 0.5f, -2.0f);
    glRotatef(30.0f, 0.0f, 0.0f, 1.0f);
    glScalef(1.0f, 0.075f, 0.60f);
    glutSolidCube(8.0f);
    glPopMatrix();
    
    //Tail Wings
    glPushMatrix();
    glTranslatef(0.0f, 1.5f, -11.0f);
    glScalef(1.0f, 0.10f, 0.5f);
    glutSolidCube(4.0f);
    glPopMatrix();
    
    glColor3f(0.50f, 0.50f, 0.50f);
    //Missile Launcher Left
    glPushMatrix();
    glTranslatef(6.0f, -0.25f, -5.0f);
    glBegin(GL_POLYGON);
    gluCylinder(obj, 1, 1, 6, 100, 100);
    glEnd();
    glPopMatrix();

    //Missile Launcher Right
    glPushMatrix();
    glTranslatef(-6.0f, -0.25f, -5.0f);
    glBegin(GL_POLYGON);
    gluCylinder(obj, 1, 1, 6, 100, 100);
    glEnd();
    glPopMatrix();
    
    glColor3f(0.25f, 0.25f, 0.25f);
    //Left Side Missile Head
    glPushMatrix();
    glTranslatef(6.0f, -0.25f, 1.0f);
    glutSolidSphere(1.0, 50, 50);
    glPopMatrix();
    
    //Right Side Missile Head
    glPushMatrix();
    glTranslatef(-6.0f, -0.25f, 1.0f);
    glutSolidSphere(1.0, 50, 50);
    glPopMatrix();
    
    //Machine gun
    glPushMatrix();
    glTranslatef(0.0f, -2.5f, 9.0f);
    glBegin(GL_POLYGON);
    gluCylinder(obj, 0.25, 0.25, 2, 100, 100);
    glEnd();
    glPopMatrix();
    
    
}
コード例 #17
0
ファイル: gltools.cpp プロジェクト: yangyang95/SpaceInvader
///////////////////////////////////////////////////////////////////
// Draw the unit axis. A small white sphere represents the origin
// and the three axes are colored Red, Green, and Blue, which 
// corresponds to positive X, Y, and Z respectively. Each axis has
// an arrow on the end, and normals are provided should the axes
// be lit. These are all built using the quadric shapes. For best
// results, put this in a display list.
void gltDrawUnitAxes(void)
	{
	GLUquadricObj *pObj;	// Temporary, used for quadrics
	
	// Measurements
	float fAxisRadius = 0.025f;
	float fAxisHeight = 1.0f;
	float fArrowRadius = 0.06f;
	float fArrowHeight = 0.1f;
	
	// Setup the quadric object
	pObj = gluNewQuadric();
	gluQuadricDrawStyle(pObj, GLU_FILL);
	gluQuadricNormals(pObj, GLU_SMOOTH);
	gluQuadricOrientation(pObj, GLU_OUTSIDE);
	gluQuadricTexture(pObj, GLU_FALSE);
	
	///////////////////////////////////////////////////////
	// Draw the blue Z axis first, with arrowed head
	glColor3f(0.0f, 0.0f, 1.0f);
	gluCylinder(pObj, fAxisRadius, fAxisRadius, fAxisHeight, 10, 1);
	glPushMatrix();
	glTranslatef(0.0f, 0.0f, 1.0f);
	gluCylinder(pObj, fArrowRadius, 0.0f, fArrowHeight, 10, 1);
    glRotatef(180.0f, 1.0f, 0.0f, 0.0f);
    gluDisk(pObj, fAxisRadius, fArrowRadius, 10, 1);
	glPopMatrix();
	
	///////////////////////////////////////////////////////
	// Draw the Red X axis 2nd, with arrowed head
    glColor3f(1.0f, 0.0f, 0.0f);
	glPushMatrix();
	glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
	gluCylinder(pObj, fAxisRadius, fAxisRadius, fAxisHeight, 10, 1);
	glPushMatrix();
	glTranslatef(0.0f, 0.0f, 1.0f);
	gluCylinder(pObj, fArrowRadius, 0.0f, fArrowHeight, 10, 1);
	glRotatef(180.0f, 0.0f, 1.0f, 0.0f);
	gluDisk(pObj, fAxisRadius, fArrowRadius, 10, 1);
	glPopMatrix();
	glPopMatrix();
	
	///////////////////////////////////////////////////////
	// Draw the Green Y axis 3rd, with arrowed head
	glColor3f(0.0f, 1.0f, 0.0f);
	glPushMatrix();
	glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
	gluCylinder(pObj, fAxisRadius, fAxisRadius, fAxisHeight, 10, 1);
	glPushMatrix();
	glTranslatef(0.0f, 0.0f, 1.0f);
	gluCylinder(pObj, fArrowRadius, 0.0f, fArrowHeight, 10, 1);
	glRotatef(180.0f, 1.0f, 0.0f, 0.0f);
	gluDisk(pObj, fAxisRadius, fArrowRadius, 10, 1);
	glPopMatrix();
	glPopMatrix();
	
	////////////////////////////////////////////////////////
	// White Sphere at origin
	glColor3f(1.0f, 1.0f, 1.0f);
	gluSphere(pObj, 0.05f, 15, 15);
	
	// Delete the quadric
	gluDeleteQuadric(pObj);
	}
コード例 #18
0
ファイル: city.c プロジェクト: deneb42/projetRobot
void createCity(char *chemin)
{
	int texId[14]; //A créer en même temps que toutes les variables. La taille depend du nombre de textures
	int i;

	GLUquadricObj* qobj;
	//GLUquadricObj* GLAPIENTRY qobj;

	// allocation d´une description de quadrique
	qobj = gluNewQuadric();
	// la quadrique est pleine
	gluQuadricDrawStyle(qobj, GLU_FILL);
	// les ombrages, s´il y en a, sont doux
	gluQuadricNormals(qobj, GLU_SMOOTH);

	load_textures(chemin, texId); // loading textures

	makeSky(texId[13]); // creating skybox

	glNewList(BORD, GL_COMPILE);
		glBegin(GL_POLYGON);
		glTexCoord2i(1,1);		glVertex3f(-150,-150,0);
		glTexCoord2i(1,0);		glVertex3f(-150,-150,5);
		glTexCoord2i(0,0);		glVertex3f(150,-150,5);
		glTexCoord2i(0,1);      glVertex3f(150,-150,0);
		glEnd();
	glEndList();


    //sol
    glNewList(FLOOR, GL_COMPILE);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D,texId[0]);

    glColor3f (1,1,1);
    glPushMatrix();
    glBegin(GL_POLYGON);
    glTexCoord2i(1,1);		glVertex3f(150,150,0);
    glTexCoord2i(1,0);		glVertex3f(150,-150,0);
    glTexCoord2i(0,0);		glVertex3f(-150,-150,0);
    glTexCoord2i(0,1);      glVertex3f(-150,150,0);
    glEnd();

    for(i=0;i<4;i++)
    {
    	glRotatef(90, 0, 0, 1);
    	glCallList(BORD);
    }

    glDisable(GL_TEXTURE_2D);
    glPopMatrix();
    glEndList();



    //batiment 1

    glNewList(BAT1, GL_COMPILE);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D,texId[1]);

    glPushMatrix();
    glTranslatef(20,20,0);

    glBegin(GL_QUADS);

    //4 faces latŽrales
    glTexCoord2i(0,0); glVertex3d(10,10,60);
    glTexCoord2i(0,4); glVertex3d(10,10,0);
    glTexCoord2i(4,4); glVertex3d(0,10,0);
    glTexCoord2i(4,0); glVertex3d(0,10,60);

    glTexCoord2i(0,0); glVertex3d(10,0,60);
    glTexCoord2i(0,4); glVertex3d(10,0,0);
    glTexCoord2i(4,4); glVertex3d(10,10,0);
    glTexCoord2i(4,0); glVertex3d(10,10,60);

    glTexCoord2i(0,0); glVertex3d(0,0,60);
    glTexCoord2i(0,4); glVertex3d(0,0,0);
    glTexCoord2i(4,4); glVertex3d(10,0,0);
    glTexCoord2i(4,0); glVertex3d(10,0,60);

    glTexCoord2i(0,0); glVertex3d(0,10,60);
    glTexCoord2i(0,4); glVertex3d(0,10,0);
    glTexCoord2i(4,4); glVertex3d(0,0,0);
    glTexCoord2i(4,0); glVertex3d(0,0,60);

    //sol
    glTexCoord2i(0,0); glVertex3d(10,10,0);
    glTexCoord2i(0,4); glVertex3d(10,0,0);
    glTexCoord2i(4,4); glVertex3d(0,0,0);
    glTexCoord2i(4,0); glVertex3d(0,10,0);

    //toit
    glTexCoord2i(0,0); glVertex3d(10,0,60);
    glTexCoord2i(0,4); glVertex3d(10,10,60);
    glTexCoord2i(4,4); glVertex3d(0,10,60);
    glTexCoord2i(4,0); glVertex3d(0,0,60);

    glEnd();

    glPopMatrix();

    glDisable(GL_TEXTURE_2D);
    glEndList();



    //batiment 2

    glNewList(BAT2, GL_COMPILE);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D,texId[2]);

    glPushMatrix();
    glTranslatef(30,-90,0);

    glBegin(GL_QUADS);

    //4 faces latŽrales
    glTexCoord2i(0,0); glVertex3d(15,15,90);
    glTexCoord2i(0,1); glVertex3d(15,15,0);
    glTexCoord2i(1,1); glVertex3d(0,15,0);
    glTexCoord2i(1,0); glVertex3d(0,15,90);

    glTexCoord2i(0,0); glVertex3d(15,0,90);
    glTexCoord2i(0,1); glVertex3d(15,0,0);
    glTexCoord2i(1,1); glVertex3d(15,15,0);
    glTexCoord2i(1,0); glVertex3d(15,15,90);

    glTexCoord2i(0,0); glVertex3d(0,0,90);
    glTexCoord2i(0,1); glVertex3d(0,0,0);
    glTexCoord2i(1,1); glVertex3d(15,0,0);
    glTexCoord2i(1,0); glVertex3d(15,0,90);

    glTexCoord2i(0,0); glVertex3d(0,15,90);
    glTexCoord2i(0,1); glVertex3d(0,15,0);
    glTexCoord2i(1,1); glVertex3d(0,0,0);
    glTexCoord2i(1,0); glVertex3d(0,0,90);

    //sol
    glTexCoord2i(0,0); glVertex3d(15,15,0);
    glTexCoord2i(0,1); glVertex3d(15,0,0);
    glTexCoord2i(1,1); glVertex3d(0,0,0);
    glTexCoord2i(1,0); glVertex3d(0,15,0);

    //toit
    glTexCoord2i(0,0); glVertex3d(15,0,90);
    glTexCoord2i(0,1); glVertex3d(15,15,90);
    glTexCoord2i(1,1); glVertex3d(0,15,90);
    glTexCoord2i(1,0); glVertex3d(0,0,90);

    glEnd();

    glPopMatrix();

    glDisable(GL_TEXTURE_2D);
    glEndList();



    //batiment3

    glNewList(BAT3,GL_COMPILE);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D,texId[3]);

    glPushMatrix();
    glTranslatef(60,80,0);

    glBegin(GL_QUADS);

    //4 faces latŽrales
    glTexCoord2i(0,0); glVertex3d(30,30,10);
    glTexCoord2i(0,1); glVertex3d(30,30,0);
    glTexCoord2i(1,1); glVertex3d(0,30,0);
    glTexCoord2i(1,0); glVertex3d(0,30,10);

    glTexCoord2i(0,0); glVertex3d(30,0,10);
    glTexCoord2i(0,1); glVertex3d(30,0,0);
    glTexCoord2i(1,1); glVertex3d(30,30,0);
    glTexCoord2i(1,0); glVertex3d(30,30,10);

    glTexCoord2i(0,0); glVertex3d(0,0,10);
    glTexCoord2i(0,1); glVertex3d(0,0,0);
    glTexCoord2i(1,1); glVertex3d(30,0,0);
    glTexCoord2i(1,0); glVertex3d(30,0,10);

    glTexCoord2i(0,0); glVertex3d(0,30,10);
    glTexCoord2i(0,1); glVertex3d(0,30,0);
    glTexCoord2i(1,1); glVertex3d(0,0,0);
    glTexCoord2i(1,0); glVertex3d(0,0,10);

    //sol
    glTexCoord2i(0,0); glVertex3d(30,30,0);
    glTexCoord2i(0,1); glVertex3d(30,0,0);
    glTexCoord2i(1,1); glVertex3d(0,0,0);
    glTexCoord2i(1,0); glVertex3d(0,30,0);

    //toit
    glTexCoord2i(0,0); glVertex3d(30,0,10);
    glTexCoord2i(0,1); glVertex3d(30,30,10);
    glTexCoord2i(1,1); glVertex3d(0,30,10);
    glTexCoord2i(1,0); glVertex3d(0,0,10);

    glEnd();

    glPopMatrix();

    glDisable(GL_TEXTURE_2D);
    glEndList();



    //batiment 4 conique

    glNewList(BAT4, GL_COMPILE);

    GLUquadricObj* quadric = gluNewQuadric();
    gluQuadricTexture(quadric, GLU_TRUE);

    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D,texId[10]);

    glPushMatrix();
    glTranslatef(0,-60,0);

    //glColor3f(0.5, 0.35, 0.05);
    gluCylinder(quadric, 5, 5, 40, 100, 100);
    glTranslatef(0,0,30);

    //glColor3f(0.5, 0.35, 0.05);
    gluCylinder(quadric, 5, 10, 30, 100, 100);
    glTranslatef(0, 0, 30);
    gluDisk(quadric,0,10,100,100);


    glPopMatrix();
    glDisable(GL_TEXTURE_2D);
    gluQuadricTexture(quadric, GLU_FALSE);
    glEndList();



    //batiment 5 avec sphere

    glNewList(BAT5, GL_COMPILE);

    GLUquadricObj* quadric2 = gluNewQuadric();
    gluQuadricTexture(quadric2, GLU_TRUE);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D,texId[11]);

    glPushMatrix();
    glTranslatef(-15,-15,0);

    glColor3f(0.01, 0.56, 0.61);
    gluCylinder(quadric2, 5, 5, 20, 100, 100);
    glTranslatef(0,0,20);

    glColor3f(0.01, 0.56, 0.61);
    gluSphere(quadric2, 10, 100, 100);


    glPopMatrix();
    glDisable(GL_TEXTURE_2D);
    gluQuadricTexture(quadric2, GLU_FALSE);
    glEndList();



    //batiment 6

    glNewList(BAT6, GL_COMPILE);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D,texId[4]);

    glPushMatrix();
    glTranslatef(-30,20,0);

    glBegin(GL_QUADS);

    //4 faces latŽrales
    glTexCoord2i(0,0); glVertex3d(20,20,70);
    glTexCoord2i(0,2); glVertex3d(20,20,0);
    glTexCoord2i(2,2); glVertex3d(0,20,0);
    glTexCoord2i(2,0); glVertex3d(0,20,70);

    glTexCoord2i(0,0); glVertex3d(20,0,70);
    glTexCoord2i(0,2); glVertex3d(20,0,0);
    glTexCoord2i(2,2); glVertex3d(20,20,0);
    glTexCoord2i(2,0); glVertex3d(20,20,70);

    glTexCoord2i(0,0); glVertex3d(0,0,70);
    glTexCoord2i(0,2); glVertex3d(0,0,0);
    glTexCoord2i(2,2); glVertex3d(20,0,0);
    glTexCoord2i(2,0); glVertex3d(20,0,70);

    glTexCoord2i(0,0); glVertex3d(0,20,70);
    glTexCoord2i(0,2); glVertex3d(0,20,0);
    glTexCoord2i(2,2); glVertex3d(0,0,0);
    glTexCoord2i(2,0); glVertex3d(0,0,70);

    //sol
    glTexCoord2i(0,0); glVertex3d(20,20,0);
    glTexCoord2i(0,2); glVertex3d(20,0,0);
    glTexCoord2i(2,2); glVertex3d(0,0,0);
    glTexCoord2i(2,0); glVertex3d(0,20,0);

    //toit
    glTexCoord2i(0,0); glVertex3d(20,0,70);
    glTexCoord2i(0,2); glVertex3d(20,20,70);
    glTexCoord2i(2,2); glVertex3d(0,20,70);
    glTexCoord2i(2,0); glVertex3d(0,0,70);

    glEnd();

    glPopMatrix();

    glDisable(GL_TEXTURE_2D);
    glEndList();



    //batiment 7
    glNewList(BAT7, GL_COMPILE);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D,texId[5]);

    glPushMatrix();
    glTranslatef(-70,-60,0);

    glBegin(GL_QUADS);

    //4 faces latŽrales
    glTexCoord2i(0,0); glVertex3d(25,25,5);
    glTexCoord2i(0,1); glVertex3d(25,25,0);
    glTexCoord2i(1,1); glVertex3d(0,25,0);
    glTexCoord2i(1,0); glVertex3d(0,25,5);

    glTexCoord2i(0,0); glVertex3d(25,0,5);
    glTexCoord2i(0,1); glVertex3d(25,0,0);
    glTexCoord2i(1,1); glVertex3d(25,25,0);
    glTexCoord2i(1,0); glVertex3d(25,25,5);

    glTexCoord2i(0,0); glVertex3d(0,0,5);
    glTexCoord2i(0,1); glVertex3d(0,0,0);
    glTexCoord2i(1,1); glVertex3d(25,0,0);
    glTexCoord2i(1,0); glVertex3d(25,0,5);

    glTexCoord2i(0,0); glVertex3d(0,25,5);
    glTexCoord2i(0,1); glVertex3d(0,25,0);
    glTexCoord2i(1,1); glVertex3d(0,0,0);
    glTexCoord2i(1,0); glVertex3d(0,0,5);

    //sol
    glTexCoord2i(0,0); glVertex3d(25,25,0);
    glTexCoord2i(0,1); glVertex3d(25,0,0);
    glTexCoord2i(1,1); glVertex3d(0,0,0);
    glTexCoord2i(1,0); glVertex3d(0,25,0);

    //toit
    glTexCoord2i(0,0); glVertex3d(25,0,5);
    glTexCoord2i(0,1); glVertex3d(25,25,5);
    glTexCoord2i(1,1); glVertex3d(0,25,5);
    glTexCoord2i(1,0); glVertex3d(0,0,5);

    glEnd();

    glPopMatrix();

    glDisable(GL_TEXTURE_2D);
    glEndList();



    //batiment 8
    glNewList(BAT8, GL_COMPILE);

    GLUquadricObj* quadric3 = gluNewQuadric();
    gluQuadricTexture(quadric3, GLU_TRUE);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D,texId[9]);

    glPushMatrix();
    glTranslatef(100, 50, 0);

    glColor3f(0.5, 0.37, 0.05);
    gluCylinder(quadric3, 10, 10, 90, 100, 100);
    glTranslatef(0, 0, 90);
    gluDisk(quadric3,0,10,100,100);

    glPopMatrix();
    glDisable(GL_TEXTURE_2D);
    gluQuadricTexture(quadric3, GLU_FALSE);
    glEndList();



    //batiment 9
    glNewList(BAT9, GL_COMPILE);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D,texId[6]);

    glPushMatrix();
    glTranslatef(-100,-120,0);

    glBegin(GL_QUADS);

    //4 faces latŽrales
    glTexCoord2i(0,0); glVertex3d(18,18,120);
    glTexCoord2i(0,1); glVertex3d(18,18,0);
    glTexCoord2i(1,1); glVertex3d(0,18,0);
    glTexCoord2i(1,0); glVertex3d(0,18,120);

    glTexCoord2i(0,0); glVertex3d(18,0,120);
    glTexCoord2i(0,1); glVertex3d(18,0,0);
    glTexCoord2i(1,1); glVertex3d(18,18,0);
    glTexCoord2i(1,0); glVertex3d(18,18,120);

    glTexCoord2i(0,0); glVertex3d(0,0,120);
    glTexCoord2i(0,1); glVertex3d(0,0,0);
    glTexCoord2i(1,1); glVertex3d(18,0,0);
    glTexCoord2i(1,0); glVertex3d(18,0,120);

    glTexCoord2i(0,0); glVertex3d(0,18,120);
    glTexCoord2i(0,1); glVertex3d(0,18,0);
    glTexCoord2i(1,1); glVertex3d(0,0,0);
    glTexCoord2i(1,0); glVertex3d(0,0,120);

    //sol
    glTexCoord2i(0,0); glVertex3d(18,18,0);
    glTexCoord2i(0,1); glVertex3d(18,0,0);
    glTexCoord2i(1,1); glVertex3d(0,0,0);
    glTexCoord2i(1,0); glVertex3d(0,18,0);

    //toit
    glTexCoord2i(0,0); glVertex3d(18,0,120);
    glTexCoord2i(0,1); glVertex3d(18,18,120);
    glTexCoord2i(1,1); glVertex3d(0,18,120);
    glTexCoord2i(1,0); glVertex3d(0,0,120);

    glEnd();
    glPopMatrix();
    glDisable(GL_TEXTURE_2D);
    glEndList();



    //batiment 10

    glNewList(BAT10, GL_COMPILE);

    GLUquadricObj* quadric4 = gluNewQuadric();
    gluQuadricTexture(quadric4, GLU_TRUE);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D,texId[7]);

    glPushMatrix();
    glTranslatef(100,-60,0);

    gluCylinder(quadric4, 30, 30, 10, 100, 100);
    glTranslatef(0,0,10);
	gluDisk(quadric4,0,30,100,100);

    gluSphere(quadric4, 10, 100, 100);

    glPopMatrix();
    glDisable(GL_TEXTURE_2D);
    gluQuadricTexture(quadric4, GLU_FALSE);
    glEndList();



    //batiment 11
    glNewList(BAT11, GL_COMPILE);

    GLUquadricObj* quadric5 = gluNewQuadric();
    gluQuadricTexture(quadric5, GLU_TRUE);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D,texId[8]);

    glPushMatrix();
    glTranslatef(-110,80,0);

    gluCylinder(quadric5, 10, 0, 95, 100, 100);

    glPopMatrix();
    glDisable(GL_TEXTURE_2D);
    gluQuadricTexture(quadric5, GLU_FALSE);
    glEndList();



    //batiment 12 sphere

    glNewList(BAT12, GL_COMPILE);

    GLUquadricObj* quadric6 = gluNewQuadric();
    gluQuadricDrawStyle(quadric6, GLU_FILL);
    gluQuadricNormals(quadric6, GLU_SMOOTH);
    gluQuadricTexture(quadric6, GLU_TRUE);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D,texId[12]);
	glColor3f(1, 1, 1);
    glPushMatrix();
    glTranslatef(-90,-60,0);
    glTranslatef(0,0,5);

    gluSphere(quadric6, 20, 100, 100);

    glPopMatrix();
    glDisable(GL_TEXTURE_2D);
    gluQuadricTexture(quadric6, GLU_FALSE);
    glEndList();


    //city
	glNewList(CITY, GL_COMPILE); // declaration de la liste City

		glCallList(SKY);
		glCallList(FLOOR);
		glCallList(BAT1);
		glCallList(BAT2);
		glCallList(BAT3);
		glCallList(BAT4);
		glCallList(BAT5);
		glCallList(BAT6);
		glCallList(BAT7);
		glCallList(BAT8);
		glCallList(BAT9);
		glCallList(BAT10);
		glCallList(BAT11);
		glCallList(BAT12);
	glEndList();
}
コード例 #19
0
void AntiGravModel::render(){
	TextureManager::getInstance()->enableTexture();

	GLUquadricObj *qGrav = gluNewQuadric();
	gluQuadricNormals(qGrav, GLU_SMOOTH);

	glPushMatrix();
        glTranslatef(0.125f, 0.2f, 0.125f);
		glScalef(0.5f, 0.5f, 0.5f);
    
		//first machine block
		drawMachineCube();

		//second machine block
		glTranslatef(1.0f,0.0f,0.0f);
		drawMachineCube();
		glTranslatef(-1.0f,0.0f,0.0f);

		//third machine block
		glTranslatef(1.0f,0.0f,1.0f);
		drawMachineCube();
		glTranslatef(-1.0f,0.0f,-1.0f);

		//fourth machine block
		glTranslatef(0.0f,0.0f,1.0f);
		drawMachineCube();
		glTranslatef(0.0f,0.0f,-1.0f);

		//rectangle
		glTranslatef(0.0f,0.8f,0.0f);
		glPushMatrix();
			glBindTexture(GL_TEXTURE_2D, TextureManager::getInstance()->getTextures("copper.bmp"));
			glBegin(GL_QUADS);
				glNormal3f(0.0f, 0.0f, -1.0f);
				glTexCoord2f(0.0f, 0.0f);
				glVertex3f(0.2f, 0.0f, 0.2f);
				glTexCoord2f(0.0f, 1.0f);
				glVertex3f(0.2f, 0.2f, 0.2f);
				glTexCoord2f(1.0f, 1.0f);
				glVertex3f(1.3f, 0.2f, 0.2f);
				glTexCoord2f(1.0f, 0.0f);
				glVertex3f(1.3f, 0.0f, 0.2f);

				glNormal3f(0.0f, 0.0f, 1.0f);
				glTexCoord2f(0.0f, 0.0f);
				glVertex3f(0.2f, 0.0f, 1.3f);
				glTexCoord2f(1.0f, 0.0f);
				glVertex3f(1.3f, 0.0f, 1.3f);
				glTexCoord2f(1.0f, 1.0f);
				glVertex3f(1.3f, 0.2f, 1.3f);
				glTexCoord2f(0.0f, 1.0f);
				glVertex3f(0.2f, 0.2f, 1.3f);
			glEnd();
	
			glBegin(GL_QUAD_STRIP);
				glNormal3f(-1.0f, 0.0f, 0.0f);
				glTexCoord2f(0.0f, 0.0f);
				glVertex3f(0.2f, 0.0f, 0.2f);
				glTexCoord2f(1.0f, 0.0f);
				glVertex3f(0.2f, 0.0f, 1.3f);
				glTexCoord2f(0.0f, 1.0f);
				glVertex3f(0.2f, 0.2f, 0.2f);
				glTexCoord2f(1.0f, 1.0f);
				glVertex3f(0.2f, 0.2f, 1.3f);

				glNormal3f(0.0f, 1.0f, 0.0f);
				glTexCoord2f(0.0f, 0.0f);
				glVertex3f(1.3f, 0.2f, 0.2f);
				glTexCoord2f(1.0f, 0.0f);
				glVertex3f(1.3f, 0.2f, 1.3f);

				glNormal3f(1.0f, 0.0f, 0.0f);
				glTexCoord2f(1.0f, 0.0f);
				glVertex3f(1.3f, 0.0f, 0.2f);
				glTexCoord2f(1.0f, 1.0f);
				glVertex3f(1.3f, 0.0f, 1.3f);

				glNormal3f(0.0f, -1.0f, 0.0f);
				glTexCoord2f(0.0f, 0.0f);
				glVertex3f(0.2f, 0.0f, 0.2f);
				glTexCoord2f(1.0f, 0.0f);
				glVertex3f(0.2f, 0.0f, 1.3f);
			glEnd();
		glPopMatrix();
		glTranslatef(0.0f,-0.8f,0.0f);

		glPushMatrix();
			glTranslatef(0.3f,1.0f,1.2f);
			teamNumber->render();
		glPopMatrix();
		TextureManager::getInstance()->enableTexture();
		//cylinder
		glTranslatef(1.0f,0.8f,1.0f);
		//glColor3f(1.0f,1.0f,1.0f);
		glBindTexture(GL_TEXTURE_2D, TextureManager::getInstance()->getTextures("copper.bmp"));
		gluQuadricTexture(qGrav,true);

		glPushMatrix();
			glRotatef(45, 0.0f, 1.0f, 0.0f);
			glRotatef(68, 1.0f, 0.0f, 0.0f);
			gluCylinder(qGrav, 0.1, 0.1, 0.6, 15, 15);
		glPopMatrix();
		glTranslatef(-1.0f,-0.8f,-1.0f);

		glTranslatef(0.4f, 0.8f, 1.0f);
		glPushMatrix();
			glRotatef(-45, 0.0f, 1.0f, 0.0f);
			glRotatef(68, 1.0f, 0.0f, 0.0f);
			gluCylinder(qGrav, 0.1, 0.1, 0.6, 15, 15);
		glPopMatrix();
		glTranslatef(-0.4f,-0.8f,-1.0f);

		glTranslatef(1.0f, 0.8f, 0.5f);
		glPushMatrix();
			glRotatef(135, 0.0f, 1.0f, 0.0f);
			glRotatef(68, 1.0f, 0.0f, 0.0f);
			gluCylinder(qGrav, 0.1, 0.1, 0.6, 15, 15);
		glPopMatrix();
		glTranslatef(-1.0f,-0.8f,-0.5f);

		glTranslatef(0.5f,0.8f,0.5f);
		glPushMatrix();
			glRotatef(-135, 0.0f, 1.0f, 0.0f);
			glRotatef(68, 1.0f, 0.0f, 0.0f);
			gluCylinder(qGrav, 0.1, 0.1, 0.6, 15, 15);
		glPopMatrix();
		glTranslatef(-0.5f,-0.8f,-0.5f);

	glPopMatrix();

    glTranslatef(0, 0.7f, 0);
	gluDeleteQuadric(qGrav);
}
コード例 #20
0
ファイル: Park.cpp プロジェクト: amcolash/cs559
void Flag::draw(DrawingState* ds){

	/* Draw flagpole */
	glPushMatrix();
	GLUquadricObj *quadric = gluNewQuadric();
	glColor4fv(&color.r);
	glRotated(-90, 1, 0, 0);
	gluCylinder(quadric, 2, 2, 100, 10, 10);
  gluDeleteQuadric(quadric);
  glPopMatrix();
	waveTime += .1*ds->speedup;

	if (!triedShader) {
		triedShader = true;
		char* error;
		if (!(shader = loadShader("Flag.vert", "Flag.frag", error))) {
			std::string s = "Can't Load Flag Shader:";
			s += error;
			fl_alert(s.c_str());
		}
	}

	if (shader != 0) {
		glUseProgram(shader);
		GLfloat waveWidth = 2.1, waveHeight = 1.3;
		GLint waveTimeLoc = glGetUniformLocation(shader, "waveTime");
		GLint waveWidthLoc = glGetUniformLocation(shader, "waveWidth");
		GLint waveHeightLoc = glGetUniformLocation(shader, "waveHeight");
		glUniform1f(waveTimeLoc, waveTime);
		glUniform1f(waveWidthLoc, waveWidth);
		glUniform1f(waveHeightLoc, waveHeight);
		
		GLint ambientLightLocation = glGetUniformLocation(shader, "ambient");
		glUniform1f(ambientLightLocation, ds->ambient);
		GLint lightLoc = glGetUniformLocation(shader, "light");
		glUniform4f(lightLoc, ds->lightPos[0], ds->lightPos[1], ds->lightPos[2], ds->lightPos[3]);
	}


	/* Draw flag */
	glPushMatrix();
	glTranslated(0, 90, 0);
	glRotated(90, 0, 1, 0);
	glNormal3f(-1, 0, 0);
	glBegin(GL_QUADS);
	glVertex3f(0, -20, 0);
	glVertex3f(0, 10, 0);
	glVertex3f(30, 10, 30);
	glVertex3f(30, -20, 30);
	glEnd();

	glBegin(GL_QUADS);
	glNormal3f(1, 0, 0);
	glVertex3f(30, -20, 30);
	glVertex3f(30, 10, 30);
	glVertex3f(0, 10, 0);
	glVertex3f(0, -20, 0);
	glEnd();

	glPopMatrix();
	glUseProgram(0);


}
コード例 #21
0
ファイル: Lesson42.cpp プロジェクト: kungfooman/easygl
	void Draw(gl_window_t *window) {
	RECT	rect;														// Holds Coordinates Of A Rectangle

	GetClientRect(window->hWnd, &rect);								// Get Window Dimensions
	int window_width=rect.right-rect.left;								// Calculate The Width (Right Side-Left Side)
	int window_height=rect.bottom-rect.top;								// Calculate The Height (Bottom-Top)

	// Update Our Texture... This Is The Key To The Programs Speed... Much Faster Than Rebuilding The Texture Each Time
	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, tex_data);

	glClear (GL_COLOR_BUFFER_BIT);										// Clear Screen

	for (int loop=0; loop<4; loop++)									// Loop To Draw Our 4 Views
	{
		glColor3ub(r[loop],g[loop],b[loop]);							// Assign Color To Current View

		
			//glClearColor(0, 0, 0, 0.5);

		if (loop==0)													// If We Are Drawing The First Scene
		{
			
			glClearColor(0, 0, 1, 0.5);

			// Set The Viewport To The Top Left.  It Will Take Up Half The Screen Width And Height
			glViewport (0, window_height/2, window_width/2, window_height/2);
			glMatrixMode (GL_PROJECTION);								// Select The Projection Matrix
			glLoadIdentity ();											// Reset The Projection Matrix
			// Set Up Ortho Mode To Fit 1/4 The Screen (Size Of A Viewport)
			gluOrtho2D(0, window_width/2, window_height/2, 0);
		}

		if (loop==1)													// If We Are Drawing The Second Scene
		{
			glClearColor(0, 1, 0, 0.5);
			// Set The Viewport To The Top Right.  It Will Take Up Half The Screen Width And Height
			glViewport (window_width/2, window_height/2, window_width/2, window_height/2);
			glMatrixMode (GL_PROJECTION);								// Select The Projection Matrix
			glLoadIdentity ();											// Reset The Projection Matrix
			// Set Up Perspective Mode To Fit 1/4 The Screen (Size Of A Viewport)
			gluPerspective( 45.0, (GLfloat)(width)/(GLfloat)(height), 0.1f, 500.0 ); 
		}

		if (loop==2)													// If We Are Drawing The Third Scene
		{
			
			glClearColor(1, 0, 0, 0.5);

			// Set The Viewport To The Bottom Right.  It Will Take Up Half The Screen Width And Height
			glViewport (window_width/2, 0, window_width/2, window_height/2);
			glMatrixMode (GL_PROJECTION);								// Select The Projection Matrix
			glLoadIdentity ();											// Reset The Projection Matrix
			// Set Up Perspective Mode To Fit 1/4 The Screen (Size Of A Viewport)
			gluPerspective( 45.0, (GLfloat)(width)/(GLfloat)(height), 0.1f, 500.0 ); 
		}

		if (loop==3)													// If We Are Drawing The Fourth Scene
		{
			glClearColor(0, 1, 1, 0.5);

			// Set The Viewport To The Bottom Left.  It Will Take Up Half The Screen Width And Height
			glViewport (0, 0, window_width/2, window_height/2);
			glMatrixMode (GL_PROJECTION);								// Select The Projection Matrix
			glLoadIdentity ();											// Reset The Projection Matrix
			// Set Up Perspective Mode To Fit 1/4 The Screen (Size Of A Viewport)
			gluPerspective( 45.0, (GLfloat)(width)/(GLfloat)(height), 0.1f, 500.0 ); 
		}

		glMatrixMode (GL_MODELVIEW);									// Select The Modelview Matrix
		glLoadIdentity ();												// Reset The Modelview Matrix

		glClear (GL_DEPTH_BUFFER_BIT);									// Clear Depth Buffer

		if (loop==0)													// Are We Drawing The First Image?  (Original Texture... Ortho)
		{
			glBegin(GL_QUADS);											// Begin Drawing A Single Quad
				// We Fill The Entire 1/4 Section With A Single Textured Quad.
				glTexCoord2f(1.0f, 0.0f); glVertex2i(window_width/2, 0              );
				glTexCoord2f(0.0f, 0.0f); glVertex2i(0,              0              );
				glTexCoord2f(0.0f, 1.0f); glVertex2i(0,              window_height/2);
				glTexCoord2f(1.0f, 1.0f); glVertex2i(window_width/2, window_height/2);
			glEnd();													// Done Drawing The Textured Quad
		}

		if (loop==1)													// Are We Drawing The Second Image?  (3D Texture Mapped Sphere... Perspective)
		{
			glTranslatef(0.0f,0.0f,-14.0f);								// Move 14 Units Into The Screen

			glRotatef(xrot,1.0f,0.0f,0.0f);								// Rotate By xrot On The X-Axis
			glRotatef(yrot,0.0f,1.0f,0.0f);								// Rotate By yrot On The Y-Axis
			glRotatef(zrot,0.0f,0.0f,1.0f);								// Rotate By zrot On The Z-Axis

			glEnable(GL_LIGHTING);										// Enable Lighting
			gluSphere(quadric,4.0f,32,32);								// Draw A Sphere
			glDisable(GL_LIGHTING);										// Disable Lighting
		}
		
		if (loop==2)													// Are We Drawing The Third Image?  (Texture At An Angle... Perspective)
		{
			glTranslatef(0.0f,0.0f,-2.0f);								// Move 2 Units Into The Screen
			glRotatef(-45.0f,1.0f,0.0f,0.0f);							// Tilt The Quad Below Back 45 Degrees.
			glRotatef(zrot/1.5f,0.0f,0.0f,1.0f);						// Rotate By zrot/1.5 On The Z-Axis

			glBegin(GL_QUADS);											// Begin Drawing A Single Quad
				glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, 0.0f);
				glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, 0.0f);
				glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 0.0f);
				glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 0.0f);
			glEnd();													// Done Drawing The Textured Quad
		}

		if (loop==3)													// Are We Drawing The Fourth Image?  (3D Texture Mapped Cylinder... Perspective)
		{
			glTranslatef(0.0f,0.0f,-7.0f);								// Move 7 Units Into The Screen
			glRotatef(-xrot/2,1.0f,0.0f,0.0f);							// Rotate By -xrot/2 On The X-Axis
			glRotatef(-yrot/2,0.0f,1.0f,0.0f);							// Rotate By -yrot/2 On The Y-Axis
			glRotatef(-zrot/2,0.0f,0.0f,1.0f);							// Rotate By -zrot/2 On The Z-Axis

			glEnable(GL_LIGHTING);										// Enable Lighting
			glTranslatef(0.0f,0.0f,-2.0f);								// Translate -2 On The Z-Axis (To Rotate Cylinder Around The Center, Not An End)
			gluCylinder(quadric,1.5f,1.5f,4.0f,32,16);					// Draw A Cylinder
			glDisable(GL_LIGHTING);										// Disable Lighting
		}
	}

	//glFlush ();															// Flush The GL Rendering Pipeline
	}
コード例 #22
0
ファイル: glwidget.cpp プロジェクト: martonmiklos/YARRH
  //draw axis
  void GlWidget::drawAxis()

  {
      GLdouble dAxisLength=1.0;
      GLdouble  dAxisRadius=0.05;
      GLdouble  dArrowLength=0.1;
      GLdouble  dArrowRadius=0.1;
      float     fScale=0.1;
      GLint     iSlices=32;
      GLint     iStacks=32;
      GLfloat   fColorX[4]={1.0,0.0,0.0,1.0};
      GLfloat   fColorY[4]={0.0,1.0,0.0,1.0};
      GLfloat   fColorZ[4]={0.0,0.0,1.0,1.0};
      bool      bSolid=true;
      bool      bBlend=true;
      GLdouble dArrowPosn = dAxisLength;// - (dArrowLength/2);
      GLfloat fCurrentColor[4];

      // Get the current color
      glGetFloatv(GL_CURRENT_COLOR, fCurrentColor);

      // Save the current transformation matrix..
      glPushMatrix();

      // Create a quadratic object used to draw our axis
      // cylinders and cones
      GLUquadricObj* pQuadric = gluNewQuadric();
      if(!pQuadric)
          return;

      // Set the quadric state
      gluQuadricNormals(pQuadric, GLU_SMOOTH);
      gluQuadricTexture(pQuadric, GL_FALSE);

      if(bSolid)
      {
          glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
          gluQuadricDrawStyle(pQuadric, GLU_FILL);
      }
      else
      {
          glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
          gluQuadricDrawStyle(pQuadric, GLU_LINE);
      }

      // Enable alpha blending?
      if(bBlend)
      {
          glEnable(GL_BLEND);
          glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
      }

      // Display a Sphere at the axis origin
      glColor4f(0.5f, 0.5f, 0.5f, 1.0f);
      gluSphere(pQuadric, dAxisRadius*fScale*2.5f, iSlices, iStacks);

      // Display the Z-Axis and arrow
      // Set the color
      glColor4fv(fColorZ);

      gluCylinder(pQuadric, dAxisRadius*fScale, dAxisRadius*fScale, dAxisLength*fScale, iSlices, iStacks);
      glTranslated(0.0f, 0.0f, dArrowPosn*fScale);    // Move to arrow position
      gluCylinder(pQuadric, dArrowRadius*fScale, 0.0f, dArrowLength*fScale, iSlices, iStacks);
      gluQuadricOrientation(pQuadric, GLU_INSIDE);
      gluDisk(pQuadric, 0.0f, dArrowRadius*fScale, iSlices, 1);
      gluQuadricOrientation(pQuadric, GLU_OUTSIDE);
      glTranslated(0.0f, 0.0f, -dArrowPosn*fScale);   // Move to 0, 0, 0


      // Display the X-Axis and arrow
      // Set the color
      glColor4fv(fColorX);

      glRotated(90, 0.0, 1.0, 0.0);                   // Rotate for X
      gluCylinder(pQuadric, dAxisRadius*fScale, dAxisRadius*fScale, dAxisLength*fScale, iSlices, iStacks);
      glTranslated(0.0f, 0.0f, dArrowPosn*fScale);    // Move to arrow position
      gluCylinder(pQuadric, dArrowRadius*fScale, 0.0f, dArrowLength*fScale, iSlices, iStacks);
      gluQuadricOrientation(pQuadric, GLU_INSIDE);
      gluDisk(pQuadric, 0.0f, dArrowRadius*fScale, iSlices, 1);
      gluQuadricOrientation(pQuadric, GLU_OUTSIDE);
      glTranslated(0.0f, 0.0f, -dArrowPosn*fScale);   // Move to 0, 0, 0


      // Display the Y-Axis and arrow
      // Set the color
      glColor4fv(fColorY);

      glRotated(-90, 1.0, 0.0, 0.0);                  // Rotate for Y
      gluCylinder(pQuadric, dAxisRadius*fScale, dAxisRadius*fScale, dAxisLength*fScale, iSlices, iStacks);
      glTranslated(0.0f, 0.0f, dArrowPosn*fScale);    // Move to arrow position
      gluCylinder(pQuadric, dArrowRadius*fScale, 0.0f, dArrowLength*fScale, iSlices, iStacks);
      gluQuadricOrientation(pQuadric, GLU_INSIDE);
      gluDisk(pQuadric, 0.0f, dArrowRadius*fScale, iSlices, 1);
      gluQuadricOrientation(pQuadric, GLU_OUTSIDE);
      glTranslated(0.0f, 0.0f, -dArrowPosn*fScale);   // Move to 0, 0, 0


      // Delete the quadric
      gluDeleteQuadric(pQuadric);

      // Restore the current transformation matrix..
      glPopMatrix();

      // Restore the current color
      glColor4fv(fCurrentColor);

      // Disable blend function
      glDisable(GL_BLEND);
  }
コード例 #23
0
ファイル: Source.cpp プロジェクト: minnipu/runningHorseOpenGL
//=========================================================//
//=========================================================//
GLvoid DrawHorse(FrameAngles gait)
{
	//Body of Horse
	glPushMatrix();
	glTranslated(horse.x, horse.y+.4, horse.z);
	glRotated(horse.angle, 0, 1, 0);
	glTranslated(0, 1, -.7);
	//DrawLinesXYZ();
	glColor3f(1.0, .57, .67);
	gluCylinder(g_normalObject, 0.35, 0.4, 1.4, 20, 8);
		glPushMatrix(); //make disk move relitive to cylinder
		gluDisk(g_normalObject, 0, 0.35, 20, 8);
		glTranslated(0, 0, 1.4);
		gluDisk(g_normalObject, 0, 0.4, 20, 8);
		glPopMatrix();
		
		//make neck bottom
		glPushMatrix();  
		glTranslatef(0, .4, 1.2);
		//
		glRotated(gait.neckbt, 1, 0, 0);
		gluCylinder(g_normalObject, 0.2, 0.19, 0.5, 20, 8);
			//make neck top
			glPushMatrix();
			glTranslatef(0, 0, 0.5);
			glRotated(gait.necktp, 1, 0, 0);
			gluCylinder(g_normalObject, 0.19, 0.10, 0.5, 20, 8);
				//make Head
				glPushMatrix();
				glTranslatef(0, 0, .5);
				glRotated(gait.head, 1, 0, 0);
				gluCylinder(g_normalObject, 0.2, 0.1, 0.6, 20, 8);
					//make Horn
					glPushMatrix();
					glTranslatef(0, 0.1, 0.2);
					glRotated(-90, 1, 0, 0);
					glColor3f(.5, 1.0, .80);
					gluCylinder(g_normalObject, 0.05, 0, 0.5, 20, 8);
					glPopMatrix();
				//DrawLinesXYZ();
				glPopMatrix();
				glColor3f(1.0, .57, .67);
			glPopMatrix();
		//	DrawLinesXYZ();
		glPopMatrix();

		
		//make Leg Left Front top
		glPushMatrix();
		glTranslatef(0.15, -.3, 1.3);
		glRotated(gait.frtLLegtp, 1, 0, 0);
	    //DrawLinesXYZ();
		gluCylinder(g_normalObject, 0.1, 0.1, 0.6, 20, 8);
			//make Leg Left Front bottom
			glPushMatrix();
			glTranslatef(0, 0, 0.5);
			glRotated(gait.frtLLegbt,10, 0, 0);
			gluCylinder(g_normalObject, 0.1, 0.13, 0.67, 20, 8);
			glPopMatrix();
		glPopMatrix();

		//make Leg Right Front top
		glPushMatrix();
		glTranslatef(-.15, -.3, 1.3);
		glRotated(gait.frtRLegtp, 1, 0, 0);
		gluCylinder(g_normalObject, 0.1, 0.1, 0.6, 20, 8);
			//make Leg Right Front bottom
			glPushMatrix();
			glTranslatef(0, 0, 0.5);
			glRotated(gait.frtRlegbt, 10, 0, 0);
			gluCylinder(g_normalObject, 0.1, 0.13, 0.67, 20, 8);
			glPopMatrix();
		glPopMatrix();
		
		//make Leg Left Back top
		glPushMatrix();
		glTranslatef(0.15, -.3, 0.15);
		glRotated(gait.bkLLegtp, 1, 0, 0);
		gluCylinder(g_normalObject, 0.15, 0.1, 0.6, 20, 8);
			//make left leg back bottom
			glPushMatrix();
			glTranslatef(0, 0, 0.5);
			glRotated(gait.bkLLegbt, -10, 0, 0);
			gluCylinder(g_normalObject, 0.1, 0.13, 0.67, 20, 8);
			glPopMatrix();
		//DrawLinesXYZ();
		glPopMatrix();

		//make right leg back top
		glPushMatrix();
		glTranslatef(-0.15, -.3, 0.15);
		glRotated(gait.bkRLegtp, 1, 0, 0);
		gluCylinder(g_normalObject, 0.15, 0.1, 0.6, 20, 8);
			//make right leg back bottom
			glPushMatrix();
			glTranslatef(0, 0, 0.5);
			glRotated(gait.bkRLegbt, -10, 0, 0);
			gluCylinder(g_normalObject, 0.1, 0.13, 0.67, 20, 8);
			glPopMatrix();
		glPopMatrix();

		//make tail
		glPushMatrix();
		glRotated(gait.tail, 1, 0,0 );
		glTranslated(0, 0.07, -0.5);
		gluCylinder(g_normalObject, 0.18, 0.1, 0.6, 20, 8);
		glPopMatrix();

	
	glPopMatrix(); //End Horse
}
コード例 #24
0
ファイル: compassWidget.cpp プロジェクト: markusk/direcs
void CompassWidget::paintGL()
{
	// clear last scene
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// reset modelview matrix
	glLoadIdentity();

	//----------------------- pfeile -------------------------
	glTranslated(0.0, 0.0, -10.0);

	// enable roation
	glRotatef(xRot / 16.0, 1.0, 0.0, 0.0);
	glRotatef(yRot / 16.0, 0.0, 1.0, 0.0);
	glRotatef(zRot / 16.0, 0.0, 0.0, 1.0);
	//----------------------- pfeile -------------------------

/*
	//-------------------------- texture ------------------------
	glRotatef(m_mouseAngleH, 1.0, 0.0, 0.0);
	glRotatef(m_mouseAngleV, 0.0, 1.0, 0.0);
	//glRotatef(zRot / 16.0, 0.0, 0.0, 1.0);
	//-------------------------- texture ------------------------
*/

	//----------------------- pfeile -------------------------
	// X cylinder (red)
	qglColor(xAxisColor);
	// object, baseradius, topradius, height, slices, stacks
	gluCylinder(xAxisCylinder, cyl_radius, cyl_radius, cyl_height, 32, 32);
	// move
	glTranslatef(0.0, 0.0, cyl_height);
	qglColor(xAxisColor);
	// X cone
	gluCylinder(xAxisCone, (cyl_radius*1.5), 0.0, cyl_height/2.0, 32, 32);

	// Y cylinder (green)
	qglColor(yAxisColor);
	// move back and rotate one axis
	glTranslatef(0.0, 0.0, - (cyl_height - cyl_radius));
	glRotated(90, 1.0, 0.0, 0.0);
	// object, baseradius, topradius, height, slices, stacks
	gluCylinder(yAxisCylinder, cyl_radius, cyl_radius, cyl_height, 32, 32);
	// move
	glTranslatef(0.0, 0.0, cyl_height);
	qglColor(yAxisColor);
	// Y cone
	gluCylinder(yAxisCone, (cyl_radius*1.5), 0.0, cyl_height/2.0, 32, 32);

	// Z cylinder (blue)
	qglColor(zAxisColor);
	// move back and rotate one axis
	glTranslatef(0.0, 0.0, - (cyl_height));
	glRotated(90, 0.0, 1.0, 0.0);
	// object, baseradius, topradius, height, slices, stacks
	gluCylinder(zAxisCylinder, cyl_radius, cyl_radius, cyl_height, 32, 32);
	// move
	glTranslatef(0.0, 0.0, cyl_height);
	qglColor(zAxisColor);
	// Z cone
	gluCylinder(zAxisCone, (cyl_radius*1.5), 0.0, cyl_height/2.0, 32, 32);
	//----------------------- pfeile -------------------------

/*
	//-------------------------- texture ------------------------
	// use mipmapped textures
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);

	// \todo should be located elsewhere
	static GLfloat no_mat[] = {0.0, 0.0, 0.0, 1.0};
	static GLfloat mat_diffuse[] = {0.5, 0.5, 0.5, 1.0};
	static GLfloat mat_specular[] = {1.0, 1.0, 1.0, 1.0};
	static GLfloat low_shininess[] = {2.5};
// 	static GLfloat translucent[] = {1.0, 1.0, 1.0, 0.33};

	glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
	glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
	glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess);
	glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);

	// bind textures
	robotTextureFront = bindTexture(robotImageFront, GL_TEXTURE_2D, GL_RGBA);
	robotTextureBack = bindTexture(robotImageBack, GL_TEXTURE_2D, GL_RGBA);
	robotTextureLeft = bindTexture(robotImageLeft, GL_TEXTURE_2D, GL_RGBA);
	robotTextureRight = bindTexture(robotImageRight, GL_TEXTURE_2D, GL_RGBA);

	// enable texturing
	glEnable(GL_TEXTURE_2D);

	// move world 7 units away from the current view point
	glTranslated(0.0, 0.0, -7.0);

	// create FRONT texture
	glBindTexture(GL_TEXTURE_2D, robotTextureFront);
	glBegin(GL_QUADS);
	glTexCoord2f(0.0, 0.0);		glVertex3f(-cubeWidth, cubeHeight, cubeHeight); // Top Left			1
	glTexCoord2f(1.0, 0.0);		glVertex3f( cubeWidth, cubeHeight, cubeHeight); // Top Right		2
	glTexCoord2f(1.0, 1.0);		glVertex3f( cubeWidth,-cubeHeight, cubeHeight); // Bottom Right		3
	glTexCoord2f(0.0, 1.0);		glVertex3f(-cubeWidth,-cubeHeight, cubeHeight); // Bottom Left		4
	glEnd();


	// create RIGHT texture
	glBindTexture(GL_TEXTURE_2D, robotTextureRight);
	glBegin(GL_QUADS);
	glTexCoord2f(0.0, 0.0);		glVertex3f( cubeHeight, cubeHeight, cubeWidth); // Top Left			1
	glTexCoord2f(1.0, 0.0);		glVertex3f( cubeHeight, cubeHeight,-cubeWidth); // Top Right		2
	glTexCoord2f(1.0, 1.0);		glVertex3f( cubeHeight,-cubeHeight,-cubeWidth); // Bottom Right		3
	glTexCoord2f(0.0, 1.0);		glVertex3f( cubeHeight,-cubeHeight, cubeWidth); // Bottom Left		4
	glEnd();

	// create LEFT texture
	glBindTexture(GL_TEXTURE_2D, robotTextureLeft);
	glBegin(GL_QUADS);
	glTexCoord2f(0.0, 0.0);		glVertex3f(-cubeHeight, cubeHeight,-cubeWidth); // Top Left			1
	glTexCoord2f(1.0, 0.0);		glVertex3f(-cubeHeight, cubeHeight, cubeWidth); // Top Right		2
	glTexCoord2f(1.0, 1.0);		glVertex3f(-cubeHeight,-cubeHeight, cubeWidth); // Bottom Right		3
	glTexCoord2f(0.0, 1.0);		glVertex3f(-cubeHeight,-cubeHeight,-cubeWidth); // Bottom Left		4
	glEnd();

	// create BACK texture
	glBindTexture(GL_TEXTURE_2D, robotTextureBack);
	glBegin(GL_QUADS);
	glTexCoord2f(0.0, 0.0);		glVertex3f( cubeHeight, cubeHeight,-cubeWidth); // Top Left			1
	glTexCoord2f(1.0, 0.0);		glVertex3f(-cubeHeight, cubeHeight,-cubeWidth); // Top Right		2
	glTexCoord2f(1.0, 1.0);		glVertex3f(-cubeHeight,-cubeHeight,-cubeWidth); // Bottom Right		3
	glTexCoord2f(0.0, 1.0);		glVertex3f( cubeHeight,-cubeHeight,-cubeWidth); // Bottom Left		4
	glEnd();

	glDisable(GL_TEXTURE_2D);
	//-------------------------- texture ------------------------
*/
}
コード例 #25
0
ファイル: glwidget.cpp プロジェクト: martonmiklos/YARRH
  //drawing 20x20cm grind in 3dview
  void GlWidget::drawGrid(){
      GLdouble gridWidth=2.0;
      GLint     iSlices=32;
      GLint     iStacks=32;
      GLdouble  lineRadius=0.001;
      bool      bSolid=true;
      bool      bBlend=true;
      GLfloat fCurrentColor[4];
      // Get the current color
      glGetFloatv(GL_CURRENT_COLOR, fCurrentColor);

      // Save the current transformation matrix..
      glPushMatrix();

      // Create a quadratic object used to draw our axis
      // cylinders and cones
      GLUquadricObj* pQuadric = gluNewQuadric();
      if(!pQuadric)
          return;

      // Set the quadric state
      gluQuadricNormals(pQuadric, GLU_SMOOTH);
      gluQuadricTexture(pQuadric, GL_FALSE);

      if(bSolid)
      {
          glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
          gluQuadricDrawStyle(pQuadric, GLU_FILL);
      }
      else
      {
          glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
          gluQuadricDrawStyle(pQuadric, GLU_LINE);
      }

      // Enable alpha blending?
      if(bBlend)
      {
          glEnable(GL_BLEND);
          glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
      }

      //draw grid
      //rotate for x
      glRotated(90, 0.0, 1.0, 0.0);
      for(int i=0; i<sizeY; i++){
          gluCylinder(pQuadric, lineRadius, lineRadius, (double)sizeX/10, iSlices, iStacks);
                glTranslated(0.0f, 0.1f, 0.0f);
      }
                gluCylinder(pQuadric, lineRadius, lineRadius, (double)sizeX/10, iSlices, iStacks);
      glRotated(90, 1.0, 0.0, 0.0);
      for(int i=0; i<sizeX+1; i++){
                gluCylinder(pQuadric, lineRadius, lineRadius, (double)sizeY/10, iSlices, iStacks);
                glTranslated(0.0f, 0.1f, 0.0f);
      }

      // Delete the quadric
      gluDeleteQuadric(pQuadric);

      // Restore the current transformation matrix..
      glPopMatrix();

      // Restore the current color
      glColor4fv(fCurrentColor);

      // Disable blend function
      glDisable(GL_BLEND);
  }
コード例 #26
0
	void drawWall1(GLUquadricObj* qobj, GLuint* tex) 
	{
		glPushMatrix();
		glTranslatef(0, 0, -27.5);
		glRotatef(90, 0, 1, 0);

		glPushMatrix();
		glColor3f(1, 1, 1);
		
		glEnable(GL_TEXTURE_2D);
		glMatrixMode(GL_TEXTURE);
		glLoadIdentity();
		glMatrixMode(GL_MODELVIEW);

		glPushMatrix();
		glTranslatef(2.45, 1.9, 0);
		glBindTexture(GL_TEXTURE_2D, tex[4]);
		glBegin(GL_QUADS);
		glTexCoord2f(0, 1);
		glNormal3f(-1, 0, 0);
		glVertex3f(-0.05, -4.5, -14.0);
		glTexCoord2f(1, 1);
		glNormal3f(-1, 0, 0);
		glVertex3f(-0.05, -4.5, -7.0);
		glTexCoord2f(1, 0);
		glNormal3f(-1, 0, 0);
		glVertex3f(-0.05, 5, -7.0);
		glTexCoord2f(0, 0);
		glNormal3f(-1, 0, 0);
		glVertex3f(-0.05, 5, -14.0);
		glEnd();
		glBegin(GL_QUADS);
		glTexCoord2f(0, 1);
		glNormal3f(-1, 0, 0);
		glVertex3f(-0.05, -4.5, 7);
		glTexCoord2f(1, 1);
		glNormal3f(-1, 0, 0);
		glVertex3f(-0.05, -4.5, 14.0);
		glTexCoord2f(1, 0);
		glNormal3f(-1, 0, 0);
		glVertex3f(-0.05, 5, 14.0);
		glTexCoord2f(0, 0);
		glNormal3f(-1, 0, 0);
		glVertex3f(-0.05, 5, 7);
		glEnd();
		glBindTexture(GL_TEXTURE_2D, tex[3]);

		glBegin(GL_QUADS);
		glTexCoord2f(0, 1);
		glNormal3f(-1, 0, 0);
		glVertex3f(0, -4.5, -21);
		glTexCoord2f(4, 1);
		glNormal3f(-1, 0, 0);
		glVertex3f(0, -4.5, 21);
		glTexCoord2f(4, 0);
		glNormal3f(-1, 0, 0);
		glVertex3f(0, 5, 21);
		glTexCoord2f(0, 0);
		glNormal3f(-1, 0, 0);
		glVertex3f(0, 5, -21);
		glEnd();

		glPopMatrix();

		glBindTexture(GL_TEXTURE_2D, tex[5]);
		glTranslatef(0, 0.65, 0);
		for (int i = -1; i < 2; i++) 
		{
			glPushMatrix();
			glTranslatef(0, -3.4, i * 3.5);
			glRotatef(-90, 1, 0, 0);
			gluCylinder(qobj, 1.2, 1.2, 4.0, 30, 1);
			glTranslatef(0, 0, 4.0);
			gluDisk(qobj, 0.0f, 1.2f, 30, 1);
			glPopMatrix();
		}
		glDisable(GL_TEXTURE_2D);
		glTranslatef(0, 0, -3.5); 
		Tank1::drawMask(qobj);
		glTranslatef(0, 0, 3.5); 
		Tank2::drawMask(qobj);
		glTranslatef(0, 0, 3.5); 
		Tank3::drawMask(qobj);
		glDisable(GL_TEXTURE_2D);
		glPopMatrix();

		glPopMatrix();
	}
コード例 #27
0
	void drawWeaponsBoard(GLUquadricObj* qobj) 
	{
		const float s1[] = { 
			1, 0, 0, 0,
			0, 1, -0.5, 0,
			0, 0, 1, 0,
			0, 0, 0, 1
		};

		glPushMatrix();
		glTranslatef(0, 0, -27.5);
		glRotatef(90, 0, 1, 0);
		glTranslatef(2.25 + 0.15, 1.5, -0.7);

		glPushMatrix();
		glTranslatef(0, 0, 3.0);
		glRotatef(180, 0, 1, 0);
		TankParts::drawCannon(qobj);
		glPopMatrix();
		glPushMatrix();
		glTranslatef(0, 0.2, 2.25);
		glRotatef(-90, 0, 1, 0);
		glScalef(0.18, 0.18, 0.18);
		TankParts::drawLaserRifle(qobj);
		glPopMatrix();

		glPushMatrix();
		glTranslatef(0, 1.15, 0);
		glPushMatrix();
		glTranslatef(0, 0.225, 0.475);
		glRotatef(-90, 0, 1, 0);
		glScalef(0.32, 0.32, 0.32);
		TankParts::drawGrenadeLauncher(qobj);
		glPopMatrix();
		glPushMatrix();
		glTranslatef(0, 0, 2.25);
		glRotatef(-90, 0, 1, 0);
		glScalef(0.09, 0.09, 0.09);
		TankParts::drawPlasmaRifle(qobj);
		glPopMatrix();
		glPopMatrix();

		glPushMatrix();
		glTranslatef(0, 2.1, 0);
		glPushMatrix();
		glColor3f(0.35, 0.35, 0.35);
		glTranslatef(0, 0, 1.1);
		glRotatef(-180, 0, 1, 0);
		glPushMatrix();
		glScalef(1.05, 1.05, 1.05);
		glTranslatef(0, 0, -0.18);
		glPushMatrix();
		gluCylinder(qobj, 0.215, 0.215, 0.64f, 20, 1);
		glTranslatef(0.0f, 0, 0.64f);
		gluDisk(qobj, 0.0f, 0.215, 20, 1);
		glPopMatrix();
		glPushMatrix();
		glMultMatrixf(s1);
		glTranslatef(0, 0.21, 0.25);
		glScalef(0.07, 0.3, 0.4);
		glutSolidCube(1.0);
		glPopMatrix();
		gluCylinder(qobj, 0.25, 0.25, 0.6f, 20, 1);
		gluDisk(qobj, 0.0f, 0.25, 20, 1);
		glTranslatef(0.0f, 0, 0.6f);
		gluDisk(qobj, 0.0f, 0.25, 20, 1);
		glPopMatrix();
		glPushMatrix();
		glScalef(0.42, 0.42, 0.42);
		TankParts::drawGatlingGun(qobj);
		glPopMatrix();
		glPopMatrix();
		glPushMatrix();
		glTranslatef(0, 0.175, 2.47);
		glRotatef(-90, 0, 1, 0);
		glScalef(0.12, 0.12, 0.12);
		TankParts::drawIonRifle(qobj);	
		glPopMatrix();
		glPopMatrix();
		
		glPopMatrix();
	}
コード例 #28
0
ファイル: G308_Skeleton.cpp プロジェクト: LizbethKim/C308A2
// [Assignment2] you need to fill this function
void Skeleton::display(bone* root, GLUquadric* q) {
	if (root == NULL) {
		return;
	}
	float theta = acos(root->dirz) * 180 / M_PI;
	//All options enabled, will show bone joints and x, y, z vectors
	if (rS < 4){		
		glPushMatrix();
		
		//Apply current bone rotations, and translations
		glRotatef(root->rotz, 0, 0, 1.0);
		glRotatef(root->roty, 0, 1.0, 0);
		glRotatef(root->rotx, 1.0, 0, 0);		

		glRotatef(root->currentRotationz, 0, 0, 1.0);
		glRotatef(root->currentRotationy, 0, 1.0, 0);
		glRotatef(root->currentRotationx, 1.0, 0, 0);

		glTranslatef(root->currentTranslatex, root->currentTranslatey, root->currentTranslatez);
	
		glRotatef(-root->rotx, 1.0, 0, 0);
		glRotatef(-root->roty, 0, 1.0, 0);
		glRotatef(-root->rotz, 0, 0, 1.0);

		glRotatef(theta, -root->diry, root->dirx, 0);

		//Drawing the bone joints
		if (rS < 3){

			glColor3f(0, 1, 1);
			glutSolidSphere(0.4, 100, 100);
			//Drawing the bone axis vectors
			if (rS < 2){
				glPushMatrix();
					glColor3f(0,0,1);
					gluCylinder(q, 0.1, 0.1, 1, 100, 100);
					glutSolidCone(0.2,0.2,100,100);
				glPopMatrix();

				glPushMatrix();
					glColor3f(0,1,0);
					glRotatef(-90,1,0,0);
					gluCylinder(q, 0.1, 0.1, 1, 100, 100);
				glPopMatrix();

				glPushMatrix();
					glColor3f(1,0,0);
					glRotatef(-90, 0, 1, 0);
					gluCylinder(q, 0.1, 0.1, 1, 100, 100);
				glPopMatrix();
			}
		}
	}


	//Draw actual bone
	glColor3f(1,1,1);
	gluCylinder(q, 0.2, 0.2, root->length, 50, 50);
	glRotatef(-theta, -root->diry, root->dirx, 0);
	glTranslatef(root->dirx*root->length, root->diry*root->length, root->dirz*root->length);
	int i;
	//Iterate over all children
	for (i = 0; i < root->numChildren; i++){
		display(root->children[i], q);
	}
	glPopMatrix();
}
コード例 #29
0
ファイル: BondLayer.C プロジェクト: bjnano/IQmol
void Bond::drawBallsAndSticks(bool selected)
{
   GLfloat radius(s_radiusBallsAndSticks*m_scale);

   if (selected) {
      radius += Primitive::s_selectOffset;
      glColor4fv(Primitive::s_selectColor);
   }else {
      glColor4fv(s_defaultColor);
   }

   Vec a(m_begin->displacedPosition());
   Vec b(m_end  ->displacedPosition());
   Vec normal = cross(s_cameraPosition-a, s_cameraPosition-b);
   normal.normalize();
   GLfloat length((a-b).norm());

   Frame frame(m_frame);
   GLUquadric* quad = gluNewQuadric();

   switch (m_order) {
      case 1: {
         glPushMatrix();
         glMultMatrixd(frame.matrix());
         gluCylinder(quad, radius, radius, length, Primitive::s_resolution, 1);
         glPopMatrix();
      } break;
 
      case 2: {
         normal *= 0.08;  // Governs the offset for the bond lines
         radius *= 0.7;   // Make the bonds a bit thinner

         frame.translate(-normal);
         glPushMatrix();
         glMultMatrixd(frame.matrix());
         gluCylinder(quad, radius, radius, length, Primitive::s_resolution, 1);
         glPopMatrix();

         frame.translate(2.0*normal);
         glPushMatrix();
         glMultMatrixd(frame.matrix());
         gluCylinder(quad, radius, radius, length, Primitive::s_resolution, 1);
         glPopMatrix();
      } break;

      case 3: {
         normal *= 0.11;  // Governs the offset for the bond lines
         radius *= 0.45;  // Make the bonds a bit thinner

         frame.translate(-normal);
         glPushMatrix();
         glMultMatrixd(frame.matrix());
         gluCylinder(quad, radius, radius, length, Primitive::s_resolution, 1);
         glPopMatrix();

         frame.translate(normal);
         glPushMatrix();
         glMultMatrixd(frame.matrix());
         gluCylinder(quad, radius, radius, length, Primitive::s_resolution, 1);
         glPopMatrix();

         frame.translate(normal);
         glPushMatrix();
         glMultMatrixd(frame.matrix());
         gluCylinder(quad, radius, radius, length, Primitive::s_resolution, 1);
         glPopMatrix();
      } break;

      case 4: {
         normal *= 0.11;  // Governs the offset for the bond lines
         radius *= 0.40;  // Make the bonds a bit thinner

         frame.translate(-1.5*normal);
         glPushMatrix();
         glMultMatrixd(frame.matrix());
         gluCylinder(quad, radius, radius, length, Primitive::s_resolution, 1);
         glPopMatrix();

         frame.translate(normal);
         glPushMatrix();
         glMultMatrixd(frame.matrix());
         gluCylinder(quad, radius, radius, length, Primitive::s_resolution, 1);
         glPopMatrix();

         frame.translate(normal);
         glPushMatrix();
         glMultMatrixd(frame.matrix());
         gluCylinder(quad, radius, radius, length, Primitive::s_resolution, 1);
         glPopMatrix();

         frame.translate(normal);
         glPushMatrix();
         glMultMatrixd(frame.matrix());
         gluCylinder(quad, radius, radius, length, Primitive::s_resolution, 1);
         glPopMatrix();
      } break;

      case 5: {  // Aromatic
         normal *= 0.08;  // Governs the offset for the bond lines

         frame.translate(-normal);
         glPushMatrix();
         glMultMatrixd(frame.matrix());
         gluCylinder(quad, radius, radius, length, Primitive::s_resolution, 1);
         glPopMatrix();

         radius *= 0.5;   // Make the second bond a bit thinner
         frame.translate(2.0*normal);
         glPushMatrix();
         glMultMatrixd(frame.matrix());
         gluCylinder(quad, radius, radius, length, Primitive::s_resolution, 1);
         glPopMatrix();
      } break;

      default: {
         radius *= 2;         // Fat bond indicates we don't know what we are doing
         glPushMatrix();
         glMultMatrixd(frame.matrix());
         gluCylinder(quad, radius, radius, length, Primitive::s_resolution, 1);
         glPopMatrix();
      } break;
      
   }

   gluDeleteQuadric(quad); 
}
コード例 #30
-1
ファイル: KDisplayTools.cpp プロジェクト: Frizlab/kiki
// --------------------------------------------------------------------------------------------------------
void kDisplaySolidCylinder ( float base, float top, float height, int subdivisions )
{
    GLUquadric * quad = gluNewQuadric();
    gluCylinder(quad, base, top, height, subdivisions, 1);
    gluDeleteQuadric(quad);
}