the whole game

This commit is contained in:
Kolyah35
2026-03-02 22:04:18 +03:00
parent 816e9060b4
commit f0617a5d22
2069 changed files with 581500 additions and 0 deletions

52
src/client/model/ChestModel.h Executable file
View File

@@ -0,0 +1,52 @@
#ifndef NET_MINECRAFT_CLIENT_MODEL__ChestModel_H__
#define NET_MINECRAFT_CLIENT_MODEL__ChestModel_H__
//package net.minecraft.client.model;
#include "Model.h"
#include "geom/ModelPart.h"
class ChestModel: public Model
{
public:
ChestModel()
: lid(0, 0),
lock(0, 0),
bottom(0, 0)
{
lid.setModel(this);
lid.setTexSize(64, 64);
lid.addBox(0.0f, -5, -14, 14, 5, 14, 0);
lid.x = 1;
lid.y = 7;
lid.z = 15;
lock.setModel(this);
lock.setTexSize(64, 64);
lock.addBox(-1, -2, -15, 2, 4, 1, 0);
lock.x = 8;
lock.y = 7;
lock.z = 15;
bottom.setModel(this);
bottom.setTexSize(64, 64);
bottom.addBox(0.0f, 0, 0, 14, 10, 14, 0);
bottom.x = 1;
bottom.y = 6;
bottom.z = 1;
}
void render() {
lock.xRot = lid.xRot;
lid.render(1 / 16.0f);
lock.render(1 / 16.0f);
bottom.render(1 / 16.0f);
}
ModelPart lid;
ModelPart bottom;
ModelPart lock;
};
#endif /*NET_MINECRAFT_CLIENT_MODEL__ChestModel_H__*/

101
src/client/model/ChickenModel.cpp Executable file
View File

@@ -0,0 +1,101 @@
#include "ChickenModel.h"
#include "../../world/entity/Entity.h"
ChickenModel::ChickenModel()
: head(0, 0),
beak(14, 0),
redThing(14, 4),
body(0, 9),
leg0(26, 0),
leg1(26, 0),
wing0(24, 13),
wing1(24, 13)
{
head.setModel(this);
beak.setModel(this);
redThing.setModel(this);
body.setModel(this);
leg0.setModel(this);
leg1.setModel(this);
wing0.setModel(this);
wing1.setModel(this);
int yo = 16;
head.addBox(-2, -6, -2, 4, 6, 3, 0); // Head
head.setPos(0, -1 + (float)yo, -4);
beak.addBox(-2, -4, -4, 4, 2, 2, 0); // Beak
beak.setPos(0, -1 + (float)yo, -4);
redThing.addBox(-1, -2, -3, 2, 2, 2, 0); // Beak
redThing.setPos(0, -1 + (float)yo, -4);
body.addBox(-3, -4, -3, 6, 8, 6, 0); // Body
body.setPos(0, 0 + (float)yo, 0);
leg0.addBox(-1, 0, -3, 3, 5, 3); // Leg0
leg0.setPos(-2, 3 + (float)yo, 1);
leg1.addBox(-1, 0, -3, 3, 5, 3); // Leg1
leg1.setPos(1, 3 + (float)yo, 1);
wing0.addBox(0, 0, -3, 1, 4, 6); // Wing0
wing0.setPos(-4, -3 + (float)yo, 0);
wing1.addBox(-1, 0, -3, 1, 4, 6); // Wing1
wing1.setPos(4, -3 + (float)yo, 0);
}
void ChickenModel::render( Entity* entity, float time, float r, float bob, float yRot, float xRot, float scale )
{
setupAnim(time, r, bob, yRot, xRot, scale);
if (young) {
float ss = 2;
glPushMatrix();
glTranslatef(0, 5 * scale, 2 * scale);
head.render(scale);
beak.render(scale);
redThing.render(scale);
glPopMatrix();
glPushMatrix();
glScalef(1 / ss, 1 / ss, 1 / ss);
glTranslatef(0, 24 * scale, 0);
body.render(scale);
leg0.render(scale);
leg1.render(scale);
wing0.render(scale);
wing1.render(scale);
glPopMatrix();
} else {
head.render(scale);
beak.render(scale);
redThing.render(scale);
body.render(scale);
leg0.render(scale);
leg1.render(scale);
wing0.render(scale);
wing1.render(scale);
}
}
void ChickenModel::setupAnim( float time, float r, float bob, float yRot, float xRot, float scale )
{
head.xRot = -((xRot / (float) (180 / Mth::PI)));
head.yRot = yRot / (float) (180 / Mth::PI);
beak.xRot = head.xRot;
beak.yRot = head.yRot;
redThing.xRot = head.xRot;
redThing.yRot = head.yRot;
body.xRot = 90 / (float) (180 / Mth::PI);
const float pend = Mth::cos(time * 0.6662f) * 1.4f * r;
leg0.xRot = pend;
leg1.xRot = -pend;
wing0.zRot = bob;
wing1.zRot = -bob;
}

23
src/client/model/ChickenModel.h Executable file
View File

@@ -0,0 +1,23 @@
#ifndef NET_MINECRAFT_CLIENT_MODEL__ChickenModel_H__
#define NET_MINECRAFT_CLIENT_MODEL__ChickenModel_H__
#include "Model.h"
#include "geom/ModelPart.h"
class Entity;
class ChickenModel: public Model
{
typedef Model super;
public:
ModelPart head, hair, body, leg0, leg1, wing0, wing1, beak, redThing;
ChickenModel();
/*@Override*/
void render(Entity* entity, float time, float r, float bob, float yRot, float xRot, float scale);
void setupAnim(float time, float r, float bob, float yRot, float xRot, float scale);
};
#endif /*NET_MINECRAFT_CLIENT_MODEL__ChickenModel_H__*/

30
src/client/model/CowModel.cpp Executable file
View File

@@ -0,0 +1,30 @@
#include "CowModel.h"
CowModel::CowModel()
: super(12, 0)
{
head = ModelPart(0, 0);
head.setModel(this);
head.addBox(-4, -4, -6, 8, 8, 6, 0); // Head
head.setPos(0, 12 - 6 - 2, -8);
head.texOffs(22, 0).addBox(-5, -5, -4, 1, 3, 1, 0); // Horn1
head.texOffs(22, 0).addBox(+4, -5, -4, 1, 3, 1, 0); // Horn1
body = ModelPart(18, 4);
body.setModel(this);
body.addBox(-6, -10, -7, 12, 18, 10, 0); // Body
body.setPos(0, 11 + 6 - 12, 2);
body.texOffs(52, 0).addBox(-2, 2, -8, 4, 6, 1);
leg0.x -= 1;
leg1.x += 1;
leg0.z += 0;
leg1.z += 0;
leg2.x -= 1;
leg3.x += 1;
leg2.z -= 1;
leg3.z -= 1;
this->zHeadOffs += 2;
}

15
src/client/model/CowModel.h Executable file
View File

@@ -0,0 +1,15 @@
#ifndef NET_MINECRAFT_CLIENT_MODEL__CowModel_H__
#define NET_MINECRAFT_CLIENT_MODEL__CowModel_H__
//package net.minecraft.client.model;
#include "QuadrupedModel.h"
class CowModel: public QuadrupedModel
{
typedef QuadrupedModel super;
public:
CowModel();
};
#endif /*NET_MINECRAFT_CLIENT_MODEL__CowModel_H__*/

82
src/client/model/CreeperModel.h Executable file
View File

