Пример #1
0
void UiRenderPass::render(Renderer* client, const DrawContext& context)
{
	sLock.lock();
	myDrawTimeStat->startTiming();

	if(context.task == DrawContext::SceneDrawTask)
	{
		client->getRenderer()->beginDraw3D(context);
		glPushAttrib(GL_ALL_ATTRIB_BITS);

		// This is a bit of a hack. DIsable depth testing for ui stuff. We will take care of ordering.
		// This may lead to depth inconsistencies wrt the background scene when drawing 3d menus, but we want te
		// menus to always be visible and unoccluded by geometry.
		glDisable(GL_DEPTH_TEST);

		ui::Container* ui = myUiRoot;
		Renderable* uiRenderable = ui->getRenderable(client);
		if(uiRenderable != NULL)
		{
			uiRenderable->draw(context);
		}

		glPopAttrib();
		client->getRenderer()->endDraw();
	}
	else if(context.task == DrawContext::OverlayDrawTask)
	{
		Vector2i displaySize;
		// check if the tile is part of a canvas (a multi-tile grid). If it is,
		// get the canvas resolution. Otherwise simply use the tile resolution.
		if(context.tile->isInGrid)
		{
			DisplaySystem* ds = SystemManager::instance()->getDisplaySystem();
			displaySize = ds->getCanvasSize();
		}
		else
		{
			displaySize = context.tile->pixelSize;
		}

		client->getRenderer()->beginDraw2D(context);
		glPushAttrib(GL_ALL_ATTRIB_BITS);

		Renderable* uiRenderable = myUiRoot->getRenderable(client);
		if(uiRenderable != NULL)
		{
			uiRenderable->draw(context);
		}

		glPopAttrib();
		client->getRenderer()->endDraw();
	}

	myDrawTimeStat->stopTiming();
	sLock.unlock();
}
Пример #2
0
void SpacePage::render(const Renderable& r)
{
    if (m_PlayerRenderable) {
        if (r.getType() == "troll") {
            m_Closest.check(r, m_PlayerRenderable->getPosition());
        }
    }
	Gosu::Graphics& g = PageManager::Instance()->graphics();
    r.draw(m_matGlobalToLocal, g.width(), g.height());
}
Пример #3
0
void ClosestHud::draw(const Matrix& mat, double wdt, double hgt)
{
    if (!m_bValid) return;
    Renderable rend = Renderable::temporary();
    rend.setImageName(L"sphere.png");
    rend.setScale(0.1);
    rend.setFixedSizeDistance(100);
    Gosu::Color col = Gosu::Colors::green;
    rend.setColor(col);
    rend.setPosition(m_vecPos);
    rend.draw(mat, wdt, hgt);
}
Пример #4
0
void RenderManager::doRender() const
{
	int camW = m_Camera->Width(), camH = m_Camera->Height();
	//m_camX = _x; m_camY = _y, 
	double camZoom = m_Camera->Zoom(), camRot = m_Camera->Rotation(), camScale = m_Camera->Scale();

	Renderable *r = m_rendlist;
	while (r != NULL) {
		CameraTransform trans = m_Camera->worldToScreen( r->m_posX, r->m_posY, r->m_layer);
		r->draw(trans.x, trans.y, trans.zoom, trans.rot);
		r = r->m_next;
	}
}
Пример #5
0
    void on_draw() override
    {
        glfwMakeContextCurrent(window);

        if (igm) igm->begin_frame();

        glEnable(GL_CULL_FACE);
        glEnable(GL_DEPTH_TEST);

        int width, height;
        glfwGetWindowSize(window, &width, &height);
        glViewport(0, 0, width, height);

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glClearColor(1.0f, 0.1f, 0.0f, 1.0f);

        ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);

        ImGui::SliderFloat("Projectile Velocity", &turret.velocity, 0.f, 100.f);

        if (ImGui::Button("Fire"))
        {
            turret.projectile = BallisticProjectile();
            turret.projectile.p = turret.source.pose;
            turret.projectile.lastPos = turret.source.pose.position;
            turret.projectile.gravity = 0.0;

            /*
            float3 firingSolutionLow;
            float3 firingSolutionHigh;
            auto numSolutions = solve_ballistic_arc(turret.source.pose.position, turret.velocity, turret.target.pose.position, 9.8f, firingSolutionLow, firingSolutionHigh);
            */

            float3 fireVelocity;
            float gravity;
            auto canFire = solve_ballistic_arc_lateral(turret.source.pose.position, turret.velocity, turret.target.pose.position, 10.f, fireVelocity, gravity);

            //std::cout << "Num Solutions: " << numSolutions << std::endl;
            //std::cout << "Low Solution: " << firingSolutionLow << std::endl;
            std::cout << "Fire Velocity: " << fireVelocity << std::endl;

            if (canFire)
            {
                turret.projectile.gravity = gravity;
                turret.projectile.add_impulse(fireVelocity);
                turret.fired = true;
            }
        }

        ImGui::Spacing();

        if (ImGui::SliderInt("M", &ssM, 1, 30)) regeneratePointer = true;
        if (ImGui::SliderInt("N1", &ssN1, 1, 30)) regeneratePointer = true;
        if (ImGui::SliderInt("N2", &ssN2, 1, 30)) regeneratePointer = true;
        if (ImGui::SliderInt("N3", &ssN3, 1, 30)) regeneratePointer = true;

        ImGui::Spacing();

        ImGui::BeginGroup();

        if (ImGui::SliderFloat3("Position", &params.position.x, -5, 5))
            parabolicPointer = make_parabolic_pointer(worldSurface, params);

        if (ImGui::SliderFloat3("Velocity", &params.velocity.x, -1.f, 1.f))
            parabolicPointer = make_parabolic_pointer(worldSurface, params);

        if (ImGui::SliderFloat("Point Spacing", &params.pointSpacing, 0.5, 2.0))
            parabolicPointer = make_parabolic_pointer(worldSurface, params);

        if (ImGui::SliderFloat("Point Count", &params.pointCount, 16, 64))
            parabolicPointer = make_parabolic_pointer(worldSurface, params);

        ImGui::EndGroup();

        const auto proj = camera.get_projection_matrix((float) width / (float) height);
        const float4x4 view = camera.get_view_matrix();
        const float4x4 viewProj = mul(proj, view);

        glViewport(0, 0, width, height);

        skydome.render(viewProj, camera.get_eye_point(), camera.farClip);
        grid.render(proj, view);

        {
            simpleShader->bind();

            simpleShader->uniform("u_eye", camera.get_eye_point());
            simpleShader->uniform("u_viewProj", viewProj);

            simpleShader->uniform("u_emissive", float3(0, 0, 0));
            simpleShader->uniform("u_diffuse", float3(0.0f, 1.0f, 0.0f));

            for (int i = 0; i < 2; i++)
            {
                simpleShader->uniform("u_lights[" + std::to_string(i) + "].position", lights[i].position);
                simpleShader->uniform("u_lights[" + std::to_string(i) + "].color", lights[i].color);
            }

            for (const auto & model : shadedModels)
            {
                simpleShader->uniform("u_modelMatrix", model.get_model());
                simpleShader->uniform("u_modelMatrixIT", inv(transpose(model.get_model())));
                model.draw();
            }

            {
                simpleShader->uniform("u_modelMatrix", turret.source.get_model());
                simpleShader->uniform("u_modelMatrixIT", inv(transpose(turret.source.get_model())));
                turret.source.draw();

                simpleShader->uniform("u_modelMatrix", turret.target.get_model());
                simpleShader->uniform("u_modelMatrixIT", inv(transpose(turret.target.get_model())));
                turret.target.draw();

                auto projectileMat = turret.projectile.p.matrix();
                simpleShader->uniform("u_modelMatrix", projectileMat);
                simpleShader->uniform("u_modelMatrixIT", inv(transpose(projectileMat)));
                turret.bullet.draw();
            }

            simpleShader->unbind();
        }

        {
            normalDebugShader->bind();
            normalDebugShader->uniform("u_viewProj", viewProj);

            // Some debug models
            for (const auto & model : debugModels)
            {
                normalDebugShader->uniform("u_modelMatrix", model.get_model());
                normalDebugShader->uniform("u_modelMatrixIT", inv(transpose(model.get_model())));
                model.draw();
            }

            // Supershape
            {
                normalDebugShader->uniform("u_modelMatrix", supershape.get_model());
                normalDebugShader->uniform("u_modelMatrixIT", inv(transpose(supershape.get_model())));
                supershape.draw();
            }

            // Parabolic pointer
            {
                normalDebugShader->uniform("u_modelMatrix", parabolicPointer.get_model());
                normalDebugShader->uniform("u_modelMatrixIT", inv(transpose(parabolicPointer.get_model())));
                parabolicPointer.draw();
            }

            // Parallel transport boxes
            for (int i = 0; i < ptfBoxes.size(); ++i)
            {
                auto & model = ptfBoxes[i];
                auto modelMat = ptf[i];
                normalDebugShader->uniform("u_modelMatrix", mul(modelMat, make_scaling_matrix(0.01)));
                normalDebugShader->uniform("u_modelMatrixIT", inv(transpose(modelMat)));
                model.draw();
            }

            normalDebugShader->unbind();
        }

        gl_check_error(__FILE__, __LINE__);
        if (igm) igm->end_frame();
        glfwSwapBuffers(window);
        frameCount++;
    }