mirror of
https://git.neolegacy.dev/neoStudiosLCE/neoLegacy.git
synced 2026-11-19 03:53:03 +01:00
Co-authored-by: DrPerkyLegit <116128211+DrPerkyLegit@users.noreply.github.com> Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: Anaël <60509176+Bakoubak@users.noreply.github.com> Reviewed-on: https://git.neolegacy.dev/neoStudiosLCE/neoLegacy/pulls/4205
108 lines
3.3 KiB
C++
108 lines
3.3 KiB
C++
#include "stdafx.h"
|
|
#include "BoatModel.h"
|
|
#include "../Minecraft.World/Boat.h"
|
|
#include "../Minecraft.World/Mth.h"
|
|
|
|
static float clampedLerp(float from, float to, float t)
|
|
{
|
|
if (t < 0.0f) return from;
|
|
if (t > 1.0f) return to;
|
|
return from + (to - from) * t;
|
|
}
|
|
|
|
ModelPart *BoatModel::makePaddle(bool isLeft)
|
|
{
|
|
ModelPart *paddle = new ModelPart(this, 62, isLeft ? 0 : 20);
|
|
paddle->setTexSize(128, 64);
|
|
paddle->addBox(-1.0f, 0.0f, -5.0f, 2, 2, 18);
|
|
paddle->addBox(isLeft ? -1.001f : 0.001f, -3.0f, 8.0f, 1, 6, 7);
|
|
return paddle;
|
|
}
|
|
|
|
BoatModel::BoatModel() : Model()
|
|
{
|
|
texWidth = 128;
|
|
texHeight = 64;
|
|
|
|
bottom = new ModelPart(this, 0, 0);
|
|
back = new ModelPart(this, 0, 19);
|
|
front = new ModelPart(this, 0, 27);
|
|
right = new ModelPart(this, 0, 35);
|
|
left = new ModelPart(this, 0, 43);
|
|
|
|
bottom->addBox(-14.0f, -9.0f, -3.0f, 28, 16, 3, 0.0f);
|
|
bottom->setPos(0.0f, 3.0f, 1.0f);
|
|
back->addBox(-13.0f, -7.0f, -1.0f, 18, 6, 2, 0.0f);
|
|
back->setPos(-15.0f, 4.0f, 4.0f);
|
|
front->addBox(-8.0f, -7.0f, -1.0f, 16, 6, 2, 0.0f);
|
|
front->setPos(15.0f, 4.0f, 0.0f);
|
|
right->addBox(-14.0f, -7.0f, -1.0f, 28, 6, 2, 0.0f);
|
|
right->setPos(0.0f, 4.0f, -9.0f);
|
|
left->addBox(-14.0f, -7.0f, -1.0f, 28, 6, 2, 0.0f);
|
|
left->setPos(0.0f, 4.0f, 9.0f);
|
|
|
|
bottom->xRot = PI / 2;
|
|
back->yRot = PI / 2 * 3;
|
|
front->yRot = PI / 2;
|
|
right->yRot = PI;
|
|
|
|
paddleLeft = makePaddle(true);
|
|
paddleLeft->setPos(3.0f, -5.0f, 9.0f);
|
|
paddleRight = makePaddle(false);
|
|
paddleRight->setPos(3.0f, -5.0f, -9.0f);
|
|
paddleRight->yRot = PI;
|
|
paddleLeft->zRot = PI / 16;
|
|
paddleRight->zRot = PI / 16;
|
|
|
|
waterPatch = new ModelPart(this, 0, 0);
|
|
waterPatch->setTexSize(128, 64);
|
|
waterPatch->addBox(-14.0f, -9.0f, -3.0f, 28, 16, 3, 0.0f);
|
|
waterPatch->setPos(0.0f, -3.0f, 1.0f);
|
|
waterPatch->xRot = PI / 2;
|
|
|
|
// 4J added - compile now to avoid random performance hit first time cubes are rendered
|
|
bottom->compile(1.0f / 16.0f);
|
|
back->compile(1.0f / 16.0f);
|
|
front->compile(1.0f / 16.0f);
|
|
right->compile(1.0f / 16.0f);
|
|
left->compile(1.0f / 16.0f);
|
|
paddleLeft->compile(1.0f / 16.0f);
|
|
paddleRight->compile(1.0f / 16.0f);
|
|
waterPatch->compile(1.0f / 16.0f);
|
|
}
|
|
|
|
void BoatModel::animatePaddle(ModelPart *paddle, float rowingTime, int side, float scale, bool usecompiled)
|
|
{
|
|
paddle->xRot = clampedLerp(-PI / 3, -PI / 12, (Mth::sin(-rowingTime) + 1.0f) / 2.0f);
|
|
paddle->yRot = clampedLerp(-PI / 4, PI / 4, (Mth::sin(-rowingTime + 1.0f) + 1.0f) / 2.0f);
|
|
if (side == 1)
|
|
{
|
|
paddle->yRot = PI - paddle->yRot;
|
|
}
|
|
paddle->render(scale, usecompiled);
|
|
}
|
|
|
|
void BoatModel::render(shared_ptr<Entity> entity, float time, float r, float bob, float yRot, float xRot, float scale, bool usecompiled)
|
|
{
|
|
glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
|
|
|
|
bottom->render(scale, usecompiled);
|
|
back->render(scale, usecompiled);
|
|
front->render(scale, usecompiled);
|
|
right->render(scale, usecompiled);
|
|
left->render(scale, usecompiled);
|
|
|
|
shared_ptr<Boat> boat = dynamic_pointer_cast<Boat>(entity);
|
|
float a = time;
|
|
animatePaddle(paddleLeft, boat != nullptr ? boat->getRowingTime(0, a) : 0.0f, 0, scale, usecompiled);
|
|
animatePaddle(paddleRight, boat != nullptr ? boat->getRowingTime(1, a) : 0.0f, 1, scale, usecompiled);
|
|
}
|
|
|
|
void BoatModel::renderWaterPatch(float scale, bool usecompiled)
|
|
{
|
|
glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
|
|
glColorMask(false, false, false, false);
|
|
waterPatch->render(scale, usecompiled);
|
|
glColorMask(true, true, true, true);
|
|
}
|