the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 248 lines 8.1 kB view raw
1#include "stdafx.h" 2#include "DragonModel.h" 3#include "..\Minecraft.World\Mth.h" 4#include "..\Minecraft.World\Enderdragon.h" 5 6DragonModel::DragonModel(float g) : Model() 7{ 8 // 4J-PB 9 texWidth = 256; 10 texHeight = 256; 11 12 setMapTex(L"body.body", 0, 0); 13 setMapTex(L"wing.skin", -56, 88); 14 setMapTex(L"wingtip.skin", -56, 144); 15 setMapTex(L"rearleg.main", 0, 0); 16 setMapTex(L"rearfoot.main", 112, 0); 17 setMapTex(L"rearlegtip.main", 196, 0); 18 setMapTex(L"head.upperhead", 112, 30); 19 setMapTex(L"wing.bone", 112, 88); 20 setMapTex(L"head.upperlip", 176, 44); 21 setMapTex(L"jaw.jaw", 176, 65); 22 setMapTex(L"frontleg.main", 112, 104); 23 setMapTex(L"wingtip.bone", 112, 136); 24 setMapTex(L"frontfoot.main", 144, 104); 25 setMapTex(L"neck.box", 192, 104); 26 setMapTex(L"frontlegtip.main", 226, 138); 27 setMapTex(L"body.scale", 220, 53); 28 setMapTex(L"head.scale", 0, 0); 29 setMapTex(L"neck.scale", 48, 0); 30 setMapTex(L"head.nostril", 112, 0); 31 32 float zo = -16; 33 head = new ModelPart(this, L"head"); 34 head->addBox(L"upperlip", -6, -1, -8 + zo, 12, 5, 16); 35 head->addBox(L"upperhead", -8, -8, 6 + zo, 16, 16, 16); 36 head->bMirror = true; 37 head->addBox(L"scale", -1 - 4, -12, 12 + zo, 2, 4, 6); 38 head->addBox(L"nostril", -1 - 4, -3, -6 + zo, 2, 2, 4); 39 head->bMirror = false; 40 head->addBox(L"scale", -1 + 4, -12, 12 + zo, 2, 4, 6); 41 head->addBox(L"nostril", -1 + 4, -3, -6 + zo, 2, 2, 4); 42 43 jaw = new ModelPart(this, L"jaw"); 44 jaw->setPos(0, 4, 8 + zo); 45 jaw->addBox(L"jaw", -6, 0, -16, 12, 4, 16); 46 head->addChild(jaw); 47 48 neck = new ModelPart(this, L"neck"); 49 neck->addBox(L"box", -5, -5, -5, 10, 10, 10); 50 neck->addBox(L"scale", -1, -9, -5 + 2, 2, 4, 6); 51 52 body = new ModelPart(this, L"body"); 53 body->setPos(0, 4, 8); 54 body->addBox(L"body", -12, 0, -16, 24, 24, 64); 55 body->addBox(L"scale", -1, -6, -10 + 20 * 0, 2, 6, 12); 56 body->addBox(L"scale", -1, -6, -10 + 20 * 1, 2, 6, 12); 57 body->addBox(L"scale", -1, -6, -10 + 20 * 2, 2, 6, 12); 58 59 wing = new ModelPart(this, L"wing"); 60 wing->setPos(-12, 5, 2); 61 wing->addBox(L"bone", -56, -4, -4, 56, 8, 8); 62 wing->addBox(L"skin", -56, 0, +2, 56, 0, 56); 63 wingTip = new ModelPart(this, L"wingtip"); 64 wingTip->setPos(-56, 0, 0); 65 wingTip->addBox(L"bone", -56, -2, -2, 56, 4, 4); 66 wingTip->addBox(L"skin", -56, 0, +2, 56, 0, 56); 67 wing->addChild(wingTip); 68 69 frontLeg = new ModelPart(this, L"frontleg"); 70 frontLeg->setPos(-12, 20, 2); 71 frontLeg->addBox(L"main", -4, -4, -4, 8, 24, 8); 72 frontLegTip = new ModelPart(this, L"frontlegtip"); 73 frontLegTip->setPos(0, 20, -1); 74 frontLegTip->addBox(L"main", -3, -1, -3, 6, 24, 6); 75 frontLeg->addChild(frontLegTip); 76 frontFoot = new ModelPart(this, L"frontfoot"); 77 frontFoot->setPos(0, 23, 0); 78 frontFoot->addBox(L"main", -4, 0, -12, 8, 4, 16); 79 frontLegTip->addChild(frontFoot); 80 81 rearLeg = new ModelPart(this, L"rearleg"); 82 rearLeg->setPos(-12 - 4, 16, 2 + 40); 83 rearLeg->addBox(L"main", -8, -4, -8, 16, 32, 16); 84 rearLegTip = new ModelPart(this, L"rearlegtip"); 85 rearLegTip->setPos(0, 32, -4); 86 rearLegTip->addBox(L"main", -6, -2, 0, 12, 32, 12); 87 rearLeg->addChild(rearLegTip); 88 rearFoot = new ModelPart(this, L"rearfoot"); 89 rearFoot->setPos(0, 31, 4); 90 rearFoot->addBox(L"main", -9, 0, -20, 18, 6, 24); 91 rearLegTip->addChild(rearFoot); 92 93 // 4J added - compile now to avoid random performance hit first time cubes are rendered 94 // 4J Stu - Not just performance, but alpha+depth tests don't work right unless we compile here 95 head->compile(1.0f/16.0f); 96 jaw->compile(1.0f/16.0f); 97 neck->compile(1.0f/16.0f); 98 body->compile(1.0f/16.0f); 99 wing->compile(1.0f/16.0f); 100 wingTip->compile(1.0f/16.0f); 101 frontLeg->compile(1.0f/16.0f); 102 frontLegTip->compile(1.0f/16.0f); 103 frontFoot->compile(1.0f/16.0f); 104 rearLeg->compile(1.0f/16.0f); 105 rearLegTip->compile(1.0f/16.0f); 106 rearFoot->compile(1.0f/16.0f); 107} 108 109void DragonModel::prepareMobModel(shared_ptr<LivingEntity> mob, float time, float r, float a) 110{ 111 this->a = a; 112} 113 114void DragonModel::render(shared_ptr<Entity> entity, float time, float r, float bob, float yRot, float xRot, float scale, bool usecompiled) 115{ 116 glPushMatrix(); 117 shared_ptr<EnderDragon> dragon = dynamic_pointer_cast<EnderDragon>(entity); 118 119 float ttt = dragon->oFlapTime + (dragon->flapTime - dragon->oFlapTime) * a; 120 jaw->xRot = (float) (Mth::sin(ttt * PI * 2) + 1) * 0.2f; 121 122 float yo = (float) (Mth::sin(ttt * PI * 2 - 1) + 1); 123 yo = (yo * yo * 1 + yo * 2) * 0.05f; 124 125 glTranslatef(0, yo - 2.0f, -3); 126 glRotatef(yo * 2, 1, 0, 0); 127 128 float yy = -30.0f; 129 float zz = 22.0f; 130 float xx = 0.0f; 131 132 float rotScale = 1.5f; 133 134 135 double startComponents[3]; 136 doubleArray start = doubleArray(startComponents,3); 137 dragon->getLatencyPos(start, 6, a); 138 139 double latencyPosAComponents[3], latencyPosBComponents[3]; 140 doubleArray latencyPosA = doubleArray( latencyPosAComponents, 3 ); 141 doubleArray latencyPosB = doubleArray( latencyPosBComponents, 3 ); 142 dragon->getLatencyPos(latencyPosA, 5, a); 143 dragon->getLatencyPos(latencyPosB, 10, a); 144 float rot2 = rotWrap(latencyPosA[0] - latencyPosB[0]); 145 float rot = rotWrap(latencyPosA[0] + rot2 / 2); 146 147 yy += 2.0f; 148 149 float rr = 0; 150 float roff = ttt * PI * 2.0f; 151 yy = 20.0f; 152 zz = -12.0f; 153 double pComponents[3]; 154 doubleArray p = doubleArray(pComponents,3); 155 156 for (int i = 0; i < 5; i++) 157 { 158 dragon->getLatencyPos(p, 5 - i, a); 159 160 rr = (float) Mth::cos(i * 0.45f + roff) * 0.15f; 161 neck->yRot = rotWrap(dragon->getHeadPartYRotDiff(i, start, p)) * PI / 180.0f * rotScale; // 4J replaced "p[0] - start[0] with call to getHeadPartYRotDiff 162 neck->xRot = rr + (float) (dragon->getHeadPartYOffset(i, start, p)) * PI / 180.0f * rotScale * 5.0f; // 4J replaced "p[1] - start[1]" with call to getHeadPartYOffset 163 neck->zRot = -rotWrap(p[0] - rot) * PI / 180.0f * rotScale; 164 165 neck->y = yy; 166 neck->z = zz; 167 neck->x = xx; 168 yy += Mth::sin(neck->xRot) * 10.0f; 169 zz -= Mth::cos(neck->yRot) * Mth::cos(neck->xRot) * 10.0f; 170 xx -= Mth::sin(neck->yRot) * Mth::cos(neck->xRot) * 10.0f; 171 neck->render(scale,usecompiled); 172 } 173 174 head->y = yy; 175 head->z = zz; 176 head->x = xx; 177 dragon->getLatencyPos(p, 0, a); 178 head->yRot = rotWrap(dragon->getHeadPartYRotDiff(6, start, p)) * PI / 180.0f * 1; // 4J replaced "p[0] - start[0] with call to getHeadPartYRotDiff 179 head->xRot = (float) (dragon->getHeadPartYOffset(6, start, p)) * PI / 180.0f * rotScale * 5.0f; // 4J Added 180 head->zRot = -rotWrap(p[0] - rot) * PI / 180 * 1; 181 head->render(scale,usecompiled); 182 glPushMatrix(); 183 glTranslatef(0, 1, 0); 184 glRotatef(-(float) (rot2) * rotScale * 1, 0, 0, 1); 185 glTranslatef(0, -1, 0); 186 body->zRot = 0; 187 body->render(scale,usecompiled); 188 189 glEnable(GL_CULL_FACE); 190 for (int i = 0; i < 2; i++) 191 { 192 float flapTime = ttt * PI * 2; 193 wing->xRot = 0.125f - (float) (Mth::cos(flapTime)) * 0.2f; 194 wing->yRot = 0.25f; 195 wing->zRot = (float) (Mth::sin(flapTime) + 0.125f) * 0.8f; 196 wingTip->zRot = -(float) (Mth::sin(flapTime + 2.0f) + 0.5f) * 0.75f; 197 198 rearLeg->xRot = 1.0f + yo * 0.1f; 199 rearLegTip->xRot = 0.5f + yo * 0.1f; 200 rearFoot->xRot = 0.75f + yo * 0.1f; 201 202 frontLeg->xRot = 1.3f + yo * 0.1f; 203 frontLegTip->xRot = -0.5f - yo * 0.1f; 204 frontFoot->xRot = 0.75f + yo * 0.1f; 205 wing->render(scale,usecompiled); 206 frontLeg->render(scale,usecompiled); 207 rearLeg->render(scale,usecompiled); 208 glScalef(-1, 1, 1); 209 if (i == 0) 210 { 211 glCullFace(GL_FRONT); 212 } 213 } 214 glPopMatrix(); 215 glCullFace(GL_BACK); 216 glDisable(GL_CULL_FACE); 217 218 rr = -(float) Mth::sin(ttt * PI * 2) * 0.0f; 219 roff = ttt * PI * 2; 220 yy = 10; 221 zz = 60; 222 xx = 0; 223 dragon->getLatencyPos(start, 11, a); 224 for (int i = 0; i < 12; i++) 225 { 226 dragon->getLatencyPos(p, 12 + i, a); 227 rr += Mth::sin(i * 0.45f + roff) * 0.05f; 228 neck->yRot = (rotWrap(p[0] - start[0]) * rotScale + 180) * PI / 180; 229 neck->xRot = rr + (float) (p[1] - start[1]) * PI / 180 * rotScale * 5; 230 neck->zRot = rotWrap(p[0] - rot) * PI / 180 * rotScale; 231 neck->y = yy; 232 neck->z = zz; 233 neck->x = xx; 234 yy += Mth::sin(neck->xRot) * 10; 235 zz -= Mth::cos(neck->yRot) * Mth::cos(neck->xRot) * 10; 236 xx -= Mth::sin(neck->yRot) * Mth::cos(neck->xRot) * 10; 237 neck->render(scale,usecompiled); 238 } 239 glPopMatrix(); 240} 241float DragonModel::rotWrap(double d) 242{ 243 while (d >= 180) 244 d -= 360; 245 while (d < -180) 246 d += 360; 247 return (float) d; 248}