@@ -0,0 +1,82 @@
#ifndef NET_MINECRAFT_CLIENT_MODEL__CreeperModel_H__
#define NET_MINECRAFT_CLIENT_MODEL__CreeperModel_H__
//package net.minecraft.client.model;
#include "Model.h"
#include "geom/ModelPart.h"
#include "../../world/entity/Entity.h"
class CreeperModel: public Model
{
typedef Model super;
public:
ModelPart head, /*hair,*/ body, leg0, leg1, leg2, leg3;
CreeperModel(float g = 0)
: head(0, 0),
//hair(32, 0),
body(16, 16),
leg0(0, 16),
leg1(0, 16),
leg2(0, 16),
leg3(0, 16)
{
float yo = 4;
head.setModel(this);
//hair.setModel(this);
body.setModel(this);
leg0.setModel(this);
leg1.setModel(this);
leg2.setModel(this);
leg3.setModel(this);
head.addBox(-4, -8, -4, 8, 8, 8, g); // Head
head.setPos(0, yo, 0);
// hair.addBox(-4, -8, -4, 8, 8, 8, g + 0.5f); // Head
// hair.setPos(0, yo, 0);
body.addBox(-4, 0, -2, 8, 12, 4, g); // Body
body.setPos(0, yo, 0);
leg0.addBox(-2, 0, -2, 4, 6, 4, g); // Leg0
leg0.setPos(-2, 12 + yo, 4);
leg1.addBox(-2, 0, -2, 4, 6, 4, g); // Leg1
leg1.setPos(2, 12 + yo, 4);
leg2.addBox(-2, 0, -2, 4, 6, 4, g); // Leg2
leg2.setPos(-2, 12 + yo, -4);
leg3.addBox(-2, 0, -2, 4, 6, 4, g); // Leg3
leg3.setPos(2, 12 + yo, -4);
}
/*@Override*/
void render(Entity* entity, float time, float r, float bob, float yRot, float xRot, float scale) {
setupAnim(time, r, bob, yRot, xRot, scale);
head.render(scale);
body.render(scale);
leg0.render(scale);
leg1.render(scale);
leg2.render(scale);
leg3.render(scale);
}
void setupAnim(float time, float r, float bob, float yRot, float xRot, float scale) {
head.yRot = yRot / (float) (180 / Mth::PI);
head.xRot = xRot / (float) (180 / Mth::PI);
const float pend = (Mth::cos(time * 0.6662f) * 1.4f) * r;
leg0.xRot = pend;
leg1.xRot = -pend;
leg2.xRot = -pend;
leg3.xRot = pend;
}
};
#endif /*NET_MINECRAFT_CLIENT_MODEL__CreeperModel_H__*/

View File

@@ -0,0 +1,246 @@
#include "HumanoidModel.h"
#include "../Minecraft.h"
#include "../../util/Mth.h"
#include "../../world/entity/player/Player.h"
#include "../../world/entity/player/Inventory.h"
HumanoidModel::HumanoidModel( float g /*= 0*/, float yOffset /*= 0*/ )
: holdingLeftHand(false),
holdingRightHand(false),
sneaking(false),
bowAndArrow(false),
head(0, 0),
//ear (24, 0),
//hair(32, 0),
body(16, 16),
arm0(24 + 16, 16),
arm1(24 + 16, 16),
leg0(0, 16),
leg1(0, 16)
{
head.setModel(this);
body.setModel(this);
arm0.setModel(this);
arm1.setModel(this);
leg0.setModel(this);
leg1.setModel(this);
head.addBox(-4, -8, -4, 8, 8, 8, g); // Head
head.setPos(0, 0 + yOffset, 0);
//ear.addBox(-3, -6, -1, 6, 6, 1, g); // Ear
//hair.addBox(-4, -8, -4, 8, 8, 8, g + 0.5f); // Head
// hair.setPos(0, 0 + yOffset, 0);
body.addBox(-4, 0, -2, 8, 12, 4, g); // Body
body.setPos(0, 0 + yOffset, 0);
arm0.addBox(-3, -2, -2, 4, 12, 4, g); // Arm0
arm0.setPos(-5, 2 + yOffset, 0);
arm1.mirror = true;
arm1.addBox(-1, -2, -2, 4, 12, 4, g); // Arm1
arm1.setPos(5, 2 + yOffset, 0);
leg0.addBox(-2, 0, -2, 4, 12, 4, g); // Leg0
leg0.setPos(-2, 12 + yOffset, 0);
leg1.mirror = true;
leg1.addBox(-2, 0, -2, 4, 12, 4, g); // Leg1
leg1.setPos(2, 12 + yOffset, 0);
}
void HumanoidModel::render(Entity* e, float time, float r, float bob, float yRot, float xRot, float scale )
{
if(e != NULL && e->isMob()) {
Mob* mob = (Mob*)(e);
ItemInstance* item = mob->getCarriedItem();
if(item != NULL) {
if(mob->getUseItemDuration() > 0) {
UseAnim::UseAnimation anim = item->getUseAnimation();
if(anim == UseAnim::bow) {
bowAndArrow = true;
}
}
}
}
setupAnim(time, r, bob, yRot, xRot, scale);
head.render(scale);
body.render(scale);
arm0.render(scale);
arm1.render(scale);
leg0.render(scale);
leg1.render(scale);
bowAndArrow = false;
//hair.render(scale);
}
void HumanoidModel::render( HumanoidModel* model, float scale )
{
head.yRot = model->head.yRot;
head.y = model->head.y;
head.xRot = model->head.xRot;
//hair.yRot = head.yRot;
//hair.xRot = head.xRot;
arm0.xRot = model->arm0.xRot;
arm0.zRot = model->arm0.zRot;
arm1.xRot = model->arm1.xRot;
arm1.zRot = model->arm1.zRot;
leg0.xRot = model->leg0.xRot;
leg1.xRot = model->leg1.xRot;
head.render(scale);
body.render(scale);
arm0.render(scale);
arm1.render(scale);
leg0.render(scale);
leg1.render(scale);
//hair.render(scale);
}
void HumanoidModel::renderHorrible( float time, float r, float bob, float yRot, float xRot, float scale )
{
setupAnim(time, r, bob, yRot, xRot, scale);
head.renderHorrible(scale);
body.renderHorrible(scale);
arm0.renderHorrible(scale);
arm1.renderHorrible(scale);
leg0.renderHorrible(scale);
leg1.renderHorrible(scale);
//hair.renderHorrible(scale);
}
// Updated to match Minecraft Java, all except hair.
void HumanoidModel::setupAnim( float time, float r, float bob, float yRot, float xRot, float scale )
{
head.yRot = yRot / (180 / Mth::PI);
head.xRot = xRot / (180 / Mth::PI);
const float tcos0 = Mth::cos(time * 0.6662f) * r;
const float tcos1 = Mth::cos(time * 0.6662f + Mth::PI) * r;
arm0.xRot = tcos1;
arm1.xRot = tcos0;
arm0.zRot = 0;
arm1.zRot = 0;
leg0.xRot = tcos0 * 1.4f;
leg1.xRot = tcos1 * 1.4f;
leg0.yRot = 0;
leg1.yRot = 0;
if (riding) {
arm0.xRot += -Mth::PI / 2 * 0.4f;
arm1.xRot += -Mth::PI / 2 * 0.4f;
leg0.xRot = -Mth::PI / 2 * 0.8f;
leg1.xRot = -Mth::PI / 2 * 0.8f;
leg0.yRot = Mth::PI / 2 * 0.2f;
leg1.yRot = -Mth::PI / 2 * 0.2f;
}
if (holdingLeftHand != 0) {
arm1.xRot = arm1.xRot * 0.5f - Mth::PI / 2.0f * 0.2f * holdingLeftHand;
}
if (holdingRightHand != 0) {
arm0.xRot = arm0.xRot * 0.5f - Mth::PI / 2.0f * 0.2f * holdingRightHand;
}
arm0.yRot = 0;
arm1.yRot = 0;
if (attackTime > -9990) {
float swing = attackTime;
body.yRot = Mth::sin(Mth::sqrt(swing) * Mth::PI * 2) * 0.2f;
arm0.z = Mth::sin(body.yRot) * 5;
arm0.x = -Mth::cos(body.yRot) * 5;
arm1.z = -Mth::sin(body.yRot) * 5;
arm1.x = Mth::cos(body.yRot) * 5;
arm0.yRot += body.yRot;
arm1.yRot += body.yRot;
arm1.xRot += body.yRot;
swing = 1 - attackTime;
swing *= swing;
swing *= swing;
swing = 1 - swing;
float aa = Mth::sin(swing * Mth::PI);
float bb = Mth::sin(attackTime * Mth::PI) * -(head.xRot - 0.7f) * 0.75f;
arm0.xRot -= aa * 1.2f + bb;
arm0.yRot += body.yRot * 2;
arm0.zRot = Mth::sin(attackTime * Mth::PI) * -0.4f;
}
if (sneaking) {
body.xRot = 0.5f;
arm0.xRot += 0.4f;
arm1.xRot += 0.4f;
leg0.z = +4.0f;
leg1.z = +4.0f;
leg0.y = +9.0f;
leg1.y = +9.0f;
head.y = +1;
} else {
body.xRot = 0.0f;
leg0.z = +0.0f;
leg1.z = +0.0f;
leg0.y = +12.0f;
leg1.y = +12.0f;
head.y = 0;
}
const float bcos = Mth::cos(bob * 0.09f) * 0.05f + 0.05f;
const float bsin = Mth::sin(bob * 0.067f) * 0.05f;
arm0.zRot += bcos;
arm1.zRot -= bcos;
arm0.xRot += bsin;
arm1.xRot -= bsin;
if (bowAndArrow) {
float attack2 = 0;
float attack = 0;
arm0.zRot = 0;
arm1.zRot = 0;
arm0.yRot = -(0.1f - attack2 * 0.6f) + head.yRot;
arm1.yRot = +(0.1f - attack2 * 0.6f) + head.yRot + 0.4f;
arm0.xRot = -Mth::PI / 2.0f + head.xRot;
arm1.xRot = -Mth::PI / 2.0f + head.xRot;
arm0.xRot -= attack2 * 1.2f - attack * 0.4f;
arm1.xRot -= attack2 * 1.2f - attack * 0.4f;
arm0.zRot += bcos;
arm1.zRot -= bcos;
arm0.xRot += bsin;
arm1.xRot -= bsin;
}
}
void HumanoidModel::onGraphicsReset()
{
head.onGraphicsReset();
body.onGraphicsReset();
arm0.onGraphicsReset();
arm1.onGraphicsReset();
leg0.onGraphicsReset();
leg1.onGraphicsReset();
//hair.onGraphicsReset();
}
//void renderHair(float scale) {
// hair.yRot = head.yRot;
// hair.xRot = head.xRot;
// hair.render(scale);
//}
//
//void renderEars(float scale) {
// ear.yRot = head.yRot;
// ear.xRot = head.xRot;
// ear.x=0;
// ear.y=0;
// ear.render(scale);
//}
//

