Rear View Mirror

From Valve Developer Community
< Ru
Revision as of 01:25, 29 February 2024 by RAZUM38RUS (talk | contribs)
Jump to navigation Jump to search
English (en)Русский (ru)Translate (Translate)

Rearview mirror for Source Engine 2013

Зеркало заднего вида (rearview mirror) для Source 2013

ШАГ - 1

Для начала откройте два файла в вашем проекте - viewrender.h и viewrender.cpp

В файле - viewrender.h ищем:

void			DrawMonitors( const CViewSetup &cameraView );

После вставляем:

void			DrawMirror(const CViewSetup &cameraView);

Далее в файле - viewrender.cpp ищем:

void CViewRender::DrawMonitors( const CViewSetup &cameraView )
{
}

После вставляем:

void CViewRender::DrawMirror(const CViewSetup &viewSet)
{
	C_BasePlayer *localPlayer = C_BasePlayer::GetLocalPlayer();
	if (!localPlayer)
		return;

	//Copy our current View.
	CViewSetup mirrorView = viewSet;

	//Get our camera render target.
	ITexture *pRenderTarget = GetCameraTexture();

	//Our view information, Origin, View Direction, window size
	// location on material, and visual ratios.
	mirrorView.width = 256;
	mirrorView.height = 128;
	mirrorView.x = 0;
	mirrorView.y = 0;
	mirrorView.origin = localPlayer->GetAbsOrigin() + Vector(0, 0, 50 /*50*/);
	mirrorView.angles = localPlayer->GetRenderAngles();
	mirrorView.angles.x += 30;
	mirrorView.angles.y = AngleNormalize(mirrorView.angles.y + 180);
	mirrorView.fov = localPlayer->GetFOV();
	mirrorView.m_bOrtho = false;
	mirrorView.m_flAspectRatio = 1.0f;

	Frustum frustum;
	//Set the view up and output the scene to our RenderTarget (Camera Material).
	render->Push3DView(mirrorView, VIEW_CLEAR_DEPTH | VIEW_CLEAR_COLOR, pRenderTarget, m_Frustum);

	ViewDrawScene(false, SKYBOX_2DSKYBOX_VISIBLE, mirrorView, 0, VIEW_MONITOR);

	render->PopView(m_Frustum);

}


ШАГ - 2

Создадим новый .cpp файл с названием : hud_mirror.cpp и разместим его в папку Client/Source Files/

В файл вставляем:

#include "cbase.h"
#include "hudelement.h"
#include "iclientmode.h"
#include <vgui_controls/ImagePanel.h>

using namespace vgui;

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"

//.vmt location + filename
#define IMAGE_MIRROR "mirror.vmt"

//-----------------------------------------------------------------------------
// Purpose: HUD Mirror panel
//-----------------------------------------------------------------------------
class CHudMirror : public CHudElement, public vgui::Panel
{
	DECLARE_CLASS_SIMPLE(CHudMirror, vgui::Panel);

public:
	CHudMirror(const char *pElementName);

protected:
	virtual void Paint();

private:
	vgui::ImagePanel *m_Mirror;
};

extern CHud gHUD;

DECLARE_HUDELEMENT(CHudMirror);

//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CHudMirror::CHudMirror(const char *pElementName) : CHudElement(pElementName), vgui::Panel(NULL, "HudMirror")
{
	vgui::Panel *pParent = g_pClientMode->GetViewport();
	SetParent(pParent); //Our parent is the screen itself. 

	m_Mirror = new ImagePanel(this, "RearViewMirror");
	m_Mirror->SetImage(IMAGE_MIRROR);

	SetPaintBackgroundEnabled(false);
}

//-----------------------------------------------------------------------------
// Purpose: Paint
//-----------------------------------------------------------------------------
void CHudMirror::Paint()
{
	//Set position Top Right corner
//	SetPos(ScreenWidth() - 270, 25);	
	SetPos(ScreenWidth()/2 - 128, 25);	//	center

	//Set Mirror to 256x128 pixels
	m_Mirror->SetSize(256, 96);
	m_Mirror->SetVisible(true);
}


ШАГ - 3

Далее открываем : scripts/HudLayout.res И в самом верху добавим:

HudMirror
{
	"wide" "256"
	"tall" "128"
	"PaintBackgroundType" "1"
}

ШАГ - 4

Нам нужно создать mirror.vmt файл и разместить его в : materials/VGUI/ В файл вставим следующий код:

"UnlitGeneric"
{
 "$basetexture" "_rt_Camera"
}

Всё закончили!!!

Sdk vehicles0000.jpg
Sdk vehicles0001.jpg
Sdk vehicles0002.jpg