aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/Common/XUI/XUI_Ctrl_MinecraftPlayer.cpp
blob: 02ee7c938cddc284819ab0c546c9e6c8ea148da9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#include "stdafx.h"
#include "..\..\Minecraft.h"
#include "..\..\ScreenSizeCalculator.h"
#include "..\..\EntityRenderDispatcher.h"
#include "..\..\Lighting.h"
#include "..\..\MultiplayerLocalPlayer.h"
#include "XUI_Ctrl_MinecraftPlayer.h"
#include "XUI_Scene_AbstractContainer.h"
#include "XUI_Scene_Inventory.h"
#include "..\..\Options.h"

//-----------------------------------------------------------------------------
//  CXuiCtrlMinecraftPlayer class
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
CXuiCtrlMinecraftPlayer::CXuiCtrlMinecraftPlayer() :
	m_bDirty(FALSE),
	m_fScale(1.0f),
	m_fAlpha(1.0f)
{
	Minecraft *pMinecraft=Minecraft::GetInstance();

	ScreenSizeCalculator ssc(pMinecraft->options, pMinecraft->width_phys, pMinecraft->height_phys);
	m_fScreenWidth=(float)pMinecraft->width_phys;
	m_fRawWidth=(float)ssc.rawWidth;
	m_fScreenHeight=(float)pMinecraft->height_phys;
	m_fRawHeight=(float)ssc.rawHeight;
}

//-----------------------------------------------------------------------------
HRESULT CXuiCtrlMinecraftPlayer::OnInit(XUIMessageInit* pInitData, BOOL& rfHandled)
{
	HRESULT hr=S_OK;

	HXUIOBJ parent = m_hObj;
	HXUICLASS hcInventoryClass = XuiFindClass( L"CXuiSceneInventory" );
	HXUICLASS currentClass;

	do
	{
		XuiElementGetParent(parent,&parent);
		currentClass = XuiGetObjectClass( parent );
	} while (parent != NULL && !XuiClassDerivesFrom( currentClass, hcInventoryClass ) );

	assert( parent != NULL );

	VOID *pObj;
	XuiObjectFromHandle( parent, &pObj );
	m_containerScene = (CXuiSceneInventory *)pObj;

	m_iPad = m_containerScene->getPad();

	return hr;
}

HRESULT CXuiCtrlMinecraftPlayer::OnRender(XUIMessageRender *pRenderData, BOOL &bHandled )
{
#ifdef _XBOX
	HXUIDC hDC = pRenderData->hDC;

	// build and render with the game call

	RenderManager.Set_matrixDirty();

	Minecraft *pMinecraft=Minecraft::GetInstance();

	glColor4f(1, 1, 1, 1);
	glClear(GL_DEPTH_BUFFER_BIT);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0, m_fRawWidth, m_fRawHeight, 0, 1000, 3000);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glTranslatef(0, 0, -2000);


	D3DXMATRIX matrix;
	CXuiControl xuiControl(m_hObj);
	xuiControl.GetFullXForm(&matrix);
	float bwidth,bheight;
	xuiControl.GetBounds(&bwidth,&bheight);

	float xo = ( (matrix._41 + ( (bwidth*matrix._11)/2) ) / m_fScreenWidth ) * m_fRawWidth;
	float yo = ( (matrix._42 + (bheight*matrix._22) ) / m_fScreenHeight ) * m_fRawHeight;

	glEnable(GL_RESCALE_NORMAL);
	glEnable(GL_COLOR_MATERIAL);

	glPushMatrix();
	glTranslatef(xo, yo - 3.5f, 50.0f);
	float ss;// = 26;
	
	if(!RenderManager.IsHiDef() && !RenderManager.IsWidescreen())
	{
		ss = 24;
	}
	else
	{
		if(app.GetLocalPlayerCount()>1)
		{
			ss = 13;
		}
		else
		{
			ss = 26;
		}
	}
	// Base scale on height of this control
	// Potentially we might want separate x & y scales here
	//ss = ( ( bheight / m_fScreenHeight ) * m_fRawHeight );
	// For testing split screen - this scale is correct for 4 player split screen

	// how many local players do we have?
// 	int iPlayerC=0;
// 
// 	for(int i=0;i<XUSER_MAX_COUNT;i++)
// 	{
// 		if(pMinecraft->localplayers[i] != NULL)
// 		{
// 			iPlayerC++;
// 		}
// 	}
// 
// 	switch(iPlayerC)
// 	{
// 	case 1:
// 		break;
// 	case 2:
// 	case 3:
// 	case 4:
// 		ss *= 0.5f;
// 		break;
// 	}

	glScalef(-ss, ss, ss);
	glRotatef(180, 0, 0, 1);

	float oybr = pMinecraft->localplayers[m_iPad]->yBodyRot;
	float oyr = pMinecraft->localplayers[m_iPad]->yRot;
	float oxr = pMinecraft->localplayers[m_iPad]->xRot;
	float oyhr = pMinecraft->localplayers[m_iPad]->yHeadRot;

	D3DXVECTOR3 pointerPosition = m_containerScene->GetCursorScreenPosition();
	//printf("Pointer screen position is x:%f, y:%f, z:%f\n",pointerPosition.x, pointerPosition.y, pointerPosition.z);

	float xd = ( matrix._41 + ( (bwidth*matrix._11)/2) ) - pointerPosition.x;

	// Need to base Y on head position, not centre of mass
	float yd = ( matrix._42 + ( (bheight*matrix._22) / 2) - 40 ) - pointerPosition.y;

	glRotatef(45 + 90, 0, 1, 0);
	Lighting::turnOn();
	glRotatef(-45 - 90, 0, 1, 0);

	glRotatef(-(float) atan(yd / 40.0f) * 20, 1, 0, 0);

	pMinecraft->localplayers[m_iPad]->yBodyRot = (float) atan(xd / 40.0f) * 20;
	pMinecraft->localplayers[m_iPad]->yRot = (float) atan(xd / 40.0f) * 40;
	pMinecraft->localplayers[m_iPad]->xRot = -(float) atan(yd / 40.0f) * 20;
	pMinecraft->localplayers[m_iPad]->yHeadRot = pMinecraft->localplayers[m_iPad]->yRot;
	//pMinecraft->localplayers[m_iPad]->glow = 1;
	glTranslatef(0, pMinecraft->localplayers[m_iPad]->heightOffset, 0);
	EntityRenderDispatcher::instance->playerRotY = 180;

	// 4J Stu - Turning on hideGui while we do this stops the name rendering in split-screen
	bool wasHidingGui = pMinecraft->options->hideGui;
	pMinecraft->options->hideGui = true;
	EntityRenderDispatcher::instance->render(pMinecraft->localplayers[m_iPad], 0, 0, 0, 0, 1,false,false);
	pMinecraft->options->hideGui = wasHidingGui;
	//pMinecraft->localplayers[m_iPad]->glow = 0;

	pMinecraft->localplayers[m_iPad]->yBodyRot = oybr;
	pMinecraft->localplayers[m_iPad]->yRot = oyr;
	pMinecraft->localplayers[m_iPad]->xRot = oxr;
	pMinecraft->localplayers[m_iPad]->yHeadRot = oyhr;
	glPopMatrix();
	Lighting::turnOff();
	glDisable(GL_RESCALE_NORMAL);

	XuiRenderRestoreState(hDC);

	bHandled = TRUE;
#endif
	return S_OK;

}