View File

@@ -0,0 +1,28 @@
#ifndef NET_MINECRAFT_CLIENT_MODEL__HumanoidModel_H__
#define NET_MINECRAFT_CLIENT_MODEL__HumanoidModel_H__
//package net.minecraft.client.model;
#include "Model.h"
#include "geom/ModelPart.h"
class ItemInstance;
class HumanoidModel: public Model
{
public:
HumanoidModel(float g = 0, float yOffset = 0);
void setupAnim(float time, float r, float bob, float yRot, float xRot, float scale);
void render(HumanoidModel* model, float scale);
void render(Entity* e, float time, float r, float bob, float yRot, float xRot, float scale);
void renderHorrible(float time, float r, float bob, float yRot, float xRot, float scale);
void onGraphicsReset();
ModelPart head, /*hair,*/ body, arm0, arm1, leg0, leg1;//, ear;
bool holdingLeftHand;
bool holdingRightHand;
bool sneaking;
bool bowAndArrow;
};
#endif /*NET_MINECRAFT_CLIENT_MODEL__HumanoidModel_H__*/

48
src/client/model/Model.h Executable file
View File

@@ -0,0 +1,48 @@
#ifndef NET_MINECRAFT_CLIENT_MODEL__Model_H__
#define NET_MINECRAFT_CLIENT_MODEL__Model_H__
//package net.minecraft.client.model;
#include <vector>
#include "geom/ModelPart.h"
class Mob;
class Entity;
class Model
{
protected:
Model()
: riding(false),
attackTime(0),
texWidth(64),
texHeight(32),
young(true)
{}
public:
virtual ~Model() {}
virtual void onGraphicsReset() {
for (unsigned int i = 0; i < cubes.size(); ++i)
cubes[i]->onGraphicsReset();
}
virtual void render(Entity* e, float time, float r, float bob, float yRot, float xRot, float scale) {}
virtual void renderHorrible(float time, float r, float bob, float yRot, float xRot, float scale) {}
virtual void setupAnim(float time, float r, float bob, float yRot, float xRot, float scale) {}
virtual void prepareMobModel(Mob* mob, float time, float r, float a) {}
float attackTime;
bool riding;
int texWidth;
int texHeight;
std::vector<ModelPart*> cubes;
bool young;
private:
//Map<String, TexOffs> mappedTexOffs = new HashMap<String, TexOffs>();
};
#endif /*NET_MINECRAFT_CLIENT_MODEL__Model_H__*/

17
src/client/model/ModelInclude.h Executable file
View File

@@ -0,0 +1,17 @@
#ifndef NET_MINECRAFT_CLIENT_MODEL__ModelInclude_H__
#define NET_MINECRAFT_CLIENT_MODEL__ModelInclude_H__
#include "HumanoidModel.h"
#include "ChickenModel.h"
#include "CowModel.h"
#include "PigModel.h"
#include "SheepModel.h"
#include "SheepFurModel.h"
#include "ZombieModel.h"
#include "SkeletonModel.h"
#include "SignModel.h"
#endif /*NET_MINECRAFT_CLIENT_MODEL__ModelInclude_H__*/

8
src/client/model/PigModel.cpp Executable file
View File

@@ -0,0 +1,8 @@
#include "PigModel.h"
PigModel::PigModel( float g /*= 0*/ )
: super(6, g)
{
head.texOffs(16, 16).addBox(-2, 0, -9, 4, 3, 1, g);
yHeadOffs = 4;
}

15
src/client/model/PigModel.h Executable file
View File

@@ -0,0 +1,15 @@
#ifndef NET_MINECRAFT_CLIENT_MODEL__PigModel_H__
#define NET_MINECRAFT_CLIENT_MODEL__PigModel_H__
//package net.minecraft.client.model;
#include "QuadrupedModel.h"
class PigModel: public QuadrupedModel
{
typedef QuadrupedModel super;
public:
PigModel(float g = 0);
};
#endif /*NET_MINECRAFT_CLIENT_MODEL__PigModel_H__*/

View File

