the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include "..\..\Minecraft.h"
3#include "..\..\ScreenSizeCalculator.h"
4#include "..\..\EntityRenderDispatcher.h"
5#include "..\..\Lighting.h"
6#include "..\..\MultiplayerLocalPlayer.h"
7#include "XUI_Ctrl_MinecraftPlayer.h"
8#include "XUI_Scene_AbstractContainer.h"
9#include "XUI_Scene_Inventory.h"
10#include "..\..\Options.h"
11
12//-----------------------------------------------------------------------------
13// CXuiCtrlMinecraftPlayer class
14//-----------------------------------------------------------------------------
15
16//-----------------------------------------------------------------------------
17CXuiCtrlMinecraftPlayer::CXuiCtrlMinecraftPlayer() :
18 m_bDirty(FALSE),
19 m_fScale(1.0f),
20 m_fAlpha(1.0f)
21{
22 Minecraft *pMinecraft=Minecraft::GetInstance();
23
24 ScreenSizeCalculator ssc(pMinecraft->options, pMinecraft->width_phys, pMinecraft->height_phys);
25 m_fScreenWidth=(float)pMinecraft->width_phys;
26 m_fRawWidth=(float)ssc.rawWidth;
27 m_fScreenHeight=(float)pMinecraft->height_phys;
28 m_fRawHeight=(float)ssc.rawHeight;
29}
30
31//-----------------------------------------------------------------------------
32HRESULT CXuiCtrlMinecraftPlayer::OnInit(XUIMessageInit* pInitData, BOOL& rfHandled)
33{
34 HRESULT hr=S_OK;
35
36 HXUIOBJ parent = m_hObj;
37 HXUICLASS hcInventoryClass = XuiFindClass( L"CXuiSceneInventory" );
38 HXUICLASS currentClass;
39
40 do
41 {
42 XuiElementGetParent(parent,&parent);
43 currentClass = XuiGetObjectClass( parent );
44 } while (parent != NULL && !XuiClassDerivesFrom( currentClass, hcInventoryClass ) );
45
46 assert( parent != NULL );
47
48 VOID *pObj;
49 XuiObjectFromHandle( parent, &pObj );
50 m_containerScene = (CXuiSceneInventory *)pObj;
51
52 m_iPad = m_containerScene->getPad();
53
54 return hr;
55}
56
57HRESULT CXuiCtrlMinecraftPlayer::OnRender(XUIMessageRender *pRenderData, BOOL &bHandled )
58{
59#ifdef _XBOX
60 HXUIDC hDC = pRenderData->hDC;
61
62 // build and render with the game call
63
64 RenderManager.Set_matrixDirty();
65
66 Minecraft *pMinecraft=Minecraft::GetInstance();
67
68 glColor4f(1, 1, 1, 1);
69 glClear(GL_DEPTH_BUFFER_BIT);
70 glMatrixMode(GL_PROJECTION);
71 glLoadIdentity();
72 glOrtho(0, m_fRawWidth, m_fRawHeight, 0, 1000, 3000);
73 glMatrixMode(GL_MODELVIEW);
74 glLoadIdentity();
75 glTranslatef(0, 0, -2000);
76
77
78 D3DXMATRIX matrix;
79 CXuiControl xuiControl(m_hObj);
80 xuiControl.GetFullXForm(&matrix);
81 float bwidth,bheight;
82 xuiControl.GetBounds(&bwidth,&bheight);
83
84 float xo = ( (matrix._41 + ( (bwidth*matrix._11)/2) ) / m_fScreenWidth ) * m_fRawWidth;
85 float yo = ( (matrix._42 + (bheight*matrix._22) ) / m_fScreenHeight ) * m_fRawHeight;
86
87 glEnable(GL_RESCALE_NORMAL);
88 glEnable(GL_COLOR_MATERIAL);
89
90 glPushMatrix();
91 glTranslatef(xo, yo - 3.5f, 50.0f);
92 float ss;// = 26;
93
94 if(!RenderManager.IsHiDef() && !RenderManager.IsWidescreen())
95 {
96 ss = 24;
97 }
98 else
99 {
100 if(app.GetLocalPlayerCount()>1)
101 {
102 ss = 13;
103 }
104 else
105 {
106 ss = 26;
107 }
108 }
109 // Base scale on height of this control
110 // Potentially we might want separate x & y scales here
111 //ss = ( ( bheight / m_fScreenHeight ) * m_fRawHeight );
112 // For testing split screen - this scale is correct for 4 player split screen
113
114 // how many local players do we have?
115// int iPlayerC=0;
116//
117// for(int i=0;i<XUSER_MAX_COUNT;i++)
118// {
119// if(pMinecraft->localplayers[i] != NULL)
120// {
121// iPlayerC++;
122// }
123// }
124//
125// switch(iPlayerC)
126// {
127// case 1:
128// break;
129// case 2:
130// case 3:
131// case 4:
132// ss *= 0.5f;
133// break;
134// }
135
136 glScalef(-ss, ss, ss);
137 glRotatef(180, 0, 0, 1);
138
139 float oybr = pMinecraft->localplayers[m_iPad]->yBodyRot;
140 float oyr = pMinecraft->localplayers[m_iPad]->yRot;
141 float oxr = pMinecraft->localplayers[m_iPad]->xRot;
142 float oyhr = pMinecraft->localplayers[m_iPad]->yHeadRot;
143
144 D3DXVECTOR3 pointerPosition = m_containerScene->GetCursorScreenPosition();
145 //printf("Pointer screen position is x:%f, y:%f, z:%f\n",pointerPosition.x, pointerPosition.y, pointerPosition.z);
146
147 float xd = ( matrix._41 + ( (bwidth*matrix._11)/2) ) - pointerPosition.x;
148
149 // Need to base Y on head position, not centre of mass
150 float yd = ( matrix._42 + ( (bheight*matrix._22) / 2) - 40 ) - pointerPosition.y;
151
152 glRotatef(45 + 90, 0, 1, 0);
153 Lighting::turnOn();
154 glRotatef(-45 - 90, 0, 1, 0);
155
156 glRotatef(-(float) atan(yd / 40.0f) * 20, 1, 0, 0);
157
158 pMinecraft->localplayers[m_iPad]->yBodyRot = (float) atan(xd / 40.0f) * 20;
159 pMinecraft->localplayers[m_iPad]->yRot = (float) atan(xd / 40.0f) * 40;
160 pMinecraft->localplayers[m_iPad]->xRot = -(float) atan(yd / 40.0f) * 20;
161 pMinecraft->localplayers[m_iPad]->yHeadRot = pMinecraft->localplayers[m_iPad]->yRot;
162 //pMinecraft->localplayers[m_iPad]->glow = 1;
163 glTranslatef(0, pMinecraft->localplayers[m_iPad]->heightOffset, 0);
164 EntityRenderDispatcher::instance->playerRotY = 180;
165
166 // 4J Stu - Turning on hideGui while we do this stops the name rendering in split-screen
167 bool wasHidingGui = pMinecraft->options->hideGui;
168 pMinecraft->options->hideGui = true;
169 EntityRenderDispatcher::instance->render(pMinecraft->localplayers[m_iPad], 0, 0, 0, 0, 1,false,false);
170 pMinecraft->options->hideGui = wasHidingGui;
171 //pMinecraft->localplayers[m_iPad]->glow = 0;
172
173 pMinecraft->localplayers[m_iPad]->yBodyRot = oybr;
174 pMinecraft->localplayers[m_iPad]->yRot = oyr;
175 pMinecraft->localplayers[m_iPad]->xRot = oxr;
176 pMinecraft->localplayers[m_iPad]->yHeadRot = oyhr;
177 glPopMatrix();
178 Lighting::turnOff();
179 glDisable(GL_RESCALE_NORMAL);
180
181 XuiRenderRestoreState(hDC);
182
183 bHandled = TRUE;
184#endif
185 return S_OK;
186
187}
188
189
190