Exemple #1
0
    void Camera::ShowGUIProperties(Editor* editor)
    {
        SceneNode::ShowGUIProperties(editor);
        std::string header = "Camera:" + GetName();
		if (ImGui::TreeNode(header.c_str()))
        {
            auto zNear = GetZNear();
            ImGui::DragFloat("##zNear", &zNear, 1.f, 0.1f, 10000.0f, "zNear %.1f");
            SetNearClip(zNear);

            auto zFar = GetZFar();
            ImGui::DragFloat("##zFar", &zFar, 1.f, 0.1f, 10000.0f, "zFar %.1f");
            SetFarClip(zFar);

            auto isOrtho = IsOrtho();
            ImGui::Checkbox("Ortho", &isOrtho);
            isOrtho ? EnableOrtho() : DisableOrtho();

            if (!isOrtho)
            {
                auto fov = GetFOVRadians();
                ImGui::SliderAngle("FOV", &fov, 0.f, CAMERA_MAX_FOV_DEGREES);
                SetFOVRadians(fov);
            }
			else
			{
				auto orthoScale = GetOrthoScale();
				ImGui::DragFloat("##orthoScale", &orthoScale, 1.f, 0.f, MAX_WORLD_SIZE, "Size %.1f");
				SetOrthoScale(orthoScale);
			}
			ImGui::TreePop();
        }

    }
Exemple #2
0
/** Support objects created, start application specific content. */
void UApp::Start() {
    // the mouse must be in cursor mode before setting the UI.
    auto input_ = GetSubsystem< Urho3D::Input >();
    input_->SetMouseVisible(true);

    // resources origin.
    cache_ = GetSubsystem< Urho3D::ResourceCache >();

    // use the default style from Urho3D.
    GetSubsystem< Urho3D::UI >()->GetRoot()->SetDefaultStyle(
                cache_->GetResource< Urho3D::XMLFile >("UI/DefaultStyle.xml"));

    // grab mouse
    input_->SetMouseGrabbed(true);

    // setup scene to render.
    scene_ = new Urho3D::Scene(context_);
    scene_->CreateComponent< Urho3D::Octree >();

    // Create the light
    {
        auto lightNode = scene_->CreateChild("Light");
        lightNode->SetPosition(Urho3D::Vector3(6, 6, -20));
        auto light = lightNode->CreateComponent< Urho3D::Light >();
        light->SetLightType(Urho3D::LIGHT_POINT);
        light->SetRange(1000);
    }

    // setup camera
    {
        auto cameraNode_ = scene_->CreateChild("Camera");
        cameraNode_->SetPosition(Urho3D::Vector3(6, 6, -20));
        auto camera_ = cameraNode_->CreateComponent< Urho3D::Camera >();
        camera_->SetFarClip(2000);
        auto renderer = GetSubsystem< Urho3D::Renderer >();
        Urho3D::SharedPtr< Urho3D::Viewport > viewport(new Urho3D::Viewport(context_, scene_, camera_));
        renderer->SetViewport(0, viewport);
    }

    // start the game
    game.start();

    // subscribe to events
    SubscribeToEvent(Urho3D::E_UPDATE,URHO3D_HANDLER(UApp,HandleUpdate));
    SubscribeToEvent(Urho3D::E_KEYDOWN,URHO3D_HANDLER(UApp,HandleKeyDown));
    SubscribeToEvent(Urho3D::E_KEYUP,URHO3D_HANDLER(UApp,HandleKeyUp));
}
Exemple #3
0
/*
===============
R_SetupProjection
===============
*/
void R_SetupProjection(void)
{
    float	xmin, xmax, ymin, ymax;
    float	width, height, depth;
    float	zNear, zFar;

    // dynamically compute far clip plane distance
    SetFarClip();

    //
    // set up projection matrix
    //
    zNear	= r_znear->value;
    zFar	= tr.viewParms.zFar;

    ymax = zNear * tan(tr.refdef.fov_y * M_PI / 360.0f);
    ymin = -ymax;

    xmax = zNear * tan(tr.refdef.fov_x * M_PI / 360.0f);
    xmin = -xmax;

    width = xmax - xmin;
    height = ymax - ymin;
    depth = zFar - zNear;

    tr.viewParms.projectionMatrix[0] = 2 * zNear / width;
    tr.viewParms.projectionMatrix[4] = 0;
    tr.viewParms.projectionMatrix[8] = (xmax + xmin)/ width;	// normally 0
    tr.viewParms.projectionMatrix[12] = 0;

    tr.viewParms.projectionMatrix[1] = 0;
    tr.viewParms.projectionMatrix[5] = 2 * zNear / height;
    tr.viewParms.projectionMatrix[9] = (ymax + ymin)/ height;	// normally 0
    tr.viewParms.projectionMatrix[13] = 0;

    tr.viewParms.projectionMatrix[2] = 0;
    tr.viewParms.projectionMatrix[6] = 0;
    tr.viewParms.projectionMatrix[10] = -(zFar + zNear)/ depth;
    tr.viewParms.projectionMatrix[14] = -2 * zFar * zNear / depth;

    tr.viewParms.projectionMatrix[3] = 0;
    tr.viewParms.projectionMatrix[7] = 0;
    tr.viewParms.projectionMatrix[11] = -1;
    tr.viewParms.projectionMatrix[15] = 0;
}
Exemple #4
0
	inline void
		MLRClippingState::Clip4dVertex(Stuff::Vector4D *v4d)
	{
#if USE_ASSEMBLER_CODE

		int _ret = 0;

		_asm {
			mov		edi, v4d

			xor		ecx,ecx
			xor		edx, edx
			test	dword ptr [edi], 080000000h
			setne	cl
			sub		edx, ecx
			and		edx, 8	// RightClipFlag

			xor		ebx, ebx
			test	dword ptr [edi+4], 080000000h
			setne	cl
			sub		ebx, ecx
			and		ebx, 2	// BottomClipFlag

			or		edx, ebx

			xor		ebx, ebx
			test	dword ptr [edi+8], 080000000h
			setne	cl
			sub		ebx, ecx
			and		ebx, 16	// NearClipFlag

			or		edx, ebx

			fld		dword ptr [edi+0Ch]

			xor		ebx, ebx
			fcom	dword ptr [edi]
			fnstsw	ax
			test	ah, 1
			setne	cl
			sub		ebx, ecx
			and		ebx, 4	// LeftClipFlag

			or		edx, ebx

			xor		ebx, ebx
			fcom	dword ptr [edi+4]
			fnstsw	ax
			test	ah, 1
			setne	cl
			sub		ebx, ecx
			and		ebx, 1	// TopClipFlag

			or		edx, ebx

			xor		ebx, ebx
			fcomp	dword ptr [edi+8]
			fnstsw	ax
			test	ah, 41h
			setne	cl
			sub		ebx, ecx
			and		ebx, 32	// FarClipFlag

			or		edx, ebx

			mov		_ret, edx
		}
		
		clippingState = _ret;
#else
		clippingState = 0;

		if(v4d->w <= v4d->z)
		{
			SetFarClip();
		}

		if(v4d->z < 0.0f)
		{
			SetNearClip();
		}

		if(v4d->x < 0.0f)
		{
			SetRightClip();
		}

		if(v4d->w < v4d->x)
		{
			SetLeftClip();
		}

		if(v4d->y < 0.0f)
		{
			SetBottomClip();
		}

		if(v4d->w < v4d->y)
		{
			SetTopClip();
		}
#endif
	}