@@ -0,0 +1,122 @@
#include "QuadrupedModel.h"
#include "geom/ModelPart.h"
#include "../../util/Mth.h"
QuadrupedModel::QuadrupedModel( int legSize, float g )
: yHeadOffs(8),
zHeadOffs(4),
head(0, 0),
body(28, 8),
leg0(0, 16),
leg1(0, 16),
leg2(0, 16),
leg3(0, 16)
{
head.setModel(this);
body.setModel(this);
leg0.setModel(this);
leg1.setModel(this);
leg2.setModel(this);
leg3.setModel(this);
head.addBox(-4, -4, -8, 8, 8, 8, g); // Head
head.setPos(0, 12 + 6 - (float)legSize, -6);
body.addBox(-5, -10, -7, 10, 16, 8, g); // Body
body.setPos(0, 11 + 6 - (float)legSize, 2);
leg0.addBox(-2, 0, -2, 4, legSize, 4, g); // Leg0
leg0.setPos(-3, 18 + 6 - (float)legSize, 7);
leg1.addBox(-2, 0, -2, 4, legSize, 4, g); // Leg1
leg1.setPos(3, 18 + 6 - (float)legSize, 7);
leg2.addBox(-2, 0, -2, 4, legSize, 4, g); // Leg2
leg2.setPos(-3, 18 + 6 - (float)legSize, -5);
leg3.addBox(-2, 0, -2, 4, legSize, 4, g); // Leg3
leg3.setPos(3, 18 + 6 - (float)legSize, -5);
}
void QuadrupedModel::render( Entity* entity, float time, float r, float bob, float yRot, float xRot, float scale )
{
setupAnim(time, r, bob, yRot, xRot, scale);
if (young) {
float ss = 2.0f;
glPushMatrix();
glTranslatef(0, yHeadOffs * scale, zHeadOffs * scale);
head.render(scale);
glPopMatrix();
glPushMatrix();
glScalef(1 / ss, 1 / ss, 1 / ss);
glTranslatef(0, 24 * scale, 0);
body.render(scale);
leg0.render(scale);
leg1.render(scale);
leg2.render(scale);
leg3.render(scale);
glPopMatrix();
} else {
head.render(scale);
body.render(scale);
leg0.render(scale);
leg1.render(scale);
leg2.render(scale);
leg3.render(scale);
}
}
void QuadrupedModel::render( QuadrupedModel* model, float scale )
{
head.yRot = model->head.yRot;
head.xRot = model->head.xRot;
head.y = model->head.y;
head.x = model->head.x;
body.yRot = model->body.yRot;
body.xRot = model->body.xRot;
leg0.xRot = model->leg0.xRot;
leg1.xRot = model->leg1.xRot;
leg2.xRot = model->leg2.xRot;
leg3.xRot = model->leg3.xRot;
if (young) {
float ss = 2.0f;
glPushMatrix();
glTranslatef(0, 8 * scale, 4 * scale);
head.render(scale);
glPopMatrix();
glPushMatrix();
glScalef(1 / ss, 1 / ss, 1 / ss);
glTranslatef(0, 24 * scale, 0);
body.render(scale);
leg0.render(scale);
leg1.render(scale);
leg2.render(scale);
leg3.render(scale);
glPopMatrix();
} else {
head.render(scale);
body.render(scale);
leg0.render(scale);
leg1.render(scale);
leg2.render(scale);
leg3.render(scale);
}
}
void QuadrupedModel::setupAnim( float time, float r, float bob, float yRot, float xRot, float scale )
{
head.xRot = xRot / (180.f / Mth::PI);
head.yRot = yRot / (180.f / Mth::PI);
body.xRot = 90 / (180.f / Mth::PI);
const float pend = Mth::cos(time * 0.6662f) * 1.4f * r;
leg0.xRot = pend;
leg1.xRot = -pend;
leg2.xRot = -pend;
leg3.xRot = pend;
}

View File

@@ -0,0 +1,28 @@
#ifndef NET_MINECRAFT_CLIENT_MODEL__QuadrupedModel_H__
#define NET_MINECRAFT_CLIENT_MODEL__QuadrupedModel_H__
//package net.minecraft.client.model;
#include "Model.h"
#include "geom/ModelPart.h"
class Entity;
class QuadrupedModel: public Model
{
public:
QuadrupedModel(int legSize, float g);
//@Override
void render(QuadrupedModel* model, float scale);
void render(Entity* entity, float time, float r, float bob, float yRot, float xRot, float scale);
void setupAnim(float time, float r, float bob, float yRot, float xRot, float scale);
ModelPart head, hair, body, leg0, leg1, leg2, leg3;
protected:
float yHeadOffs;
float zHeadOffs;
};
#endif /*NET_MINECRAFT_CLIENT_MODEL__QuadrupedModel_H__*/

View File

@@ -0,0 +1,49 @@
#include "SheepFurModel.h"
#include "geom/ModelPart.h"
#include "../../world/entity/Mob.h"
#include "../../world/entity/animal/Sheep.h"
SheepFurModel::SheepFurModel()
: super(12, 0)
{
head = ModelPart(this, 0, 0);
head.addBox(-3, -4, -4, 6, 6, 6, 0.6f); // Head
head.setPos(0, 12 - 6, -8);
body = ModelPart(this, 28, 8);
body.addBox(-4, -10, -7, 8, 16, 6, 1.75f); // Body
body.setPos(0, 11 + 6 - 12, 2);
float g = 0.5f;
leg0 = ModelPart(this, 0, 16);
leg0.addBox(-2, 0, -2, 4, 6, 4, g); // Leg0
leg0.setPos(-3, 18 + 6 - 12, 7);
leg1 = ModelPart(this, 0, 16);
leg1.addBox(-2, 0, -2, 4, 6, 4, g); // Leg1
leg1.setPos(3, 18 + 6 - 12, 7);
leg2 = ModelPart(this, 0, 16);
leg2.addBox(-2, 0, -2, 4, 6, 4, g); // Leg2
leg2.setPos(-3, 18 + 6 - 12, -5);
leg3 = ModelPart(this, 0, 16);
leg3.addBox(-2, 0, -2, 4, 6, 4, g); // Leg3
leg3.setPos(3, 18 + 6 - 12, -5);
}
void SheepFurModel::prepareMobModel( Mob* mob, float time, float r, float a )
{
super::prepareMobModel(mob, time, r, a);
Sheep* sheep = (Sheep*) mob;
head.y = 6 + sheep->getHeadEatPositionScale(a) * 9.f;
headXRot = sheep->getHeadEatAngleScale(a);
}
void SheepFurModel::setupAnim( float time, float r, float bob, float yRot, float xRot, float scale )
{
super::setupAnim(time, r, bob, yRot, xRot, scale);
head.xRot = headXRot;
}

View File

@@ -0,0 +1,24 @@
#ifndef NET_MINECRAFT_CLIENT_MODEL__SheepFurModel_H__
#define NET_MINECRAFT_CLIENT_MODEL__SheepFurModel_H__
//package net.minecraft.client.model;
#include "QuadrupedModel.h"
class SheepFurModel: public QuadrupedModel
{
typedef QuadrupedModel super;
public:
SheepFurModel();
/*@Override*/
void prepareMobModel(Mob* mob, float time, float r, float a);
/*@Override*/
void setupAnim(float time, float r, float bob, float yRot, float xRot, float scale);
private:
float headXRot;
};
#endif /*NET_MINECRAFT_CLIENT_MODEL__SheepFurModel_H__*/

32
src/client/model/SheepModel.cpp Executable file
View File

@@ -0,0 +1,32 @@
#include "SheepModel.h"
#include "geom/ModelPart.h"
#include "../../world/entity/Mob.h"
#include "../../world/entity/animal/Sheep.h"
SheepModel::SheepModel()
: super(12, 0)
{
head = ModelPart(this, 0, 0);
head.addBox(-3, -4, -6, 6, 6, 8, 0); // Head
head.setPos(0, 12 - 6, -8);
body = ModelPart(this, 28, 8);
body.addBox(-4, -10, -7, 8, 16, 6, 0); // Body
body.setPos(0, 11 + 6 - 12, 2);
}
void SheepModel::prepareMobModel( Mob* mob, float time, float r, float a )
{
super::prepareMobModel(mob, time, r, a);
Sheep* sheep = (Sheep*) mob;
head.y = 6 + sheep->getHeadEatPositionScale(a) * 9.f;
headXRot = sheep->getHeadEatAngleScale(a);
}
void SheepModel::setupAnim( float time, float r, float bob, float yRot, float xRot, float scale )
{
super::setupAnim(time, r, bob, yRot, xRot, scale);
head.xRot = headXRot;
}

