mirror of
https://github.com/XProger/OpenLara.git
synced 2025-08-18 10:51:23 +02:00
#8 fix cutscene (TR2 CUT1)
This commit is contained in:
@@ -16,13 +16,14 @@ struct Animation {
|
|||||||
TR::AnimFrame *frameA, *frameB;
|
TR::AnimFrame *frameA, *frameB;
|
||||||
vec3 offset, jump;
|
vec3 offset, jump;
|
||||||
bool isEnded, isPrepareToNext, flip;
|
bool isEnded, isPrepareToNext, flip;
|
||||||
|
bool smooth;
|
||||||
|
|
||||||
quat *overrides; // left & right arms animation frames
|
quat *overrides; // left & right arms animation frames
|
||||||
int overrideMask;
|
int overrideMask;
|
||||||
|
|
||||||
Animation() : overrides(NULL) {}
|
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);
|
setModel(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +91,7 @@ struct Animation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void playNext() {
|
void playNext() {
|
||||||
setAnim(next, anims[index].nextFrame);
|
setAnim(next, anims[index].nextFrame, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
TR::AnimFrame* getFrame(TR::Animation *anim, int index) {
|
TR::AnimFrame* getFrame(TR::Animation *anim, int index) {
|
||||||
@@ -121,7 +122,6 @@ struct Animation {
|
|||||||
int k = fIndex * anim->frameRate;
|
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
|
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,
|
int fIndexA = fIndex % fCount,
|
||||||
fIndexB = (fIndex + 1) % fCount;
|
fIndexB = (fIndex + 1) % fCount;
|
||||||
|
|
||||||
@@ -138,7 +138,10 @@ struct Animation {
|
|||||||
|
|
||||||
getCommand(anim, frameNext, NULL, NULL, &flip);
|
getCommand(anim, frameNext, NULL, NULL, &flip);
|
||||||
|
|
||||||
frameB = getFrame(anim, fIndexB);
|
if (smooth)
|
||||||
|
frameB = getFrame(anim, fIndexB);
|
||||||
|
else
|
||||||
|
frameB = frameA;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isFrameActive(int index) {
|
bool isFrameActive(int index) {
|
||||||
|
@@ -332,9 +332,12 @@ struct Camera : ICamera {
|
|||||||
TR::CameraFrame *frameA = &level->cameraFrames[indexA];
|
TR::CameraFrame *frameA = &level->cameraFrames[indexA];
|
||||||
TR::CameraFrame *frameB = &level->cameraFrames[indexB];
|
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;
|
eye.pos = frameA->pos;
|
||||||
target.pos = frameA->target;
|
target.pos = frameA->target;
|
||||||
fov = frameA->fov / 32767.0f * 120.0f;
|
fov = frameA->fov / 32767.0f * 120.0f;
|
||||||
|
@@ -144,7 +144,7 @@ struct Controller {
|
|||||||
vec3 lastPos;
|
vec3 lastPos;
|
||||||
bool invertAim;
|
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();
|
const TR::Entity &e = getEntity();
|
||||||
pos = vec3(float(e.x), float(e.y), float(e.z));
|
pos = vec3(float(e.x), float(e.y), float(e.z));
|
||||||
angle = vec3(0.0f, e.rotation, 0.0f);
|
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_ON : flags.invisible = true; break;
|
||||||
case TR::Effect::INV_OFF : flags.invisible = false; break;
|
case TR::Effect::INV_OFF : flags.invisible = false; break;
|
||||||
case TR::Effect::DYN_ON : break; // TODO TR2
|
case TR::Effect::DYN_ON :
|
||||||
case TR::Effect::DYN_OFF : break; // TODO TR2
|
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
|
case TR::Effect::FOOTPRINT : break; // TODO TR3
|
||||||
default : ASSERT(false);
|
default : ASSERT(false);
|
||||||
}
|
}
|
||||||
@@ -1043,7 +1048,7 @@ struct Controller {
|
|||||||
if (animation.isEnded) { // if animation is end - switch to next
|
if (animation.isEnded) { // if animation is end - switch to next
|
||||||
if (animation.offset != 0.0f) cmdOffset(animation.offset);
|
if (animation.offset != 0.0f) cmdOffset(animation.offset);
|
||||||
if (animation.jump != 0.0f) cmdJump(animation.jump);
|
if (animation.jump != 0.0f) cmdJump(animation.jump);
|
||||||
animation.playNext();
|
// animation.playNext();
|
||||||
} else
|
} else
|
||||||
animation.framePrev = animation.frameIndex;
|
animation.framePrev = animation.frameIndex;
|
||||||
}
|
}
|
||||||
|
@@ -48,6 +48,7 @@ namespace Debug {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void begin() {
|
void begin() {
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadMatrixf((GLfloat*)&Core::mProj);
|
glLoadMatrixf((GLfloat*)&Core::mProj);
|
||||||
@@ -484,7 +485,7 @@ namespace Debug {
|
|||||||
if (!controller) continue;
|
if (!controller) continue;
|
||||||
|
|
||||||
sprintf(buf, "%s (%d) %s", getEntityName(level, e), i, controller->flags.invisible ? "INVISIBLE" : "");
|
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++) {
|
for (int i = 0; i < level.camerasCount; i++) {
|
||||||
|
12
src/format.h
12
src/format.h
@@ -1480,7 +1480,7 @@ namespace TR {
|
|||||||
int16 intensity2;
|
int16 intensity2;
|
||||||
union Flags {
|
union Flags {
|
||||||
struct {
|
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;
|
uint16 value;
|
||||||
} flags;
|
} flags;
|
||||||
@@ -2897,6 +2897,15 @@ namespace TR {
|
|||||||
cutMatrix.rotateY(e.rotation);
|
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 {
|
LevelID getTitleId() const {
|
||||||
@@ -3557,6 +3566,7 @@ namespace TR {
|
|||||||
if (version & (VER_TR2 | VER_TR3))
|
if (version & (VER_TR2 | VER_TR3))
|
||||||
stream.read(e.intensity2);
|
stream.read(e.intensity2);
|
||||||
stream.read(e.flags.value);
|
stream.read(e.flags.value);
|
||||||
|
e.flags.smooth = true;
|
||||||
|
|
||||||
e.type = Entity::remap(version, e.type);
|
e.type = Entity::remap(version, e.type);
|
||||||
|
|
||||||
|
@@ -2029,16 +2029,19 @@ struct Level : IGame {
|
|||||||
for (int i = 0; i < level.entitiesCount; i++) {
|
for (int i = 0; i < level.entitiesCount; i++) {
|
||||||
TR::Entity &e = level.entities[i];
|
TR::Entity &e = level.entities[i];
|
||||||
Controller *controller = (Controller*)e.controller;
|
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;
|
int pIndex = 0;
|
||||||
float dist = (players[0]->pos - controller->pos).length2();
|
float dist = (players[0]->getPos() - controller->getPos()).length2();
|
||||||
if (players[1]) {
|
if (players[1]) {
|
||||||
float dist2 = (players[1]->pos - controller->pos).length2();
|
float dist2 = (players[1]->getPos() - controller->getPos()).length2();
|
||||||
if (dist2 < dist) {
|
if (dist2 < dist) {
|
||||||
dist = dist2;
|
dist = dist2;
|
||||||
pIndex = 1;
|
pIndex = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dist > 8192 * 8192) continue;
|
||||||
|
|
||||||
// get index to insert
|
// get index to insert
|
||||||
int index = base;
|
int index = base;
|
||||||
while (index < count) {
|
while (index < count) {
|
||||||
|
Reference in New Issue
Block a user