1
0
mirror of https://github.com/XProger/OpenLara.git synced 2025-08-15 09:34:18 +02:00

#8 fix cutscene (TR2 CUT1)

This commit is contained in:
XProger
2018-04-20 02:25:30 +03:00
parent 24eb034332
commit 9c6a8c1a3b
6 changed files with 41 additions and 16 deletions

View File

@@ -16,13 +16,14 @@ struct Animation {
TR::AnimFrame *frameA, *frameB;
vec3 offset, jump;
bool isEnded, isPrepareToNext, flip;
bool smooth;
quat *overrides; // left & right arms animation frames
int overrideMask;
Animation() : overrides(NULL) {}
Animation(TR::Level *level, const TR::Model *model) : level(level), overrides(NULL), overrideMask(0) {
Animation(TR::Level *level, const TR::Model *model, bool smooth = true) : level(level), smooth(smooth), overrides(NULL), overrideMask(0) {
setModel(model);
}
@@ -90,7 +91,7 @@ struct Animation {
}
void playNext() {
setAnim(next, anims[index].nextFrame);
setAnim(next, anims[index].nextFrame, false);
}
TR::AnimFrame* getFrame(TR::Animation *anim, int index) {
@@ -121,7 +122,6 @@ struct Animation {
int k = fIndex * anim->frameRate;
delta = (time * 30.0f - k) / min((int)anim->frameRate, max(1, framesCount - k)); // min is because in some cases framesCount > realFramesCount / frameRate * frameRate
// size of frame (in bytes)
int fIndexA = fIndex % fCount,
fIndexB = (fIndex + 1) % fCount;
@@ -138,7 +138,10 @@ struct Animation {
getCommand(anim, frameNext, NULL, NULL, &flip);
if (smooth)
frameB = getFrame(anim, fIndexB);
else
frameB = frameA;
}
bool isFrameActive(int index) {

View File

@@ -332,9 +332,12 @@ struct Camera : ICamera {
TR::CameraFrame *frameA = &level->cameraFrames[indexA];
TR::CameraFrame *frameB = &level->cameraFrames[indexB];
const int eps = 512;
const float maxDelta = 256 * 256;
if (abs(frameA->pos.x - frameB->pos.x) > eps || abs(frameA->pos.y - frameB->pos.y) > eps || abs(frameA->pos.z - frameB->pos.z) > eps) {
float dp = (vec3(frameA->pos) - vec3(frameB->pos)).length2();
float dt = (vec3(frameA->target) - vec3(frameB->target)).length2();
if (dp > maxDelta || dt > maxDelta) {
eye.pos = frameA->pos;
target.pos = frameA->target;
fov = frameA->fov / 32767.0f * 120.0f;

View File

@@ -144,7 +144,7 @@ struct Controller {
vec3 lastPos;
bool invertAim;
Controller(IGame *game, int entity) : next(NULL), game(game), level(game->getLevel()), entity(entity), animation(level, getModel()), state(animation.state), layers(0), explodeMask(0), explodeParts(0), lastPos(0), invertAim(false) {
Controller(IGame *game, int entity) : next(NULL), game(game), level(game->getLevel()), entity(entity), animation(level, getModel(), level->entities[entity].flags.smooth), state(animation.state), layers(0), explodeMask(0), explodeParts(0), lastPos(0), invertAim(false) {
const TR::Entity &e = getEntity();
pos = vec3(float(e.x), float(e.y), float(e.z));
angle = vec3(0.0f, e.rotation, 0.0f);
@@ -977,8 +977,13 @@ struct Controller {
}
case TR::Effect::INV_ON : flags.invisible = true; break;
case TR::Effect::INV_OFF : flags.invisible = false; break;
case TR::Effect::DYN_ON : break; // TODO TR2
case TR::Effect::DYN_OFF : break; // TODO TR2
case TR::Effect::DYN_ON :
Core::lightColor[1] = vec4(0.6f, 0.5f, 0.1f, 1.0f / 4096.0f);
Core::lightPos[1] = getPos();
break;
case TR::Effect::DYN_OFF :
Core::lightColor[1] = vec4(0, 0, 0, 1);
break;
case TR::Effect::FOOTPRINT : break; // TODO TR3
default : ASSERT(false);
}
@@ -1043,7 +1048,7 @@ struct Controller {
if (animation.isEnded) { // if animation is end - switch to next
if (animation.offset != 0.0f) cmdOffset(animation.offset);
if (animation.jump != 0.0f) cmdJump(animation.jump);
animation.playNext();
// animation.playNext();
} else
animation.framePrev = animation.frameIndex;
}

View File

@@ -48,6 +48,7 @@ namespace Debug {
}
void begin() {
glActiveTexture(GL_TEXTURE0);
glDisable(GL_TEXTURE_2D);
glMatrixMode(GL_PROJECTION);
glLoadMatrixf((GLfloat*)&Core::mProj);
@@ -484,7 +485,7 @@ namespace Debug {
if (!controller) continue;
sprintf(buf, "%s (%d) %s", getEntityName(level, e), i, controller->flags.invisible ? "INVISIBLE" : "");
Debug::Draw::text(controller->getPos() + randf() * 64, controller->flags.active ? vec4(0, 0, 0.8f, 1) : vec4(0.8f, 0, 0, 1), buf);
Debug::Draw::text(controller->getPos() + randf() * 64.0f, controller->flags.active ? vec4(0, 0, 0.8f, 1) : vec4(0.8f, 0, 0, 1), buf);
}
for (int i = 0; i < level.camerasCount; i++) {

View File

@@ -1480,7 +1480,7 @@ namespace TR {
int16 intensity2;
union Flags {
struct {
uint16 state:2, unused:4, collision:1, invisible:1, once:1, active:5, reverse:1, rendered:1;
uint16 state:2, unused:3, smooth:1, collision:1, invisible:1, once:1, active:5, reverse:1, rendered:1;
};
uint16 value;
} flags;
@@ -2897,6 +2897,15 @@ namespace TR {
cutMatrix.rotateY(e.rotation);
}
}
// turn off interpolation for some entities
if (id == LVL_TR2_CUT_1)
for (int i = 0; i < entitiesBaseCount; i++) {
Entity &e = entities[i];
if (e.type == Entity::CUT_6 || e.type == Entity::CUT_8 || e.type == Entity::CUT_9) {
e.flags.smooth = false;
}
}
}
LevelID getTitleId() const {
@@ -3557,6 +3566,7 @@ namespace TR {
if (version & (VER_TR2 | VER_TR3))
stream.read(e.intensity2);
stream.read(e.flags.value);
e.flags.smooth = true;
e.type = Entity::remap(version, e.type);

View File

@@ -2029,16 +2029,19 @@ struct Level : IGame {
for (int i = 0; i < level.entitiesCount; i++) {
TR::Entity &e = level.entities[i];
Controller *controller = (Controller*)e.controller;
if (controller && controller->isActive() && e.isEnemy() && e.castShadow() && controller != players[0] && controller != players[1]) {
if (controller && e.castShadow() && controller != players[0] && controller != players[1]) {
int pIndex = 0;
float dist = (players[0]->pos - controller->pos).length2();
float dist = (players[0]->getPos() - controller->getPos()).length2();
if (players[1]) {
float dist2 = (players[1]->pos - controller->pos).length2();
float dist2 = (players[1]->getPos() - controller->getPos()).length2();
if (dist2 < dist) {
dist = dist2;
pIndex = 1;
}
}
if (dist > 8192 * 8192) continue;
// get index to insert
int index = base;
while (index < count) {