23
src/client/model/SheepModel.h Executable file
View File

@@ -0,0 +1,23 @@
#ifndef NET_MINECRAFT_CLIENT_MODEL__SheepModel_H__
#define NET_MINECRAFT_CLIENT_MODEL__SheepModel_H__
//package net.minecraft.client.model;
#include "QuadrupedModel.h"
class SheepModel: public QuadrupedModel
{
typedef QuadrupedModel super;
public:
SheepModel();
/*@Override*/
void prepareMobModel(Mob* mob, float time, float r, float a);
/*@Override*/
void setupAnim(float time, float r, float bob, float yRot, float xRot, float scale);
private:
float headXRot;
};
#endif /*NET_MINECRAFT_CLIENT_MODEL__SheepModel_H__*/

32
src/client/model/SignModel.h Executable file
View File

@@ -0,0 +1,32 @@
#ifndef NET_MINECRAFT_CLIENT_MODEL__SignModel_H__
#define NET_MINECRAFT_CLIENT_MODEL__SignModel_H__
//package net.minecraft.client.model;
#include "Model.h"
#include "geom/ModelPart.h"
class SignModel: public Model
{
public:
SignModel()
: cube(0, 0),
cube2(0, 14)
{
cube.addBox(-12, -14, -1, 24, 12, 2, 0);
cube2.addBox(-1, -2, -1, 2, 14, 2, 0);
cube.setModel(this);
cube2.setModel(this);
}
void render() {
cube.render(1 / 16.0f);
cube2.render(1 / 16.0f);
}
ModelPart cube;
ModelPart cube2;
};
#endif /*NET_MINECRAFT_CLIENT_MODEL__SignModel_H__*/

View File

@@ -0,0 +1,46 @@
#ifndef NET_MINECRAFT_CLIENT_MODEL__SkeletonModel_H__
#define NET_MINECRAFT_CLIENT_MODEL__SkeletonModel_H__
//package net.minecraft.client.model;
#include "ZombieModel.h"
#include "geom/ModelPart.h"
class SkeletonModel: public ZombieModel
{
typedef ZombieModel super;
public:
SkeletonModel()
{
float g = 0;
arm0 = ModelPart(24 + 16, 16);
arm0.setModel(this);
arm0.addBox(-1, -2, -1, 2, 12, 2, g); // Arm0
arm0.setPos(-5, 2, 0);
arm1 = ModelPart(24 + 16, 16);
arm1.setModel(this);
arm1.mirror = true;
arm1.addBox(-1, -2, -1, 2, 12, 2, g); // Arm1
arm1.setPos(5, 2, 0);
leg0 = ModelPart(0, 16);
leg0.setModel(this);
leg0.addBox(-1, 0, -1, 2, 12, 2, g); // Leg0
leg0.setPos(-2, 12, 0);
leg1 = ModelPart(0, 16);
leg1.setModel(this);
leg1.mirror = true;
leg1.addBox(-1, 0, -1, 2, 12, 2, g); // Leg1
leg1.setPos(2, 12, 0);
}
void setupAnim(float time, float r, float bob, float yRot, float xRot, float scale) {
bowAndArrow = true;
super::setupAnim(time, r, bob, yRot, xRot, scale);
}
};
#endif /*NET_MINECRAFT_CLIENT_MODEL__SkeletonModel_H__*/

168
src/client/model/SpiderModel.h Executable file
View File

@@ -0,0 +1,168 @@
#ifndef NET_MINECRAFT_CLIENT_MODEL__SpiderModel_H__
#define NET_MINECRAFT_CLIENT_MODEL__SpiderModel_H__
//package net.minecraft.client.model;
#include "Model.h"
#include "geom/ModelPart.h"
#include "../../world/entity/Entity.h"
#include "../../util/Mth.h"
class SpiderModel: public Model
{
typedef Model super;
public:
ModelPart head, body0, body1, leg0, leg1, leg2, leg3, leg4, leg5, leg6, leg7;
SpiderModel()
: head(32, 4),
body0(0, 0),
body1(0, 12),
leg0(18, 0),
leg1(18, 0),
leg2(18, 0),
leg3(18, 0),
leg4(18, 0),
leg5(18, 0),
leg6(18, 0),
leg7(18, 0)
{
float g = 0;
head.setModel(this);
body0.setModel(this);
body0.setModel(this);
leg0.setModel(this);
leg1.setModel(this);
leg2.setModel(this);
leg3.setModel(this);
leg4.setModel(this);
leg5.setModel(this);
leg6.setModel(this);
leg7.setModel(this);
float yo = 18 + 6 - 9;
head.addBox(-4, -4, -8, 8, 8, 8, g); // Head
head.setPos(0, 0 + yo, -3);
body0.addBox(-3, -3, -3, 6, 6, 6, g); // Body
body0.setPos(0, yo, 0);
body1.addBox(-5, -4, -6, 10, 8, 12, g); // Body
body1.setPos(0, 0 + yo, 3 + 6);
leg0.addBox(-15, -1, -1, 16, 2, 2, g); // Leg0
leg0.setPos(-4, 0 + yo, 2);
leg1.addBox(-1, -1, -1, 16, 2, 2, g); // Leg1
leg1.setPos(4, 0 + yo, 2);
leg2.addBox(-15, -1, -1, 16, 2, 2, g); // Leg2
leg2.setPos(-4, 0 + yo, 1);
leg3.addBox(-1, -1, -1, 16, 2, 2, g); // Leg3
leg3.setPos(4, 0 + yo, 1);
leg4.addBox(-15, -1, -1, 16, 2, 2, g); // Leg0
leg4.setPos(-4, 0 + yo, 0);
leg5.addBox(-1, -1, -1, 16, 2, 2, g); // Leg1
leg5.setPos(4, 0 + yo, 0);
leg6.addBox(-15, -1, -1, 16, 2, 2, g); // Leg2
leg6.setPos(-4, 0 + yo, -1);
leg7.addBox(-1, -1, -1, 16, 2, 2, g); // Leg3
leg7.setPos(4, 0 + yo, -1);
}
/*@Override*/
void render(Entity* entity, float time, float r, float bob, float yRot, float xRot, float scale) {
setupAnim(time, r, bob, yRot, xRot, scale);
head.render(scale);
body0.render(scale);
body1.render(scale);
leg0.render(scale);
leg1.render(scale);
leg2.render(scale);
leg3.render(scale);
leg4.render(scale);
leg5.render(scale);
leg6.render(scale);
leg7.render(scale);
}
void setupAnim(float time, float r, float bob, float yRot, float xRot, float scale) {
head.yRot = yRot / (float) (180 / Mth::PI);
head.xRot = xRot / (float) (180 / Mth::PI);
const float sr = (float) Mth::PI / 4.0f;
leg0.zRot = -sr;
leg1.zRot = sr;
leg2.zRot = -sr * 0.74f;
leg3.zRot = sr * 0.74f;
leg4.zRot = -sr * 0.74f;
leg5.zRot = sr * 0.74f;
leg6.zRot = -sr;
leg7.zRot = sr;
//float ro = -(float) Mth::PI / 2.0f * 0;
const float ur = (float) Mth::PI / 8.0f;
const float ur2 = sr;
leg0.yRot = ur2;
leg1.yRot = -ur2;
leg2.yRot = ur;
leg3.yRot = -ur;
leg4.yRot = -ur;
leg5.yRot = +ur;
leg6.yRot = -ur2;
leg7.yRot = +ur2;
//static Stopwatch w;
//w.start();
float c0 = -((float) Mth::cos(time * 0.6662f * 2 + Mth::PI * 2 * 0 / 4.0f) * 0.4f) * r;
float c1 = -((float) Mth::cos(time * 0.6662f * 2 + Mth::PI * 2 * 2 / 4.0f) * 0.4f) * r;
float c2 = -((float) Mth::cos(time * 0.6662f * 2 + Mth::PI * 2 * 1 / 4.0f) * 0.4f) * r;
float c3 = -((float) Mth::cos(time * 0.6662f * 2 + Mth::PI * 2 * 3 / 4.0f) * 0.4f) * r;
//LOGI("spider: %f, %f, %f, %f\n", c0, c1, c2, c3);
float s0 = std::abs((float) Mth::sin(time * 0.6662f + Mth::PI * 2 * 0 / 4.0f) * 0.4f) * r;
float s1 = std::abs((float) Mth::sin(time * 0.6662f + Mth::PI * 2 * 2 / 4.0f) * 0.4f) * r;
float s2 = std::abs((float) Mth::sin(time * 0.6662f + Mth::PI * 2 * 1 / 4.0f) * 0.4f) * r;
float s3 = std::abs((float) Mth::sin(time * 0.6662f + Mth::PI * 2 * 3 / 4.0f) * 0.4f) * r;
//w.stop();
//w.printEvery(100);
//LOGI("spiddy: %f, %f, %f, %f\n", s0, s1, s2, s3);
leg0.yRot += c0;
leg1.yRot -= c0;
leg2.yRot += c1;
leg3.yRot -= c1;
leg4.yRot += c2;
leg5.yRot -= c2;
leg6.yRot += c3;
leg7.yRot -= c3;
leg0.zRot += s0;
leg1.zRot -= s0;
leg2.zRot += s1;
leg3.zRot -= s1;
leg4.zRot += s2;
leg5.zRot -= s2;
leg6.zRot += s3;
leg7.zRot -= s3;
}
};
#endif /*NET_MINECRAFT_CLIENT_MODEL__SpiderModel_H__*/

37
src/client/model/ZombieModel.h Executable file
View File

@@ -0,0 +1,37 @@
#ifndef NET_MINECRAFT_CLIENT_MODEL__ZombieModel_H__
#define NET_MINECRAFT_CLIENT_MODEL__ZombieModel_H__
//package net.minecraft.client.model;
#include "HumanoidModel.h"
class ZombieModel: public HumanoidModel
{
typedef HumanoidModel super;
public:
void setupAnim(float time, float r, float bob, float yRot, float xRot, float scale) {
super::setupAnim(time, r, bob, yRot, xRot, scale);
if(!holdingLeftHand && !holdingRightHand) {
float attack2 = (float) Mth::sin(attackTime * Mth::PI);
float attack = (float) Mth::sin((1 - (1 - attackTime) * (1 - attackTime)) * Mth::PI);
arm0.zRot = 0;// -attack;
arm1.zRot = 0;// +attack;
arm0.yRot = -(0.1f - attack2 * 0.6f);
arm1.yRot = +(0.1f - attack2 * 0.6f);
arm0.xRot = -Mth::PI / 2.0f;
arm1.xRot = -Mth::PI / 2.0f;
arm0.xRot -= attack2 * 1.2f - attack * 0.4f;
arm1.xRot -= attack2 * 1.2f - attack * 0.4f;
// body.yRot = attack;
const float zBob = Mth::cos(bob * 0.09f) * 0.05f + 0.05f;
const float xBob = Mth::sin(bob * 0.067f) * 0.05f;
arm0.zRot += zBob;
arm1.zRot -= zBob;
arm0.xRot += xBob;
arm1.xRot -= xBob;
}
}
};
#endif /*NET_MINECRAFT_CLIENT_MODEL__ZombieModel_H__*/

75
src/client/model/geom/Cube.cpp Executable file
View File

@@ -0,0 +1,75 @@
#include "Cube.h"
#include "ModelPart.h"
#include "../../renderer/Tesselator.h"
#include "../../renderer/gles.h"
#include "../../../util/Mth.h"
Cube::Cube(ModelPart* modelPart, int xTexOffs, int yTexOffs, float x0, float y0, float z0, int w, int h, int d, float g)
: x0(x0),
y0(y0),
z0(z0),
x1(x0 + w),
y1(y0 + h),
z1(z0 + d)
{
float x1 = this->x1;
float y1 = this->y1;
float z1 = this->z1;
x0 -= g;
y0 -= g;
z0 -= g;
x1 += g;
y1 += g;
z1 += g;
if (modelPart->mirror) {
float tmp = x1;
x1 = x0;
x0 = tmp;
}
vertices[0] = VertexPT(x0, y0, z0, 0, 0);
vertices[1] = VertexPT(x1, y0, z0, 0, 8);
vertices[2] = VertexPT(x1, y1, z0, 8, 8);
vertices[3] = VertexPT(x0, y1, z0, 8, 0);
vertices[4] = VertexPT(x0, y0, z1, 0, 0);
vertices[5] = VertexPT(x1, y0, z1, 0, 8);
vertices[6] = VertexPT(x1, y1, z1, 8, 8);
vertices[7] = VertexPT(x0, y1, z1, 8, 0);
VertexPT* ptr = vertices - 1;
VertexPT* u0 = ++ptr;
VertexPT* u1 = ++ptr;
VertexPT* u2 = ++ptr;
VertexPT* u3 = ++ptr;
VertexPT* l0 = ++ptr;
VertexPT* l1 = ++ptr;
VertexPT* l2 = ++ptr;
VertexPT* l3 = ++ptr;
polygons[0] = PolygonQuad(l1, u1, u2, l2, xTexOffs + d + w, yTexOffs + d, xTexOffs + d + w + d, yTexOffs + d + h); // Right
polygons[1] = PolygonQuad(u0, l0, l3, u3, xTexOffs + 0, yTexOffs + d, xTexOffs + d, yTexOffs + d + h); // Left
polygons[2] = PolygonQuad(l1, l0, u0, u1, xTexOffs + d, yTexOffs + 0, xTexOffs + d + w, yTexOffs + d); // Up
polygons[3] = PolygonQuad(u2, u3, l3, l2, xTexOffs + d + w, yTexOffs + d, xTexOffs + d + w + w, yTexOffs); // Down
polygons[4] = PolygonQuad(u1, u0, u3, u2, xTexOffs + d, yTexOffs + d, xTexOffs + d + w, yTexOffs + d + h); // Front
polygons[5] = PolygonQuad(l0, l1, l2, l3, xTexOffs + d + w + d, yTexOffs + d, xTexOffs + d + w + d + w, yTexOffs + d + h); // Back
if (modelPart->mirror) {
for (int i = 0; i < 6; i++)
polygons[i].mirror();
}
}
void Cube::compile(Tesselator& t, float scale) {
for (int i = 0; i < 6; i++) {
polygons[i].render(t, scale);
}
}
Cube* Cube::setId(const std::string& id) {
this->id = id;
return this;
}

29
src/client/model/geom/Cube.h Executable file
View File

@@ -0,0 +1,29 @@
#ifndef NET_MINECRAFT_CLIENT_MODEL_GEOM__Cube_H__
#define NET_MINECRAFT_CLIENT_MODEL_GEOM__Cube_H__
//package net.minecraft.client.model;
#include <string>
#include "Polygon.h"
class Tesselator;
class ModelPart;
class Cube
{
public:
Cube(ModelPart* modelPart, int xTexOffs, int yTexOffs, float x0, float y0, float z0, int w, int h, int d, float g);
void compile(Tesselator& t, float scale);
Cube* setId(const std::string& id);
private:
VertexPT vertices[8];
PolygonQuad polygons[6];
std::string id;
const float x0, y0, z0, x1, y1, z1;
friend class ModelPart;
};
#endif /*NET_MINECRAFT_CLIENT_MODEL_GEOM__Cube_H__*/

View File

@@ -0,0 +1,303 @@
#include "ModelPart.h"
#include "Cube.h"
#include "../Model.h"
#include "../../renderer/Tesselator.h"
#include "../../../util/Mth.h"
ModelPart::ModelPart( const std::string& id )
: id(id),
model(NULL),
xTexOffs(0),
yTexOffs(0)
{
_init();
}
ModelPart::ModelPart( int xTexOffs /*= 0*/, int yTexOffs /*= 0*/ )
: xTexOffs(xTexOffs),
yTexOffs(yTexOffs),
model(NULL)
{
_init();
}
ModelPart::ModelPart( Model* model, int xTexOffs /*= 0*/, int yTexOffs /*= 0*/ )
: model(model),
xTexOffs(xTexOffs),
yTexOffs(yTexOffs)
{
_init();
}
ModelPart::~ModelPart() {
clear();
}
void ModelPart::_init() {
x = y = z = 0;
xRot = yRot = zRot = 0;
list = 0;
mirror = false;
visible = true;
neverRender = false;
compiled = false;
xTexSize = 64;
yTexSize = 32;
vboId = 0;
glGenBuffers2(1, &vboId);
}
void ModelPart::setModel(Model* model) {
if (this->model) {
Util::remove(this->model->cubes, this);
}
if (model) {
model->cubes.push_back(this);
setTexSize(model->texWidth, model->texHeight);
}
this->model = model;
}
void ModelPart::addChild(ModelPart* child) {
children.push_back(child);
}
ModelPart& ModelPart::addBox(const std::string& id, float x0, float y0, float z0, int w, int h, int d) {
std::string newid = this->id + "." + id;
//TexOffs offs = model.getMapTex(id); //@todo @diff
//texOffs(offs.x, offs.y);
cubes.push_back((new Cube(this, xTexOffs, yTexOffs, x0, y0, z0, w, h, d, 0))->setId(newid));
return *this;
}
ModelPart& ModelPart::addBox(float x0, float y0, float z0, int w, int h, int d) {
cubes.push_back(new Cube(this, xTexOffs, yTexOffs, x0, y0, z0, w, h, d, 0));
return *this;
}
void ModelPart::addBox(float x0, float y0, float z0, int w, int h, int d, float g) {
cubes.push_back(new Cube(this, xTexOffs, yTexOffs, x0, y0, z0, w, h, d, g));
}
//This Cube constructor is commented out
//void ModelPart::addTexBox(float x0, float y0, float z0, int w, int h, int d, int tex) {
// cubes.push_back(new Cube(this, xTexOffs, yTexOffs, x0, y0, z0, w, h, d, tex));
//}
void ModelPart::setPos( float x, float y, float z )
{
this->x = x;
this->y = y;
this->z = z;
}
void ModelPart::render( float scale )
{
if (neverRender) return;
if (!visible) return;
if (!compiled) compile(scale);
if (xRot != 0 || yRot != 0 || zRot != 0) {
glPushMatrix2();
glTranslatef2(x * scale, y * scale, z * scale);
const float c = Mth::RADDEG;
if (zRot != 0) glRotatef2(zRot * c, 0.0f, 0.0f, 1.0f);
if (yRot != 0) glRotatef2(yRot * c, 0.0f, 1.0f, 0.0f);
if (xRot != 0) glRotatef2(xRot * c, 1.0f, 0.0f, 0.0f);
//LOGI("A");
draw();
if (!children.empty()) {
for (unsigned int i = 0; i < children.size(); i++) {
children[i]->render(scale);
}
}
glPopMatrix2();
} else if (x != 0 || y != 0 || z != 0) {
glTranslatef2(x * scale, y * scale, z * scale);
//LOGI("B");
draw();
if (!children.empty()) {
for (unsigned int i = 0; i < children.size(); i++) {
children[i]->render(scale);
}
}
glTranslatef2(-x * scale, -y * scale, -z * scale);
} else {
//LOGI("C");
draw();
if (!children.empty()) {
for (unsigned int i = 0; i < children.size(); i++) {
children[i]->render(scale);
}
}
}
}
void ModelPart::renderRollable( float scale )
{
if (neverRender) return;
if (!visible) return;
if (!compiled) compile(scale);
glPushMatrix2();
glTranslatef2(x * scale, y * scale, z * scale);
const float c = Mth::RADDEG;
if (yRot != 0) glRotatef2(yRot * c, 0.0f, 1.0f, 0.0f);
if (xRot != 0) glRotatef2(xRot * c, 1.0f, 0.0f, 0.0f);
if (zRot != 0) glRotatef2(zRot * c, 0.0f, 0.0f, 1.0f);
draw();
glPopMatrix2();
}
void ModelPart::translateTo( float scale )
{
if (neverRender) return;
if (!visible) return;
if (!compiled) compile(scale);
if (xRot != 0 || yRot != 0 || zRot != 0) {
const float c = Mth::RADDEG;
glTranslatef2(x * scale, y * scale, z * scale);
if (zRot != 0) glRotatef2(zRot * c, 0.0f, 0.0f, 1.0f);
if (yRot != 0) glRotatef2(yRot * c, 0.0f, 1.0f, 0.0f);
if (xRot != 0) glRotatef2(xRot * c, 1.0f, 0.0f, 0.0f);
} else if (x != 0 || y != 0 || z != 0) {
glTranslatef2(x * scale, y * scale, z * scale);
} else {
}
}
void ModelPart::compile( float scale )
{
#ifndef OPENGL_ES
list = glGenLists(1);
// FIX NORMAL BUG HERE
glNewList(list, GL_COMPILE);
#endif
Tesselator& t = Tesselator::instance;
t.begin();
t.color(255, 255, 255, 255);
for (int i = 0; i < 6; i++) {
for (unsigned int i = 0; i < cubes.size(); ++i)
cubes[i]->compile(t, scale);
}
t.end(true, vboId);
#ifndef OPENGL_ES
glEndList();
#endif
compiled = true;
}
void ModelPart::draw()
{
#ifdef OPENGL_ES
drawArrayVT_NoState(vboId, cubes.size() * 2 * 3 * 6, 24);
#else
glCallList(list);
#endif
}
ModelPart& ModelPart::setTexSize(int xs, int ys) {
xTexSize = (float)xs;
yTexSize = (float)ys;
return *this;
}
ModelPart& ModelPart::texOffs(int xTexOffs, int yTexOffs) {
this->xTexOffs = xTexOffs;
this->yTexOffs = yTexOffs;
return *this;
}
void ModelPart::mimic(const ModelPart* o) {
x = o->x;
y = o->y;
z = o->z;
xRot = o->xRot;
yRot = o->yRot;
zRot = o->zRot;
}
void ModelPart::renderHorrible( float scale )
{
if (neverRender) {
return;
}
if (!visible) {
return;
}
//if (!compiled) compile(scale);
if (xRot != 0 || yRot != 0 || zRot != 0) {
glPushMatrix2();
glTranslatef2(x * scale, y * scale, z * scale);
if (zRot != 0) glRotatef2(zRot * Mth::RADDEG, 0.0f, 0.0f, 1.0f);
if (yRot != 0) glRotatef2(yRot * Mth::RADDEG, 0.0f, 1.0f, 0.0f);
if (xRot != 0) glRotatef2(xRot * Mth::RADDEG, 1.0f, 0.0f, 0.0f);
drawSlow(scale);
glPopMatrix2();
} else if (x != 0 || y != 0 || z != 0) {
glTranslatef2(x * scale, y * scale, z * scale);
drawSlow(scale);
glTranslatef2(-x * scale, -y * scale, -z * scale);
} else {
drawSlow(scale);
}
}
void ModelPart::drawSlow( float scale )
{
Tesselator& t = Tesselator::instance;
t.begin();
for (int j = 0; j < (int)cubes.size(); ++j) {
Cube* c = cubes[j];
for (int i = 0; i < 6; i++) {
c->polygons[i].render(t, scale, vboId);
}
}
t.draw();
}
void ModelPart::clear()
{
for (unsigned int i = 0; i < cubes.size(); ++i)
delete cubes[i];
cubes.clear();
setModel(NULL);
}
ModelPart& ModelPart::operator=( const ModelPart& rhs )
{
clear();
if (!id.empty() || !rhs.id.empty()) {
id = rhs.id;
}
xTexOffs = rhs.xTexOffs;
yTexOffs = rhs.yTexOffs;
compiled = false;
mirror = rhs.mirror;
setModel(rhs.model);
cubes.assign(rhs.cubes.begin(), rhs.cubes.end());
mimic(&rhs);
return *this;
}

View File

@@ -0,0 +1,74 @@
#ifndef NET_MINECRAFT_CLIENT_MODEL_GEOM__ModelPart_H__
#define NET_MINECRAFT_CLIENT_MODEL_GEOM__ModelPart_H__
#include "../../renderer/gles.h"
class Model;
class Cube;
class ModelPart
{
public:
ModelPart(const std::string& id);
ModelPart(int xTexOffs = 0, int yTexOffs = 0);
ModelPart(Model* model, int xTexOffs = 0, int yTexOffs = 0);
~ModelPart();
void _init();
void clear();//const ModelPart& rhs);
ModelPart& operator=(const ModelPart& rhs);
void setModel(Model* model);
void setPos( float x, float y, float z );
void translateTo( float scale );
ModelPart& setTexSize(int xs, int ys);
ModelPart& texOffs(int xTexOffs, int yTexOffs);
void mimic(const ModelPart* o);
// Render normally
void render( float scale );
void renderRollable( float scale );
void draw();
// Bad, immediate version... //@fix @todo: remove this
void renderHorrible(float scale);
void drawSlow( float scale );
void onGraphicsReset() { compiled = false; }
void compile( float scale );
void addChild(ModelPart* child);
ModelPart& addBox(const std::string& id, float x0, float y0, float z0, int w, int h, int d);
ModelPart& addBox(float x0, float y0, float z0, int w, int h, int d);
void addBox(float x0, float y0, float z0, int w, int h, int d, float g);
void addTexBox(float x0, float y0, float z0, int w, int h, int d, int tex);
float x, y, z;
float xRot, yRot, zRot;
bool mirror;
bool visible;
std::vector<Cube*> cubes;
std::vector<ModelPart*> children;
std::string id;
float xTexSize;
float yTexSize;
private:
int xTexOffs, yTexOffs;
bool neverRender;
bool compiled;
int list;
GLuint vboId;
Model* model;
};
#endif /*NET_MINECRAFT_CLIENT_MODEL_GEOM__ModelPart_H__*/

View File

@@ -0,0 +1,55 @@
#include "Polygon.h"
#include "../../renderer/Tesselator.h"
#include "../../../world/phys/Vec3.h"
PolygonQuad::PolygonQuad(VertexPT* v0, VertexPT* v1, VertexPT* v2, VertexPT* v3)
: _flipNormal(false)
{
vertices[0] = *v0;
vertices[1] = *v1;
vertices[2] = *v2;
vertices[3] = *v3;
}
PolygonQuad::PolygonQuad( VertexPT* v0, VertexPT* v1, VertexPT* v2, VertexPT* v3,
int uu0, int vv0, int uu1, int vv1)
: _flipNormal(false)
{
const float us = -0.002f / 64.0f;//0.1f / 64.0f;
const float vs = -0.002f / 32.0f;//0.1f / 32.0f;
vertices[0] = v0->remap(uu1 / 64.0f - us, vv0 / 32.0f + vs);
vertices[1] = v1->remap(uu0 / 64.0f + us, vv0 / 32.0f + vs);
vertices[2] = v2->remap(uu0 / 64.0f + us, vv1 / 32.0f - vs);
vertices[3] = v3->remap(uu1 / 64.0f - us, vv1 / 32.0f - vs);
}
PolygonQuad::PolygonQuad( VertexPT* v0, VertexPT* v1, VertexPT* v2, VertexPT* v3,
float uu0, float vv0, float uu1, float vv1)
: _flipNormal(false)
{
vertices[0] = v0->remap(uu1, vv0);
vertices[1] = v1->remap(uu0, vv0);
vertices[2] = v2->remap(uu0, vv1);
vertices[3] = v3->remap(uu1, vv1);
}
void PolygonQuad::mirror() {
for (int i = 0; i < VERTEX_COUNT / 2; ++i) {
const int j = VERTEX_COUNT - i - 1;
VertexPT tmp = vertices[i];
vertices[i] = vertices[j];
vertices[j] = tmp;
}
}
void PolygonQuad::render(Tesselator& t, float scale, int vboId /* = -1 */) {
for (int i = 0; i < 4; i++) {
VertexPT& v = vertices[i];
t.vertexUV(v.pos.x * scale, v.pos.y * scale, v.pos.z * scale, v.u, v.v);
}
}
PolygonQuad* PolygonQuad::flipNormal() {
_flipNormal = true;
return this;
}

29
src/client/model/geom/Polygon.h Executable file
View File

@@ -0,0 +1,29 @@
#ifndef NET_MINECRAFT_CLIENT_MODEL__Polygon_H__
#define NET_MINECRAFT_CLIENT_MODEL__Polygon_H__
//package net.minecraft.client.model;
#include "Vertex.h"
class Tesselator;
class PolygonQuad
{
public:
PolygonQuad() {}
PolygonQuad(VertexPT*,VertexPT*,VertexPT*,VertexPT*);
PolygonQuad(VertexPT*,VertexPT*,VertexPT*,VertexPT*, int u0, int v0, int u1, int v1);
PolygonQuad(VertexPT*,VertexPT*,VertexPT*,VertexPT*, float u0, float v0, float u1, float v1);
void mirror();
void render(Tesselator& t, float scale, int vboId = -1);
PolygonQuad* flipNormal();
VertexPT vertices[4];
//int vertexCount;
private:
static const int VERTEX_COUNT = 4;
bool _flipNormal;
};
#endif /*NET_MINECRAFT_CLIENT_MODEL__Polygon_H__*/

40
src/client/model/geom/Vertex.h Executable file
View File

@@ -0,0 +1,40 @@
#ifndef NET_MINECRAFT_CLIENT_MODEL__Vertex_H__
#define NET_MINECRAFT_CLIENT_MODEL__Vertex_H__
//package net.minecraft.client.model;
#include "../../../world/phys/Vec3.h"
class VertexPT
{
public:
Vec3 pos;
float u, v;
VertexPT() {}
VertexPT(float x, float y, float z, float u_, float v_)
: pos(x, y, z),
u(u_),
v(v_)
{}
VertexPT remap(float u, float v) {
return VertexPT(*this, u, v);
}
VertexPT(const VertexPT& vertex, float u_, float v_) {
pos = vertex.pos;
u = u_;
v = v_;
}
VertexPT(const Vec3& pos_, float u_, float v_) {
pos = pos_;
u = u_;
v = v_;
}
};
#endif /*NET_MINECRAFT_CLIENT_MODEL__Vertex_H__*/